Просмотр исходного кода

益寿缘app-优化App奖品发红包逻辑

cgp 1 неделя назад
Родитель
Сommit
6ce066ffa8

+ 8 - 2
fs-service/src/main/java/com/fs/his/domain/FsUserRewards.java

@@ -102,11 +102,17 @@ public class FsUserRewards {
      * 公司id 当前分支是益寿缘分支不做区分默认为1
      * */
     @TableField(exist = false)
-    private Long companyId=1L;
+    private Long companyId;
 
     /**
      * 销售id 当前分支是益寿缘分支不做区分默认为1
      * */
     @TableField(exist = false)
-    private Long companyUserId=1L;
+    private Long companyUserId;
+
+    /**
+     * AppId
+     * */
+    @TableField(exist = false)
+    private String appId;
 }

+ 5 - 0
fs-service/src/main/java/com/fs/his/service/IFsStorePaymentService.java

@@ -96,6 +96,11 @@ public interface IFsStorePaymentService
 
     R sendRedPacket(WxSendRedPacketParam param);
 
+    /**
+     * 发送App奖品红包
+     * */
+    R sendRedPacketAppReward(WxSendRedPacketParam param);
+
     R sendRedPacketV3(WxSendRedPacketParam param);
 
     String transferNotify(String notifyData, HttpServletRequest request);

+ 31 - 15
fs-service/src/main/java/com/fs/his/service/impl/FsStorePaymentServiceImpl.java

@@ -575,27 +575,43 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
         if (result.getMsg().equals("商家余额不足") && param.getRedPacketMode() == 1) {
             redisCache.incr("sys_config:redPacket.config.newCount",1L);
         }
-//            String backConfigStr = configService.selectConfigByKey("redPacket.config.back");
-//            if (StringUtils.isNotBlank(backConfigStr)) {
-//                List<RedPacketConfig> backConfigList = JSONArray.parseArray(backConfigStr, RedPacketConfig.class);
-//                for (RedPacketConfig redPacketConfig : backConfigList) {
-//                    if (config.getIsNew() != null && config.getIsNew() == 1) {
-//                        result = sendRedPacketV3Internal(param, redPacketConfig);
-//                    } else {
-//                        result = sendRedPacketLegacyInternal(param, redPacketConfig);
-//                    }
-//                    if (result.isSuccess()) {
-//                        break;
-//                    }
-//                }
-//            }
-//        }
         result.put("mchId", config.getMchId() + "");
         result.put("isNew", config.getIsNew());
         logger.info("红包返回:{}", result);
         return result;
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
+    public R sendRedPacketAppReward(WxSendRedPacketParam param) {
+        String json;
+        RedPacketConfig config = new RedPacketConfig();
+        // 根据红包模式获取配置
+        json = redisCache.getCacheObject("sys_config:redPacket.config.new");
+        if (StringUtil.isNullOrEmpty(json) || json.isEmpty()) {
+            json = configService.selectConfigByKey("redPacket.config");
+        }
+        config = JSONUtil.toBean(json, RedPacketConfig.class);
+        //这里暂时写成益寿缘App的appId常量
+        config.setAppId(param.getAppId());
+        logger.info("app奖品红包最终传参 {}", config);
+        // 根据 isNew 判断使用哪种发红包方式
+        R result;
+        if (config.getIsNew() != null && config.getIsNew() == 1) {
+            result = sendRedPacketV3Internal(param, config);
+        } else {
+            result = sendRedPacketLegacyInternal(param, config);
+        }
+
+        if (result.getMsg().equals("商家余额不足") && param.getRedPacketMode() == 1) {
+            redisCache.incr("sys_config:redPacket.config.newCount",1L);
+        }
+        result.put("mchId", config.getMchId());
+        result.put("isNew", config.getIsNew());
+        logger.info("红包返回:{}", result);
+        return result;
+    }
+
     private static long getExpireSeconds() {
         Calendar calendar = Calendar.getInstance();
         calendar.add(Calendar.DAY_OF_YEAR, 1);

+ 81 - 5
fs-service/src/main/java/com/fs/his/strategy/impl/FirstLoginRedPacketStrategy.java

@@ -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;
     }

+ 3 - 3
fs-service/src/main/java/com/fs/his/strategy/impl/WatchCourseRedPacketStrategy.java

@@ -39,7 +39,7 @@ public class WatchCourseRedPacketStrategy 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;
@@ -80,8 +80,8 @@ public class WatchCourseRedPacketStrategy implements RewardStrategy {
      */
     private WxSendRedPacketParam buildRedPacketParam(FsUserRewards reward, FsUser fsUser) {
         WxSendRedPacketParam param = new WxSendRedPacketParam();
-        param.setAppId("");
-        param.setOpenId(fsUser.getMpOpenId());
+        param.setAppId(reward.getAppId());
+        param.setOpenId(fsUser.getMaOpenId());
         param.setRedPacketMode(1);
         param.setCompanyId(reward.getCompanyId());
         param.setUser(fsUser);