bug fix
This commit is contained in:
@@ -80,6 +80,8 @@ public class BuyOrderController {
|
||||
private ExpressFeeService expressFeeService;
|
||||
@Autowired
|
||||
private SysConfigService sysConfigService;
|
||||
@Autowired
|
||||
private BuyOrderProductService buyOrderProductService;
|
||||
|
||||
@RequestMapping(value = "/decomposeShipment", method = RequestMethod.GET)
|
||||
public R decomposeShipment(@RequestParam("userId") Integer userId) {
|
||||
@@ -103,8 +105,8 @@ public class BuyOrderController {
|
||||
*/
|
||||
@RequestMapping(path = "/orderList", method = RequestMethod.POST)
|
||||
public R orderList(@RequestBody BuyOrderListRequestVo requestVo) {
|
||||
List<BuyOrderResponseVo> page = buyOrderService.orderList(requestVo);
|
||||
return R.ok().put("result", page);
|
||||
Map<String, Object> result = buyOrderService.orderList(requestVo);
|
||||
return R.ok().put("result", result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,6 +123,7 @@ public class BuyOrderController {
|
||||
|
||||
/**
|
||||
* 下单
|
||||
* TODO 原下单接口,新版本上线后废弃
|
||||
*
|
||||
* @param buyOrder 订单
|
||||
* @return R
|
||||
@@ -210,6 +213,103 @@ public class BuyOrderController {
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下单
|
||||
*
|
||||
* @param buyOrder
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping(value = "placeOrder", method = RequestMethod.POST)
|
||||
public R placeOrder(@RequestBody BuyOrder buyOrder) throws IOException {
|
||||
List<BuyOrderProduct> buyOrderProductList = buyOrder.getProductInfoList();
|
||||
// 订单总金额
|
||||
BigDecimal totalPrice = new BigDecimal(0);
|
||||
// 遍历商品总价计算
|
||||
for (BuyOrderProduct buyOrderProduct : buyOrderProductList) {
|
||||
Integer productId = buyOrderProduct.getProductId();
|
||||
int quantity = buyOrderProduct.getQuantity();
|
||||
ShopProduct product = shopProductService.getById(productId);
|
||||
BigDecimal price = getRealPrice(product);
|
||||
if (!handleStock(buyOrderProduct, product)) {
|
||||
return R.error(500, "库存不足");
|
||||
}
|
||||
totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity)));
|
||||
//buyOrderDetail.setProductName(product.getProductName());
|
||||
//buyOrderDetail.setProductPrice(product.getPrice());
|
||||
int originWeight = product.getWeight();
|
||||
int originWeightIntValue = originWeight / 100;
|
||||
int originWeightDecimalValue = originWeightIntValue % 100;
|
||||
//buyOrderProduct.setWeight(BigDecimal.valueOf(originWeightIntValue).add(BigDecimal.valueOf(originWeightDecimalValue).divide(new BigDecimal(100),
|
||||
//MathContext.DECIMAL64)));
|
||||
// buyOrderDetail.setProductUrl(product.getProductImages());
|
||||
// buyOrderDetail.setOrderStatus(Constants.ORDER_STATUS_TO_BE_PAID);
|
||||
}
|
||||
|
||||
totalPrice = totalPrice.subtract(useCouponAmount(buyOrder));
|
||||
totalPrice = totalPrice.add(getShoppingAmount(buyOrder));
|
||||
String orderSn = IdWorker.getTimeId().substring(0, 32);
|
||||
buyOrder.setOrderSn(orderSn);
|
||||
buyOrder.setPaymentDate(new Date());
|
||||
QueryWrapper<UserAddress> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", buyOrder.getAddressId());
|
||||
UserAddress userAddress = userAddressService.getOne(queryWrapper);
|
||||
UserAddressVo vo = new UserAddressVo();
|
||||
vo = userAddressService.getAddressName(vo, userAddress.getRegionCode());
|
||||
buyOrder.setProvince(vo.getProvince());
|
||||
buyOrder.setCity(vo.getCity());
|
||||
buyOrder.setDistrict(vo.getCounty());
|
||||
buyOrder.setAddress(vo.getDetailAddress());
|
||||
buyOrderService.save(buyOrder);
|
||||
|
||||
for (BuyOrderProduct buyOrderDetail : buyOrderProductList) {
|
||||
buyOrderDetail.setOrderId(buyOrder.getOrderId());
|
||||
//buyOrderDetail.setUserId(buyOrder.getUserId());
|
||||
if (Constants.BUY_TYPE_CART.equals(buyOrder.getBuyType())) {
|
||||
handleBuyCart(buyOrder, buyOrderDetail);
|
||||
}
|
||||
}
|
||||
// buyOrderDetailService.saveBatch(buyOrderDetails);
|
||||
buyOrderProductService.saveBatch(buyOrderProductList);
|
||||
// 1. 虚拟币支付
|
||||
if (Constants.PAYMENT_METHOD_VIRTUAL.equals(buyOrder.getPaymentMethod())) {
|
||||
buyOrder.setOrderStatus(Constants.ORDER_STATUS_TO_BE_SHIPPED);
|
||||
MyUserEntity user = this.myUserService.getById(buyOrder.getUserId());
|
||||
if (usePeanutCoin(user, totalPrice)) {
|
||||
// 更新订单状态
|
||||
buyOrderService.updateOrderStatus(user.getId(), buyOrder.getOrderSn(), "0");
|
||||
recordTransaction(buyOrder, user, totalPrice);
|
||||
addEbookToUser(buyOrderProductList, buyOrder, 0);
|
||||
} else {
|
||||
return R.error(500, "花生币余额不足!");
|
||||
}
|
||||
}
|
||||
// 2. 微信支付
|
||||
if (Constants.PAYMENT_METHOD_WECHAT_PAY.equals(buyOrder.getPaymentMethod())) {
|
||||
rabbitTemplate.convertAndSend(
|
||||
DelayQueueConfig.ORDER_TO_BE_PAY_EXCHANGE,
|
||||
DelayQueueConfig.ORDER_TO_BE_PAY_ROUTING_KEY,
|
||||
buyOrder.getOrderId(),
|
||||
messagePostProcessor()
|
||||
);
|
||||
WechatPaymentInfo paymentInfo = new WechatPaymentInfo();
|
||||
paymentInfo.setOrderSn(orderSn);
|
||||
paymentInfo.setBuyOrderId(buyOrder.getOrderId());
|
||||
paymentInfo.setTotalAmount(totalPrice);
|
||||
wxpayService.prepay(paymentInfo);
|
||||
}
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("orderSn", buyOrder.getOrderSn());
|
||||
result.put("money", totalPrice);
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算运费
|
||||
*
|
||||
* @param vo
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(path = "/calculateTransportPrice", method = RequestMethod.POST)
|
||||
public R getTransportPrice(@RequestBody ProductTransportVo vo) {
|
||||
String regionCode = vo.getRegionCode();
|
||||
@@ -443,6 +543,7 @@ public class BuyOrderController {
|
||||
|
||||
/**
|
||||
* 处理商品库存
|
||||
* TODO 新版本上线后删除此方法
|
||||
*
|
||||
* @param buyOrderDetail
|
||||
* @param product
|
||||
@@ -459,6 +560,24 @@ public class BuyOrderController {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理商品库存
|
||||
*
|
||||
* @param buyOrderProduct 订单商品信息
|
||||
* @param product 商品
|
||||
* @return boolean
|
||||
*/
|
||||
private boolean handleStock(BuyOrderProduct buyOrderProduct, ShopProduct product) {
|
||||
int quantity = buyOrderProduct.getQuantity();
|
||||
if (product.getProductStock() - quantity < 0) {
|
||||
return false;
|
||||
}
|
||||
product.setProductStock(product.getProductStock() - quantity);
|
||||
product.setSumSales(product.getSumSales() + quantity);
|
||||
shopProductService.updateById(product);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用优惠券
|
||||
*
|
||||
@@ -543,8 +662,9 @@ public class BuyOrderController {
|
||||
|
||||
/**
|
||||
* 给用户添加电子书
|
||||
* TODO 新版本上线删除此接口
|
||||
* @param products
|
||||
*
|
||||
* @param products
|
||||
* @param buyOrder
|
||||
*/
|
||||
private void addEbookToUser(List<BuyOrderDetail> products, BuyOrder buyOrder) {
|
||||
@@ -557,8 +677,26 @@ public class BuyOrderController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 给用户添加电子书
|
||||
* TODO 这里的参数 0 没用 新版本上线后删除
|
||||
*
|
||||
* @param products
|
||||
* @param buyOrder
|
||||
*/
|
||||
private void addEbookToUser(List<BuyOrderProduct> products, BuyOrder buyOrder, Integer x) {
|
||||
List<Integer> productIds = products.stream().map(BuyOrderProduct::getProductId).collect(Collectors.toList());
|
||||
for (Integer productId : productIds) {
|
||||
List<Integer> collect = shopProductBookService.getBaseMapper().selectList(new LambdaQueryWrapper<ShopProductBookEntity>()
|
||||
.eq(ShopProductBookEntity::getProductId, productId)
|
||||
.eq(ShopProductBookEntity::getDelFlag, 0)).stream().map(ShopProductBookEntity::getBookId).collect(Collectors.toList());
|
||||
userEbookBuyService.addBookForUser(buyOrder.getUserId(), collect);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 购物车
|
||||
* TODO 新版本上线后删除此方法
|
||||
*
|
||||
* @param buyOrder
|
||||
* @param buyOrderDetail
|
||||
@@ -572,6 +710,21 @@ public class BuyOrderController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 购物车
|
||||
*
|
||||
* @param buyOrder 订单
|
||||
* @param buyOrderProduct
|
||||
*/
|
||||
private void handleBuyCart(BuyOrder buyOrder, BuyOrderProduct buyOrderProduct) {
|
||||
List<OrderCartEntity> orderCartList = orderCartService.getBaseMapper().selectList(new QueryWrapper<OrderCartEntity>()
|
||||
.eq("user_id", buyOrder.getUserId()).eq("product_id", buyOrderProduct.getProductId()));
|
||||
if (orderCartList.size() > 0) {
|
||||
List<Integer> collect = orderCartList.stream().map(OrderCartEntity::getCartId).collect(Collectors.toList());
|
||||
orderCartService.removeByIds(collect);
|
||||
}
|
||||
}
|
||||
|
||||
private MessagePostProcessor messagePostProcessor() {
|
||||
return message -> {
|
||||
//设置有效期30分钟
|
||||
|
||||
@@ -125,9 +125,13 @@ public class BuyOrder implements Serializable {
|
||||
@TableLogic
|
||||
private Integer delFlag;
|
||||
|
||||
// TODO 新版本上线后删除该属性
|
||||
@TableField(exist = false)
|
||||
private List<BuyOrderDetail> products;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<BuyOrderProduct> productInfoList;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String buyType;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public interface BuyOrderService extends IService<BuyOrder> {
|
||||
* @param requestVo
|
||||
* @return
|
||||
*/
|
||||
List<BuyOrderResponseVo> orderList(BuyOrderListRequestVo requestVo);
|
||||
Map<String,Object> orderList(BuyOrderListRequestVo requestVo);
|
||||
|
||||
/**
|
||||
* 订单拆分发货
|
||||
|
||||
@@ -305,20 +305,29 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BuyOrderResponseVo> orderList(BuyOrderListRequestVo requestVo) {
|
||||
public Map<String, Object> orderList(BuyOrderListRequestVo requestVo) {
|
||||
Page<BuyOrder> buyOrderPage = new Page<>(requestVo.getPageIndex(), requestVo.getPageSize());
|
||||
List<BuyOrderResponseVo> result = new ArrayList<>();
|
||||
List<BuyOrderResponseVo> data = new ArrayList<>();
|
||||
QueryWrapper<BuyOrder> buyOrderQueryWrapper = new QueryWrapper<>();
|
||||
buyOrderQueryWrapper.like(StringUtils.isNotBlank(requestVo.getSearchKeyWord()), "order_sn", requestVo.getSearchKeyWord());
|
||||
buyOrderQueryWrapper.eq(StringUtils.isNotBlank(requestVo.getOrderStatus()), "order_status", requestVo.getOrderStatus());
|
||||
buyOrderQueryWrapper.gt(requestVo.getStartTime() != null, "create_time", requestVo.getStartTime());
|
||||
buyOrderQueryWrapper.lt(requestVo.getEndTime() != null, "create_time", requestVo.getStartTime());
|
||||
|
||||
Integer totalSize = list(buyOrderQueryWrapper).size();
|
||||
Integer totalPage = totalSize / requestVo.getPageSize() + 1;
|
||||
Page<BuyOrder> page = page(buyOrderPage, buyOrderQueryWrapper);
|
||||
List<BuyOrder> buyOrderList = page.getRecords();
|
||||
for (BuyOrder buyOrder : buyOrderList) {
|
||||
BuyOrderResponseVo responseVo = setBuyOrderInfo(buyOrder);
|
||||
result.add(responseVo);
|
||||
data.add(responseVo);
|
||||
}
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("totalDataSize", totalSize);
|
||||
result.put("totalPage", totalPage);
|
||||
result.put("data", data);
|
||||
result.put("currentPage", requestVo.getPageIndex());
|
||||
result.put("pageSize", requestVo.getPageSize());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -382,17 +391,28 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
|
||||
return setBuyOrderInfo(buyOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置订单信息
|
||||
*
|
||||
* @param buyOrder
|
||||
* @return
|
||||
*/
|
||||
private BuyOrderResponseVo setBuyOrderInfo(BuyOrder buyOrder) {
|
||||
BuyOrderResponseVo responseVo = new BuyOrderResponseVo();
|
||||
Integer userId = buyOrder.getUserId();
|
||||
QueryWrapper<MyUserEntity> userEntityQueryWrapper = new QueryWrapper<>();
|
||||
userEntityQueryWrapper.eq("id", userId);
|
||||
MyUserEntity user = myUserService.getOne(userEntityQueryWrapper);
|
||||
UserResponseVo userResponseVo = new UserResponseVo();
|
||||
userResponseVo.setUserPhone(user.getTel());
|
||||
userResponseVo.setUserName(user.getName());
|
||||
responseVo.setUserInfo(userResponseVo);
|
||||
if (user != null) {
|
||||
UserResponseVo userResponseVo = new UserResponseVo();
|
||||
userResponseVo.setUserPhone(user.getTel());
|
||||
if (user.getName() != null) {
|
||||
userResponseVo.setUserName(user.getName());
|
||||
}
|
||||
responseVo.setUserInfo(userResponseVo);
|
||||
}
|
||||
responseVo.setOrderPrice(buyOrder.getOrderMoney());
|
||||
responseVo.setOrderType(buyOrder.getOrderType());
|
||||
BeanUtil.copyProperties(buyOrder, responseVo);
|
||||
ConsigneeVo consigneeVo = new ConsigneeVo();
|
||||
consigneeVo.setConsigneeName(buyOrder.getShippingUser());
|
||||
|
||||
@@ -65,4 +65,16 @@ public class BuyOrderResponseVo {
|
||||
* 用户信息
|
||||
*/
|
||||
private UserResponseVo userInfo;
|
||||
/**
|
||||
* 订单类型
|
||||
*/
|
||||
private String orderType;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
/**
|
||||
* 发货时间
|
||||
*/
|
||||
private Date shippingTime;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user