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