Commit f9bf41d7735d5f8f44c3e6dbcb255d21f3a835e1

Authored by YunaiV
1 parent b1ce971a

code review:分佣剩余部分的 review

Showing 13 changed files with 79 additions and 61 deletions
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java
... ... @@ -17,7 +17,7 @@ public enum BrokerageRecordBizTypeEnum implements IntArrayValuable {
17 17  
18 18 ORDER(1, "获得推广佣金", "获得推广佣金 {}", true),
19 19 WITHDRAW(2, "提现申请", "提现申请扣除佣金 {}", false),
20   - WITHDRAW_REJECT(3, "提现申请驳回", "提现申请驳回返还佣金 {}", true),
  20 + WITHDRAW_REJECT(3, "提现申请驳回", "提现申请驳回,返还佣金 {}", true),
21 21 ;
22 22  
23 23 public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageRecordBizTypeEnum::getType).toArray();
... ...
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java
... ... @@ -6,6 +6,7 @@ import lombok.Getter;
6 6  
7 7 import java.util.Arrays;
8 8  
  9 +// TODO 芋艿:提现的打通,在纠结下;
9 10 /**
10 11 * 佣金提现状态枚举
11 12 *
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java
... ... @@ -45,7 +45,7 @@ public class AppBrokerageRecordController {
45 45 @GetMapping("/get-product-brokerage-price")
46 46 @Operation(summary = "获得商品的分销金额")
47 47 public CommonResult<AppBrokerageProductPriceRespVO> getProductBrokeragePrice(@RequestParam("spuId") Long spuId) {
48   - return success(brokerageRecordService.calculateProductBrokeragePrice(spuId, getLoginUserId()));
  48 + return success(brokerageRecordService.calculateProductBrokeragePrice(getLoginUserId(), spuId));
49 49 }
50 50  
51 51 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java
... ... @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.trade.controller.app.brokerage;
3 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 5 import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
6   -import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
7 6 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO;
8 7 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawPageReqVO;
9 8 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO;
... ... @@ -32,14 +31,10 @@ public class AppBrokerageWithdrawController {
32 31 @Resource
33 32 private BrokerageWithdrawService brokerageWithdrawService;
34 33  
35   - @Resource
36   - private DictDataApi dictDataApi;
37   -
38 34 @GetMapping("/page")
39 35 @Operation(summary = "获得分销提现分页")
40 36 @PreAuthenticated
41 37 public CommonResult<PageResult<AppBrokerageWithdrawRespVO>> getBrokerageWithdrawPage(AppBrokerageWithdrawPageReqVO pageReqVO) {
42   - // 分页查询
43 38 PageResult<BrokerageWithdrawDO> pageResult = brokerageWithdrawService.getBrokerageWithdrawPage(
44 39 BrokerageWithdrawConvert.INSTANCE.convert(pageReqVO, getLoginUserId()));
45 40 return success(BrokerageWithdrawConvert.INSTANCE.convertPage03(pageResult));
... ... @@ -49,7 +44,7 @@ public class AppBrokerageWithdrawController {
49 44 @Operation(summary = "创建分销提现")
50 45 @PreAuthenticated
51 46 public CommonResult<Long> createBrokerageWithdraw(@RequestBody @Valid AppBrokerageWithdrawCreateReqVO createReqVO) {
52   - return success(brokerageWithdrawService.createBrokerageWithdraw(createReqVO, getLoginUserId()));
  47 + return success(brokerageWithdrawService.createBrokerageWithdraw(getLoginUserId(), createReqVO));
53 48 }
54 49  
55 50 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryPageReqVO.java
... ... @@ -4,6 +4,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
4 4 import cn.iocoder.yudao.framework.common.pojo.SortingField;
5 5 import io.swagger.v3.oas.annotations.media.Schema;
6 6 import lombok.Data;
  7 +import org.hibernate.validator.constraints.Range;
  8 +
  9 +import javax.validation.constraints.NotNull;
7 10  
8 11 @Schema(description = "用户 App - 下级分销统计分页 Request VO")
9 12 @Data
... ... @@ -19,7 +22,9 @@ public class AppBrokerageUserChildSummaryPageReqVO extends PageParam {
19 22 @Schema(description = "排序字段", example = "userCount")
20 23 private SortingField sortingField;
21 24  
22   - @Schema(description = "下级的级别", example = "1") // 1 - 直接下级;2 - 间接下级
  25 + @Schema(description = "下级的级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") // 1 - 直接下级;2 - 间接下级
  26 + @NotNull(message = "下级的级别不能为空")
  27 + @Range(min = 1, max = 2, message = "下级的级别只能是 {min} 或者 {max}")
23 28 private Integer level;
24 29  
25 30 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java
... ... @@ -105,6 +105,8 @@ public class TradeOrderDO extends BaseDO {
105 105 */
106 106 private Boolean commentStatus;
107 107  
  108 + // TODO @疯狂:加一个推广人编号;
  109 +
