|
|
@@ -1,9 +1,19 @@
|
|
|
package com.fs.his.strategy.impl;
|
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.course.config.CourseConfig;
|
|
|
+import com.fs.course.domain.FsCourseAnswerLogs;
|
|
|
import com.fs.course.domain.FsCourseRedPacketLog;
|
|
|
+import com.fs.course.domain.FsCourseWatchLog;
|
|
|
+import com.fs.course.domain.FsUserCourseVideo;
|
|
|
+import com.fs.course.mapper.FsCourseAnswerLogsMapper;
|
|
|
import com.fs.course.mapper.FsCourseRedPacketLogMapper;
|
|
|
+import com.fs.course.mapper.FsCourseWatchLogMapper;
|
|
|
+import com.fs.course.mapper.FsUserCourseVideoMapper;
|
|
|
+import com.fs.course.param.FsCourseSendRewardUParam;
|
|
|
import com.fs.his.domain.FsUser;
|
|
|
import com.fs.his.domain.FsUserRewards;
|
|
|
import com.fs.his.enums.ActivityTypeEnum;
|
|
|
@@ -12,12 +22,14 @@ import com.fs.his.param.WxSendRedPacketParam;
|
|
|
import com.fs.his.service.IFsStorePaymentService;
|
|
|
import com.fs.his.strategy.RewardResult;
|
|
|
import com.fs.his.strategy.RewardStrategy;
|
|
|
+import com.fs.system.service.ISysConfigService;
|
|
|
import com.github.binarywang.wxpay.bean.transfer.TransferBillsResult;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.Date;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
@@ -29,8 +41,20 @@ public class FirstLoginRedPacketStrategy implements RewardStrategy {
|
|
|
@Autowired
|
|
|
private IFsStorePaymentService fsStorePaymentService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FsCourseWatchLogMapper courseWatchLogMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsCourseAnswerLogsMapper courseAnswerLogsMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private FsCourseRedPacketLogMapper redPacketLogMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserCourseVideoMapper fsUserCourseVideoMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysConfigService configService;
|
|
|
@Override
|
|
|
public RewardResult process(FsUserRewards reward) {
|
|
|
log.info("处理首次登录红包发放: rewardId={}", reward.getId());
|
|
|
@@ -39,7 +63,7 @@ public class FirstLoginRedPacketStrategy implements RewardStrategy {
|
|
|
if (fsUser!=null){
|
|
|
WxSendRedPacketParam param=buildRedPacketParam(reward, fsUser);
|
|
|
//调用发送红包接口逻辑
|
|
|
- R sendRedPacket = fsStorePaymentService.sendRedPacket(param);
|
|
|
+ R sendRedPacket = fsStorePaymentService.sendRedPacketAppReward(param);
|
|
|
if (sendRedPacket.get("code").equals(200)) {
|
|
|
FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog();
|
|
|
TransferBillsResult transferBillsResult;
|
|
|
@@ -74,17 +98,69 @@ public class FirstLoginRedPacketStrategy implements RewardStrategy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public R sendRewardByFsUser(FsCourseSendRewardUParam param) {
|
|
|
+ FsUser user = fsUserMapper.selectFsUserByUserId(param.getUserId());
|
|
|
+ if (user == null){
|
|
|
+ return R.error("未识别到用户信息");
|
|
|
+ }
|
|
|
+ FsCourseWatchLog watchLog = courseWatchLogMapper.getWatchCourseVideoByFsUser(param.getUserId(), param.getVideoId(), param.getCompanyUserId());
|
|
|
+ if (watchLog == null) {
|
|
|
+ return R.error("无记录");
|
|
|
+ }
|
|
|
+
|
|
|
+ FsCourseAnswerLogs rightLog = courseAnswerLogsMapper.selectRightLogByCourseVideo(param.getVideoId(), param.getUserId(), param.getQwUserId());
|
|
|
+
|
|
|
+ if (rightLog == null) {
|
|
|
+ log.error("未答题:{}",param.getUserId());
|
|
|
+ return R.error("未答题");
|
|
|
+ }
|
|
|
+ if (watchLog.getRewardType() != null ) {
|
|
|
+ if (watchLog.getRewardType() == 1){
|
|
|
+ FsCourseRedPacketLog fsCourseRedPacketLog = redPacketLogMapper.selectUserFsCourseRedPacketLog(param.getVideoId(), param.getUserId(),param.getPeriodId());
|
|
|
+ if(fsCourseRedPacketLog != null && fsCourseRedPacketLog.getStatus() == 1) {
|
|
|
+ return R.error("已领取该课程奖励,不可重复领取!");
|
|
|
+ }
|
|
|
+ if(fsCourseRedPacketLog != null && fsCourseRedPacketLog.getStatus() == 0) {
|
|
|
+ if(StringUtils.isNotEmpty(fsCourseRedPacketLog.getResult())){
|
|
|
+ R r = JSON.parseObject(fsCourseRedPacketLog.getResult(), R.class);
|
|
|
+ return r;
|
|
|
+ } else {
|
|
|
+ return R.error("操作频繁,请稍后再试!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if (watchLog.getRewardType() == 2){
|
|
|
+ return R.error("已领取该课程奖励,不可重复领取!");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 获取视频信息
|
|
|
+ FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
|
|
|
+
|
|
|
+ // 获取配置信息
|
|
|
+ String json = configService.selectConfigByKey("course.config");
|
|
|
+ CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
+ // 红包奖励
|
|
|
+ //return sendRedPacketRewardFsUser(param, user, watchLog, video, config);
|
|
|
+ return new R();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 构建红包参数
|
|
|
*/
|
|
|
private WxSendRedPacketParam buildRedPacketParam(FsUserRewards reward, FsUser fsUser) {
|
|
|
WxSendRedPacketParam param = new WxSendRedPacketParam();
|
|
|
- param.setAppId("");
|
|
|
- param.setOpenId(fsUser.getMpOpenId());
|
|
|
- param.setRedPacketMode(1);
|
|
|
+ param.setAppId("wxd10af32266cf4566");
|
|
|
+ param.setOpenId(fsUser.getMaOpenId());
|
|
|
+ param.setRedPacketMode(1);//1:为总公司
|
|
|
param.setCompanyId(reward.getCompanyId());
|
|
|
param.setUser(fsUser);
|
|
|
- param.setSource(2);
|
|
|
+ param.setSource(1);
|
|
|
param.setAmount(reward.getRewardAmount());
|
|
|
return param;
|
|
|
}
|