|
@@ -863,28 +863,21 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
FsCourseWatchLog log = new FsCourseWatchLog();
|
|
FsCourseWatchLog log = new FsCourseWatchLog();
|
|
|
|
|
|
// 根据链接类型判断是否已发放奖励
|
|
// 根据链接类型判断是否已发放奖励
|
|
- log = courseWatchLogMapper.getWatchCourseVideo(param.getUserId(), param.getVideoId(), param.getQwUserId(), param.getQwExternalId());
|
|
|
|
- if (log == null) {
|
|
|
|
- return R.error("无记录");
|
|
|
|
- }
|
|
|
|
- if (log.getRewardType() != null) {
|
|
|
|
|
|
+ if (param.getLinkType() != null && param.getLinkType() == 1) {
|
|
FsCourseRedPacketLog packetLog = redPacketLogMapper.selectFsCourseRedPacketLogByTemporary(param.getVideoId(), param.getUserId());
|
|
FsCourseRedPacketLog packetLog = redPacketLogMapper.selectFsCourseRedPacketLogByTemporary(param.getVideoId(), param.getUserId());
|
|
- if(packetLog != null && packetLog.getStatus() == 1) {
|
|
|
|
|
|
+ if (packetLog != null) {
|
|
return R.error("奖励已发放");
|
|
return R.error("奖励已发放");
|
|
}
|
|
}
|
|
- if(packetLog != null && packetLog.getStatus() == 0) {
|
|
|
|
- if(StringUtils.isNotEmpty(packetLog.getResult())){
|
|
|
|
- R r = JSON.parseObject(packetLog.getResult(), R.class);
|
|
|
|
- return r;
|
|
|
|
- } else {
|
|
|
|
- return R.error("奖励已发放");
|
|
|
|
- }
|
|
|
|
|
|
+ } else {
|
|
|
|
+ log = courseWatchLogMapper.getWatchCourseVideo(param.getUserId(), param.getVideoId(), param.getQwUserId(), param.getQwExternalId());
|
|
|
|
+ if (log == null) {
|
|
|
|
+ return R.error("无记录");
|
|
}
|
|
}
|
|
- if(packetLog != null && packetLog.getStatus() == 2) {
|
|
|
|
- return R.error("请联系客服补发");
|
|
|
|
|
|
+ if (log.getRewardType() != null) {
|
|
|
|
+ return R.error("奖励已发放");
|
|
}
|
|
}
|
|
- return R.error("奖励已发放");
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
// 获取视频信息
|
|
// 获取视频信息
|
|
FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
|
|
FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
|
|
|
|
|
|
@@ -962,6 +955,19 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
* @return 处理结果
|
|
* @return 处理结果
|
|
*/
|
|
*/
|
|
private R sendRedPacketReward(FsCourseSendRewardUParam param, FsUser user, FsCourseWatchLog log, FsUserCourseVideo video, CourseConfig config) {
|
|
private R sendRedPacketReward(FsCourseSendRewardUParam param, FsUser user, FsCourseWatchLog log, FsUserCourseVideo video, CourseConfig config) {
|
|
|
|
+ // 判断是否属于领取红包时间(会员看课发放红包)
|
|
|
|
+ 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;
|
|
BigDecimal amount = BigDecimal.ZERO;
|
|
@@ -977,46 +983,39 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
WxSendRedPacketParam packetParam = new WxSendRedPacketParam();
|
|
WxSendRedPacketParam packetParam = new WxSendRedPacketParam();
|
|
packetParam.setOpenId(user.getMpOpenId());
|
|
packetParam.setOpenId(user.getMpOpenId());
|
|
// 来源是小程序切换openId
|
|
// 来源是小程序切换openId
|
|
|
|
+// if (param.getSource() == 2) {
|
|
|
|
+// packetParam.setOpenId(user.getMaOpenId());
|
|
|
|
+// }
|
|
if (param.getSource() == 2) {
|
|
if (param.getSource() == 2) {
|
|
- //处理多小程序问题
|
|
|
|
FsUserWx fsUserWx = fsUserWxService.selectByAppIdAndUserId(param.getAppId(),user.getUserId(),1);
|
|
FsUserWx fsUserWx = fsUserWxService.selectByAppIdAndUserId(param.getAppId(),user.getUserId(),1);
|
|
- if (fsUserWx ==null || fsUserWx.getOpenId()==null){
|
|
|
|
- packetParam.setOpenId(user.getCourseMaOpenId());
|
|
|
|
|
|
+ if (fsUserWx ==null){
|
|
|
|
+ packetParam.setOpenId(user.getMaOpenId());
|
|
|
|
+ try {
|
|
|
|
+ handleFsUserWx(user,param.getAppId());
|
|
|
|
+ } catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ logger.error(e.getMessage(),e);
|
|
|
|
+ }
|
|
|
|
+
|
|
}else {
|
|
}else {
|
|
|
|
+ //查出openid并赋值
|
|
packetParam.setOpenId(fsUserWx.getOpenId());
|
|
packetParam.setOpenId(fsUserWx.getOpenId());
|
|
}
|
|
}
|
|
- //查出公司绑定openid并赋值
|
|
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|
|
packetParam.setAmount(amount);
|
|
packetParam.setAmount(amount);
|
|
packetParam.setSource(param.getSource());
|
|
packetParam.setSource(param.getSource());
|
|
packetParam.setRedPacketMode(config.getRedPacketMode());
|
|
packetParam.setRedPacketMode(config.getRedPacketMode());
|
|
packetParam.setCompanyId(param.getCompanyId());
|
|
packetParam.setCompanyId(param.getCompanyId());
|
|
|
|
+ packetParam.setAppId(param.getAppId());
|
|
|
|
+ if (StringUtils.isNotEmpty(param.getCode())){
|
|
|
|
+ packetParam.setCode(param.getCode());
|
|
|
|
+ packetParam.setUser(user);
|
|
|
|
+ }
|
|
|
|
|
|
- System.out.println("红包金额"+amount);
|
|
|
|
- System.out.println("红包商户号"+packetParam);
|
|
|
|
- //2025.6.19 红包金额为0的时候
|
|
|
|
|
|
+ //2025.7.11 红包金额为0的时候
|
|
if (amount.compareTo(BigDecimal.ZERO)>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);
|
|
R sendRedPacket = paymentService.sendRedPacket(packetParam);
|
|
if (sendRedPacket.get("code").equals(200)) {
|
|
if (sendRedPacket.get("code").equals(200)) {
|
|
@@ -1026,8 +1025,10 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
transferBillsResult = (TransferBillsResult)sendRedPacket.get("data");
|
|
transferBillsResult = (TransferBillsResult)sendRedPacket.get("data");
|
|
redPacketLog.setResult(JSON.toJSONString(sendRedPacket));
|
|
redPacketLog.setResult(JSON.toJSONString(sendRedPacket));
|
|
redPacketLog.setOutBatchNo(transferBillsResult.getOutBillNo());
|
|
redPacketLog.setOutBatchNo(transferBillsResult.getOutBillNo());
|
|
|
|
+ redPacketLog.setBatchId(transferBillsResult.getTransferBillNo());
|
|
}else {
|
|
}else {
|
|
redPacketLog.setOutBatchNo(sendRedPacket.get("orderCode").toString());
|
|
redPacketLog.setOutBatchNo(sendRedPacket.get("orderCode").toString());
|
|
|
|
+ redPacketLog.setBatchId(sendRedPacket.get("batchId").toString());
|
|
}
|
|
}
|
|
// 添加红包记录
|
|
// 添加红包记录
|
|
redPacketLog.setCourseId(param.getCourseId());
|
|
redPacketLog.setCourseId(param.getCourseId());
|
|
@@ -1042,28 +1043,22 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
redPacketLog.setAmount(amount);
|
|
redPacketLog.setAmount(amount);
|
|
redPacketLog.setWatchLogId(log.getLogId() != null ? log.getLogId() : null);
|
|
redPacketLog.setWatchLogId(log.getLogId() != null ? log.getLogId() : null);
|
|
redPacketLog.setPeriodId(param.getPeriodId());
|
|
redPacketLog.setPeriodId(param.getPeriodId());
|
|
|
|
+ redPacketLog.setAppId(param.getAppId());
|
|
|
|
+
|
|
redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
|
|
|
// 更新观看记录的奖励类型
|
|
// 更新观看记录的奖励类型
|
|
|
|
+// if (param.getLinkType() == null || param.getLinkType() == 0) {
|
|
log.setRewardType(config.getRewardType());
|
|
log.setRewardType(config.getRewardType());
|
|
courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
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;
|
|
return sendRedPacket;
|
|
} else {
|
|
} else {
|
|
return R.error("奖励发送失败,请联系客服");
|
|
return R.error("奖励发送失败,请联系客服");
|
|
}
|
|
}
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
|
|
+ // 发送红包
|
|
FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
// 添加红包记录
|
|
// 添加红包记录
|
|
redPacketLog.setCourseId(param.getCourseId());
|
|
redPacketLog.setCourseId(param.getCourseId());
|
|
@@ -1071,7 +1066,8 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
redPacketLog.setCompanyId(param.getCompanyId());
|
|
redPacketLog.setCompanyId(param.getCompanyId());
|
|
redPacketLog.setUserId(param.getUserId());
|
|
redPacketLog.setUserId(param.getUserId());
|
|
redPacketLog.setVideoId(param.getVideoId());
|
|
redPacketLog.setVideoId(param.getVideoId());
|
|
- redPacketLog.setStatus(0);
|
|
|
|
|
|
+ redPacketLog.setStatus(1);//直接设置发送成功
|
|
|
|
+ redPacketLog.setResult("{\"msg\":\"发送0红包成功\",\"code\":200,\"isNew\":1}");
|
|
redPacketLog.setQwUserId(param.getQwUserId() != null ? param.getQwUserId() : null);
|
|
redPacketLog.setQwUserId(param.getQwUserId() != null ? param.getQwUserId() : null);
|
|
redPacketLog.setCompanyUserId(param.getCompanyUserId());
|
|
redPacketLog.setCompanyUserId(param.getCompanyUserId());
|
|
redPacketLog.setCreateTime(new Date());
|
|
redPacketLog.setCreateTime(new Date());
|
|
@@ -1081,13 +1077,34 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
|
|
|
// 更新观看记录的奖励类型
|
|
// 更新观看记录的奖励类型
|
|
-// if (param.getLinkType() == null || param.getLinkType() == 0) {
|
|
|
|
log.setRewardType(config.getRewardType());
|
|
log.setRewardType(config.getRewardType());
|
|
courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
-// }
|
|
|
|
return R.ok("红包发送成功");
|
|
return R.ok("红包发送成功");
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ private void handleFsUserWx(FsUser user, String appId) {
|
|
|
|
+ // 尝试更新
|
|
|
|
+ boolean updated = fsUserWxService.lambdaUpdate()
|
|
|
|
+ .eq(FsUserWx::getFsUserId, user.getUserId())
|
|
|
|
+ .eq(FsUserWx::getAppId,appId )
|
|
|
|
+ .eq(FsUserWx::getOpenId, user.getMaOpenId())
|
|
|
|
+// .set(FsUserWx::getUnionId, session.getUnionid() == null ? "" : session.getUnionid())
|
|
|
|
+ .set(FsUserWx::getUpdateTime, new Date())
|
|
|
|
+ .update();
|
|
|
|
+
|
|
|
|
+ // 如果更新失败(记录不存在),则插入
|
|
|
|
+ if (!updated) {
|
|
|
|
+ FsUserWx fsUserWx = new FsUserWx();
|
|
|
|
+ fsUserWx.setType(1);
|
|
|
|
+ fsUserWx.setFsUserId(user.getUserId());
|
|
|
|
+ fsUserWx.setAppId(appId);
|
|
|
|
+ fsUserWx.setOpenId(user.getMaOpenId());
|
|
|
|
+// fsUserWx.setUnionId(session.getUnionid() == null ? "" : session.getUnionid());
|
|
|
|
+ fsUserWx.setCreateTime(new Date());
|
|
|
|
+ fsUserWx.setUpdateTime(new Date());
|
|
|
|
+ fsUserWxService.save(fsUserWx);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|