|
|
@@ -1491,12 +1491,60 @@ 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("奖励发送失败,请联系客服");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 先注释 20251024 redis 余额 充值没有考虑 其余扣减没有考虑
|
|
|
// ===================== 20251022 xgb 修改 本次修改目的为了实时扣减公司余额=====================
|
|
|
// 1 使用redis缓存加锁 预扣减余额 红包发送失败 恢复redis缓存余额,如果回滚失败登记异常记录表 定时任务重新回滚余额
|
|
|
// 2 另起定时任务 同步缓存余额到redis中
|
|
|
// 3 启动系统时查询公司账户余额(这个时候要保证余额正确)保存到redis缓存中
|
|
|
|
|
|
+
|
|
|
// 预设值异常对象
|
|
|
+ /*
|
|
|
BalanceRollbackError balanceRollbackError = new BalanceRollbackError();
|
|
|
balanceRollbackError.setCompanyId(packetParam.getCompanyId());
|
|
|
balanceRollbackError.setUserId(user.getUserId());
|
|
|
@@ -1554,6 +1602,8 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
// 调用第三方接口(锁外操作)
|
|
|
R sendRedPacket;
|
|
|
try {
|
|
|
@@ -1562,7 +1612,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
logger.error("红包发送异常: 异常请求参数{}",packetParam, e);
|
|
|
// 异常时回滚余额
|
|
|
|
|
|
- rollbackBalance(balanceRollbackError);
|
|
|
+// rollbackBalance(balanceRollbackError);
|
|
|
return R.error("奖励发送失败,请联系客服");
|
|
|
}
|
|
|
|
|
|
@@ -1600,12 +1650,14 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
// 发送成功,记录日志等操作
|
|
|
return sendRedPacket;
|
|
|
+
|
|
|
+
|
|
|
} else {
|
|
|
// 发送失败,回滚余额
|
|
|
- rollbackBalance(balanceRollbackError);
|
|
|
+// rollbackBalance(balanceRollbackError);
|
|
|
return R.error("奖励发送失败,请联系客服");
|
|
|
}
|
|
|
-
|
|
|
+ */
|
|
|
// ===================== 本次修改目的为了实时扣减公司余额=====================
|
|
|
} else {
|
|
|
FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|