下单支付

pull/1/head
feijinping 3 years ago
parent 688611b268
commit 8563e7dbb7

@ -0,0 +1,22 @@
package com.cyl.h5.controller;
import com.cyl.h5.pojo.vo.form.OrderSubmitForm;
import com.cyl.oms.pojo.vo.OrderVO;
import com.cyl.oms.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/order")
public class OrderController {
@Autowired
private OrderService orderService;
@PostMapping("submit")
public ResponseEntity<OrderVO> submit(@RequestBody OrderSubmitForm form) {
return ResponseEntity.ok(orderService.submit(form));
}
}

@ -0,0 +1,47 @@
package com.cyl.h5.controller;
import com.cyl.ums.domain.MemberAddress;
import com.cyl.ums.pojo.query.MemberAddressQuery;
import com.cyl.ums.service.MemberAddressService;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RequestMapping("ucenter")
@RestController
public class UserController {
@Autowired
private MemberAddressService memberAddressService;
@GetMapping("user-address")
public ResponseEntity<List<MemberAddress>> queryPageOfAddress() {
MemberAddressQuery q = new MemberAddressQuery();
q.setMemberId(SecurityUtils.getUserId());
return ResponseEntity.ok(memberAddressService.selectList(q, null));
}
@PostMapping("add-update-user-address")
public ResponseEntity<MemberAddress> addOrUpdateAddress(@RequestBody MemberAddress address) {
if (address.getId() != null) {
address.setMemberId(null);
memberAddressService.updateSelective(address);
} else {
address.setMemberId(SecurityUtils.getUserId());
memberAddressService.insert(address);
}
return ResponseEntity.ok(address);
}
@DeleteMapping("delete-user-address")
public ResponseEntity<Integer> deleteUserAddress(@RequestBody List<Long> ids) {
return ResponseEntity.ok(memberAddressService.deleteUserIds(ids));
}
@GetMapping("detail-user-address")
public ResponseEntity<MemberAddress> detailUserAddress(@RequestParam("id") Long id) {
return ResponseEntity.ok(memberAddressService.selectByUserAndId(id));
}
}

@ -0,0 +1,21 @@
package com.cyl.h5.pojo.vo.form;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
@Data
public class OrderSubmitForm {
@NotNull
private Long addressId;
private String note;
@NotEmpty
private List<SkuParam> skus;
@Data
public static class SkuParam {
private Long skuId;
private Integer quantity;
}
}

@ -13,4 +13,6 @@ import java.util.List;
public interface OrderConvert { public interface OrderConvert {
List<OrderVO> dos2vos(List<Order> list); List<OrderVO> dos2vos(List<Order> list);
OrderVO do2vo(Order order);
} }

@ -2,6 +2,11 @@ package com.cyl.oms.pojo.vo;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
import com.cyl.oms.domain.OrderItem;
import com.cyl.pay.domain.PayOrder;
import com.cyl.pay.pojo.vo.PayOrderVO;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.domain.BaseAudit; import com.ruoyi.common.core.domain.BaseAudit;
@ -102,4 +107,6 @@ public class OrderVO extends BaseAudit {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "确认收货时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") @Excel(name = "确认收货时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime receiveTime; private LocalDateTime receiveTime;
private List<OrderItem> items;
private PayOrderVO payOrder;
} }

