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,7 +17,7 @@ public enum BrokerageRecordBizTypeEnum implements IntArrayValuable {
17 17
18 ORDER(1, "获得推广佣金", "获得推广佣金 {}", true), 18 ORDER(1, "获得推广佣金", "获得推广佣金 {}", true),
19 WITHDRAW(2, "提现申请", "提现申请扣除佣金 {}", false), 19 WITHDRAW(2, "提现申请", "提现申请扣除佣金 {}", false),
20 - WITHDRAW_REJECT(3, "提现申请驳回", "提现申请驳回返还佣金 {}", true), 20 + WITHDRAW_REJECT(3, "提现申请驳回", "提现申请驳回,返还佣金 {}", true),
21 ; 21 ;
22 22
23 public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageRecordBizTypeEnum::getType).toArray(); 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 +6,7 @@ import lombok.Getter;
6 6
7 import java.util.Arrays; 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,7 +45,7 @@ public class AppBrokerageRecordController {
45 @GetMapping("/get-product-brokerage-price") 45 @GetMapping("/get-product-brokerage-price")
46 @Operation(summary = "获得商品的分销金额") 46 @Operation(summary = "获得商品的分销金额")
47 public CommonResult<AppBrokerageProductPriceRespVO> getProductBrokeragePrice(@RequestParam("spuId") Long spuId) { 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,7 +3,6 @@ package cn.iocoder.yudao.module.trade.controller.app.brokerage;
3 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; 5 import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
6 -import cn.iocoder.yudao.module.system.api.dict.DictDataApi;  
7 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO; 6 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO;
8 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawPageReqVO; 7 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawPageReqVO;
9 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO; 8 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO;
@@ -32,14 +31,10 @@ public class AppBrokerageWithdrawController { @@ -32,14 +31,10 @@ public class AppBrokerageWithdrawController {
32 @Resource 31 @Resource
33 private BrokerageWithdrawService brokerageWithdrawService; 32 private BrokerageWithdrawService brokerageWithdrawService;
34 33
35 - @Resource  
36 - private DictDataApi dictDataApi;  
37 -  
38 @GetMapping("/page") 34 @GetMapping("/page")
39 @Operation(summary = "获得分销提现分页") 35 @Operation(summary = "获得分销提现分页")
40 @PreAuthenticated 36 @PreAuthenticated
41 public CommonResult<PageResult<AppBrokerageWithdrawRespVO>> getBrokerageWithdrawPage(AppBrokerageWithdrawPageReqVO pageReqVO) { 37 public CommonResult<PageResult<AppBrokerageWithdrawRespVO>> getBrokerageWithdrawPage(AppBrokerageWithdrawPageReqVO pageReqVO) {
42 - // 分页查询  
43 PageResult<BrokerageWithdrawDO> pageResult = brokerageWithdrawService.getBrokerageWithdrawPage( 38 PageResult<BrokerageWithdrawDO> pageResult = brokerageWithdrawService.getBrokerageWithdrawPage(
44 BrokerageWithdrawConvert.INSTANCE.convert(pageReqVO, getLoginUserId())); 39 BrokerageWithdrawConvert.INSTANCE.convert(pageReqVO, getLoginUserId()));
45 return success(BrokerageWithdrawConvert.INSTANCE.convertPage03(pageResult)); 40 return success(BrokerageWithdrawConvert.INSTANCE.convertPage03(pageResult));
@@ -49,7 +44,7 @@ public class AppBrokerageWithdrawController { @@ -49,7 +44,7 @@ public class AppBrokerageWithdrawController {
49 @Operation(summary = "创建分销提现") 44 @Operation(summary = "创建分销提现")
50 @PreAuthenticated 45 @PreAuthenticated
51 public CommonResult<Long> createBrokerageWithdraw(@RequestBody @Valid AppBrokerageWithdrawCreateReqVO createReqVO) { 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,6 +4,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
4 import cn.iocoder.yudao.framework.common.pojo.SortingField; 4 import cn.iocoder.yudao.framework.common.pojo.SortingField;
5 import io.swagger.v3.oas.annotations.media.Schema; 5 import io.swagger.v3.oas.annotations.media.Schema;
6 import lombok.Data; 6 import lombok.Data;
  7 +import org.hibernate.validator.constraints.Range;
  8 +
  9 +import javax.validation.constraints.NotNull;
7 10
8 @Schema(description = "用户 App - 下级分销统计分页 Request VO") 11 @Schema(description = "用户 App - 下级分销统计分页 Request VO")
9 @Data 12 @Data
@@ -19,7 +22,9 @@ public class AppBrokerageUserChildSummaryPageReqVO extends PageParam { @@ -19,7 +22,9 @@ public class AppBrokerageUserChildSummaryPageReqVO extends PageParam {
19 @Schema(description = "排序字段", example = "userCount") 22 @Schema(description = "排序字段", example = "userCount")
20 private SortingField sortingField; 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 private Integer level; 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,6 +105,8 @@ public class TradeOrderDO extends BaseDO {
105 */ 105 */
106 private Boolean commentStatus; 106 private Boolean commentStatus;
107 107
  108 + // TODO @疯狂:加一个推广人编号;
  109 +
108 // ========== 价格 + 支付基本信息 ========== 110 // ========== 价格 + 支付基本信息 ==========
109 111
110 // 价格文档 - 淘宝:https://open.taobao.com/docV3.htm?docId=108471&docType=1 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,6 +62,19 @@ public interface BrokerageRecordService {
62 void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, Integer brokeragePrice, String title); 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 * @param userId 会员编号 80 * @param userId 会员编号
@@ -134,10 +147,10 @@ public interface BrokerageRecordService { @@ -134,10 +147,10 @@ public interface BrokerageRecordService {
134 /** 147 /**
135 * 计算商品被购买后,推广员可以得到的佣金 148 * 计算商品被购买后,推广员可以得到的佣金
136 * 149 *
137 - * @param spuId 商品编号  
138 * @param userId 用户编号 150 * @param userId 用户编号
  151 + * @param spuId 商品编号
139 * @return 用户佣金 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,6 +231,30 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
231 return count; 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 @Override 258 @Override
235 public List<UserBrokerageSummaryRespBO> getUserBrokerageSummaryListByUserId(Collection<Long> userIds, 259 public List<UserBrokerageSummaryRespBO> getUserBrokerageSummaryListByUserId(Collection<Long> userIds,
236 Integer bizType, Integer status) { 260 Integer bizType, Integer status) {
@@ -255,6 +279,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { @@ -255,6 +279,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
255 return new PageResult<>(pageResult.getRecords(), pageResult.getTotal()); 279 return new PageResult<>(pageResult.getRecords(), pageResult.getTotal());
256 } 280 }
257 281
  282 + // TODO @疯狂:这个要不我们先做精准的?先查询自己的推广金额,然后查询比该金额多的有多少人?
258 @Override 283 @Override
259 public Integer getUserRankByPrice(Long userId, LocalDateTime[] times) { 284 public Integer getUserRankByPrice(Long userId, LocalDateTime[] times) {
260 AppBrokerageUserRankPageReqVO pageParam = new AppBrokerageUserRankPageReqVO().setTimes(times); 285 AppBrokerageUserRankPageReqVO pageParam = new AppBrokerageUserRankPageReqVO().setTimes(times);
@@ -291,26 +316,8 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { @@ -291,26 +316,8 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
291 brokerageRecordMapper.insert(record); 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 @Override 319 @Override
313 - public AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long spuId, Long userId) { 320 + public AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long userId, Long spuId) {
314 // 1. 构建默认的返回值 321 // 1. 构建默认的返回值
315 AppBrokerageProductPriceRespVO respVO = new AppBrokerageProductPriceRespVO().setEnabled(false) 322 AppBrokerageProductPriceRespVO respVO = new AppBrokerageProductPriceRespVO().setEnabled(false)
316 .setBrokerageMinPrice(0).setBrokerageMaxPrice(0); 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,11 +49,11 @@ public interface BrokerageWithdrawService {
49 /** 49 /**
50 * 【会员】创建佣金提现 50 * 【会员】创建佣金提现
51 * 51 *
52 - * @param createReqVO 创建信息  
53 * @param userId 会员用户编号 52 * @param userId 会员用户编号
  53 + * @param createReqVO 创建信息
54 * @return 佣金提现编号 54 * @return 佣金提现编号
55 */ 55 */
56 - Long createBrokerageWithdraw(AppBrokerageWithdrawCreateReqVO createReqVO, Long userId); 56 + Long createBrokerageWithdraw(Long userId, AppBrokerageWithdrawCreateReqVO createReqVO);
57 57
58 /** 58 /**
59 * 按照 userId,汇总每个用户的提现 59 * 按照 userId,汇总每个用户的提现
@@ -62,7 +62,8 @@ public interface BrokerageWithdrawService { @@ -62,7 +62,8 @@ public interface BrokerageWithdrawService {
62 * @param status 提现状态 62 * @param status 提现状态
63 * @return 用户提现汇总 List 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 * 按照 userId,汇总每个用户的提现 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,29 +69,27 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
69 } 69 }
70 70
71 // 2. 更新 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 if (rows == 0) { 74 if (rows == 0) {
78 throw exception(BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING); 75 throw exception(BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING);
79 } 76 }
80 77
81 - String templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_APPROVE; 78 + String templateCode;
82 if (BrokerageWithdrawStatusEnum.AUDIT_SUCCESS.equals(status)) { 79 if (BrokerageWithdrawStatusEnum.AUDIT_SUCCESS.equals(status)) {
  80 + templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_APPROVE;
83 // 3.1 通过时佣金转余额 81 // 3.1 通过时佣金转余额
84 if (BrokerageWithdrawTypeEnum.WALLET.getType().equals(withdraw.getType())) { 82 if (BrokerageWithdrawTypeEnum.WALLET.getType().equals(withdraw.getType())) {
85 - // todo 83 + // todo 疯狂:
86 } 84 }
  85 + // TODO 疯狂:调用转账接口
87 } else if (BrokerageWithdrawStatusEnum.AUDIT_FAIL.equals(status)) { 86 } else if (BrokerageWithdrawStatusEnum.AUDIT_FAIL.equals(status)) {
88 templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_REJECT; 87 templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_REJECT;
89 -  
90 // 3.2 驳回时需要退还用户佣金 88 // 3.2 驳回时需要退还用户佣金
91 brokerageRecordService.addBrokerage(withdraw.getUserId(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT, 89 brokerageRecordService.addBrokerage(withdraw.getUserId(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT,
92 String.valueOf(withdraw.getId()), withdraw.getPrice(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT.getTitle()); 90 String.valueOf(withdraw.getId()), withdraw.getPrice(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT.getTitle());
93 } else { 91 } else {
94 - throw new IllegalArgumentException("不支持的提现状态"); 92 + throw new IllegalArgumentException("不支持的提现状态:" + status);
95 } 93 }
96 94
97 // 4. 通知用户 95 // 4. 通知用户
@@ -100,10 +98,8 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { @@ -100,10 +98,8 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
100 .put("price", MoneyUtils.fenToYuanStr(withdraw.getPrice())) 98 .put("price", MoneyUtils.fenToYuanStr(withdraw.getPrice()))
101 .put("reason", withdraw.getAuditReason()) 99 .put("reason", withdraw.getAuditReason())
102 .build(); 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 private BrokerageWithdrawDO validateBrokerageWithdrawExists(Integer id) { 105 private BrokerageWithdrawDO validateBrokerageWithdrawExists(Integer id) {
@@ -126,22 +122,22 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { @@ -126,22 +122,22 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
126 122
127 @Override 123 @Override
128 @Transactional(rollbackFor = Exception.class) 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 TradeConfigDO tradeConfig = validateWithdrawPrice(createReqVO.getPrice()); 127 TradeConfigDO tradeConfig = validateWithdrawPrice(createReqVO.getPrice());
132 - // 校验提现参数 128 + // 1.2 校验提现参数
133 createReqVO.validate(validator); 129 createReqVO.validate(validator);
134 130
135 - // 计算手续费 131 + // 2.1 计算手续费
136 Integer feePrice = calculateFeePrice(createReqVO.getPrice(), tradeConfig.getBrokerageWithdrawFeePercent()); 132 Integer feePrice = calculateFeePrice(createReqVO.getPrice(), tradeConfig.getBrokerageWithdrawFeePercent());
137 - // 创建佣金提现记录 133 + // 2.2 创建佣金提现记录
138 BrokerageWithdrawDO withdraw = BrokerageWithdrawConvert.INSTANCE.convert(createReqVO, userId, feePrice); 134 BrokerageWithdrawDO withdraw = BrokerageWithdrawConvert.INSTANCE.convert(createReqVO, userId, feePrice);
139 brokerageWithdrawMapper.insert(withdraw); 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 return withdraw.getId(); 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,6 +5,7 @@
5 <select id="selectSummaryPageByUserId" 5 <select id="selectSummaryPageByUserId"
6 resultType="cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO"> 6 resultType="cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO">
7 SELECT bu.id, bu.bind_user_time AS brokerageTime, u.nickname, u.avatar, 7 SELECT bu.id, bu.bind_user_time AS brokerageTime, u.nickname, u.avatar,
  8 + <!-- TODO @疯狂:biz_type、status 可以通过参数传入哇? -->
8 (SELECT SUM(price) FROM trade_brokerage_record r 9 (SELECT SUM(price) FROM trade_brokerage_record r
9 WHERE r.user_id = u.id AND biz_type = 1 AND r.status = 1 AND r.deleted = FALSE) AS brokeragePrice, 10 WHERE r.user_id = u.id AND biz_type = 1 AND r.status = 1 AND r.deleted = FALSE) AS brokeragePrice,
10 (SELECT COUNT(1) FROM trade_brokerage_record r 11 (SELECT COUNT(1) FROM trade_brokerage_record r
@@ -13,7 +14,8 @@ @@ -13,7 +14,8 @@
13 WHERE c.bind_user_id = u.id AND c.deleted = FALSE) AS brokerageUserCount 14 WHERE c.bind_user_id = u.id AND c.deleted = FALSE) AS brokerageUserCount
14 FROM member_user AS u 15 FROM member_user AS u
15 JOIN trade_brokerage_user AS bu ON bu.id = u.id 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 <if test="param.nickname != null and param.nickname != ''"> 19 <if test="param.nickname != null and param.nickname != ''">
18 AND u.nickname LIKE concat('', #{param.nickname}, '') 20 AND u.nickname LIKE concat('', #{param.nickname}, '')
19 </if> 21 </if>
yudao-server/src/main/resources/application-local.yaml
@@ -9,7 +9,7 @@ spring: @@ -9,7 +9,7 @@ spring:
9 exclude: 9 exclude:
10 - com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 排除 Druid 的自动配置,使用 dynamic-datasource-spring-boot-starter 配置多数据源 10 - com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 排除 Druid 的自动配置,使用 dynamic-datasource-spring-boot-starter 配置多数据源
11 - org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration # 排除积木报表带来的 MongoDB 的自动配置 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 - de.codecentric.boot.admin.server.config.AdminServerAutoConfiguration # 禁用 Spring Boot Admin 的 Server 的自动配置 13 - de.codecentric.boot.admin.server.config.AdminServerAutoConfiguration # 禁用 Spring Boot Admin 的 Server 的自动配置
14 - de.codecentric.boot.admin.server.ui.config.AdminServerUiAutoConfiguration # 禁用 Spring Boot Admin 的 Server UI 的自动配置 14 - de.codecentric.boot.admin.server.ui.config.AdminServerUiAutoConfiguration # 禁用 Spring Boot Admin 的 Server UI 的自动配置
15 - de.codecentric.boot.admin.client.config.SpringBootAdminClientAutoConfiguration # 禁用 Spring Boot Admin 的 Client 的自动配置 15 - de.codecentric.boot.admin.client.config.SpringBootAdminClientAutoConfiguration # 禁用 Spring Boot Admin 的 Client 的自动配置