|
@@ -81,6 +81,7 @@ import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeansException;
|
|
import org.springframework.beans.BeansException;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -247,6 +248,9 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
@Autowired
|
|
@Autowired
|
|
private CloudHostProper cloudHostProper;
|
|
private CloudHostProper cloudHostProper;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisTemplate<String,BigDecimal> redisTemplate;
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 查询课堂视频
|
|
* 查询课堂视频
|
|
@@ -1151,7 +1155,8 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
|
|
|
BigDecimal companyMoney = null;
|
|
BigDecimal companyMoney = null;
|
|
if(StringUtils.equals(ENABLE_RED_PACK_ACCOUNT,"1")) {
|
|
if(StringUtils.equals(ENABLE_RED_PACK_ACCOUNT,"1")) {
|
|
- companyMoney = redisCache.getCacheObject(REDPACKET_COMPANY_MONEY);
|
|
|
|
|
|
+ companyMoney = redisTemplate.opsForValue().get(REDPACKET_COMPANY_MONEY);
|
|
|
|
+
|
|
if(ObjectUtils.isNull(companyMoney)){
|
|
if(ObjectUtils.isNull(companyMoney)){
|
|
SysConfig sysConfig = sysConfigService.selectConfigByConfigKey("company.money");
|
|
SysConfig sysConfig = sysConfigService.selectConfigByConfigKey("company.money");
|
|
if(ObjectUtils.isNull(sysConfig)){
|
|
if(ObjectUtils.isNull(sysConfig)){
|
|
@@ -1197,19 +1202,17 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
redPacketLog.setAccBalanceAfter(companyMoney.subtract(amount));
|
|
redPacketLog.setAccBalanceAfter(companyMoney.subtract(amount));
|
|
}
|
|
}
|
|
|
|
|
|
- CompletableFuture.runAsync(() -> {
|
|
|
|
- redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
|
- // 更新观看记录的奖励类型
|
|
|
|
- log.setRewardType(config.getRewardType());
|
|
|
|
- courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
|
- });
|
|
|
|
|
|
+ redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
|
+ // 更新观看记录的奖励类型
|
|
|
|
+ log.setRewardType(config.getRewardType());
|
|
|
|
+ courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
|
|
|
if(StringUtils.equals(ENABLE_RED_PACK_ACCOUNT,"1")) {
|
|
if(StringUtils.equals(ENABLE_RED_PACK_ACCOUNT,"1")) {
|
|
// 更新账户余额
|
|
// 更新账户余额
|
|
logger.info("[更新账户余额] 当前余额{} 更新后余额{}",companyMoney.toPlainString(),companyMoney.subtract(amount).toPlainString());
|
|
logger.info("[更新账户余额] 当前余额{} 更新后余额{}",companyMoney.toPlainString(),companyMoney.subtract(amount).toPlainString());
|
|
|
|
|
|
companyMoney = companyMoney.subtract(amount);
|
|
companyMoney = companyMoney.subtract(amount);
|
|
- redisCache.setCacheObject(REDPACKET_COMPANY_MONEY,companyMoney);
|
|
|
|
|
|
+ redisTemplate.opsForValue().set(REDPACKET_COMPANY_MONEY,companyMoney);
|
|
}
|
|
}
|
|
return sendRedPacket;
|
|
return sendRedPacket;
|
|
} else {
|
|
} else {
|
|
@@ -1311,11 +1314,8 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
packetParam.setAppId(param.getAppId());
|
|
packetParam.setAppId(param.getAppId());
|
|
packetParam.setUser(user);
|
|
packetParam.setUser(user);
|
|
|
|
|
|
- System.out.println("红包金额"+amount);
|
|
|
|
- System.out.println("红包商户号"+packetParam);
|
|
|
|
-// if (ObjectUtils.isNotEmpty(config.getIsNegative())&&config.getIsNegative() == 1) {
|
|
|
|
-// return processRedPacket(config, packetParam, param, amount, log);
|
|
|
|
-// }
|
|
|
|
|
|
+ logger.info("红包金额 {},红包商户号 {}",amount,packetParam);
|
|
|
|
+
|
|
//2025.6.19 红包金额为0的时候
|
|
//2025.6.19 红包金额为0的时候
|
|
if (amount.compareTo(BigDecimal.ZERO)>0){
|
|
if (amount.compareTo(BigDecimal.ZERO)>0){
|
|
|
|
|
|
@@ -1324,42 +1324,93 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
if (money.compareTo(BigDecimal.ZERO)<0) {
|
|
if (money.compareTo(BigDecimal.ZERO)<0) {
|
|
return R.error("服务商余额不足,请联系群主服务器充值!");
|
|
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.setBatchId(sendRedPacket.get("batchId").toString());
|
|
|
|
|
|
+
|
|
|
|
+ //---------------发红包前先判断润天账户余额是否足够---------
|
|
|
|
+ RLock lock = redissonClient.getLock(REDPACKET_POOL_LOCK);
|
|
|
|
+ try{
|
|
|
|
+ boolean locked = lock.tryLock(3, 10, TimeUnit.SECONDS);
|
|
|
|
+
|
|
|
|
+ if (!locked) {
|
|
|
|
+ logger.error("获取锁失败");
|
|
|
|
+ return R.error("[红包领取] 系统繁忙,请重试!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BigDecimal companyMoney = null;
|
|
|
|
+ if(StringUtils.equals(ENABLE_RED_PACK_ACCOUNT,"1")) {
|
|
|
|
+ companyMoney = redisTemplate.opsForValue().get(REDPACKET_COMPANY_MONEY);
|
|
|
|
+ if(ObjectUtils.isNull(companyMoney)){
|
|
|
|
+ SysConfig sysConfig = sysConfigService.selectConfigByConfigKey("company.money");
|
|
|
|
+ if(ObjectUtils.isNull(sysConfig)){
|
|
|
|
+ throw new IllegalArgumentException("润天公司账户余额不能为空!请检查配置!");
|
|
|
|
+ }
|
|
|
|
+ String configValue = sysConfig.getConfigValue();
|
|
|
|
+ companyMoney = new BigDecimal(configValue);
|
|
|
|
+ logger.info("缓存公司余额为空,从数据库读取 companyMoney: {}",companyMoney);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (companyMoney.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
+ logger.info("润天账户余额: {} 不足!", companyMoney);
|
|
|
|
+ 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.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());
|
|
|
|
+ if(StringUtils.equals(ENABLE_RED_PACK_ACCOUNT,"1")) {
|
|
|
|
+ redPacketLog.setAccBalanceBefore(companyMoney);
|
|
|
|
+ redPacketLog.setAccBalanceAfter(companyMoney.subtract(amount));
|
|
|
|
+ }
|
|
|
|
+ redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
|
+
|
|
|
|
+ // 更新观看记录的奖励类型
|
|
|
|
+ log.setRewardType(config.getRewardType());
|
|
|
|
+ courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if(StringUtils.equals(ENABLE_RED_PACK_ACCOUNT,"1")) {
|
|
|
|
+ // 更新账户余额
|
|
|
|
+ logger.info("[更新账户余额] 当前余额{} 更新后余额{}",companyMoney.toPlainString(),companyMoney.subtract(amount).toPlainString());
|
|
|
|
+
|
|
|
|
+ companyMoney = companyMoney.subtract(amount);
|
|
|
|
+ redisTemplate.opsForValue().set(REDPACKET_COMPANY_MONEY,companyMoney);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return sendRedPacket;
|
|
|
|
+ } else {
|
|
|
|
+ return R.error("奖励发送失败,请联系客服");
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ logger.error("领取红包失败原因:{}", ExceptionUtils.getFullStackTrace(e),e);
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ }finally {
|
|
|
|
+ if (lock.isHeldByCurrentThread()) {
|
|
|
|
+ lock.unlock();
|
|
}
|
|
}
|
|
- // 添加红包记录
|
|
|
|
- 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("奖励发送失败,请联系客服");
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
// 添加红包记录
|
|
// 添加红包记录
|
|
@@ -1386,93 +1437,6 @@ 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());
|
|
|
|
-
|
|
|
|
- // Set batch number based on isNew flag
|
|
|
|
- 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);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- /**
|
|
|
|
- * 获取用户openId
|
|
|
|
- *
|
|
|
|
- * @param userId 用户ID
|
|
|
|
- * @param companyId 公司ID
|
|
|
|
- * @param source 来源 1公众号 2小程序
|
|
|
|
- * @return openId
|
|
|
|
- */
|
|
|
|
- private String getOpenId(Long userId, Long companyId, Integer source) {
|
|
|
|
- Company company = companyMapper.selectCompanyById(companyId);
|
|
|
|
- String appId = source == 1 ? company.getCourseMaAppId() : company.getCourseMiniAppId();
|
|
|
|
-
|
|
|
|
- // 公司配置为空时获取默认配置
|
|
|
|
- if (StringUtils.isBlank(appId)) {
|
|
|
|
- String json = configService.selectConfigByKey("course.config");
|
|
|
|
- CourseConfig config = JSON.parseObject(json, CourseConfig.class);
|
|
|
|
- appId = source == 1 ? config.getMpAppId() : config.getMiniprogramAppid();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 查询openId
|
|
|
|
- Wrapper<FsUserWx> queryWrapper = Wrappers.<FsUserWx>lambdaQuery().eq(FsUserWx::getFsUserId, userId).eq(FsUserWx::getAppId, appId);
|
|
|
|
- FsUserWx fsUserWx = fsUserWxService.getOne(queryWrapper);
|
|
|
|
- if (Objects.isNull(fsUserWx)) {
|
|
|
|
- throw new CustomException("获取openId失败");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return fsUserWx.getOpenId();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 发放积分奖励
|
|
* 发放积分奖励
|
|
*
|
|
*
|
|
@@ -2225,6 +2189,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
}
|
|
}
|
|
|
|
|
|
link.setCreateTime(sendTime);
|
|
link.setCreateTime(sendTime);
|
|
|
|
+ link.setProjectCode(cloudHostProper.getProjectCode());
|
|
|
|
|
|
FsCourseRealLink courseMap = new FsCourseRealLink();
|
|
FsCourseRealLink courseMap = new FsCourseRealLink();
|
|
BeanUtils.copyProperties(link,courseMap);
|
|
BeanUtils.copyProperties(link,courseMap);
|