@ -2,11 +2,33 @@ package com.cyl.oms.service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Map;
import java.util.stream.Collectors;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cyl.h5.pojo.vo.form.OrderSubmitForm;
import com.cyl.oms.convert.OrderConvert;
import com.cyl.oms.domain.OrderItem;
import com.cyl.oms.mapper.OrderItemMapper;
import com.cyl.oms.pojo.vo.OrderVO;
import com.cyl.pms.domain.Product;
import com.cyl.pms.domain.Sku;
import com.cyl.pms.mapper.ProductMapper;
import com.cyl.pms.mapper.SkuMapper;
import com.cyl.ums.domain.MemberAddress;
import com.cyl.ums.mapper.MemberAddressMapper;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -25,6 +47,16 @@ import com.cyl.oms.pojo.query.OrderQuery;
public class OrderService { public class OrderService {
@Autowired @Autowired
private OrderMapper orderMapper; private OrderMapper orderMapper;
@Autowired
private OrderConvert orderConvert;
@Autowired
private OrderItemMapper orderItemMapper;
@Autowired
private MemberAddressMapper memberAddressMapper;
@Autowired
private SkuMapper skuMapper;
@Autowired
private ProductMapper productMapper;
/** /**
* *
@ -193,4 +225,73 @@ public class OrderService {
public int deleteById(Long id) { public int deleteById(Long id) {
return orderMapper.deleteById(id); return orderMapper.deleteById(id);
} }
public OrderVO submit(OrderSubmitForm form) {
MemberAddress addr = memberAddressMapper.selectById(form.getAddressId());
if (addr == null) {
throw new BaseException("参数错误");
}
List<Long> skuIds = form.getSkus().stream().map(OrderSubmitForm.SkuParam::getSkuId).distinct().collect(Collectors.toList());
List<Sku> skus = skuMapper.selectBatchIds(skuIds);
if (skuIds.size() != skus.size()) {
throw new BaseException("参数错误");
}
Map<Long, Sku> id2sku = skus.stream().collect(Collectors.toMap(Sku::getId, it -> it));
Map<Long, Product> id2Product = productMapper.selectBatchIds(
skus.stream().map(Sku::getProductId).distinct().collect(Collectors.toList())
).stream().collect(Collectors.toMap(Product::getId, it -> it));
// 1. 生成订单商品快照
Order order = new Order();
order.setTotalAmount(BigDecimal.ZERO);
List<OrderItem> items = new ArrayList<>();
form.getSkus().forEach(it -> {
Sku s = id2sku.get(it.getSkuId());
Product p = id2Product.get(s.getProductId());
OrderItem item = new OrderItem();
item.setProductId(s.getProductId());
item.setOutProductId(p.getOutProductId());
item.setSkuId(it.getSkuId());
item.setOutSkuId(s.getOutSkuId());
item.setProductSnapshotId(p.getId());
item.setSkuSnapshotId(s.getId());
item.setPic(StrUtil.isNotEmpty(s.getPic()) ? s.getPic() : p.getPic());
item.setProductName(p.getName());
item.setSalePrice(s.getPrice());
item.setQuantity(it.getQuantity());
item.setProductCategoryId(p.getCategoryId());
item.setSpData(s.getSpData());
items.add(item);
order.setTotalAmount(order.getTotalAmount().add(s.getPrice().multiply(BigDecimal.valueOf(it.getQuantity()))));
});
LoginUser user = SecurityUtils.getLoginUser();
// 2. 生成订单
order.setMemberId(user.getUserId());
order.setMemberUsername(user.getUsername());
order.setStatus(0);
order.setAftersaleStatus(1);
order.setAutoConfirmDay(7);
order.setReceiverName(addr.getName());
order.setReceiverPhone(addr.getPhone());
order.setReceiverProvince(addr.getProvince());
order.setReceiverDistrict(addr.getDistrict());
order.setReceiverDetailAddress(addr.getDetailAddress());
order.setNote(form.getNote());
order.setConfirmStatus(0);
order.setDeleteStatus(0);
orderMapper.insert(order);
items.forEach(it -> it.setOrderId(order.getId()));
items.forEach(orderItemMapper::insert);
// 3. 判断是否付费,生成支付订单
if (BigDecimal.ZERO.compareTo(order.getTotalAmount()) > 0) {
// todo 生成支付订单
}
OrderVO vo = orderConvert.do2vo(order);
vo.setItems(items);
return vo;
}
} }

@ -0,0 +1,4 @@
package com.cyl.pay.domain;
public class PayOrder {
}

@ -0,0 +1,4 @@
package com.cyl.pay.pojo.vo;
public class PayOrderVO {
}

@ -18,4 +18,6 @@ public interface MemberAddressMapper extends BaseMapper<MemberAddress> {
* @return * @return
*/ */
List<MemberAddress> selectByEntity(MemberAddress memberAddress); List<MemberAddress> selectByEntity(MemberAddress memberAddress);
int updateByPrimaryKeySelective(MemberAddress address);
} }

