Переглянути джерело

feat:调整发送红包奖励余额判断(fby)

caoliqin 1 місяць тому
батько
коміт
6aab77114d

+ 50 - 49
fs-service/src/main/java/com/fs/course/service/impl/FsUserCourseVideoServiceImpl.java

@@ -1595,50 +1595,50 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
         //2025.6.19 红包金额为0的时候
         if (amount.compareTo(BigDecimal.ZERO)>0){
 
-            Company company = companyMapper.selectCompanyById(param.getCompanyId());
-            BigDecimal money = company.getMoney();
-            if (money.compareTo(BigDecimal.ZERO)<=0) {
-                return R.error("服务商余额不足,请联系群主服务器充值!");
-            }
-
-            // 发送红包
-            R sendRedPacket = paymentService.sendRedPacket(packetParam);
-            if (sendRedPacket.get("code").equals(200)) {
-                FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
-                TransferBillsResult transferBillsResult;
-                if (sendRedPacket.get("isNew").equals(1)){
-                    transferBillsResult = (TransferBillsResult)sendRedPacket.get("data");
-                    redPacketLog.setResult(JSON.toJSONString(sendRedPacket));
-                    redPacketLog.setOutBatchNo(transferBillsResult.getOutBillNo());
-                    redPacketLog.setBatchId(transferBillsResult.getTransferBillNo());
-                }else {
-                    redPacketLog.setOutBatchNo(sendRedPacket.get("orderCode").toString());
-                    redPacketLog.setBatchId(sendRedPacket.get("batchId").toString());
-                }
-                // 添加红包记录
-                redPacketLog.setCourseId(param.getCourseId());
-                redPacketLog.setCompanyId(param.getCompanyId());
-                redPacketLog.setUserId(param.getUserId());
-                redPacketLog.setVideoId(param.getVideoId());
-                redPacketLog.setStatus(0);
-                redPacketLog.setQwUserId(param.getQwUserId() != null ? param.getQwUserId() : null);
-                redPacketLog.setCompanyUserId(param.getCompanyUserId());
-                redPacketLog.setCreateTime(new Date());
-                redPacketLog.setAmount(amount);
-                redPacketLog.setWatchLogId(log.getLogId() != null ? log.getLogId() : null);
-                redPacketLog.setPeriodId(param.getPeriodId());
-                redPacketLog.setAppId(param.getAppId());
-
-                redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
-
-                // 更新观看记录的奖励类型
-                log.setRewardType(config.getRewardType());
-                courseWatchLogMapper.updateFsCourseWatchLog(log);
-
-                return sendRedPacket;
-            } else {
-                return R.error("奖励发送失败,请联系客服");
-            }
+//            Company company = companyMapper.selectCompanyById(param.getCompanyId());
+//            BigDecimal money = company.getMoney();
+//            if (money.compareTo(BigDecimal.ZERO)<=0) {
+//                return R.error("服务商余额不足,请联系群主服务器充值!");
+//            }
+//
+//            // 发送红包
+//            R sendRedPacket = paymentService.sendRedPacket(packetParam);
+//            if (sendRedPacket.get("code").equals(200)) {
+//                FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
+//                TransferBillsResult transferBillsResult;
+//                if (sendRedPacket.get("isNew").equals(1)){
+//                    transferBillsResult = (TransferBillsResult)sendRedPacket.get("data");
+//                    redPacketLog.setResult(JSON.toJSONString(sendRedPacket));
+//                    redPacketLog.setOutBatchNo(transferBillsResult.getOutBillNo());
+//                    redPacketLog.setBatchId(transferBillsResult.getTransferBillNo());
+//                }else {
+//                    redPacketLog.setOutBatchNo(sendRedPacket.get("orderCode").toString());
+//                    redPacketLog.setBatchId(sendRedPacket.get("batchId").toString());
+//                }
+//                // 添加红包记录
+//                redPacketLog.setCourseId(param.getCourseId());
+//                redPacketLog.setCompanyId(param.getCompanyId());
+//                redPacketLog.setUserId(param.getUserId());
+//                redPacketLog.setVideoId(param.getVideoId());
+//                redPacketLog.setStatus(0);
+//                redPacketLog.setQwUserId(param.getQwUserId() != null ? param.getQwUserId() : null);
+//                redPacketLog.setCompanyUserId(param.getCompanyUserId());
+//                redPacketLog.setCreateTime(new Date());
+//                redPacketLog.setAmount(amount);
+//                redPacketLog.setWatchLogId(log.getLogId() != null ? log.getLogId() : null);
+//                redPacketLog.setPeriodId(param.getPeriodId());
+//                redPacketLog.setAppId(param.getAppId());
+//
+//                redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
+//
+//                // 更新观看记录的奖励类型
+//                log.setRewardType(config.getRewardType());
+//                courseWatchLogMapper.updateFsCourseWatchLog(log);
+//
+//                return sendRedPacket;
+//            } else {
+//                return R.error("奖励发送失败,请联系客服");
+//            }
 
             // 先注释 20251024 redis 余额 充值没有考虑 其余扣减没有考虑
             // ===================== 20251022 xgb 修改 本次修改目的为了实时扣减公司余额=====================
@@ -1648,7 +1648,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
 
 
             // 预设值异常对象
-            /*
+
             BalanceRollbackError balanceRollbackError = new BalanceRollbackError();
             balanceRollbackError.setCompanyId(packetParam.getCompanyId());
             balanceRollbackError.setUserId(user.getUserId());
@@ -1680,13 +1680,14 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
                         return R.error("系统异常,请稍后重试");
                     }
 
-                    if (originalMoney.compareTo(BigDecimal.ZERO) < 0) {
+                    // 预扣减金额
+                    BigDecimal newMoney = originalMoney.subtract(amount);
+
+                    if (originalMoney.compareTo(BigDecimal.ZERO) <= 0 || newMoney.compareTo(BigDecimal.ZERO) < 0) {
                         logger.error("服务商余额不足,异常请求参数{}",packetParam);
                         return R.error("服务商余额不足,请联系群主服务器充值!");
                     }
 
-                    // 预扣减金额
-                    BigDecimal newMoney = originalMoney.subtract(amount);
                     redisCache.setCacheObject(companyMoneyKey, newMoney.toString());
                 } else {
                     logger.error("获取redis锁失败,异常请求参数{}",packetParam);
@@ -1761,7 +1762,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
 //                rollbackBalance(balanceRollbackError);
                 return R.error("奖励发送失败,请联系客服");
             }
-             */
+
             // ===================== 本次修改目的为了实时扣减公司余额=====================
         } else {
             FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();