108 110 // ========== 价格 + 支付基本信息 ==========
109 111  
110 112 // 价格文档 - 淘宝:https://open.taobao.com/docV3.htm?docId=108471&docType=1
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/package-info.java deleted
1   -/**
2   - * 占位文件,无特殊用途
3   - */
4   -package cn.iocoder.yudao.module.trade.job;
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java
... ... @@ -62,6 +62,19 @@ public interface BrokerageRecordService {
62 62 void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, Integer brokeragePrice, String title);
63 63  
64 64 /**
  65 + * 减少佣金【只针对自己】
  66 + *
  67 + * @param userId 会员编号
  68 + * @param bizType 业务类型
  69 + * @param bizId 业务编号
  70 + * @param brokeragePrice 佣金
  71 + * @param title 标题
  72 + */
  73 + default void reduceBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, Integer brokeragePrice, String title) {
  74 + addBrokerage(userId, bizType, bizId, -brokeragePrice, title);
  75 + }
  76 +
  77 + /**
65 78 * 取消佣金:将佣金记录,状态修改为已失效
66 79 *
67 80 * @param userId 会员编号
... ... @@ -134,10 +147,10 @@ public interface BrokerageRecordService {
134 147 /**
135 148 * 计算商品被购买后,推广员可以得到的佣金
136 149 *
137   - * @param spuId 商品编号
138 150 * @param userId 用户编号
  151 + * @param spuId 商品编号
139 152 * @return 用户佣金
140 153 */
141   - AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long spuId, Long userId);
  154 + AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long userId, Long spuId);
142 155  
143 156 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java
... ... @@ -231,6 +231,30 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
231 231 return count;
232 232 }
233 233  
  234 + /**
  235 + * 激动单条佣金记录
  236 + *
  237 + * @param record 佣金记录
  238 + * @return 解冻是否成功
  239 + */
  240 + @Transactional(rollbackFor = Exception.class)
  241 + public boolean unfreezeRecord(BrokerageRecordDO record) {
  242 + // 更新记录状态
  243 + BrokerageRecordDO updateObj = new BrokerageRecordDO()
  244 + .setStatus(BrokerageRecordStatusEnum.SETTLEMENT.getStatus())
  245 + .setUnfreezeTime(LocalDateTime.now());
  246 + int updateRows = brokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj);
  247 + if (updateRows == 0) {
  248 + log.error("[unfreezeRecord][record({}) 更新为已结算失败]", record.getId());
  249 + return false;
  250 + }
  251 +
  252 + // 更新用户冻结佣金
  253 + brokerageUserService.updateFrozenPriceDecrAndPriceIncr(record.getUserId(), -record.getPrice());
  254 + log.info("[unfreezeRecord][record({}) 更新为已结算成功]", record.getId());
  255 + return true;
  256 + }
  257 +
234 258 @Override
235 259 public List<UserBrokerageSummaryRespBO> getUserBrokerageSummaryListByUserId(Collection<Long> userIds,
236 260 Integer bizType, Integer status) {
... ... @@ -255,6 +279,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
255 279 return new PageResult<>(pageResult.getRecords(), pageResult.getTotal());
256 280 }
257 281  
  282 + // TODO @疯狂:这个要不我们先做精准的?先查询自己的推广金额,然后查询比该金额多的有多少人?
