diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java index 73fbb4c91..546069465 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java +++ b/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 { ORDER(1, "获得推广佣金", "获得推广佣金 {}", true), WITHDRAW(2, "提现申请", "提现申请扣除佣金 {}", false), - WITHDRAW_REJECT(3, "提现申请驳回", "提现申请驳回返还佣金 {}", true), + WITHDRAW_REJECT(3, "提现申请驳回", "提现申请驳回,返还佣金 {}", true), ; public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageRecordBizTypeEnum::getType).toArray(); diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java index a80aad02a..b68db4a71 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java +++ b/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; import java.util.Arrays; +// TODO 芋艿:提现的打通,在纠结下; /** * 佣金提现状态枚举 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java index 7cbd6e551..303e67cb4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java +++ b/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 { @GetMapping("/get-product-brokerage-price") @Operation(summary = "获得商品的分销金额") public CommonResult getProductBrokeragePrice(@RequestParam("spuId") Long spuId) { - return success(brokerageRecordService.calculateProductBrokeragePrice(spuId, getLoginUserId())); + return success(brokerageRecordService.calculateProductBrokeragePrice(getLoginUserId(), spuId)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java index 8ca12b79b..b1ef5f890 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java +++ b/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; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; -import cn.iocoder.yudao.module.system.api.dict.DictDataApi; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawPageReqVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO; @@ -32,14 +31,10 @@ public class AppBrokerageWithdrawController { @Resource private BrokerageWithdrawService brokerageWithdrawService; - @Resource - private DictDataApi dictDataApi; - @GetMapping("/page") @Operation(summary = "获得分销提现分页") @PreAuthenticated public CommonResult> getBrokerageWithdrawPage(AppBrokerageWithdrawPageReqVO pageReqVO) { - // 分页查询 PageResult pageResult = brokerageWithdrawService.getBrokerageWithdrawPage( BrokerageWithdrawConvert.INSTANCE.convert(pageReqVO, getLoginUserId())); return success(BrokerageWithdrawConvert.INSTANCE.convertPage03(pageResult)); @@ -49,7 +44,7 @@ public class AppBrokerageWithdrawController { @Operation(summary = "创建分销提现") @PreAuthenticated public CommonResult createBrokerageWithdraw(@RequestBody @Valid AppBrokerageWithdrawCreateReqVO createReqVO) { - return success(brokerageWithdrawService.createBrokerageWithdraw(createReqVO, getLoginUserId())); + return success(brokerageWithdrawService.createBrokerageWithdraw(getLoginUserId(), createReqVO)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryPageReqVO.java index 066fc0912..890500c62 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryPageReqVO.java +++ b/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; import cn.iocoder.yudao.framework.common.pojo.SortingField; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import org.hibernate.validator.constraints.Range; + +import javax.validation.constraints.NotNull; @Schema(description = "用户 App - 下级分销统计分页 Request VO") @Data @@ -19,7 +22,9 @@ public class AppBrokerageUserChildSummaryPageReqVO extends PageParam { @Schema(description = "排序字段", example = "userCount") private SortingField sortingField; - @Schema(description = "下级的级别", example = "1") // 1 - 直接下级;2 - 间接下级 + @Schema(description = "下级的级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") // 1 - 直接下级;2 - 间接下级 + @NotNull(message = "下级的级别不能为空") + @Range(min = 1, max = 2, message = "下级的级别只能是 {min} 或者 {max}") private Integer level; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java index 8a3b5b23f..ea3dd2f18 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java +++ b/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 { */ private Boolean commentStatus; + // TODO @疯狂:加一个推广人编号; + // ========== 价格 + 支付基本信息 ========== // 价格文档 - 淘宝:https://open.taobao.com/docV3.htm?docId=108471&docType=1 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/package-info.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/package-info.java deleted file mode 100644 index 129413067..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * 占位文件,无特殊用途 - */ -package cn.iocoder.yudao.module.trade.job; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java index 410c7631b..2a6e95985 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java @@ -61,6 +61,19 @@ public interface BrokerageRecordService { */ void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, Integer brokeragePrice, String title); + /** + * 减少佣金【只针对自己】 + * + * @param userId 会员编号 + * @param bizType 业务类型 + * @param bizId 业务编号 + * @param brokeragePrice 佣金 + * @param title 标题 + */ + default void reduceBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, Integer brokeragePrice, String title) { + addBrokerage(userId, bizType, bizId, -brokeragePrice, title); + } + /** * 取消佣金:将佣金记录,状态修改为已失效 * @@ -134,10 +147,10 @@ public interface BrokerageRecordService { /** * 计算商品被购买后,推广员可以得到的佣金 * - * @param spuId 商品编号 * @param userId 用户编号 + * @param spuId 商品编号 * @return 用户佣金 */ - AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long spuId, Long userId); + AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long userId, Long spuId); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java index 02fc897ba..b10c48182 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java +++ b/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 { return count; } + /** + * 激动单条佣金记录 + * + * @param record 佣金记录 + * @return 解冻是否成功 + */ + @Transactional(rollbackFor = Exception.class) + public boolean unfreezeRecord(BrokerageRecordDO record) { + // 更新记录状态 + BrokerageRecordDO updateObj = new BrokerageRecordDO() + .setStatus(BrokerageRecordStatusEnum.SETTLEMENT.getStatus()) + .setUnfreezeTime(LocalDateTime.now()); + int updateRows = brokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); + if (updateRows == 0) { + log.error("[unfreezeRecord][record({}) 更新为已结算失败]", record.getId()); + return false; + } + + // 更新用户冻结佣金 + brokerageUserService.updateFrozenPriceDecrAndPriceIncr(record.getUserId(), -record.getPrice()); + log.info("[unfreezeRecord][record({}) 更新为已结算成功]", record.getId()); + return true; + } + @Override public List getUserBrokerageSummaryListByUserId(Collection userIds, Integer bizType, Integer status) { @@ -255,6 +279,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { return new PageResult<>(pageResult.getRecords(), pageResult.getTotal()); } + // TODO @疯狂:这个要不我们先做精准的?先查询自己的推广金额,然后查询比该金额多的有多少人? @Override public Integer getUserRankByPrice(Long userId, LocalDateTime[] times) { AppBrokerageUserRankPageReqVO pageParam = new AppBrokerageUserRankPageReqVO().setTimes(times); @@ -291,26 +316,8 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { brokerageRecordMapper.insert(record); } - @Transactional(rollbackFor = Exception.class) - public boolean unfreezeRecord(BrokerageRecordDO record) { - // 更新记录状态 - BrokerageRecordDO updateObj = new BrokerageRecordDO() - .setStatus(BrokerageRecordStatusEnum.SETTLEMENT.getStatus()) - .setUnfreezeTime(LocalDateTime.now()); - int updateRows = brokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); - if (updateRows == 0) { - log.error("[unfreezeRecord][record({}) 更新为已结算失败]", record.getId()); - return false; - } - - // 更新用户冻结佣金 - brokerageUserService.updateFrozenPriceDecrAndPriceIncr(record.getUserId(), -record.getPrice()); - log.info("[unfreezeRecord][record({}) 更新为已结算成功]", record.getId()); - return true; - } - @Override - public AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long spuId, Long userId) { + public AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long userId, Long spuId) { // 1. 构建默认的返回值 AppBrokerageProductPriceRespVO respVO = new AppBrokerageProductPriceRespVO().setEnabled(false) .setBrokerageMinPrice(0).setBrokerageMaxPrice(0); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java index b934afa35..04ea9c49b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java +++ b/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 { /** * 【会员】创建佣金提现 * - * @param createReqVO 创建信息 * @param userId 会员用户编号 + * @param createReqVO 创建信息 * @return 佣金提现编号 */ - Long createBrokerageWithdraw(AppBrokerageWithdrawCreateReqVO createReqVO, Long userId); + Long createBrokerageWithdraw(Long userId, AppBrokerageWithdrawCreateReqVO createReqVO); /** * 按照 userId,汇总每个用户的提现 @@ -62,7 +62,8 @@ public interface BrokerageWithdrawService { * @param status 提现状态 * @return 用户提现汇总 List */ - List getWithdrawSummaryListByUserId(Collection userIds, BrokerageWithdrawStatusEnum status); + List getWithdrawSummaryListByUserId(Collection userIds, + BrokerageWithdrawStatusEnum status); /** * 按照 userId,汇总每个用户的提现 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java index 5c045a03b..b6b4034ce 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java +++ b/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 { } // 2. 更新 - BrokerageWithdrawDO updateObj = new BrokerageWithdrawDO() - .setStatus(status.getStatus()) - .setAuditReason(auditReason) - .setAuditTime(LocalDateTime.now()); - int rows = brokerageWithdrawMapper.updateByIdAndStatus(id, BrokerageWithdrawStatusEnum.AUDITING.getStatus(), updateObj); + int rows = brokerageWithdrawMapper.updateByIdAndStatus(id, BrokerageWithdrawStatusEnum.AUDITING.getStatus(), + new BrokerageWithdrawDO().setStatus(status.getStatus()).setAuditReason(auditReason).setAuditTime(LocalDateTime.now())); if (rows == 0) { throw exception(BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING); } - String templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_APPROVE; + String templateCode; if (BrokerageWithdrawStatusEnum.AUDIT_SUCCESS.equals(status)) { + templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_APPROVE; // 3.1 通过时佣金转余额 if (BrokerageWithdrawTypeEnum.WALLET.getType().equals(withdraw.getType())) { - // todo + // todo 疯狂: } + // TODO 疯狂:调用转账接口 } else if (BrokerageWithdrawStatusEnum.AUDIT_FAIL.equals(status)) { templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_REJECT; - // 3.2 驳回时需要退还用户佣金 brokerageRecordService.addBrokerage(withdraw.getUserId(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT, String.valueOf(withdraw.getId()), withdraw.getPrice(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT.getTitle()); } else { - throw new IllegalArgumentException("不支持的提现状态"); + throw new IllegalArgumentException("不支持的提现状态:" + status); } // 4. 通知用户 @@ -100,10 +98,8 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { .put("price", MoneyUtils.fenToYuanStr(withdraw.getPrice())) .put("reason", withdraw.getAuditReason()) .build(); - NotifySendSingleToUserReqDTO reqDTO = new NotifySendSingleToUserReqDTO() - .setUserId(withdraw.getUserId()) - .setTemplateCode(templateCode).setTemplateParams(templateParams); - notifyMessageSendApi.sendSingleMessageToMember(reqDTO); + notifyMessageSendApi.sendSingleMessageToMember(new NotifySendSingleToUserReqDTO() + .setUserId(withdraw.getUserId()).setTemplateCode(templateCode).setTemplateParams(templateParams)); } private BrokerageWithdrawDO validateBrokerageWithdrawExists(Integer id) { @@ -126,22 +122,22 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { @Override @Transactional(rollbackFor = Exception.class) - public Long createBrokerageWithdraw(AppBrokerageWithdrawCreateReqVO createReqVO, Long userId) { - // 校验提现金额 + public Long createBrokerageWithdraw(Long userId, AppBrokerageWithdrawCreateReqVO createReqVO) { + // 1.1 校验提现金额 TradeConfigDO tradeConfig = validateWithdrawPrice(createReqVO.getPrice()); - // 校验提现参数 + // 1.2 校验提现参数 createReqVO.validate(validator); - // 计算手续费 + // 2.1 计算手续费 Integer feePrice = calculateFeePrice(createReqVO.getPrice(), tradeConfig.getBrokerageWithdrawFeePercent()); - // 创建佣金提现记录 + // 2.2 创建佣金提现记录 BrokerageWithdrawDO withdraw = BrokerageWithdrawConvert.INSTANCE.convert(createReqVO, userId, feePrice); brokerageWithdrawMapper.insert(withdraw); - // 创建用户佣金记录 - brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.WITHDRAW, String.valueOf(withdraw.getId()), - -createReqVO.getPrice(), BrokerageRecordBizTypeEnum.WITHDRAW.getTitle()); - + // 3. 创建用户佣金记录 + // 注意,佣金是否充足,reduceBrokerage 已经进行校验 + brokerageRecordService.reduceBrokerage(userId, BrokerageRecordBizTypeEnum.WITHDRAW, String.valueOf(withdraw.getId()), + createReqVO.getPrice(), BrokerageRecordBizTypeEnum.WITHDRAW.getTitle()); return withdraw.getId(); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml b/yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml index b1a1ef8d6..7f75491ff 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml @@ -5,6 +5,7 @@