From 1cc2dfc963252e339b524b4a8078e217c86c4b9c Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 12:29:38 +0800 Subject: [PATCH] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80Review=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/brokerage.sql | 17 ++-- .../trade/enums/ErrorCodeConstants.java | 1 + .../brokerage/BrokerageBindModeEnum.java | 10 ++- .../BrokerageEnabledConditionEnum.java | 5 +- .../brokerage/BrokerageRecordBizTypeEnum.java | 5 +- .../user/TradeBrokerageUserController.java | 2 +- .../admin/config/vo/TradeConfigBaseVO.java | 1 - .../record/TradeBrokerageRecordConvert.java | 12 ++- .../user/TradeBrokerageUserConvert.java | 2 +- .../convert/order/TradeOrderConvert.java | 8 +- .../record/TradeBrokerageRecordMapper.java | 5 +- .../user/TradeBrokerageUserMapper.java | 10 +-- .../brokerage/bo/BrokerageAddReqBO.java | 36 +++++++++ .../bo/UserBrokerageSummaryBO.java | 2 +- .../record/TradeBrokerageRecordService.java | 21 ++--- .../TradeBrokerageRecordServiceImpl.java | 81 +++++++++---------- .../record/bo/BrokerageAddReqBO.java | 43 ---------- .../user/TradeBrokerageUserService.java | 9 +-- .../user/TradeBrokerageUserServiceImpl.java | 21 ++--- .../order/TradeOrderUpdateServiceImpl.java | 17 ++-- .../TradeBrokerageRecordServiceImplTest.java | 16 ++-- .../member/enums/ErrorCodeConstants.java | 1 - 22 files changed, 155 insertions(+), 170 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/{record => }/bo/UserBrokerageSummaryBO.java (84%) delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index 48adc14e8..53b9dc04e 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -3,8 +3,8 @@ create table trade_config ( id bigint auto_increment comment '自增主键' primary key, brokerage_enabled bit default 1 not null comment '是否启用分佣', - brokerage_enabled_condition tinyint default 0 not null comment '分佣模式:0-人人分销 1-指定分销', - brokerage_bind_mode tinyint default 0 not null comment '分销关系绑定模式: 0-没有推广人,1-新用户', + brokerage_enabled_condition tinyint default 0 not null comment '分佣模式:1-人人分销 2-指定分销', + brokerage_bind_mode tinyint default 0 not null comment '分销关系绑定模式: 1-没有推广人,2-新用户, 3-扫码覆盖', brokerage_post_urls varchar(2000) default '' null comment '分销海报图地址数组', brokerage_first_percent int default 0 not null comment '一级返佣比例', brokerage_second_percent int default 0 not null comment '二级返佣比例', @@ -104,14 +104,15 @@ create index idx_audit_status on trade_brokerage_withdraw (status) comment '状 insert into system_dict_type(type, name) values ('brokerage_enabled_condition', '分佣模式'); insert into system_dict_data(dict_type, label, value, sort, remark) -values ('brokerage_enabled_condition', '人人分销', 0, 0, '所有用户都可以分销'), - ('brokerage_enabled_condition', '指定分销', 1, 1, '仅可后台手动设置推广员'); +values ('brokerage_enabled_condition', '人人分销', 1, 1, '所有用户都可以分销'), + ('brokerage_enabled_condition', '指定分销', 2, 2, '仅可后台手动设置推广员'); insert into system_dict_type(type, name) values ('brokerage_bind_mode', '分销关系绑定模式'); insert into system_dict_data(dict_type, label, value, sort, remark) -values ('brokerage_bind_mode', '没有推广人', 0, 0, '只要用户没有推广人,随时都可以绑定推广关系'), - ('brokerage_bind_mode', '新用户', 1, 1, '仅新用户注册时才能绑定推广关系'); +values ('brokerage_bind_mode', '没有推广人', 1, 1, '只要用户没有推广人,随时都可以绑定推广关系'), + ('brokerage_bind_mode', '新用户', 2, 2, '仅新用户注册时才能绑定推广关系'), + ('brokerage_bind_mode', '扫码覆盖', 3, 3, '如果用户已经有推广人,推广人会被变更'); insert into system_dict_type(type, name) values ('brokerage_withdraw_type', '佣金提现类型'); @@ -124,8 +125,8 @@ values ('brokerage_withdraw_type', '钱包', 1, 1), insert into system_dict_type(type, name) values ('brokerage_record_biz_type', '佣金记录业务类型'); insert into system_dict_data(dict_type, label, value, sort) -values ('brokerage_record_biz_type', '订单返佣', 0, 0), - ('brokerage_record_biz_type', '申请提现', 1, 1); +values ('brokerage_record_biz_type', '订单返佣', 1, 1), + ('brokerage_record_biz_type', '申请提现', 2, 2); insert into system_dict_type(type, name) values ('brokerage_record_status', '佣金记录状态'); diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index f6c0ca782..5ddff9b11 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -77,5 +77,6 @@ public interface ErrorCodeConstants { // ========== 分销用户 模块 1011007000 ========== ErrorCode BROKERAGE_USER_NOT_EXISTS = new ErrorCode(1011007000, "分销用户不存在"); + ErrorCode USER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH = new ErrorCode(1011007001, "用户冻结佣金({})数量不足"); } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java index 19bb53daa..3b6610ac9 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java @@ -15,16 +15,18 @@ import java.util.Arrays; @Getter public enum BrokerageBindModeEnum implements IntArrayValuable { - // TODO @疯狂:要不从 1 开始? /** * 只要用户没有推广人,随时都可以绑定分销关系 */ - ANYTIME(0, "没有推广人"), + ANYTIME(1, "没有推广人"), /** * 仅新用户注册时才能绑定推广关系 */ - REGISTER(1, "新用户"), - // TODO @疯狂:要加个 2,每次扫码都覆盖 + REGISTER(2, "新用户"), + /** + * 每次扫码都覆盖 + */ + OVERRIDE(3, "扫码覆盖"), ; public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageBindModeEnum::getMode).toArray(); diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java index 1d1ef0c81..990d10e16 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java @@ -15,15 +15,14 @@ import java.util.Arrays; @Getter public enum BrokerageEnabledConditionEnum implements IntArrayValuable { - // TODO @疯狂:这个也从 1 开始哇 /** * 所有用户都可以分销 */ - ALL(0, "人人分销"), + ALL(1, "人人分销"), /** * 仅可后台手动设置推广员 */ - ADMIN(1, "指定分销"), + ADMIN(2, "指定分销"), ; public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageEnabledConditionEnum::getCondition).toArray(); 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 50c83c05a..ae798a6ac 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 @@ -15,9 +15,8 @@ import java.util.Arrays; @Getter public enum BrokerageRecordBizTypeEnum implements IntArrayValuable { - // TODO @疯狂:这个也从 1 开始哇 - ORDER(0, "获得推广佣金", "获得推广佣金 {}", true), - WITHDRAW(1, "提现申请", "提现申请扣除佣金 {}", false), + ORDER(1, "获得推广佣金", "获得推广佣金 {}", true), + WITHDRAW(2, "提现申请", "提现申请扣除佣金 {}", false), ; public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageRecordBizTypeEnum::getType).toArray(); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java index 5da3acb5b..38a27d8c8 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java @@ -10,7 +10,7 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerag import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java index 55b168582..ee20156f1 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java @@ -54,7 +54,6 @@ public class TradeConfigBaseVO { @PositiveOrZero(message = "用户提现最低金额不能是负数") private Integer brokerageWithdrawMinPrice; - // TODO @疯狂:要不要做成字典?按道理都可以体现对哇?感觉是全局的配置哈; @Schema(description = "提现银行", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]") @NotEmpty(message = "提现银行不能为空") private List brokerageBankNames; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java index 1e8290460..2d67f5f2e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.trade.convert.brokerage.record; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordRespVO; @@ -29,19 +30,22 @@ public interface TradeBrokerageRecordConvert { PageResult convertPage(PageResult page); - default TradeBrokerageRecordDO convert(TradeBrokerageUserDO user, String bizId, int brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime) { + default TradeBrokerageRecordDO convert(TradeBrokerageUserDO user, BrokerageRecordBizTypeEnum bizType, String bizId, + Integer brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime, + String title) { + brokerageFrozenDays = ObjectUtil.defaultIfNull(brokerageFrozenDays, 0); // 不冻结时,佣金直接就是结算状态 Integer status = brokerageFrozenDays > 0 ? BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus() : BrokerageRecordStatusEnum.SETTLEMENT.getStatus(); return new TradeBrokerageRecordDO() .setUserId(user.getId()) - .setBizType(BrokerageRecordBizTypeEnum.ORDER.getType()) + .setBizType(bizType.getType()) .setBizId(bizId) .setPrice(brokerage) .setTotalPrice(user.getBrokeragePrice()) - .setTitle(BrokerageRecordBizTypeEnum.ORDER.getTitle()) // TODO @疯狂:可能 title 不是很固化,会存在类似:沐晴成功购买《XXX JVM 实战》 - .setDescription(StrUtil.format(BrokerageRecordBizTypeEnum.ORDER.getDescription(), String.valueOf(brokerage / 100.0))) + .setTitle(title) + .setDescription(StrUtil.format(bizType.getDescription(), String.valueOf(brokerage / 100.0))) .setStatus(status) .setFrozenDays(brokerageFrozenDays) .setUnfreezeTime(unfreezeTime); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java index b5800efed..beda1571c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java @@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index f42af2d73..27854def6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.common.util.string.StrUtils; import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; import cn.iocoder.yudao.module.pay.enums.DictTypeConstants; @@ -277,8 +277,8 @@ public interface TradeOrderConvert { default BrokerageAddReqBO convert(TradeOrderItemDO item, ProductSkuRespDTO sku) { return new BrokerageAddReqBO().setBizId(String.valueOf(item.getId())) - .setPayPrice(item.getPayPrice()).setCount(item.getCount()) - .setSkuFirstBrokeragePrice(sku.getSubCommissionFirstPrice()) - .setSkuSecondBrokeragePrice(sku.getSubCommissionSecondPrice()); + .setBasePrice(item.getPayPrice() * item.getCount()) + .setFirstBrokeragePrice(sku.getSubCommissionFirstPrice()) + .setSecondBrokeragePrice(sku.getSubCommissionSecondPrice()); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java index 2adb488eb..9a8c6df76 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java @@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -43,8 +43,7 @@ public interface TradeBrokerageRecordMapper extends BaseMapperX 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" brokerage_price = brokerage_price + " + incrCount) @@ -46,7 +46,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" brokerage_price = brokerage_price + " + incrCount) // 负数,所以使用 + 号 @@ -60,7 +60,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) @@ -75,7 +75,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) // 负数,所以使用 + 号 @@ -90,7 +90,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount + // 负数,所以使用 + 号 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java new file mode 100644 index 000000000..7e17d9bda --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.module.trade.service.brokerage.bo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 佣金 增加 Request BO + * + * @author owen + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class BrokerageAddReqBO { + + // TODO @疯狂:bo 的话,也可以考虑加下 @Validated 注解,校验下参数;防御性下哈,虽然不一定用的到 + + /** + * 业务ID + */ + private String bizId; + /** + * 佣金基数 + */ + private Integer basePrice; + /** + * 一级佣金(固定) + */ + private Integer firstBrokeragePrice; + /** + * 二级佣金(固定) + */ + private Integer secondBrokeragePrice; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/UserBrokerageSummaryBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryBO.java similarity index 84% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/UserBrokerageSummaryBO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryBO.java index 15f3e73fe..ffbb3ed9a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/UserBrokerageSummaryBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryBO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.service.brokerage.record.bo; +package cn.iocoder.yudao.module.trade.service.brokerage.bo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java index 477e2c76e..d02745e3b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java @@ -3,8 +3,9 @@ package cn.iocoder.yudao.module.trade.service.brokerage.record; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import java.util.List; @@ -31,23 +32,23 @@ public interface TradeBrokerageRecordService { */ PageResult getBrokerageRecordPage(TradeBrokerageRecordPageReqVO pageReqVO); - // TODO @疯狂:是不是 bizType 得加下?方便未来拓展哈; /** * 增加佣金 * - * @param userId 会员编号 - * @param list 请求参数列表 + * @param userId 会员编号 + * @param bizType 业务类型 + * @param list 请求参数列表 */ - void addBrokerage(Long userId, List list); + void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, List list); - // TODO @疯狂:是不是 bizType 得加下?方便未来拓展哈; /** * 取消佣金:将佣金记录,状态修改为已失效 * - * @param userId 会员编号 - * @param bizId 业务编号 + * @param userId 会员编号 + * @param bizType 业务类型 + * @param bizId 业务编号 */ - void cancelBrokerage(Long userId, String bizId); + void cancelBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId); /** * 解冻佣金:将待结算的佣金记录,状态修改为已结算 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java index 72e85124a..01946a060 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java @@ -14,8 +14,8 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.TradeBrokerageRecordMapper; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import lombok.extern.slf4j.Slf4j; @@ -57,42 +57,40 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ return tradeBrokerageRecordMapper.selectPage(pageReqVO); } - // TODO @疯狂:buyerId 要不要统一改成 userId 哈; @Override @Transactional(rollbackFor = Exception.class) - public void addBrokerage(Long buyerId, List list) { + public void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, List list) { TradeConfigDO memberConfig = tradeConfigService.getTradeConfig(); // 0 未启用分销功能 - // TODO @疯狂:BooleanUtil.isFalse();逻辑里,尽量不做 !取反,这样要多思考一层; if (memberConfig == null || !BooleanUtil.isTrue(memberConfig.getBrokerageEnabled())) { - log.warn("[addBrokerage][增加佣金失败:brokerageEnabled 未配置,buyerId({})", buyerId); + log.warn("[addBrokerage][增加佣金失败:brokerageEnabled 未配置,userId({})", userId); return; } // 1.1 获得一级推广人 - TradeBrokerageUserDO firstUser = tradeBrokerageUserService.getInviteBrokerageUser(buyerId); + TradeBrokerageUserDO firstUser = tradeBrokerageUserService.getBindBrokerageUser(userId); if (firstUser == null || !BooleanUtil.isTrue(firstUser.getBrokerageEnabled())) { return; } - - // 1.2 计算一级分佣 // TODO 疯狂:类似 1.1 和 1.2 的空行,可以去掉;一般在代码里的空行,是为了逻辑分块;但是分块如果太多,就会导致代码里都是空行哈; - addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqBO::getSkuFirstBrokeragePrice); + // 1.2 计算一级分佣 + addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqBO::getFirstBrokeragePrice, bizType); // 2.1 获得二级推广员 - // TODO @疯狂:这里可以加个 firstUser.getBrokerageUserId() 为空的判断 return + if (firstUser.getBrokerageUserId() == null) { + return; + } TradeBrokerageUserDO secondUser = tradeBrokerageUserService.getBrokerageUser(firstUser.getBrokerageUserId()); if (secondUser == null || !BooleanUtil.isTrue(secondUser.getBrokerageEnabled())) { return; } - // 2.2 计算二级分佣 - addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqBO::getSkuSecondBrokeragePrice); + addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqBO::getSecondBrokeragePrice, bizType); } @Override @Transactional(rollbackFor = Exception.class) - public void cancelBrokerage(Long userId, String bizId) { - TradeBrokerageRecordDO record = tradeBrokerageRecordMapper.selectByUserIdAndBizTypeAndBizId(BrokerageRecordBizTypeEnum.ORDER.getType(), bizId); + public void cancelBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId) { + TradeBrokerageRecordDO record = tradeBrokerageRecordMapper.selectByBizTypeAndBizId(bizType.getType(), bizId); if (record == null || ObjectUtil.notEqual(record.getUserId(), userId)) { log.error("[cancelBrokerage][userId({})][bizId({}) 更新为已失效失败:记录不存在]", userId, bizId); return; @@ -114,24 +112,23 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ } } - // TODO @疯狂:是不是 calculateBrokeragePrice /** * 计算佣金 * - * @param payPrice 订单支付金额 - * @param percent 商品 SKU 设置的佣金 - * @param skuBrokeragePrice 商品的佣金 + * @param basePrice 佣金基数 + * @param percent 佣金比例 + * @param fixedBrokeragePrice 固定佣金 * @return 佣金 */ - int calculateBrokerage(Integer payPrice, Integer percent, Integer skuBrokeragePrice) { - // 1. 优先使用商品 SKU 设置的佣金 - if (skuBrokeragePrice != null && skuBrokeragePrice > 0) { - return ObjectUtil.defaultIfNull(skuBrokeragePrice, 0); + int calculateBrokeragePrice(Integer basePrice, Integer percent, Integer fixedBrokeragePrice) { + // 1. 优先使用固定佣金 + if (fixedBrokeragePrice != null && fixedBrokeragePrice > 0) { + return ObjectUtil.defaultIfNull(fixedBrokeragePrice, 0); } - // 2. 根据订单支付金额计算佣金 + // 2. 根据比例计算佣金 // TODO @疯狂:要不要把 MoneyUtils 抽到 common 里,然后这里也使用这个类的方法; - if (payPrice != null && payPrice > 0 && percent != null && percent > 0) { - return NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue(); + if (basePrice != null && basePrice > 0 && percent != null && percent > 0) { + return NumberUtil.div(NumberUtil.mul(basePrice, percent), 100, 0, RoundingMode.DOWN).intValue(); } return 0; } @@ -139,32 +136,32 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ /** * 增加用户佣金 * - * @param user 用户 - * @param list 佣金增加参数列表 - * @param brokerageFrozenDays 冻结天数 - * @param brokeragePercent 佣金比例 - * @param skuBrokeragePriceFun 商品 SKU 设置的佣金 + * @param user 用户 + * @param list 佣金增加参数列表 + * @param brokerageFrozenDays 冻结天数 + * @param brokeragePercent 佣金比例 + * @param FixedBrokeragePriceFun 固定佣金 + * @param bizType 业务类型 */ private void addBrokerage(TradeBrokerageUserDO user, List list, Integer brokerageFrozenDays, - Integer brokeragePercent, Function skuBrokeragePriceFun) { + Integer brokeragePercent, Function FixedBrokeragePriceFun, + BrokerageRecordBizTypeEnum bizType) { // 1.1 处理冻结时间 - // TODO @疯狂:是不是 brokerageFrozenDays != null && brokerageFrozenDays > 0 ?然后计算;更简洁一点; - brokerageFrozenDays = ObjectUtil.defaultIfNull(brokerageFrozenDays, 0); LocalDateTime unfreezeTime = null; - if (brokerageFrozenDays > 0) { + if (brokerageFrozenDays != null && brokerageFrozenDays > 0) { unfreezeTime = LocalDateTime.now().plusDays(brokerageFrozenDays); } // 1.2 计算分佣 int totalBrokerage = 0; List records = new ArrayList<>(); for (BrokerageAddReqBO item : list) { - int brokeragePerItem = calculateBrokerage(item.getPayPrice(), brokeragePercent, skuBrokeragePriceFun.apply(item)); - // TODO @疯狂:其实可以 brokeragePerItem <= 0 ,continue;这样 { 层级更少;代码更简洁;} - if (brokeragePerItem > 0) { - int brokerage = brokeragePerItem * item.getCount(); - records.add(TradeBrokerageRecordConvert.INSTANCE.convert(user, item.getBizId(), brokerageFrozenDays, brokerage, unfreezeTime)); - totalBrokerage += brokerage; + int brokeragePerItem = calculateBrokeragePrice(item.getBasePrice(), brokeragePercent, FixedBrokeragePriceFun.apply(item)); + if (brokeragePerItem <= 0) { + continue; } + records.add(TradeBrokerageRecordConvert.INSTANCE.convert(user, bizType, item.getBizId(), + brokerageFrozenDays, brokeragePerItem, unfreezeTime, bizType.getTitle())); + totalBrokerage += brokeragePerItem; } if (CollUtil.isEmpty(records)) { return; @@ -173,7 +170,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ tradeBrokerageRecordMapper.insertBatch(records); // 2. 更新用户佣金 - if (brokerageFrozenDays > 0) { // 更新用户冻结佣金 + if (brokerageFrozenDays != null && brokerageFrozenDays > 0) { // 更新用户冻结佣金 tradeBrokerageUserService.updateUserFrozenBrokeragePrice(user.getId(), totalBrokerage); } else { // 更新用户可用佣金 tradeBrokerageUserService.updateUserBrokeragePrice(user.getId(), totalBrokerage); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java deleted file mode 100644 index d325118a9..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java +++ /dev/null @@ -1,43 +0,0 @@ -package cn.iocoder.yudao.module.trade.service.brokerage.record.bo; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -// TODO @疯狂:要不要 service 还是拍平;就是都放在 brokerage 包下,然后 bo 里面,稍微分分; -/** - * 佣金 增加 Request BO - * - * @author owen - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class BrokerageAddReqBO { - - // TODO @疯狂:bo 的话,也可以考虑加下 @Validated 注解,校验下参数;防御性下哈,虽然不一定用的到 - - /** - * 业务ID - */ - private String bizId; - // TODO @疯狂:不需要 payPrice 和 count,计算成 price 就好啦; - /** - * 商品支付价格 - */ - private Integer payPrice; - // TODO @疯狂:可以去掉 sku 哈,更抽象一点; - /** - * SKU 一级佣金 - */ - private Integer skuFirstBrokeragePrice; - /** - * SKU 二级佣金 - */ - private Integer skuSecondBrokeragePrice; - /** - * 购买数量 - */ - private Integer count; - -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java index f817890e1..c62fc1947 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java @@ -61,7 +61,7 @@ public interface TradeBrokerageUserService { * @param id 用户编号 * @return 用户的推广人 */ - TradeBrokerageUserDO getInviteBrokerageUser(Long id); + TradeBrokerageUserDO getBindBrokerageUser(Long id); /** * 更新用户佣金 @@ -69,16 +69,15 @@ public interface TradeBrokerageUserService { * @param id 用户编号 * @param brokeragePrice 用户可用佣金 */ - void updateUserBrokeragePrice(Long id, int brokeragePrice); + void updateUserBrokeragePrice(Long id, Integer brokeragePrice); - // TODO @疯狂:int 类型一般不用哈;尽量都用封装类型;不差这点内存哈; /** * 更新用户冻结佣金 * * @param id 用户编号 * @param frozenBrokeragePrice 用户冻结佣金 */ - void updateUserFrozenBrokeragePrice(Long id, int frozenBrokeragePrice); + void updateUserFrozenBrokeragePrice(Long id, Integer frozenBrokeragePrice); /** * 更新用户冻结佣金(减少), 更新用户佣金(增加) @@ -86,7 +85,7 @@ public interface TradeBrokerageUserService { * @param id 用户编号 * @param frozenBrokeragePrice 减少冻结佣金(负数) */ - void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice); + void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, Integer frozenBrokeragePrice); /** * 获得推广用户数量(一级) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java index c6ec31b93..6851e522c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java @@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBro import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.TradeBrokerageUserMapper; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; @@ -15,8 +14,8 @@ import java.util.List; import java.util.Optional; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_USER_NOT_EXISTS; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.USER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH; /** * 分销用户 Service 实现类 @@ -65,9 +64,8 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService } } - // TODO @疯狂:getBindBrokerageUser 会不会好点,因为统一使用 Bind 替代了 Invite @Override - public TradeBrokerageUserDO getInviteBrokerageUser(Long id) { + public TradeBrokerageUserDO getBindBrokerageUser(Long id) { return Optional.ofNullable(id) .map(this::getBrokerageUser) .map(TradeBrokerageUserDO::getBrokerageUserId) @@ -75,10 +73,8 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService .orElse(null); } - // TODO @疯狂:单个更新,不用事务哈; @Override - @Transactional(rollbackFor = Exception.class) - public void updateUserBrokeragePrice(Long id, int brokeragePrice) { + public void updateUserBrokeragePrice(Long id, Integer brokeragePrice) { if (brokeragePrice > 0) { brokerageUserMapper.updateBrokeragePriceIncr(id, brokeragePrice); } else if (brokeragePrice < 0) { @@ -86,10 +82,8 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService } } - // TODO @疯狂:单个更新,不用事务哈; @Override - @Transactional(rollbackFor = Exception.class) - public void updateUserFrozenBrokeragePrice(Long id, int frozenBrokeragePrice) { + public void updateUserFrozenBrokeragePrice(Long id, Integer frozenBrokeragePrice) { if (frozenBrokeragePrice > 0) { brokerageUserMapper.updateFrozenBrokeragePriceIncr(id, frozenBrokeragePrice); } else if (frozenBrokeragePrice < 0) { @@ -97,15 +91,12 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService } } - // TODO @疯狂:单个更新,不用事务哈; @Override - @Transactional(rollbackFor = Exception.class) - public void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice) { + public void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, Integer frozenBrokeragePrice) { Assert.isTrue(frozenBrokeragePrice < 0); int updateRows = brokerageUserMapper.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(id, frozenBrokeragePrice); if (updateRows == 0) { - // TODO @疯狂:挪到 trade 这变的错误码哈; - throw exception(MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH); + throw exception(USER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index b75b7ac7c..199cfcbfd 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -12,8 +12,6 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; import cn.iocoder.yudao.module.member.api.point.MemberPointApi; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; @@ -49,9 +47,12 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper; import cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.*; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; +import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.trade.service.cart.CartService; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; import cn.iocoder.yudao.module.trade.service.message.TradeMessageService; @@ -370,7 +371,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 增加用户经验 getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); // 增加用户佣金 - getSelf().addBrokerageAsync(order.getUserId(), order.getId()); + getSelf().addBrokerageAsync(order.getUserId(), BrokerageRecordBizTypeEnum.ORDER, order.getId()); } /** @@ -640,7 +641,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 扣减用户经验 getSelf().reduceUserExperienceAsync(order.getUserId(), orderRefundPrice, afterSaleId); // 更新分佣记录为已失效 - getSelf().cancelBrokerageAsync(order.getUserId(), id); + getSelf().cancelBrokerageAsync(order.getUserId(), BrokerageRecordBizTypeEnum.ORDER, id); } @Override @@ -750,16 +751,16 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Async - protected void addBrokerageAsync(Long userId, Long orderId) { + protected void addBrokerageAsync(Long userId, BrokerageRecordBizTypeEnum bizType, Long orderId) { List orderItems = tradeOrderItemMapper.selectListByOrderId(orderId); List list = convertList(orderItems, item -> TradeOrderConvert.INSTANCE.convert(item, productSkuApi.getSku(item.getSkuId()))); - tradeBrokerageRecordService.addBrokerage(userId, list); + tradeBrokerageRecordService.addBrokerage(userId, bizType, list); } @Async - protected void cancelBrokerageAsync(Long userId, Long orderItemId) { - tradeBrokerageRecordService.cancelBrokerage(userId, String.valueOf(orderItemId)); + protected void cancelBrokerageAsync(Long userId, BrokerageRecordBizTypeEnum bizType, Long orderItemId) { + tradeBrokerageRecordService.cancelBrokerage(userId, bizType, String.valueOf(orderItemId)); } /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java index 9daf3cafb..eb51279d5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java @@ -79,38 +79,38 @@ public class TradeBrokerageRecordServiceImplTest extends BaseDbUnitTest { } @Test - public void testCalculateBrokerage_useSkuBrokeragePrice() { + public void testCalculateBrokeragePrice_useFixedBrokeragePrice() { // mock 数据 Integer payPrice = randomInteger(); Integer percent = randomInt(1, 101); - Integer skuBrokeragePrice = randomInt(); + Integer fixedBrokeragePrice = randomInt(); // 调用 - int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); + int brokerage = tradeBrokerageRecordService.calculateBrokeragePrice(payPrice, percent, fixedBrokeragePrice); // 断言 - assertEquals(brokerage, skuBrokeragePrice); + assertEquals(brokerage, fixedBrokeragePrice); } @Test - public void testCalculateBrokerage_usePercent() { + public void testCalculateBrokeragePrice_usePercent() { // mock 数据 Integer payPrice = randomInteger(); Integer percent = randomInt(1, 101); Integer skuBrokeragePrice = randomEle(new Integer[]{0, null}); System.out.println("skuBrokeragePrice=" + skuBrokeragePrice); // 调用 - int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); + int brokerage = tradeBrokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); // 断言 assertEquals(brokerage, NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue()); } @Test - public void testCalculateBrokerage_equalsZero() { + public void testCalculateBrokeragePrice_equalsZero() { // mock 数据 Integer payPrice = null; Integer percent = null; Integer skuBrokeragePrice = null; // 调用 - int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); + int brokerage = tradeBrokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); // 断言 assertEquals(brokerage, 0); } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java index dc7a58770..cf375f4e4 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java @@ -13,7 +13,6 @@ public interface ErrorCodeConstants { ErrorCode USER_NOT_EXISTS = new ErrorCode(1004001000, "用户不存在"); ErrorCode USER_MOBILE_NOT_EXISTS = new ErrorCode(1004001001, "手机号未注册用户"); ErrorCode USER_MOBILE_USED = new ErrorCode(1004001002, "修改手机失败,该手机号({})已经被使用"); - ErrorCode MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH = new ErrorCode(1004001003, "用户冻结佣金({})数量不足"); // ========== AUTH 模块 1004003000 ========== ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1004003000, "登录失败,账号密码不正确");