@ -1,22 +1,23 @@
package com.cyl.ums.service; package com.cyl.ums.service;
import java.util.Arrays; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import java.util.List;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cyl.ums.domain.MemberAddress;
import com.cyl.ums.mapper.MemberAddressMapper;
import com.cyl.ums.pojo.query.MemberAddressQuery;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.SecurityUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.cyl.ums.mapper.MemberAddressMapper;
import com.cyl.ums.domain.MemberAddress; import java.time.LocalDateTime;
import com.cyl.ums.pojo.query.MemberAddressQuery; import java.util.List;
/** /**
* Service * Service
* *
*
* @author zcc * @author zcc
*/ */
@Service @Service
@ -38,7 +39,7 @@ public class MemberAddressService {
* *
* *
* @param query * @param query
* @param page * @param page
* @return * @return
*/ */
public List<MemberAddress> selectList(MemberAddressQuery query, Pageable page) { public List<MemberAddress> selectList(MemberAddressQuery query, Pageable page) {
@ -119,4 +120,22 @@ public class MemberAddressService {
public int deleteById(Long id) { public int deleteById(Long id) {
return memberAddressMapper.deleteById(id); return memberAddressMapper.deleteById(id);
} }
public Integer deleteUserIds(List<Long> ids) {
LambdaQueryWrapper<MemberAddress> qw = new LambdaQueryWrapper<>();
qw.eq(MemberAddress::getMemberId, SecurityUtils.getUserId());
qw.in(MemberAddress::getId, ids);
return memberAddressMapper.delete(qw);
}
public MemberAddress selectByUserAndId(Long id) {
LambdaQueryWrapper<MemberAddress> qw = new LambdaQueryWrapper<>();
qw.eq(MemberAddress::getMemberId, SecurityUtils.getUserId());
qw.eq(MemberAddress::getId, id);
return memberAddressMapper.selectOne(qw);
}
public int updateSelective(MemberAddress address) {
return memberAddressMapper.updateByPrimaryKeySelective(address);
}
} }

@ -45,4 +45,53 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="isDefault != null "> and is_default = #{isDefault}</if> <if test="isDefault != null "> and is_default = #{isDefault}</if>
</where> </where>
</select> </select>
<update id="updateByPrimaryKeySelective" parameterType="MemberAddress">
update ums_member_address
<set>
<if test="memberId != null">
member_id = #{memberId, jdbcType=BIGINT},
</if>
<if test="name != null">
name = #{name, jdbcType=BIGINT},
</if>
<if test="phone != null">
phone = #{phone, jdbcType=BIGINT},
</if>
<if test="defaultStatus != null">
default_status = #{defaultStatus, jdbcType=BIGINT},
</if>
<if test="postCode != null">
post_code = #{postCode, jdbcType=BIGINT},
</if>
<if test="province != null">
province = #{province, jdbcType=BIGINT},
</if>
<if test="city != null">
city = #{city, jdbcType=BIGINT},
</if>
<if test="district != null">
district = #{district, jdbcType=BIGINT},
</if>
<if test="detailAddress != null">
detail_address = #{detailAddress, jdbcType=BIGINT},
</if>
<if test="isDefault != null">
is_default = #{isDefault, jdbcType=BIGINT},
</if>
<if test="createBy != null">
create_by = #{createBy, jdbcType=BIGINT},
</if>
<if test="createTime != null">
create_time = #{createTime, jdbcType=BIGINT},
</if>
<if test="updateBy != null">
update_by = #{updateBy, jdbcType=BIGINT},
</if>
<if test="updateTime != null">
update_time = #{updateTime, jdbcType=BIGINT},
</if>
</set>
where id = #{id, jdbcType=BIGINT}
</update>
</mapper> </mapper>

Loading…
Cancel
Save