From 166b1b31c0b20c3016fa2bebce376fdef96ea142 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 10:59:06 +0800 Subject: [PATCH 01/12] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/brokerage.sql | 11 +++--- .../user/TradeBrokerageUserController.java | 35 ++++++++++++++++++- .../user/vo/TradeBrokerageUserRespVO.java | 26 ++++++++++++++ .../user/TradeBrokerageUserConvert.java | 34 ++++++++++++++++++ .../record/TradeBrokerageRecordMapper.java | 7 ++++ .../record/TradeBrokerageRecordService.java | 14 ++++++-- .../TradeBrokerageRecordServiceImpl.java | 7 ++++ .../record/bo/UserBrokerageSummaryBO.java | 24 +++++++++++++ .../user/TradeBrokerageUserService.java | 7 ++++ .../user/TradeBrokerageUserServiceImpl.java | 5 +++ .../dal/dataobject/user/MemberUserDO.java | 34 ------------------ 11 files changed, 163 insertions(+), 41 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/UserBrokerageSummaryBO.java diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index 127fcb728..48adc14e8 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -24,7 +24,7 @@ create table trade_config create table trade_brokerage_user ( id bigint auto_increment comment '用户编号' primary key, - brokerage_user_id bigint not null comment '推广员编号', + brokerage_user_id bigint null comment '推广员编号', brokerage_bind_time datetime null comment '推广员绑定时间', brokerage_enabled bit default 1 not null comment '是否成为推广员', brokerage_time datetime null comment '成为分销员时间', @@ -185,12 +185,15 @@ SELECT @parentId := LAST_INSERT_ID(); INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) VALUES ('分销用户查询', 'trade:brokerage-user:query', 3, 1, @parentId, '', '', '', 0); INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) -VALUES ('分销用户修改推广员', 'trade:brokerage-user:update-brokerage-user', 3, 2, @parentId, '', '', '', 0); +VALUES ('分销用户推广人查询', 'trade:brokerage-user:user-query', 3, 2, @parentId, '', '', '', 0); INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) -VALUES ('分销用户清除推广员', 'trade:brokerage-user:clear-brokerage-user', 3, 3, @parentId, '', '', '', 0); +VALUES ('分销用户推广订单查询', 'trade:brokerage-user:order-query', 3, 3, @parentId, '', '', '', 0); INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) VALUES ('分销用户修改推广资格', 'trade:brokerage-user:update-brokerage-enable', 3, 4, @parentId, '', '', '', 0); - +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('分销用户修改推广员', 'trade:brokerage-user:update-brokerage-user', 3, 5, @parentId, '', '', '', 0); +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('分销用户清除推广员', 'trade:brokerage-user:clear-brokerage-user', 3, 6, @parentId, '', '', '', 0); -- 增加菜单:佣金记录 INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name) 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 e4cc63fb9..5da3acb5b 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 @@ -2,9 +2,15 @@ package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.*; import cn.iocoder.yudao.module.trade.convert.brokerage.user.TradeBrokerageUserConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +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.user.TradeBrokerageUserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -15,8 +21,12 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.Map; +import java.util.Set; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; @Tag(name = "管理后台 - 分销用户") @RestController @@ -26,6 +36,11 @@ public class TradeBrokerageUserController { @Resource private TradeBrokerageUserService brokerageUserService; + @Resource + private TradeBrokerageRecordService brokerageRecordService; + + @Resource + private MemberUserApi memberUserApi; @PutMapping("/update-brokerage-user") @Operation(summary = "修改推广员") @@ -64,8 +79,26 @@ public class TradeBrokerageUserController { @Operation(summary = "获得分销用户分页") @PreAuthorize("@ss.hasPermission('trade:brokerage-user:query')") public CommonResult> getBrokerageUserPage(@Valid TradeBrokerageUserPageReqVO pageVO) { + // 分页查询 PageResult pageResult = brokerageUserService.getBrokerageUserPage(pageVO); - return success(TradeBrokerageUserConvert.INSTANCE.convertPage(pageResult)); + + // 涉及到的用户 + Set userIds = convertSet(pageResult.getList(), TradeBrokerageUserDO::getId); + // 查询用户信息 + Map userMap = memberUserApi.getUserMap(userIds); + // 合计分佣订单 + Map userOrderSummaryMap = convertMap(userIds, + userId -> userId, + userId -> brokerageRecordService.summaryByUserIdAndBizTypeAndStatus(userId, + BrokerageRecordBizTypeEnum.ORDER.getType(), BrokerageRecordStatusEnum.SETTLEMENT.getStatus())); + // 合计推广用户数量 + Map brokerageUserCountMap = convertMap(userIds, + userId -> userId, + userId -> brokerageUserService.getCountByBrokerageUserId(userId)); + + // todo 合计提现 + + return success(TradeBrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java index 090eb04b5..ee82efa0d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java @@ -19,4 +19,30 @@ public class TradeBrokerageUserRespVO extends TradeBrokerageUserBaseVO { @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; + + // ========== 用户信息 ========== + + @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png") + private String avatar; + @Schema(description = "用户昵称", example = "李四") + private String nickname; + + + // ========== 推广信息 ========== + + @Schema(description = "推广用户数量(一级)", example = "20019") + private Integer brokerageUserCount; + @Schema(description = "推广订单数量", example = "20019") + private Integer brokerageOrderCount; + @Schema(description = "推广订单金额", example = "20019") + private Integer brokerageOrderPrice; + + + // ========== 提现信息 ========== + + @Schema(description = "已提现金额", example = "20019") + private Integer withdrawPrice; + @Schema(description = "已提现次数", example = "20019") + private Integer withdrawCount; + } 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 1a62bded0..b5800efed 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 @@ -1,12 +1,17 @@ package cn.iocoder.yudao.module.trade.convert.brokerage.user; +import cn.hutool.core.map.MapUtil; 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 org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; import java.util.List; +import java.util.Map; +import java.util.Optional; /** * 分销用户 Convert @@ -24,4 +29,33 @@ public interface TradeBrokerageUserConvert { PageResult convertPage(PageResult page); + default PageResult convertPage(PageResult pageResult, + Map userMap, + Map brokerageUserCountMap, + Map userOrderSummaryMap) { + PageResult result = convertPage(pageResult); + for (TradeBrokerageUserRespVO vo : result.getList()) { + // 用户信息 + Optional.ofNullable(userMap.get(vo.getId())) + .ifPresent(user -> { + vo.setNickname(user.getNickname()); + vo.setAvatar(user.getAvatar()); + }); + + // 推广用户数量(一级) + vo.setBrokerageUserCount(MapUtil.getInt(brokerageUserCountMap, vo.getId(), 0)); + + Optional orderSummaryOptional = Optional.ofNullable(userOrderSummaryMap.get(vo.getId())); + // 推广订单数量 + vo.setBrokerageOrderCount(orderSummaryOptional.map(UserBrokerageSummaryBO::getCount).orElse(0)); + // 推广订单金额 + vo.setBrokerageOrderPrice(orderSummaryOptional.map(UserBrokerageSummaryBO::getPrice).orElse(0)); + + // todo 已提现次数 + vo.setWithdrawCount(0); + // todo 已提现金额 + vo.setWithdrawPrice(0); + } + return result; + } } 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 41ed8bad9..2adb488eb 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,8 +5,11 @@ 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 com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; import java.time.LocalDateTime; import java.util.List; @@ -46,4 +49,8 @@ public interface TradeBrokerageRecordMapper extends BaseMapperX Date: Fri, 8 Sep 2023 12:29:38 +0800 Subject: [PATCH 02/12] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80Review?= =?UTF-8?q?=E4=BB=A3=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, "登录失败,账号密码不正确"); From ddcebb1986c7c11457fb7f93fd142e4af3495e13 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 12:46:43 +0800 Subject: [PATCH 03/12] =?UTF-8?q?common:=20MoneyUtils=20=E7=A7=BB=E5=88=B0?= =?UTF-8?q?=20common=20=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/util/number}/MoneyUtils.java | 13 ++++++++++++- .../record/TradeBrokerageRecordServiceImpl.java | 6 ++---- .../pay/service/order/PayOrderServiceImpl.java | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) rename {yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/util => yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number}/MoneyUtils.java (71%) diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/util/MoneyUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java similarity index 71% rename from yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/util/MoneyUtils.java rename to yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java index 5e5d859e6..e2fd3fa6e 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/util/MoneyUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.pay.util; +package cn.iocoder.yudao.framework.common.util.number; import cn.hutool.core.util.NumberUtil; @@ -23,6 +23,17 @@ public class MoneyUtils { return calculateRatePrice(price, rate, 0, RoundingMode.HALF_UP).intValue(); } + /** + * 计算百分比金额,向下传入 + * + * @param price 金额 + * @param rate 百分比,例如说 56.77% 则传入 56.77 + * @return 百分比金额 + */ + public static Integer calculateRatePriceFloor(Integer price, Double rate) { + return calculateRatePrice(price, rate, 0, RoundingMode.FLOOR).intValue(); + } + /** * 计算百分比金额 * 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 01946a060..ad1a5c8ff 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 @@ -2,10 +2,10 @@ package cn.iocoder.yudao.module.trade.service.brokerage.record; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.BooleanUtil; -import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.convert.brokerage.record.TradeBrokerageRecordConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; @@ -24,7 +24,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.math.RoundingMode; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -126,9 +125,8 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ return ObjectUtil.defaultIfNull(fixedBrokeragePrice, 0); } // 2. 根据比例计算佣金 - // TODO @疯狂:要不要把 MoneyUtils 抽到 common 里,然后这里也使用这个类的方法; if (basePrice != null && basePrice > 0 && percent != null && percent > 0) { - return NumberUtil.div(NumberUtil.mul(basePrice, percent), 100, 0, RoundingMode.DOWN).intValue(); + return MoneyUtils.calculateRatePriceFloor(basePrice, Double.valueOf(percent)); } return 0; } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java index 944df1a10..0445df8a6 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java @@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; import cn.iocoder.yudao.framework.pay.core.client.PayClient; import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; @@ -31,7 +32,6 @@ import cn.iocoder.yudao.module.pay.framework.pay.config.PayProperties; import cn.iocoder.yudao.module.pay.service.app.PayAppService; import cn.iocoder.yudao.module.pay.service.channel.PayChannelService; import cn.iocoder.yudao.module.pay.service.notify.PayNotifyService; -import cn.iocoder.yudao.module.pay.util.MoneyUtils; import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; From 0a0c3c0ede6eec2266507684759784d8ad803a31 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 12:56:34 +0800 Subject: [PATCH 04/12] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E7=9B=B8=E5=85=B3=E7=B1=BB=E5=9E=8B=E7=A7=BB=E9=99=A4?= =?UTF-8?q?Trade=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...er.java => BrokerageRecordController.java} | 26 +++---- ...BaseVO.java => BrokerageRecordBaseVO.java} | 2 +- ...qVO.java => BrokerageRecordPageReqVO.java} | 2 +- ...RespVO.java => BrokerageRecordRespVO.java} | 2 +- ...ller.java => BrokerageUserController.java} | 34 +++++----- ...erBaseVO.java => BrokerageUserBaseVO.java} | 2 +- ...BrokerageUserClearBrokerageUserReqVO.java} | 2 +- ...ReqVO.java => BrokerageUserPageReqVO.java} | 2 +- ...erRespVO.java => BrokerageUserRespVO.java} | 2 +- ...erageUserUpdateBrokerageEnabledReqVO.java} | 2 +- ...rokerageUserUpdateBrokerageUserReqVO.java} | 2 +- ...nvert.java => BrokerageRecordConvert.java} | 24 +++---- ...Convert.java => BrokerageUserConvert.java} | 26 +++---- ...geRecordDO.java => BrokerageRecordDO.java} | 2 +- ...kerageUserDO.java => BrokerageUserDO.java} | 2 +- .../record/BrokerageRecordMapper.java | 55 +++++++++++++++ .../record/TradeBrokerageRecordMapper.java | 55 --------------- ...erMapper.java => BrokerageUserMapper.java} | 40 +++++------ ...b.java => BrokerageRecordUnfreezeJob.java} | 8 +-- ...rvice.java => BrokerageRecordService.java} | 10 +-- ...l.java => BrokerageRecordServiceImpl.java} | 68 +++++++++---------- ...Service.java => BrokerageUserService.java} | 15 ++-- ...mpl.java => BrokerageUserServiceImpl.java} | 22 +++--- .../order/TradeOrderUpdateServiceImpl.java | 8 +-- ...va => BrokerageRecordServiceImplTest.java} | 42 ++++++------ ...java => BrokerageUserServiceImplTest.java} | 22 +++--- 26 files changed, 238 insertions(+), 239 deletions(-) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/{TradeBrokerageRecordController.java => BrokerageRecordController.java} (59%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/{TradeBrokerageRecordBaseVO.java => BrokerageRecordBaseVO.java} (98%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/{TradeBrokerageRecordPageReqVO.java => BrokerageRecordPageReqVO.java} (94%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/{TradeBrokerageRecordRespVO.java => BrokerageRecordRespVO.java} (89%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/{TradeBrokerageUserController.java => BrokerageUserController.java} (73%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/{TradeBrokerageUserBaseVO.java => BrokerageUserBaseVO.java} (97%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/{TradeBrokerageUserClearBrokerageUserReqVO.java => BrokerageUserClearBrokerageUserReqVO.java} (90%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/{TradeBrokerageUserPageReqVO.java => BrokerageUserPageReqVO.java} (93%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/{TradeBrokerageUserRespVO.java => BrokerageUserRespVO.java} (95%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/{TradeBrokerageUserUpdateBrokerageEnabledReqVO.java => BrokerageUserUpdateBrokerageEnabledReqVO.java} (92%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/{TradeBrokerageUserUpdateBrokerageUserReqVO.java => BrokerageUserUpdateBrokerageUserReqVO.java} (92%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/{TradeBrokerageRecordConvert.java => BrokerageRecordConvert.java} (65%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/{TradeBrokerageUserConvert.java => BrokerageUserConvert.java} (62%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/{TradeBrokerageRecordDO.java => BrokerageRecordDO.java} (97%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/{TradeBrokerageUserDO.java => BrokerageUserDO.java} (96%) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/BrokerageRecordMapper.java delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/{TradeBrokerageUserMapper.java => BrokerageUserMapper.java} (65%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/{TradeBrokerageRecordUnfreezeJob.java => BrokerageRecordUnfreezeJob.java} (63%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/{TradeBrokerageRecordService.java => BrokerageRecordService.java} (86%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/{TradeBrokerageRecordServiceImpl.java => BrokerageRecordServiceImpl.java} (72%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/{TradeBrokerageUserService.java => BrokerageUserService.java} (78%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/{TradeBrokerageUserServiceImpl.java => BrokerageUserServiceImpl.java} (80%) rename yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/{TradeBrokerageRecordServiceImplTest.java => BrokerageRecordServiceImplTest.java} (67%) rename yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/{TradeBrokerageUserServiceImplTest.java => BrokerageUserServiceImplTest.java} (74%) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/TradeBrokerageRecordController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/BrokerageRecordController.java similarity index 59% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/TradeBrokerageRecordController.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/BrokerageRecordController.java index 38b2f4d71..81034124b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/TradeBrokerageRecordController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/BrokerageRecordController.java @@ -2,11 +2,11 @@ package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record; import cn.iocoder.yudao.framework.common.pojo.CommonResult; 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.controller.admin.brokerage.record.vo.TradeBrokerageRecordRespVO; -import cn.iocoder.yudao.module.trade.convert.brokerage.record.TradeBrokerageRecordConvert; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordRespVO; +import cn.iocoder.yudao.module.trade.convert.brokerage.record.BrokerageRecordConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; +import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -26,26 +26,26 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RestController @RequestMapping("/trade/brokerage-record") @Validated -public class TradeBrokerageRecordController { +public class BrokerageRecordController { @Resource - private TradeBrokerageRecordService tradeBrokerageRecordService; + private BrokerageRecordService brokerageRecordService; @GetMapping("/get") @Operation(summary = "获得佣金记录") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('trade:brokerage-record:query')") - public CommonResult getBrokerageRecord(@RequestParam("id") Integer id) { - TradeBrokerageRecordDO tradeBrokerageRecord = tradeBrokerageRecordService.getBrokerageRecord(id); - return success(TradeBrokerageRecordConvert.INSTANCE.convert(tradeBrokerageRecord)); + public CommonResult getBrokerageRecord(@RequestParam("id") Integer id) { + BrokerageRecordDO brokerageRecord = brokerageRecordService.getBrokerageRecord(id); + return success(BrokerageRecordConvert.INSTANCE.convert(brokerageRecord)); } @GetMapping("/page") @Operation(summary = "获得佣金记录分页") @PreAuthorize("@ss.hasPermission('trade:brokerage-record:query')") - public CommonResult> getBrokerageRecordPage(@Valid TradeBrokerageRecordPageReqVO pageVO) { - PageResult pageResult = tradeBrokerageRecordService.getBrokerageRecordPage(pageVO); - return success(TradeBrokerageRecordConvert.INSTANCE.convertPage(pageResult)); + public CommonResult> getBrokerageRecordPage(@Valid BrokerageRecordPageReqVO pageVO) { + PageResult pageResult = brokerageRecordService.getBrokerageRecordPage(pageVO); + return success(BrokerageRecordConvert.INSTANCE.convertPage(pageResult)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordBaseVO.java similarity index 98% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordBaseVO.java index f15d07706..cce84a804 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordBaseVO.java @@ -15,7 +15,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 */ @Data -public class TradeBrokerageRecordBaseVO { +public class BrokerageRecordBaseVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25973") @NotNull(message = "用户编号不能为空") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordPageReqVO.java similarity index 94% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordPageReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordPageReqVO.java index abd948f09..533fbd2ca 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordPageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordPageReqVO.java @@ -15,7 +15,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class TradeBrokerageRecordPageReqVO extends PageParam { +public class BrokerageRecordPageReqVO extends PageParam { @Schema(description = "用户编号", example = "25973") private Long userId; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordRespVO.java similarity index 89% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordRespVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordRespVO.java index 724d7d3e5..aead00a08 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordRespVO.java @@ -11,7 +11,7 @@ import java.time.LocalDateTime; @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class TradeBrokerageRecordRespVO extends TradeBrokerageRecordBaseVO { +public class BrokerageRecordRespVO extends BrokerageRecordBaseVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "28896") private Integer id; 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/BrokerageUserController.java similarity index 73% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java index 38a27d8c8..b6c9a1c84 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/BrokerageUserController.java @@ -5,13 +5,13 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.*; -import cn.iocoder.yudao.module.trade.convert.brokerage.user.TradeBrokerageUserConvert; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.convert.brokerage.user.BrokerageUserConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; 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.BrokerageRecordService; 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.brokerage.user.BrokerageUserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -32,12 +32,12 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. @RestController @RequestMapping("/trade/brokerage-user") @Validated -public class TradeBrokerageUserController { +public class BrokerageUserController { @Resource - private TradeBrokerageUserService brokerageUserService; + private BrokerageUserService brokerageUserService; @Resource - private TradeBrokerageRecordService brokerageRecordService; + private BrokerageRecordService brokerageRecordService; @Resource private MemberUserApi memberUserApi; @@ -45,7 +45,7 @@ public class TradeBrokerageUserController { @PutMapping("/update-brokerage-user") @Operation(summary = "修改推广员") @PreAuthorize("@ss.hasPermission('trade:brokerage-user:update-brokerage-user')") - public CommonResult updateBrokerageUser(@Valid @RequestBody TradeBrokerageUserUpdateBrokerageUserReqVO updateReqVO) { + public CommonResult updateBrokerageUser(@Valid @RequestBody BrokerageUserUpdateBrokerageUserReqVO updateReqVO) { brokerageUserService.updateBrokerageUserId(updateReqVO.getId(), updateReqVO.getBrokerageUserId()); return success(true); } @@ -53,7 +53,7 @@ public class TradeBrokerageUserController { @PutMapping("/clear-brokerage-user") @Operation(summary = "清除推广员") @PreAuthorize("@ss.hasPermission('trade:brokerage-user:clear-brokerage-user')") - public CommonResult clearBrokerageUser(@Valid @RequestBody TradeBrokerageUserClearBrokerageUserReqVO updateReqVO) { + public CommonResult clearBrokerageUser(@Valid @RequestBody BrokerageUserClearBrokerageUserReqVO updateReqVO) { brokerageUserService.updateBrokerageUserId(updateReqVO.getId(), null); return success(true); } @@ -61,7 +61,7 @@ public class TradeBrokerageUserController { @PutMapping("/update-brokerage-enable") @Operation(summary = "修改推广资格") @PreAuthorize("@ss.hasPermission('trade:brokerage-user:update-brokerage-enable')") - public CommonResult updateBrokerageEnabled(@Valid @RequestBody TradeBrokerageUserUpdateBrokerageEnabledReqVO updateReqVO) { + public CommonResult updateBrokerageEnabled(@Valid @RequestBody BrokerageUserUpdateBrokerageEnabledReqVO updateReqVO) { brokerageUserService.updateBrokerageEnabled(updateReqVO.getId(), updateReqVO.getBrokerageEnabled()); return success(true); } @@ -70,20 +70,20 @@ public class TradeBrokerageUserController { @Operation(summary = "获得分销用户") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('trade:brokerage-user:query')") - public CommonResult getBrokerageUser(@RequestParam("id") Long id) { - TradeBrokerageUserDO brokerageUser = brokerageUserService.getBrokerageUser(id); - return success(TradeBrokerageUserConvert.INSTANCE.convert(brokerageUser)); + public CommonResult getBrokerageUser(@RequestParam("id") Long id) { + BrokerageUserDO brokerageUser = brokerageUserService.getBrokerageUser(id); + return success(BrokerageUserConvert.INSTANCE.convert(brokerageUser)); } @GetMapping("/page") @Operation(summary = "获得分销用户分页") @PreAuthorize("@ss.hasPermission('trade:brokerage-user:query')") - public CommonResult> getBrokerageUserPage(@Valid TradeBrokerageUserPageReqVO pageVO) { + public CommonResult> getBrokerageUserPage(@Valid BrokerageUserPageReqVO pageVO) { // 分页查询 - PageResult pageResult = brokerageUserService.getBrokerageUserPage(pageVO); + PageResult pageResult = brokerageUserService.getBrokerageUserPage(pageVO); // 涉及到的用户 - Set userIds = convertSet(pageResult.getList(), TradeBrokerageUserDO::getId); + Set userIds = convertSet(pageResult.getList(), BrokerageUserDO::getId); // 查询用户信息 Map userMap = memberUserApi.getUserMap(userIds); // 合计分佣订单 @@ -98,7 +98,7 @@ public class TradeBrokerageUserController { // todo 合计提现 - return success(TradeBrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap)); + return success(BrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java similarity index 97% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserBaseVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java index d75e6a1b1..41ddd454c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java @@ -14,7 +14,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 */ @Data -public class TradeBrokerageUserBaseVO { +public class BrokerageUserBaseVO { @Schema(description = "推广员编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4587") @NotNull(message = "推广员编号不能为空") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserClearBrokerageUserReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserClearBrokerageUserReqVO.java similarity index 90% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserClearBrokerageUserReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserClearBrokerageUserReqVO.java index 18a5a5e85..edb0102a0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserClearBrokerageUserReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserClearBrokerageUserReqVO.java @@ -9,7 +9,7 @@ import javax.validation.constraints.NotNull; @Schema(description = "管理后台 - 分销用户 - 清除推广员 Request VO") @Data @ToString(callSuper = true) -public class TradeBrokerageUserClearBrokerageUserReqVO { +public class BrokerageUserClearBrokerageUserReqVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20019") @NotNull(message = "用户编号不能为空") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java similarity index 93% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserPageReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java index ec63775d3..2b99d686e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserPageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java @@ -15,7 +15,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class TradeBrokerageUserPageReqVO extends PageParam { +public class BrokerageUserPageReqVO extends PageParam { @Schema(description = "推广员编号", example = "4587") private Long brokerageUserId; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserRespVO.java similarity index 95% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserRespVO.java index ee82efa0d..c353b4614 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserRespVO.java @@ -11,7 +11,7 @@ import java.time.LocalDateTime; @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class TradeBrokerageUserRespVO extends TradeBrokerageUserBaseVO { +public class BrokerageUserRespVO extends BrokerageUserBaseVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20019") private Long id; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java similarity index 92% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java index 1fd38b028..5e6d920be 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java @@ -9,7 +9,7 @@ import javax.validation.constraints.NotNull; @Schema(description = "管理后台 - 分销用户 - 修改推广员 Request VO") @Data @ToString(callSuper = true) -public class TradeBrokerageUserUpdateBrokerageEnabledReqVO { +public class BrokerageUserUpdateBrokerageEnabledReqVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20019") @NotNull(message = "用户编号不能为空") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageUserReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java similarity index 92% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageUserReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java index 28ea301c1..c6c72999d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageUserReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java @@ -9,7 +9,7 @@ import javax.validation.constraints.NotNull; @Schema(description = "管理后台 - 分销用户 - 修改推广员 Request VO") @Data @ToString(callSuper = true) -public class TradeBrokerageUserUpdateBrokerageUserReqVO { +public class BrokerageUserUpdateBrokerageUserReqVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20019") @NotNull(message = "用户编号不能为空") 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/BrokerageRecordConvert.java similarity index 65% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java index 2d67f5f2e..d619c6926 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/BrokerageRecordConvert.java @@ -3,9 +3,9 @@ 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; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordRespVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; import org.mapstruct.Mapper; @@ -20,25 +20,25 @@ import java.util.List; * @author owen */ @Mapper -public interface TradeBrokerageRecordConvert { +public interface BrokerageRecordConvert { - TradeBrokerageRecordConvert INSTANCE = Mappers.getMapper(TradeBrokerageRecordConvert.class); + BrokerageRecordConvert INSTANCE = Mappers.getMapper(BrokerageRecordConvert.class); - TradeBrokerageRecordRespVO convert(TradeBrokerageRecordDO bean); + BrokerageRecordRespVO convert(BrokerageRecordDO bean); - List convertList(List list); + List convertList(List list); - PageResult convertPage(PageResult page); + PageResult convertPage(PageResult page); - default TradeBrokerageRecordDO convert(TradeBrokerageUserDO user, BrokerageRecordBizTypeEnum bizType, String bizId, - Integer brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime, - String title) { + default BrokerageRecordDO convert(BrokerageUserDO 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() + return new BrokerageRecordDO() .setUserId(user.getId()) .setBizType(bizType.getType()) .setBizId(bizId) 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/BrokerageUserConvert.java similarity index 62% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java index beda1571c..c4a31cc98 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/BrokerageUserConvert.java @@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.trade.convert.brokerage.user; import cn.hutool.core.map.MapUtil; 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.controller.admin.brokerage.user.vo.BrokerageUserRespVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -19,22 +19,22 @@ import java.util.Optional; * @author owen */ @Mapper -public interface TradeBrokerageUserConvert { +public interface BrokerageUserConvert { - TradeBrokerageUserConvert INSTANCE = Mappers.getMapper(TradeBrokerageUserConvert.class); + BrokerageUserConvert INSTANCE = Mappers.getMapper(BrokerageUserConvert.class); - TradeBrokerageUserRespVO convert(TradeBrokerageUserDO bean); + BrokerageUserRespVO convert(BrokerageUserDO bean); - List convertList(List list); + List convertList(List list); - PageResult convertPage(PageResult page); + PageResult convertPage(PageResult page); - default PageResult convertPage(PageResult pageResult, - Map userMap, - Map brokerageUserCountMap, - Map userOrderSummaryMap) { - PageResult result = convertPage(pageResult); - for (TradeBrokerageUserRespVO vo : result.getList()) { + default PageResult convertPage(PageResult pageResult, + Map userMap, + Map brokerageUserCountMap, + Map userOrderSummaryMap) { + PageResult result = convertPage(pageResult); + for (BrokerageUserRespVO vo : result.getList()) { // 用户信息 Optional.ofNullable(userMap.get(vo.getId())) .ifPresent(user -> { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/BrokerageRecordDO.java similarity index 97% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/BrokerageRecordDO.java index bb3f09c52..be69c6075 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/BrokerageRecordDO.java @@ -23,7 +23,7 @@ import java.time.LocalDateTime; @Builder @NoArgsConstructor @AllArgsConstructor -public class TradeBrokerageRecordDO extends BaseDO { +public class BrokerageRecordDO extends BaseDO { /** * 编号 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java similarity index 96% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java index 3f1cc73aa..4b85dc3d0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java @@ -22,7 +22,7 @@ import java.time.LocalDateTime; @Builder @NoArgsConstructor @AllArgsConstructor -public class TradeBrokerageUserDO extends BaseDO { +public class BrokerageUserDO extends BaseDO { /** * 用户编号 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/BrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/BrokerageRecordMapper.java new file mode 100644 index 000000000..9f9aae824 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/BrokerageRecordMapper.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +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.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; +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; +import org.apache.ibatis.annotations.Select; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 佣金记录 Mapper + * + * @author owen + */ +@Mapper +public interface BrokerageRecordMapper extends BaseMapperX { + + default PageResult selectPage(BrokerageRecordPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(BrokerageRecordDO::getUserId, reqVO.getUserId()) + .eqIfPresent(BrokerageRecordDO::getBizType, reqVO.getBizType()) + .eqIfPresent(BrokerageRecordDO::getStatus, reqVO.getStatus()) + .betweenIfPresent(BrokerageRecordDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(BrokerageRecordDO::getId)); + } + + default List selectListByStatusAndUnfreezeTimeLt(Integer status, LocalDateTime unfreezeTime) { + return selectList(new LambdaQueryWrapper() + .eq(BrokerageRecordDO::getStatus, status) + .lt(BrokerageRecordDO::getUnfreezeTime, unfreezeTime)); + } + + default int updateByIdAndStatus(Integer id, Integer status, BrokerageRecordDO updateObj) { + return update(updateObj, new LambdaQueryWrapper() + .eq(BrokerageRecordDO::getId, id) + .eq(BrokerageRecordDO::getStatus, status)); + } + + default BrokerageRecordDO selectByBizTypeAndBizId(Integer bizType, String bizId) { + return selectOne(BrokerageRecordDO::getBizType, bizType, + BrokerageRecordDO::getBizId, bizId); + } + + @Select("select count(1), sum(price) from trade_brokerage_record where user_id = #{userId} and biz_type = #{bizType} and status = #{status}") + UserBrokerageSummaryBO selectCountAndSumPriceByUserIdAndBizTypeAndStatus(@Param("userId") Long userId, + @Param("bizType") Integer bizType, + @Param("status") Integer status); +} 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 deleted file mode 100644 index 9a8c6df76..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java +++ /dev/null @@ -1,55 +0,0 @@ -package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -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.bo.UserBrokerageSummaryBO; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; - -import java.time.LocalDateTime; -import java.util.List; - -/** - * 佣金记录 Mapper - * - * @author owen - */ -@Mapper -public interface TradeBrokerageRecordMapper extends BaseMapperX { - - default PageResult selectPage(TradeBrokerageRecordPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(TradeBrokerageRecordDO::getUserId, reqVO.getUserId()) - .eqIfPresent(TradeBrokerageRecordDO::getBizType, reqVO.getBizType()) - .eqIfPresent(TradeBrokerageRecordDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(TradeBrokerageRecordDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(TradeBrokerageRecordDO::getId)); - } - - default List selectListByStatusAndUnfreezeTimeLt(Integer status, LocalDateTime unfreezeTime) { - return selectList(new LambdaQueryWrapper() - .eq(TradeBrokerageRecordDO::getStatus, status) - .lt(TradeBrokerageRecordDO::getUnfreezeTime, unfreezeTime)); - } - - default int updateByIdAndStatus(Integer id, Integer status, TradeBrokerageRecordDO updateObj) { - return update(updateObj, new LambdaQueryWrapper() - .eq(TradeBrokerageRecordDO::getId, id) - .eq(TradeBrokerageRecordDO::getStatus, status)); - } - - default TradeBrokerageRecordDO selectByBizTypeAndBizId(Integer bizType, String bizId) { - return selectOne(TradeBrokerageRecordDO::getBizType, bizType, - TradeBrokerageRecordDO::getBizId, bizId); - } - - @Select("select count(1), sum(price) from trade_brokerage_record where user_id = #{userId} and biz_type = #{bizType} and status = #{status}") - UserBrokerageSummaryBO selectCountAndSumPriceByUserIdAndBizTypeAndStatus(@Param("userId") Long userId, - @Param("bizType") Integer bizType, - @Param("status") Integer status); -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/TradeBrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java similarity index 65% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/TradeBrokerageUserMapper.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java index de163eb59..d5cc39523 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/TradeBrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java @@ -4,8 +4,8 @@ import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.pojo.PageResult; 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.user.vo.TradeBrokerageUserPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; @@ -15,14 +15,14 @@ import org.apache.ibatis.annotations.Mapper; * @author owen */ @Mapper -public interface TradeBrokerageUserMapper extends BaseMapperX { +public interface BrokerageUserMapper extends BaseMapperX { - default PageResult selectPage(TradeBrokerageUserPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(TradeBrokerageUserDO::getBrokerageUserId, reqVO.getBrokerageUserId()) - .eqIfPresent(TradeBrokerageUserDO::getBrokerageEnabled, reqVO.getBrokerageEnabled()) - .betweenIfPresent(TradeBrokerageUserDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(TradeBrokerageUserDO::getId)); + default PageResult selectPage(BrokerageUserPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(BrokerageUserDO::getBrokerageUserId, reqVO.getBrokerageUserId()) + .eqIfPresent(BrokerageUserDO::getBrokerageEnabled, reqVO.getBrokerageEnabled()) + .betweenIfPresent(BrokerageUserDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(BrokerageUserDO::getId)); } /** @@ -33,9 +33,9 @@ public interface TradeBrokerageUserMapper extends BaseMapperX 0); - LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" brokerage_price = brokerage_price + " + incrCount) - .eq(TradeBrokerageUserDO::getId, id); + .eq(BrokerageUserDO::getId, id); update(null, lambdaUpdateWrapper); } @@ -48,9 +48,9 @@ public interface TradeBrokerageUserMapper extends BaseMapperX lambdaUpdateWrapper = new LambdaUpdateWrapper() + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" brokerage_price = brokerage_price + " + incrCount) // 负数,所以使用 + 号 - .eq(TradeBrokerageUserDO::getId, id); + .eq(BrokerageUserDO::getId, id); update(null, lambdaUpdateWrapper); } @@ -62,9 +62,9 @@ public interface TradeBrokerageUserMapper extends BaseMapperX 0); - LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) - .eq(TradeBrokerageUserDO::getId, id); + .eq(BrokerageUserDO::getId, id); update(null, lambdaUpdateWrapper); } @@ -77,9 +77,9 @@ public interface TradeBrokerageUserMapper extends BaseMapperX lambdaUpdateWrapper = new LambdaUpdateWrapper() + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) // 负数,所以使用 + 号 - .eq(TradeBrokerageUserDO::getId, id); + .eq(BrokerageUserDO::getId, id); update(null, lambdaUpdateWrapper); } @@ -92,11 +92,11 @@ public interface TradeBrokerageUserMapper extends BaseMapperX lambdaUpdateWrapper = new LambdaUpdateWrapper() + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount + // 负数,所以使用 + 号 ", brokerage_price = brokerage_price + " + -incrCount) // 负数,所以使用 - 号 - .eq(TradeBrokerageUserDO::getId, id) - .ge(TradeBrokerageUserDO::getFrozenBrokeragePrice, -incrCount); // cas 逻辑 + .eq(BrokerageUserDO::getId, id) + .ge(BrokerageUserDO::getFrozenBrokeragePrice, -incrCount); // cas 逻辑 return update(null, lambdaUpdateWrapper); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/TradeBrokerageRecordUnfreezeJob.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/BrokerageRecordUnfreezeJob.java similarity index 63% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/TradeBrokerageRecordUnfreezeJob.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/BrokerageRecordUnfreezeJob.java index 94218d47e..c221408e5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/TradeBrokerageRecordUnfreezeJob.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/BrokerageRecordUnfreezeJob.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.trade.job.brokerage; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; -import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService; import org.springframework.stereotype.Component; import javax.annotation.Resource; @@ -15,14 +15,14 @@ import javax.annotation.Resource; */ @Component @TenantJob -public class TradeBrokerageRecordUnfreezeJob implements JobHandler { +public class BrokerageRecordUnfreezeJob implements JobHandler { @Resource - private TradeBrokerageRecordService tradeBrokerageRecordService; + private BrokerageRecordService brokerageRecordService; @Override public String execute(String param) { - int count = tradeBrokerageRecordService.unfreezeRecord(); + int count = brokerageRecordService.unfreezeRecord(); return StrUtil.format("解冻佣金 {} 个", count); } 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/BrokerageRecordService.java similarity index 86% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java index d02745e3b..f0cadd761 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/BrokerageRecordService.java @@ -1,8 +1,8 @@ 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.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; 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; @@ -14,7 +14,7 @@ import java.util.List; * * @author owen */ -public interface TradeBrokerageRecordService { +public interface BrokerageRecordService { /** * 获得佣金记录 @@ -22,7 +22,7 @@ public interface TradeBrokerageRecordService { * @param id 编号 * @return 佣金记录 */ - TradeBrokerageRecordDO getBrokerageRecord(Integer id); + BrokerageRecordDO getBrokerageRecord(Integer id); /** * 获得佣金记录分页 @@ -30,7 +30,7 @@ public interface TradeBrokerageRecordService { * @param pageReqVO 分页查询 * @return 佣金记录分页 */ - PageResult getBrokerageRecordPage(TradeBrokerageRecordPageReqVO pageReqVO); + PageResult getBrokerageRecordPage(BrokerageRecordPageReqVO pageReqVO); /** * 增加佣金 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/BrokerageRecordServiceImpl.java similarity index 72% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java index ad1a5c8ff..ae9f1ff88 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/BrokerageRecordServiceImpl.java @@ -6,17 +6,17 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.convert.brokerage.record.TradeBrokerageRecordConvert; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.convert.brokerage.record.BrokerageRecordConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; 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.dal.mysql.brokerage.record.BrokerageRecordMapper; 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.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.brokerage.user.BrokerageUserService; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -37,23 +37,23 @@ import java.util.function.Function; @Slf4j @Service @Validated -public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordService { +public class BrokerageRecordServiceImpl implements BrokerageRecordService { @Resource - private TradeBrokerageRecordMapper tradeBrokerageRecordMapper; + private BrokerageRecordMapper brokerageRecordMapper; @Resource private TradeConfigService tradeConfigService; @Resource - private TradeBrokerageUserService tradeBrokerageUserService; + private BrokerageUserService brokerageUserService; @Override - public TradeBrokerageRecordDO getBrokerageRecord(Integer id) { - return tradeBrokerageRecordMapper.selectById(id); + public BrokerageRecordDO getBrokerageRecord(Integer id) { + return brokerageRecordMapper.selectById(id); } @Override - public PageResult getBrokerageRecordPage(TradeBrokerageRecordPageReqVO pageReqVO) { - return tradeBrokerageRecordMapper.selectPage(pageReqVO); + public PageResult getBrokerageRecordPage(BrokerageRecordPageReqVO pageReqVO) { + return brokerageRecordMapper.selectPage(pageReqVO); } @Override @@ -67,7 +67,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ } // 1.1 获得一级推广人 - TradeBrokerageUserDO firstUser = tradeBrokerageUserService.getBindBrokerageUser(userId); + BrokerageUserDO firstUser = brokerageUserService.getBindBrokerageUser(userId); if (firstUser == null || !BooleanUtil.isTrue(firstUser.getBrokerageEnabled())) { return; } @@ -78,7 +78,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ if (firstUser.getBrokerageUserId() == null) { return; } - TradeBrokerageUserDO secondUser = tradeBrokerageUserService.getBrokerageUser(firstUser.getBrokerageUserId()); + BrokerageUserDO secondUser = brokerageUserService.getBrokerageUser(firstUser.getBrokerageUserId()); if (secondUser == null || !BooleanUtil.isTrue(secondUser.getBrokerageEnabled())) { return; } @@ -89,15 +89,15 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ @Override @Transactional(rollbackFor = Exception.class) public void cancelBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId) { - TradeBrokerageRecordDO record = tradeBrokerageRecordMapper.selectByBizTypeAndBizId(bizType.getType(), bizId); + BrokerageRecordDO record = brokerageRecordMapper.selectByBizTypeAndBizId(bizType.getType(), bizId); if (record == null || ObjectUtil.notEqual(record.getUserId(), userId)) { log.error("[cancelBrokerage][userId({})][bizId({}) 更新为已失效失败:记录不存在]", userId, bizId); return; } // 1. 更新佣金记录为已失效 - TradeBrokerageRecordDO updateObj = new TradeBrokerageRecordDO().setStatus(BrokerageRecordStatusEnum.CANCEL.getStatus()); - int updateRows = tradeBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); + BrokerageRecordDO updateObj = new BrokerageRecordDO().setStatus(BrokerageRecordStatusEnum.CANCEL.getStatus()); + int updateRows = brokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); if (updateRows == 0) { log.error("[cancelBrokerage][record({}) 更新为已失效失败]", record.getId()); return; @@ -105,9 +105,9 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ // 2. 更新用户的佣金 if (BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus().equals(record.getStatus())) { - tradeBrokerageUserService.updateUserFrozenBrokeragePrice(userId, -record.getPrice()); + brokerageUserService.updateUserFrozenBrokeragePrice(userId, -record.getPrice()); } else if (BrokerageRecordStatusEnum.SETTLEMENT.getStatus().equals(record.getStatus())) { - tradeBrokerageUserService.updateUserBrokeragePrice(userId, -record.getPrice()); + brokerageUserService.updateUserBrokeragePrice(userId, -record.getPrice()); } } @@ -141,7 +141,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ * @param FixedBrokeragePriceFun 固定佣金 * @param bizType 业务类型 */ - private void addBrokerage(TradeBrokerageUserDO user, List list, Integer brokerageFrozenDays, + private void addBrokerage(BrokerageUserDO user, List list, Integer brokerageFrozenDays, Integer brokeragePercent, Function FixedBrokeragePriceFun, BrokerageRecordBizTypeEnum bizType) { // 1.1 处理冻结时间 @@ -151,13 +151,13 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ } // 1.2 计算分佣 int totalBrokerage = 0; - List records = new ArrayList<>(); + List records = new ArrayList<>(); for (BrokerageAddReqBO item : list) { int brokeragePerItem = calculateBrokeragePrice(item.getBasePrice(), brokeragePercent, FixedBrokeragePriceFun.apply(item)); if (brokeragePerItem <= 0) { continue; } - records.add(TradeBrokerageRecordConvert.INSTANCE.convert(user, bizType, item.getBizId(), + records.add(BrokerageRecordConvert.INSTANCE.convert(user, bizType, item.getBizId(), brokerageFrozenDays, brokeragePerItem, unfreezeTime, bizType.getTitle())); totalBrokerage += brokeragePerItem; } @@ -165,20 +165,20 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ return; } // 1.3 保存佣金记录 - tradeBrokerageRecordMapper.insertBatch(records); + brokerageRecordMapper.insertBatch(records); // 2. 更新用户佣金 if (brokerageFrozenDays != null && brokerageFrozenDays > 0) { // 更新用户冻结佣金 - tradeBrokerageUserService.updateUserFrozenBrokeragePrice(user.getId(), totalBrokerage); + brokerageUserService.updateUserFrozenBrokeragePrice(user.getId(), totalBrokerage); } else { // 更新用户可用佣金 - tradeBrokerageUserService.updateUserBrokeragePrice(user.getId(), totalBrokerage); + brokerageUserService.updateUserBrokeragePrice(user.getId(), totalBrokerage); } } @Override public int unfreezeRecord() { // 1. 查询待结算的佣金记录 - List records = tradeBrokerageRecordMapper.selectListByStatusAndUnfreezeTimeLt( + List records = brokerageRecordMapper.selectListByStatusAndUnfreezeTimeLt( BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus(), LocalDateTime.now()); if (CollUtil.isEmpty(records)) { return 0; @@ -186,7 +186,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ // 2. 遍历执行 int count = 0; - for (TradeBrokerageRecordDO record : records) { + for (BrokerageRecordDO record : records) { try { boolean success = getSelf().unfreezeRecord(record); if (success) { @@ -201,24 +201,24 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ @Override public UserBrokerageSummaryBO summaryByUserIdAndBizTypeAndStatus(Long userId, Integer bizType, Integer status) { - UserBrokerageSummaryBO summaryBO = tradeBrokerageRecordMapper.selectCountAndSumPriceByUserIdAndBizTypeAndStatus(userId, bizType, status); + UserBrokerageSummaryBO summaryBO = brokerageRecordMapper.selectCountAndSumPriceByUserIdAndBizTypeAndStatus(userId, bizType, status); return summaryBO == null ? new UserBrokerageSummaryBO(0, 0) : summaryBO; } @Transactional(rollbackFor = Exception.class) - public boolean unfreezeRecord(TradeBrokerageRecordDO record) { + public boolean unfreezeRecord(BrokerageRecordDO record) { // 更新记录状态 - TradeBrokerageRecordDO updateObj = new TradeBrokerageRecordDO() + BrokerageRecordDO updateObj = new BrokerageRecordDO() .setStatus(BrokerageRecordStatusEnum.SETTLEMENT.getStatus()) .setUnfreezeTime(LocalDateTime.now()); - int updateRows = tradeBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); + int updateRows = brokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); if (updateRows == 0) { log.error("[unfreezeRecord][record({}) 更新为已结算失败]", record.getId()); return false; } // 更新用户冻结佣金 - tradeBrokerageUserService.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(record.getUserId(), -record.getPrice()); + brokerageUserService.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(record.getUserId(), -record.getPrice()); log.info("[unfreezeRecord][record({}) 更新为已结算成功]", record.getId()); return true; } @@ -228,7 +228,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ * * @return 自己 */ - private TradeBrokerageRecordServiceImpl getSelf() { + private BrokerageRecordServiceImpl getSelf() { return SpringUtil.getBean(getClass()); } 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/BrokerageUserService.java similarity index 78% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java index c62fc1947..d1ed8865c 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/BrokerageUserService.java @@ -1,19 +1,18 @@ package cn.iocoder.yudao.module.trade.service.brokerage.user; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; import java.util.Collection; import java.util.List; -// TODO @疯狂:要不去掉 Trade 前缀哈;交易这块,我准备除了 tradeorder 保持下,类似 aftersale,都要取消前缀了;tradeorder 保持的原因,是避免 payorder 和它重复 /** * 分销用户 Service 接口 * * @author owen */ -public interface TradeBrokerageUserService { +public interface BrokerageUserService { /** * 获得分销用户 @@ -21,7 +20,7 @@ public interface TradeBrokerageUserService { * @param id 编号 * @return 分销用户 */ - TradeBrokerageUserDO getBrokerageUser(Long id); + BrokerageUserDO getBrokerageUser(Long id); /** * 获得分销用户列表 @@ -29,7 +28,7 @@ public interface TradeBrokerageUserService { * @param ids 编号 * @return 分销用户列表 */ - List getBrokerageUserList(Collection ids); + List getBrokerageUserList(Collection ids); /** * 获得分销用户分页 @@ -37,7 +36,7 @@ public interface TradeBrokerageUserService { * @param pageReqVO 分页查询 * @return 分销用户分页 */ - PageResult getBrokerageUserPage(TradeBrokerageUserPageReqVO pageReqVO); + PageResult getBrokerageUserPage(BrokerageUserPageReqVO pageReqVO); /** * 修改推广员编号 @@ -61,7 +60,7 @@ public interface TradeBrokerageUserService { * @param id 用户编号 * @return 用户的推广人 */ - TradeBrokerageUserDO getBindBrokerageUser(Long id); + BrokerageUserDO getBindBrokerageUser(Long id); /** * 更新用户佣金 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/BrokerageUserServiceImpl.java similarity index 80% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java index 6851e522c..8f840bb7d 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/BrokerageUserServiceImpl.java @@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.trade.service.brokerage.user; import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.TradeBrokerageUserMapper; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.BrokerageUserMapper; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -24,23 +24,23 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.USER_FROZEN */ @Service @Validated -public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService { +public class BrokerageUserServiceImpl implements BrokerageUserService { @Resource - private TradeBrokerageUserMapper brokerageUserMapper; + private BrokerageUserMapper brokerageUserMapper; @Override - public TradeBrokerageUserDO getBrokerageUser(Long id) { + public BrokerageUserDO getBrokerageUser(Long id) { return brokerageUserMapper.selectById(id); } @Override - public List getBrokerageUserList(Collection ids) { + public List getBrokerageUserList(Collection ids) { return brokerageUserMapper.selectBatchIds(ids); } @Override - public PageResult getBrokerageUserPage(TradeBrokerageUserPageReqVO pageReqVO) { + public PageResult getBrokerageUserPage(BrokerageUserPageReqVO pageReqVO) { return brokerageUserMapper.selectPage(pageReqVO); } @@ -65,10 +65,10 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService } @Override - public TradeBrokerageUserDO getBindBrokerageUser(Long id) { + public BrokerageUserDO getBindBrokerageUser(Long id) { return Optional.ofNullable(id) .map(this::getBrokerageUser) - .map(TradeBrokerageUserDO::getBrokerageUserId) + .map(BrokerageUserDO::getBrokerageUserId) .map(this::getBrokerageUser) .orElse(null); } @@ -102,7 +102,7 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService @Override public Long getCountByBrokerageUserId(Long brokerageUserId) { - return brokerageUserMapper.selectCount(TradeBrokerageUserDO::getBrokerageUserId, brokerageUserId); + return brokerageUserMapper.selectCount(BrokerageUserDO::getBrokerageUserId, brokerageUserId); } } 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 199cfcbfd..1cda4b3a5 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 @@ -51,7 +51,7 @@ 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.record.BrokerageRecordService; 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; @@ -121,7 +121,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Resource private MemberPointApi memberPointApi; @Resource - private TradeBrokerageRecordService tradeBrokerageRecordService; + private BrokerageRecordService brokerageRecordService; @Resource private ProductCommentApi productCommentApi; @@ -755,12 +755,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { List orderItems = tradeOrderItemMapper.selectListByOrderId(orderId); List list = convertList(orderItems, item -> TradeOrderConvert.INSTANCE.convert(item, productSkuApi.getSku(item.getSkuId()))); - tradeBrokerageRecordService.addBrokerage(userId, bizType, list); + brokerageRecordService.addBrokerage(userId, bizType, list); } @Async protected void cancelBrokerageAsync(Long userId, BrokerageRecordBizTypeEnum bizType, Long orderItemId) { - tradeBrokerageRecordService.cancelBrokerage(userId, bizType, String.valueOf(orderItemId)); + brokerageRecordService.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/BrokerageRecordServiceImplTest.java similarity index 67% rename from yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java rename to yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImplTest.java index eb51279d5..00ff04d6d 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/BrokerageRecordServiceImplTest.java @@ -3,10 +3,10 @@ package cn.iocoder.yudao.module.trade.service.brokerage.record; import cn.hutool.core.util.NumberUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -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.dal.mysql.brokerage.record.TradeBrokerageRecordMapper; -import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.BrokerageRecordMapper; +import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -27,51 +27,51 @@ import static org.junit.jupiter.api.Assertions.assertEquals; // TODO @芋艿:单测后续看看 /** - * {@link TradeBrokerageRecordServiceImpl} 的单元测试类 + * {@link BrokerageRecordServiceImpl} 的单元测试类 * * @author owen */ -@Import(TradeBrokerageRecordServiceImpl.class) -public class TradeBrokerageRecordServiceImplTest extends BaseDbUnitTest { +@Import(BrokerageRecordServiceImpl.class) +public class BrokerageRecordServiceImplTest extends BaseDbUnitTest { @Resource - private TradeBrokerageRecordServiceImpl tradeBrokerageRecordService; + private BrokerageRecordServiceImpl brokerageRecordService; @Resource - private TradeBrokerageRecordMapper tradeBrokerageRecordMapper; + private BrokerageRecordMapper brokerageRecordMapper; @MockBean private TradeConfigService tradeConfigService; @MockBean - private TradeBrokerageUserService tradeBrokerageUserService; + private BrokerageUserService brokerageUserService; @Test @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 public void testGetBrokerageRecordPage() { // mock 数据 - TradeBrokerageRecordDO dbBrokerageRecord = randomPojo(TradeBrokerageRecordDO.class, o -> { // 等会查询到 + BrokerageRecordDO dbBrokerageRecord = randomPojo(BrokerageRecordDO.class, o -> { // 等会查询到 o.setUserId(null); o.setBizType(null); o.setStatus(null); o.setCreateTime(null); }); - tradeBrokerageRecordMapper.insert(dbBrokerageRecord); + brokerageRecordMapper.insert(dbBrokerageRecord); // 测试 userId 不匹配 - tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setUserId(null))); + brokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setUserId(null))); // 测试 bizType 不匹配 - tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setBizType(null))); + brokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setBizType(null))); // 测试 status 不匹配 - tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setStatus(null))); + brokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setStatus(null))); // 测试 createTime 不匹配 - tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setCreateTime(null))); + brokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setCreateTime(null))); // 准备参数 - TradeBrokerageRecordPageReqVO reqVO = new TradeBrokerageRecordPageReqVO(); + BrokerageRecordPageReqVO reqVO = new BrokerageRecordPageReqVO(); reqVO.setUserId(null); reqVO.setBizType(null); reqVO.setStatus(null); reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); // 调用 - PageResult pageResult = tradeBrokerageRecordService.getBrokerageRecordPage(reqVO); + PageResult pageResult = brokerageRecordService.getBrokerageRecordPage(reqVO); // 断言 assertEquals(1, pageResult.getTotal()); assertEquals(1, pageResult.getList().size()); @@ -85,7 +85,7 @@ public class TradeBrokerageRecordServiceImplTest extends BaseDbUnitTest { Integer percent = randomInt(1, 101); Integer fixedBrokeragePrice = randomInt(); // 调用 - int brokerage = tradeBrokerageRecordService.calculateBrokeragePrice(payPrice, percent, fixedBrokeragePrice); + int brokerage = brokerageRecordService.calculateBrokeragePrice(payPrice, percent, fixedBrokeragePrice); // 断言 assertEquals(brokerage, fixedBrokeragePrice); } @@ -98,7 +98,7 @@ public class TradeBrokerageRecordServiceImplTest extends BaseDbUnitTest { Integer skuBrokeragePrice = randomEle(new Integer[]{0, null}); System.out.println("skuBrokeragePrice=" + skuBrokeragePrice); // 调用 - int brokerage = tradeBrokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); + int brokerage = brokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); // 断言 assertEquals(brokerage, NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue()); } @@ -110,7 +110,7 @@ public class TradeBrokerageRecordServiceImplTest extends BaseDbUnitTest { Integer percent = null; Integer skuBrokeragePrice = null; // 调用 - int brokerage = tradeBrokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); + int brokerage = brokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); // 断言 assertEquals(brokerage, 0); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java similarity index 74% rename from yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java rename to yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java index 153bbb426..6950f84e4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java @@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.trade.service.brokerage.user; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.TradeBrokerageUserMapper; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.BrokerageUserMapper; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Import; @@ -19,24 +19,24 @@ import static org.junit.jupiter.api.Assertions.assertEquals; // TODO @芋艿:单测后续看看 /** - * {@link TradeBrokerageUserServiceImpl} 的单元测试类 + * {@link BrokerageUserServiceImpl} 的单元测试类 * * @author owen */ -@Import(TradeBrokerageUserServiceImpl.class) -public class TradeBrokerageUserServiceImplTest extends BaseDbUnitTest { +@Import(BrokerageUserServiceImpl.class) +public class BrokerageUserServiceImplTest extends BaseDbUnitTest { @Resource - private TradeBrokerageUserServiceImpl brokerageUserService; + private BrokerageUserServiceImpl brokerageUserService; @Resource - private TradeBrokerageUserMapper brokerageUserMapper; + private BrokerageUserMapper brokerageUserMapper; @Test @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 public void testGetBrokerageUserPage() { // mock 数据 - TradeBrokerageUserDO dbBrokerageUser = randomPojo(TradeBrokerageUserDO.class, o -> { // 等会查询到 + BrokerageUserDO dbBrokerageUser = randomPojo(BrokerageUserDO.class, o -> { // 等会查询到 o.setBrokerageUserId(null); o.setBrokerageEnabled(null); o.setCreateTime(null); @@ -49,13 +49,13 @@ public class TradeBrokerageUserServiceImplTest extends BaseDbUnitTest { // 测试 createTime 不匹配 brokerageUserMapper.insert(cloneIgnoreId(dbBrokerageUser, o -> o.setCreateTime(null))); // 准备参数 - TradeBrokerageUserPageReqVO reqVO = new TradeBrokerageUserPageReqVO(); + BrokerageUserPageReqVO reqVO = new BrokerageUserPageReqVO(); reqVO.setBrokerageUserId(null); reqVO.setBrokerageEnabled(null); reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); // 调用 - PageResult pageResult = brokerageUserService.getBrokerageUserPage(reqVO); + PageResult pageResult = brokerageUserService.getBrokerageUserPage(reqVO); // 断言 assertEquals(1, pageResult.getTotal()); assertEquals(1, pageResult.getList().size()); From b85d660a5cc375bccb9c200fd0ac4a813c62c00d Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 22:33:44 +0800 Subject: [PATCH 05/12] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E5=AE=8C=E5=96=84=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../record/AppBrokerageRecordPageReqVO.java | 7 ++- .../AppBrokerageWithdrawCreateReqVO.java | 59 +++++++++++++++++-- .../brokerage/bo/BrokerageAddReqBO.java | 7 ++- .../record/BrokerageRecordService.java | 3 +- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java index b7675e6ec..e2df6dae6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java @@ -1,6 +1,9 @@ package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record; import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -8,12 +11,12 @@ import lombok.Data; @Data public class AppBrokerageRecordPageReqVO extends PageParam { - // TODO @疯狂:要加下枚举校验 - @Schema(description = "业务类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @InEnum(value = BrokerageRecordBizTypeEnum.class, message = "业务类型必须是 {value}") private Integer bizType; @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @InEnum(value = BrokerageRecordStatusEnum.class, message = "状态必须是 {value}") private Integer status; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java index 75aec997b..752818130 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java @@ -1,29 +1,76 @@ package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw; +import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawTypeEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import org.hibernate.validator.constraints.URL; +import javax.validation.Validator; import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; @Schema(description = "用户 App - 分销提现创建 Request VO") @Data public class AppBrokerageWithdrawCreateReqVO { - // TODO @疯狂:参数校验逻辑,需要根据 type 进行不同的校验;感觉可以通过分组? - @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @InEnum(value = BrokerageWithdrawTypeEnum.class, message = "提现方式必须是 {value}") private Integer type; - @Schema(description = "提现账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456789") // 银行卡号/微信账号/支付宝账号 + @Schema(description = "提现金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") + @Min(value = 1, message = "提现金额不能小于 1") + private Integer price; + + + // ========== 银行卡、微信、支付宝 提现相关字段 ========== + + @Schema(description = "提现账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456789") + @NotBlank(message = "提现账号不能为空", groups = {Bank.class, Wechat.class, Alipay.class}) private String accountNo; + + // ========== 微信、支付宝 提现相关字段 ========== + @Schema(description = "收款码的图片", example = "https://www.iocoder.cn/1.png") @URL(message = "收款码的图片,必须是一个 URL") private String accountQrCodeUrl; - @Schema(description = "提现金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") - @Min(value = 1, message = "提现金额必须大于 1") - private Integer price; + + // ========== 银行卡 提现相关字段 ========== + + @Schema(description = "持卡人姓名", example = "张三") + @NotBlank(message = "持卡人姓名不能为空", groups = {Bank.class}) + private String name; + @Schema(description = "提现银行", example = "1") + @NotBlank(message = "提现银行不能为空", groups = {Bank.class}) + private Integer bankName; + @Schema(description = "开户地址", example = "海淀支行") + private String bankAddress; + + public interface Wallet { + } + + public interface Bank { + } + + public interface Wechat { + } + + public interface Alipay { + } + + public void validate(Validator validator) { + if (BrokerageWithdrawTypeEnum.WALLET.getType().equals(type)) { + ValidationUtils.validate(validator, this, Wallet.class); + } else if (BrokerageWithdrawTypeEnum.BANK.getType().equals(type)) { + ValidationUtils.validate(validator, this, Bank.class); + } else if (BrokerageWithdrawTypeEnum.WECHAT.getType().equals(type)) { + ValidationUtils.validate(validator, this, Wechat.class); + } else if (BrokerageWithdrawTypeEnum.ALIPAY.getType().equals(type)) { + ValidationUtils.validate(validator, this, Alipay.class); + } + } } 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 index 7e17d9bda..510960beb 100644 --- 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 @@ -4,6 +4,8 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import javax.validation.constraints.NotBlank; + /** * 佣金 增加 Request BO * @@ -14,11 +16,10 @@ import lombok.NoArgsConstructor; @AllArgsConstructor public class BrokerageAddReqBO { - // TODO @疯狂:bo 的话,也可以考虑加下 @Validated 注解,校验下参数;防御性下哈,虽然不一定用的到 - /** - * 业务ID + * 业务编号 */ + @NotBlank(message = "业务编号不能为空") private String bizId; /** * 佣金基数 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java index f0cadd761..64e5fe52f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java @@ -7,6 +7,7 @@ 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 javax.validation.Valid; import java.util.List; /** @@ -39,7 +40,7 @@ public interface BrokerageRecordService { * @param bizType 业务类型 * @param list 请求参数列表 */ - void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, List list); + void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, @Valid List list); /** * 取消佣金:将佣金记录,状态修改为已失效 From f36a6c5d6ca554962315d625df29fb0a6619aad5 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 22:40:49 +0800 Subject: [PATCH 06/12] =?UTF-8?q?trade:=20=E4=BC=98=E5=8C=96=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=8E=A8=E5=B9=BF=E5=91=98=E6=8E=A5=E5=8F=A3=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/brokerage/user/BrokerageUserController.java | 2 +- .../user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java | 4 +--- .../trade/service/brokerage/user/BrokerageUserService.java | 6 +++--- .../service/brokerage/user/BrokerageUserServiceImpl.java | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java index b6c9a1c84..1e1ad3acd 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java @@ -62,7 +62,7 @@ public class BrokerageUserController { @Operation(summary = "修改推广资格") @PreAuthorize("@ss.hasPermission('trade:brokerage-user:update-brokerage-enable')") public CommonResult updateBrokerageEnabled(@Valid @RequestBody BrokerageUserUpdateBrokerageEnabledReqVO updateReqVO) { - brokerageUserService.updateBrokerageEnabled(updateReqVO.getId(), updateReqVO.getBrokerageEnabled()); + brokerageUserService.updateBrokerageEnabled(updateReqVO.getId(), updateReqVO.getEnabled()); return success(true); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java index 5e6d920be..92001e698 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java @@ -15,10 +15,8 @@ public class BrokerageUserUpdateBrokerageEnabledReqVO { @NotNull(message = "用户编号不能为空") private Long id; - // TODO @疯狂:是不是这个字段,可以改成 enabled - @Schema(description = "推广资格", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "推广资格不能为空") - private Boolean brokerageEnabled; + private Boolean enabled; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java index d1ed8865c..362743b65 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java @@ -49,10 +49,10 @@ public interface BrokerageUserService { /** * 修改推广资格 * - * @param id 用户编号 - * @param brokerageEnabled 推广资格 + * @param id 用户编号 + * @param enabled 推广资格 */ - void updateBrokerageEnabled(Long id, Boolean brokerageEnabled); + void updateBrokerageEnabled(Long id, Boolean enabled); /** * 获得用户的推广人 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java index 8f840bb7d..3a4fb475f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java @@ -52,7 +52,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } @Override - public void updateBrokerageEnabled(Long id, Boolean brokerageEnabled) { + public void updateBrokerageEnabled(Long id, Boolean enabled) { // 校验存在 validateBrokerageUserExists(id); // TODO @疯狂:貌似没实现完 From 4b43304c765190a0cae4fc6285e3ec5b69abb8c3 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 22:51:05 +0800 Subject: [PATCH 07/12] =?UTF-8?q?trade:=20=E4=BC=98=E5=8C=96=E5=88=86?= =?UTF-8?q?=E9=94=80=E7=94=A8=E6=88=B7=E7=BB=91=E5=AE=9A=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=BC=96=E5=8F=B7=E3=80=81=E7=BB=91=E5=AE=9A=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/brokerage.sql | 6 +++--- .../admin/brokerage/user/BrokerageUserController.java | 2 +- .../admin/brokerage/user/vo/BrokerageUserBaseVO.java | 4 ++-- .../admin/brokerage/user/vo/BrokerageUserPageReqVO.java | 2 +- .../dal/dataobject/brokerage/user/BrokerageUserDO.java | 9 +++++---- .../dal/mysql/brokerage/user/BrokerageUserMapper.java | 2 +- .../brokerage/record/BrokerageRecordServiceImpl.java | 4 ++-- .../service/brokerage/user/BrokerageUserService.java | 4 ++-- .../service/brokerage/user/BrokerageUserServiceImpl.java | 6 +++--- .../brokerage/user/BrokerageUserServiceImplTest.java | 6 +++--- .../src/test/resources/sql/create_tables.sql | 4 ++-- 11 files changed, 25 insertions(+), 24 deletions(-) diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index 53b9dc04e..08b05da14 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -24,8 +24,8 @@ create table trade_config create table trade_brokerage_user ( id bigint auto_increment comment '用户编号' primary key, - brokerage_user_id bigint null comment '推广员编号', - brokerage_bind_time datetime null comment '推广员绑定时间', + bind_user_id bigint null comment '推广员编号', + bind_user_time datetime null comment '推广员绑定时间', brokerage_enabled bit default 1 not null comment '是否成为推广员', brokerage_time datetime null comment '成为分销员时间', brokerage_price int default 0 not null comment '可用佣金', @@ -38,7 +38,7 @@ create table trade_brokerage_user tenant_id bigint default 0 not null comment '租户编号' ) comment '分销用户'; -create index idx_invite_user_id on trade_brokerage_user (brokerage_user_id) comment '推广员编号'; +create index idx_invite_user_id on trade_brokerage_user (bind_user_id) comment '推广员编号'; create index idx_agent on trade_brokerage_user (brokerage_enabled) comment '是否成为推广员'; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java index 1e1ad3acd..0992f52e0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java @@ -94,7 +94,7 @@ public class BrokerageUserController { // 合计推广用户数量 Map brokerageUserCountMap = convertMap(userIds, userId -> userId, - userId -> brokerageUserService.getCountByBrokerageUserId(userId)); + userId -> brokerageUserService.getCountByBindUserId(userId)); // todo 合计提现 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java index 41ddd454c..5da0b5d6b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java @@ -18,11 +18,11 @@ public class BrokerageUserBaseVO { @Schema(description = "推广员编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4587") @NotNull(message = "推广员编号不能为空") - private Long brokerageUserId; + private Long bindUserId; @Schema(description = "推广员绑定时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime brokerageBindTime; + private LocalDateTime bindUserTime; @Schema(description = "推广资格", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "推广资格不能为空") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java index 2b99d686e..e6908e8aa 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java @@ -18,7 +18,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ public class BrokerageUserPageReqVO extends PageParam { @Schema(description = "推广员编号", example = "4587") - private Long brokerageUserId; + private Long bindUserId; @Schema(description = "推广资格") private Boolean brokerageEnabled; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java index 4b85dc3d0..09ad6d72d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java @@ -26,21 +26,22 @@ public class BrokerageUserDO extends BaseDO { /** * 用户编号 + *

+ * 对应 MemberUserDO 的 id 字段 */ @TableId private Long id; - // TODO @疯狂:貌似改成 bindUserId,更明确? /** * 推广员编号 - * + *

* 关联 MemberUserDO 的 id 字段 */ - private Long brokerageUserId; + private Long bindUserId; /** * 推广员绑定时间 */ - private LocalDateTime brokerageBindTime; + private LocalDateTime bindUserTime; /** * 推广资格 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java index d5cc39523..2d536bb88 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java @@ -19,7 +19,7 @@ public interface BrokerageUserMapper extends BaseMapperX { default PageResult selectPage(BrokerageUserPageReqVO reqVO) { return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(BrokerageUserDO::getBrokerageUserId, reqVO.getBrokerageUserId()) + .eqIfPresent(BrokerageUserDO::getBindUserId, reqVO.getBindUserId()) .eqIfPresent(BrokerageUserDO::getBrokerageEnabled, reqVO.getBrokerageEnabled()) .betweenIfPresent(BrokerageUserDO::getCreateTime, reqVO.getCreateTime()) .orderByDesc(BrokerageUserDO::getId)); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java index ae9f1ff88..1a0cf4fe7 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java @@ -75,10 +75,10 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqBO::getFirstBrokeragePrice, bizType); // 2.1 获得二级推广员 - if (firstUser.getBrokerageUserId() == null) { + if (firstUser.getBindUserId() == null) { return; } - BrokerageUserDO secondUser = brokerageUserService.getBrokerageUser(firstUser.getBrokerageUserId()); + BrokerageUserDO secondUser = brokerageUserService.getBrokerageUser(firstUser.getBindUserId()); if (secondUser == null || !BooleanUtil.isTrue(secondUser.getBrokerageEnabled())) { return; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java index 362743b65..5ba7eb4c1 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java @@ -89,8 +89,8 @@ public interface BrokerageUserService { /** * 获得推广用户数量(一级) * - * @param brokerageUserId 推广员编号 + * @param bindUserId 绑定的推广员编号 * @return 推广用户数量 */ - Long getCountByBrokerageUserId(Long brokerageUserId); + Long getCountByBindUserId(Long bindUserId); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java index 3a4fb475f..a09192ed6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java @@ -68,7 +68,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { public BrokerageUserDO getBindBrokerageUser(Long id) { return Optional.ofNullable(id) .map(this::getBrokerageUser) - .map(BrokerageUserDO::getBrokerageUserId) + .map(BrokerageUserDO::getBindUserId) .map(this::getBrokerageUser) .orElse(null); } @@ -101,8 +101,8 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } @Override - public Long getCountByBrokerageUserId(Long brokerageUserId) { - return brokerageUserMapper.selectCount(BrokerageUserDO::getBrokerageUserId, brokerageUserId); + public Long getCountByBindUserId(Long bindUserId) { + return brokerageUserMapper.selectCount(BrokerageUserDO::getBindUserId, bindUserId); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java index 6950f84e4..1c505e1b4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java @@ -37,20 +37,20 @@ public class BrokerageUserServiceImplTest extends BaseDbUnitTest { public void testGetBrokerageUserPage() { // mock 数据 BrokerageUserDO dbBrokerageUser = randomPojo(BrokerageUserDO.class, o -> { // 等会查询到 - o.setBrokerageUserId(null); + o.setBindUserId(null); o.setBrokerageEnabled(null); o.setCreateTime(null); }); brokerageUserMapper.insert(dbBrokerageUser); // 测试 brokerageUserId 不匹配 - brokerageUserMapper.insert(cloneIgnoreId(dbBrokerageUser, o -> o.setBrokerageUserId(null))); + brokerageUserMapper.insert(cloneIgnoreId(dbBrokerageUser, o -> o.setBindUserId(null))); // 测试 brokerageEnabled 不匹配 brokerageUserMapper.insert(cloneIgnoreId(dbBrokerageUser, o -> o.setBrokerageEnabled(null))); // 测试 createTime 不匹配 brokerageUserMapper.insert(cloneIgnoreId(dbBrokerageUser, o -> o.setCreateTime(null))); // 准备参数 BrokerageUserPageReqVO reqVO = new BrokerageUserPageReqVO(); - reqVO.setBrokerageUserId(null); + reqVO.setBindUserId(null); reqVO.setBrokerageEnabled(null); reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql index 02045d2c2..eafad666f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql @@ -129,8 +129,8 @@ CREATE TABLE IF NOT EXISTS "trade_after_sale_log" ( CREATE TABLE IF NOT EXISTS "trade_brokerage_user" ( "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "brokerage_user_id" bigint NOT NULL, - "brokerage_bind_time" varchar, + "bind_user_id" bigint NOT NULL, + "bind_user_time" varchar, "brokerage_enabled" bit NOT NULL, "brokerage_time" varchar, "brokerage_price" int NOT NULL, From 1ead3685958846d86afe620f547932bececdc094 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 23:10:04 +0800 Subject: [PATCH 08/12] =?UTF-8?q?trade:=20=E4=BC=98=E5=8C=96=E5=88=86?= =?UTF-8?q?=E9=94=80=E7=94=A8=E6=88=B7=E4=BD=A3=E9=87=91=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/brokerage.sql | 26 ++++++------ .../trade/enums/ErrorCodeConstants.java | 2 +- .../user/vo/BrokerageUserBaseVO.java | 4 +- .../brokerage/AppBrokerageUserController.java | 24 +++++------ .../AppBrokerageUserChildSummaryRespVO.java | 2 +- .../user/AppBrokerageUserMySummaryRespVO.java | 8 ++-- .../AppBrokerageUserRankByPriceRespVO.java | 2 +- .../vo/user/AppBrokerageUserRespVO.java | 4 +- .../record/BrokerageRecordConvert.java | 2 +- .../convert/order/TradeOrderConvert.java | 4 +- .../brokerage/user/BrokerageUserDO.java | 5 +-- .../brokerage/user/BrokerageUserMapper.java | 24 +++++------ .../brokerage/bo/BrokerageAddReqBO.java | 4 +- .../record/BrokerageRecordServiceImpl.java | 42 +++++++++---------- .../brokerage/user/BrokerageUserService.java | 18 ++++---- .../user/BrokerageUserServiceImpl.java | 30 ++++++------- .../BrokerageRecordServiceImplTest.java | 22 +++++----- .../src/test/resources/sql/create_tables.sql | 26 ++++++------ 18 files changed, 124 insertions(+), 125 deletions(-) diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index 08b05da14..a84d80051 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -23,19 +23,19 @@ create table trade_config -- 增加分销用户扩展表 create table trade_brokerage_user ( - id bigint auto_increment comment '用户编号' primary key, - bind_user_id bigint null comment '推广员编号', - bind_user_time datetime null comment '推广员绑定时间', - brokerage_enabled bit default 1 not null comment '是否成为推广员', - brokerage_time datetime null comment '成为分销员时间', - brokerage_price int default 0 not null comment '可用佣金', - frozen_brokerage_price int default 0 not null comment '冻结佣金', - creator varchar(64) collate utf8mb4_unicode_ci default '' null comment '创建者', - create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', - updater varchar(64) collate utf8mb4_unicode_ci default '' null comment '更新者', - update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', - deleted bit default b'0' not null comment '是否删除', - tenant_id bigint default 0 not null comment '租户编号' + id bigint auto_increment comment '用户编号' primary key, + bind_user_id bigint null comment '推广员编号', + bind_user_time datetime null comment '推广员绑定时间', + brokerage_enabled bit default 1 not null comment '是否成为推广员', + brokerage_time datetime null comment '成为分销员时间', + price int default 0 not null comment '可用佣金', + frozen_price int default 0 not null comment '冻结佣金', + creator varchar(64) collate utf8mb4_unicode_ci default '' null comment '创建者', + create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', + updater varchar(64) collate utf8mb4_unicode_ci default '' null comment '更新者', + update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', + deleted bit default b'0' not null comment '是否删除', + tenant_id bigint default 0 not null comment '租户编号' ) comment '分销用户'; create index idx_invite_user_id on trade_brokerage_user (bind_user_id) comment '推广员编号'; 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 5ddff9b11..fa5be50b7 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,6 +77,6 @@ public interface ErrorCodeConstants { // ========== 分销用户 模块 1011007000 ========== ErrorCode BROKERAGE_USER_NOT_EXISTS = new ErrorCode(1011007000, "分销用户不存在"); - ErrorCode USER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH = new ErrorCode(1011007001, "用户冻结佣金({})数量不足"); + ErrorCode BROKERAGE_USER_FROZEN_PRICE_NOT_ENOUGH = new ErrorCode(1011007001, "用户冻结佣金({})数量不足"); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java index 5da0b5d6b..34f792b72 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java @@ -34,10 +34,10 @@ public class BrokerageUserBaseVO { @Schema(description = "可用佣金", requiredMode = Schema.RequiredMode.REQUIRED, example = "11089") @NotNull(message = "可用佣金不能为空") - private Integer brokeragePrice; + private Integer price; @Schema(description = "冻结佣金", requiredMode = Schema.RequiredMode.REQUIRED, example = "30916") @NotNull(message = "冻结佣金不能为空") - private Integer frozenBrokeragePrice; + private Integer frozenPrice; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index 1b760be05..ecbb7de45 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -34,8 +34,8 @@ public class AppBrokerageUserController { @PreAuthenticated public CommonResult getBrokerageUser() { AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO() - .setBrokeragePrice(2000) - .setFrozenBrokeragePrice(3000); + .setPrice(2000) + .setFrozenPrice(3000); return success(respVO); } @@ -45,10 +45,10 @@ public class AppBrokerageUserController { @PreAuthenticated public CommonResult getBrokerageUserSummary() { AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO() - .setYesterdayBrokeragePrice(1) - .setBrokeragePrice(2) - .setFrozenBrokeragePrice(3) - .setWithdrawBrokeragePrice(4) + .setYesterdayPrice(1) + .setPrice(2) + .setFrozenPrice(3) + .setWithdrawPrice(4) .setFirstBrokerageUserCount(166) .setSecondBrokerageUserCount(233); return success(respVO); @@ -81,16 +81,16 @@ public class AppBrokerageUserController { public CommonResult> getBrokerageUserChildSummaryPageByPrice(AppBrokerageUserRankPageReqVO pageReqVO) { AppBrokerageUserRankByPriceRespVO vo1 = new AppBrokerageUserRankByPriceRespVO() .setId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(10); + .setPrice(10); AppBrokerageUserRankByPriceRespVO vo2 = new AppBrokerageUserRankByPriceRespVO() .setId(2L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(6); + .setPrice(6); AppBrokerageUserRankByPriceRespVO vo3 = new AppBrokerageUserRankByPriceRespVO() .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(4); + .setPrice(4); AppBrokerageUserRankByPriceRespVO vo4 = new AppBrokerageUserRankByPriceRespVO() .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(4); + .setPrice(4); return success(new PageResult<>(asList(vo1, vo2, vo3, vo4), 10L)); } @@ -102,11 +102,11 @@ public class AppBrokerageUserController { AppBrokerageUserChildSummaryPageReqVO pageReqVO) { AppBrokerageUserChildSummaryRespVO vo1 = new AppBrokerageUserChildSummaryRespVO() .setId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(10).setBrokeragePrice(20).setBrokerageOrderCount(30) + .setPrice(10).setPrice(20).setBrokerageOrderCount(30) .setBrokerageTime(LocalDateTime.now()); AppBrokerageUserChildSummaryRespVO vo2 = new AppBrokerageUserChildSummaryRespVO() .setId(1L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(20).setBrokeragePrice(30).setBrokerageOrderCount(40) + .setPrice(20).setPrice(30).setBrokerageOrderCount(40) .setBrokerageTime(LocalDateTime.now()); return success(new PageResult<>(asList(vo1, vo2), 10L)); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java index 1beb1b5e2..55d88d74f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java @@ -19,7 +19,7 @@ public class AppBrokerageUserChildSummaryRespVO { private String avatar; @Schema(description = "佣金金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Integer brokeragePrice; + private Integer price; @Schema(description = "分销订单数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "20") private Integer brokerageOrderCount; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java index 64fafe329..33a089cc6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java @@ -8,16 +8,16 @@ import lombok.Data; public class AppBrokerageUserMySummaryRespVO { @Schema(description = "昨天的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Integer yesterdayBrokeragePrice; + private Integer yesterdayPrice; @Schema(description = "提现的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Integer withdrawBrokeragePrice; + private Integer withdrawPrice; @Schema(description = "可用的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2408") - private Integer brokeragePrice; + private Integer price; @Schema(description = "冻结的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "234") - private Integer frozenBrokeragePrice; + private Integer frozenPrice; @Schema(description = "分销用户数量(一级)", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") private Integer firstBrokerageUserCount; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java index 91345ea78..d80fb67a2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java @@ -17,6 +17,6 @@ public class AppBrokerageUserRankByPriceRespVO { private String avatar; @Schema(description = "佣金金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Integer brokeragePrice; + private Integer price; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java index 04f1a7278..9db6e0cc2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java @@ -8,9 +8,9 @@ import lombok.Data; public class AppBrokerageUserRespVO { @Schema(description = "可用的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2408") - private Integer brokeragePrice; + private Integer price; @Schema(description = "冻结的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "234") - private Integer frozenBrokeragePrice; + private Integer frozenPrice; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java index d619c6926..9307a4f55 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java @@ -43,7 +43,7 @@ public interface BrokerageRecordConvert { .setBizType(bizType.getType()) .setBizId(bizId) .setPrice(brokerage) - .setTotalPrice(user.getBrokeragePrice()) + .setTotalPrice(user.getPrice()) .setTitle(title) .setDescription(StrUtil.format(bizType.getDescription(), String.valueOf(brokerage / 100.0))) .setStatus(status) 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 27854def6..8588fb972 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 @@ -278,7 +278,7 @@ public interface TradeOrderConvert { default BrokerageAddReqBO convert(TradeOrderItemDO item, ProductSkuRespDTO sku) { return new BrokerageAddReqBO().setBizId(String.valueOf(item.getId())) .setBasePrice(item.getPayPrice() * item.getCount()) - .setFirstBrokeragePrice(sku.getSubCommissionFirstPrice()) - .setSecondBrokeragePrice(sku.getSubCommissionSecondPrice()); + .setFirstFixedPrice(sku.getSubCommissionFirstPrice()) + .setSecondFixedPrice(sku.getSubCommissionSecondPrice()); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java index 09ad6d72d..1773e41e7 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java @@ -8,7 +8,6 @@ import lombok.*; import java.time.LocalDateTime; -// TODO @疯狂:因为独立了表,是不是可以把字段的 brokerage 去掉了哈? /** * 分销用户 DO * @@ -55,10 +54,10 @@ public class BrokerageUserDO extends BaseDO { /** * 可用佣金 */ - private Integer brokeragePrice; + private Integer price; /** * 冻结佣金 */ - private Integer frozenBrokeragePrice; + private Integer frozenPrice; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java index 2d536bb88..2f7d1d19c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java @@ -31,10 +31,10 @@ public interface BrokerageUserMapper extends BaseMapperX { * @param id 用户编号 * @param incrCount 增加佣金(正数) */ - default void updateBrokeragePriceIncr(Long id, Integer incrCount) { + default void updatePriceIncr(Long id, Integer incrCount) { Assert.isTrue(incrCount > 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" brokerage_price = brokerage_price + " + incrCount) + .setSql(" price = price + " + incrCount) .eq(BrokerageUserDO::getId, id); update(null, lambdaUpdateWrapper); } @@ -46,10 +46,10 @@ public interface BrokerageUserMapper extends BaseMapperX { * @param id 用户编号 * @param incrCount 增加佣金(负数) */ - default void updateBrokeragePriceDecr(Long id, Integer incrCount) { + default void updatePriceDecr(Long id, Integer incrCount) { Assert.isTrue(incrCount < 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" brokerage_price = brokerage_price + " + incrCount) // 负数,所以使用 + 号 + .setSql(" price = price + " + incrCount) // 负数,所以使用 + 号 .eq(BrokerageUserDO::getId, id); update(null, lambdaUpdateWrapper); } @@ -60,10 +60,10 @@ public interface BrokerageUserMapper extends BaseMapperX { * @param id 用户编号 * @param incrCount 增加冻结佣金(正数) */ - default void updateFrozenBrokeragePriceIncr(Long id, Integer incrCount) { + default void updateFrozenPriceIncr(Long id, Integer incrCount) { Assert.isTrue(incrCount > 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) + .setSql(" frozen_price = frozen_price + " + incrCount) .eq(BrokerageUserDO::getId, id); update(null, lambdaUpdateWrapper); } @@ -75,10 +75,10 @@ public interface BrokerageUserMapper extends BaseMapperX { * @param id 用户编号 * @param incrCount 减少冻结佣金(负数) */ - default void updateFrozenBrokeragePriceDecr(Long id, Integer incrCount) { + default void updateFrozenPriceDecr(Long id, Integer incrCount) { Assert.isTrue(incrCount < 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) // 负数,所以使用 + 号 + .setSql(" frozen_price = frozen_price + " + incrCount) // 负数,所以使用 + 号 .eq(BrokerageUserDO::getId, id); update(null, lambdaUpdateWrapper); } @@ -90,13 +90,13 @@ public interface BrokerageUserMapper extends BaseMapperX { * @param incrCount 减少冻结佣金(负数) * @return 更新条数 */ - default int updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, Integer incrCount) { + default int updateFrozenPriceDecrAndPriceIncr(Long id, Integer incrCount) { Assert.isTrue(incrCount < 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount + // 负数,所以使用 + 号 - ", brokerage_price = brokerage_price + " + -incrCount) // 负数,所以使用 - 号 + .setSql(" frozen_price = frozen_price + " + incrCount + // 负数,所以使用 + 号 + ", price = price + " + -incrCount) // 负数,所以使用 - 号 .eq(BrokerageUserDO::getId, id) - .ge(BrokerageUserDO::getFrozenBrokeragePrice, -incrCount); // cas 逻辑 + .ge(BrokerageUserDO::getFrozenPrice, -incrCount); // cas 逻辑 return update(null, lambdaUpdateWrapper); } 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 index 510960beb..07e07817e 100644 --- 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 @@ -28,10 +28,10 @@ public class BrokerageAddReqBO { /** * 一级佣金(固定) */ - private Integer firstBrokeragePrice; + private Integer firstFixedPrice; /** * 二级佣金(固定) */ - private Integer secondBrokeragePrice; + private Integer secondFixedPrice; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java index 1a0cf4fe7..960b45ae5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java @@ -72,7 +72,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { return; } // 1.2 计算一级分佣 - addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqBO::getFirstBrokeragePrice, bizType); + addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqBO::getFirstFixedPrice, bizType); // 2.1 获得二级推广员 if (firstUser.getBindUserId() == null) { @@ -83,7 +83,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { return; } // 2.2 计算二级分佣 - addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqBO::getSecondBrokeragePrice, bizType); + addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqBO::getSecondFixedPrice, bizType); } @Override @@ -105,24 +105,24 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { // 2. 更新用户的佣金 if (BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus().equals(record.getStatus())) { - brokerageUserService.updateUserFrozenBrokeragePrice(userId, -record.getPrice()); + brokerageUserService.updateUserFrozenPrice(userId, -record.getPrice()); } else if (BrokerageRecordStatusEnum.SETTLEMENT.getStatus().equals(record.getStatus())) { - brokerageUserService.updateUserBrokeragePrice(userId, -record.getPrice()); + brokerageUserService.updateUserPrice(userId, -record.getPrice()); } } /** * 计算佣金 * - * @param basePrice 佣金基数 - * @param percent 佣金比例 - * @param fixedBrokeragePrice 固定佣金 + * @param basePrice 佣金基数 + * @param percent 佣金比例 + * @param fixedPrice 固定佣金 * @return 佣金 */ - int calculateBrokeragePrice(Integer basePrice, Integer percent, Integer fixedBrokeragePrice) { + int calculatePrice(Integer basePrice, Integer percent, Integer fixedPrice) { // 1. 优先使用固定佣金 - if (fixedBrokeragePrice != null && fixedBrokeragePrice > 0) { - return ObjectUtil.defaultIfNull(fixedBrokeragePrice, 0); + if (fixedPrice != null && fixedPrice > 0) { + return ObjectUtil.defaultIfNull(fixedPrice, 0); } // 2. 根据比例计算佣金 if (basePrice != null && basePrice > 0 && percent != null && percent > 0) { @@ -134,15 +134,15 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { /** * 增加用户佣金 * - * @param user 用户 - * @param list 佣金增加参数列表 - * @param brokerageFrozenDays 冻结天数 - * @param brokeragePercent 佣金比例 - * @param FixedBrokeragePriceFun 固定佣金 - * @param bizType 业务类型 + * @param user 用户 + * @param list 佣金增加参数列表 + * @param brokerageFrozenDays 冻结天数 + * @param brokeragePercent 佣金比例 + * @param fixedPriceFun 固定佣金 + * @param bizType 业务类型 */ private void addBrokerage(BrokerageUserDO user, List list, Integer brokerageFrozenDays, - Integer brokeragePercent, Function FixedBrokeragePriceFun, + Integer brokeragePercent, Function fixedPriceFun, BrokerageRecordBizTypeEnum bizType) { // 1.1 处理冻结时间 LocalDateTime unfreezeTime = null; @@ -153,7 +153,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { int totalBrokerage = 0; List records = new ArrayList<>(); for (BrokerageAddReqBO item : list) { - int brokeragePerItem = calculateBrokeragePrice(item.getBasePrice(), brokeragePercent, FixedBrokeragePriceFun.apply(item)); + int brokeragePerItem = calculatePrice(item.getBasePrice(), brokeragePercent, fixedPriceFun.apply(item)); if (brokeragePerItem <= 0) { continue; } @@ -169,9 +169,9 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { // 2. 更新用户佣金 if (brokerageFrozenDays != null && brokerageFrozenDays > 0) { // 更新用户冻结佣金 - brokerageUserService.updateUserFrozenBrokeragePrice(user.getId(), totalBrokerage); + brokerageUserService.updateUserFrozenPrice(user.getId(), totalBrokerage); } else { // 更新用户可用佣金 - brokerageUserService.updateUserBrokeragePrice(user.getId(), totalBrokerage); + brokerageUserService.updateUserPrice(user.getId(), totalBrokerage); } } @@ -218,7 +218,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { } // 更新用户冻结佣金 - brokerageUserService.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(record.getUserId(), -record.getPrice()); + brokerageUserService.updateFrozenPriceDecrAndPriceIncr(record.getUserId(), -record.getPrice()); log.info("[unfreezeRecord][record({}) 更新为已结算成功]", record.getId()); return true; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java index 5ba7eb4c1..c26cfb6e3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java @@ -65,26 +65,26 @@ public interface BrokerageUserService { /** * 更新用户佣金 * - * @param id 用户编号 - * @param brokeragePrice 用户可用佣金 + * @param id 用户编号 + * @param price 用户可用佣金 */ - void updateUserBrokeragePrice(Long id, Integer brokeragePrice); + void updateUserPrice(Long id, Integer price); /** * 更新用户冻结佣金 * - * @param id 用户编号 - * @param frozenBrokeragePrice 用户冻结佣金 + * @param id 用户编号 + * @param frozenPrice 用户冻结佣金 */ - void updateUserFrozenBrokeragePrice(Long id, Integer frozenBrokeragePrice); + void updateUserFrozenPrice(Long id, Integer frozenPrice); /** * 更新用户冻结佣金(减少), 更新用户佣金(增加) * - * @param id 用户编号 - * @param frozenBrokeragePrice 减少冻结佣金(负数) + * @param id 用户编号 + * @param frozenPrice 减少冻结佣金(负数) */ - void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, Integer frozenBrokeragePrice); + void updateFrozenPriceDecrAndPriceIncr(Long id, Integer frozenPrice); /** * 获得推广用户数量(一级) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java index a09192ed6..33f81602d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java @@ -14,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.trade.enums.ErrorCodeConstants.BROKERAGE_USER_FROZEN_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 实现类 @@ -74,29 +74,29 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } @Override - public void updateUserBrokeragePrice(Long id, Integer brokeragePrice) { - if (brokeragePrice > 0) { - brokerageUserMapper.updateBrokeragePriceIncr(id, brokeragePrice); - } else if (brokeragePrice < 0) { - brokerageUserMapper.updateBrokeragePriceDecr(id, brokeragePrice); + public void updateUserPrice(Long id, Integer price) { + if (price > 0) { + brokerageUserMapper.updatePriceIncr(id, price); + } else if (price < 0) { + brokerageUserMapper.updatePriceDecr(id, price); } } @Override - public void updateUserFrozenBrokeragePrice(Long id, Integer frozenBrokeragePrice) { - if (frozenBrokeragePrice > 0) { - brokerageUserMapper.updateFrozenBrokeragePriceIncr(id, frozenBrokeragePrice); - } else if (frozenBrokeragePrice < 0) { - brokerageUserMapper.updateFrozenBrokeragePriceDecr(id, frozenBrokeragePrice); + public void updateUserFrozenPrice(Long id, Integer frozenPrice) { + if (frozenPrice > 0) { + brokerageUserMapper.updateFrozenPriceIncr(id, frozenPrice); + } else if (frozenPrice < 0) { + brokerageUserMapper.updateFrozenPriceDecr(id, frozenPrice); } } @Override - public void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, Integer frozenBrokeragePrice) { - Assert.isTrue(frozenBrokeragePrice < 0); - int updateRows = brokerageUserMapper.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(id, frozenBrokeragePrice); + public void updateFrozenPriceDecrAndPriceIncr(Long id, Integer frozenPrice) { + Assert.isTrue(frozenPrice < 0); + int updateRows = brokerageUserMapper.updateFrozenPriceDecrAndPriceIncr(id, frozenPrice); if (updateRows == 0) { - throw exception(USER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH); + throw exception(BROKERAGE_USER_FROZEN_PRICE_NOT_ENOUGH); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImplTest.java index 00ff04d6d..abf2b37c1 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImplTest.java @@ -79,38 +79,38 @@ public class BrokerageRecordServiceImplTest extends BaseDbUnitTest { } @Test - public void testCalculateBrokeragePrice_useFixedBrokeragePrice() { + public void testCalculatePrice_useFixedPrice() { // mock 数据 Integer payPrice = randomInteger(); Integer percent = randomInt(1, 101); - Integer fixedBrokeragePrice = randomInt(); + Integer fixedPrice = randomInt(); // 调用 - int brokerage = brokerageRecordService.calculateBrokeragePrice(payPrice, percent, fixedBrokeragePrice); + int brokerage = brokerageRecordService.calculatePrice(payPrice, percent, fixedPrice); // 断言 - assertEquals(brokerage, fixedBrokeragePrice); + assertEquals(brokerage, fixedPrice); } @Test - public void testCalculateBrokeragePrice_usePercent() { + public void testCalculatePrice_usePercent() { // mock 数据 Integer payPrice = randomInteger(); Integer percent = randomInt(1, 101); - Integer skuBrokeragePrice = randomEle(new Integer[]{0, null}); - System.out.println("skuBrokeragePrice=" + skuBrokeragePrice); + Integer fixedPrice = randomEle(new Integer[]{0, null}); + System.out.println("fixedPrice=" + fixedPrice); // 调用 - int brokerage = brokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); + int brokerage = brokerageRecordService.calculatePrice(payPrice, percent, fixedPrice); // 断言 assertEquals(brokerage, NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue()); } @Test - public void testCalculateBrokeragePrice_equalsZero() { + public void testCalculatePrice_equalsZero() { // mock 数据 Integer payPrice = null; Integer percent = null; - Integer skuBrokeragePrice = null; + Integer fixedPrice = null; // 调用 - int brokerage = brokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); + int brokerage = brokerageRecordService.calculatePrice(payPrice, percent, fixedPrice); // 断言 assertEquals(brokerage, 0); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql index eafad666f..4c0e0fcea 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql @@ -128,19 +128,19 @@ CREATE TABLE IF NOT EXISTS "trade_after_sale_log" ( CREATE TABLE IF NOT EXISTS "trade_brokerage_user" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "bind_user_id" bigint NOT NULL, - "bind_user_time" varchar, - "brokerage_enabled" bit NOT NULL, - "brokerage_time" varchar, - "brokerage_price" int NOT NULL, - "frozen_brokerage_price" int NOT NULL, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint NOT NULL DEFAULT '0', + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "bind_user_id" bigint NOT NULL, + "bind_user_time" varchar, + "brokerage_enabled" bit NOT NULL, + "brokerage_time" varchar, + "price" int NOT NULL, + "frozen_price" int NOT NULL, + "creator" varchar DEFAULT '', + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar DEFAULT '', + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + "tenant_id" bigint NOT NULL DEFAULT '0', PRIMARY KEY ("id") ) COMMENT '分销用户'; CREATE TABLE IF NOT EXISTS "trade_brokerage_record" From 6ef36d5ca6277d9ad64a824e9af8ec6aefd71a70 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 23:33:02 +0800 Subject: [PATCH 09/12] =?UTF-8?q?trade:=20=E5=A2=9E=E5=8A=A0=E5=88=86?= =?UTF-8?q?=E9=94=80=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/api/brokerage/BrokerageApi.java | 30 +++++++++++ .../api/brokerage/dto/BrokerageUserDTO.java | 51 +++++++++++++++++++ .../trade/api/brokerage/BrokerageApiImpl.java | 33 ++++++++++++ .../brokerage/user/BrokerageUserConvert.java | 3 ++ .../yudao-module-member-biz/pom.xml | 5 ++ .../app/user/AppMemberUserController.java | 9 +++- 6 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java create mode 100644 yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/dto/BrokerageUserDTO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java new file mode 100644 index 000000000..4952e5cad --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.trade.api.brokerage; + +import cn.iocoder.yudao.module.trade.api.brokerage.dto.BrokerageUserDTO; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageBindModeEnum; + +/** + * 分销 API 接口 + * + * @author owen + */ +public interface BrokerageApi { + + /** + * 获得分销用户 + * + * @param userId 用户编号 + * @return 分销用户信息 + */ + BrokerageUserDTO getBrokerageUser(Long userId); + + /** + * 绑定推广员 + * + * @param userId 用户编号 + * @param bindUserId 推广员编号 + * @param bindMode 绑定模式 {@link BrokerageBindModeEnum} + * @return 是否绑定 + */ + boolean bindUser(Long userId, Long bindUserId, Integer bindMode); +} diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/dto/BrokerageUserDTO.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/dto/BrokerageUserDTO.java new file mode 100644 index 000000000..864abe148 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/dto/BrokerageUserDTO.java @@ -0,0 +1,51 @@ +package cn.iocoder.yudao.module.trade.api.brokerage.dto; + +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 分销用户 DTO + * + * @author owen + */ +@Data +public class BrokerageUserDTO { + + /** + * 用户编号 + *

+ * 对应 MemberUserDO 的 id 字段 + */ + private Long id; + + /** + * 推广员编号 + *

+ * 关联 MemberUserDO 的 id 字段 + */ + private Long bindUserId; + /** + * 推广员绑定时间 + */ + private LocalDateTime bindUserTime; + + /** + * 推广资格 + */ + private Boolean brokerageEnabled; + /** + * 成为分销员时间 + */ + private LocalDateTime brokerageTime; + + /** + * 可用佣金 + */ + private Integer price; + /** + * 冻结佣金 + */ + private Integer frozenPrice; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java new file mode 100644 index 000000000..1bb520734 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.trade.api.brokerage; + +import cn.iocoder.yudao.module.trade.api.brokerage.dto.BrokerageUserDTO; +import cn.iocoder.yudao.module.trade.convert.brokerage.user.BrokerageUserConvert; +import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; + +/** + * 分销 API 接口实现类 + * + * @author owen + */ +@Service +@Validated +public class BrokerageApiImpl implements BrokerageApi { + + @Resource + private BrokerageUserService brokerageUserService; + + public BrokerageUserDTO getBrokerageUser(Long userId) { + return BrokerageUserConvert.INSTANCE.convertDTO(brokerageUserService.getBrokerageUser(userId)); + } + + @Override + public boolean bindUser(Long userId, Long bindUserId, Integer bindMode) { + // todo 待实现 + return false; + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java index c4a31cc98..01d0be8c8 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.trade.convert.brokerage.user; import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; +import cn.iocoder.yudao.module.trade.api.brokerage.dto.BrokerageUserDTO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; @@ -58,4 +59,6 @@ public interface BrokerageUserConvert { } return result; } + + BrokerageUserDTO convertDTO(BrokerageUserDO brokerageUser); } diff --git a/yudao-module-member/yudao-module-member-biz/pom.xml b/yudao-module-member/yudao-module-member-biz/pom.xml index a5eda05b0..1df7e7be8 100644 --- a/yudao-module-member/yudao-module-member-biz/pom.xml +++ b/yudao-module-member/yudao-module-member-biz/pom.xml @@ -33,6 +33,11 @@ yudao-module-infra-api ${revision} + + cn.iocoder.boot + yudao-module-trade-api + ${revision} + diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppMemberUserController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppMemberUserController.java index 4d15aad1f..461a1a5c5 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppMemberUserController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppMemberUserController.java @@ -8,6 +8,8 @@ import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.service.level.MemberLevelService; import cn.iocoder.yudao.module.member.service.user.MemberUserService; +import cn.iocoder.yudao.module.trade.api.brokerage.BrokerageApi; +import cn.iocoder.yudao.module.trade.api.brokerage.dto.BrokerageUserDTO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; @@ -16,6 +18,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.Optional; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @@ -33,14 +36,18 @@ public class AppMemberUserController { @Resource private MemberLevelService levelService; + @Resource + private BrokerageApi brokerageApi; + @GetMapping("/get") @Operation(summary = "获得基本信息") @PreAuthenticated public CommonResult getUserInfo() { MemberUserDO user = userService.getUser(getLoginUserId()); MemberLevelDO level = levelService.getLevel(user.getLevelId()); + BrokerageUserDTO brokerageUser = brokerageApi.getBrokerageUser(user.getId()); return success(MemberUserConvert.INSTANCE.convert(user, level) - .setBrokerageEnabled(true) // TODO @疯狂:这里我先写死,后面改成 db 返回; + .setBrokerageEnabled(Optional.ofNullable(brokerageUser).map(BrokerageUserDTO::getBrokerageEnabled).orElse(false)) ); } From f97c7a0f6e14decc794b538d2611dd8a6a4f138f Mon Sep 17 00:00:00 2001 From: owen Date: Sat, 9 Sep 2023 01:46:42 +0800 Subject: [PATCH 10/12] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E7=BB=91=E5=AE=9A=E6=8E=A8=E5=B9=BF=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/api/brokerage/BrokerageApi.java | 5 +- .../trade/enums/ErrorCodeConstants.java | 6 ++ .../trade/api/brokerage/BrokerageApiImpl.java | 5 +- .../brokerage/AppBrokerageUserController.java | 17 +++- .../vo/user/AppBrokerageUserBindReqVO.java | 17 ++++ .../brokerage/user/BrokerageUserService.java | 10 ++ .../user/BrokerageUserServiceImpl.java | 92 ++++++++++++++++++- 7 files changed, 140 insertions(+), 12 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserBindReqVO.java diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java index 4952e5cad..4d7314d4b 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.trade.api.brokerage; import cn.iocoder.yudao.module.trade.api.brokerage.dto.BrokerageUserDTO; -import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageBindModeEnum; /** * 分销 API 接口 @@ -23,8 +22,8 @@ public interface BrokerageApi { * * @param userId 用户编号 * @param bindUserId 推广员编号 - * @param bindMode 绑定模式 {@link BrokerageBindModeEnum} + * @param isNewUser 是否为新用户 * @return 是否绑定 */ - boolean bindUser(Long userId, Long bindUserId, Integer bindMode); + boolean bindUser(Long userId, Long bindUserId, Boolean isNewUser); } 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 fa5be50b7..236e7af23 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 @@ -78,5 +78,11 @@ public interface ErrorCodeConstants { // ========== 分销用户 模块 1011007000 ========== ErrorCode BROKERAGE_USER_NOT_EXISTS = new ErrorCode(1011007000, "分销用户不存在"); ErrorCode BROKERAGE_USER_FROZEN_PRICE_NOT_ENOUGH = new ErrorCode(1011007001, "用户冻结佣金({})数量不足"); + ErrorCode BROKERAGE_BIND_SELF = new ErrorCode(1011007002, "不能绑定自己"); + ErrorCode BROKERAGE_BIND_USER_NOT_ENABLED = new ErrorCode(1011007003, "绑定用户没有推广资格"); + ErrorCode BROKERAGE_BIND_CONDITION_ADMIN = new ErrorCode(1011007004, "仅可在后台绑定推广员"); + ErrorCode BROKERAGE_BIND_MODE_REGISTER = new ErrorCode(1011007005, "只有在注册时可以绑定"); + ErrorCode BROKERAGE_BIND_OVERRIDE = new ErrorCode(1011007006, "已绑定了推广人"); + ErrorCode BROKERAGE_BIND_LOOP = new ErrorCode(1011007007, "下级不能绑定自己的上级"); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java index 1bb520734..4a534fa22 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java @@ -25,9 +25,8 @@ public class BrokerageApiImpl implements BrokerageApi { } @Override - public boolean bindUser(Long userId, Long bindUserId, Integer bindMode) { - // todo 待实现 - return false; + public boolean bindUser(Long userId, Long bindUserId, Boolean isNewUser) { + return brokerageUserService.bindUser(userId, bindUserId, isNewUser); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index ecbb7de45..ef1634098 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -4,21 +4,22 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.*; +import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import javax.validation.Valid; import java.time.LocalDateTime; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static java.util.Arrays.asList; @Tag(name = "用户 APP - 分销用户") @@ -27,6 +28,8 @@ import static java.util.Arrays.asList; @Validated @Slf4j public class AppBrokerageUserController { + @Resource + private BrokerageUserService brokerageUserService; // TODO 芋艿:临时 mock => @GetMapping("/get") @@ -120,4 +123,10 @@ public class AppBrokerageUserController { return success(1); } + @PutMapping("/bind-user") + @Operation(summary = "绑定推广员") + public CommonResult getBrokerageUserRankByPrice(@Valid AppBrokerageUserBindReqVO reqVO) { + return success(brokerageUserService.bindUser(getLoginUserId(), reqVO.getBindUserId(), false)); + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserBindReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserBindReqVO.java new file mode 100644 index 000000000..f2a14996a --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserBindReqVO.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@Schema(description = "应用 App - 绑定推广员 Request VO") +@Data +public class AppBrokerageUserBindReqVO extends PageParam { + + @Schema(description = "推广员编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @NotNull(message = "推广员编号不能为空") + private Long bindUserId; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java index c26cfb6e3..61aa8bde0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java @@ -93,4 +93,14 @@ public interface BrokerageUserService { * @return 推广用户数量 */ Long getCountByBindUserId(Long bindUserId); + + /** + * 【会员】绑定推广员 + * + * @param userId 用户编号 + * @param bindUserId 推广员编号 + * @param isNewUser 是否为新用户 + * @return 是否绑定 + */ + boolean bindUser(Long userId, Long bindUserId, Boolean isNewUser); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java index 33f81602d..7666da49b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java @@ -1,21 +1,27 @@ package cn.iocoder.yudao.module.trade.service.brokerage.user; import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.BooleanUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.BrokerageUserMapper; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageBindModeEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageEnabledConditionEnum; +import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.time.LocalDateTime; import java.util.Collection; import java.util.List; +import java.util.Objects; import java.util.Optional; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_USER_FROZEN_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.*; /** * 分销用户 Service 实现类 @@ -29,6 +35,9 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { @Resource private BrokerageUserMapper brokerageUserMapper; + @Resource + private TradeConfigService tradeConfigService; + @Override public BrokerageUserDO getBrokerageUser(Long id) { return brokerageUserMapper.selectById(id); @@ -105,4 +114,83 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { return brokerageUserMapper.selectCount(BrokerageUserDO::getBindUserId, bindUserId); } + @Override + public boolean bindUser(Long userId, Long bindUserId, Boolean isNewUser) { + if (userId == null) { + throw exception(0); + } + + boolean isInsert = false; + BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(userId); + // 分销用户不存在的情况:1.新注册 2.旧数据 3.分销功能关闭后又打开 + if (brokerageUser == null) { + isInsert = true; + brokerageUser = new BrokerageUserDO().setId(userId).setBrokerageEnabled(false).setPrice(0).setFrozenPrice(0); + } + + // 校验能否绑定 + boolean validated = validateCanBindUser(brokerageUser, bindUserId, isNewUser); + if (!validated) { + return false; + } + + if (isInsert) { + Integer enabledCondition = tradeConfigService.getTradeConfig().getBrokerageEnabledCondition(); + if (BrokerageEnabledConditionEnum.ALL.getCondition().equals(enabledCondition)) { + // 人人分销:用户默认就有分销资格 + brokerageUser.setBrokerageEnabled(true).setBindUserTime(LocalDateTime.now()); + } + brokerageUserMapper.insert(brokerageUser); + } else { + brokerageUserMapper.updateById(new BrokerageUserDO().setId(userId) + .setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now())); + } + return true; + } + + private boolean validateCanBindUser(BrokerageUserDO user, Long bindUserId, Boolean isNewUser) { + if (bindUserId == null) { + return false; + } + + // 校验分销功能是否启用 + TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig(); + if (tradeConfig == null || !BooleanUtil.isTrue(tradeConfig.getBrokerageEnabled())) { + return false; + } + + // 校验绑定自己 + if (Objects.equals(user.getId(), bindUserId)) { + throw exception(BROKERAGE_BIND_SELF); + } + + // 校验要绑定的用户有无推广资格 + BrokerageUserDO bindUser = brokerageUserMapper.selectById(bindUserId); + if (bindUser == null || !BooleanUtil.isTrue(bindUser.getBrokerageEnabled())) { + throw exception(BROKERAGE_BIND_USER_NOT_ENABLED); + } + + // 校验分佣模式:仅可后台手动设置推广员 + if (BrokerageEnabledConditionEnum.ADMIN.getCondition().equals(tradeConfig.getBrokerageEnabledCondition())) { + throw exception(BROKERAGE_BIND_CONDITION_ADMIN); + } + + // 校验分销关系绑定模式 + if (BrokerageBindModeEnum.REGISTER.getMode().equals(tradeConfig.getBrokerageBindMode())) { + if (!BooleanUtil.isTrue(isNewUser)) { + throw exception(BROKERAGE_BIND_MODE_REGISTER); // 只有在注册时可以绑定 + } + } else if (BrokerageBindModeEnum.ANYTIME.getMode().equals(tradeConfig.getBrokerageBindMode())) { + if (user.getBindUserId() != null) { + throw exception(BROKERAGE_BIND_OVERRIDE); // 已绑定了推广人 + } + } + + // A->B->A:下级不能绑定自己的上级, A->B->C->A可以!! + if (Objects.equals(user.getId(), bindUser.getBindUserId())) { + throw exception(BROKERAGE_BIND_LOOP); + } + return true; + } + } From 259734964de364fd6d58c1db4cecd0fc3b126246 Mon Sep 17 00:00:00 2001 From: owen Date: Sat, 9 Sep 2023 01:54:48 +0800 Subject: [PATCH 11/12] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E5=90=8E=E5=8F=B0=E5=8A=9F=E8=83=BD=EF=BC=9A=E6=B8=85?= =?UTF-8?q?=E9=99=A4=E6=8E=A8=E5=B9=BF=E5=91=98=E3=80=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=8E=A8=E5=B9=BF=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/brokerage/user/BrokerageUserController.java | 2 +- .../vo/BrokerageUserUpdateBrokerageUserReqVO.java | 2 +- .../dal/mysql/brokerage/user/BrokerageUserMapper.java | 5 +++++ .../service/brokerage/user/BrokerageUserService.java | 6 +++--- .../brokerage/user/BrokerageUserServiceImpl.java | 11 +++++++++-- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java index 0992f52e0..f29e2c9a8 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java @@ -46,7 +46,7 @@ public class BrokerageUserController { @Operation(summary = "修改推广员") @PreAuthorize("@ss.hasPermission('trade:brokerage-user:update-brokerage-user')") public CommonResult updateBrokerageUser(@Valid @RequestBody BrokerageUserUpdateBrokerageUserReqVO updateReqVO) { - brokerageUserService.updateBrokerageUserId(updateReqVO.getId(), updateReqVO.getBrokerageUserId()); + brokerageUserService.updateBrokerageUserId(updateReqVO.getId(), updateReqVO.getBindUserId()); return success(true); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java index c6c72999d..d62c7fd1e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java @@ -17,6 +17,6 @@ public class BrokerageUserUpdateBrokerageUserReqVO { @Schema(description = "推广员编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4587") @NotNull(message = "推广员编号不能为空") - private Long brokerageUserId; + private Long bindUserId; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java index 2f7d1d19c..b7d045a66 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java @@ -100,4 +100,9 @@ public interface BrokerageUserMapper extends BaseMapperX { return update(null, lambdaUpdateWrapper); } + default void updateBindUserIdAndBindUserTimeToNull(Long id) { + update(null, new LambdaUpdateWrapper() + .eq(BrokerageUserDO::getId, id) + .set(BrokerageUserDO::getBindUserId, null).set(BrokerageUserDO::getBindUserTime, null)); + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java index 61aa8bde0..f06bb7ffc 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java @@ -41,10 +41,10 @@ public interface BrokerageUserService { /** * 修改推广员编号 * - * @param id 用户编号 - * @param brokerageUserId 推广员编号 + * @param id 用户编号 + * @param bindUserId 推广员编号 */ - void updateBrokerageUserId(Long id, Long brokerageUserId); + void updateBrokerageUserId(Long id, Long bindUserId); /** * 修改推广资格 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java index 7666da49b..5df10fa58 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java @@ -54,10 +54,17 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } @Override - public void updateBrokerageUserId(Long id, Long brokerageUserId) { + public void updateBrokerageUserId(Long id, Long bindUserId) { // 校验存在 validateBrokerageUserExists(id); - // TODO @疯狂:貌似没实现完 + if (bindUserId == null) { + // 清除推广员 + brokerageUserMapper.updateBindUserIdAndBindUserTimeToNull(id); + } else { + // 修改推广员 + brokerageUserMapper.updateById(new BrokerageUserDO().setId(id) + .setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now())); + } } @Override From 4e9be7a1815f8c96567294d7600870ee88c7c028 Mon Sep 17 00:00:00 2001 From: owen Date: Sat, 9 Sep 2023 01:58:46 +0800 Subject: [PATCH 12/12] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E5=90=8E=E5=8F=B0=E5=8A=9F=E8=83=BD=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=8E=A8=E5=B9=BF=E8=B5=84=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dal/mysql/brokerage/user/BrokerageUserMapper.java | 6 ++++++ .../service/brokerage/user/BrokerageUserServiceImpl.java | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java index b7d045a66..ee90b3e7d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java @@ -105,4 +105,10 @@ public interface BrokerageUserMapper extends BaseMapperX { .eq(BrokerageUserDO::getId, id) .set(BrokerageUserDO::getBindUserId, null).set(BrokerageUserDO::getBindUserTime, null)); } + + default void updateEnabledFalseAndBrokerageTimeToNull(Long id) { + update(null, new LambdaUpdateWrapper() + .eq(BrokerageUserDO::getId, id) + .set(BrokerageUserDO::getBrokerageEnabled, false).set(BrokerageUserDO::getBrokerageTime, null)); + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java index 5df10fa58..6d6d7d2ac 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java @@ -71,7 +71,14 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { public void updateBrokerageEnabled(Long id, Boolean enabled) { // 校验存在 validateBrokerageUserExists(id); - // TODO @疯狂:貌似没实现完 + if (BooleanUtil.isTrue(enabled)) { + // 开通推广资格 + brokerageUserMapper.updateById(new BrokerageUserDO().setId(id) + .setBrokerageEnabled(true).setBrokerageTime(LocalDateTime.now())); + } else { + // 取消推广资格 + brokerageUserMapper.updateEnabledFalseAndBrokerageTimeToNull(id); + } } private void validateBrokerageUserExists(Long id) {