|
@@ -13,7 +13,11 @@ import com.fs.common.enums.BizResponseEnum;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.common.utils.date.DateUtil;
|
|
|
+import com.fs.company.domain.Company;
|
|
|
+import com.fs.company.domain.CompanyMoneyLogs;
|
|
|
import com.fs.company.domain.CompanyUser;
|
|
|
+import com.fs.company.mapper.CompanyMapper;
|
|
|
+import com.fs.company.mapper.CompanyMoneyLogsMapper;
|
|
|
import com.fs.company.mapper.CompanyUserMapper;
|
|
|
import com.fs.course.config.CourseConfig;
|
|
|
import com.fs.course.domain.*;
|
|
@@ -100,6 +104,8 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
@Autowired
|
|
|
private IFsUserService fsUserService;
|
|
|
@Autowired
|
|
|
+ private CompanyMapper companyMapper;
|
|
|
+ @Autowired
|
|
|
private FsUserCourseStudyLogMapper courseStudyLogMapper;
|
|
|
|
|
|
@Autowired
|
|
@@ -133,6 +139,8 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
@Autowired
|
|
|
private FsUserIntegralLogsMapper fsUserIntegralLogsMapper;
|
|
|
@Autowired
|
|
|
+ private CompanyMoneyLogsMapper moneyLogsMapper;
|
|
|
+ @Autowired
|
|
|
private FsUserMapper fsUserMapper;
|
|
|
@Autowired
|
|
|
private IFsStorePaymentService paymentService;
|
|
@@ -858,8 +866,31 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
packetParam.setUser(user);
|
|
|
}
|
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(config.getIsNegative())&&config.getIsNegative() == 1) {
|
|
|
+ return processRedPacket(config, packetParam, param, amount, log);
|
|
|
+ }
|
|
|
//2025.7.11 红包金额为0的时候
|
|
|
if (amount.compareTo(BigDecimal.ZERO)>0){
|
|
|
+
|
|
|
+ Company company = companyMapper.selectCompanyByIdForUpdate(param.getCompanyId());
|
|
|
+ BigDecimal money = company.getMoney();
|
|
|
+ BigDecimal subtract = money.subtract(amount);
|
|
|
+ if (subtract.compareTo(BigDecimal.ZERO)<0){
|
|
|
+ FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
|
+ redPacketLog.setCourseId(param.getCourseId());
|
|
|
+ redPacketLog.setCompanyId(param.getCompanyId());
|
|
|
+ redPacketLog.setUserId(param.getUserId());
|
|
|
+ redPacketLog.setVideoId(param.getVideoId());
|
|
|
+ redPacketLog.setStatus(2);
|
|
|
+ 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());
|
|
|
+ redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
+ return R.error("销售公司余额不足");
|
|
|
+ }
|
|
|
// 发送红包
|
|
|
R sendRedPacket = paymentService.sendRedPacket(packetParam);
|
|
|
if (sendRedPacket.get("code").equals(200)) {
|
|
@@ -1015,8 +1046,32 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
|
|
|
System.out.println("红包金额"+amount);
|
|
|
System.out.println("红包商户号"+packetParam);
|
|
|
+
|
|
|
+ if (ObjectUtils.isNotEmpty(config.getIsNegative())&&config.getIsNegative() == 1) {
|
|
|
+ return processRedPacket(config, packetParam, param, amount, log);
|
|
|
+ }
|
|
|
//2025.7.11 红包金额为0的时候
|
|
|
if (amount.compareTo(BigDecimal.ZERO)>0){
|
|
|
+
|
|
|
+ Company company = companyMapper.selectCompanyByIdForUpdate(param.getCompanyId());
|
|
|
+ BigDecimal money = company.getMoney();
|
|
|
+ BigDecimal subtract = money.subtract(amount);
|
|
|
+ if (subtract.compareTo(BigDecimal.ZERO)<0){
|
|
|
+ FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
|
+ redPacketLog.setCourseId(param.getCourseId());
|
|
|
+ redPacketLog.setCompanyId(param.getCompanyId());
|
|
|
+ redPacketLog.setUserId(param.getUserId());
|
|
|
+ redPacketLog.setVideoId(param.getVideoId());
|
|
|
+ redPacketLog.setStatus(2);
|
|
|
+ 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());
|
|
|
+ redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
+ return R.error("销售公司余额不足");
|
|
|
+ }
|
|
|
// 发送红包
|
|
|
R sendRedPacket = paymentService.sendRedPacket(packetParam);
|
|
|
if (sendRedPacket.get("code").equals(200)) {
|
|
@@ -1026,10 +1081,8 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
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());
|
|
@@ -1044,19 +1097,27 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
redPacketLog.setAmount(amount);
|
|
|
redPacketLog.setWatchLogId(log.getLogId() != null ? log.getLogId() : null);
|
|
|
redPacketLog.setPeriodId(param.getPeriodId());
|
|
|
-
|
|
|
redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
|
|
|
// 更新观看记录的奖励类型
|
|
|
-// if (param.getLinkType() == null || param.getLinkType() == 0) {
|
|
|
log.setRewardType(config.getRewardType());
|
|
|
courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
-// }
|
|
|
+ company.setMoney(subtract);
|
|
|
+ companyMapper.updateCompany(company);
|
|
|
+
|
|
|
+ CompanyMoneyLogs logs=new CompanyMoneyLogs();
|
|
|
+ logs.setCompanyId(company.getCompanyId());
|
|
|
+ logs.setRemark("扣除红包金额");
|
|
|
+ logs.setMoney(amount.multiply(new BigDecimal(-1)));
|
|
|
+ logs.setLogsType(15);
|
|
|
+ logs.setBalance(company.getMoney());
|
|
|
+ logs.setCreateTime(new Date());
|
|
|
+ moneyLogsMapper.insertCompanyMoneyLogs(logs);
|
|
|
+
|
|
|
return sendRedPacket;
|
|
|
} else {
|
|
|
return R.error("奖励发送失败,请联系客服");
|
|
|
}
|
|
|
-
|
|
|
} else {
|
|
|
// 发送红包
|
|
|
FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
@@ -1083,7 +1144,63 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 直接发送奖励
|
|
|
+ *
|
|
|
+ * @param config
|
|
|
+ * @param packetParam
|
|
|
+ * @param param
|
|
|
+ * @param amount
|
|
|
+ * @param log
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private R processRedPacket(CourseConfig config, WxSendRedPacketParam packetParam, FsCourseSendRewardUParam param, BigDecimal amount, FsCourseWatchLog log) {
|
|
|
+ R sendRedPacket = paymentService.sendRedPacket(packetParam);
|
|
|
+
|
|
|
+ if (!sendRedPacket.get("code").equals(200)) {
|
|
|
+ return R.error("奖励发送失败,请联系客服");
|
|
|
+ }
|
|
|
+
|
|
|
+ createRedPacketLog(sendRedPacket, param, amount, log);
|
|
|
+ updateWatchLogRewardType(log, config);
|
|
|
+
|
|
|
+ return sendRedPacket;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createRedPacketLog(R sendRedPacket, FsCourseSendRewardUParam param, BigDecimal amount, FsCourseWatchLog log) {
|
|
|
+ FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
|
+
|
|
|
+ // Set common fields
|
|
|
+ redPacketLog.setCourseId(param.getCourseId());
|
|
|
+ redPacketLog.setCompanyId(param.getCompanyId());
|
|
|
+ redPacketLog.setUserId(param.getUserId());
|
|
|
+ redPacketLog.setVideoId(param.getVideoId());
|
|
|
+ redPacketLog.setStatus(0);
|
|
|
+ redPacketLog.setQwUserId(param.getQwUserId());
|
|
|
+ redPacketLog.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ redPacketLog.setCreateTime(new Date());
|
|
|
+ redPacketLog.setAmount(amount);
|
|
|
+ redPacketLog.setWatchLogId(log != null ? log.getLogId() : null);
|
|
|
+ redPacketLog.setPeriodId(param.getPeriodId());
|
|
|
+ redPacketLog.setAppId(param.getAppId());
|
|
|
+
|
|
|
+ if (sendRedPacket.get("isNew").equals(1)) {
|
|
|
+ TransferBillsResult transferBillsResult = (TransferBillsResult) sendRedPacket.get("data");
|
|
|
+ redPacketLog.setResult(JSON.toJSONString(sendRedPacket));
|
|
|
+ redPacketLog.setOutBatchNo(transferBillsResult.getOutBillNo());
|
|
|
+ } else {
|
|
|
+ redPacketLog.setOutBatchNo(sendRedPacket.get("orderCode").toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
+ }
|
|
|
|
|
|
+ private void updateWatchLogRewardType(FsCourseWatchLog log, CourseConfig config) {
|
|
|
+ if (log != null) {
|
|
|
+ log.setRewardType(config.getRewardType());
|
|
|
+ courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 发放积分奖励
|
|
|
*
|