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

避免用户绑定本地生活用户后,token中数据未能更新,导致不能同步抽奖次数

wangzhijun 6 дней назад
Родитель
Сommit
c3c9ab0ebd

+ 17 - 6
nightFragrance-massage/src/main/java/com/ylx/massage/service/impl/TCommentUserServiceImpl.java

@@ -14,11 +14,13 @@ import com.ylx.lottery.service.LotteryCountService;
 import com.ylx.massage.domain.CommentUserAudit;
 import com.ylx.massage.domain.CommentUserAudit;
 import com.ylx.massage.domain.TCommentUser;
 import com.ylx.massage.domain.TCommentUser;
 import com.ylx.massage.domain.TOrder;
 import com.ylx.massage.domain.TOrder;
+import com.ylx.massage.domain.TWxUser;
 import com.ylx.massage.enums.OrderStatusEnum;
 import com.ylx.massage.enums.OrderStatusEnum;
 import com.ylx.massage.mapper.TCommentUserMapper;
 import com.ylx.massage.mapper.TCommentUserMapper;
 import com.ylx.massage.service.TCommentUserAuditService;
 import com.ylx.massage.service.TCommentUserAuditService;
 import com.ylx.massage.service.TCommentUserService;
 import com.ylx.massage.service.TCommentUserService;
 import com.ylx.massage.service.TOrderService;
 import com.ylx.massage.service.TOrderService;
+import com.ylx.massage.service.TWxUserService;
 import com.ylx.point.domain.dto.ApiAddPointsDTO;
 import com.ylx.point.domain.dto.ApiAddPointsDTO;
 import com.ylx.point.service.IPointAccountService;
 import com.ylx.point.service.IPointAccountService;
 import com.ylx.usercenter.domain.dto.UnifiedUserCenterDTO;
 import com.ylx.usercenter.domain.dto.UnifiedUserCenterDTO;
@@ -59,6 +61,8 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
     private UnifiedUserCenterService unifiedUserCenterService;
     private UnifiedUserCenterService unifiedUserCenterService;
     @Resource
     @Resource
     private IPointAccountService pointAccountService;
     private IPointAccountService pointAccountService;
+    @Resource
+    private TWxUserService wxUserService;
 
 
     @Override
     @Override
     @Transactional(rollbackFor = Exception.class)
     @Transactional(rollbackFor = Exception.class)
@@ -114,7 +118,7 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
         grantLotteryCountForComment(wxLoginUser);
         grantLotteryCountForComment(wxLoginUser);
 
 
         // 已绑定一账通 → 异步同步抽奖次数
         // 已绑定一账通 → 异步同步抽奖次数
-        syncLotteryCountIfNeeded(wxLoginUser);
+        syncLotteryCountIfNeeded(wxLoginUser.getId());
 
 
         return true;
         return true;
     }
     }
@@ -188,13 +192,20 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
         lotteryCountLogService.save(log);
         lotteryCountLogService.save(log);
     }
     }
 
 
-    private void syncLotteryCountIfNeeded(WxLoginUser wxLoginUser) {
-        if (ObjectUtil.equals(wxLoginUser.getIsBind(), 1)
-                && StringUtils.isNotBlank(wxLoginUser.getLocalLiveUserId())) {
+    private void syncLotteryCountIfNeeded(String id) {
+
+        // 避免用户绑定本地生活用户后,token中数据未能更新,导致不能同步抽奖次数
+        TWxUser user = this.wxUserService.getById(id);
+        if (ObjectUtil.isNull(user)) {
+            throw new ServiceException("用户不存在");
+        }
+
+        if (ObjectUtil.equals(user.getIsBind(), 1)
+                && StringUtils.isNotBlank(user.getLocalLiveUserId())) {
 
 
             UnifiedUserCenterDTO dto = new UnifiedUserCenterDTO();
             UnifiedUserCenterDTO dto = new UnifiedUserCenterDTO();
-            dto.setSourceUserId(wxLoginUser.getLocalLiveUserId());
-            dto.setTargetUserId(wxLoginUser.getId());
+            dto.setSourceUserId(user.getLocalLiveUserId());
+            dto.setTargetUserId(user.getId());
 
 
             // 👇 加上这个 if 判断,只有当当前存在活跃事务时,才去注册 afterCommit 回调
             // 👇 加上这个 if 判断,只有当当前存在活跃事务时,才去注册 afterCommit 回调
             if (TransactionSynchronizationManager.isSynchronizationActive()) {
             if (TransactionSynchronizationManager.isSynchronizationActive()) {

+ 9 - 2
nightFragrance-massage/src/main/java/com/ylx/massage/service/impl/TOrderServiceImpl.java

@@ -755,7 +755,7 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
         grantLotteryCountForPay(user, orderNew);
         grantLotteryCountForPay(user, orderNew);
 
 
         // 已绑定一账通 → 异步同步抽奖次数
         // 已绑定一账通 → 异步同步抽奖次数
-        syncLotteryCountIfNeeded(user);
+        syncLotteryCountIfNeeded(user.getId());
     }
     }
 
 
     /**
     /**
@@ -1568,7 +1568,14 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
         }
         }
     }
     }
 
 
-    private void syncLotteryCountIfNeeded(TWxUser user) {
+    private void syncLotteryCountIfNeeded(String id) {
+
+        // 避免用户绑定本地生活用户后,token中数据未能更新,导致不能同步抽奖次数
+        TWxUser user = this.wxUserService.getById(id);
+        if (ObjectUtil.isNull(user)) {
+            throw new ServiceException("用户不存在");
+        }
+
         if (ObjectUtil.equals(user.getIsBind(), 1) && com.ylx.common.utils.StringUtils.isNotBlank(user.getLocalLiveUserId())) {
         if (ObjectUtil.equals(user.getIsBind(), 1) && com.ylx.common.utils.StringUtils.isNotBlank(user.getLocalLiveUserId())) {
 
 
             UnifiedUserCenterDTO dto = new UnifiedUserCenterDTO();
             UnifiedUserCenterDTO dto = new UnifiedUserCenterDTO();