Procházet zdrojové kódy

盲豆转赠(bug修复)

zhangkaikai před 1 rokem
rodič
revize
011fadc5cc

+ 14 - 3
mp-service/src/main/java/com/qs/mp/user/service/impl/UserCoinServiceImpl.java

@@ -109,9 +109,20 @@ public class UserCoinServiceImpl extends ServiceImpl<UserCoinMapper, UserCoin> i
       Assert.isTrue(rtn1, "扣除转赠方盲豆失败, userId:" + coinTransferParamDTO.getFromUserId());
       // 增加受赠方盲豆
       UserCoin toUserCoin = getById(coinTransferParamDTO.getToUserId());
-      boolean rtn2 = update(new LambdaUpdateWrapper<UserCoin>().set(UserCoin::getCoin, toUserCoin.getCoin() + coinTransferParamDTO.getRealTransferCoin())
-              .eq(UserCoin::getUserId, coinTransferParamDTO.getToUserId()));
-      Assert.isTrue(rtn2, "增加受赠方盲豆失败,userId:" + coinTransferParamDTO.getToUserId());
+      if (toUserCoin == null) {
+        // 受赠方从未获得过盲豆
+        UserCoin toUserNoCoin = new UserCoin();
+        toUserNoCoin.setCoin(coinTransferParamDTO.getRealTransferCoin());
+        toUserNoCoin.setUserId(coinTransferParamDTO.getToUserId());
+        toUserNoCoin.setCreatedTime(new Date());
+        toUserNoCoin.setUpdatedTime(new Date());
+        boolean rtn2 = save(toUserNoCoin);
+        Assert.isTrue(rtn2, "从未获得过盲豆的用户转赠盲豆失败, userId:" + coinTransferParamDTO.getToUserId());
+      } else {
+        boolean rtn3 = update(new LambdaUpdateWrapper<UserCoin>().set(UserCoin::getCoin, toUserCoin.getCoin() + coinTransferParamDTO.getRealTransferCoin())
+                .eq(UserCoin::getUserId, coinTransferParamDTO.getToUserId()));
+        Assert.isTrue(rtn3, "增加受赠方盲豆失败,userId:" + coinTransferParamDTO.getToUserId());
+      }
 
       // 盲豆转赠日志
       List<UserCoinLog> userCoinLogList = new ArrayList<>();