258 283 @Override
259 284 public Integer getUserRankByPrice(Long userId, LocalDateTime[] times) {
260 285 AppBrokerageUserRankPageReqVO pageParam = new AppBrokerageUserRankPageReqVO().setTimes(times);
... ... @@ -291,26 +316,8 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
291 316 brokerageRecordMapper.insert(record);
292 317 }
293 318  
294   - @Transactional(rollbackFor = Exception.class)
295   - public boolean unfreezeRecord(BrokerageRecordDO record) {
296   - // 更新记录状态
297   - BrokerageRecordDO updateObj = new BrokerageRecordDO()
298   - .setStatus(BrokerageRecordStatusEnum.SETTLEMENT.getStatus())
299   - .setUnfreezeTime(LocalDateTime.now());
300   - int updateRows = brokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj);
301   - if (updateRows == 0) {
302   - log.error("[unfreezeRecord][record({}) 更新为已结算失败]", record.getId());
303   - return false;
304   - }
305   -
306   - // 更新用户冻结佣金
307   - brokerageUserService.updateFrozenPriceDecrAndPriceIncr(record.getUserId(), -record.getPrice());
308   - log.info("[unfreezeRecord][record({}) 更新为已结算成功]", record.getId());
309   - return true;
310   - }
311   -
312 319 @Override
313   - public AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long spuId, Long userId) {
  320 + public AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long userId, Long spuId) {
314 321 // 1. 构建默认的返回值
315 322 AppBrokerageProductPriceRespVO respVO = new AppBrokerageProductPriceRespVO().setEnabled(false)
316 323 .setBrokerageMinPrice(0).setBrokerageMaxPrice(0);
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java
... ... @@ -49,11 +49,11 @@ public interface BrokerageWithdrawService {
49 49 /**
50 50 * 【会员】创建佣金提现
51 51 *
52   - * @param createReqVO 创建信息
53 52 * @param userId 会员用户编号
  53 + * @param createReqVO 创建信息
54 54 * @return 佣金提现编号
55 55 */
56   - Long createBrokerageWithdraw(AppBrokerageWithdrawCreateReqVO createReqVO, Long userId);
  56 + Long createBrokerageWithdraw(Long userId, AppBrokerageWithdrawCreateReqVO createReqVO);
57 57  
58 58 /**
59 59 * 按照 userId,汇总每个用户的提现
... ... @@ -62,7 +62,8 @@ public interface BrokerageWithdrawService {
62 62 * @param status 提现状态
63 63 * @return 用户提现汇总 List
64 64 */
65   - List<BrokerageWithdrawSummaryRespBO> getWithdrawSummaryListByUserId(Collection<Long> userIds, BrokerageWithdrawStatusEnum status);
  65 + List<BrokerageWithdrawSummaryRespBO> getWithdrawSummaryListByUserId(Collection<Long> userIds,
  66 + BrokerageWithdrawStatusEnum status);
66 67  
67 68 /**
68 69 * 按照 userId,汇总每个用户的提现
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java
... ... @@ -69,29 +69,27 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
69 69 }
70 70  
71 71 // 2. 更新
72   - BrokerageWithdrawDO updateObj = new BrokerageWithdrawDO()
73   - .setStatus(status.getStatus())
74   - .setAuditReason(auditReason)
75   - .setAuditTime(LocalDateTime.now());
76   - int rows = brokerageWithdrawMapper.updateByIdAndStatus(id, BrokerageWithdrawStatusEnum.AUDITING.getStatus(), updateObj);
  72 + int rows = brokerageWithdrawMapper.updateByIdAndStatus(id, BrokerageWithdrawStatusEnum.AUDITING.getStatus(),
  73 + new BrokerageWithdrawDO().setStatus(status.getStatus()).setAuditReason(auditReason).setAuditTime(LocalDateTime.now()));
77 74 if (rows == 0) {
78 75 throw exception(BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING);
79 76 }
80 77  
81   - String templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_APPROVE;
  78 + String templateCode;
82 79 if (BrokerageWithdrawStatusEnum.AUDIT_SUCCESS.equals(status)) {
  80 + templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_APPROVE;
83 81 // 3.1 通过时佣金转余额
84 82 if (BrokerageWithdrawTypeEnum.WALLET.getType().equals(withdraw.getType())) {
85   - // todo
  83 + // todo 疯狂:
86 84 }
  85 + // TODO 疯狂:调用转账接口
87 86 } else if (BrokerageWithdrawStatusEnum.AUDIT_FAIL.equals(status)) {
88 87 templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_REJECT;
89   -
90 88 // 3.2 驳回时需要退还用户佣金
91 89 brokerageRecordService.addBrokerage(withdraw.getUserId(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT,
92 90 String.valueOf(withdraw.getId()), withdraw.getPrice(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT.getTitle());
93 91 } else {
94   - throw new IllegalArgumentException("不支持的提现状态");
  92 + throw new IllegalArgumentException("不支持的提现状态:" + status);
95 93 }
96 94  
97 95 // 4. 通知用户
... ... @@ -100,10 +98,8 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
100 98 .put("price", MoneyUtils.fenToYuanStr(withdraw.getPrice()))
101 99 .put("reason", withdraw.getAuditReason())
102 100 .build();
103   - NotifySendSingleToUserReqDTO reqDTO = new NotifySendSingleToUserReqDTO()
104   - .setUserId(withdraw.getUserId())
105   - .setTemplateCode(templateCode).setTemplateParams(templateParams);
106   - notifyMessageSendApi.sendSingleMessageToMember(reqDTO);
  101 + notifyMessageSendApi.sendSingleMessageToMember(new NotifySendSingleToUserReqDTO()
  102 + .setUserId(withdraw.getUserId()).setTemplateCode(templateCode).setTemplateParams(templateParams));
107 103 }
108 104  
109 105 private BrokerageWithdrawDO validateBrokerageWithdrawExists(Integer id) {
... ... @@ -126,22 +122,22 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
126 122  
127 123 @Override
128 124 @Transactional(rollbackFor = Exception.class)
129   - public Long createBrokerageWithdraw(AppBrokerageWithdrawCreateReqVO createReqVO, Long userId) {
130   - // 校验提现金额
  125 + public Long createBrokerageWithdraw(Long userId, AppBrokerageWithdrawCreateReqVO createReqVO) {
  126 + // 1.1 校验提现金额
131 127 TradeConfigDO tradeConfig = validateWithdrawPrice(createReqVO.getPrice());
132   - // 校验提现参数
  128 + // 1.2 校验提现参数
133 129 createReqVO.validate(validator);
134 130  
135   - // 计算手续费
  131 + // 2.1 计算手续费
136 132 Integer feePrice = calculateFeePrice(createReqVO.getPrice(), tradeConfig.getBrokerageWithdrawFeePercent());
137   - // 创建佣金提现记录
  133 + // 2.2 创建佣金提现记录
138 134 BrokerageWithdrawDO withdraw = BrokerageWithdrawConvert.INSTANCE.convert(createReqVO, userId, feePrice);
139 135 brokerageWithdrawMapper.insert(withdraw);
140 136  
141   - // 创建用户佣金记录
142   - brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.WITHDRAW, String.valueOf(withdraw.getId()),
143   - -createReqVO.getPrice(), BrokerageRecordBizTypeEnum.WITHDRAW.getTitle());
144   -
  137 + // 3. 创建用户佣金记录
  138 + // 注意,佣金是否充足,reduceBrokerage 已经进行校验
  139 + brokerageRecordService.reduceBrokerage(userId, BrokerageRecordBizTypeEnum.WITHDRAW, String.valueOf(withdraw.getId()),
  140 + createReqVO.getPrice(), BrokerageRecordBizTypeEnum.WITHDRAW.getTitle());
145 141 return withdraw.getId();
146 142 }
147 143  
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml
... ... @@ -5,6 +5,7 @@
5 5 <select id="selectSummaryPageByUserId"
6 6 resultType="cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO">
7 7 SELECT bu.id, bu.bind_user_time AS brokerageTime, u.nickname, u.avatar,
  8 + <!-- TODO @疯狂:biz_type、status 可以通过参数传入哇? -->
8 9 (SELECT SUM(price) FROM trade_brokerage_record r
9 10 WHERE r.user_id = u.id AND biz_type = 1 AND r.status = 1 AND r.deleted = FALSE) AS brokeragePrice,
10 11 (SELECT COUNT(1) FROM trade_brokerage_record r
... ... @@ -13,7 +14,8 @@
13 14 WHERE c.bind_user_id = u.id AND c.deleted = FALSE) AS brokerageUserCount
14 15 FROM member_user AS u
15 16 JOIN trade_brokerage_user AS bu ON bu.id = u.id
16   - <where>
  17 + <!-- TODO @疯狂:1)bind_user_id 是不是可以先改成内存查询出 userId 的集合,然后去 in 哈?2)nickname 是不是可以基于查询出来的 userId 对应的 nickname 在内存里过滤,主要是避免和 member_user 链表 -->
  18 + <where>
17 19 <if test="param.nickname != null and param.nickname != ''">
18 20 AND u.nickname LIKE concat('', #{param.nickname}, '')
19 21 </if>
... ...
yudao-server/src/main/resources/application-local.yaml
... ... @@ -9,7 +9,7 @@ spring:
9 9 exclude:
10 10 - com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 排除 Druid 的自动配置,使用 dynamic-datasource-spring-boot-starter 配置多数据源
11 11 - org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration # 排除积木报表带来的 MongoDB 的自动配置
12   - - org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration # 默认 local 环境,不开启 Quartz 的自动配置
  12 +# - org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration # 默认 local 环境,不开启 Quartz 的自动配置
13 13 - de.codecentric.boot.admin.server.config.AdminServerAutoConfiguration # 禁用 Spring Boot Admin 的 Server 的自动配置
14 14 - de.codecentric.boot.admin.server.ui.config.AdminServerUiAutoConfiguration # 禁用 Spring Boot Admin 的 Server UI 的自动配置
15 15 - de.codecentric.boot.admin.client.config.SpringBootAdminClientAutoConfiguration # 禁用 Spring Boot Admin 的 Client 的自动配置
... ...