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 new file mode 100644 index 000000000..ed71b8434 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageUserTypeEnum.java @@ -0,0 +1,39 @@ +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; + +/** + * 分销用户类型枚举 + * + * @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/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 e6908e8aa..c40affac0 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,6 +1,8 @@ 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; @@ -27,4 +29,11 @@ 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 = "绑定时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + 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 ee90b3e7d..3d1b20a5e 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,11 +1,14 @@ 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; @@ -19,12 +22,32 @@ public interface BrokerageUserMapper extends BaseMapperX { default PageResult selectPage(BrokerageUserPageReqVO reqVO) { return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(BrokerageUserDO::getBindUserId, reqVO.getBindUserId()) .eqIfPresent(BrokerageUserDO::getBrokerageEnabled, reqVO.getBrokerageEnabled()) .betweenIfPresent(BrokerageUserDO::getCreateTime, reqVO.getCreateTime()) + .betweenIfPresent(BrokerageUserDO::getBindUserTime, reqVO.getBindUserTime()) + .and(reqVO.getBindUserId() != null, w -> buildBindUserCondition(reqVO, w)) .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 { + buildFirstBindUserCondition(reqVO.getBindUserId(), wrapper); + buildSecondBindUserCondition(reqVO.getBindUserId(), wrapper.or()); + } + } + + static void buildFirstBindUserCondition(Long bindUserId, LambdaQueryWrapper wrapper) { + wrapper.eq(BrokerageUserDO::getBindUserId, bindUserId); + } + + static void buildSecondBindUserCondition(Long bindUserId, LambdaQueryWrapper w) { + w.inSql(BrokerageUserDO::getBindUserId, StrUtil.format("SELECT id FROM trade_brokerage_user WHERE bind_user_id = {}", bindUserId)); + } + /** * 更新用户可用佣金(增加) *