|
@@ -914,7 +914,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
switch (config.getRewardType()) {
|
|
|
// 红包奖励
|
|
|
case 1:
|
|
|
- return sendRedPacketReward(param, user, log, video, config);
|
|
|
+ return sendRedPacketRewardFsUser(param, user, log, video, config);
|
|
|
// 积分奖励
|
|
|
case 2:
|
|
|
return sendIntegralReward(param,user, log, config);
|
|
@@ -1073,6 +1073,164 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 发放红包奖励
|
|
|
+ *
|
|
|
+ * @param param 请求参数
|
|
|
+ * @param user 用户信息
|
|
|
+ * @param log 观看日志
|
|
|
+ * @param video 视频信息
|
|
|
+ * @param config 配置信息
|
|
|
+ * @return 处理结果
|
|
|
+ */
|
|
|
+ private R sendRedPacketRewardFsUser(FsCourseSendRewardUParam param, FsUser user, FsCourseWatchLog log, FsUserCourseVideo video, CourseConfig config) {
|
|
|
+ // 判断是否属于领取红包时间(会员看课发放红包)
|
|
|
+ if (param.getPeriodId()!=null && param.getPeriodId()>0) {
|
|
|
+ FsUserCoursePeriodDays periodDays = new FsUserCoursePeriodDays();
|
|
|
+ periodDays.setVideoId(param.getVideoId());
|
|
|
+ periodDays.setPeriodId(param.getPeriodId());
|
|
|
+ //正常情况是只能查询到一条,之前可能存在重复的脏数据,暂使用查询list的方式
|
|
|
+ List<FsUserCoursePeriodDays> fsUserCoursePeriodDays = fsUserCoursePeriodDaysMapper.selectFsUserCoursePeriodDaysList(periodDays);
|
|
|
+ if(fsUserCoursePeriodDays != null && !fsUserCoursePeriodDays.isEmpty()){
|
|
|
+ periodDays = fsUserCoursePeriodDays.get(0);
|
|
|
+ }
|
|
|
+ if(periodDays != null && periodDays.getLastJoinTime() !=null && LocalDateTime.now().isAfter(periodDays.getLastJoinTime())) {
|
|
|
+ return R.error(403,"已超过领取红包时间");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确定红包金额
|
|
|
+ BigDecimal amount = BigDecimal.ZERO;
|
|
|
+ FsUserCourseVideoRedPackage redPackage = fsUserCourseVideoRedPackageMapper.selectRedPacketByCompanyId(param.getVideoId(), param.getCompanyId(), param.getPeriodId());
|
|
|
+
|
|
|
+ if (redPackage != null) {
|
|
|
+ amount = redPackage.getRedPacketMoney();
|
|
|
+ } else if (video != null) {
|
|
|
+ amount = video.getRedPacketMoney();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 准备发送红包参数
|
|
|
+ WxSendRedPacketParam packetParam = new WxSendRedPacketParam();
|
|
|
+// packetParam.setOpenId(getOpenId(user.getUserId(), param.getCompanyId(), param.getSource()));
|
|
|
+ packetParam.setOpenId(user.getMpOpenId());
|
|
|
+ // 来源是小程序切换openId
|
|
|
+ if (param.getSource() == 2) {
|
|
|
+ //处理多小程序问题
|
|
|
+ Company company = companyMapper.selectCompanyById(param.getCompanyId());
|
|
|
+ if (company.getCourseMiniAppId()==null){
|
|
|
+ return R.error("销售公司参数错误,未绑定小程序");
|
|
|
+ }
|
|
|
+ FsUserWx fsUserWx = fsUserWxService.selectByAppIdAndUserId(company.getCourseMiniAppId(),user.getUserId(),1);
|
|
|
+ if (fsUserWx ==null || fsUserWx.getOpenId()==null){
|
|
|
+ return R.error("小程序openId参数缺失");
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println("小程序id"+user.getCourseMaOpenId());
|
|
|
+ //查出公司绑定openid并赋值
|
|
|
+ packetParam.setOpenId(fsUserWx.getOpenId());
|
|
|
+ }
|
|
|
+ packetParam.setAmount(amount);
|
|
|
+ packetParam.setSource(param.getSource());
|
|
|
+ packetParam.setRedPacketMode(config.getRedPacketMode());
|
|
|
+ packetParam.setCompanyId(param.getCompanyId());
|
|
|
+
|
|
|
+ System.out.println("红包金额"+amount);
|
|
|
+ System.out.println("红包商户号"+packetParam);
|
|
|
+ //2025.6.19 红包金额为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)) {
|
|
|
+ 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());
|
|
|
+ }else {
|
|
|
+ redPacketLog.setOutBatchNo(sendRedPacket.get("orderCode").toString());
|
|
|
+ }
|
|
|
+ // 添加红包记录
|
|
|
+ redPacketLog.setCourseId(param.getCourseId());
|
|
|
+// redPacketLog.setOutBatchNo(sendRedPacket.get("orderCode").toString());
|
|
|
+ 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());
|
|
|
+ redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
+
|
|
|
+ // 更新观看记录的奖励类型
|
|
|
+ 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();
|
|
|
+ // 添加红包记录
|
|
|
+ redPacketLog.setCourseId(param.getCourseId());
|
|
|
+// redPacketLog.setOutBatchNo(sendRedPacket.get("orderCode").toString());
|
|
|
+ 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(BigDecimal.ZERO);
|
|
|
+ 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);
|
|
|
+// }
|
|
|
+ return R.ok("红包发送成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取用户openId
|
|
|
*
|