Explorar el Código

feature: 成团次数达到活法设置次数时下架

liufeng hace 1 año
padre
commit
c300b1f018

+ 11 - 0
mp-service/src/main/java/com/qs/mp/framework/service/impl/AsyncTaskServiceImpl.java

@@ -228,6 +228,17 @@ public class AsyncTaskServiceImpl extends ServiceImpl<AsyncTaskMapper, AsyncTask
                 groupBuyingGroup.setGroupStatus(GroupingStatusEnum.END.getValue());
             }
             groupBuyingGroupService.updateById(groupBuyingGroup);
+            int complete =  groupBuying.getCompleteGroupTimes();
+            int count = groupBuyingGroupService.count(new LambdaQueryWrapper<GroupBuyingGroup>()
+                .eq(GroupBuyingGroup::getGroupStatus,GroupingStatusEnum.END.getValue())
+                .eq(GroupBuyingGroup::getGroupbuyingId,groupBuying.getId())
+                .eq(GroupBuyingGroup::getIsDelete,0)
+            );
+            // 已达到最大拼团次数,下架该活动
+            if(complete == count){
+                groupBuying.setIsPutaway(1);
+                groupBuyingService.updateById(groupBuying);
+            }
         }
         // 用户关系绑定
         channelUserRelService.bindUser(buyingOrder.getUserId(), buyingOrder.getChannelId());

+ 56 - 23
mp-service/src/main/java/com/qs/mp/user/service/impl/UserGroupOrderServiceImpl.java

@@ -4,8 +4,9 @@ import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.qs.mp.admin.domain.TicketBox;
+import com.qs.mp.admin.domain.*;
 import com.qs.mp.admin.domain.vo.*;
 import com.qs.mp.admin.service.*;
 import com.qs.mp.channel.domain.*;
@@ -18,6 +19,9 @@ import com.qs.mp.common.enums.*;
 import com.qs.mp.common.exception.ServiceException;
 import com.qs.mp.common.utils.DateUtils;
 import com.qs.mp.common.utils.LogUtil;
+import com.qs.mp.common.utils.RSAUtil;
+import com.qs.mp.common.utils.StringUtils;
+import com.qs.mp.framework.redis.RedisKey;
 import com.qs.mp.framework.redis.RedisLockKey;
 import com.qs.mp.framework.service.IAsyncTaskService;
 import com.qs.mp.pay.domain.PayOrder;
@@ -96,6 +100,16 @@ public class UserGroupOrderServiceImpl extends
     private IChannelMoneyLogService channelMoneyLogService;
     @Autowired
     private IChannelCommissionService channelCommissionService;
+    @Autowired
+    private IGroupBuyingAwardsPrizeService groupBuyingAwardsPrizeService;
+    @Autowired
+    private IGoodsService goodsService;
+    @Autowired
+    private IUserPrizeStorageService userPrizeStorageService;
+    @Autowired
+    private ICouponService couponService;
+    @Autowired
+    private ICouponPkgService couponPkgService;
 
 
     @Override
@@ -289,11 +303,11 @@ public class UserGroupOrderServiceImpl extends
         save(groupBuyingOrder);
 
 
-//        if (orderSettleVO.getPayAmt() == 0) {
+//        if (orderSettleVO.getOrderAmt() == 0) {
 //            // 无需支付的,直接置为成功
 //            processTicketOrder(userTicketOrder);
 //            // 插入付款异步任务
-//            Assert.isTrue(asyncTaskService.insertAsyncTask(AsyncTaskTypeEnum.TICKET_PAY, userTicketOrder.getOrderId()),
+//            Assert.isTrue(asyncTaskService.insertAsyncTask(AsyncTaskTypeEnum.TICKET_PAY, orderSettleVO.getOrderId()),
 //                    "盲票支付,创建异步任务失败:" + userTicketOrder.getOrderId());
 //        }
 
@@ -325,9 +339,8 @@ public class UserGroupOrderServiceImpl extends
         // 插入异步任务
         Assert.isTrue(asyncTaskService.insertAsyncTask(AsyncTaskTypeEnum.TICKET_PAY, payOrder.getBizId()),
                 "创建支付成功异步任务失败. orderId:" + payOrder.getOrderId());
