diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index ff291647e..19c1a56dd 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -2,41 +2,50 @@ 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 '分佣模式: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 '二级返佣比例', - brokerage_withdraw_min_price int default 0 not null comment '用户提现最低金额', - brokerage_bank_names varchar(200) default '' not null comment '提现银行(字典类型=brokerage_bank_name)', - brokerage_frozen_days int default 7 not null comment '佣金冻结时间(天)', - brokerage_withdraw_type varchar(32) default '1,2,3,4' not null comment '提现方式:1-钱包;2-银行卡;3-微信;4-支付宝', - 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 '租户编号' + brokerage_enabled bit default 1 not null comment '是否启用分佣', + 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 '二级返佣比例', + brokerage_withdraw_min_price int default 0 not null comment '用户提现最低金额', + brokerage_bank_names varchar(200) default '' not null comment '提现银行(字典类型=brokerage_bank_name)', + brokerage_frozen_days int default 7 not null comment '佣金冻结时间(天)', + brokerage_withdraw_type varchar(32) default '1,2,3,4' not null comment '提现方式:1-钱包;2-银行卡;3-微信;4-支付宝', + creator varchar(64) default '' null comment '创建者', + create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', + updater varchar(64) 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 '交易中心配置'; +# alter table trade_brokerage_user +# add level int not null default 1 comment '等级' after frozen_price; +# alter table trade_brokerage_user +# add path varchar(2000) null comment '路径' after level; + + -- 增加分销用户扩展表 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 '成为分销员时间', - 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 '分销用户'; + 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 '冻结佣金', + level int default 1 not null comment '等级', + path varchar(2000) null comment '路径', + creator varchar(64) default '' null comment '创建者', + create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', + updater varchar(64) 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 '推广员编号'; create index idx_agent on trade_brokerage_user (brokerage_enabled) comment '是否成为推广员'; @@ -44,26 +53,26 @@ create index idx_agent on trade_brokerage_user (brokerage_enabled) comment '是 create table trade_brokerage_record ( - id int auto_increment comment '编号' + id int auto_increment comment '编号' primary key, - user_id bigint not null comment '用户编号', - biz_id varchar(64) default '' not null comment '业务编号', - biz_type tinyint default 0 not null comment '业务类型:1-订单,2-提现', - title varchar(64) default '' not null comment '标题', - price int default 0 not null comment '金额', - total_price int default 0 not null comment '当前总佣金', - description varchar(500) default '' not null comment '说明', - status tinyint default 0 not null comment '状态:0-待结算,1-已结算,2-已取消', - frozen_days int default 0 not null comment '冻结时间(天)', - unfreeze_time datetime null comment '解冻时间', - source_user_type tinyint not null comment '来源用户类型:1-一级推广用户,2-二级推广用户', - source_user_id bigint not null comment '来源用户编号', - creator varchar(64) collate utf8mb4_general_ci default '' null comment '创建者', - create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', - updater varchar(64) collate utf8mb4_general_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 '租户编号' + user_id bigint not null comment '用户编号', + biz_id varchar(64) default '' not null comment '业务编号', + biz_type tinyint default 0 not null comment '业务类型:1-订单,2-提现', + title varchar(64) default '' not null comment '标题', + price int default 0 not null comment '金额', + total_price int default 0 not null comment '当前总佣金', + description varchar(500) default '' not null comment '说明', + status tinyint default 0 not null comment '状态:0-待结算,1-已结算,2-已取消', + frozen_days int default 0 not null comment '冻结时间(天)', + unfreeze_time datetime null comment '解冻时间', + source_user_level int not null comment '来源用户等级', + source_user_id bigint not null comment '来源用户编号', + creator varchar(64) default '' null comment '创建者', + create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', + updater varchar(64) 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 '佣金记录'; @@ -76,26 +85,26 @@ create table trade_brokerage_withdraw ( id int auto_increment comment '编号' primary key, - user_id bigint not null comment '用户编号', - price int default 0 not null comment '提现金额', - fee_price int default 0 not null comment '提现手续费', - total_price int default 0 not null comment '当前总佣金', - type tinyint default 0 not null comment '提现类型:1-钱包;2-银行卡;3-微信;4-支付宝', - name varchar(64) null comment '真实姓名', - account_no varchar(64) null comment '账号', - bank_name varchar(100) null comment '银行名称', - bank_address varchar(200) null comment '开户地址', - account_qr_code_url varchar(512) null comment '收款码', - status tinyint(2) default 0 not null comment '状态:0-审核中,10-审核通过 20-审核不通过;预留:11 - 提现成功;21-提现失败', - audit_reason varchar(128) null comment '审核驳回原因', - audit_time datetime null comment '审核时间', - remark varchar(500) null comment '备注', - creator varchar(64) collate utf8mb4_general_ci default '' null comment '创建者', - create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', - updater varchar(64) collate utf8mb4_general_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 '租户编号' + user_id bigint not null comment '用户编号', + price int default 0 not null comment '提现金额', + fee_price int default 0 not null comment '提现手续费', + total_price int default 0 not null comment '当前总佣金', + type tinyint default 0 not null comment '提现类型:1-钱包;2-银行卡;3-微信;4-支付宝', + name varchar(64) null comment '真实姓名', + account_no varchar(64) null comment '账号', + bank_name varchar(100) null comment '银行名称', + bank_address varchar(200) null comment '开户地址', + account_qr_code_url varchar(512) null comment '收款码', + status tinyint(2) default 0 not null comment '状态:0-审核中,10-审核通过 20-审核不通过;预留:11 - 提现成功;21-提现失败', + audit_reason varchar(128) null comment '审核驳回原因', + audit_time datetime null comment '审核时间', + remark varchar(500) null comment '备注', + creator varchar(64) default '' null comment '创建者', + create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', + updater varchar(64) 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 '佣金提现'; diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java index a728365e6..d61bb5aa2 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java @@ -100,6 +100,13 @@ public class LambdaQueryWrapperX extends LambdaQueryWrapper { return betweenIfPresent(column, val1, val2); } + public LambdaQueryWrapperX findInSetIfPresent(SFunction column, Object val) { + if (val != null) { + return (LambdaQueryWrapperX) super.apply("FIND_IN_SET({0}, " + columnToString(column) + ")", val); + } + return this; + } + // ========== 重写父类方法,方便链式调用 ========== @Override diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/serviceImpl.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/serviceImpl.vm index 148d1fa41..9cb6e8b27 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/serviceImpl.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/serviceImpl.vm @@ -64,14 +64,14 @@ public class ${table.className}ServiceImpl implements ${table.className}Service @Override public ${table.className}DO get${simpleClassName}(${primaryColumn.javaType} id) { - if (CollUtil.isEmpty(ids)) { - return ListUtil.empty(); - } return ${classNameVar}Mapper.selectById(id); } @Override public List<${table.className}DO> get${simpleClassName}List(Collection<${primaryColumn.javaType}> ids) { + if (CollUtil.isEmpty(ids)) { + return ListUtil.empty(); + } return ${classNameVar}Mapper.selectBatchIds(ids); } 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 deleted file mode 100644 index a08ce7f46..000000000 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java +++ /dev/null @@ -1,52 +0,0 @@ -package cn.iocoder.yudao.module.trade.api.brokerage; - -import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; -import cn.iocoder.yudao.module.trade.api.brokerage.dto.BrokerageUserDTO; - -import javax.validation.constraints.NotNull; -import java.time.LocalDateTime; - -// TODO @疯狂:是不是不需要这个啦? -/** - * 分销 API 接口 - * - * @author owen - */ -public interface BrokerageApi { - - /** - * 获得分销用户 - * - * @param userId 用户编号 - * @return 分销用户信息 - */ - BrokerageUserDTO getBrokerageUser(Long userId); - - /** - * 【会员】绑定推广员 - * - * @param userId 用户编号 - * @param bindUserId 推广员编号 - * @param registerTime 用户注册时间 - * @return 是否绑定 - */ - default boolean bindUser(@NotNull Long userId, @NotNull Long bindUserId, @NotNull LocalDateTime registerTime) { - // 注册时间在30秒内的,都算新用户 - // TODO @疯狂:这个要不抽到 service 里哈? - boolean isNewUser = LocalDateTimeUtils.afterNow(registerTime.minusSeconds(30)); - return bindUser(userId, bindUserId, isNewUser); - } - - /** - * 绑定推广员 - * - * @param userId 用户编号 - * @param bindUserId 推广员编号 - * @param isNewUser 是否为新用户 - * @return 是否绑定 - */ - boolean bindUser(@NotNull(message = "用户编号不能为空") Long userId, - @NotNull(message = "推广员编号不能为空") Long bindUserId, - @NotNull Boolean isNewUser); - -} 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 deleted file mode 100644 index 864abe148..000000000 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/dto/BrokerageUserDTO.java +++ /dev/null @@ -1,51 +0,0 @@ -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-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageUserTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageUserTypeEnum.java deleted file mode 100644 index a75ad4414..000000000 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageUserTypeEnum.java +++ /dev/null @@ -1,40 +0,0 @@ -package cn.iocoder.yudao.module.trade.enums.brokerage; - -import cn.iocoder.yudao.framework.common.core.IntArrayValuable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; - -// TODO @疯狂:是不是搞成层级,类似 level 这样?因为本质上,它是 1 级、2 级、3 级这样的关系哈 -/** - * 分销用户类型枚举 - * - * @author owen - */ -@AllArgsConstructor -@Getter -public enum BrokerageUserTypeEnum implements IntArrayValuable { - - ALL(0, "全部"), - FIRST(1, "一级推广人"), - SECOND(2, "二级推广人"), - ; - - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageUserTypeEnum::getType).toArray(); - - /** - * 类型 - */ - private final Integer type; - /** - * 名字 - */ - private final String name; - - @Override - public int[] array() { - return ARRAYS; - } - -} 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 deleted file mode 100644 index 4910f07a5..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -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; - - @Override - public BrokerageUserDTO getBrokerageUser(Long userId) { - return BrokerageUserConvert.INSTANCE.convertDTO(brokerageUserService.getBrokerageUser(userId)); - } - - @Override - public boolean bindUser(Long userId, Long bindUserId, Boolean isNewUser) { - return brokerageUserService.bindBrokerageUser(userId, bindUserId, isNewUser); - } - -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordBaseVO.java index 477f89978..425758631 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordBaseVO.java @@ -57,8 +57,8 @@ public class BrokerageRecordBaseVO { @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime unfreezeTime; - @Schema(description = "来源用户类型") - private Integer sourceUserType; + @Schema(description = "来源用户等级") + private Integer sourceUserLevel; @Schema(description = "来源用户编号") private Long sourceUserId; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordPageReqVO.java index 4ef472290..9067fea60 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordPageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordPageReqVO.java @@ -1,8 +1,6 @@ package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo; import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageUserTypeEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; @@ -33,7 +31,6 @@ public class BrokerageRecordPageReqVO extends PageParam { private LocalDateTime[] createTime; @Schema(description = "用户类型") - @InEnum(value = BrokerageUserTypeEnum.class, message = "用户类型必须是 {value}") - private Integer sourceUserType; + private Integer sourceUserLevel; } 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 f47f5d9ed..d90900061 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 @@ -9,7 +9,6 @@ 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.enums.brokerage.BrokerageUserTypeEnum; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService; import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService; @@ -96,7 +95,7 @@ public class BrokerageUserController { // 合计推广用户数量 Map brokerageUserCountMap = convertMap(userIds, userId -> userId, - userId -> brokerageUserService.getBrokerageUserCountByBindUserId(userId, BrokerageUserTypeEnum.ALL)); + userId -> brokerageUserService.getBrokerageUserCountByBindUserId(userId, null)); // todo 合计提现 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 c40affac0..14327c7d2 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 @@ -1,8 +1,6 @@ package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo; import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageUserTypeEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; @@ -29,9 +27,8 @@ public class BrokerageUserPageReqVO extends PageParam { @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] createTime; - @Schema(description = "用户类型") - @InEnum(value = BrokerageUserTypeEnum.class, message = "用户类型必须是 {value}") - private Integer userType; + @Schema(description = "用户等级") + private Integer level; @Schema(description = "绑定时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) 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 90527896f..5d620a898 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 @@ -35,7 +35,7 @@ public interface BrokerageRecordConvert { default BrokerageRecordDO convert(BrokerageUserDO user, BrokerageRecordBizTypeEnum bizType, String bizId, Integer brokerageFrozenDays, int brokeragePrice, LocalDateTime unfreezeTime, - String title, Long sourceUserId, Integer sourceUserType) { + String title, Long sourceUserId, Integer sourceUserLevel) { brokerageFrozenDays = ObjectUtil.defaultIfNull(brokerageFrozenDays, 0); // 不冻结时,佣金直接就是结算状态 Integer status = brokerageFrozenDays > 0 @@ -47,7 +47,7 @@ public interface BrokerageRecordConvert { .setTitle(title) .setDescription(StrUtil.format(bizType.getDescription(), String.format("¥%.2f", brokeragePrice / 100d))) .setStatus(status).setFrozenDays(brokerageFrozenDays).setUnfreezeTime(unfreezeTime) - .setSourceUserType(sourceUserType).setSourceUserId(sourceUserId); + .setSourceUserLevel(sourceUserLevel).setSourceUserId(sourceUserId); } default PageResult convertPage(PageResult pageResult, Map userMap) { 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 544e29a87..83101a1de 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,7 +3,6 @@ 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; @@ -56,6 +55,4 @@ public interface BrokerageUserConvert { user -> target.setNickname(user.getNickname()).setAvatar(user.getAvatar())); return target; } - - BrokerageUserDTO convertDTO(BrokerageUserDO brokerageUser); } 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 b31aaa007..aa659fd4b 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 @@ -29,7 +29,6 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; -import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; @@ -276,10 +275,10 @@ public interface TradeOrderConvert { TradeOrderDO convert(TradeOrderRemarkReqVO reqVO); - default BrokerageAddReqBO convert(TradeOrderItemDO item, ProductSkuRespDTO sku) { + default BrokerageAddReqBO convert(MemberUserRespDTO user, TradeOrderItemDO item, ProductSkuRespDTO sku) { return new BrokerageAddReqBO().setBizId(String.valueOf(item.getId())).setSourceUserId(item.getUserId()) .setBasePrice(item.getPayPrice() * item.getCount()) - .setTitle(BrokerageRecordBizTypeEnum.ORDER.getTitle()) // TODO @疯狂:标题类似:木晴冰雪成功购买云时代的JVM原理与实战;茫农成功购买深入拆解消息队列47讲 + .setTitle(StrUtil.format("{}成功购买{}", user.getNickname(), item.getSpuName())) .setFirstFixedPrice(sku.getFirstBrokerageRecord()).setSecondFixedPrice(sku.getSecondBrokerageRecord()); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/BrokerageRecordDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/BrokerageRecordDO.java index a9ececb68..0f59eada5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/BrokerageRecordDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/BrokerageRecordDO.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; -import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageUserTypeEnum; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -83,11 +82,11 @@ public class BrokerageRecordDO extends BaseDO { private LocalDateTime unfreezeTime; /** - * 来源用户类型 + * 来源用户等级 *

