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

益寿缘app-完善首次注册弹窗接口

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

+ 12 - 1
fs-service/src/main/java/com/fs/app/domain/FsAppRole.java

@@ -1,7 +1,8 @@
 package com.fs.app.domain;
 
 import java.math.BigDecimal;
-import com.baomidou.mybatisplus.annotation.TableId;
+
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.fs.common.annotation.Excel;
 import lombok.Data;
 import com.fs.common.core.domain.BaseEntity;
@@ -96,5 +97,15 @@ public class FsAppRole extends BaseEntity{
     @Excel(name = "角色商城id")
     private String roleStoreProductIds;
 
+    /** 商品名称*/
+    @TableField(exist = false)
+    private String goodsName;
+
+    /** 商品图片*/
+    @TableField(exist = false)
+    private String goodsUrl;
 
+    /** 是否显示 true:显示,false:隐藏*/
+    @TableField(exist = false)
+    private boolean isShow=false;
 }

+ 8 - 0
fs-service/src/main/java/com/fs/app/mapper/FsAppRoleMapper.java

@@ -19,6 +19,14 @@ public interface FsAppRoleMapper extends BaseMapper<FsAppRole>{
      */
     FsAppRole selectFsAppRoleById(Long id);
 
+    /**
+     * 查询APP角色以及奖品
+     *
+     * @param id APP角色主键
+     * @return APP角色
+     */
+    FsAppRole selectFsAppRoleAndRewardsById(Long id);
+
     /**
      * 查询APP角色列表
      * 

+ 12 - 0
fs-service/src/main/java/com/fs/his/domain/FsUserRewards.java

@@ -81,6 +81,18 @@ public class FsUserRewards {
      */
     private Integer isFirstLogin;
 
+    /** 商品名称*/
+    private String goodsName;
+
+    /** 商品图片*/
+    private String goodsUrl;
+
+    /**
+     * 用户领取奖品的地址id
+     * */
+    @TableField(exist = false)
+    private Long addressId;
+
     /**
      * 公司id 当前分支是益寿缘分支不做区分默认为1
      * */

+ 2 - 1
fs-service/src/main/java/com/fs/his/service/IAppUserRewardService.java

@@ -23,8 +23,9 @@ public interface IAppUserRewardService {
      * 用户领取奖励
      * @param fsUserId 用户ID
      * @param rewardsId 奖品ID
+     * @param addressId 地址ID
      * */
-    public void claimRewards(Long fsUserId,Long rewardsId);
+    public void claimRewards(Long fsUserId,Long rewardsId,Long addressId);
 
     /**
      * 判断指定用户是否满足首次注册登录的条件

+ 43 - 16
fs-service/src/main/java/com/fs/his/service/impl/AppUserRewardServiceImpl.java

@@ -1,6 +1,5 @@
 package com.fs.his.service.impl;
 
-import cn.hutool.core.util.RandomUtil;
 import com.fs.app.domain.FsAppRole;
 import com.fs.app.mapper.FsAppRoleMapper;
 import com.fs.common.exception.CustomException;
@@ -49,13 +48,20 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
         String activityType = ActivityTypeEnum.FIRST_LOGIN.getCode();
 
         // TODO 根据配置获取奖品类型
-        Integer rewardType = RandomUtil.randomInt(1, 4);
-        Integer productType=1;
-        Long goodsId=1L;
-        BigDecimal rewardAmount=new BigDecimal("10");
-        Long rewardPoints=600L;
+        FsAppRole appRoleConfig = getAppRoleConfig(fsUserId);
+        if (appRoleConfig==null){
+            log.info("当前用户未匹配到App奖励角色");
+            return;
+        }
+        Integer rewardType = appRoleConfig.getCourseRewardType();
+        Integer productType=appRoleConfig.getCourseProductType();
+        Long goodsId=appRoleConfig.getCourseProductId();
+        BigDecimal rewardAmount=appRoleConfig.getCourseRedPacket();
+        Long rewardPoints=appRoleConfig.getCourseIntegral().longValue();
+        String goodsName = appRoleConfig.getGoodsName();
+        String goodsUrl = appRoleConfig.getGoodsUrl();
         // 构建奖品记录
-        FsUserRewards reward = buildFirstLoginReward(fsUserId, activityType, rewardType, productType, goodsId, rewardAmount,rewardPoints);
+        FsUserRewards reward = buildAppUserReward(fsUserId, activityType, rewardType, productType, goodsId, rewardAmount,rewardPoints,goodsName,goodsUrl);
         try {
             // 插入奖品表
             int insertResult = rewardsMapper.insertFsUserRewards(reward);
@@ -100,7 +106,7 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
      * @param rewardAmount 红包
      * @param rewardPoints 积分
      * */
-    private FsUserRewards buildFirstLoginReward(Long fsUserId, String activityType, Integer rewardType, Integer productType, Long goodsId,BigDecimal rewardAmount,Long rewardPoints) {
+    private FsUserRewards buildAppUserReward(Long fsUserId, String activityType, Integer rewardType, Integer productType, Long goodsId,BigDecimal rewardAmount,Long rewardPoints,String goodsName,String goodsUrl) {
         FsUserRewards reward = new FsUserRewards();
         reward.setFsUserId(fsUserId);
         reward.setActivityType(activityType);
@@ -118,6 +124,8 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
         }else if (rewardType == 3){//实物商品
             reward.setProductType(productType); // 1-药品 2-套餐包
             reward.setGoodsId(goodsId);    // 药品/套餐包id
+            reward.setGoodsName(goodsName);
+            reward.setGoodsUrl(goodsUrl);
         }
         return reward;
     }
@@ -127,13 +135,20 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
     public void addUserWatchCourseRewards(Long fsUserId) {
         String activityType = ActivityTypeEnum.WATCH_COURSE.getCode();
         // TODO 根据配置获取奖品类型、金额等
-        Integer rewardType = RandomUtil.randomInt(1, 4);
-        Integer productType=1;
-        Long goodsId=1L;
-        BigDecimal rewardAmount=new BigDecimal("10");
-        Long rewardPoints=600L;
+        FsAppRole appRoleConfig = getAppRoleConfig(fsUserId);
+        if (appRoleConfig==null){
+            log.info("当前用户未匹配到App奖励角色");
+            return;
+        }
+        Integer rewardType = appRoleConfig.getRegisterRewardType();
+        Integer productType=appRoleConfig.getRegisterProductType();
+        Long goodsId=appRoleConfig.getRegisterProductId();
+        BigDecimal rewardAmount=appRoleConfig.getRegisterRedPacket();
+        Long rewardPoints=appRoleConfig.getRegisterIntegral().longValue();
+        String goodsName = appRoleConfig.getGoodsName();
+        String goodsUrl = appRoleConfig.getGoodsUrl();
         // 构建奖品记录
-        FsUserRewards reward = buildFirstLoginReward(fsUserId, activityType, rewardType, productType, goodsId, rewardAmount,rewardPoints);
+        FsUserRewards reward = buildAppUserReward(fsUserId, activityType, rewardType, productType, goodsId, rewardAmount,rewardPoints,goodsName,goodsUrl);
         // 插入奖品表
         int insertResult = rewardsMapper.insertFsUserRewards(reward);
         if (insertResult > 0) {
@@ -146,7 +161,7 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
     }
 
     @Override
-    public void claimRewards(Long fsUserId,Long rewardsId) {
+    public void claimRewards(Long fsUserId,Long rewardsId,Long addressId) {
         FsUserRewards reward = rewardsMapper.selectByUserIdAndRewardsId(fsUserId, rewardsId);
         if (reward==null){
             log.info("用户:{}没有奖品:{}", fsUserId, rewardsId);
@@ -161,6 +176,7 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
                 return;
             }
         }
+        reward.setAddressId(addressId);
         //执行奖品领取逻辑
         RewardStrategy strategy = strategyFactory.getStrategy(reward.getActivityType(), reward.getRewardType());
         RewardResult result = strategy.process(reward);
@@ -208,7 +224,8 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
         FsUserRewards queryReward = rewardsMapper.selectByUserIdAndActivityType(fsUserId, activityType);
         if (queryReward == null) {
             //TODO 查询当前用户对应的角色配置返回红包、积分、商品弹窗信息
-            fsAppRole = appRoleMapper.selectFsAppRoleById(1L);
+            fsAppRole = appRoleMapper.selectFsAppRoleAndRewardsById(1L);
+            fsAppRole.setShow(true);//弹窗显示
             return fsAppRole;
         }
         return fsAppRole;
@@ -225,6 +242,7 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
             //TODO 查询当前用户对应的角色配置返回红包、积分、商品弹窗信息(还需要判断当前用户是否满足看课奖励)
             fsAppRole = appRoleMapper.selectFsAppRoleById(1L);
             //从缓存查询当前用户看课天数对比角色要求的看课天数,达标才返回
+            fsAppRole.setShow(true);//弹窗显示
             return fsAppRole;
         }
         return fsAppRole;
@@ -235,4 +253,13 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
         // TODO 实现过期判断逻辑
         return false;
     }
+    //根据用户id、角色id获取配置的奖品信息
+    private FsAppRole getAppRoleConfig(Long fsUserId){
+        //TODO 获取当前用户最高权重角色id
+        FsAppRole fsAppRole = appRoleMapper.selectFsAppRoleAndRewardsById(1L);
+        if (fsAppRole==null){
+            return null;
+        }
+        return fsAppRole;
+    }
 }

+ 4 - 2
fs-service/src/main/java/com/fs/his/strategy/impl/FirstLoginProductStrategy.java

@@ -7,7 +7,6 @@ import com.fs.his.domain.FsUserRewards;
 import com.fs.his.enums.ActivityTypeEnum;
 import com.fs.his.mapper.FsUserMapper;
 import com.fs.his.param.FsPackageOrderAddRewardsParam;
-import com.fs.his.param.FsPackageOrderCreateParam;
 import com.fs.his.service.IFsPackageOrderService;
 import com.fs.his.strategy.RewardResult;
 import com.fs.his.strategy.RewardStrategy;
@@ -32,7 +31,9 @@ public class FirstLoginProductStrategy implements RewardStrategy {
             if (fsUser == null) {
                 return RewardResult.fail("用户不存在");
             }
-
+            if (reward.getAddressId()==null){
+                return RewardResult.fail("请选择收货地址");
+            }
             // 调用创建0元订单接口
             FsPackageOrderAddRewardsParam param = buildOrderCreateParam(reward, fsUser);
             R result = packageOrderService.addAppPackageOrder(param);
@@ -72,6 +73,7 @@ public class FirstLoginProductStrategy implements RewardStrategy {
         param.setCompanyId(reward.getCompanyId());
         param.setCompanyUserId(reward.getCompanyUserId());
         param.setUserId(fsUser.getUserId());
+        param.setAddressId(reward.getAddressId());
         return param;
     }
 

+ 9 - 7
fs-service/src/main/java/com/fs/his/strategy/impl/WatchCourseProductStrategy.java

@@ -6,7 +6,7 @@ import com.fs.his.domain.FsUser;
 import com.fs.his.domain.FsUserRewards;
 import com.fs.his.enums.ActivityTypeEnum;
 import com.fs.his.mapper.FsUserMapper;
-import com.fs.his.param.FsPackageOrderCreateParam;
+import com.fs.his.param.FsPackageOrderAddRewardsParam;
 import com.fs.his.service.IFsPackageOrderService;
 import com.fs.his.strategy.RewardResult;
 import com.fs.his.strategy.RewardStrategy;
@@ -31,10 +31,12 @@ public class WatchCourseProductStrategy  implements RewardStrategy {
             if (fsUser == null) {
                 return RewardResult.fail("用户不存在");
             }
-
+            if (reward.getAddressId()==null){
+                return RewardResult.fail("请选择收货地址");
+            }
             // 调用创建0元订单接口
-            FsPackageOrderCreateParam param = buildOrderCreateParam(reward, fsUser);
-            R result = packageOrderService.createOrder1(param);
+            FsPackageOrderAddRewardsParam param = buildOrderCreateParam(reward, fsUser);
+            R result = packageOrderService.addAppPackageOrder(param);
 
             // 检查订单创建是否成功
             if (!result.isSuccess()) {
@@ -66,12 +68,12 @@ public class WatchCourseProductStrategy  implements RewardStrategy {
     /**
      * 构建创建订单参数
      */
-    private FsPackageOrderCreateParam buildOrderCreateParam(FsUserRewards reward, FsUser fsUser) {
-        FsPackageOrderCreateParam param = new FsPackageOrderCreateParam();
+    private FsPackageOrderAddRewardsParam buildOrderCreateParam(FsUserRewards reward, FsUser fsUser) {
+        FsPackageOrderAddRewardsParam param = new FsPackageOrderAddRewardsParam();
         param.setCompanyId(reward.getCompanyId());
         param.setCompanyUserId(reward.getCompanyUserId());
         param.setUserId(fsUser.getUserId());
-        param.setPackageId(reward.getGoodsId());
+        param.setAddressId(reward.getAddressId());
         return param;
     }
 

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

@@ -60,6 +60,6 @@ public class WatchCourseRedPacketStrategy implements RewardStrategy {
 
     @Override
     public Integer getRewardType() {
-        return 2;
+        return 1;
     }
 }

+ 30 - 1
fs-service/src/main/resources/mapper/app/FsAppRoleMapper.xml

@@ -62,7 +62,36 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectFsAppRoleVo"/>
         where id = #{id}
     </select>
-        
+    <select id="selectFsAppRoleAndRewardsById" resultType="com.fs.app.domain.FsAppRole">
+        SELECT far.id, far.role_name, far.register_reward_type, far.register_red_packet,
+               far.register_product_id, far.register_product_type, far.register_integral,
+               far.course_day, far.course_reward_type, far.course_red_packet,
+               far.course_integral, far.course_product_type, far.course_product_id,
+               far.course_need_day, far.course_reward_rule_type, far.course_reward_rule,
+               far.role_level, far.role_tags, far.role_package_product_ids,
+               far.role_store_product_ids, far.create_time, far.update_time,
+
+               -- 根据register_product_type选择不同的商品名称和图片
+               CASE
+                   WHEN far.register_product_type = 1 THEN fp.package_name
+                   WHEN far.register_product_type = 2 THEN fsps.product_name
+                   ELSE NULL
+                   END AS goodsName,
+
+               CASE
+                   WHEN far.register_product_type = 1 THEN fp.img_url
+                   WHEN far.register_product_type = 2 THEN fsps.image
+                   ELSE NULL
+                   END AS goodsUrl
+
+        FROM fs_app_role far
+                 LEFT JOIN fs_package fp ON far.register_product_type = 1
+            AND fp.package_id = far.register_product_id
+                 LEFT JOIN fs_store_product_scrm fsps ON far.register_product_type = 2
+            AND fsps.product_id = far.register_product_id
+        WHERE far.id = #{id}
+    </select>
+
     <insert id="insertFsAppRole" parameterType="FsAppRole" useGeneratedKeys="true" keyProperty="id">
         insert into fs_app_role
         <trim prefix="(" suffix=")" suffixOverrides=",">

+ 15 - 3
fs-service/src/main/resources/mapper/his/FsUserRewardsMapper.xml

@@ -15,6 +15,8 @@
         <result property="productType" column="product_type"/>
         <result property="rewardAmount" column="reward_amount"/>
         <result property="rewardPoints" column="reward_points"/>
+        <result property="goodsName" column="goods_name"/>
+        <result property="goodsUrl" column="goods_url"/>
         <result property="grantTime" column="grant_time"/>
         <result property="createTime" column="create_time"/>
         <result property="updateTime" column="update_time"/>
@@ -24,8 +26,8 @@
     <!-- 基础字段列表 -->
     <sql id="selectFsUserRewardsVo">
         select id, fs_user_id, activity_type, reward_type, status,
-               order_code, goods_id, product_type, reward_amount,reward_points,
-               grant_time, create_time, update_time, is_first_login
+               order_code, goods_id, product_type, reward_amount, reward_points,
+               goods_name, goods_url, grant_time, create_time, update_time, is_first_login
         from fs_user_rewards
     </sql>
 
@@ -81,6 +83,8 @@
             <if test="productType != null"> and product_type = #{productType}</if>
             <if test="rewardAmount != null"> and reward_amount = #{rewardAmount}</if>
             <if test="rewardPoints != null"> and reward_points = #{rewardPoints}</if>
+            <if test="goodsName != null and goodsName != ''"> and goods_name = #{goodsName}</if>
+            <if test="goodsUrl != null and goodsUrl != ''"> and goods_url = #{goodsUrl}</if>
             <if test="grantTime != null"> and grant_time = #{grantTime}</if>
             <if test="createTime != null"> and create_time = #{createTime}</if>
             <if test="updateTime != null"> and update_time = #{updateTime}</if>
@@ -102,8 +106,11 @@
             <if test="productType != null">product_type,</if>
             <if test="rewardAmount != null">reward_amount,</if>
             <if test="rewardPoints != null">reward_points,</if>
+            <if test="goodsName != null and goodsName != ''">goods_name,</if>
+            <if test="goodsUrl != null and goodsUrl != ''">goods_url,</if>
             <if test="grantTime != null">grant_time,</if>
             <if test="isFirstLogin != null">is_first_login,</if>
+            create_time,
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="fsUserId != null">#{fsUserId},</if>
@@ -115,12 +122,15 @@
             <if test="productType != null">#{productType},</if>
             <if test="rewardAmount != null">#{rewardAmount},</if>
             <if test="rewardPoints != null">#{rewardPoints},</if>
+            <if test="goodsName != null and goodsName != ''">#{goodsName},</if>
+            <if test="goodsUrl != null and goodsUrl != ''">#{goodsUrl},</if>
             <if test="grantTime != null">#{grantTime},</if>
             <if test="isFirstLogin != null">#{isFirstLogin},</if>
+            sysdate(),
         </trim>
     </insert>
 
-    <!-- 修改记录-->
+    <!-- 修改记录 -->
     <update id="updateFsUserRewards" parameterType="com.fs.his.domain.FsUserRewards">
         update fs_user_rewards
         <trim prefix="SET" suffixOverrides=",">
@@ -133,6 +143,8 @@
             <if test="productType != null">product_type = #{productType},</if>
             <if test="rewardAmount != null">reward_amount = #{rewardAmount},</if>
             <if test="rewardPoints != null">reward_points = #{rewardPoints},</if>
+            <if test="goodsName != null and goodsName != ''">goods_name = #{goodsName},</if>
+            <if test="goodsUrl != null and goodsUrl != ''">goods_url = #{goodsUrl},</if>
             <if test="grantTime != null">grant_time = #{grantTime},</if>
             <if test="isFirstLogin != null">is_first_login = #{isFirstLogin},</if>
             update_time = sysdate()

+ 10 - 4
fs-user-app/src/main/java/com/fs/app/controller/AppUserRewardController.java

@@ -23,6 +23,8 @@ import java.util.*;
 @RequestMapping(value="/app/reward")
 public class AppUserRewardController  extends AppBaseController{
 
+    private final static Long testUserId=700010L;
+
     @Autowired
     private IAppUserRewardService appUserRewardService;
 
@@ -38,11 +40,12 @@ public class AppUserRewardController  extends AppBaseController{
             return R.error("请登录");
         }
         Long fsUserId = Long.valueOf(loginUserId);
+//        Long fsUserId = testUserId;
         boolean rewardAdded = appUserRewardService.checkFirstLoginRewardStatus(fsUserId);
         if (rewardAdded) {
             //添加首次登录奖励
             appUserRewardService.addUserFirstLoginRewards(fsUserId);
-            log.info("用户首次登录奖励添加成功: userId={}", loginUserId);
+            log.info("用户首次登录奖励添加成功: userId={}", fsUserId);
         }
         return R.ok();
     }
@@ -73,13 +76,15 @@ public class AppUserRewardController  extends AppBaseController{
      */
     @Login
     @ApiOperation("查询用户的奖品列表")
-    @GetMapping("/getMyRewardList")
+    @PostMapping("/getMyRewardList")
     public TableDataInfo getMyRewardList(@RequestBody FsUserRewards queryRewards) {
         String loginUserId = getUserId();
+//        String loginUserId = String.valueOf(testUserId);
         if (StringUtils.isEmpty(loginUserId)){
             return getDataTable(Collections.emptyList());
         }
         queryRewards.setFsUserId(Long.valueOf(loginUserId));
+        queryRewards.setFsUserId(Long.valueOf(loginUserId));
         startPage();
         List<FsUserRewards> list = appUserRewardService.getMyRewardList(queryRewards);
         if (CollectionUtils.isEmpty(list)){
@@ -93,12 +98,13 @@ public class AppUserRewardController  extends AppBaseController{
     @Login
     @ApiOperation("奖品列表用户领取奖励")
     @PostMapping("/claim")
-    public R claimRewards(@RequestParam("rewardsId") Long rewardsId) {
+    public R claimRewards(@RequestParam("rewardsId") Long rewardsId,
+                          @RequestParam(value = "addressId", required = false) Long addressId) {//领取商品时必传收货地址id
         String loginUserId = getUserId();
         if (StringUtils.isEmpty(loginUserId)){
             return R.error("请登录");
         }
-        appUserRewardService.claimRewards(Long.valueOf(loginUserId),rewardsId);
+        appUserRewardService.claimRewards(Long.valueOf(loginUserId),rewardsId,addressId);
         return R.ok();
     }