-        //todo 处理开团发奖逻辑
-        //return processTicketOrder(ticketOrder);
-        return true;
+        return processTicketOrder(buyingOrder);
+
     }
 
     /**
@@ -458,23 +471,6 @@ public class UserGroupOrderServiceImpl extends
         channelMoneyLogService.changeMoney(moneyLog);
     }
 
-    private ChannelCommission saveSiteCommAmt(ChannelCommParam channelCommParam, TicketBox ticketBox,
-                                              Channel channel, int sumCommAmt) {
-        ChannelCommission siteCommission = new ChannelCommission();
-        siteCommission.setChannelId(channel.getChannelId());
-        siteCommission.setOrderId(channelCommParam.getOrderId());
-        siteCommission.setBoxId(channelCommParam.getBoxId());
-        siteCommission.setSaleAmt(channelCommParam.getPayAmt());
-        siteCommission.setSaleCommRate(ticketBox.getSaleCommRate());
-        siteCommission.setSaleCommAmt(new BigDecimal(siteCommission.getSaleAmt()).multiply(
-                siteCommission.getSaleCommRate()).divide(new BigDecimal(100), 0, RoundingMode.DOWN)
-                .intValue());
-        siteCommission.setCommRate(channel.getCommRate());
-        siteCommission.setCommAmt(new BigDecimal(siteCommission.getSaleCommAmt()).multiply(
-                siteCommission.getCommRate()).divide(new BigDecimal(100), 0, RoundingMode.DOWN).intValue() - sumCommAmt);
-        channelCommissionService.save(siteCommission);
-        return siteCommission;
-    }
 
     private ChannelCommission saveSiteCommAmt(ChannelCommParam channelCommParam, GroupBuyingOrder groupBuyingOrder,
                                               Channel channel, int sumCommAmt) {
@@ -493,4 +489,41 @@ public class UserGroupOrderServiceImpl extends
         channelCommissionService.save(siteCommission);
         return siteCommission;
     }
+    private boolean processTicketOrder(GroupBuyingOrder groupBuyingOrder) {
+        List<GroupBuyingOrder> orders =list(new LambdaQueryWrapper<GroupBuyingOrder>()
+                .eq(GroupBuyingOrder::getGroupId,groupBuyingOrder.getGroupId()));
+        // 更新订单状态为已完成
+        boolean updateRst = update(
+                new LambdaUpdateWrapper<GroupBuyingOrder>().set(GroupBuyingOrder::getStatus,
+                        UserTicketOrderStatusEnum.FINISHED)
+                        .eq(GroupBuyingOrder::getStatus, UserTicketOrderStatusEnum.NOT_PAY)
+                        .eq(GroupBuyingOrder::getGroupbuyingId,groupBuyingOrder.getGroupbuyingId())
+                        .eq(GroupBuyingOrder::getGroupId,groupBuyingOrder.getGroupId())
+                );
+        Assert.isTrue(updateRst, "支付回调用户拼团订单处理,更新订单状态失败,orderId:" + groupBuyingOrder.getOrderId());
+
+        // 先更新订单状态再发放关联商品
+        GroupBuyingAwardsPrize groupBuyingAwardsPrize = groupBuyingAwardsPrizeService.getOne(new LambdaQueryWrapper<GroupBuyingAwardsPrize>()
+                .eq(GroupBuyingAwardsPrize::getIsDelete,0)
+                .eq(GroupBuyingAwardsPrize::getGroupbuyingId,groupBuyingOrder.getGroupbuyingId())
+        );
+        if(null == groupBuyingAwardsPrize){
+            LogUtil.info(logger, "未查到活动奖品。groupbuyingId:{0}", groupBuyingOrder.getGroupbuyingId());
+        }else {
+            Goods goods = goodsService.getById(Long.valueOf(groupBuyingAwardsPrize.getRefId()));
+            for (GroupBuyingOrder order : orders) {
+                if (TicketBoxGoodsTypeEnum.GOODS.equals(groupBuyingAwardsPrize.getPrizeType())) {
+                    userPrizeStorageService.takeInStorage(order.getUserId(),goods.getTitle(),goods.getPicUrl(),
+                           String.valueOf(goods.getGoodsId()) ,PrizeStorageInTypeEnum.TICKET_GOODS,groupBuyingAwardsPrize.getRefId());
+               }
+//                else if (TicketBoxGoodsTypeEnum.COUPON.equals(groupBuyingAwardsPrize.getPrizeType())) {
+//                    couponService.distribute(ticket, orderItem.getUserId(), ticketBoxGoods.getRefId());
+//                } else if (TicketBoxGoodsTypeEnum.COUPON_PKG.equals(groupBuyingAwardsPrize.getPrizeType())) {
+//                    couponPkgService.distribute(ticket, orderItem.getUserId(), ticketBoxGoods.getRefId());
+//                }
+            }
+        }
+        return true;
+    }
+
 }