Commit 421bb7d1548667fdc8844e59345d9ce504c40cab
1 parent
51899c4c
code review:分销逻辑
Showing
21 changed files
with
71 additions
and
35 deletions
yudao-framework/yudao-spring-boot-starter-biz-error-code/pom.xml
| ... | ... | @@ -14,7 +14,7 @@ |
| 14 | 14 | <name>${project.artifactId}</name> |
| 15 | 15 | <description> |
| 16 | 16 | 错误码 ErrorCode 的自动配置功能,提供如下功能: |
| 17 | - 1. 远程读取:项目启动时,从 system-server 服务,读取数据库中的 ErrorCode 错误码,实现错误码的提水可配置; | |
| 17 | + 1. 远程读取:项目启动时,从 system-server 服务,读取数据库中的 ErrorCode 错误码,实现错误码的提示可配置; | |
| 18 | 18 | 2. 自动更新:管理员在管理后台修数据库中的 ErrorCode 错误码时,项目自动从 system-server 服务加载最新的 ErrorCode 错误码; |
| 19 | 19 | 3. 自动写入:项目启动时,将项目本地的错误码写到 system-server 服务中,方便管理员在管理后台编辑; |
| 20 | 20 | </description> | ... | ... |
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java
| ... | ... | @@ -87,7 +87,7 @@ public interface ErrorCodeConstants { |
| 87 | 87 | // ========== 分销提现 模块 1011008000 ========== |
| 88 | 88 | ErrorCode BROKERAGE_WITHDRAW_NOT_EXISTS = new ErrorCode(1011008000, "佣金提现记录不存在"); |
| 89 | 89 | ErrorCode BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING = new ErrorCode(1011008001, "佣金提现记录状态不是审核中"); |
| 90 | - ErrorCode BROKERAGE_WITHDRAW_MIN_PRICE = new ErrorCode(1011008002, "提现金额不能低于{}元"); | |
| 91 | - ErrorCode BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH = new ErrorCode(1011008003, "您当前最多可提现{}元"); | |
| 90 | + ErrorCode BROKERAGE_WITHDRAW_MIN_PRICE = new ErrorCode(1011008002, "提现金额不能低于 {} 元"); | |
| 91 | + ErrorCode BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH = new ErrorCode(1011008003, "您当前最多可提现 {} 元"); | |
| 92 | 92 | |
| 93 | 93 | } | ... | ... |
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java
| ... | ... | @@ -22,7 +22,9 @@ public enum BrokerageWithdrawStatusEnum implements IntArrayValuable { |
| 22 | 22 | WITHDRAW_FAIL(21, "提现失败"), |
| 23 | 23 | ; |
| 24 | 24 | |
| 25 | + // TODO @疯狂:字典现在枚举在每个模块的 DictTypeConstants 里哈;可以创建一个出来;主要是想,治理每个模块到底有多少个枚举; | |
| 25 | 26 | public static final String DICT_TYPE = "BROKERAGE_WITHDRAW_STATUS"; |
| 27 | + | |
| 26 | 28 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageWithdrawStatusEnum::getStatus).toArray(); |
| 27 | 29 | |
| 28 | 30 | /** | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java
| ... | ... | @@ -45,6 +45,7 @@ public class AppBrokerageRecordController { |
| 45 | 45 | return success(BrokerageRecordConvert.INSTANCE.convertPage02(pageResult)); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | + // TODO @疯狂:这里还有一个漏网之鱼~ | |
| 48 | 49 | @GetMapping("/get-product-brokerage-price") |
| 49 | 50 | @Operation(summary = "获得商品的分销金额") |
| 50 | 51 | public CommonResult<AppBrokerageProductPriceRespVO> getProductBrokeragePrice(@RequestParam("spuId") Long spuId) { | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java
| ... | ... | @@ -55,6 +55,7 @@ public class AppBrokerageUserController { |
| 55 | 55 | @PreAuthenticated |
| 56 | 56 | public CommonResult<AppBrokerageUserRespVO> getBrokerageUser() { |
| 57 | 57 | Optional<BrokerageUserDO> user = Optional.ofNullable(brokerageUserService.getBrokerageUser(getLoginUserId())); |
| 58 | + // 返回数据 | |
| 58 | 59 | AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO() |
| 59 | 60 | .setBrokerageEnabled(user.map(BrokerageUserDO::getBrokerageEnabled).orElse(false)) |
| 60 | 61 | .setBrokeragePrice(user.map(BrokerageUserDO::getBrokeragePrice).orElse(0)) |
| ... | ... | @@ -66,6 +67,7 @@ public class AppBrokerageUserController { |
| 66 | 67 | @Operation(summary = "绑定推广员") |
| 67 | 68 | @PreAuthenticated |
| 68 | 69 | public CommonResult<Boolean> bindBrokerageUser(@Valid @RequestBody AppBrokerageUserBindReqVO reqVO) { |
| 70 | + // TODO @疯狂:是不是 isNewUser 不用传递哈,交给 service 自己计算出来? | |
| 69 | 71 | return success(brokerageUserService.bindBrokerageUser(getLoginUserId(), reqVO.getBindUserId(), false)); |
| 70 | 72 | } |
| 71 | 73 | |
| ... | ... | @@ -74,17 +76,17 @@ public class AppBrokerageUserController { |
| 74 | 76 | @PreAuthenticated |
| 75 | 77 | public CommonResult<AppBrokerageUserMySummaryRespVO> getBrokerageUserSummary() { |
| 76 | 78 | Long userId = getLoginUserId(); |
| 79 | + // 统计 yesterdayPrice、withdrawPrice、firstBrokerageUserCount、secondBrokerageUserCount 字段 | |
| 77 | 80 | LocalDateTime yesterday = LocalDateTime.now().minusDays(1); |
| 78 | 81 | LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday); |
| 79 | 82 | LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday); |
| 80 | - | |
| 81 | 83 | AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO() |
| 82 | 84 | .setYesterdayPrice(brokerageRecordService.getSummaryPriceByUserId(userId, BrokerageRecordBizTypeEnum.ORDER.getType(), beginTime, endTime)) |
| 83 | 85 | .setWithdrawPrice(brokerageWithdrawService.getSummaryPriceByUserIdAndStatus(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS.getStatus())) |
| 84 | - .setBrokeragePrice(0) | |
| 85 | - .setFrozenPrice(0) | |
| 86 | + .setBrokeragePrice(0).setFrozenPrice(0) | |
| 86 | 87 | .setFirstBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1)) |
| 87 | 88 | .setSecondBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2)); |
| 89 | + // 设置 brokeragePrice、frozenPrice 字段 | |
| 88 | 90 | Optional.ofNullable(brokerageUserService.getBrokerageUser(userId)) |
| 89 | 91 | .ifPresent(user -> respVO.setBrokeragePrice(user.getBrokeragePrice()).setFrozenPrice(user.getFrozenPrice())); |
| 90 | 92 | return success(respVO); |
| ... | ... | @@ -117,7 +119,6 @@ public class AppBrokerageUserController { |
| 117 | 119 | @PreAuthenticated |
| 118 | 120 | public CommonResult<PageResult<AppBrokerageUserChildSummaryRespVO>> getBrokerageUserChildSummaryPage( |
| 119 | 121 | AppBrokerageUserChildSummaryPageReqVO pageReqVO) { |
| 120 | - // 分页查询 | |
| 121 | 122 | PageResult<AppBrokerageUserChildSummaryRespVO> pageResult = brokerageUserService.getBrokerageUserChildSummaryPage(pageReqVO, getLoginUserId()); |
| 122 | 123 | return success(pageResult); |
| 123 | 124 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java
| ... | ... | @@ -30,6 +30,7 @@ import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLogi |
| 30 | 30 | @Validated |
| 31 | 31 | @Slf4j |
| 32 | 32 | public class AppBrokerageWithdrawController { |
| 33 | + | |
| 33 | 34 | @Resource |
| 34 | 35 | private BrokerageWithdrawService brokerageWithdrawService; |
| 35 | 36 | |
| ... | ... | @@ -44,6 +45,7 @@ public class AppBrokerageWithdrawController { |
| 44 | 45 | PageResult<BrokerageWithdrawDO> pageResult = brokerageWithdrawService.getBrokerageWithdrawPage( |
| 45 | 46 | BrokerageWithdrawConvert.INSTANCE.convert(pageReqVO, getLoginUserId())); |
| 46 | 47 | // 拼接信息 |
| 48 | + // TODO @疯狂:后端可以直接用 DictFrameworkUtils.getDictDataLabel() 去渲染哈;这样就不用 getDictDataLabelMap 方法了; | |
| 47 | 49 | Map<String, String> statusNameMap = dictDataApi.getDictDataLabelMap(BrokerageWithdrawStatusEnum.DICT_TYPE); |
| 48 | 50 | return success(BrokerageWithdrawConvert.INSTANCE.convertPage02(pageResult, statusNameMap)); |
| 49 | 51 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java
| ... | ... | @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 5 | import cn.iocoder.yudao.module.trade.controller.app.config.vo.AppTradeConfigRespVO; |
| 6 | 6 | import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; |
| 7 | 7 | import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; |
| 8 | +import io.swagger.v3.oas.annotations.Operation; | |
| 8 | 9 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 9 | 10 | import lombok.RequiredArgsConstructor; |
| 10 | 11 | import lombok.extern.slf4j.Slf4j; |
| ... | ... | @@ -24,13 +25,15 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 24 | 25 | @Validated |
| 25 | 26 | @Slf4j |
| 26 | 27 | public class AppTradeConfigController { |
| 28 | + | |
| 27 | 29 | @Resource |
| 28 | 30 | private TradeConfigService tradeConfigService; |
| 29 | 31 | |
| 30 | 32 | @GetMapping("/get") |
| 33 | + @Operation(summary = "获得交易配置") | |
| 31 | 34 | public CommonResult<AppTradeConfigRespVO> getTradeConfig() { |
| 32 | 35 | TradeConfigDO tradeConfig = ObjUtil.defaultIfNull(tradeConfigService.getTradeConfig(), new TradeConfigDO()); |
| 33 | - | |
| 36 | + // TODO @疯狂:是不是直接 convert 就好啦; | |
| 34 | 37 | AppTradeConfigRespVO respVO = new AppTradeConfigRespVO() |
| 35 | 38 | .setBrokeragePosterUrls(tradeConfig.getBrokeragePostUrls()) |
| 36 | 39 | .setBrokerageFrozenDays(tradeConfig.getBrokerageFrozenDays()) | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java
| ... | ... | @@ -18,6 +18,7 @@ public class AppTradeConfigRespVO { |
| 18 | 18 | @Schema(description = "佣金提现最小金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") |
| 19 | 19 | private Integer brokerageWithdrawMinPrice; |
| 20 | 20 | |
| 21 | + // TODO @疯狂:如果是 list,要不加个 s,复数; | |
| 21 | 22 | @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1, 2]") |
| 22 | 23 | private List<Integer> brokerageWithdrawType; |
| 23 | 24 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverConfigController.java
| ... | ... | @@ -17,6 +17,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 17 | 17 | @Validated |
| 18 | 18 | public class AppDeliverConfigController { |
| 19 | 19 | |
| 20 | + // TODO @芋艿:这里后面干掉,合并到 AppTradeConfigController 中 | |
| 20 | 21 | @GetMapping("/get") |
| 21 | 22 | @Operation(summary = "获得配送配置") |
| 22 | 23 | public CommonResult<AppDeliveryConfigRespVO> getDeliveryConfig() { | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java
| ... | ... | @@ -58,12 +58,12 @@ public interface BrokerageUserConvert { |
| 58 | 58 | return target; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - default PageResult<AppBrokerageUserRankByUserCountRespVO> convertPage03(PageResult<AppBrokerageUserRankByUserCountRespVO> pageResult, Map<Long, MemberUserRespDTO> userMap) { | |
| 62 | - for (AppBrokerageUserRankByUserCountRespVO vo : pageResult.getList()) { | |
| 63 | - copyTo(userMap.get(vo.getId()), vo); | |
| 64 | - } | |
| 61 | + default PageResult<AppBrokerageUserRankByUserCountRespVO> convertPage03(PageResult<AppBrokerageUserRankByUserCountRespVO> pageResult, | |
| 62 | + Map<Long, MemberUserRespDTO> userMap) { | |
| 63 | + pageResult.getList().forEach(vo -> copyTo(userMap.get(vo.getId()), vo)); | |
| 65 | 64 | return pageResult; |
| 66 | 65 | } |
| 67 | 66 | |
| 68 | 67 | void copyTo(MemberUserRespDTO from, @MappingTarget AppBrokerageUserRankByUserCountRespVO to); |
| 68 | + | |
| 69 | 69 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java
| ... | ... | @@ -25,7 +25,6 @@ import java.util.List; |
| 25 | 25 | public interface BrokerageRecordMapper extends BaseMapperX<BrokerageRecordDO> { |
| 26 | 26 | |
| 27 | 27 | default PageResult<BrokerageRecordDO> selectPage(BrokerageRecordPageReqVO reqVO) { |
| 28 | - // 分页查询 | |
| 29 | 28 | return selectPage(reqVO, new LambdaQueryWrapperX<BrokerageRecordDO>() |
| 30 | 29 | .eqIfPresent(BrokerageRecordDO::getUserId, reqVO.getUserId()) |
| 31 | 30 | .eqIfPresent(BrokerageRecordDO::getBizType, reqVO.getBizType()) |
| ... | ... | @@ -59,7 +58,8 @@ public interface BrokerageRecordMapper extends BaseMapperX<BrokerageRecordDO> { |
| 59 | 58 | @Param("bizType") Integer bizType, |
| 60 | 59 | @Param("status") Integer status); |
| 61 | 60 | |
| 62 | - @Select("SELECT SUM(price) FROM trade_brokerage_record WHERE user_id = #{userId} AND biz_type = #{bizType} " + | |
| 61 | + @Select("SELECT SUM(price) FROM trade_brokerage_record " + | |
| 62 | + "WHERE user_id = #{userId} AND biz_type = #{bizType} " + | |
| 63 | 63 | "AND create_time BETWEEN #{beginTime} AND #{endTime}") |
| 64 | 64 | Integer selectSummaryPriceByUserIdAndBizTypeAndCreateTimeBetween(@Param("userId") Long userId, |
| 65 | 65 | @Param("bizType") Integer bizType, |
| ... | ... | @@ -76,4 +76,5 @@ public interface BrokerageRecordMapper extends BaseMapperX<BrokerageRecordDO> { |
| 76 | 76 | @Param("status") Integer status, |
| 77 | 77 | @Param("beginTime") LocalDateTime beginTime, |
| 78 | 78 | @Param("endTime") LocalDateTime endTime); |
| 79 | + | |
| 79 | 80 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java
| ... | ... | @@ -36,6 +36,8 @@ public interface BrokerageWithdrawMapper extends BaseMapperX<BrokerageWithdrawDO |
| 36 | 36 | .eq(BrokerageWithdrawDO::getStatus, status)); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - @Select("SELECT SUM(price) FROM trade_brokerage_withdraw WHERE user_id = #{userId} AND status = #{status}") | |
| 39 | + @Select("SELECT SUM(price) FROM trade_brokerage_withdraw " + | |
| 40 | + "WHERE user_id = #{userId} AND status = #{status}") | |
| 40 | 41 | Integer selectSummaryPriceByUserIdAndStatus(@Param("userId") Long userId, @Param("status") Integer status); |
| 42 | + | |
| 41 | 43 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java
| ... | ... | @@ -37,7 +37,7 @@ public interface BrokerageRecordService { |
| 37 | 37 | PageResult<BrokerageRecordDO> getBrokerageRecordPage(BrokerageRecordPageReqVO pageReqVO); |
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | - * 增加佣金 | |
| 40 | + * 增加佣金【多级分佣】 | |
| 41 | 41 | * |
| 42 | 42 | * @param userId 会员编号 |
| 43 | 43 | * @param bizType 业务类型 |
| ... | ... | @@ -46,7 +46,7 @@ public interface BrokerageRecordService { |
| 46 | 46 | void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, @Valid List<BrokerageAddReqBO> list); |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | - * 增加佣金 | |
| 49 | + * 增加佣金【只针对自己】 | |
| 50 | 50 | * |
| 51 | 51 | * @param userId 会员编号 |
| 52 | 52 | * @param bizType 业务类型 |
| ... | ... | @@ -95,6 +95,7 @@ public interface BrokerageRecordService { |
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | 97 | * 获得用户佣金排行分页列表(基于佣金总数) |
| 98 | + * | |
| 98 | 99 | * @param pageReqVO 分页查询 |
| 99 | 100 | * @return 排行榜分页 |
| 100 | 101 | */ |
| ... | ... | @@ -108,4 +109,5 @@ public interface BrokerageRecordService { |
| 108 | 109 | * @return 用户的排名 |
| 109 | 110 | */ |
| 110 | 111 | Integer getUserRankByPrice(Long userId, LocalDateTime[] times); |
| 112 | + | |
| 111 | 113 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java
| ... | ... | @@ -240,10 +240,11 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { |
| 240 | 240 | return new PageResult<>(pageResult.getRecords(), pageResult.getTotal()); |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | + // TODO @疯狂:这个求出来,应该是不准的?例如说超过 100+ 名后? | |
| 243 | 244 | @Override |
| 244 | 245 | public Integer getUserRankByPrice(Long userId, LocalDateTime[] times) { |
| 245 | 246 | AppBrokerageUserRankPageReqVO pageParam = new AppBrokerageUserRankPageReqVO().setTimes(times); |
| 246 | - // 取前100名 | |
| 247 | + // 取前 100 名 | |
| 247 | 248 | pageParam.setPageSize(100); |
| 248 | 249 | PageResult<AppBrokerageUserRankByPriceRespVO> pageResult = getBrokerageUserChildSummaryPageByPrice(pageParam); |
| 249 | 250 | // 获得索引 |
| ... | ... | @@ -255,21 +256,23 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { |
| 255 | 256 | @Override |
| 256 | 257 | @Transactional(rollbackFor = Exception.class) |
| 257 | 258 | public void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, Integer brokeragePrice, String title) { |
| 258 | - // 校验佣金余额 | |
| 259 | + // 1. 校验佣金余额 | |
| 259 | 260 | BrokerageUserDO user = brokerageUserService.getBrokerageUser(userId); |
| 260 | 261 | int balance = Optional.of(user) |
| 261 | 262 | .map(BrokerageUserDO::getBrokeragePrice).orElse(0); |
| 262 | 263 | if (balance + brokeragePrice < 0) { |
| 264 | + // TODO @疯狂:要不 MoneyUtils 那,统一搞个 format 金额的方法?然后把分到元的字符串,统一收口掉; | |
| 263 | 265 | throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, new Money(0, balance)); |
| 264 | 266 | } |
| 265 | 267 | |
| 266 | - // 扣减佣金余额 | |
| 268 | + // 2. 更新佣金余额 | |
| 267 | 269 | boolean success = brokerageUserService.updateUserPrice(userId, brokeragePrice); |
| 268 | 270 | if (!success) { |
| 271 | + // 失败时,则抛出异常。只会出现扣减佣金时,余额不足的情况 | |
| 269 | 272 | throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, new Money(0, balance)); |
| 270 | 273 | } |
| 271 | 274 | |
| 272 | - // 新增记录 | |
| 275 | + // 3. 新增记录 | |
| 273 | 276 | BrokerageRecordDO record = BrokerageRecordConvert.INSTANCE.convert(user, bizType, bizId, 0, brokeragePrice, |
| 274 | 277 | null, title, null, null); |
| 275 | 278 | brokerageRecordMapper.insert(record); | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java
| ... | ... | @@ -67,7 +67,6 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { |
| 67 | 67 | public void updateBrokerageUserId(Long id, Long bindUserId) { |
| 68 | 68 | // 校验存在 |
| 69 | 69 | BrokerageUserDO brokerageUser = validateBrokerageUserExists(id); |
| 70 | - | |
| 71 | 70 | // 绑定关系未发生变化 |
| 72 | 71 | if (Objects.equals(brokerageUser.getBindUserId(), bindUserId)) { |
| 73 | 72 | return; |
| ... | ... | @@ -185,6 +184,13 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { |
| 185 | 184 | return true; |
| 186 | 185 | } |
| 187 | 186 | |
| 187 | + /** | |
| 188 | + * 补全绑定用户的字段 | |
| 189 | + * | |
| 190 | + * @param bindUserId 绑定的用户编号 | |
| 191 | + * @param brokerageUser update 对象 | |
| 192 | + * @return 补全后的 update 对象 | |
| 193 | + */ | |
| 188 | 194 | private BrokerageUserDO fillBindUserData(Long bindUserId, BrokerageUserDO brokerageUser) { |
| 189 | 195 | return brokerageUser.setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now()); |
| 190 | 196 | } |
| ... | ... | @@ -255,6 +261,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { |
| 255 | 261 | } |
| 256 | 262 | |
| 257 | 263 | // 下级不能绑定自己的上级 |
| 264 | + // TODO @疯狂:这里是不是查询不到的时候,应该有个 break 结束循环哈 | |
| 258 | 265 | for (int i = 0; i <= Short.MAX_VALUE; i++) { |
| 259 | 266 | if (Objects.equals(bindUser.getBindUserId(), user.getId())) { |
| 260 | 267 | throw exception(BROKERAGE_BIND_LOOP); |
| ... | ... | @@ -263,18 +270,24 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { |
| 263 | 270 | } |
| 264 | 271 | } |
| 265 | 272 | |
| 273 | + /** | |
| 274 | + * 根据绑定用户编号,获得绑定用户编号列表 | |
| 275 | + * | |
| 276 | + * @param bindUserId 绑定用户编号 | |
| 277 | + * @param level 绑定用户的层级。 | |
| 278 | + * 如果 level 为空,则查询 1+2 两个层级 | |
| 279 | + * @return 绑定用户编号列表 | |
| 280 | + */ | |
| 266 | 281 | private List<Long> buildBindUserIdsByLevel(Long bindUserId, Integer level) { |
| 282 | + Assert.isTrue(level == null || level <= 2, "目前只支持 level 小于等于 2"); | |
| 267 | 283 | List<Long> bindUserIds = CollUtil.newArrayList(); |
| 268 | 284 | if (level == null || level == 1) { |
| 269 | 285 | bindUserIds.add(bindUserId); |
| 270 | 286 | } |
| 271 | 287 | if (level == null || level == 2) { |
| 272 | - List<Long> firstUserIds = convertList(brokerageUserMapper.selectListByBindUserId(bindUserId), BrokerageUserDO::getId); | |
| 273 | - bindUserIds.addAll(firstUserIds); | |
| 288 | + bindUserIds.addAll(convertList(brokerageUserMapper.selectListByBindUserId(bindUserId), BrokerageUserDO::getId)); | |
| 274 | 289 | } |
| 275 | - | |
| 276 | 290 | return bindUserIds; |
| 277 | - | |
| 278 | 291 | } |
| 279 | 292 | |
| 280 | 293 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java
yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml
| ... | ... | @@ -4,14 +4,13 @@ |
| 4 | 4 | |
| 5 | 5 | <select id="selectSummaryPageByUserId" |
| 6 | 6 | resultType="cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO"> |
| 7 | - SELECT bu.id, bu.bind_user_time AS brokerageTime, | |
| 8 | - u.nickname, u.avatar, | |
| 7 | + SELECT bu.id, bu.bind_user_time AS brokerageTime, u.nickname, u.avatar, | |
| 9 | 8 | (SELECT SUM(price) FROM trade_brokerage_record r |
| 10 | - WHERE r.user_id = u.id AND biz_type = 1 AND r.status = 1 AND r.deleted = FALSE) AS brokeragePrice, | |
| 9 | + WHERE r.user_id = u.id AND biz_type = 1 AND r.status = 1 AND r.deleted = FALSE) AS brokeragePrice, | |
| 11 | 10 | (SELECT COUNT(1) FROM trade_brokerage_record r |
| 12 | - WHERE r.user_id = u.id AND biz_type = 1 AND r.status = 1 AND r.deleted = FALSE) AS brokerageOrderCount, | |
| 11 | + WHERE r.user_id = u.id AND biz_type = 1 AND r.status = 1 AND r.deleted = FALSE) AS brokerageOrderCount, | |
| 13 | 12 | (SELECT COUNT(1) FROM trade_brokerage_user c |
| 14 | - WHERE c.bind_user_id = u.id AND c.deleted = FALSE) AS brokerageUserCount | |
| 13 | + WHERE c.bind_user_id = u.id AND c.deleted = FALSE) AS brokerageUserCount | |
| 15 | 14 | FROM member_user AS u |
| 16 | 15 | JOIN trade_brokerage_user AS bu ON bu.id = u.id |
| 17 | 16 | <where> |
| ... | ... | @@ -22,8 +21,7 @@ |
| 22 | 21 | AND bu.bind_user_id = #{userId} |
| 23 | 22 | </if> |
| 24 | 23 | <if test="param.level == 2"> |
| 25 | - AND bu.bind_user_id = (SELECT id FROM trade_brokerage_user c WHERE c.bind_user_id = | |
| 26 | - #{userId}) | |
| 24 | + AND bu.bind_user_id IN (SELECT id FROM trade_brokerage_user c WHERE c.bind_user_id = #{userId}) | |
| 27 | 25 | </if> |
| 28 | 26 | </where> |
| 29 | 27 | <choose> |
| ... | ... | @@ -41,4 +39,5 @@ |
| 41 | 39 | </otherwise> |
| 42 | 40 | </choose> |
| 43 | 41 | </select> |
| 42 | + | |
| 44 | 43 | </mapper> | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java
| ... | ... | @@ -38,6 +38,7 @@ public class DictDataApiImpl implements DictDataApi { |
| 38 | 38 | |
| 39 | 39 | @Override |
| 40 | 40 | public List<DictDataRespDTO> getDictDataList(String type) { |
| 41 | + // TODO @疯狂:不用 DictDataExportReqVO 哈;可以考虑直接加个允许传递 type 传递的 | |
| 41 | 42 | List<DictDataDO> list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(type)); |
| 42 | 43 | return DictDataConvert.INSTANCE.convertList04(list); |
| 43 | 44 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java
| ... | ... | @@ -28,10 +28,12 @@ public class AppDictDataController { |
| 28 | 28 | @Resource |
| 29 | 29 | private DictDataService dictDataService; |
| 30 | 30 | |
| 31 | + // TODO @疯狂:暂时不用 path 参数哈;主要考虑一些中间件支持的一般,例如说链路追踪之类的;还是作为一个参数噶; | |
| 31 | 32 | @GetMapping("/type/{dictType}") |
| 32 | 33 | @Operation(summary = "根据字典类型查询字典数据信息") |
| 33 | - public CommonResult<List<AppDictDataRespVO>> getDicts(@PathVariable String dictType) { | |
| 34 | + public CommonResult<List<AppDictDataRespVO>> getDictDataList(@PathVariable String dictType) { | |
| 34 | 35 | List<DictDataDO> list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(dictType)); |
| 35 | 36 | return success(DictDataConvert.INSTANCE.convertList03(list)); |
| 36 | 37 | } |
| 38 | + | |
| 37 | 39 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java
| ... | ... | @@ -14,6 +14,8 @@ import lombok.NoArgsConstructor; |
| 14 | 14 | @EqualsAndHashCode(callSuper = true) |
| 15 | 15 | public class AppDictDataRespVO extends DictDataBaseVO { |
| 16 | 16 | |
| 17 | + // TODO @疯狂:app 的接口,不集成 admin 接口的 vo 哈;看看是不是只返回必要的字段,类似 remark、sort 不好返回的哈; | |
| 18 | + | |
| 17 | 19 | @Schema(description = "字典数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 18 | 20 | private Long id; |
| 19 | 21 | ... | ... |