release: 修改会员,是否永久会员

release-2024-08-08
huangyw 4 months ago
parent 11b49e598f
commit a0d580aaf1

@ -31,6 +31,9 @@ public enum PointEnums {
LOTTERY_RESULT_WIN(1, "中奖"), LOTTERY_RESULT_WIN(1, "中奖"),
LOTTERY_RESULT_LOSE(2, "未中奖"), LOTTERY_RESULT_LOSE(2, "未中奖"),
MEMBERSHIP_LIFE(1, "永久会员"),
MEMBERSHIP_NOT_LIFE(2, "非永久会员"),
; ;
private final Integer code; private final Integer code;
private final String description; private final String description;

@ -8,7 +8,9 @@ import com.luoo.user.pojo.MembershipCode;
import com.luoo.user.service.MembershipCodeService; import com.luoo.user.service.MembershipCodeService;
import controller.BaseController; import controller.BaseController;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import java.util.List; import java.util.List;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -36,12 +38,14 @@ public class MembershipController extends BaseController {
@GetMapping("/code/generate") @GetMapping("/code/generate")
@GlobalInterceptor(checkAdminLogin = true) @GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams(value = { @ApiImplicitParams(value = {
@ApiImplicitParam(name = "duration", value = "会员时长(天)", required = true, dataType = "Integer", paramType = "query") @ApiImplicitParam(name = "duration", value = "会员时长(天)", required = true, dataType = "Integer", paramType = "query"),
@ApiImplicitParam(name = "life", value = "是否永久会员 1-是 2-否", required = true, dataType = "Integer", paramType = "query")
}) })
public Result<String> generateMembershipCode( public Result<String> generateMembershipCode(
@RequestHeader(value = "Authorization", required = true) String authorization, @RequestHeader(value = "Authorization", required = true) String authorization,
@NotNull Integer duration) { @NotNull Integer duration,
return Result.success(membershipCodeService.generateMembershipCode(authorization, duration)); @NotNull Integer life) {
return Result.success(membershipCodeService.generateMembershipCode(authorization, duration, life));
} }
@ApiOperation(value = "1.1 批量生成会员码", notes = "仅限admin权限用户调用") @ApiOperation(value = "1.1 批量生成会员码", notes = "仅限admin权限用户调用")
@ -49,14 +53,16 @@ public class MembershipController extends BaseController {
@GlobalInterceptor(checkAdminLogin = true) @GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams(value = { @ApiImplicitParams(value = {
@ApiImplicitParam(name = "duration", value = "会员时长(天)", required = true, dataType = "Integer", paramType = "query"), @ApiImplicitParam(name = "duration", value = "会员时长(天)", required = true, dataType = "Integer", paramType = "query"),
@ApiImplicitParam(name = "count", value = "生成数量", required = true, dataType = "Integer", paramType = "query") @ApiImplicitParam(name = "count", value = "生成数量", required = true, dataType = "Integer", paramType = "query"),
@ApiImplicitParam(name = "life", value = "是否永久会员 1-是 2-否", required = true, dataType = "Integer", paramType = "query")
}) })
public Result<List<String>> generateMembershipCodeBatch( public Result<List<String>> generateMembershipCodeBatch(
@RequestHeader(value = "Authorization", required = true) String authorization, @RequestHeader(value = "Authorization", required = true) String authorization,
@NotNull Integer duration, @NotNull Integer duration,
@NotNull Integer count) { @NotNull Integer count,
@NotNull Integer life) {
List<String> list = membershipCodeService.generateMembershipCodeBatch(authorization, List<String> list = membershipCodeService.generateMembershipCodeBatch(authorization,
duration, count); duration, count, life);
return Result.success(list); return Result.success(list);
} }
@ -75,7 +81,7 @@ public class MembershipController extends BaseController {
} }
@ApiOperation(value = "3.查询会员码", notes = "仅限admin权限用户调用") @ApiOperation(value = "3.查询会员码", notes = "仅限admin权限用户调用")
@GetMapping("/code/list") @GetMapping("/code/list{page}/{size}")
@GlobalInterceptor(checkAdminLogin = true) @GlobalInterceptor(checkAdminLogin = true)
public Result<PageResult<MembershipCode>> queryMembershipCode( public Result<PageResult<MembershipCode>> queryMembershipCode(
@RequestHeader(value = "Authorization", required = true) String authorization, @RequestHeader(value = "Authorization", required = true) String authorization,

@ -45,6 +45,10 @@ public class MembershipCode implements Serializable {
@ApiModelProperty(value = "时长") @ApiModelProperty(value = "时长")
private Integer duration; private Integer duration;
@Column(name = "life")
@ApiModelProperty(value = "是否永久会员 1-是 2-否")
private Integer life;
@Size(max = 20) @Size(max = 20)
@Column(name = "user_id", length = 20) @Column(name = "user_id", length = 20)
@ApiModelProperty(value = "用户id") @ApiModelProperty(value = "用户id")

@ -10,14 +10,17 @@ import com.luoo.user.pojo.UserInfo;
import com.luoo.user.pojo.UserPointLog; import com.luoo.user.pojo.UserPointLog;
import dto.UserLoginDto; import dto.UserLoginDto;
import enums.MembershipEnums; import enums.MembershipEnums;
import enums.PointEnums;
import enums.UserVipStatusEnum; import enums.UserVipStatusEnum;
import exception.BizException; import exception.BizException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@ -68,10 +71,11 @@ public class MembershipCodeService {
* *
* @param token token * @param token token
* @param duration * @param duration
* @param life
* @return * @return
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public String generateMembershipCode(String token, Integer duration) { public String generateMembershipCode(String token, Integer duration, Integer life) {
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
// UUID作为会员码 // UUID作为会员码
@ -81,6 +85,7 @@ public class MembershipCodeService {
.code(code) .code(code)
.status(MembershipEnums.CREATED.getCode()) .status(MembershipEnums.CREATED.getCode())
.duration(duration) .duration(duration)
.life(life)
.createUser(userLoginDto.getUserId()) .createUser(userLoginDto.getUserId())
.build(); .build();
membershipCodeDao.save(build); membershipCodeDao.save(build);
@ -93,13 +98,14 @@ public class MembershipCodeService {
* @param token token * @param token token
* @param duration * @param duration
* @param count * @param count
* @param life
* @return list * @return list
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public List<String> generateMembershipCodeBatch(String token, Integer duration, Integer count) { public List<String> generateMembershipCodeBatch(String token, Integer duration, Integer count, Integer life) {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
String code = generateMembershipCode(token, duration); String code = generateMembershipCode(token, duration, life);
result.add(code); result.add(code);
} }
return result; return result;
@ -127,6 +133,12 @@ public class MembershipCodeService {
// 处理用户表 // 处理用户表
UserInfo userInfo = userInfoDao.findById(userLoginDto.getUserId()).get(); UserInfo userInfo = userInfoDao.findById(userLoginDto.getUserId()).get();
// 永久会员码
if(Objects.equals(membershipCode.getLife(), PointEnums.MEMBERSHIP_LIFE.getCode())) {
userInfo.setVipStatus(UserVipStatusEnum.LIFE.getCode());
} else {
// 非永久会员码
// 计算会员到期时间 // 计算会员到期时间
LocalDate vipExpireTime; LocalDate vipExpireTime;
if (Objects.equals(UserVipStatusEnum.INITIAL.getCode(), userInfo.getVipStatus())) { if (Objects.equals(UserVipStatusEnum.INITIAL.getCode(), userInfo.getVipStatus())) {
@ -139,6 +151,8 @@ public class MembershipCodeService {
userInfo.setVipExpireTime(vipExpireTime); userInfo.setVipExpireTime(vipExpireTime);
// 无论如何当即设置为会员生效状态 // 无论如何当即设置为会员生效状态
userInfo.setVipStatus(UserVipStatusEnum.ACTIVE.getCode()); userInfo.setVipStatus(UserVipStatusEnum.ACTIVE.getCode());
}
userInfoDao.save(userInfo); userInfoDao.save(userInfo);
} }

@ -5,12 +5,14 @@ create table tb_membership_code
code varchar(50) null comment '会员码', code varchar(50) null comment '会员码',
status tinyint null comment '状态 1-已生成 2-已绑定 3-已退款 4-已废弃', status tinyint null comment '状态 1-已生成 2-已绑定 3-已退款 4-已废弃',
duration int null comment '会员时长(天)', duration int null comment '会员时长(天)',
life tinyint null comment '是否永久会员 1-是 2-否',
user_id varchar(20) null comment '使用用户', user_id varchar(20) null comment '使用用户',
create_time datetime null comment '创建时间', create_time datetime null comment '创建时间',
update_time datetime null comment '修改时间', update_time datetime null comment '修改时间',
create_user varchar(20) null comment '创建人', create_user varchar(20) null comment '创建人',
update_user varchar(20) null comment '修改人' update_user varchar(20) null comment '修改人'
) comment '会员码'; )
comment '会员码';
create table tb_user_point_log create table tb_user_point_log
( (

Loading…
Cancel
Save