Commit e384b810bf360817c5d57e7c1d779c9b659079cc

Authored by YunaiV
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
@@ -61,10 +61,13 @@ public class MoneyUtils { @@ -61,10 +61,13 @@ public class MoneyUtils {
61 /** 61 /**
62 * 分转元(字符串) 62 * 分转元(字符串)
63 * 63 *
  64 + * 例如说 fen 为 1 时,则结果为 0.01
  65 + *
64 * @param fen 分 66 * @param fen 分
65 * @return 元 67 * @return 元
66 */ 68 */
67 public static String fenToYuanStr(int fen) { 69 public static String fenToYuanStr(int fen) {
68 return new Money(0, fen).toString(); 70 return new Money(0, fen).toString();
69 } 71 }
  72 +
70 } 73 }
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java
@@ -147,4 +147,5 @@ public class ProductSpuRespDTO { @@ -147,4 +147,5 @@ public class ProductSpuRespDTO {
147 * true - 自行设置 147 * true - 自行设置
148 */ 148 */
149 private Boolean subCommissionType; 149 private Boolean subCommissionType;
  150 +
150 } 151 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java
@@ -179,6 +179,7 @@ public class ProductSpuDO extends BaseDO { @@ -179,6 +179,7 @@ public class ProductSpuDO extends BaseDO {
179 @TableField(typeHandler = JacksonTypeHandler.class) 179 @TableField(typeHandler = JacksonTypeHandler.class)
180 private List<Long> giveCouponTemplateIds; 180 private List<Long> giveCouponTemplateIds;
181 181
  182 + // TODO @puhui999:字段估计要改成 brokerageType
182 /** 183 /**
183 * 分销类型 184 * 分销类型
184 * 185 *
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/DictTypeConstants.java
@@ -8,4 +8,5 @@ package cn.iocoder.yudao.module.trade.enums; @@ -8,4 +8,5 @@ package cn.iocoder.yudao.module.trade.enums;
8 public interface DictTypeConstants { 8 public interface DictTypeConstants {
9 9
10 String BROKERAGE_WITHDRAW_STATUS = "brokerage_withdraw_status"; // 佣金提现状态 10 String BROKERAGE_WITHDRAW_STATUS = "brokerage_withdraw_status"; // 佣金提现状态
  11 +
11 } 12 }
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,6 +92,7 @@ public class BrokerageUserController {
92 Set<Long> userIds = convertSet(pageResult.getList(), BrokerageUserDO::getId); 92 Set<Long> userIds = convertSet(pageResult.getList(), BrokerageUserDO::getId);
93 // 查询用户信息 93 // 查询用户信息
94 Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(userIds); 94 Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(userIds);
  95 + // TODO @疯狂:看看下面两个 getBrokerageUserCountByBindUserId、getWithdrawSummaryByUserId 有没可能一次性出结果,不然 n 次有点太花性能了;
95 // 合计分佣订单 96 // 合计分佣订单
96 Map<Long, UserBrokerageSummaryBO> userOrderSummaryMap = convertMap(userIds, 97 Map<Long, UserBrokerageSummaryBO> userOrderSummaryMap = convertMap(userIds,
97 userId -> userId, 98 userId -> userId,
@@ -101,13 +102,13 @@ public class BrokerageUserController { @@ -101,13 +102,13 @@ public class BrokerageUserController {
101 Map<Long, Long> brokerageUserCountMap = convertMap(userIds, 102 Map<Long, Long> brokerageUserCountMap = convertMap(userIds,
102 userId -> userId, 103 userId -> userId,
103 userId -> brokerageUserService.getBrokerageUserCountByBindUserId(userId, null)); 104 userId -> brokerageUserService.getBrokerageUserCountByBindUserId(userId, null));
104 -  
105 // 合计提现 105 // 合计提现
106 Map<Long, UserWithdrawSummaryBO> withdrawMap = convertMap(userIds, 106 Map<Long, UserWithdrawSummaryBO> withdrawMap = convertMap(userIds,
107 userId -> userId, 107 userId -> userId,
108 userId -> brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS)); 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,13 +77,15 @@ public class AppBrokerageUserController {
77 @PreAuthenticated 77 @PreAuthenticated
78 public CommonResult<AppBrokerageUserMySummaryRespVO> getBrokerageUserSummary() { 78 public CommonResult<AppBrokerageUserMySummaryRespVO> getBrokerageUserSummary() {
79 Long userId = getLoginUserId(); 79 Long userId = getLoginUserId();
  80 + // TODO @疯狂:后面这种,要不也改成 convert;感觉 controller 这样更容易看到整体;核心其实是 86、8/87、9/90、9/91 这阶段
80 // 统计 yesterdayPrice、withdrawPrice、firstBrokerageUserCount、secondBrokerageUserCount 字段 81 // 统计 yesterdayPrice、withdrawPrice、firstBrokerageUserCount、secondBrokerageUserCount 字段
81 LocalDateTime yesterday = LocalDateTime.now().minusDays(1); 82 LocalDateTime yesterday = LocalDateTime.now().minusDays(1);
82 LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday); 83 LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday);
83 LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday); 84 LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday);
84 AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO() 85 AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO()
85 .setYesterdayPrice(brokerageRecordService.getSummaryPriceByUserId(userId, BrokerageRecordBizTypeEnum.ORDER.getType(), beginTime, endTime)) 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 .setBrokeragePrice(0).setFrozenPrice(0) 89 .setBrokeragePrice(0).setFrozenPrice(0)
88 .setFirstBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1)) 90 .setFirstBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1))
89 .setSecondBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2)); 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&lt;BrokerageWithdrawDO @@ -41,4 +41,5 @@ public interface BrokerageWithdrawMapper extends BaseMapperX&lt;BrokerageWithdrawDO
41 "WHERE user_id = #{userId} AND status = #{status} AND deleted = FALSE") 41 "WHERE user_id = #{userId} AND status = #{status} AND deleted = FALSE")
42 UserWithdrawSummaryBO selectCountAndSumPriceByUserIdAndStatus(@Param("userId") Long userId, 42 UserWithdrawSummaryBO selectCountAndSumPriceByUserIdAndStatus(@Param("userId") Long userId,
43 @Param("status") Integer status); 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,37 +315,34 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
315 315
316 // 2.1 校验分销功能是否开启 316 // 2.1 校验分销功能是否开启
317 TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig(); 317 TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig();
318 - if (tradeConfig == null || !BooleanUtil.isTrue(tradeConfig.getBrokerageEnabled())) { 318 + if (tradeConfig == null || BooleanUtil.isFalse(tradeConfig.getBrokerageEnabled())) {
319 return respVO; 319 return respVO;
320 } 320 }
321 -  
322 // 2.2 校验用户是否有分销资格 321 // 2.2 校验用户是否有分销资格
323 respVO.setEnabled(brokerageUserService.getUserBrokerageEnabled(getLoginUserId())); 322 respVO.setEnabled(brokerageUserService.getUserBrokerageEnabled(getLoginUserId()));
324 - if (!BooleanUtil.isTrue(respVO.getEnabled())) { 323 + if (BooleanUtil.isFalse(respVO.getEnabled())) {
325 return respVO; 324 return respVO;
326 } 325 }
327 -  
328 - Integer fixedMinPrice = 0;  
329 - Integer fixedMaxPrice = 0;  
330 - Integer spuMinPrice = 0;  
331 - Integer spuMaxPrice = 0;  
332 // 2.3 校验商品是否存在 326 // 2.3 校验商品是否存在
333 ProductSpuRespDTO spu = productSpuApi.getSpu(spuId); 327 ProductSpuRespDTO spu = productSpuApi.getSpu(spuId);
334 if (spu == null) { 328 if (spu == null) {
335 return respVO; 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 List<ProductSkuRespDTO> skuList = productSkuApi.getSkuListBySpuId(ListUtil.of(spuId)); 337 List<ProductSkuRespDTO> skuList = productSkuApi.getSkuListBySpuId(ListUtil.of(spuId));
339 if (BooleanUtil.isTrue(spu.getSubCommissionType())) { 338 if (BooleanUtil.isTrue(spu.getSubCommissionType())) {
340 - // 3.1 商品单独分佣模式  
341 fixedMinPrice = getMinValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice); 339 fixedMinPrice = getMinValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice);
342 fixedMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice); 340 fixedMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice);
  341 + // 3.2 全局分佣模式(根据商品价格比例计算)
343 } else { 342 } else {
344 - // 3.2 全局分佣模式(根据商品价格比例计算)  
345 spuMinPrice = getMinValue(skuList, ProductSkuRespDTO::getPrice); 343 spuMinPrice = getMinValue(skuList, ProductSkuRespDTO::getPrice);
346 spuMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getPrice); 344 spuMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getPrice);
347 } 345 }
348 -  
349 respVO.setBrokerageMinPrice(calculatePrice(spuMinPrice, tradeConfig.getBrokerageFirstPercent(), fixedMinPrice)); 346 respVO.setBrokerageMinPrice(calculatePrice(spuMinPrice, tradeConfig.getBrokerageFirstPercent(), fixedMinPrice));
350 respVO.setBrokerageMaxPrice(calculatePrice(spuMaxPrice, tradeConfig.getBrokerageFirstPercent(), fixedMaxPrice)); 347 respVO.setBrokerageMaxPrice(calculatePrice(spuMaxPrice, tradeConfig.getBrokerageFirstPercent(), fixedMaxPrice));
351 return respVO; 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,6 +236,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
236 236
237 // 校验分销关系绑定模式 237 // 校验分销关系绑定模式
238 if (BrokerageBindModeEnum.REGISTER.getMode().equals(tradeConfig.getBrokerageBindMode())) { 238 if (BrokerageBindModeEnum.REGISTER.getMode().equals(tradeConfig.getBrokerageBindMode())) {
  239 + // TODO @疯狂:是不是把 isNewUser 挪到这里好点呀?
239 if (!BooleanUtil.isTrue(isNewUser)) { 240 if (!BooleanUtil.isTrue(isNewUser)) {
240 throw exception(BROKERAGE_BIND_MODE_REGISTER); // 只有在注册时可以绑定 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
@@ -36,7 +36,7 @@ public class MemberUserRespDTO { @@ -36,7 +36,7 @@ public class MemberUserRespDTO {
36 */ 36 */
37 private String mobile; 37 private String mobile;
38 /** 38 /**
39 - * 创建时间 39 + * 创建时间(注册时间)
40 */ 40 */
41 private LocalDateTime createTime; 41 private LocalDateTime createTime;
42 42
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,7 +31,7 @@ public class AppDictDataController {
31 @GetMapping("/type") 31 @GetMapping("/type")
32 @Operation(summary = "根据字典类型查询字典数据信息") 32 @Operation(summary = "根据字典类型查询字典数据信息")
33 @Parameter(name = "type", description = "字典类型", required = true, example = "common_status") 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 List<DictDataDO> list = dictDataService.getEnabledDictDataListByType(type); 35 List<DictDataDO> list = dictDataService.getEnabledDictDataListByType(type);
36 return success(DictDataConvert.INSTANCE.convertList03(list)); 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,7 +6,6 @@ import lombok.Data;
6 import lombok.NoArgsConstructor; 6 import lombok.NoArgsConstructor;
7 7
8 import javax.validation.constraints.NotBlank; 8 import javax.validation.constraints.NotBlank;
9 -import javax.validation.constraints.NotNull;  
10 import javax.validation.constraints.Size; 9 import javax.validation.constraints.Size;
11 10
12 @Schema(description = "用户 App - 字典数据信息 Response VO") 11 @Schema(description = "用户 App - 字典数据信息 Response VO")
@@ -19,23 +18,12 @@ public class AppDictDataRespVO { @@ -19,23 +18,12 @@ public class AppDictDataRespVO {
19 private Long id; 18 private Long id;
20 19
21 @Schema(description = "字典标签", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") 20 @Schema(description = "字典标签", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
22 - @NotBlank(message = "字典标签不能为空")  
23 - @Size(max = 100, message = "字典标签长度不能超过100个字符")  
24 private String label; 21 private String label;
25 22
26 @Schema(description = "字典值", requiredMode = Schema.RequiredMode.REQUIRED, example = "iocoder") 23 @Schema(description = "字典值", requiredMode = Schema.RequiredMode.REQUIRED, example = "iocoder")
27 - @NotBlank(message = "字典键值不能为空")  
28 - @Size(max = 100, message = "字典键值长度不能超过100个字符")  
29 private String value; 24 private String value;
30 25
31 @Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex") 26 @Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex")
32 - @NotBlank(message = "字典类型不能为空")  
33 - @Size(max = 100, message = "字典类型长度不能超过100个字符")  
34 private String dictType; 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&lt;DictDataDO&gt; { @@ -50,6 +50,8 @@ public interface DictDataMapper extends BaseMapperX&lt;DictDataDO&gt; {
50 50
51 default List<DictDataDO> selectListByTypeAndStatus(String dictType, Integer status) { 51 default List<DictDataDO> selectListByTypeAndStatus(String dictType, Integer status) {
52 return selectList(new LambdaQueryWrapper<DictDataDO>() 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 }