|
@@ -15,6 +15,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.yami.shop.bean.enums.ScoreLogType;
|
|
|
import com.yami.shop.bean.event.UpdateUserScoreEvent;
|
|
|
+import com.yami.shop.bean.model.PointsRecord;
|
|
|
import com.yami.shop.bean.param.ScoreExpireParam;
|
|
|
import com.yami.shop.common.bean.SysConfig;
|
|
|
import com.yami.shop.bean.model.UserExtension;
|
|
@@ -24,8 +25,7 @@ import com.yami.shop.common.util.PageParam;
|
|
|
import com.yami.shop.security.api.util.SecurityUtils;
|
|
|
import com.yami.shop.service.SysConfigService;
|
|
|
import com.yami.shop.service.UserExtensionService;
|
|
|
-import com.yami.shop.user.comment.dto.ScoreDataDto;
|
|
|
-import com.yami.shop.user.comment.model.UserLevel;
|
|
|
+import com.yami.shop.bean.dto.ScoreDataDto;
|
|
|
import com.yami.shop.user.comment.model.UserScoreDetail;
|
|
|
import com.yami.shop.user.comment.model.UserScoreLog;
|
|
|
import com.yami.shop.user.comment.service.UserLevelService;
|
|
@@ -37,13 +37,12 @@ import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+
|
|
|
/**
|
|
|
* 用户积分信息管理实现
|
|
|
*
|
|
@@ -59,133 +58,41 @@ public class UserScoreController {
|
|
|
|
|
|
private final UserScoreLogService scoreLogService;
|
|
|
private final UserScoreDetailService userScoreDetailService;
|
|
|
- private final ApplicationContext applicationContext;
|
|
|
private final SysConfigService sysConfigService;
|
|
|
- private final UserExtensionService userExtensionService;
|
|
|
- private final UserLevelService userLevelService;
|
|
|
-
|
|
|
-
|
|
|
- @GetMapping("/updateUserScore")
|
|
|
- @ApiOperation(value = "积分签到", notes = "积分签到")
|
|
|
- public ResponseEntity<String> updateUserScore() {
|
|
|
- String userId = SecurityUtils.getUser().getUserId();
|
|
|
- ScoreConfigParam scoreParam = sysConfigService.getSysConfigObject(Constant.SCORE_CONFIG, ScoreConfigParam.class);
|
|
|
- //签到,计算连续签到日期
|
|
|
- if(isSignIn(userId)){
|
|
|
- return ResponseEntity.ok("今天已经签到过了,请明天再试!");
|
|
|
- }
|
|
|
- //根据逗号分隔
|
|
|
- String[] signInScore = scoreParam.getSignInScoreString().split(StrUtil.COMMA);
|
|
|
- Integer count = getCount(userId);
|
|
|
- count++;
|
|
|
- int score = Integer.parseInt(signInScore[count - 1]);
|
|
|
- String remarks = "签到第" + count + "天获取的积分";
|
|
|
- applicationContext.publishEvent(new UpdateUserScoreEvent(ScoreLogType.SIGN_IN.value(),score,1,
|
|
|
- null, remarks,userId));
|
|
|
- return ResponseEntity.ok("领取积分成功");
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 获取数据库的签到记录记录
|
|
|
- * @param userId
|
|
|
- * @return
|
|
|
- */
|
|
|
- private Integer getCount(String userId) {
|
|
|
- Integer count = scoreLogService.getConsecutiveDays(userId);
|
|
|
- //如果没有记录就是第一天签到
|
|
|
- if(count == null){
|
|
|
- count = 0;
|
|
|
- }
|
|
|
- //如果是第七天之后都是第七天的奖励
|
|
|
- count = Math.min(6,count);
|
|
|
- return count;
|
|
|
- }
|
|
|
|
|
|
@GetMapping("/scoreInfo")
|
|
|
@ApiOperation(value = "查看积分中心信息", notes = "查看积分中心信息")
|
|
|
- public ResponseEntity<ScoreDataDto> scoreInfo() {
|
|
|
- ScoreDataDto scoreDataDto = new ScoreDataDto();
|
|
|
+ public ResponseEntity<ScoreDataDto> scoreInfo(@RequestParam Integer platform) {
|
|
|
String userId = SecurityUtils.getUser().getUserId();
|
|
|
- ScoreConfigParam scoreParam = sysConfigService.getSysConfigObject(Constant.SCORE_CONFIG, ScoreConfigParam.class);
|
|
|
- // 0.计算过期时间
|
|
|
- ScoreExpireParam scoreExpireParam = sysConfigService.getSysConfigObject(Constant.SCORE_EXPIRE,ScoreExpireParam.class);
|
|
|
- if (Objects.isNull(scoreParam)) {
|
|
|
- return ResponseEntity.ok().build();
|
|
|
- }
|
|
|
- Integer year = Objects.isNull(scoreExpireParam) ? 0:scoreExpireParam.getExpireYear();
|
|
|
- ArrayList<Integer> signInScores = new ArrayList<>();
|
|
|
- for(String s : scoreParam.getSignInScoreString().trim().split(StrUtil.COMMA)){
|
|
|
- Integer signInScore = Integer.valueOf(s);
|
|
|
- signInScores.add(signInScore);
|
|
|
- }
|
|
|
- UserExtension userExtension = userExtensionService.getOne(new LambdaQueryWrapper<UserExtension>().eq(UserExtension::getUserId, userId));
|
|
|
- if (userExtension == null) {
|
|
|
- return ResponseEntity.ok().build();
|
|
|
- }
|
|
|
- UserScoreDetail userScoreDetail = userScoreDetailService.getOne(new LambdaQueryWrapper<UserScoreDetail>().eq(UserScoreDetail::getUserId, userId)
|
|
|
- .eq(UserScoreDetail::getStatus, -1).orderByDesc(UserScoreDetail::getExpireTime).last("limit 1"));
|
|
|
- scoreDataDto.setIsRegister(1);
|
|
|
- scoreDataDto.setExpireScore(Objects.nonNull(userScoreDetail) ?userScoreDetail.getUsableScore():0);
|
|
|
- scoreDataDto.setExpireYear(year);
|
|
|
- scoreDataDto.setGrowth(userExtension.getGrowth());
|
|
|
- scoreDataDto.setScore(userExtension.getScore());
|
|
|
- scoreDataDto.setScoreList(signInScores);
|
|
|
- scoreDataDto.setRegisterScore(scoreParam.getRegisterScore());
|
|
|
- scoreDataDto.setShopScore(scoreParam.getShopGetScore());
|
|
|
- scoreDataDto.setIsSignIn(isSignIn(userId)? 1:0);
|
|
|
- scoreDataDto.setLevelType(userExtension.getLevelType());
|
|
|
-// UserLevel userLevel = userLevelService.getOne(new LambdaQueryWrapper<UserLevel>()
|
|
|
-// .eq(UserLevel::getLevel, userExtension.getLevel())
|
|
|
-// .eq(UserLevel::getLevelType, userExtension.getLevelType())
|
|
|
-// );
|
|
|
- //scoreDataDto.setLevelName(userLevel.getLevelName());
|
|
|
- //计算签到天数
|
|
|
- Integer count = scoreLogService.getConsecutiveDays(userId);
|
|
|
- //如果没有记录就是第一天签到
|
|
|
- if(count == null){
|
|
|
- count = 1;
|
|
|
- }
|
|
|
- count = Math.min(7,count);
|
|
|
- scoreDataDto.setSignInCount(isSignIn(userId)?count:count+ 1);
|
|
|
- return ResponseEntity.ok(scoreDataDto);
|
|
|
+ return ResponseEntity.ok(userScoreDetailService.doGetUserScore(userId, platform));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 是否已经签到
|
|
|
- * @param userId
|
|
|
- * @return
|
|
|
- */
|
|
|
- private boolean isSignIn(String userId){
|
|
|
- List<UserScoreLog> scoreList = scoreLogService.list(new LambdaQueryWrapper<UserScoreLog>().eq(UserScoreLog::getSource, ScoreLogType.SIGN_IN.value())
|
|
|
- .ge(UserScoreLog::getCreateTime, DateUtil.beginOfDay(DateUtil.date()))
|
|
|
- .le(UserScoreLog::getCreateTime, DateUtil.endOfDay(DateUtil.date()))
|
|
|
- .eq(UserScoreLog::getUserId, userId));
|
|
|
- return CollectionUtils.isNotEmpty(scoreList);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 分页查询积分明细
|
|
|
+ *
|
|
|
* @param page 分页对象
|
|
|
* @return 分页数据
|
|
|
*/
|
|
|
- @GetMapping("/page" )
|
|
|
+ @GetMapping("/page")
|
|
|
@ApiOperation(value = "查询积分明细", notes = "查询积分明细")
|
|
|
- public ResponseEntity<IPage<UserScoreLog>> getScoreLogPage(PageParam<UserScoreLog> page) {
|
|
|
+ public ResponseEntity<IPage<PointsRecord>> getScoreLogPage(@ModelAttribute PageParam<PointsRecord> page, @RequestParam Integer platform) {
|
|
|
String userId = SecurityUtils.getUser().getUserId();
|
|
|
- return ResponseEntity.ok(scoreLogService.page(page,new LambdaQueryWrapper<UserScoreLog>()
|
|
|
- .eq(UserScoreLog::getUserId,userId).orderByDesc(UserScoreLog::getCreateTime)));
|
|
|
+ return ResponseEntity.ok(userScoreDetailService.doGetScorePage(page, userId,platform));
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 积分说明
|
|
|
+ *
|
|
|
* @return 积分说明
|
|
|
*/
|
|
|
- @GetMapping("/getScoreExplain" )
|
|
|
+ @GetMapping("/getScoreExplain")
|
|
|
@ApiOperation(value = "积分说明", notes = "积分说明")
|
|
|
public ResponseEntity<SysConfig> getScoreExplain() {
|
|
|
- SysConfig config = sysConfigService.getOne(new LambdaQueryWrapper<SysConfig>().eq(SysConfig::getParamKey,Constant.SCORE_EXPLAIN));
|
|
|
- if(Objects.isNull(config)){
|
|
|
+ SysConfig config = sysConfigService.getOne(new LambdaQueryWrapper<SysConfig>().eq(SysConfig::getParamKey, Constant.SCORE_EXPLAIN));
|
|
|
+ if (Objects.isNull(config)) {
|
|
|
return ResponseEntity.ok(new SysConfig());
|
|
|
}
|
|
|
return ResponseEntity.ok(config);
|
|
@@ -193,13 +100,14 @@ public class UserScoreController {
|
|
|
|
|
|
/**
|
|
|
* 等级页展示
|
|
|
+ *
|
|
|
* @return 等级页展示
|
|
|
*/
|
|
|
- @GetMapping("/getLevelShow" )
|
|
|
+ @GetMapping("/getLevelShow")
|
|
|
@ApiOperation(value = "等级页展示", notes = "等级页展示")
|
|
|
public ResponseEntity<String> getLevelShow() {
|
|
|
- String config = sysConfigService.getSysConfigObject(Constant.LEVEL_SHOW,String.class);
|
|
|
- if(Objects.isNull(config)){
|
|
|
+ String config = sysConfigService.getSysConfigObject(Constant.LEVEL_SHOW, String.class);
|
|
|
+ if (Objects.isNull(config)) {
|
|
|
return ResponseEntity.ok().build();
|
|
|
}
|
|
|
return ResponseEntity.ok(config);
|
|
@@ -207,13 +115,14 @@ public class UserScoreController {
|
|
|
|
|
|
/**
|
|
|
* 积分常见问题
|
|
|
+ *
|
|
|
* @return 积分常见问题
|
|
|
*/
|
|
|
- @GetMapping("/getScoreQuestion" )
|
|
|
+ @GetMapping("/getScoreQuestion")
|
|
|
@ApiOperation(value = "积分常见问题", notes = "积分常见问题")
|
|
|
public ResponseEntity<SysConfig> getScoreQuestion() {
|
|
|
- SysConfig config = sysConfigService.getOne(new LambdaQueryWrapper<SysConfig>().eq(SysConfig::getParamKey,Constant.SCORE_QUESTION));
|
|
|
- if(Objects.isNull(config)){
|
|
|
+ SysConfig config = sysConfigService.getOne(new LambdaQueryWrapper<SysConfig>().eq(SysConfig::getParamKey, Constant.SCORE_QUESTION));
|
|
|
+ if (Objects.isNull(config)) {
|
|
|
return ResponseEntity.ok(new SysConfig());
|
|
|
}
|
|
|
return ResponseEntity.ok(config);
|