|
@@ -86,6 +86,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
import java.time.*;
|
|
import java.time.*;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -112,27 +113,6 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
private Boolean isNewWxMerchant;
|
|
private Boolean isNewWxMerchant;
|
|
private static final Logger logger = LoggerFactory.getLogger(FsUserCourseVideoServiceImpl.class);
|
|
private static final Logger logger = LoggerFactory.getLogger(FsUserCourseVideoServiceImpl.class);
|
|
|
|
|
|
- /**
|
|
|
|
- * 红包账户锁
|
|
|
|
- */
|
|
|
|
- private static final String REDPACKET_POOL_LOCK = "redpacket_pool_lock";
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 公司红包金额
|
|
|
|
- */
|
|
|
|
- private static final String REDPACKET_COMPANY_MONEY = "redpacket_money";
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 红包改变记录
|
|
|
|
- */
|
|
|
|
- private static final String REDPACKET_COMPANY_MONEY_CHANGE = "redpacket_money_change";
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 是否开启红包账户扣减
|
|
|
|
- */
|
|
|
|
- @Value("${enableRedPackAccount:0}")
|
|
|
|
- private String ENABLE_RED_PACK_ACCOUNT;
|
|
|
|
-
|
|
|
|
private static final String miniappRealLink = "/pages_course/video.html?course=";
|
|
private static final String miniappRealLink = "/pages_course/video.html?course=";
|
|
private static final String REAL_LINK_PREFIX = "/courseH5/pages/course/learning?course=";
|
|
private static final String REAL_LINK_PREFIX = "/courseH5/pages/course/learning?course=";
|
|
private static final String SHORT_LINK_PREFIX = "/courseH5/pages/course/learning?s=";
|
|
private static final String SHORT_LINK_PREFIX = "/courseH5/pages/course/learning?s=";
|
|
@@ -249,8 +229,6 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
@Autowired
|
|
@Autowired
|
|
ConfigUtil configUtil;
|
|
ConfigUtil configUtil;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private RedisTemplate<String,BigDecimal> redisTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -777,7 +755,12 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
}
|
|
}
|
|
|
|
|
|
private R addCustomerService(String qwUserById,String msg){
|
|
private R addCustomerService(String qwUserById,String msg){
|
|
|
|
+ String json = configService.selectConfigByKey("course.config");
|
|
|
|
+ CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
String contactWay = "";
|
|
String contactWay = "";
|
|
|
|
+ if (ObjectUtils.isNotEmpty(config.getShowQwCode())&&!config.getShowQwCode()){
|
|
|
|
+ return R.error(400,msg).put("qrcode",contactWay);
|
|
|
|
+ }
|
|
QwUser qwUser = qwUserMapper.selectQwUserById(Long.parseLong(qwUserById));
|
|
QwUser qwUser = qwUserMapper.selectQwUserById(Long.parseLong(qwUserById));
|
|
if (qwUser==null){
|
|
if (qwUser==null){
|
|
return R.error("客服不存在");
|
|
return R.error("客服不存在");
|
|
@@ -1011,23 +994,31 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
// if (StringUtils.isEmpty(user.getMpOpenId())){
|
|
// if (StringUtils.isEmpty(user.getMpOpenId())){
|
|
// return R.error("未识别到领取信息");
|
|
// return R.error("未识别到领取信息");
|
|
// }
|
|
// }
|
|
|
|
+ log.info("查询会员信息:{}", user);
|
|
if (user.getStatus()==0){
|
|
if (user.getStatus()==0){
|
|
return R.error("会员被停用,无权限,请联系客服!");
|
|
return R.error("会员被停用,无权限,请联系客服!");
|
|
}
|
|
}
|
|
- FsCourseWatchLog log = new FsCourseWatchLog();
|
|
|
|
|
|
+ FsCourseWatchLog watchLog = new FsCourseWatchLog();
|
|
|
|
|
|
// 根据链接类型判断是否已发放奖励
|
|
// 根据链接类型判断是否已发放奖励
|
|
- log = courseWatchLogMapper.getWatchCourseVideo(param.getUserId(), param.getVideoId(), param.getQwUserId(), param.getQwExternalId());
|
|
|
|
- if (log == null) {
|
|
|
|
|
|
+ watchLog = courseWatchLogMapper.getWatchCourseVideo(param.getUserId(), param.getVideoId(), param.getQwUserId(), param.getQwExternalId());
|
|
|
|
+ log.info("看课记录:{}", watchLog);
|
|
|
|
+ if (watchLog == null) {
|
|
return R.error("无记录");
|
|
return R.error("无记录");
|
|
}
|
|
}
|
|
- if (log.getRewardType() != null) {
|
|
|
|
|
|
+ if (watchLog.getLogType() != 2) {
|
|
|
|
+ return R.error("未完课");
|
|
|
|
+ }
|
|
|
|
+ if (watchLog.getRewardType() != null) {
|
|
FsCourseRedPacketLog packetLog = redPacketLogMapper.selectFsCourseRedPacketLogByTemporary(param.getVideoId(), param.getUserId());
|
|
FsCourseRedPacketLog packetLog = redPacketLogMapper.selectFsCourseRedPacketLogByTemporary(param.getVideoId(), param.getUserId());
|
|
|
|
+ log.info("课程红包:{}", packetLog);
|
|
if(packetLog != null && packetLog.getStatus() == 1) {
|
|
if(packetLog != null && packetLog.getStatus() == 1) {
|
|
return R.error("已领取该课程奖励,不可重复领取!");
|
|
return R.error("已领取该课程奖励,不可重复领取!");
|
|
}
|
|
}
|
|
if(packetLog != null && packetLog.getStatus() == 0) {
|
|
if(packetLog != null && packetLog.getStatus() == 0) {
|
|
|
|
+ log.info("判断领取记录");
|
|
if(StringUtils.isNotEmpty(packetLog.getResult())){
|
|
if(StringUtils.isNotEmpty(packetLog.getResult())){
|
|
|
|
+ log.info("是否有结果");
|
|
R r = JSON.parseObject(packetLog.getResult(), R.class);
|
|
R r = JSON.parseObject(packetLog.getResult(), R.class);
|
|
return r;
|
|
return r;
|
|
} else {
|
|
} else {
|
|
@@ -1045,22 +1036,22 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
// 获取配置信息
|
|
// 获取配置信息
|
|
String json = configService.selectConfigByKey("course.config");
|
|
String json = configService.selectConfigByKey("course.config");
|
|
CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
-
|
|
|
|
|
|
+ log.info("奖励类型:{}", config.getRewardType());
|
|
// 根据奖励类型发放不同奖励
|
|
// 根据奖励类型发放不同奖励
|
|
switch (config.getRewardType()) {
|
|
switch (config.getRewardType()) {
|
|
// 红包奖励
|
|
// 红包奖励
|
|
case 1:
|
|
case 1:
|
|
- return sendRedPacketReward(param, user, log, video, config);
|
|
|
|
|
|
+ return sendRedPacketReward(param, user, watchLog, video, config);
|
|
// 积分奖励
|
|
// 积分奖励
|
|
case 2:
|
|
case 2:
|
|
- return sendIntegralReward(param,user, log, config);
|
|
|
|
|
|
+ return sendIntegralReward(param,user, watchLog, config);
|
|
// 红包+积分
|
|
// 红包+积分
|
|
case 3:
|
|
case 3:
|
|
- R sendRed = sendRedPacketReward(param, user, log, video, config);
|
|
|
|
|
|
+ R sendRed = sendRedPacketReward(param, user, watchLog, video, config);
|
|
if (!Objects.equals(sendRed.get("code"), 200)) {
|
|
if (!Objects.equals(sendRed.get("code"), 200)) {
|
|
return sendRed;
|
|
return sendRed;
|
|
}
|
|
}
|
|
- return sendIntegralReward(param,user, log, config);
|
|
|
|
|
|
+ return sendIntegralReward(param,user, watchLog, config);
|
|
default:
|
|
default:
|
|
return R.error("参数错误!");
|
|
return R.error("参数错误!");
|
|
}
|
|
}
|
|
@@ -1068,6 +1059,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public R sendRewardByFsUser(FsCourseSendRewardUParam param) {
|
|
public R sendRewardByFsUser(FsCourseSendRewardUParam param) {
|
|
|
|
+ log.info("进入用户判断");
|
|
FsUser user = fsUserMapper.selectFsUserByUserId(param.getUserId());
|
|
FsUser user = fsUserMapper.selectFsUserByUserId(param.getUserId());
|
|
if (user == null){
|
|
if (user == null){
|
|
return R.error("未识别到用户信息");
|
|
return R.error("未识别到用户信息");
|
|
@@ -1143,7 +1135,7 @@ 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) {
|
|
-
|
|
|
|
|
|
+ logger.info("进入发放红包");
|
|
// 确定红包金额
|
|
// 确定红包金额
|
|
BigDecimal amount = BigDecimal.ZERO;
|
|
BigDecimal amount = BigDecimal.ZERO;
|
|
FsUserCourseVideoRedPackage redPackage = fsUserCourseVideoRedPackageMapper.selectRedPacketByCompanyId(param.getVideoId(), param.getCompanyId(), param.getPeriodId());
|
|
FsUserCourseVideoRedPackage redPackage = fsUserCourseVideoRedPackageMapper.selectRedPacketByCompanyId(param.getVideoId(), param.getCompanyId(), param.getPeriodId());
|
|
@@ -1156,23 +1148,46 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
|
|
|
// 准备发送红包参数
|
|
// 准备发送红包参数
|
|
WxSendRedPacketParam packetParam = new WxSendRedPacketParam();
|
|
WxSendRedPacketParam packetParam = new WxSendRedPacketParam();
|
|
- packetParam.setOpenId(user.getMpOpenId());
|
|
|
|
- // 来源是小程序切换openId
|
|
|
|
- if (param.getSource() == 2) {
|
|
|
|
- //处理多小程序问题
|
|
|
|
|
|
+
|
|
|
|
+ if (user.getMpOpenId()!=null&&!isNewWxMerchant){
|
|
|
|
+ packetParam.setOpenId(user.getMpOpenId());
|
|
|
|
+ }else {
|
|
|
|
+ //修复数据
|
|
FsUserWx fsUserWx = fsUserWxService.selectByAppIdAndUserId(param.getAppId(),user.getUserId(),1);
|
|
FsUserWx fsUserWx = fsUserWxService.selectByAppIdAndUserId(param.getAppId(),user.getUserId(),1);
|
|
if (fsUserWx ==null){
|
|
if (fsUserWx ==null){
|
|
|
|
+ if (user.getCourseMaOpenId()==null){
|
|
|
|
+ logger.error(" 【转账openId参数错误】:{}", user.getUserId());
|
|
|
|
+ return R.error("openId参数错误,请清理缓存后重新授权!");
|
|
|
|
+ }
|
|
|
|
+ packetParam.setOpenId(user.getCourseMaOpenId());
|
|
try {
|
|
try {
|
|
handleFsUserWx(user,param.getAppId());
|
|
handleFsUserWx(user,param.getAppId());
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
- logger.error("【更新或插入用户与小程序的绑定关系失败】:{}", user.getUserId());
|
|
|
|
|
|
+ logger.error(" 【更新或插入用户与小程序的绑定关系失败】:{}", user.getUserId(),e);
|
|
}
|
|
}
|
|
|
|
+
|
|
}else {
|
|
}else {
|
|
packetParam.setOpenId(fsUserWx.getOpenId());
|
|
packetParam.setOpenId(fsUserWx.getOpenId());
|
|
}
|
|
}
|
|
- //查出公司绑定openid并赋值
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// packetParam.setOpenId(user.getMpOpenId());
|
|
|
|
+// // 来源是小程序切换openId
|
|
|
|
+// if (param.getSource() == 2) {
|
|
|
|
+// //处理多小程序问题
|
|
|
|
+// FsUserWx fsUserWx = fsUserWxService.selectByAppIdAndUserId(param.getAppId(),user.getUserId(),1);
|
|
|
|
+// if (fsUserWx ==null){
|
|
|
|
+// try {
|
|
|
|
+// handleFsUserWx(user,param.getAppId());
|
|
|
|
+// }catch (Exception e){
|
|
|
|
+// logger.error("【更新或插入用户与小程序的绑定关系失败】:{}", user.getUserId());
|
|
|
|
+// }
|
|
|
|
+// }else {
|
|
|
|
+// packetParam.setOpenId(fsUserWx.getOpenId());
|
|
|
|
+// }
|
|
|
|
+// //查出公司绑定openid并赋值
|
|
|
|
+// }
|
|
|
|
+
|
|
//判断服务号配置是否存在
|
|
//判断服务号配置是否存在
|
|
if (StringUtils.isNotEmpty(config.getMpAppId())){
|
|
if (StringUtils.isNotEmpty(config.getMpAppId())){
|
|
packetParam.setMpAppId(config.getMpAppId());
|
|
packetParam.setMpAppId(config.getMpAppId());
|
|
@@ -1187,28 +1202,8 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
logger.info("红包金额 {},红包商户号 {}",amount,packetParam);
|
|
logger.info("红包金额 {},红包商户号 {}",amount,packetParam);
|
|
//2025.6.19 红包金额为0的时候
|
|
//2025.6.19 红包金额为0的时候
|
|
if (amount.compareTo(BigDecimal.ZERO)>0){
|
|
if (amount.compareTo(BigDecimal.ZERO)>0){
|
|
-
|
|
|
|
- //---------------发红包前先判断润天账户余额是否足够---------
|
|
|
|
- RLock lock = redissonClient.getLock(REDPACKET_POOL_LOCK);
|
|
|
|
- try{
|
|
|
|
- boolean locked = lock.tryLock(3, 10, TimeUnit.SECONDS);
|
|
|
|
-
|
|
|
|
- if (!locked) {
|
|
|
|
- logger.error("获取锁失败");
|
|
|
|
- return R.error("[红包领取] 系统繁忙,请重试!");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 发送红包
|
|
|
|
- return sendRedPacketRewardToUser(param, log, config, packetParam, amount);
|
|
|
|
-
|
|
|
|
- }catch (Exception e){
|
|
|
|
- logger.error("领取红包失败原因:{}", ExceptionUtils.getFullStackTrace(e),e);
|
|
|
|
- throw new RuntimeException(e);
|
|
|
|
- }finally {
|
|
|
|
- if (lock.isHeldByCurrentThread()) {
|
|
|
|
- lock.unlock();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ // 发送红包
|
|
|
|
+ return sendRedPacketRewardToUser(param, log, config, packetParam, amount);
|
|
} else {
|
|
} else {
|
|
FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
// 添加红包记录
|
|
// 添加红包记录
|
|
@@ -1236,25 +1231,6 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
|
|
|
private R sendRedPacketRewardToUser(FsCourseSendRewardUParam param, FsCourseWatchLog log, CourseConfig config, WxSendRedPacketParam packetParam, BigDecimal amount) {
|
|
private R sendRedPacketRewardToUser(FsCourseSendRewardUParam param, FsCourseWatchLog log, CourseConfig config, WxSendRedPacketParam packetParam, BigDecimal amount) {
|
|
|
|
|
|
- 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);
|
|
R sendRedPacket = paymentService.sendRedPacket(packetParam);
|
|
@@ -1280,23 +1256,12 @@ 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());
|
|
- if(StringUtils.equals(ENABLE_RED_PACK_ACCOUNT,"1")) {
|
|
|
|
- redPacketLog.setAccBalanceBefore(companyMoney);
|
|
|
|
- redPacketLog.setAccBalanceAfter(companyMoney.subtract(amount));
|
|
|
|
- }
|
|
|
|
|
|
|
|
redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
// 更新观看记录的奖励类型
|
|
// 更新观看记录的奖励类型
|
|
log.setRewardType(config.getRewardType());
|
|
log.setRewardType(config.getRewardType());
|
|
courseWatchLogMapper.updateFsCourseWatchLog(log);
|
|
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;
|
|
return sendRedPacket;
|
|
} else {
|
|
} else {
|
|
return R.error("奖励发送失败,请联系客服");
|
|
return R.error("奖励发送失败,请联系客服");
|
|
@@ -1304,6 +1269,8 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
private void handleFsUserWx(FsUser user, String appId) {
|
|
private void handleFsUserWx(FsUser user, String appId) {
|
|
FsUserWx fsUserWx = new FsUserWx();
|
|
FsUserWx fsUserWx = new FsUserWx();
|
|
fsUserWx.setType(1);
|
|
fsUserWx.setType(1);
|
|
@@ -1408,92 +1375,43 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
return R.error("服务商余额不足,请联系群主服务器充值!");
|
|
return R.error("服务商余额不足,请联系群主服务器充值!");
|
|
}
|
|
}
|
|
|
|
|
|
- //---------------发红包前先判断润天账户余额是否足够---------
|
|
|
|
- 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();
|
|
|
|
|
|
+ // 发送红包
|
|
|
|
+ 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());
|
|
|
|
+
|
|
|
|
+ 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();
|
|
// 添加红包记录
|
|
// 添加红包记录
|
|
@@ -1651,6 +1569,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
redPacketLog.setAmount(BigDecimal.valueOf(config.getAnswerIntegral()).divide(BigDecimal.valueOf(1000)));
|
|
redPacketLog.setAmount(BigDecimal.valueOf(config.getAnswerIntegral()).divide(BigDecimal.valueOf(1000)));
|
|
redPacketLog.setRemark("点播答题领取积分转");
|
|
redPacketLog.setRemark("点播答题领取积分转");
|
|
redPacketLog.setWatchLogId(log.getLogId() !=null ? log.getLogId() : null);
|
|
redPacketLog.setWatchLogId(log.getLogId() !=null ? log.getLogId() : null);
|
|
|
|
+ redPacketLog.setPeriodId(param.getPeriodId());
|
|
redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog);
|
|
return R.ok("奖励发放成功").put("rewardType",config.getRewardType());
|
|
return R.ok("奖励发放成功").put("rewardType",config.getRewardType());
|
|
}
|
|
}
|
|
@@ -1792,7 +1711,6 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
return ResponseResult.fail(504, "课程配置错误,项目归属为空,课程ID: " + param.getCourseId());
|
|
return ResponseResult.fail(504, "课程配置错误,项目归属为空,课程ID: " + param.getCourseId());
|
|
}
|
|
}
|
|
|
|
|
|
- // 查询【用户-项目】关系
|
|
|
|
FsUserCompanyUser userCompanyUser = userCompanyUserService.selectByUserIdAndProjectId(fsUser.getUserId(), courseProject);
|
|
FsUserCompanyUser userCompanyUser = userCompanyUserService.selectByUserIdAndProjectId(fsUser.getUserId(), courseProject);
|
|
|
|
|
|
// 添加逻辑:如果存在fs_user表数据,但是又不存在fs_user_company_user表,则表示是以前企微看课的,需要手动绑定
|
|
// 添加逻辑:如果存在fs_user表数据,但是又不存在fs_user_company_user表,则表示是以前企微看课的,需要手动绑定
|
|
@@ -1915,6 +1833,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
LocalDateTime effectiveEndTime = companyUserEndDateTime != null ?
|
|
LocalDateTime effectiveEndTime = companyUserEndDateTime != null ?
|
|
companyUserEndDateTime : periodDays.getEndDateTime();
|
|
companyUserEndDateTime : periodDays.getEndDateTime();
|
|
// 检查时间范围和状态
|
|
// 检查时间范围和状态
|
|
|
|
+ log.error("传入参数:开始时间:{},结束时间:{},periodDays={}",effectiveStartTime,effectiveEndTime,periodDays);
|
|
return DateUtil.isWithinRangeSafe(LocalDateTime.now(), effectiveStartTime, effectiveEndTime)&& periodDays.getStatus() == 1;
|
|
return DateUtil.isWithinRangeSafe(LocalDateTime.now(), effectiveStartTime, effectiveEndTime)&& periodDays.getStatus() == 1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2861,3 +2780,4 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|