- * 枚举 {@link BrokerageUserTypeEnum},被推广用户和 {@link #userId} 的推广层级关系 + * 被推广用户和 {@link #userId} 的推广层级关系 */ - private Integer sourceUserType; + private Integer sourceUserLevel; /** * 来源用户编号 *

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 4348fa195..3493cac97 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 @@ -60,4 +60,12 @@ public class BrokerageUserDO extends BaseDO { */ private Integer frozenPrice; + /** + * 等级 + */ + private Integer level; + /** + * 路径 + */ + private String path; } 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 index 8e749b41c..776a77ce1 100644 --- 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 @@ -5,7 +5,6 @@ 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.enums.brokerage.BrokerageUserTypeEnum; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; @@ -24,14 +23,12 @@ import java.util.List; public interface BrokerageRecordMapper extends BaseMapperX { default PageResult selectPage(BrokerageRecordPageReqVO reqVO) { - boolean sourceUserTypeCondition = reqVO.getSourceUserType() != null && - !BrokerageUserTypeEnum.ALL.getType().equals(reqVO.getSourceUserType()); // 分页查询 return selectPage(reqVO, new LambdaQueryWrapperX() .eqIfPresent(BrokerageRecordDO::getUserId, reqVO.getUserId()) .eqIfPresent(BrokerageRecordDO::getBizType, reqVO.getBizType()) .eqIfPresent(BrokerageRecordDO::getStatus, reqVO.getStatus()) - .eq(sourceUserTypeCondition, BrokerageRecordDO::getSourceUserType, reqVO.getSourceUserType()) + .eqIfPresent(BrokerageRecordDO::getSourceUserLevel, reqVO.getSourceUserLevel()) .betweenIfPresent(BrokerageRecordDO::getCreateTime, reqVO.getCreateTime()) .orderByDesc(BrokerageRecordDO::getId)); } 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 18ddef3b2..239625b17 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 @@ -1,17 +1,15 @@ package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user; import cn.hutool.core.lang.Assert; -import cn.hutool.core.util.StrUtil; 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.BrokerageUserPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; -import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageUserTypeEnum; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; + +import java.util.List; /** * 分销用户 Mapper @@ -21,35 +19,16 @@ import org.apache.ibatis.annotations.Select; @Mapper public interface BrokerageUserMapper extends BaseMapperX { - default PageResult selectPage(BrokerageUserPageReqVO reqVO) { + default PageResult selectPage(BrokerageUserPageReqVO reqVO, List levels) { return selectPage(reqVO, new LambdaQueryWrapperX() .eqIfPresent(BrokerageUserDO::getBrokerageEnabled, reqVO.getBrokerageEnabled()) .betweenIfPresent(BrokerageUserDO::getCreateTime, reqVO.getCreateTime()) .betweenIfPresent(BrokerageUserDO::getBindUserTime, reqVO.getBindUserTime()) - .and(reqVO.getBindUserId() != null, w -> buildBindUserCondition(reqVO, w)) + .findInSetIfPresent(BrokerageUserDO::getPath, reqVO.getBindUserId()) + .inIfPresent(BrokerageUserDO::getLevel, levels) .orderByDesc(BrokerageUserDO::getId)); } - static void buildBindUserCondition(BrokerageUserPageReqVO reqVO, LambdaQueryWrapper wrapper) { - if (BrokerageUserTypeEnum.FIRST.getType().equals(reqVO.getUserType())) { - buildFirstBindUserCondition(reqVO.getBindUserId(), wrapper); - } else if (BrokerageUserTypeEnum.SECOND.getType().equals(reqVO.getUserType())) { - buildSecondBindUserCondition(reqVO.getBindUserId(), wrapper); - } else { - // TODO @疯狂:要不要把这个逻辑,挪到 Service 里,算出子用户有哪些,然后 IN? - buildFirstBindUserCondition(reqVO.getBindUserId(), wrapper); - buildSecondBindUserCondition(reqVO.getBindUserId(), wrapper.or()); // 通过 or 实现多个条件 - } - } - - static void buildFirstBindUserCondition(Long bindUserId, LambdaQueryWrapper wrapper) { - wrapper.eq(BrokerageUserDO::getBindUserId, bindUserId); - } - - static void buildSecondBindUserCondition(Long bindUserId, LambdaQueryWrapper wrapper) { - wrapper.inSql(BrokerageUserDO::getBindUserId, StrUtil.format("SELECT id FROM trade_brokerage_user WHERE bind_user_id = {}", bindUserId)); - } - /** * 更新用户可用佣金(增加) * @@ -128,7 +107,8 @@ public interface BrokerageUserMapper extends BaseMapperX { default void updateBindUserIdAndBindUserTimeToNull(Long id) { update(null, new LambdaUpdateWrapper() .eq(BrokerageUserDO::getId, id) - .set(BrokerageUserDO::getBindUserId, null).set(BrokerageUserDO::getBindUserTime, null)); + .set(BrokerageUserDO::getBindUserId, null).set(BrokerageUserDO::getBindUserTime, null) + .set(BrokerageUserDO::getLevel, 1).set(BrokerageUserDO::getPath, "")); } default void updateEnabledFalseAndBrokerageTimeToNull(Long id) { @@ -137,11 +117,10 @@ public interface BrokerageUserMapper extends BaseMapperX { .set(BrokerageUserDO::getBrokerageEnabled, false).set(BrokerageUserDO::getBrokerageTime, null)); } - default Long selectCountByBindUserId(Long bindUserId) { - return selectCount(BrokerageUserDO::getBindUserId, bindUserId); + default Long selectCountByBindUserIdAndLevelIn(Long bindUserId, List levels) { + return selectCount(new LambdaQueryWrapperX() + .findInSetIfPresent(BrokerageUserDO::getPath, bindUserId) + .inIfPresent(BrokerageUserDO::getLevel, levels)); } - @Select("SELECT COUNT(1) from trade_brokerage_user WHERE bind_user_id IN (SELECT id FROM trade_brokerage_user WHERE bind_user_id = #{bindUserId})") - Long selectCountByBindUserIdInBindUserId(Long bindUserId); - } 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 e5dc343ef..5752f0615 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 @@ -15,7 +15,6 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; 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.enums.brokerage.BrokerageUserTypeEnum; 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.BrokerageUserService; @@ -29,6 +28,7 @@ import javax.annotation.Resource; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * 佣金记录 Service 实现类 @@ -74,7 +74,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { } // 1.2 计算一级分佣 addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), - bizType, BrokerageUserTypeEnum.FIRST); + bizType, 1); // 2.1 获得二级推广员 if (firstUser.getBindUserId() == null) { @@ -86,7 +86,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { } // 2.2 计算二级分佣 addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), - bizType, BrokerageUserTypeEnum.SECOND); + bizType, 2); } @Override @@ -142,10 +142,10 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { * @param brokerageFrozenDays 冻结天数 * @param brokeragePercent 佣金比例 * @param bizType 业务类型 - * @param sourceUserType 来源用户类型 + * @param sourceUserLevel 来源用户等级 */ private void addBrokerage(BrokerageUserDO user, List list, Integer brokerageFrozenDays, - Integer brokeragePercent, BrokerageRecordBizTypeEnum bizType, BrokerageUserTypeEnum sourceUserType) { + Integer brokeragePercent, BrokerageRecordBizTypeEnum bizType, Integer sourceUserLevel) { // 1.1 处理冻结时间 LocalDateTime unfreezeTime = null; if (brokerageFrozenDays != null && brokerageFrozenDays > 0) { @@ -157,12 +157,12 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { for (BrokerageAddReqBO item : list) { // 计算金额 Integer fixedPrice; - if (BrokerageUserTypeEnum.FIRST.equals(sourceUserType)) { + if (Objects.equals(sourceUserLevel, 1)) { fixedPrice = item.getFirstFixedPrice(); - } else if (BrokerageUserTypeEnum.SECOND.equals(sourceUserType)) { + } else if (Objects.equals(sourceUserLevel, 2)) { fixedPrice = item.getSecondFixedPrice(); } else { - throw new IllegalArgumentException(StrUtil.format("来源用户({}) 不合法", sourceUserType)); + throw new IllegalArgumentException(StrUtil.format("用户等级({}) 不合法", sourceUserLevel)); } int brokeragePrice = calculatePrice(item.getBasePrice(), brokeragePercent, fixedPrice); if (brokeragePrice <= 0) { @@ -172,7 +172,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { // 创建记录实体 records.add(BrokerageRecordConvert.INSTANCE.convert(user, bizType, item.getBizId(), brokerageFrozenDays, brokeragePrice, unfreezeTime, item.getTitle(), - item.getSourceUserId(), sourceUserType.getType())); + item.getSourceUserId(), sourceUserLevel)); } if (CollUtil.isEmpty(records)) { 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 df910789a..bd2b8c0f0 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 @@ -1,10 +1,12 @@ package cn.iocoder.yudao.module.trade.service.brokerage.user; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; 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.enums.brokerage.BrokerageUserTypeEnum; +import javax.validation.constraints.NotNull; +import java.time.LocalDateTime; import java.util.Collection; import java.util.List; @@ -91,10 +93,25 @@ public interface BrokerageUserService { * 获得推广用户数量 * * @param bindUserId 绑定的推广员编号 - * @param userType 用户类型 + * @param level 推广用户等级 * @return 推广用户数量 */ - Long getBrokerageUserCountByBindUserId(Long bindUserId, BrokerageUserTypeEnum userType); + Long getBrokerageUserCountByBindUserId(Long bindUserId, Integer level); + + /** + * 【会员】绑定推广员 + * + * @param userId 用户编号 + * @param bindUserId 推广员编号 + * @param registerTime 用户注册时间 + * @return 是否绑定 + */ + default boolean bindBrokerageUser(@NotNull Long userId, @NotNull Long bindUserId, @NotNull LocalDateTime registerTime) { + // 注册时间在30秒内的,都算新用户 + boolean isNewUser = LocalDateTimeUtils.afterNow(registerTime.minusSeconds(30)); + return bindBrokerageUser(userId, bindUserId, 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 e317f2b7f..1ddda4d84 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,7 +1,10 @@ package cn.iocoder.yudao.module.trade.service.brokerage.user; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.BooleanUtil; +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.user.vo.BrokerageUserPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; @@ -9,17 +12,13 @@ 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.enums.brokerage.BrokerageUserTypeEnum; 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 java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; @@ -51,7 +50,8 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { @Override public PageResult getBrokerageUserPage(BrokerageUserPageReqVO pageReqVO) { - return brokerageUserMapper.selectPage(pageReqVO); + List levels = buildUserQueryLevels(pageReqVO.getBindUserId(), pageReqVO.getLevel()); + return brokerageUserMapper.selectPage(pageReqVO, levels); } @Override @@ -66,10 +66,14 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { return; } + // 绑定关系未发生变化 + if (Objects.equals(brokerageUser.getBindUserId(), bindUserId)) { + return; + } + // 情况二:修改推广员 validateCanBindUser(brokerageUser, bindUserId); - brokerageUserMapper.updateById(new BrokerageUserDO().setId(id) - .setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now())); + brokerageUserMapper.updateById(fillBindUserData(bindUserId, new BrokerageUserDO().setId(id))); } @Override @@ -132,19 +136,12 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } @Override - public Long getBrokerageUserCountByBindUserId(Long bindUserId, BrokerageUserTypeEnum userType) { - switch (userType) { - case ALL: // TODO @疯狂:ALL 是不是不用搞个枚举,默认为空就是不过滤哈~ - Long firstCount = brokerageUserMapper.selectCountByBindUserId(bindUserId); - Long secondCount = brokerageUserMapper.selectCountByBindUserIdInBindUserId(bindUserId); - return firstCount + secondCount; - case FIRST: - return brokerageUserMapper.selectCountByBindUserId(bindUserId); - case SECOND: - return brokerageUserMapper.selectCountByBindUserIdInBindUserId(bindUserId); - default: - return 0L; + public Long getBrokerageUserCountByBindUserId(Long bindUserId, Integer level) { + List levels = buildUserQueryLevels(bindUserId, level); + if (CollUtil.isEmpty(levels)) { + return 0L; } + return brokerageUserMapper.selectCountByBindUserIdAndLevelIn(bindUserId, levels); } @Override @@ -171,14 +168,30 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { brokerageUser.setBrokerageEnabled(true).setBrokerageTime(LocalDateTime.now()); } brokerageUser.setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now()); - brokerageUserMapper.insert(brokerageUser); + brokerageUserMapper.insert(fillBindUserData(bindUserId, brokerageUser)); } else { - brokerageUserMapper.updateById(new BrokerageUserDO().setId(userId) - .setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now())); + brokerageUserMapper.updateById(fillBindUserData(bindUserId, new BrokerageUserDO().setId(userId))); } return true; } + private BrokerageUserDO fillBindUserData(Long bindUserId, BrokerageUserDO brokerageUser) { + BrokerageUserDO bindUser = getBrokerageUser(bindUserId); + + Integer bindUserLevel = 0; + String bindUserPath = ""; + if (bindUser != null) { + bindUserLevel = ObjectUtil.defaultIfNull(bindUser.getLevel(), 0); + bindUserPath = bindUser.getPath(); + } + + String path = StrUtil.isEmpty(bindUserPath) + ? String.valueOf(bindUserId) + : String.format("%s,%s", bindUserPath, bindUserId); + return brokerageUser.setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now()) + .setLevel(bindUserLevel + 1).setPath(path); + } + @Override public Boolean getUserBrokerageEnabled(Long userId) { // 全局分销功能是否开启 @@ -231,11 +244,29 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { throw exception(BROKERAGE_BIND_SELF); } - // TODO @疯狂:这块是不是一直查询到根节点,中间不允许出现自己;就是不能形成环。虽然目前是 2 级,但是未来可能会改多级; = = 环的话,就会存在问题哈 - // A->B->A:下级不能绑定自己的上级, A->B->C->A可以!! - if (Objects.equals(user.getId(), bindUser.getBindUserId())) { + // 下级不能绑定自己的上级 + if (StrUtil.split(bindUser.getPath(), ",").contains(String.valueOf(user.getId()))) { throw exception(BROKERAGE_BIND_LOOP); } } + private List buildUserQueryLevels(Long bindUserId, Integer level) { + List levels = new ArrayList<>(2); + + BrokerageUserDO bindUser = getBrokerageUser(bindUserId); + if (bindUser == null) { + return levels; + } + + if (level == null) { + // 默认查两层 + levels.add(bindUser.getLevel() + 1); + levels.add(bindUser.getLevel() + 2); + } else { + levels.add(bindUser.getLevel() + level); + } + return levels; + + } + } 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 9a2b34a93..5f79c51e8 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,6 +12,8 @@ import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; 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; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum; import cn.iocoder.yudao.module.pay.api.order.PayOrderApi; @@ -115,6 +117,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Resource private BargainRecordApi bargainRecordApi; @Resource + private MemberUserApi memberUserApi; + @Resource private MemberLevelApi memberLevelApi; @Resource private MemberPointApi memberPointApi; @@ -781,9 +785,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Async protected void addBrokerageAsync(Long userId, Long orderId) { + MemberUserRespDTO user = memberUserApi.getUser(userId); + Assert.notNull(user); + List orderItems = tradeOrderItemMapper.selectListByOrderId(orderId); List list = convertList(orderItems, - item -> TradeOrderConvert.INSTANCE.convert(item, productSkuApi.getSku(item.getSkuId()))); + item -> TradeOrderConvert.INSTANCE.convert(user, item, productSkuApi.getSku(item.getSkuId()))); brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, list); }