|
|
@@ -747,7 +747,7 @@ public class LifeUserOrderService extends ServiceImpl<LifeUserOrderMapper, LifeU
|
|
|
.eq("id", lifeUserOrderDto.getCouponId()).setSql("inventory_num = inventory_num - " + lifeUserOrderDto.getCount()));
|
|
|
} else {
|
|
|
successful = lifeCouponMapper.update(null, new UpdateWrapper<LifeCoupon>()
|
|
|
- .eq("id", lifeUserOrderDto.getCouponId()).setSql("stock_qty = stock_qty - " + lifeUserOrderDto.getCount()));
|
|
|
+ .eq("id", lifeUserOrderDto.getCouponId()).setSql("single_qty = single_qty - " + lifeUserOrderDto.getCount()));
|
|
|
}
|
|
|
if(successful == 0){
|
|
|
log.error("库存不足");
|
|
|
@@ -776,7 +776,6 @@ public class LifeUserOrderService extends ServiceImpl<LifeUserOrderMapper, LifeU
|
|
|
UpdateWrapper<OrderCouponMiddle> orderCouponMiddleUpdateWrapper = new UpdateWrapper<>();
|
|
|
orderCouponMiddleUpdateWrapper.eq("order_id",lifeUserOrderDto.getId());
|
|
|
// 根据状态判断怎么更新数据 目前只进行已支付,已取消,已过期判断
|
|
|
- // TODO 后续再进行已核销和已退款判断 ()
|
|
|
switch (lifeUserOrderDto.getStatus()){
|
|
|
case 1:
|
|
|
lifeUserOrder.setPayTime(date);
|
|
|
@@ -793,7 +792,31 @@ public class LifeUserOrderService extends ServiceImpl<LifeUserOrderMapper, LifeU
|
|
|
orderCouponMiddleUpdateWrapper.set("status",lifeUserOrderDto.getStatus());
|
|
|
break;
|
|
|
}
|
|
|
- return this.saveOrUpdate(lifeUserOrder) && orderCouponMiddleService.update(orderCouponMiddleUpdateWrapper);
|
|
|
+ // 查询券id->查询一个
|
|
|
+ int updateNum = orderCouponMiddleMapper.update(null, orderCouponMiddleUpdateWrapper);
|
|
|
+ if(1 != lifeUserOrderDto.getStatus()) {
|
|
|
+ List<OrderCouponMiddle> orderCouponMiddles = orderCouponMiddleMapper.selectList(new QueryWrapper<OrderCouponMiddle>().eq("order_id", lifeUserOrderDto.getId()));
|
|
|
+ if (0 != updateNum && orderCouponMiddles.size() > 0) {
|
|
|
+ Integer couponId = orderCouponMiddles.get(0).getCouponId();
|
|
|
+ // 2.过期后更新库存
|
|
|
+ if (1 == lifeUserOrder.getCouponType()) {
|
|
|
+ // 代金券
|
|
|
+ // 恢复库存
|
|
|
+ lifeCouponMapper.update(null, new LambdaUpdateWrapper<LifeCoupon>()
|
|
|
+ .setSql("single_qty=single_qty+" + updateNum)
|
|
|
+ .eq(LifeCoupon::getId, couponId));
|
|
|
+ } else {
|
|
|
+ // 团购
|
|
|
+ lifeGroupBuyMainMapper.update(null, new LambdaUpdateWrapper<LifeGroupBuyMain>()
|
|
|
+ .setSql("inventory_num=inventory_num+" + updateNum)
|
|
|
+ .eq(LifeGroupBuyMain::getId, couponId));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("取消失败,未查询到订单");
|
|
|
+ throw new RuntimeException("取消失败,未查询到订单");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return this.saveOrUpdate(lifeUserOrder);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1034,7 +1057,7 @@ public class LifeUserOrderService extends ServiceImpl<LifeUserOrderMapper, LifeU
|
|
|
LifeCoupon lifeCoupon = lifeCouponMapper.selectById(couponId);
|
|
|
status = lifeCoupon.getStatus();
|
|
|
// 限购数量
|
|
|
- buyLimit = Integer.parseInt(lifeCoupon.getPurchaseLimitCode());
|
|
|
+ buyLimit = lifeCoupon.getBuyLimit();
|
|
|
// 已购数量
|
|
|
buyCount = orderCouponMiddleMapper.selectCount(new QueryWrapper<OrderCouponMiddle>().eq("coupon_id", couponId).notIn("status", OrderStatusEnum.CANCEL.getStatus(), OrderStatusEnum.REFUND.getStatus())
|
|
|
.inSql("order_id", "select order_id from life_user_order where user_id = " + userId + " and store_id = " + storeId));
|