|
|
@@ -25,12 +25,11 @@ import com.fs.common.utils.date.DateUtil;
|
|
|
import com.fs.company.constant.CompanyTrafficConstants;
|
|
|
import com.fs.company.domain.Company;
|
|
|
import com.fs.company.domain.CompanyCompanyFsuser;
|
|
|
+import com.fs.company.domain.CompanyRedPacketBalanceDeductionRecord;
|
|
|
import com.fs.company.domain.CompanyUser;
|
|
|
-import com.fs.company.mapper.CompanyCompanyFsuserMapper;
|
|
|
-import com.fs.company.mapper.CompanyMapper;
|
|
|
-import com.fs.company.mapper.CompanyMoneyLogsMapper;
|
|
|
-import com.fs.company.mapper.CompanyUserMapper;
|
|
|
+import com.fs.company.mapper.*;
|
|
|
import com.fs.company.service.ICompanyService;
|
|
|
+import com.fs.company.util.CompanyRedPacketBalanceUtil;
|
|
|
import com.fs.config.cloud.CloudHostProper;
|
|
|
import com.fs.course.config.CourseConfig;
|
|
|
import com.fs.course.domain.*;
|
|
|
@@ -183,8 +182,6 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
private FsCourseSopLogsMapper courseSopLogsMapper;
|
|
|
@Autowired
|
|
|
private QwApiService qwApiService;
|
|
|
- // @Autowired
|
|
|
-// private IAdHtmlClickLogService adHtmlClickLogService;
|
|
|
@Autowired
|
|
|
private QwUserMapper qwUserMapper;
|
|
|
@Autowired
|
|
|
@@ -259,16 +256,10 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
|
|
|
@Autowired
|
|
|
private IFsUserCompanyBindService fsUserCompanyBindService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private BalanceRollbackErrorMapper balanceRollbackErrorMapper;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IFsUserIntegralLogsService iFsUserIntegralLogsService;
|
|
|
@Autowired
|
|
|
- private QwTagGroupMapper qwTagGroupMapper;
|
|
|
- @Autowired
|
|
|
- private QwTagMapper qwTagMapper;
|
|
|
+ private CompanyRedPacketBalanceUtil companyRedPacketBalanceUtil;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1478,16 +1469,34 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
// 更新观看记录的奖励类型
|
|
|
log.setRewardType(config.getRewardType());
|
|
|
courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
- return R.ok("红包发送成功");
|
|
|
+ return R.ok("答题成功,请联系群主");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private R sendRedPacketRewardToUser(FsCourseSendRewardUParam param, FsCourseWatchLog log, CourseConfig config, WxSendRedPacketParam packetParam, BigDecimal amount) {
|
|
|
-
|
|
|
+ // 打开红包扣减功能
|
|
|
+ CompanyRedPacketBalanceDeductionRecord record = null;
|
|
|
+ if("1".equals(config.getIsRedPackageBalanceDeduction())){
|
|
|
+ try {
|
|
|
+ record = companyRedPacketBalanceUtil.subCacheRedPacketBalance(packetParam.getCompanyId(), amount);
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ return R.error(e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("公司红包余额扣减失败 err: {}", e.getMessage(), e);
|
|
|
+ return R.error("奖励发送失败,请联系客服");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
// 发送红包
|
|
|
- R sendRedPacket = paymentService.sendRedPacket(packetParam);
|
|
|
+ R sendRedPacket;
|
|
|
+ try {
|
|
|
+ sendRedPacket = paymentService.sendRedPacket(packetParam);
|
|
|
+ } catch (Exception e) {
|
|
|
+ companyRedPacketBalanceUtil.invalidRecord(record);
|
|
|
+ return R.error("奖励发送失败,请联系客服!");
|
|
|
+ }
|
|
|
+
|
|
|
if (sendRedPacket.get("code").equals(200)) {
|
|
|
FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
|
TransferBillsResult transferBillsResult;
|
|
|
@@ -1516,31 +1525,15 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
log.setRewardType(config.getRewardType());
|
|
|
courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
|
|
|
-// redisCache.setCacheObject("h5user:redPacket:"+param.getUserId(),LocalDateTime.now().toString());
|
|
|
+ companyRedPacketBalanceUtil.updateRecordRedPacketId(record, redPacketLog.getLogId());
|
|
|
|
|
|
return sendRedPacket;
|
|
|
} else {
|
|
|
+ companyRedPacketBalanceUtil.invalidRecord(record);
|
|
|
return R.error("奖励发送失败,请联系客服");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private void handleFsUserWx(FsUser user, String appId) {
|
|
|
- FsUserWx fsUserWx = new FsUserWx();
|
|
|
- fsUserWx.setType(1);
|
|
|
- fsUserWx.setFsUserId(user.getUserId());
|
|
|
- fsUserWx.setAppId(appId);
|
|
|
- fsUserWx.setOpenId(user.getCourseMaOpenId());
|
|
|
- fsUserWx.setUnionId(user.getUnionId());
|
|
|
- fsUserWx.setCreateTime(new Date());
|
|
|
- fsUserWx.setUpdateTime(new Date());
|
|
|
- fsUserWxService.saveOrUpdateByUniqueKey(fsUserWx);
|
|
|
-
|
|
|
- logger.info("【更新或插入用户与小程序{}的绑定关系】:{}", appId, user.getUserId());
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 发放红包奖励
|
|
|
*
|
|
|
@@ -1619,181 +1612,73 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
if (openRedPacket && amount.compareTo(BigDecimal.ZERO)>0){
|
|
|
|
|
|
// 打开红包扣减功能
|
|
|
- if("1".equals(config.getIsRedPackageBalanceDeduction())){
|
|
|
- // 先注释 20251024 redis 余额 充值没有考虑 其余扣减没有考虑
|
|
|
- // ===================== 20251022 xgb 修改 本次修改目的为了实时扣减公司余额=====================
|
|
|
- // 1 使用redis缓存加锁 预扣减余额 红包发送失败 恢复redis缓存余额,如果回滚失败登记异常记录表 定时任务重新回滚余额
|
|
|
- // 2 另起定时任务 同步缓存余额到redis中
|
|
|
- // 3 注意!!!!! 启动系统时查询公司账户余额(这个时候要保证余额正确)启动会自动保存到redis缓存中
|
|
|
- // 注意!!!!! 打开这个开关前记得检测redis缓存余额是否正确 若不正确 修改数据库字段red_package_money,删除redis缓存,重启系统,
|
|
|
-
|
|
|
-
|
|
|
- // 预设值异常对象
|
|
|
-
|
|
|
- BalanceRollbackError balanceRollbackError = new BalanceRollbackError();
|
|
|
- balanceRollbackError.setCompanyId(packetParam.getCompanyId());
|
|
|
- balanceRollbackError.setUserId(user.getUserId());
|
|
|
- balanceRollbackError.setLogId(log.getLogId());
|
|
|
- balanceRollbackError.setVideoId(log.getVideoId());
|
|
|
- balanceRollbackError.setStatus(0);
|
|
|
- balanceRollbackError.setMoney(amount);
|
|
|
-
|
|
|
- if(packetParam.getCompanyId()== null){
|
|
|
- logger.error("发送红包参数错误,公司不能为空,异常请求参数{}",packetParam);
|
|
|
- return R.error("发送红包失败,请联系管理员");
|
|
|
- }
|
|
|
- String companyMoneyKey = FsConstants.COMPANY_MONEY_KEY + packetParam.getCompanyId();
|
|
|
-
|
|
|
- // 第一次加锁:预扣减余额
|
|
|
- RLock lock1 = redissonClient.getLock(FsConstants.COMPANY_MONEY_LOCK + packetParam.getCompanyId());
|
|
|
- boolean lockAcquired = false;
|
|
|
- BigDecimal newMoney;
|
|
|
- try {
|
|
|
- if (lock1.tryLock(3, 10, TimeUnit.SECONDS)) {
|
|
|
- lockAcquired = true;
|
|
|
- BigDecimal originalMoney;
|
|
|
- // 获取当前余额
|
|
|
- String moneyStr = redisCache.getCacheObject(companyMoneyKey);
|
|
|
- if (StringUtils.isNotEmpty(moneyStr)) {
|
|
|
- originalMoney = new BigDecimal(moneyStr);
|
|
|
- }else {
|
|
|
- // 缓存没有值,重启系统恢复redis数据 保证数据正确性
|
|
|
- logger.error("发送红包获取redis余额缓存异常,异常请求参数{}",packetParam);
|
|
|
- return R.error("系统异常,请稍后重试");
|
|
|
- }
|
|
|
-
|
|
|
- if (originalMoney.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
- logger.error("服务商余额不足,异常请求参数{}",packetParam);
|
|
|
- return R.error("服务商余额不足,请联系群主服务器充值!");
|
|
|
- }
|
|
|
-
|
|
|
- // 预扣减金额
|
|
|
- newMoney = originalMoney.subtract(amount);
|
|
|
- redisCache.setCacheObject(companyMoneyKey, newMoney.toString());
|
|
|
- } else {
|
|
|
- logger.error("获取redis锁失败,异常请求参数{}",packetParam);
|
|
|
- return R.error("系统繁忙,请稍后重试");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error("预扣减余额失败: 异常请求参数{},异常信息{}", packetParam, e.getMessage(), e);
|
|
|
- return R.error("系统异常,请稍后重试");
|
|
|
- }finally {
|
|
|
- // 只有在成功获取锁的情况下才释放锁
|
|
|
- if (lockAcquired && lock1.isHeldByCurrentThread()) {
|
|
|
- try {
|
|
|
- lock1.unlock();
|
|
|
- } catch (IllegalMonitorStateException e) {
|
|
|
- logger.warn("尝试释放非当前线程持有的锁: companyId={}", packetParam.getCompanyId());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // 调用第三方接口(锁外操作)
|
|
|
- R sendRedPacket;
|
|
|
+ CompanyRedPacketBalanceDeductionRecord record = null;
|
|
|
+ if ("1".equals(config.getIsRedPackageBalanceDeduction())) {
|
|
|
try {
|
|
|
- sendRedPacket= paymentService.sendRedPacket(packetParam);
|
|
|
+ record = companyRedPacketBalanceUtil.subCacheRedPacketBalance(packetParam.getCompanyId(), amount);
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ return R.error(e.getMessage());
|
|
|
} catch (Exception e) {
|
|
|
- logger.error("红包发送异常: 异常请求参数{}",packetParam, e);
|
|
|
- // 异常时回滚余额
|
|
|
-
|
|
|
- rollbackBalance(balanceRollbackError);
|
|
|
- return R.error("奖励发送失败,请联系客服");
|
|
|
- }
|
|
|
-
|
|
|
- // 红包发送成功处理
|
|
|
- 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.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);
|
|
|
-
|
|
|
- // 异步登记余额扣减日志
|
|
|
- BigDecimal money=amount.multiply(BigDecimal.valueOf(-1));
|
|
|
- companyService.asyncRecordBalanceLog(param.getCompanyId(), money, 15, newMoney, "发放红包");
|
|
|
- // 发送成功,记录日志等操作
|
|
|
- return sendRedPacket;
|
|
|
-
|
|
|
-
|
|
|
- } else {
|
|
|
- // 发送失败,回滚余额
|
|
|
- rollbackBalance(balanceRollbackError);
|
|
|
+ logger.error("公司红包余额扣减失败 err: {}", e.getMessage(), e);
|
|
|
return R.error("奖励发送失败,请联系客服");
|
|
|
}
|
|
|
-
|
|
|
- // ===================== 本次修改目的为了实时扣减公司余额=====================
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
Company company = companyMapper.selectCompanyById(param.getCompanyId());
|
|
|
BigDecimal money = company.getMoney();
|
|
|
if (money.compareTo(BigDecimal.ZERO)<=0) {
|
|
|
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());
|
|
|
- redPacketLog.setBatchId(transferBillsResult.getTransferBillNo());
|
|
|
- }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());
|
|
|
-
|
|
|
- redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
|
-
|
|
|
- // 更新观看记录的奖励类型
|
|
|
- log.setRewardType(config.getRewardType());
|
|
|
- courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
-
|
|
|
- return sendRedPacket;
|
|
|
- } else {
|
|
|
- return R.error("奖励发送失败,请联系客服");
|
|
|
+ // 发送红包
|
|
|
+ R sendRedPacket;
|
|
|
+ try {
|
|
|
+ sendRedPacket = paymentService.sendRedPacket(packetParam);
|
|
|
+ } catch (Exception e) {
|
|
|
+ companyRedPacketBalanceUtil.invalidRecord(record);
|
|
|
+ return R.error("奖励发送失败,请联系客服!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 红包发送成功处理
|
|
|
+ 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.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);
|
|
|
+
|
|
|
+ companyRedPacketBalanceUtil.updateRecordRedPacketId(record, redPacketLog.getLogId());
|
|
|
+
|
|
|
+ // 发送成功,记录日志等操作
|
|
|
+ return sendRedPacket;
|
|
|
+ } else {
|
|
|
+ companyRedPacketBalanceUtil.invalidRecord(record);
|
|
|
+ return R.error("奖励发送失败,请联系客服");
|
|
|
}
|
|
|
} else {
|
|
|
FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
|
@@ -1816,7 +1701,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
// 更新观看记录的奖励类
|
|
|
log.setRewardType(config.getRewardType());
|
|
|
courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
|
- return R.ok("红包发送成功");
|
|
|
+ return R.ok("答题成功,请联系群主");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -1844,144 +1729,6 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
return company.getOpenRedPacket() == 1 && periodRedPacketState;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @Description: 回滚redis缓存中的余额 异常登记回滚异常表,定时重新回滚
|
|
|
- * @Param:
|
|
|
- * @Return:
|
|
|
- * @Author xgb
|
|
|
- * @Date 2025/10/22 10:37
|
|
|
- */
|
|
|
- private void rollbackBalance(BalanceRollbackError balanceRollbackError) {
|
|
|
- String companyMoneyKey = FsConstants.COMPANY_MONEY_KEY + balanceRollbackError.getCompanyId();
|
|
|
- RLock lock2 = redissonClient.getLock(FsConstants.COMPANY_MONEY_LOCK + balanceRollbackError.getCompanyId());
|
|
|
- boolean lockAcquired = false;
|
|
|
- boolean backError=true;
|
|
|
- try {
|
|
|
- if (lock2.tryLock(3, 10, TimeUnit.SECONDS)) {
|
|
|
- lockAcquired=true;
|
|
|
- // 获取当前余额
|
|
|
- String currentMoneyStr = redisCache.getCacheObject(companyMoneyKey);
|
|
|
- if (StringUtils.isEmpty(currentMoneyStr)) {
|
|
|
- throw new RuntimeException("回滚余额异常");
|
|
|
- }
|
|
|
-
|
|
|
- // 回滚金额(加回之前扣减的金额)
|
|
|
- BigDecimal rollbackMoney = new BigDecimal(currentMoneyStr).add(balanceRollbackError.getMoney());
|
|
|
- redisCache.setCacheObject(companyMoneyKey, rollbackMoney.toString());
|
|
|
- backError=false;
|
|
|
- logger.info("余额回滚成功: companyId={}, amount={}", balanceRollbackError.getCompanyId(), balanceRollbackError.getMoney());
|
|
|
-
|
|
|
- } else {
|
|
|
- logger.warn("回滚余额时获取锁失败: companyId={}", balanceRollbackError.getCompanyId());
|
|
|
- // 登记回滚余额异常表
|
|
|
- balanceRollbackErrorMapper.insert(balanceRollbackError);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error("回滚余额时发生异常: companyId={}", balanceRollbackError.getCompanyId(), e);
|
|
|
- // 登记回滚余额异常表
|
|
|
- if(backError){
|
|
|
- balanceRollbackErrorMapper.insert(balanceRollbackError);
|
|
|
- }
|
|
|
- }finally {
|
|
|
- // 只有在成功获取锁的情况下才释放锁
|
|
|
- if (lockAcquired && lock2.isHeldByCurrentThread()) {
|
|
|
- try {
|
|
|
- lock2.unlock();
|
|
|
- } catch (IllegalMonitorStateException e) {
|
|
|
- logger.warn("尝试释放非当前线程持有的锁: balanceRollbackError={}",balanceRollbackError);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 直接发送奖励
|
|
|
- *
|
|
|
- * @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();
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 发放积分奖励
|
|
|
*
|
|
|
@@ -2496,12 +2243,6 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
return ResponseResult.ok(vo);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public R addWatchLogByLink(FsUserCourseAddCompanyUserParam param) {
|
|
|
-
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public R updateWatchDurationWx(FsUserCourseVideoUParam param) {
|
|
|
//临时短链不做记录
|