Commit e384b810bf360817c5d57e7c1d779c9b659079cc
1 parent
c9236512
code review:分销逻辑
Showing
13 changed files
with
28 additions
and
30 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/DictTypeConstants.java
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java
| ... | ... | @@ -92,6 +92,7 @@ public class BrokerageUserController { |
| 92 | 92 | Set<Long> userIds = convertSet(pageResult.getList(), BrokerageUserDO::getId); |
| 93 | 93 | // 查询用户信息 |
| 94 | 94 | Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(userIds); |
| 95 | + // TODO @疯狂:看看下面两个 getBrokerageUserCountByBindUserId、getWithdrawSummaryByUserId 有没可能一次性出结果,不然 n 次有点太花性能了; | |
| 95 | 96 | // 合计分佣订单 |
| 96 | 97 | Map<Long, UserBrokerageSummaryBO> userOrderSummaryMap = convertMap(userIds, |
| 97 | 98 | userId -> userId, |
| ... | ... | @@ -101,13 +102,13 @@ public class BrokerageUserController { |
| 101 | 102 | Map<Long, Long> brokerageUserCountMap = convertMap(userIds, |
| 102 | 103 | userId -> userId, |
| 103 | 104 | userId -> brokerageUserService.getBrokerageUserCountByBindUserId(userId, null)); |
| 104 | - | |
| 105 | 105 | // 合计提现 |
| 106 | 106 | Map<Long, UserWithdrawSummaryBO> withdrawMap = convertMap(userIds, |
| 107 | 107 | userId -> userId, |
| 108 | 108 | userId -> brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS)); |
| 109 | - | |
| 110 | - return success(BrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap, withdrawMap)); | |
| 109 | + // 拼接返回 | |
| 110 | + return success(BrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, | |
| 111 | + userOrderSummaryMap, withdrawMap)); | |
| 111 | 112 | } |
| 112 | 113 | |
| 113 | 114 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java
| ... | ... | @@ -77,13 +77,15 @@ public class AppBrokerageUserController { |
| 77 | 77 | @PreAuthenticated |
| 78 | 78 | public CommonResult<AppBrokerageUserMySummaryRespVO> getBrokerageUserSummary() { |
| 79 | 79 | Long userId = getLoginUserId(); |
| 80 | + // TODO @疯狂:后面这种,要不也改成 convert;感觉 controller 这样更容易看到整体;核心其实是 86、8/87、9/90、9/91 这阶段 | |
| 80 | 81 | // 统计 yesterdayPrice、withdrawPrice、firstBrokerageUserCount、secondBrokerageUserCount 字段 |
| 81 | 82 | LocalDateTime yesterday = LocalDateTime.now().minusDays(1); |
| 82 | 83 | LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday); |
| 83 | 84 | LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday); |
| 84 | 85 | AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO() |
| 85 | 86 | .setYesterdayPrice(brokerageRecordService.getSummaryPriceByUserId(userId, BrokerageRecordBizTypeEnum.ORDER.getType(), beginTime, endTime)) |
| 86 | - .setWithdrawPrice(Optional.ofNullable(brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS)).map(UserWithdrawSummaryBO::getPrice).orElse(0)) | |
| 87 | + .setWithdrawPrice(Optional.ofNullable(brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS)) | |
| 88 | + .map(UserWithdrawSummaryBO::getPrice).orElse(0)) | |
| 87 | 89 | .setBrokeragePrice(0).setFrozenPrice(0) |
| 88 | 90 | .setFirstBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1)) |
| 89 | 91 | .setSecondBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2)); | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java
| ... | ... | @@ -41,4 +41,5 @@ public interface BrokerageWithdrawMapper extends BaseMapperX<BrokerageWithdrawDO |
| 41 | 41 | "WHERE user_id = #{userId} AND status = #{status} AND deleted = FALSE") |
| 42 | 42 | UserWithdrawSummaryBO selectCountAndSumPriceByUserIdAndStatus(@Param("userId") Long userId, |
| 43 | 43 | @Param("status") Integer status); |
| 44 | + | |
| 44 | 45 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java
| ... | ... | @@ -315,37 +315,34 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { |
| 315 | 315 | |
| 316 | 316 | // 2.1 校验分销功能是否开启 |
| 317 | 317 | TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig(); |
| 318 | - if (tradeConfig == null || !BooleanUtil.isTrue(tradeConfig.getBrokerageEnabled())) { | |
| 318 | + if (tradeConfig == null || BooleanUtil.isFalse(tradeConfig.getBrokerageEnabled())) { | |
| 319 | 319 | return respVO; |
| 320 | 320 | } |
| 321 | - | |
| 322 | 321 | // 2.2 校验用户是否有分销资格 |
| 323 | 322 | respVO.setEnabled(brokerageUserService.getUserBrokerageEnabled(getLoginUserId())); |
| 324 | - if (!BooleanUtil.isTrue(respVO.getEnabled())) { | |
| 323 | + if (BooleanUtil.isFalse(respVO.getEnabled())) { | |
| 325 | 324 | return respVO; |
| 326 | 325 | } |
| 327 | - | |
| 328 | - Integer fixedMinPrice = 0; | |
| 329 | - Integer fixedMaxPrice = 0; | |
| 330 | - Integer spuMinPrice = 0; | |
| 331 | - Integer spuMaxPrice = 0; | |
| 332 | 326 | // 2.3 校验商品是否存在 |
| 333 | 327 | ProductSpuRespDTO spu = productSpuApi.getSpu(spuId); |
| 334 | 328 | if (spu == null) { |
| 335 | 329 | return respVO; |
| 336 | 330 | } |
| 337 | 331 | |
| 332 | + // 3.1 商品单独分佣模式 | |
| 333 | + Integer fixedMinPrice = 0; | |
| 334 | + Integer fixedMaxPrice = 0; | |
| 335 | + Integer spuMinPrice = 0; | |
| 336 | + Integer spuMaxPrice = 0; | |
| 338 | 337 | List<ProductSkuRespDTO> skuList = productSkuApi.getSkuListBySpuId(ListUtil.of(spuId)); |
| 339 | 338 | if (BooleanUtil.isTrue(spu.getSubCommissionType())) { |
| 340 | - // 3.1 商品单独分佣模式 | |
| 341 | 339 | fixedMinPrice = getMinValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice); |
| 342 | 340 | fixedMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice); |
| 341 | + // 3.2 全局分佣模式(根据商品价格比例计算) | |
| 343 | 342 | } else { |
| 344 | - // 3.2 全局分佣模式(根据商品价格比例计算) | |
| 345 | 343 | spuMinPrice = getMinValue(skuList, ProductSkuRespDTO::getPrice); |
| 346 | 344 | spuMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getPrice); |
| 347 | 345 | } |
| 348 | - | |
| 349 | 346 | respVO.setBrokerageMinPrice(calculatePrice(spuMinPrice, tradeConfig.getBrokerageFirstPercent(), fixedMinPrice)); |
| 350 | 347 | respVO.setBrokerageMaxPrice(calculatePrice(spuMaxPrice, tradeConfig.getBrokerageFirstPercent(), fixedMaxPrice)); |
| 351 | 348 | return respVO; | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java
| ... | ... | @@ -236,6 +236,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { |
| 236 | 236 | |
| 237 | 237 | // 校验分销关系绑定模式 |
| 238 | 238 | if (BrokerageBindModeEnum.REGISTER.getMode().equals(tradeConfig.getBrokerageBindMode())) { |
| 239 | + // TODO @疯狂:是不是把 isNewUser 挪到这里好点呀? | |
| 239 | 240 | if (!BooleanUtil.isTrue(isNewUser)) { |
| 240 | 241 | throw exception(BROKERAGE_BIND_MODE_REGISTER); // 只有在注册时可以绑定 |
| 241 | 242 | } | ... | ... |
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java
| ... | ... | @@ -31,7 +31,7 @@ public class AppDictDataController { |
| 31 | 31 | @GetMapping("/type") |
| 32 | 32 | @Operation(summary = "根据字典类型查询字典数据信息") |
| 33 | 33 | @Parameter(name = "type", description = "字典类型", required = true, example = "common_status") |
| 34 | - public CommonResult<List<AppDictDataRespVO>> getDictDataListByType(@RequestParam String type) { | |
| 34 | + public CommonResult<List<AppDictDataRespVO>> getDictDataListByType(@RequestParam("type") String type) { | |
| 35 | 35 | List<DictDataDO> list = dictDataService.getEnabledDictDataListByType(type); |
| 36 | 36 | return success(DictDataConvert.INSTANCE.convertList03(list)); |
| 37 | 37 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java
| ... | ... | @@ -6,7 +6,6 @@ import lombok.Data; |
| 6 | 6 | import lombok.NoArgsConstructor; |
| 7 | 7 | |
| 8 | 8 | import javax.validation.constraints.NotBlank; |
| 9 | -import javax.validation.constraints.NotNull; | |
| 10 | 9 | import javax.validation.constraints.Size; |
| 11 | 10 | |
| 12 | 11 | @Schema(description = "用户 App - 字典数据信息 Response VO") |
| ... | ... | @@ -19,23 +18,12 @@ public class AppDictDataRespVO { |
| 19 | 18 | private Long id; |
| 20 | 19 | |
| 21 | 20 | @Schema(description = "字典标签", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") |
| 22 | - @NotBlank(message = "字典标签不能为空") | |
| 23 | - @Size(max = 100, message = "字典标签长度不能超过100个字符") | |
| 24 | 21 | private String label; |
| 25 | 22 | |
| 26 | 23 | @Schema(description = "字典值", requiredMode = Schema.RequiredMode.REQUIRED, example = "iocoder") |
| 27 | - @NotBlank(message = "字典键值不能为空") | |
| 28 | - @Size(max = 100, message = "字典键值长度不能超过100个字符") | |
| 29 | 24 | private String value; |
| 30 | 25 | |
| 31 | 26 | @Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex") |
| 32 | - @NotBlank(message = "字典类型不能为空") | |
| 33 | - @Size(max = 100, message = "字典类型长度不能超过100个字符") | |
| 34 | 27 | private String dictType; |
| 35 | 28 | |
| 36 | - @Schema(description = "颜色类型,default、primary、success、info、warning、danger", example = "default") | |
| 37 | - private String colorType; | |
| 38 | - @Schema(description = "css 样式", example = "btn-visible") | |
| 39 | - private String cssClass; | |
| 40 | - | |
| 41 | 29 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java
| ... | ... | @@ -50,6 +50,8 @@ public interface DictDataMapper extends BaseMapperX<DictDataDO> { |
| 50 | 50 | |
| 51 | 51 | default List<DictDataDO> selectListByTypeAndStatus(String dictType, Integer status) { |
| 52 | 52 | return selectList(new LambdaQueryWrapper<DictDataDO>() |
| 53 | - .eq(DictDataDO::getDictType, dictType).eq(DictDataDO::getStatus, status)); | |
| 53 | + .eq(DictDataDO::getDictType, dictType) | |
| 54 | + .eq(DictDataDO::getStatus, status)); | |
| 54 | 55 | } |
| 56 | + | |
| 55 | 57 | } | ... | ... |