Commit 33dc329485ee9ecdf87dd67dcd7a6b9264229c0e
1 parent
424750f6
【功能新增】商城分销: 创建分销员
Showing
6 changed files
with
71 additions
and
0 deletions
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java
| ... | ... | @@ -93,6 +93,7 @@ public interface ErrorCodeConstants { |
| 93 | 93 | ErrorCode BROKERAGE_BIND_OVERRIDE = new ErrorCode(1_011_007_006, "已绑定了推广人"); |
| 94 | 94 | ErrorCode BROKERAGE_BIND_LOOP = new ErrorCode(1_011_007_007, "下级不能绑定自己的上级"); |
| 95 | 95 | ErrorCode BROKERAGE_USER_LEVEL_NOT_SUPPORT = new ErrorCode(1_011_007_008, "目前只支持 level 小于等于 2"); |
| 96 | + ErrorCode BROKERAGE_CREATE_USER_EXISTS = new ErrorCode(1_011_007_009, "分销用户已存在"); | |
| 96 | 97 | |
| 97 | 98 | // ========== 分销提现 模块 1-011-008-000 ========== |
| 98 | 99 | ErrorCode BROKERAGE_WITHDRAW_NOT_EXISTS = new ErrorCode(1_011_008_000, "佣金提现记录不存在"); | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java
| ... | ... | @@ -47,6 +47,13 @@ public class BrokerageUserController { |
| 47 | 47 | @Resource |
| 48 | 48 | private MemberUserApi memberUserApi; |
| 49 | 49 | |
| 50 | + @PostMapping("/create") | |
| 51 | + @Operation(summary = "创建分销用户") | |
| 52 | + @PreAuthorize("@ss.hasPermission('trade:brokerage-user:create')") | |
| 53 | + public CommonResult<Long> createBrokerageUser(@Valid @RequestBody BrokerageUserCreateReqVO createReqVO) { | |
| 54 | + return success(brokerageUserService.createBrokerageUser(createReqVO)); | |
| 55 | + } | |
| 56 | + | |
| 50 | 57 | @PutMapping("/update-bind-user") |
| 51 | 58 | @Operation(summary = "修改推广员") |
| 52 | 59 | @PreAuthorize("@ss.hasPermission('trade:brokerage-user:update-bind-user')") | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserCreateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import jakarta.validation.constraints.NotNull; | |
| 5 | +import lombok.Data; | |
| 6 | + | |
| 7 | +@Schema(description = "管理后台 - 分销用户创建 Request VO") | |
| 8 | +@Data | |
| 9 | +public class BrokerageUserCreateReqVO { | |
| 10 | + | |
| 11 | + @Schema(description = "分销用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 12 | + @NotNull(message = "分销用户编号不能为空") | |
| 13 | + private Long userId; | |
| 14 | + | |
| 15 | + @Schema(description = "推广员编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4587") | |
| 16 | + private Long bindUserId; | |
| 17 | + | |
| 18 | + @Schema(description = "推广资格", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 19 | + @NotNull(message = "推广资格不能为空") | |
| 20 | + private Boolean brokerageEnabled; | |
| 21 | + | |
| 22 | + @Schema(description = "可用佣金", requiredMode = Schema.RequiredMode.REQUIRED, example = "11089") | |
| 23 | + @NotNull(message = "可用佣金不能为空") | |
| 24 | + private Integer price; | |
| 25 | + | |
| 26 | + @Schema(description = "冻结佣金", requiredMode = Schema.RequiredMode.REQUIRED, example = "30916") | |
| 27 | + @NotNull(message = "冻结佣金不能为空") | |
| 28 | + private Integer frozenPrice; | |
| 29 | + | |
| 30 | +} | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java
| ... | ... | @@ -59,6 +59,9 @@ public interface BrokerageUserConvert { |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | default BrokerageUserRespVO copyTo(MemberUserRespDTO source, BrokerageUserRespVO target) { |
| 62 | + if (target == null) { | |
| 63 | + return null; | |
| 64 | + } | |
| 62 | 65 | Optional.ofNullable(source).ifPresent( |
| 63 | 66 | user -> target.setNickname(user.getNickname()).setAvatar(user.getAvatar())); |
| 64 | 67 | return target; | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java
| 1 | 1 | package cn.iocoder.yudao.module.trade.service.brokerage; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserCreateReqVO; | |
| 4 | 5 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO; |
| 5 | 6 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryPageReqVO; |
| 6 | 7 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO; |
| 7 | 8 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO; |
| 8 | 9 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO; |
| 9 | 10 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; |
| 11 | +import jakarta.validation.Valid; | |
| 10 | 12 | import jakarta.validation.constraints.NotNull; |
| 11 | 13 | |
| 12 | 14 | /** |
| ... | ... | @@ -108,6 +110,13 @@ public interface BrokerageUserService { |
| 108 | 110 | boolean bindBrokerageUser(@NotNull Long userId, @NotNull Long bindUserId); |
| 109 | 111 | |
| 110 | 112 | /** |
| 113 | + * 创建分销用户 | |
| 114 | + * @param createReqVO 请求 | |
| 115 | + * @return 编号 | |
| 116 | + */ | |
| 117 | + Long createBrokerageUser(@Valid BrokerageUserCreateReqVO createReqVO); | |
| 118 | + | |
| 119 | + /** | |
| 111 | 120 | * 获取用户是否有分销资格 |
| 112 | 121 | * |
| 113 | 122 | * @param userId 用户编号 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java
| ... | ... | @@ -8,9 +8,11 @@ import cn.hutool.core.util.ObjUtil; |
| 8 | 8 | import cn.hutool.core.util.StrUtil; |
| 9 | 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 10 | 10 | import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; |
| 11 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 11 | 12 | import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; |
| 12 | 13 | import cn.iocoder.yudao.module.member.api.user.MemberUserApi; |
| 13 | 14 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| 15 | +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserCreateReqVO; | |
| 14 | 16 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO; |
| 15 | 17 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryPageReqVO; |
| 16 | 18 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO; |
| ... | ... | @@ -28,6 +30,7 @@ import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; |
| 28 | 30 | import com.baomidou.mybatisplus.core.metadata.IPage; |
| 29 | 31 | import jakarta.annotation.Resource; |
| 30 | 32 | import org.springframework.stereotype.Service; |
| 33 | +import org.springframework.transaction.annotation.Transactional; | |
| 31 | 34 | import org.springframework.validation.annotation.Validated; |
| 32 | 35 | |
| 33 | 36 | import java.time.LocalDateTime; |
| ... | ... | @@ -202,6 +205,24 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { |
| 202 | 205 | return true; |
| 203 | 206 | } |
| 204 | 207 | |
| 208 | + @Override | |
| 209 | + @Transactional(rollbackFor = Exception.class) | |
| 210 | + public Long createBrokerageUser(BrokerageUserCreateReqVO createReqVO) { | |
| 211 | + // 1. 校验分销用户是否已存在 | |
| 212 | + BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(createReqVO.getUserId()); | |
| 213 | + if (brokerageUser != null) { | |
| 214 | + throw exception(BROKERAGE_CREATE_USER_EXISTS); | |
| 215 | + } | |
| 216 | + | |
| 217 | + // 2.1 创建分销人 | |
| 218 | + brokerageUser = BeanUtils.toBean(createReqVO, BrokerageUserDO.class).setId(createReqVO.getUserId()) | |
| 219 | + .setBrokerageTime(LocalDateTime.now()).setBindUserId(null); | |
| 220 | + brokerageUserMapper.insert(brokerageUser); | |
| 221 | + // 2.2 绑定推广员 | |
| 222 | + updateBrokerageUserId(brokerageUser.getId(), createReqVO.getBindUserId()); | |
| 223 | + return brokerageUser.getId(); | |
| 224 | + } | |
| 225 | + | |
| 205 | 226 | /** |
| 206 | 227 | * 补全绑定用户的字段 |
| 207 | 228 | * | ... | ... |