Commit 1cc2dfc963252e339b524b4a8078e217c86c4b9c
1 parent
166b1b31
trade: 分销Review代码修改
Showing
21 changed files
with
126 additions
and
141 deletions
sql/mysql/brokerage.sql
| @@ -3,8 +3,8 @@ create table trade_config | @@ -3,8 +3,8 @@ create table trade_config | ||
| 3 | ( | 3 | ( |
| 4 | id bigint auto_increment comment '憓蜓' primary key, | 4 | id bigint auto_increment comment '憓蜓' primary key, |
| 5 | brokerage_enabled bit default 1 not null comment '膛', | 5 | brokerage_enabled bit default 1 not null comment '膛', |
| 6 | - brokerage_enabled_condition tinyint default 0 not null comment '膛璅∪0-鈭箔犖 1-', | ||
| 7 | - brokerage_bind_mode tinyint default 0 not null comment '蝟餌芋撘: 0-瘝⊥撟蹂犖嚗1-', | 6 | + brokerage_enabled_condition tinyint default 0 not null comment '膛璅∪1-鈭箔犖 2-', |
| 7 | + brokerage_bind_mode tinyint default 0 not null comment '蝟餌芋撘: 1-瘝⊥撟蹂犖嚗2-, 3-', | ||
| 8 | brokerage_post_urls varchar(2000) default '' null comment '瘚瑟蝏', | 8 | brokerage_post_urls varchar(2000) default '' null comment '瘚瑟蝏', |
| 9 | brokerage_first_percent int default 0 not null comment '銝蝥扯膛瘥', | 9 | brokerage_first_percent int default 0 not null comment '銝蝥扯膛瘥', |
| 10 | brokerage_second_percent int default 0 not null comment '鈭漣餈膛瘥', | 10 | brokerage_second_percent int default 0 not null comment '鈭漣餈膛瘥', |
| @@ -104,14 +104,15 @@ create index idx_audit_status on trade_brokerage_withdraw (status) comment ' | @@ -104,14 +104,15 @@ create index idx_audit_status on trade_brokerage_withdraw (status) comment ' | ||
| 104 | insert into system_dict_type(type, name) | 104 | insert into system_dict_type(type, name) |
| 105 | values ('brokerage_enabled_condition', '膛璅∪'); | 105 | values ('brokerage_enabled_condition', '膛璅∪'); |
| 106 | insert into system_dict_data(dict_type, label, value, sort, remark) | 106 | insert into system_dict_data(dict_type, label, value, sort, remark) |
| 107 | -values ('brokerage_enabled_condition', '鈭箔犖', 0, 0, '隞亙'), | ||
| 108 | - ('brokerage_enabled_condition', '', 1, 1, '隞霈曄蔭撟踹'); | 107 | +values ('brokerage_enabled_condition', '鈭箔犖', 1, 1, '隞亙'), |
| 108 | + ('brokerage_enabled_condition', '', 2, 2, '隞霈曄蔭撟踹'); | ||
| 109 | 109 | ||
| 110 | insert into system_dict_type(type, name) | 110 | insert into system_dict_type(type, name) |
| 111 | values ('brokerage_bind_mode', '蝟餌芋撘'); | 111 | values ('brokerage_bind_mode', '蝟餌芋撘'); |
| 112 | insert into system_dict_data(dict_type, label, value, sort, remark) | 112 | insert into system_dict_data(dict_type, label, value, sort, remark) |
| 113 | -values ('brokerage_bind_mode', '瘝⊥撟蹂犖', 0, 0, '閬瘝⊥撟蹂犖嚗隞亦撟踹蝟'), | ||
| 114 | - ('brokerage_bind_mode', '', 1, 1, '隞瘜典蝏撟踹蝟'); | 113 | +values ('brokerage_bind_mode', '瘝⊥撟蹂犖', 1, 1, '閬瘝⊥撟蹂犖嚗隞亦撟踹蝟'), |
| 114 | + ('brokerage_bind_mode', '', 2, 2, '隞瘜典蝏撟踹蝟'), | ||
| 115 | + ('brokerage_bind_mode', '', 3, 3, '憒撌脩撟蹂犖嚗撟蹂犖隡◤'); | ||
| 115 | 116 | ||
| 116 | insert into system_dict_type(type, name) | 117 | insert into system_dict_type(type, name) |
| 117 | values ('brokerage_withdraw_type', '雿蝐餃'); | 118 | values ('brokerage_withdraw_type', '雿蝐餃'); |
| @@ -124,8 +125,8 @@ values ('brokerage_withdraw_type', '', 1, 1), | @@ -124,8 +125,8 @@ values ('brokerage_withdraw_type', '', 1, 1), | ||
| 124 | insert into system_dict_type(type, name) | 125 | insert into system_dict_type(type, name) |
| 125 | values ('brokerage_record_biz_type', '雿扇敶蝐餃'); | 126 | values ('brokerage_record_biz_type', '雿扇敶蝐餃'); |
| 126 | insert into system_dict_data(dict_type, label, value, sort) | 127 | insert into system_dict_data(dict_type, label, value, sort) |
| 127 | -values ('brokerage_record_biz_type', '霈W膛', 0, 0), | ||
| 128 | - ('brokerage_record_biz_type', '霂瑟', 1, 1); | 128 | +values ('brokerage_record_biz_type', '霈W膛', 1, 1), |
| 129 | + ('brokerage_record_biz_type', '霂瑟', 2, 2); | ||
| 129 | 130 | ||
| 130 | insert into system_dict_type(type, name) | 131 | insert into system_dict_type(type, name) |
| 131 | values ('brokerage_record_status', '雿扇敶'); | 132 | values ('brokerage_record_status', '雿扇敶'); |
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 { | @@ -77,5 +77,6 @@ public interface ErrorCodeConstants { | ||
| 77 | 77 | ||
| 78 | // ========== 分销用户 模块 1011007000 ========== | 78 | // ========== 分销用户 模块 1011007000 ========== |
| 79 | ErrorCode BROKERAGE_USER_NOT_EXISTS = new ErrorCode(1011007000, "分销用户不存在"); | 79 | ErrorCode BROKERAGE_USER_NOT_EXISTS = new ErrorCode(1011007000, "分销用户不存在"); |
| 80 | + ErrorCode USER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH = new ErrorCode(1011007001, "用户冻结佣金({})数量不足"); | ||
| 80 | 81 | ||
| 81 | } | 82 | } |
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; | @@ -15,16 +15,18 @@ import java.util.Arrays; | ||
| 15 | @Getter | 15 | @Getter |
| 16 | public enum BrokerageBindModeEnum implements IntArrayValuable { | 16 | public enum BrokerageBindModeEnum implements IntArrayValuable { |
| 17 | 17 | ||
| 18 | - // TODO @疯狂:要不从 1 开始? | ||
| 19 | /** | 18 | /** |
| 20 | * 只要用户没有推广人,随时都可以绑定分销关系 | 19 | * 只要用户没有推广人,随时都可以绑定分销关系 |
| 21 | */ | 20 | */ |
| 22 | - ANYTIME(0, "没有推广人"), | 21 | + ANYTIME(1, "没有推广人"), |
| 23 | /** | 22 | /** |
| 24 | * 仅新用户注册时才能绑定推广关系 | 23 | * 仅新用户注册时才能绑定推广关系 |
| 25 | */ | 24 | */ |
| 26 | - REGISTER(1, "新用户"), | ||
| 27 | - // TODO @疯狂:要加个 2,每次扫码都覆盖 | 25 | + REGISTER(2, "新用户"), |
| 26 | + /** | ||
| 27 | + * 每次扫码都覆盖 | ||
| 28 | + */ | ||
| 29 | + OVERRIDE(3, "扫码覆盖"), | ||
| 28 | ; | 30 | ; |
| 29 | 31 | ||
| 30 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageBindModeEnum::getMode).toArray(); | 32 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageBindModeEnum::getMode).toArray(); |
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; | @@ -15,15 +15,14 @@ import java.util.Arrays; | ||
| 15 | @Getter | 15 | @Getter |
| 16 | public enum BrokerageEnabledConditionEnum implements IntArrayValuable { | 16 | public enum BrokerageEnabledConditionEnum implements IntArrayValuable { |
| 17 | 17 | ||
| 18 | - // TODO @疯狂:这个也从 1 开始哇 | ||
| 19 | /** | 18 | /** |
| 20 | * 所有用户都可以分销 | 19 | * 所有用户都可以分销 |
| 21 | */ | 20 | */ |
| 22 | - ALL(0, "人人分销"), | 21 | + ALL(1, "人人分销"), |
| 23 | /** | 22 | /** |
| 24 | * 仅可后台手动设置推广员 | 23 | * 仅可后台手动设置推广员 |
| 25 | */ | 24 | */ |
| 26 | - ADMIN(1, "指定分销"), | 25 | + ADMIN(2, "指定分销"), |
| 27 | ; | 26 | ; |
| 28 | 27 | ||
| 29 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageEnabledConditionEnum::getCondition).toArray(); | 28 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageEnabledConditionEnum::getCondition).toArray(); |
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; | @@ -15,9 +15,8 @@ import java.util.Arrays; | ||
| 15 | @Getter | 15 | @Getter |
| 16 | public enum BrokerageRecordBizTypeEnum implements IntArrayValuable { | 16 | public enum BrokerageRecordBizTypeEnum implements IntArrayValuable { |
| 17 | 17 | ||
| 18 | - // TODO @疯狂:这个也从 1 开始哇 | ||
| 19 | - ORDER(0, "获得推广佣金", "获得推广佣金 {}", true), | ||
| 20 | - WITHDRAW(1, "提现申请", "提现申请扣除佣金 {}", false), | 18 | + ORDER(1, "获得推广佣金", "获得推广佣金 {}", true), |
| 19 | + WITHDRAW(2, "提现申请", "提现申请扣除佣金 {}", false), | ||
| 21 | ; | 20 | ; |
| 22 | 21 | ||
| 23 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageRecordBizTypeEnum::getType).toArray(); | 22 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageRecordBizTypeEnum::getType).toArray(); |
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 | @@ -10,7 +10,7 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerag | ||
| 10 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; | 10 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; |
| 11 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; | 11 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; |
| 12 | import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; | 12 | import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; |
| 13 | -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; | 13 | +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; |
| 14 | import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; | 14 | import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; |
| 15 | import io.swagger.v3.oas.annotations.Operation; | 15 | import io.swagger.v3.oas.annotations.Operation; |
| 16 | import io.swagger.v3.oas.annotations.Parameter; | 16 | import io.swagger.v3.oas.annotations.Parameter; |
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 { | @@ -54,7 +54,6 @@ public class TradeConfigBaseVO { | ||
| 54 | @PositiveOrZero(message = "用户提现最低金额不能是负数") | 54 | @PositiveOrZero(message = "用户提现最低金额不能是负数") |
| 55 | private Integer brokerageWithdrawMinPrice; | 55 | private Integer brokerageWithdrawMinPrice; |
| 56 | 56 | ||
| 57 | - // TODO @疯狂:要不要做成字典?按道理都可以体现对哇?感觉是全局的配置哈; | ||
| 58 | @Schema(description = "提现银行", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]") | 57 | @Schema(description = "提现银行", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]") |
| 59 | @NotEmpty(message = "提现银行不能为空") | 58 | @NotEmpty(message = "提现银行不能为空") |
| 60 | private List<Integer> brokerageBankNames; | 59 | private List<Integer> brokerageBankNames; |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java
| 1 | package cn.iocoder.yudao.module.trade.convert.brokerage.record; | 1 | package cn.iocoder.yudao.module.trade.convert.brokerage.record; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.util.ObjectUtil; | ||
| 3 | import cn.hutool.core.util.StrUtil; | 4 | import cn.hutool.core.util.StrUtil; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordRespVO; | 6 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordRespVO; |
| @@ -29,19 +30,22 @@ public interface TradeBrokerageRecordConvert { | @@ -29,19 +30,22 @@ public interface TradeBrokerageRecordConvert { | ||
| 29 | 30 | ||
| 30 | PageResult<TradeBrokerageRecordRespVO> convertPage(PageResult<TradeBrokerageRecordDO> page); | 31 | PageResult<TradeBrokerageRecordRespVO> convertPage(PageResult<TradeBrokerageRecordDO> page); |
| 31 | 32 | ||
| 32 | - default TradeBrokerageRecordDO convert(TradeBrokerageUserDO user, String bizId, int brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime) { | 33 | + default TradeBrokerageRecordDO convert(TradeBrokerageUserDO user, BrokerageRecordBizTypeEnum bizType, String bizId, |
| 34 | + Integer brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime, | ||
| 35 | + String title) { | ||
| 36 | + brokerageFrozenDays = ObjectUtil.defaultIfNull(brokerageFrozenDays, 0); | ||
| 33 | // 不冻结时,佣金直接就是结算状态 | 37 | // 不冻结时,佣金直接就是结算状态 |
| 34 | Integer status = brokerageFrozenDays > 0 | 38 | Integer status = brokerageFrozenDays > 0 |
| 35 | ? BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus() | 39 | ? BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus() |
| 36 | : BrokerageRecordStatusEnum.SETTLEMENT.getStatus(); | 40 | : BrokerageRecordStatusEnum.SETTLEMENT.getStatus(); |
| 37 | return new TradeBrokerageRecordDO() | 41 | return new TradeBrokerageRecordDO() |
| 38 | .setUserId(user.getId()) | 42 | .setUserId(user.getId()) |
| 39 | - .setBizType(BrokerageRecordBizTypeEnum.ORDER.getType()) | 43 | + .setBizType(bizType.getType()) |
| 40 | .setBizId(bizId) | 44 | .setBizId(bizId) |
| 41 | .setPrice(brokerage) | 45 | .setPrice(brokerage) |
| 42 | .setTotalPrice(user.getBrokeragePrice()) | 46 | .setTotalPrice(user.getBrokeragePrice()) |
| 43 | - .setTitle(BrokerageRecordBizTypeEnum.ORDER.getTitle()) // TODO @疯狂:可能 title 不是很固化,会存在类似:沐晴成功购买《XXX JVM 实战》 | ||
| 44 | - .setDescription(StrUtil.format(BrokerageRecordBizTypeEnum.ORDER.getDescription(), String.valueOf(brokerage / 100.0))) | 47 | + .setTitle(title) |
| 48 | + .setDescription(StrUtil.format(bizType.getDescription(), String.valueOf(brokerage / 100.0))) | ||
| 45 | .setStatus(status) | 49 | .setStatus(status) |
| 46 | .setFrozenDays(brokerageFrozenDays) | 50 | .setFrozenDays(brokerageFrozenDays) |
| 47 | .setUnfreezeTime(unfreezeTime); | 51 | .setUnfreezeTime(unfreezeTime); |
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; | @@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 5 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; | 5 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| 6 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserRespVO; | 6 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserRespVO; |
| 7 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; | 7 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; |
| 8 | -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; | 8 | +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; |
| 9 | import org.mapstruct.Mapper; | 9 | import org.mapstruct.Mapper; |
| 10 | import org.mapstruct.factory.Mappers; | 10 | import org.mapstruct.factory.Mappers; |
| 11 | 11 |
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; | @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.common.util.string.StrUtils; | ||
| 7 | import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; | 7 | import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; |
| 8 | import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; | 8 | import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; |
| 9 | import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; | 9 | import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; |
| 10 | -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; | 10 | +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; |
| 11 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; | 11 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| 12 | import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; | 12 | import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; |
| 13 | import cn.iocoder.yudao.module.pay.enums.DictTypeConstants; | 13 | import cn.iocoder.yudao.module.pay.enums.DictTypeConstants; |
| @@ -277,8 +277,8 @@ public interface TradeOrderConvert { | @@ -277,8 +277,8 @@ public interface TradeOrderConvert { | ||
| 277 | 277 | ||
| 278 | default BrokerageAddReqBO convert(TradeOrderItemDO item, ProductSkuRespDTO sku) { | 278 | default BrokerageAddReqBO convert(TradeOrderItemDO item, ProductSkuRespDTO sku) { |
| 279 | return new BrokerageAddReqBO().setBizId(String.valueOf(item.getId())) | 279 | return new BrokerageAddReqBO().setBizId(String.valueOf(item.getId())) |
| 280 | - .setPayPrice(item.getPayPrice()).setCount(item.getCount()) | ||
| 281 | - .setSkuFirstBrokeragePrice(sku.getSubCommissionFirstPrice()) | ||
| 282 | - .setSkuSecondBrokeragePrice(sku.getSubCommissionSecondPrice()); | 280 | + .setBasePrice(item.getPayPrice() * item.getCount()) |
| 281 | + .setFirstBrokeragePrice(sku.getSubCommissionFirstPrice()) | ||
| 282 | + .setSecondBrokeragePrice(sku.getSubCommissionSecondPrice()); | ||
| 283 | } | 283 | } |
| 284 | } | 284 | } |
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; | @@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; | 6 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; |
| 7 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; | 7 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; |
| 8 | -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; | 8 | +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; |
| 9 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 9 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| 10 | import org.apache.ibatis.annotations.Mapper; | 10 | import org.apache.ibatis.annotations.Mapper; |
| 11 | import org.apache.ibatis.annotations.Param; | 11 | import org.apache.ibatis.annotations.Param; |
| @@ -43,8 +43,7 @@ public interface TradeBrokerageRecordMapper extends BaseMapperX<TradeBrokerageRe | @@ -43,8 +43,7 @@ public interface TradeBrokerageRecordMapper extends BaseMapperX<TradeBrokerageRe | ||
| 43 | .eq(TradeBrokerageRecordDO::getStatus, status)); | 43 | .eq(TradeBrokerageRecordDO::getStatus, status)); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | - // TODO @疯狂:userId??? | ||
| 47 | - default TradeBrokerageRecordDO selectByUserIdAndBizTypeAndBizId(Integer bizType, String bizId) { | 46 | + default TradeBrokerageRecordDO selectByBizTypeAndBizId(Integer bizType, String bizId) { |
| 48 | return selectOne(TradeBrokerageRecordDO::getBizType, bizType, | 47 | return selectOne(TradeBrokerageRecordDO::getBizType, bizType, |
| 49 | TradeBrokerageRecordDO::getBizId, bizId); | 48 | TradeBrokerageRecordDO::getBizId, bizId); |
| 50 | } | 49 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/TradeBrokerageUserMapper.java
| @@ -31,7 +31,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX<TradeBrokerageUser | @@ -31,7 +31,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX<TradeBrokerageUser | ||
| 31 | * @param id 用户编号 | 31 | * @param id 用户编号 |
| 32 | * @param incrCount 增加佣金(正数) | 32 | * @param incrCount 增加佣金(正数) |
| 33 | */ | 33 | */ |
| 34 | - default void updateBrokeragePriceIncr(Long id, int incrCount) { | 34 | + default void updateBrokeragePriceIncr(Long id, Integer incrCount) { |
| 35 | Assert.isTrue(incrCount > 0); | 35 | Assert.isTrue(incrCount > 0); |
| 36 | LambdaUpdateWrapper<TradeBrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<TradeBrokerageUserDO>() | 36 | LambdaUpdateWrapper<TradeBrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<TradeBrokerageUserDO>() |
| 37 | .setSql(" brokerage_price = brokerage_price + " + incrCount) | 37 | .setSql(" brokerage_price = brokerage_price + " + incrCount) |
| @@ -46,7 +46,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX<TradeBrokerageUser | @@ -46,7 +46,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX<TradeBrokerageUser | ||
| 46 | * @param id 用户编号 | 46 | * @param id 用户编号 |
| 47 | * @param incrCount 增加佣金(负数) | 47 | * @param incrCount 增加佣金(负数) |
| 48 | */ | 48 | */ |
| 49 | - default void updateBrokeragePriceDecr(Long id, int incrCount) { | 49 | + default void updateBrokeragePriceDecr(Long id, Integer incrCount) { |
| 50 | Assert.isTrue(incrCount < 0); | 50 | Assert.isTrue(incrCount < 0); |
| 51 | LambdaUpdateWrapper<TradeBrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<TradeBrokerageUserDO>() | 51 | LambdaUpdateWrapper<TradeBrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<TradeBrokerageUserDO>() |
| 52 | .setSql(" brokerage_price = brokerage_price + " + incrCount) // 负数,所以使用 + 号 | 52 | .setSql(" brokerage_price = brokerage_price + " + incrCount) // 负数,所以使用 + 号 |
| @@ -60,7 +60,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX<TradeBrokerageUser | @@ -60,7 +60,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX<TradeBrokerageUser | ||
| 60 | * @param id 用户编号 | 60 | * @param id 用户编号 |
| 61 | * @param incrCount 增加冻结佣金(正数) | 61 | * @param incrCount 增加冻结佣金(正数) |
| 62 | */ | 62 | */ |
| 63 | - default void updateFrozenBrokeragePriceIncr(Long id, int incrCount) { | 63 | + default void updateFrozenBrokeragePriceIncr(Long id, Integer incrCount) { |
| 64 | Assert.isTrue(incrCount > 0); | 64 | Assert.isTrue(incrCount > 0); |
| 65 | LambdaUpdateWrapper<TradeBrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<TradeBrokerageUserDO>() | 65 | LambdaUpdateWrapper<TradeBrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<TradeBrokerageUserDO>() |
| 66 | .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) | 66 | .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) |
| @@ -75,7 +75,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX<TradeBrokerageUser | @@ -75,7 +75,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX<TradeBrokerageUser | ||
| 75 | * @param id 用户编号 | 75 | * @param id 用户编号 |
| 76 | * @param incrCount 减少冻结佣金(负数) | 76 | * @param incrCount 减少冻结佣金(负数) |
| 77 | */ | 77 | */ |
| 78 | - default void updateFrozenBrokeragePriceDecr(Long id, int incrCount) { | 78 | + default void updateFrozenBrokeragePriceDecr(Long id, Integer incrCount) { |
| 79 | Assert.isTrue(incrCount < 0); | 79 | Assert.isTrue(incrCount < 0); |
| 80 | LambdaUpdateWrapper<TradeBrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<TradeBrokerageUserDO>() | 80 | LambdaUpdateWrapper<TradeBrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<TradeBrokerageUserDO>() |
| 81 | .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) // 负数,所以使用 + 号 | 81 | .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) // 负数,所以使用 + 号 |
| @@ -90,7 +90,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX<TradeBrokerageUser | @@ -90,7 +90,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX<TradeBrokerageUser | ||
| 90 | * @param incrCount 减少冻结佣金(负数) | 90 | * @param incrCount 减少冻结佣金(负数) |
| 91 | * @return 更新条数 | 91 | * @return 更新条数 |
| 92 | */ | 92 | */ |
| 93 | - default int updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int incrCount) { | 93 | + default int updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, Integer incrCount) { |
| 94 | Assert.isTrue(incrCount < 0); | 94 | Assert.isTrue(incrCount < 0); |
| 95 | LambdaUpdateWrapper<TradeBrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<TradeBrokerageUserDO>() | 95 | LambdaUpdateWrapper<TradeBrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<TradeBrokerageUserDO>() |
| 96 | .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount + // 负数,所以使用 + 号 | 96 | .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount + // 负数,所以使用 + 号 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java
| 1 | -package cn.iocoder.yudao.module.trade.service.brokerage.record.bo; | 1 | +package cn.iocoder.yudao.module.trade.service.brokerage.bo; |
| 2 | 2 | ||
| 3 | import lombok.AllArgsConstructor; | 3 | import lombok.AllArgsConstructor; |
| 4 | import lombok.Data; | 4 | import lombok.Data; |
| 5 | import lombok.NoArgsConstructor; | 5 | import lombok.NoArgsConstructor; |
| 6 | 6 | ||
| 7 | -// TODO @疯狂:要不要 service 还是拍平;就是都放在 brokerage 包下,然后 bo 里面,稍微分分; | ||
| 8 | /** | 7 | /** |
| 9 | * 佣金 增加 Request BO | 8 | * 佣金 增加 Request BO |
| 10 | * | 9 | * |
| @@ -21,23 +20,17 @@ public class BrokerageAddReqBO { | @@ -21,23 +20,17 @@ public class BrokerageAddReqBO { | ||
| 21 | * 业务ID | 20 | * 业务ID |
| 22 | */ | 21 | */ |
| 23 | private String bizId; | 22 | private String bizId; |
| 24 | - // TODO @疯狂:不需要 payPrice 和 count,计算成 price 就好啦; | ||
| 25 | /** | 23 | /** |
| 26 | - * 商品支付价格 | 24 | + * 佣金基数 |
| 27 | */ | 25 | */ |
| 28 | - private Integer payPrice; | ||
| 29 | - // TODO @疯狂:可以去掉 sku 哈,更抽象一点; | 26 | + private Integer basePrice; |
| 30 | /** | 27 | /** |
| 31 | - * SKU 一级佣金 | 28 | + * 一级佣金(固定) |
| 32 | */ | 29 | */ |
| 33 | - private Integer skuFirstBrokeragePrice; | 30 | + private Integer firstBrokeragePrice; |
| 34 | /** | 31 | /** |
| 35 | - * SKU 二级佣金 | 32 | + * 二级佣金(固定) |
| 36 | */ | 33 | */ |
| 37 | - private Integer skuSecondBrokeragePrice; | ||
| 38 | - /** | ||
| 39 | - * 购买数量 | ||
| 40 | - */ | ||
| 41 | - private Integer count; | 34 | + private Integer secondBrokeragePrice; |
| 42 | 35 | ||
| 43 | } | 36 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/UserBrokerageSummaryBO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryBO.java
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; | @@ -3,8 +3,9 @@ package cn.iocoder.yudao.module.trade.service.brokerage.record; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; | 4 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; |
| 5 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; | 5 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; |
| 6 | -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; | ||
| 7 | -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; | 6 | +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; |
| 7 | +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; | ||
| 8 | +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; | ||
| 8 | 9 | ||
| 9 | import java.util.List; | 10 | import java.util.List; |
| 10 | 11 | ||
| @@ -31,23 +32,23 @@ public interface TradeBrokerageRecordService { | @@ -31,23 +32,23 @@ public interface TradeBrokerageRecordService { | ||
| 31 | */ | 32 | */ |
| 32 | PageResult<TradeBrokerageRecordDO> getBrokerageRecordPage(TradeBrokerageRecordPageReqVO pageReqVO); | 33 | PageResult<TradeBrokerageRecordDO> getBrokerageRecordPage(TradeBrokerageRecordPageReqVO pageReqVO); |
| 33 | 34 | ||
| 34 | - // TODO @疯狂:是不是 bizType 得加下?方便未来拓展哈; | ||
| 35 | /** | 35 | /** |
| 36 | * 增加佣金 | 36 | * 增加佣金 |
| 37 | * | 37 | * |
| 38 | - * @param userId 会员编号 | ||
| 39 | - * @param list 请求参数列表 | 38 | + * @param userId 会员编号 |
| 39 | + * @param bizType 业务类型 | ||
| 40 | + * @param list 请求参数列表 | ||
| 40 | */ | 41 | */ |
| 41 | - void addBrokerage(Long userId, List<BrokerageAddReqBO> list); | 42 | + void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, List<BrokerageAddReqBO> list); |
| 42 | 43 | ||
| 43 | - // TODO @疯狂:是不是 bizType 得加下?方便未来拓展哈; | ||
| 44 | /** | 44 | /** |
| 45 | * 取消佣金:将佣金记录,状态修改为已失效 | 45 | * 取消佣金:将佣金记录,状态修改为已失效 |
| 46 | * | 46 | * |
| 47 | - * @param userId 会员编号 | ||
| 48 | - * @param bizId 业务编号 | 47 | + * @param userId 会员编号 |
| 48 | + * @param bizType 业务类型 | ||
| 49 | + * @param bizId 业务编号 | ||
| 49 | */ | 50 | */ |
| 50 | - void cancelBrokerage(Long userId, String bizId); | 51 | + void cancelBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId); |
| 51 | 52 | ||
| 52 | /** | 53 | /** |
| 53 | * 解冻佣金:将待结算的佣金记录,状态修改为已结算 | 54 | * 解冻佣金:将待结算的佣金记录,状态修改为已结算 |
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; | @@ -14,8 +14,8 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; | ||
| 14 | import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.TradeBrokerageRecordMapper; | 14 | import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.TradeBrokerageRecordMapper; |
| 15 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; | 15 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; |
| 16 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; | 16 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; |
| 17 | -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; | ||
| 18 | -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; | 17 | +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; |
| 18 | +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; | ||
| 19 | import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; | 19 | import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; |
| 20 | import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; | 20 | import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; |
| 21 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
| @@ -57,42 +57,40 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ | @@ -57,42 +57,40 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ | ||
| 57 | return tradeBrokerageRecordMapper.selectPage(pageReqVO); | 57 | return tradeBrokerageRecordMapper.selectPage(pageReqVO); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | - // TODO @疯狂:buyerId 要不要统一改成 userId 哈; | ||
| 61 | @Override | 60 | @Override |
| 62 | @Transactional(rollbackFor = Exception.class) | 61 | @Transactional(rollbackFor = Exception.class) |
| 63 | - public void addBrokerage(Long buyerId, List<BrokerageAddReqBO> list) { | 62 | + public void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, List<BrokerageAddReqBO> list) { |
| 64 | TradeConfigDO memberConfig = tradeConfigService.getTradeConfig(); | 63 | TradeConfigDO memberConfig = tradeConfigService.getTradeConfig(); |
| 65 | // 0 未启用分销功能 | 64 | // 0 未启用分销功能 |
| 66 | - // TODO @疯狂:BooleanUtil.isFalse();逻辑里,尽量不做 !取反,这样要多思考一层; | ||
| 67 | if (memberConfig == null || !BooleanUtil.isTrue(memberConfig.getBrokerageEnabled())) { | 65 | if (memberConfig == null || !BooleanUtil.isTrue(memberConfig.getBrokerageEnabled())) { |
| 68 | - log.warn("[addBrokerage][增加佣金失败:brokerageEnabled 未配置,buyerId({})", buyerId); | 66 | + log.warn("[addBrokerage][增加佣金失败:brokerageEnabled 未配置,userId({})", userId); |
| 69 | return; | 67 | return; |
| 70 | } | 68 | } |
| 71 | 69 | ||
| 72 | // 1.1 获得一级推广人 | 70 | // 1.1 获得一级推广人 |
| 73 | - TradeBrokerageUserDO firstUser = tradeBrokerageUserService.getInviteBrokerageUser(buyerId); | 71 | + TradeBrokerageUserDO firstUser = tradeBrokerageUserService.getBindBrokerageUser(userId); |
| 74 | if (firstUser == null || !BooleanUtil.isTrue(firstUser.getBrokerageEnabled())) { | 72 | if (firstUser == null || !BooleanUtil.isTrue(firstUser.getBrokerageEnabled())) { |
| 75 | return; | 73 | return; |
| 76 | } | 74 | } |
| 77 | - | ||
| 78 | - // 1.2 计算一级分佣 // TODO 疯狂:类似 1.1 和 1.2 的空行,可以去掉;一般在代码里的空行,是为了逻辑分块;但是分块如果太多,就会导致代码里都是空行哈; | ||
| 79 | - addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqBO::getSkuFirstBrokeragePrice); | 75 | + // 1.2 计算一级分佣 |
| 76 | + addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqBO::getFirstBrokeragePrice, bizType); | ||
| 80 | 77 | ||
| 81 | // 2.1 获得二级推广员 | 78 | // 2.1 获得二级推广员 |
| 82 | - // TODO @疯狂:这里可以加个 firstUser.getBrokerageUserId() 为空的判断 return | 79 | + if (firstUser.getBrokerageUserId() == null) { |
| 80 | + return; | ||
| 81 | + } | ||
| 83 | TradeBrokerageUserDO secondUser = tradeBrokerageUserService.getBrokerageUser(firstUser.getBrokerageUserId()); | 82 | TradeBrokerageUserDO secondUser = tradeBrokerageUserService.getBrokerageUser(firstUser.getBrokerageUserId()); |
| 84 | if (secondUser == null || !BooleanUtil.isTrue(secondUser.getBrokerageEnabled())) { | 83 | if (secondUser == null || !BooleanUtil.isTrue(secondUser.getBrokerageEnabled())) { |
| 85 | return; | 84 | return; |
| 86 | } | 85 | } |
| 87 | - | ||
| 88 | // 2.2 计算二级分佣 | 86 | // 2.2 计算二级分佣 |
| 89 | - addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqBO::getSkuSecondBrokeragePrice); | 87 | + addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqBO::getSecondBrokeragePrice, bizType); |
| 90 | } | 88 | } |
| 91 | 89 | ||
| 92 | @Override | 90 | @Override |
| 93 | @Transactional(rollbackFor = Exception.class) | 91 | @Transactional(rollbackFor = Exception.class) |
| 94 | - public void cancelBrokerage(Long userId, String bizId) { | ||
| 95 | - TradeBrokerageRecordDO record = tradeBrokerageRecordMapper.selectByUserIdAndBizTypeAndBizId(BrokerageRecordBizTypeEnum.ORDER.getType(), bizId); | 92 | + public void cancelBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId) { |
| 93 | + TradeBrokerageRecordDO record = tradeBrokerageRecordMapper.selectByBizTypeAndBizId(bizType.getType(), bizId); | ||
| 96 | if (record == null || ObjectUtil.notEqual(record.getUserId(), userId)) { | 94 | if (record == null || ObjectUtil.notEqual(record.getUserId(), userId)) { |
| 97 | log.error("[cancelBrokerage][userId({})][bizId({}) 更新为已失效失败:记录不存在]", userId, bizId); | 95 | log.error("[cancelBrokerage][userId({})][bizId({}) 更新为已失效失败:记录不存在]", userId, bizId); |
| 98 | return; | 96 | return; |
| @@ -114,24 +112,23 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ | @@ -114,24 +112,23 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ | ||
| 114 | } | 112 | } |
| 115 | } | 113 | } |
| 116 | 114 | ||
| 117 | - // TODO @疯狂:是不是 calculateBrokeragePrice | ||
| 118 | /** | 115 | /** |
| 119 | * 计算佣金 | 116 | * 计算佣金 |
| 120 | * | 117 | * |
| 121 | - * @param payPrice 订单支付金额 | ||
| 122 | - * @param percent 商品 SKU 设置的佣金 | ||
| 123 | - * @param skuBrokeragePrice 商品的佣金 | 118 | + * @param basePrice 佣金基数 |
| 119 | + * @param percent 佣金比例 | ||
| 120 | + * @param fixedBrokeragePrice 固定佣金 | ||
| 124 | * @return 佣金 | 121 | * @return 佣金 |
| 125 | */ | 122 | */ |
| 126 | - int calculateBrokerage(Integer payPrice, Integer percent, Integer skuBrokeragePrice) { | ||
| 127 | - // 1. 优先使用商品 SKU 设置的佣金 | ||
| 128 | - if (skuBrokeragePrice != null && skuBrokeragePrice > 0) { | ||
| 129 | - return ObjectUtil.defaultIfNull(skuBrokeragePrice, 0); | 123 | + int calculateBrokeragePrice(Integer basePrice, Integer percent, Integer fixedBrokeragePrice) { |
| 124 | + // 1. 优先使用固定佣金 | ||
| 125 | + if (fixedBrokeragePrice != null && fixedBrokeragePrice > 0) { | ||
| 126 | + return ObjectUtil.defaultIfNull(fixedBrokeragePrice, 0); | ||
| 130 | } | 127 | } |
| 131 | - // 2. 根据订单支付金额计算佣金 | 128 | + // 2. 根据比例计算佣金 |
| 132 | // TODO @疯狂:要不要把 MoneyUtils 抽到 common 里,然后这里也使用这个类的方法; | 129 | // TODO @疯狂:要不要把 MoneyUtils 抽到 common 里,然后这里也使用这个类的方法; |
| 133 | - if (payPrice != null && payPrice > 0 && percent != null && percent > 0) { | ||
| 134 | - return NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue(); | 130 | + if (basePrice != null && basePrice > 0 && percent != null && percent > 0) { |
| 131 | + return NumberUtil.div(NumberUtil.mul(basePrice, percent), 100, 0, RoundingMode.DOWN).intValue(); | ||
| 135 | } | 132 | } |
| 136 | return 0; | 133 | return 0; |
| 137 | } | 134 | } |
| @@ -139,32 +136,32 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ | @@ -139,32 +136,32 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ | ||
| 139 | /** | 136 | /** |
| 140 | * 增加用户佣金 | 137 | * 增加用户佣金 |
| 141 | * | 138 | * |
| 142 | - * @param user 用户 | ||
| 143 | - * @param list 佣金增加参数列表 | ||
| 144 | - * @param brokerageFrozenDays 冻结天数 | ||
| 145 | - * @param brokeragePercent 佣金比例 | ||
| 146 | - * @param skuBrokeragePriceFun 商品 SKU 设置的佣金 | 139 | + * @param user 用户 |
| 140 | + * @param list 佣金增加参数列表 | ||
| 141 | + * @param brokerageFrozenDays 冻结天数 | ||
| 142 | + * @param brokeragePercent 佣金比例 | ||
| 143 | + * @param FixedBrokeragePriceFun 固定佣金 | ||
| 144 | + * @param bizType 业务类型 | ||
| 147 | */ | 145 | */ |
| 148 | private void addBrokerage(TradeBrokerageUserDO user, List<BrokerageAddReqBO> list, Integer brokerageFrozenDays, | 146 | private void addBrokerage(TradeBrokerageUserDO user, List<BrokerageAddReqBO> list, Integer brokerageFrozenDays, |
| 149 | - Integer brokeragePercent, Function<BrokerageAddReqBO, Integer> skuBrokeragePriceFun) { | 147 | + Integer brokeragePercent, Function<BrokerageAddReqBO, Integer> FixedBrokeragePriceFun, |
| 148 | + BrokerageRecordBizTypeEnum bizType) { | ||
| 150 | // 1.1 处理冻结时间 | 149 | // 1.1 处理冻结时间 |
| 151 | - // TODO @疯狂:是不是 brokerageFrozenDays != null && brokerageFrozenDays > 0 ?然后计算;更简洁一点; | ||
| 152 | - brokerageFrozenDays = ObjectUtil.defaultIfNull(brokerageFrozenDays, 0); | ||
| 153 | LocalDateTime unfreezeTime = null; | 150 | LocalDateTime unfreezeTime = null; |
| 154 | - if (brokerageFrozenDays > 0) { | 151 | + if (brokerageFrozenDays != null && brokerageFrozenDays > 0) { |
| 155 | unfreezeTime = LocalDateTime.now().plusDays(brokerageFrozenDays); | 152 | unfreezeTime = LocalDateTime.now().plusDays(brokerageFrozenDays); |
| 156 | } | 153 | } |
| 157 | // 1.2 计算分佣 | 154 | // 1.2 计算分佣 |
| 158 | int totalBrokerage = 0; | 155 | int totalBrokerage = 0; |
| 159 | List<TradeBrokerageRecordDO> records = new ArrayList<>(); | 156 | List<TradeBrokerageRecordDO> records = new ArrayList<>(); |
| 160 | for (BrokerageAddReqBO item : list) { | 157 | for (BrokerageAddReqBO item : list) { |
| 161 | - int brokeragePerItem = calculateBrokerage(item.getPayPrice(), brokeragePercent, skuBrokeragePriceFun.apply(item)); | ||
| 162 | - // TODO @疯狂:其实可以 brokeragePerItem <= 0 ,continue;这样 { 层级更少;代码更简洁;} | ||
| 163 | - if (brokeragePerItem > 0) { | ||
| 164 | - int brokerage = brokeragePerItem * item.getCount(); | ||
| 165 | - records.add(TradeBrokerageRecordConvert.INSTANCE.convert(user, item.getBizId(), brokerageFrozenDays, brokerage, unfreezeTime)); | ||
| 166 | - totalBrokerage += brokerage; | 158 | + int brokeragePerItem = calculateBrokeragePrice(item.getBasePrice(), brokeragePercent, FixedBrokeragePriceFun.apply(item)); |
| 159 | + if (brokeragePerItem <= 0) { | ||
| 160 | + continue; | ||
| 167 | } | 161 | } |
| 162 | + records.add(TradeBrokerageRecordConvert.INSTANCE.convert(user, bizType, item.getBizId(), | ||
| 163 | + brokerageFrozenDays, brokeragePerItem, unfreezeTime, bizType.getTitle())); | ||
| 164 | + totalBrokerage += brokeragePerItem; | ||
| 168 | } | 165 | } |
| 169 | if (CollUtil.isEmpty(records)) { | 166 | if (CollUtil.isEmpty(records)) { |
| 170 | return; | 167 | return; |
| @@ -173,7 +170,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ | @@ -173,7 +170,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ | ||
| 173 | tradeBrokerageRecordMapper.insertBatch(records); | 170 | tradeBrokerageRecordMapper.insertBatch(records); |
| 174 | 171 | ||
| 175 | // 2. 更新用户佣金 | 172 | // 2. 更新用户佣金 |
| 176 | - if (brokerageFrozenDays > 0) { // 更新用户冻结佣金 | 173 | + if (brokerageFrozenDays != null && brokerageFrozenDays > 0) { // 更新用户冻结佣金 |
| 177 | tradeBrokerageUserService.updateUserFrozenBrokeragePrice(user.getId(), totalBrokerage); | 174 | tradeBrokerageUserService.updateUserFrozenBrokeragePrice(user.getId(), totalBrokerage); |
| 178 | } else { // 更新用户可用佣金 | 175 | } else { // 更新用户可用佣金 |
| 179 | tradeBrokerageUserService.updateUserBrokeragePrice(user.getId(), totalBrokerage); | 176 | tradeBrokerageUserService.updateUserBrokeragePrice(user.getId(), totalBrokerage); |
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 { | @@ -61,7 +61,7 @@ public interface TradeBrokerageUserService { | ||
| 61 | * @param id 用户编号 | 61 | * @param id 用户编号 |
| 62 | * @return 用户的推广人 | 62 | * @return 用户的推广人 |
| 63 | */ | 63 | */ |
| 64 | - TradeBrokerageUserDO getInviteBrokerageUser(Long id); | 64 | + TradeBrokerageUserDO getBindBrokerageUser(Long id); |
| 65 | 65 | ||
| 66 | /** | 66 | /** |
| 67 | * 更新用户佣金 | 67 | * 更新用户佣金 |
| @@ -69,16 +69,15 @@ public interface TradeBrokerageUserService { | @@ -69,16 +69,15 @@ public interface TradeBrokerageUserService { | ||
| 69 | * @param id 用户编号 | 69 | * @param id 用户编号 |
| 70 | * @param brokeragePrice 用户可用佣金 | 70 | * @param brokeragePrice 用户可用佣金 |
| 71 | */ | 71 | */ |
| 72 | - void updateUserBrokeragePrice(Long id, int brokeragePrice); | 72 | + void updateUserBrokeragePrice(Long id, Integer brokeragePrice); |
| 73 | 73 | ||
| 74 | - // TODO @疯狂:int 类型一般不用哈;尽量都用封装类型;不差这点内存哈; | ||
| 75 | /** | 74 | /** |
| 76 | * 更新用户冻结佣金 | 75 | * 更新用户冻结佣金 |
| 77 | * | 76 | * |
| 78 | * @param id 用户编号 | 77 | * @param id 用户编号 |
| 79 | * @param frozenBrokeragePrice 用户冻结佣金 | 78 | * @param frozenBrokeragePrice 用户冻结佣金 |
| 80 | */ | 79 | */ |
| 81 | - void updateUserFrozenBrokeragePrice(Long id, int frozenBrokeragePrice); | 80 | + void updateUserFrozenBrokeragePrice(Long id, Integer frozenBrokeragePrice); |
| 82 | 81 | ||
| 83 | /** | 82 | /** |
| 84 | * 更新用户冻结佣金(减少), 更新用户佣金(增加) | 83 | * 更新用户冻结佣金(减少), 更新用户佣金(增加) |
| @@ -86,7 +85,7 @@ public interface TradeBrokerageUserService { | @@ -86,7 +85,7 @@ public interface TradeBrokerageUserService { | ||
| 86 | * @param id 用户编号 | 85 | * @param id 用户编号 |
| 87 | * @param frozenBrokeragePrice 减少冻结佣金(负数) | 86 | * @param frozenBrokeragePrice 减少冻结佣金(负数) |
| 88 | */ | 87 | */ |
| 89 | - void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice); | 88 | + void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, Integer frozenBrokeragePrice); |
| 90 | 89 | ||
| 91 | /** | 90 | /** |
| 92 | * 获得推广用户数量(一级) | 91 | * 获得推广用户数量(一级) |
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 | @@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBro | ||
| 6 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; | 6 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; |
| 7 | import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.TradeBrokerageUserMapper; | 7 | import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.TradeBrokerageUserMapper; |
| 8 | import org.springframework.stereotype.Service; | 8 | import org.springframework.stereotype.Service; |
| 9 | -import org.springframework.transaction.annotation.Transactional; | ||
| 10 | import org.springframework.validation.annotation.Validated; | 9 | import org.springframework.validation.annotation.Validated; |
| 11 | 10 | ||
| 12 | import javax.annotation.Resource; | 11 | import javax.annotation.Resource; |
| @@ -15,8 +14,8 @@ import java.util.List; | @@ -15,8 +14,8 @@ import java.util.List; | ||
| 15 | import java.util.Optional; | 14 | import java.util.Optional; |
| 16 | 15 | ||
| 17 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 16 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 18 | -import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH; | ||
| 19 | import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_USER_NOT_EXISTS; | 17 | import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_USER_NOT_EXISTS; |
| 18 | +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.USER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH; | ||
| 20 | 19 | ||
| 21 | /** | 20 | /** |
| 22 | * 分销用户 Service 实现类 | 21 | * 分销用户 Service 实现类 |
| @@ -65,9 +64,8 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService | @@ -65,9 +64,8 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService | ||
| 65 | } | 64 | } |
| 66 | } | 65 | } |
| 67 | 66 | ||
| 68 | - // TODO @疯狂:getBindBrokerageUser 会不会好点,因为统一使用 Bind 替代了 Invite | ||
| 69 | @Override | 67 | @Override |
| 70 | - public TradeBrokerageUserDO getInviteBrokerageUser(Long id) { | 68 | + public TradeBrokerageUserDO getBindBrokerageUser(Long id) { |
| 71 | return Optional.ofNullable(id) | 69 | return Optional.ofNullable(id) |
| 72 | .map(this::getBrokerageUser) | 70 | .map(this::getBrokerageUser) |
| 73 | .map(TradeBrokerageUserDO::getBrokerageUserId) | 71 | .map(TradeBrokerageUserDO::getBrokerageUserId) |
| @@ -75,10 +73,8 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService | @@ -75,10 +73,8 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService | ||
| 75 | .orElse(null); | 73 | .orElse(null); |
| 76 | } | 74 | } |
| 77 | 75 | ||
| 78 | - // TODO @疯狂:单个更新,不用事务哈; | ||
| 79 | @Override | 76 | @Override |
| 80 | - @Transactional(rollbackFor = Exception.class) | ||
| 81 | - public void updateUserBrokeragePrice(Long id, int brokeragePrice) { | 77 | + public void updateUserBrokeragePrice(Long id, Integer brokeragePrice) { |
| 82 | if (brokeragePrice > 0) { | 78 | if (brokeragePrice > 0) { |
| 83 | brokerageUserMapper.updateBrokeragePriceIncr(id, brokeragePrice); | 79 | brokerageUserMapper.updateBrokeragePriceIncr(id, brokeragePrice); |
| 84 | } else if (brokeragePrice < 0) { | 80 | } else if (brokeragePrice < 0) { |
| @@ -86,10 +82,8 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService | @@ -86,10 +82,8 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService | ||
| 86 | } | 82 | } |
| 87 | } | 83 | } |
| 88 | 84 | ||
| 89 | - // TODO @疯狂:单个更新,不用事务哈; | ||
| 90 | @Override | 85 | @Override |
| 91 | - @Transactional(rollbackFor = Exception.class) | ||
| 92 | - public void updateUserFrozenBrokeragePrice(Long id, int frozenBrokeragePrice) { | 86 | + public void updateUserFrozenBrokeragePrice(Long id, Integer frozenBrokeragePrice) { |
| 93 | if (frozenBrokeragePrice > 0) { | 87 | if (frozenBrokeragePrice > 0) { |
| 94 | brokerageUserMapper.updateFrozenBrokeragePriceIncr(id, frozenBrokeragePrice); | 88 | brokerageUserMapper.updateFrozenBrokeragePriceIncr(id, frozenBrokeragePrice); |
| 95 | } else if (frozenBrokeragePrice < 0) { | 89 | } else if (frozenBrokeragePrice < 0) { |
| @@ -97,15 +91,12 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService | @@ -97,15 +91,12 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService | ||
| 97 | } | 91 | } |
| 98 | } | 92 | } |
| 99 | 93 | ||
| 100 | - // TODO @疯狂:单个更新,不用事务哈; | ||
| 101 | @Override | 94 | @Override |
| 102 | - @Transactional(rollbackFor = Exception.class) | ||
| 103 | - public void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice) { | 95 | + public void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, Integer frozenBrokeragePrice) { |
| 104 | Assert.isTrue(frozenBrokeragePrice < 0); | 96 | Assert.isTrue(frozenBrokeragePrice < 0); |
| 105 | int updateRows = brokerageUserMapper.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(id, frozenBrokeragePrice); | 97 | int updateRows = brokerageUserMapper.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(id, frozenBrokeragePrice); |
| 106 | if (updateRows == 0) { | 98 | if (updateRows == 0) { |
| 107 | - // TODO @疯狂:挪到 trade 这变的错误码哈; | ||
| 108 | - throw exception(MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH); | 99 | + throw exception(USER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH); |
| 109 | } | 100 | } |
| 110 | } | 101 | } |
| 111 | 102 |
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; | @@ -12,8 +12,6 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 12 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | 12 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 13 | import cn.iocoder.yudao.module.member.api.address.AddressApi; | 13 | import cn.iocoder.yudao.module.member.api.address.AddressApi; |
| 14 | import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; | 14 | import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; |
| 15 | -import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; | ||
| 16 | -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; | ||
| 17 | import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; | 15 | import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; |
| 18 | import cn.iocoder.yudao.module.member.api.point.MemberPointApi; | 16 | import cn.iocoder.yudao.module.member.api.point.MemberPointApi; |
| 19 | import cn.iocoder.yudao.module.member.api.user.MemberUserApi; | 17 | import cn.iocoder.yudao.module.member.api.user.MemberUserApi; |
| @@ -49,9 +47,12 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; | @@ -49,9 +47,12 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; | ||
| 49 | import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper; | 47 | import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper; |
| 50 | import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper; | 48 | import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper; |
| 51 | import cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants; | 49 | import cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants; |
| 50 | +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; | ||
| 52 | import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; | 51 | import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; |
| 53 | import cn.iocoder.yudao.module.trade.enums.order.*; | 52 | import cn.iocoder.yudao.module.trade.enums.order.*; |
| 54 | import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; | 53 | import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; |
| 54 | +import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; | ||
| 55 | +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; | ||
| 55 | import cn.iocoder.yudao.module.trade.service.cart.CartService; | 56 | import cn.iocoder.yudao.module.trade.service.cart.CartService; |
| 56 | import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; | 57 | import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; |
| 57 | import cn.iocoder.yudao.module.trade.service.message.TradeMessageService; | 58 | import cn.iocoder.yudao.module.trade.service.message.TradeMessageService; |
| @@ -370,7 +371,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -370,7 +371,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 370 | // 增加用户经验 | 371 | // 增加用户经验 |
| 371 | getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); | 372 | getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); |
| 372 | // 增加用户佣金 | 373 | // 增加用户佣金 |
| 373 | - getSelf().addBrokerageAsync(order.getUserId(), order.getId()); | 374 | + getSelf().addBrokerageAsync(order.getUserId(), BrokerageRecordBizTypeEnum.ORDER, order.getId()); |
| 374 | } | 375 | } |
| 375 | 376 | ||
| 376 | /** | 377 | /** |
| @@ -640,7 +641,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -640,7 +641,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 640 | // 扣减用户经验 | 641 | // 扣减用户经验 |
| 641 | getSelf().reduceUserExperienceAsync(order.getUserId(), orderRefundPrice, afterSaleId); | 642 | getSelf().reduceUserExperienceAsync(order.getUserId(), orderRefundPrice, afterSaleId); |
| 642 | // 更新分佣记录为已失效 | 643 | // 更新分佣记录为已失效 |
| 643 | - getSelf().cancelBrokerageAsync(order.getUserId(), id); | 644 | + getSelf().cancelBrokerageAsync(order.getUserId(), BrokerageRecordBizTypeEnum.ORDER, id); |
| 644 | } | 645 | } |
| 645 | 646 | ||
| 646 | @Override | 647 | @Override |
| @@ -750,16 +751,16 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -750,16 +751,16 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 750 | 751 | ||
| 751 | 752 | ||
| 752 | @Async | 753 | @Async |
| 753 | - protected void addBrokerageAsync(Long userId, Long orderId) { | 754 | + protected void addBrokerageAsync(Long userId, BrokerageRecordBizTypeEnum bizType, Long orderId) { |
| 754 | List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(orderId); | 755 | List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(orderId); |
| 755 | List<BrokerageAddReqBO> list = convertList(orderItems, | 756 | List<BrokerageAddReqBO> list = convertList(orderItems, |
| 756 | item -> TradeOrderConvert.INSTANCE.convert(item, productSkuApi.getSku(item.getSkuId()))); | 757 | item -> TradeOrderConvert.INSTANCE.convert(item, productSkuApi.getSku(item.getSkuId()))); |
| 757 | - tradeBrokerageRecordService.addBrokerage(userId, list); | 758 | + tradeBrokerageRecordService.addBrokerage(userId, bizType, list); |
| 758 | } | 759 | } |
| 759 | 760 | ||
| 760 | @Async | 761 | @Async |
| 761 | - protected void cancelBrokerageAsync(Long userId, Long orderItemId) { | ||
| 762 | - tradeBrokerageRecordService.cancelBrokerage(userId, String.valueOf(orderItemId)); | 762 | + protected void cancelBrokerageAsync(Long userId, BrokerageRecordBizTypeEnum bizType, Long orderItemId) { |
| 763 | + tradeBrokerageRecordService.cancelBrokerage(userId, bizType, String.valueOf(orderItemId)); | ||
| 763 | } | 764 | } |
| 764 | 765 | ||
| 765 | /** | 766 | /** |
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 { | @@ -79,38 +79,38 @@ public class TradeBrokerageRecordServiceImplTest extends BaseDbUnitTest { | ||
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | @Test | 81 | @Test |
| 82 | - public void testCalculateBrokerage_useSkuBrokeragePrice() { | 82 | + public void testCalculateBrokeragePrice_useFixedBrokeragePrice() { |
| 83 | // mock 数据 | 83 | // mock 数据 |
| 84 | Integer payPrice = randomInteger(); | 84 | Integer payPrice = randomInteger(); |
| 85 | Integer percent = randomInt(1, 101); | 85 | Integer percent = randomInt(1, 101); |
| 86 | - Integer skuBrokeragePrice = randomInt(); | 86 | + Integer fixedBrokeragePrice = randomInt(); |
| 87 | // 调用 | 87 | // 调用 |
| 88 | - int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); | 88 | + int brokerage = tradeBrokerageRecordService.calculateBrokeragePrice(payPrice, percent, fixedBrokeragePrice); |
| 89 | // 断言 | 89 | // 断言 |
| 90 | - assertEquals(brokerage, skuBrokeragePrice); | 90 | + assertEquals(brokerage, fixedBrokeragePrice); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | @Test | 93 | @Test |
| 94 | - public void testCalculateBrokerage_usePercent() { | 94 | + public void testCalculateBrokeragePrice_usePercent() { |
| 95 | // mock 数据 | 95 | // mock 数据 |
| 96 | Integer payPrice = randomInteger(); | 96 | Integer payPrice = randomInteger(); |
| 97 | Integer percent = randomInt(1, 101); | 97 | Integer percent = randomInt(1, 101); |
| 98 | Integer skuBrokeragePrice = randomEle(new Integer[]{0, null}); | 98 | Integer skuBrokeragePrice = randomEle(new Integer[]{0, null}); |
| 99 | System.out.println("skuBrokeragePrice=" + skuBrokeragePrice); | 99 | System.out.println("skuBrokeragePrice=" + skuBrokeragePrice); |
| 100 | // 调用 | 100 | // 调用 |
| 101 | - int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); | 101 | + int brokerage = tradeBrokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); |
| 102 | // 断言 | 102 | // 断言 |
| 103 | assertEquals(brokerage, NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue()); | 103 | assertEquals(brokerage, NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue()); |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | @Test | 106 | @Test |
| 107 | - public void testCalculateBrokerage_equalsZero() { | 107 | + public void testCalculateBrokeragePrice_equalsZero() { |
| 108 | // mock 数据 | 108 | // mock 数据 |
| 109 | Integer payPrice = null; | 109 | Integer payPrice = null; |
| 110 | Integer percent = null; | 110 | Integer percent = null; |
| 111 | Integer skuBrokeragePrice = null; | 111 | Integer skuBrokeragePrice = null; |
| 112 | // 调用 | 112 | // 调用 |
| 113 | - int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); | 113 | + int brokerage = tradeBrokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); |
| 114 | // 断言 | 114 | // 断言 |
| 115 | assertEquals(brokerage, 0); | 115 | assertEquals(brokerage, 0); |
| 116 | } | 116 | } |
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 { | @@ -13,7 +13,6 @@ public interface ErrorCodeConstants { | ||
| 13 | ErrorCode USER_NOT_EXISTS = new ErrorCode(1004001000, "用户不存在"); | 13 | ErrorCode USER_NOT_EXISTS = new ErrorCode(1004001000, "用户不存在"); |
| 14 | ErrorCode USER_MOBILE_NOT_EXISTS = new ErrorCode(1004001001, "手机号未注册用户"); | 14 | ErrorCode USER_MOBILE_NOT_EXISTS = new ErrorCode(1004001001, "手机号未注册用户"); |
| 15 | ErrorCode USER_MOBILE_USED = new ErrorCode(1004001002, "修改手机失败,该手机号({})已经被使用"); | 15 | ErrorCode USER_MOBILE_USED = new ErrorCode(1004001002, "修改手机失败,该手机号({})已经被使用"); |
| 16 | - ErrorCode MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH = new ErrorCode(1004001003, "用户冻结佣金({})数量不足"); | ||
| 17 | 16 | ||
| 18 | // ========== AUTH 模块 1004003000 ========== | 17 | // ========== AUTH 模块 1004003000 ========== |
| 19 | ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1004003000, "登录失败,账号密码不正确"); | 18 | ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1004003000, "登录失败,账号密码不正确"); |