会员: 修改会员等级,使用单独的表单、接口
This commit is contained in:
parent
5a2d9d14df
commit
bdb38c4157
|
@ -92,3 +92,7 @@ INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, com
|
|||
VALUES ('会员等级更新', 'member:level:update', 3, 3, @parentId, '', '', '', 0);
|
||||
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
|
||||
VALUES ('会员等级删除', 'member:level:delete', 3, 4, @parentId, '', '', '', 0);
|
||||
|
||||
-- 会员用户管理: 增加按钮权限
|
||||
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
|
||||
VALUES ('用户等级修改', 'member:user:update-level', 3, 5, 2309, '', '', '', 0);
|
|
@ -50,7 +50,6 @@ public interface ErrorCodeConstants {
|
|||
|
||||
ErrorCode LEVEL_LOG_NOT_EXISTS = new ErrorCode(1004011100, "用户等级记录不存在");
|
||||
ErrorCode EXPERIENCE_LOG_NOT_EXISTS = new ErrorCode(1004011200, "用户经验记录不存在");
|
||||
ErrorCode LEVEL_REASON_NOT_EXISTS = new ErrorCode(1004011300, "用户等级调整原因不能为空");
|
||||
|
||||
//========== 用户分组 1004012000 ==========
|
||||
ErrorCode GROUP_NOT_EXISTS = new ErrorCode(1004012000, "用户分组不存在");
|
||||
|
|
|
@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserPageReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserRespVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateLevelReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.member.convert.user.MemberUserConvert;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.group.MemberGroupDO;
|
||||
|
@ -52,6 +53,14 @@ public class MemberUserController {
|
|||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/update-level")
|
||||
@Operation(summary = "更新会员用户等级")
|
||||
@PreAuthorize("@ss.hasPermission('member:user:update-level')")
|
||||
public CommonResult<Boolean> updateUserLevel(@Valid @RequestBody MemberUserUpdateLevelReqVO updateReqVO) {
|
||||
memberLevelService.updateUserLevel(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得会员用户")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package cn.iocoder.yudao.module.member.controller.admin.user.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Schema(description = "管理后台 - 会员用户 修改等级 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class MemberUserUpdateLevelReqVO extends MemberUserBaseVO {
|
||||
|
||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23788")
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 取消用户等级时,值为空
|
||||
*/
|
||||
@Schema(description = "用户等级编号", example = "1")
|
||||
private Long levelId;
|
||||
|
||||
@Schema(description = "修改原因", requiredMode = Schema.RequiredMode.REQUIRED, example = "推广需要")
|
||||
@NotBlank(message = "修改原因不能为空")
|
||||
private String reason;
|
||||
|
||||
}
|
|
@ -17,7 +17,4 @@ public class MemberUserUpdateReqVO extends MemberUserBaseVO {
|
|||
@NotNull(message = "编号不能为空")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "会员级别修改原因", requiredMode = Schema.RequiredMode.REQUIRED, example = "推广需要")
|
||||
private String levelReason;
|
||||
|
||||
}
|
||||
|
|
|
@ -50,14 +50,13 @@ public interface MemberUserMapper extends BaseMapperX<MemberUserDO> {
|
|||
.orderByDesc(MemberUserDO::getId));
|
||||
}
|
||||
|
||||
// TODO @疯狂:命名可以改成 updateUserLevelToNull;db 侧的操作,尽量无业务含义,更多是 select、update、insert 操作
|
||||
/**
|
||||
* 取消会员的等级
|
||||
*
|
||||
* @param userId 会员编号
|
||||
* @return 受影响的行数
|
||||
*/
|
||||
default int cancelUserLevel(Long userId) {
|
||||
default int updateUserLevelToNull(Long userId) {
|
||||
return update(null, new LambdaUpdateWrapper<MemberUserDO>()
|
||||
.eq(MemberUserDO::getId, userId)
|
||||
.set(MemberUserDO::getExperience, 0)
|
||||
|
|
|
@ -5,11 +5,10 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|||
import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelCreateReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelPageReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateLevelReqVO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
@ -89,11 +88,9 @@ public interface MemberLevelService {
|
|||
/**
|
||||
* 修改会员的等级
|
||||
*
|
||||
* @param user 会员
|
||||
* @param levelId 要修改的等级编号,编号为空时,代表取消会员的等级
|
||||
* @param levelReason 修改原因
|
||||
* @param updateReqVO 修改参数
|
||||
*/
|
||||
void updateUserLevel(MemberUserDO user, @Nullable Long levelId, String levelReason);
|
||||
void updateUserLevel(MemberUserUpdateLevelReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 增加会员经验
|
||||
|
|
|
@ -4,11 +4,11 @@ import cn.hutool.core.collection.CollUtil;
|
|||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelCreateReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelPageReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateLevelReqVO;
|
||||
import cn.iocoder.yudao.module.member.convert.level.MemberLevelConvert;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
|
@ -180,41 +180,42 @@ public class MemberLevelServiceImpl implements MemberLevelService {
|
|||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void updateUserLevel(MemberUserDO user, Long levelId, String reason) {
|
||||
public void updateUserLevel(MemberUserUpdateLevelReqVO updateReqVO) {
|
||||
MemberUserDO user = memberUserMapper.selectById(updateReqVO.getId());
|
||||
if (user == null) {
|
||||
throw exception(USER_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 未调整的情况1
|
||||
if (user.getLevelId() == null && levelId == null) {
|
||||
if (user.getLevelId() == null && updateReqVO.getLevelId() == null) {
|
||||
return;
|
||||
}
|
||||
// 未调整的情况2
|
||||
if (ObjUtil.equal(user.getLevelId(), levelId)) {
|
||||
if (ObjUtil.equal(user.getLevelId(), updateReqVO.getLevelId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 需要后台用户填写为什么调整会员的等级
|
||||
if (StrUtil.isBlank(reason)) {
|
||||
throw exception(LEVEL_REASON_NOT_EXISTS);
|
||||
}
|
||||
|
||||
int experience;
|
||||
int totalExperience = 0;
|
||||
// 记录等级变动
|
||||
if (levelId == null) {
|
||||
if (updateReqVO.getLevelId() == null) {
|
||||
// 取消用户等级时,为扣减经验
|
||||
experience = -user.getExperience();
|
||||
|
||||
// 取消了会员的等级
|
||||
memberLevelLogService.createCancelLog(user.getId(), reason);
|
||||
memberUserMapper.cancelUserLevel(user.getId());
|
||||
memberLevelLogService.createCancelLog(user.getId(), updateReqVO.getReason());
|
||||
memberUserMapper.updateUserLevelToNull(user.getId());
|
||||
} else {
|
||||
MemberLevelDO level = validateLevelExists(levelId);
|
||||
MemberLevelDO level = validateLevelExists(updateReqVO.getLevelId());
|
||||
// 变动经验值 = 等级的升级经验 - 会员当前的经验;正数为增加经验,负数为扣减经验
|
||||
experience = level.getExperience() - user.getExperience();
|
||||
// 会员当前的经验 = 等级的升级经验
|
||||
totalExperience = level.getExperience();
|
||||
|
||||
memberLevelLogService.createAdjustLog(user, level, experience, reason);
|
||||
memberLevelLogService.createAdjustLog(user, level, experience, updateReqVO.getReason());
|
||||
|
||||
// 更新会员表上的等级编号、经验值
|
||||
updateUserLevelIdAndExperience(user.getId(), levelId, totalExperience);
|
||||
updateUserLevelIdAndExperience(user.getId(), updateReqVO.getLevelId(), totalExperience);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ import cn.iocoder.yudao.module.member.convert.auth.AuthConvert;
|
|||
import cn.iocoder.yudao.module.member.convert.user.MemberUserConvert;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper;
|
||||
import cn.iocoder.yudao.module.member.service.level.MemberLevelService;
|
||||
import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi;
|
||||
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO;
|
||||
import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
|
||||
|
@ -56,9 +55,6 @@ public class MemberUserServiceImpl implements MemberUserService {
|
|||
@Resource
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
@Resource
|
||||
private MemberLevelService memberLevelService;
|
||||
|
||||
@Override
|
||||
public MemberUserDO getUserByMobile(String mobile) {
|
||||
return memberUserMapper.selectByMobile(mobile);
|
||||
|
@ -195,10 +191,6 @@ public class MemberUserServiceImpl implements MemberUserService {
|
|||
// 更新
|
||||
MemberUserDO updateObj = MemberUserConvert.INSTANCE.convert(updateReqVO);
|
||||
memberUserMapper.updateById(updateObj);
|
||||
|
||||
// 会员级别修改
|
||||
// TODO @疯狂:修改用户等级,要不要单独一个前端操作 + 接口;因为它是个相对严肃独立的动作
|
||||
memberLevelService.updateUserLevel(user, updateReqVO.getLevelId(), updateReqVO.getLevelReason());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
|
Loading…
Reference in New Issue