|
@@ -12,6 +12,8 @@ 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.CompanyUserMapper;
|
|
|
import com.fs.course.config.CourseConfig;
|
|
@@ -27,7 +29,9 @@ import com.fs.course.vo.FsUserCourseVideoListUVO;
|
|
|
import com.fs.course.vo.FsUserCourseVideoQVO;
|
|
|
import com.fs.course.vo.FsUserCourseVideoVO;
|
|
|
import com.fs.course.vo.newfs.*;
|
|
|
+import com.fs.his.domain.FsUserWx;
|
|
|
import com.fs.his.param.WxSendRedPacketParam;
|
|
|
+import com.fs.his.service.IFsUserWxService;
|
|
|
import com.fs.his.vo.OptionsVO;
|
|
|
import com.fs.qw.domain.QwCompany;
|
|
|
import com.fs.qw.domain.QwExternalContact;
|
|
@@ -59,6 +63,7 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.security.core.parameters.P;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -175,6 +180,9 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
|
|
|
@Autowired
|
|
|
private FsUserCourseCompanyUserTimeMapper companyUserTimeMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsUserWxService fsUserWxService;
|
|
|
/**
|
|
|
* 查询课堂视频
|
|
|
*
|
|
@@ -819,6 +827,9 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
packetParam.setRedPacketMode(config.getRedPacketMode());
|
|
|
packetParam.setCompanyId(param.getCompanyId());
|
|
|
packetParam.setAppId(param.getAppId());
|
|
|
+ if (StringUtils.isNotEmpty(param.getCode())){
|
|
|
+ packetParam.setCode(param.getCode());
|
|
|
+ }
|
|
|
|
|
|
//2025.7.11 红包金额为0的时候
|
|
|
if (amount.compareTo(BigDecimal.ZERO)>0){
|
|
@@ -888,6 +899,138 @@ 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(param.getAppId(),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.7.11 红包金额为0的时候
|
|
|
+ if (amount.compareTo(BigDecimal.ZERO)>0){
|
|
|
+ // 发送红包
|
|
|
+ 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.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);
|
|
|
+
|
|
|
+ // 更新观看记录的奖励类型
|
|
|
+// if (param.getLinkType() == null || param.getLinkType() == 0) {
|
|
|
+ log.setRewardType(config.getRewardType());
|
|
|
+ courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
+// }
|
|
|
+ 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(1);//直接设置发送成功
|
|
|
+ redPacketLog.setResult("{\"msg\":\"发送0红包成功\",\"code\":200,\"isNew\":1}");
|
|
|
+ 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);
|
|
|
+
|
|
|
+ // 更新观看记录的奖励类型
|
|
|
+ log.setRewardType(config.getRewardType());
|
|
|
+ courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
+ return R.ok("红包发送成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 发放积分奖励
|
|
|
*
|