Просмотр исходного кода

:bug: 判断是否开启分销,解决微信模板消息发送失败重复计算积分和佣金的问题

Twelve615 1 год назад
Родитель
Сommit
676a4c437e

+ 33 - 19
crmeb-service/src/main/java/com/zbkj/service/service/impl/OrderTaskServiceImpl.java

@@ -446,7 +446,7 @@ public class OrderTaskServiceImpl implements OrderTaskService {
             }
             try {
                 Boolean result = payService.payAfterProcessingTemp(String.valueOf(data));
-//                Boolean result = payService.payAfterProcessing(String.valueOf(data));
+                //Boolean result = payService.payAfterProcessing(String.valueOf(data));
                 if (!result) {
                     redisUtil.lPush(redisKey, data);
                 }
@@ -623,24 +623,31 @@ public class OrderTaskServiceImpl implements OrderTaskService {
             return Boolean.FALSE;
         }
         User user = userService.getById(order.getUid());
-        // 获取佣金记录
-        List<UserBrokerageRecord> recordList = userBrokerageRecordService.findListByLinkNoAndLinkType(orderNo, BrokerageRecordConstants.BROKERAGE_RECORD_LINK_TYPE_ORDER);
-        logger.info("收货处理佣金条数:" + recordList.size());
-        for (UserBrokerageRecord record : recordList) {
-            if (!record.getStatus().equals(BrokerageRecordConstants.BROKERAGE_RECORD_STATUS_CREATE)) {
-                throw new CrmebException(StrUtil.format("订单收货task处理,订单佣金记录不是创建状态,orderNo={}", orderNo));
-            }
-            // 佣金进入冻结期
-            record.setStatus(BrokerageRecordConstants.BROKERAGE_RECORD_STATUS_FROZEN);
-            // 计算解冻时间
-            long thawTime = DateUtil.current(false);
-            if (record.getFrozenTime() > 0) {
-                DateTime dateTime = DateUtil.offsetDay(new Date(), record.getFrozenTime());
-                thawTime = dateTime.getTime();
+        // 分销
+        List<UserBrokerageRecord> recordList = null;
+        String isOpen = systemConfigService.getValueByKey(SysConfigConstants.RETAIL_STORE_SWITCH);
+        if (StrUtil.isNotBlank(isOpen) && Constants.COMMON_SWITCH_OPEN.equals(isOpen)) {
+            // 开启分销功能
+            // 获取佣金记录
+            recordList = userBrokerageRecordService.findListByLinkNoAndLinkType(orderNo, BrokerageRecordConstants.BROKERAGE_RECORD_LINK_TYPE_ORDER);
+            logger.info("收货处理佣金条数:" + recordList.size());
+            for (UserBrokerageRecord record : recordList) {
+                if (!record.getStatus().equals(BrokerageRecordConstants.BROKERAGE_RECORD_STATUS_CREATE)) {
+                    throw new CrmebException(StrUtil.format("订单收货task处理,订单佣金记录不是创建状态,orderNo={}", orderNo));
+                }
+                // 佣金进入冻结期
+                record.setStatus(BrokerageRecordConstants.BROKERAGE_RECORD_STATUS_FROZEN);
+                // 计算解冻时间
+                long thawTime = DateUtil.current(false);
+                if (record.getFrozenTime() > 0) {
+                    DateTime dateTime = DateUtil.offsetDay(new Date(), record.getFrozenTime());
+                    thawTime = dateTime.getTime();
+                }
+                record.setThawTime(thawTime);
             }
-            record.setThawTime(thawTime);
         }
 
+
         // 获取积分记录
         List<UserIntegralRecord> integralRecordList = userIntegralRecordService.findListByOrderNoAndUid(orderNo, order.getUid());
         logger.info("收货处理积分条数:" + integralRecordList.size());
@@ -660,12 +667,13 @@ public class OrderTaskServiceImpl implements OrderTaskService {
             record.setThawTime(thawTime);
         }
 
+        List<UserBrokerageRecord> finalRecordList = recordList;
         Boolean execute = transactionTemplate.execute(e -> {
             // 日志
             orderStatusService.createLog(order.getOrderNo(), OrderStatusConstants.ORDER_STATUS_USER_TAKE_DELIVERY, OrderStatusConstants.ORDER_LOG_MESSAGE_TAKE);
             // 分佣-佣金进入冻结期
-            if (CollUtil.isNotEmpty(recordList)) {
-                userBrokerageRecordService.updateBatchById(recordList);
+            if (CollUtil.isNotEmpty(finalRecordList)) {
+                userBrokerageRecordService.updateBatchById(finalRecordList);
             }
             // 积分进入冻结期
             if (CollUtil.isNotEmpty(userIntegralRecordList)) {
@@ -675,7 +683,13 @@ public class OrderTaskServiceImpl implements OrderTaskService {
         });
         if (execute) {
             // 发送消息 确认收获通知
-            pushMessageOrder(order, user);
+            try {
+                pushMessageOrder(order, user);
+            } catch (Exception e) {
+                // 防止将订单号再次放入redis定时器重复计算佣金积分,这里捕捉异常并不抛出
+                logger.error("收获后续处理发送模板消息失败,{}", e.getMessage());
+                e.printStackTrace();
+            }
         }
         return execute;
     }

+ 9 - 1
crmeb-service/src/main/java/com/zbkj/service/service/impl/PayServiceImpl.java

@@ -825,11 +825,14 @@ public class PayServiceImpl implements PayService {
             throw new CrmebException("商户订单信息不存在,orderNo: " + orderNo);
         }
         List<UserIntegralRecord> integralList = CollUtil.newArrayList();
+        // 用户佣金记录
         List<UserBrokerageRecord> brokerageRecordList = CollUtil.newArrayList();
         List<OrderProfitSharing> profitSharingList = CollUtil.newArrayList();
         List<MerchantBill> merchantBillList = CollUtil.newArrayList();
         List<Bill> billList = CollUtil.newArrayList();
+        // 商户订单
         List<MerchantOrder> merchantOrderList = CollUtil.newArrayList();
+        // 订单详情
         List<OrderDetail> orderDetailList = CollUtil.newArrayList();
 
         for (Order order : orderList) {
@@ -903,7 +906,12 @@ public class PayServiceImpl implements PayService {
             }
             if (payNotification.getIsWechat().equals(1) || payNotification.getIsRoutine().equals(1)) {
                 //下发模板通知
-                pushMessageOrder(platOrder, user, payNotification);
+                // fixme: 此处微信模板消息发送失败导致抛出异常将订单号重新放回队列重复以上操作产生重复佣金与积分
+                try {
+                    pushMessageOrder(platOrder, user, payNotification);
+                } catch (Exception e) {
+                    logger.error("发送通知失败:{}",e.getMessage());
+                }
             }
 
             // 购买成功后根据配置送优惠券