Commit a431bccc02a41972a68998ab888efa40281ba5e9
1 parent
9e99b043
分销:Review代码修改
Showing
13 changed files
with
154 additions
and
73 deletions
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java
| ... | ... | @@ -10,10 +10,10 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; |
| 10 | 10 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; |
| 11 | 11 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; |
| 12 | 12 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; |
| 13 | -import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService; | |
| 14 | -import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; | |
| 15 | 13 | import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService; |
| 16 | 14 | import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService; |
| 15 | +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService; | |
| 16 | +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; | |
| 17 | 17 | import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO; |
| 18 | 18 | import io.swagger.v3.oas.annotations.Operation; |
| 19 | 19 | import io.swagger.v3.oas.annotations.Parameter; |
| ... | ... | @@ -92,20 +92,17 @@ public class BrokerageUserController { |
| 92 | 92 | Set<Long> userIds = convertSet(pageResult.getList(), BrokerageUserDO::getId); |
| 93 | 93 | // 查询用户信息 |
| 94 | 94 | Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(userIds); |
| 95 | - // TODO @疯狂:看看下面两个 getBrokerageUserCountByBindUserId、getWithdrawSummaryByUserId 有没可能一次性出结果,不然 n 次有点太花性能了; | |
| 96 | 95 | // 合计分佣订单 |
| 97 | - Map<Long, UserBrokerageSummaryBO> userOrderSummaryMap = convertMap(userIds, | |
| 98 | - userId -> userId, | |
| 99 | - userId -> brokerageRecordService.getUserBrokerageSummaryByUserId(userId, | |
| 100 | - BrokerageRecordBizTypeEnum.ORDER.getType(), BrokerageRecordStatusEnum.SETTLEMENT.getStatus())); | |
| 96 | + Map<Long, UserBrokerageSummaryBO> userOrderSummaryMap = brokerageRecordService.getUserBrokerageSummaryMapByUserId( | |
| 97 | + userIds, BrokerageRecordBizTypeEnum.ORDER.getType(), BrokerageRecordStatusEnum.SETTLEMENT.getStatus()); | |
| 98 | + // TODO @芋艿:看看下面 getBrokerageUserCountByBindUserId 有没可能一次性出结果,不然 n 次有点太花性能了; | |
| 101 | 99 | // 合计推广用户数量 |
| 102 | 100 | Map<Long, Long> brokerageUserCountMap = convertMap(userIds, |
| 103 | 101 | userId -> userId, |
| 104 | 102 | userId -> brokerageUserService.getBrokerageUserCountByBindUserId(userId, null)); |
| 105 | 103 | // 合计提现 |
| 106 | - Map<Long, UserWithdrawSummaryBO> withdrawMap = convertMap(userIds, | |
| 107 | - userId -> userId, | |
| 108 | - userId -> brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS)); | |
| 104 | + Map<Long, UserWithdrawSummaryBO> withdrawMap = brokerageWithdrawService.getWithdrawSummaryMapByUserId(userIds, | |
| 105 | + BrokerageWithdrawStatusEnum.AUDIT_SUCCESS); | |
| 109 | 106 | // 拼接返回 |
| 110 | 107 | return success(BrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, |
| 111 | 108 | userOrderSummaryMap, withdrawMap)); | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java
| ... | ... | @@ -27,6 +27,7 @@ import org.springframework.web.bind.annotation.*; |
| 27 | 27 | import javax.annotation.Resource; |
| 28 | 28 | import javax.validation.Valid; |
| 29 | 29 | import java.time.LocalDateTime; |
| 30 | +import java.util.Collections; | |
| 30 | 31 | import java.util.Map; |
| 31 | 32 | import java.util.Optional; |
| 32 | 33 | |
| ... | ... | @@ -76,23 +77,25 @@ public class AppBrokerageUserController { |
| 76 | 77 | @Operation(summary = "获得个人分销统计") |
| 77 | 78 | @PreAuthenticated |
| 78 | 79 | public CommonResult<AppBrokerageUserMySummaryRespVO> getBrokerageUserSummary() { |
| 79 | - Long userId = getLoginUserId(); | |
| 80 | - // TODO @疯狂:后面这种,要不也改成 convert;感觉 controller 这样更容易看到整体;核心其实是 86、8/87、9/90、9/91 这阶段 | |
| 81 | - // 统计 yesterdayPrice、withdrawPrice、firstBrokerageUserCount、secondBrokerageUserCount 字段 | |
| 80 | + // 查询当前登录用户信息 | |
| 81 | + BrokerageUserDO brokerageUser = brokerageUserService.getBrokerageUser(getLoginUserId()); | |
| 82 | + // 统计用户昨日的佣金 | |
| 82 | 83 | LocalDateTime yesterday = LocalDateTime.now().minusDays(1); |
| 83 | 84 | LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday); |
| 84 | 85 | LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday); |
| 85 | - AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO() | |
| 86 | - .setYesterdayPrice(brokerageRecordService.getSummaryPriceByUserId(userId, BrokerageRecordBizTypeEnum.ORDER.getType(), beginTime, endTime)) | |
| 87 | - .setWithdrawPrice(Optional.ofNullable(brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS)) | |
| 88 | - .map(UserWithdrawSummaryBO::getPrice).orElse(0)) | |
| 89 | - .setBrokeragePrice(0).setFrozenPrice(0) | |
| 90 | - .setFirstBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1)) | |
| 91 | - .setSecondBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2)); | |
| 92 | - // 设置 brokeragePrice、frozenPrice 字段 | |
| 93 | - Optional.ofNullable(brokerageUserService.getBrokerageUser(userId)) | |
| 94 | - .ifPresent(user -> respVO.setBrokeragePrice(user.getBrokeragePrice()).setFrozenPrice(user.getFrozenPrice())); | |
| 95 | - return success(respVO); | |
| 86 | + Integer yesterdayPrice = brokerageRecordService.getSummaryPriceByUserId(brokerageUser.getId(), | |
| 87 | + BrokerageRecordBizTypeEnum.ORDER.getType(), beginTime, endTime); | |
| 88 | + // 统计用户提现的佣金 | |
| 89 | + Integer withdrawPrice = brokerageWithdrawService.getWithdrawSummaryByUserId(Collections.singleton(brokerageUser.getId()), | |
| 90 | + BrokerageWithdrawStatusEnum.AUDIT_SUCCESS).stream() | |
| 91 | + .findFirst().map(UserWithdrawSummaryBO::getPrice).orElse(0); | |
| 92 | + // 统计分销用户数量(一级) | |
| 93 | + Long firstBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(brokerageUser.getId(), 1); | |
| 94 | + // 统计分销用户数量(二级) | |
| 95 | + Long secondBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(brokerageUser.getId(), 2); | |
| 96 | + | |
| 97 | + // 拼接返回 | |
| 98 | + return success(BrokerageUserConvert.INSTANCE.convert(yesterdayPrice, withdrawPrice, firstBrokerageUserCount, secondBrokerageUserCount, brokerageUser)); | |
| 96 | 99 | } |
| 97 | 100 | |
| 98 | 101 | @GetMapping("/rank-page-by-user-count") | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.trade.convert.brokerage; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.map.MapUtil; |
| 4 | +import cn.hutool.core.util.ObjUtil; | |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 6 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| 6 | 7 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserRespVO; |
| 8 | +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserMySummaryRespVO; | |
| 7 | 9 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO; |
| 8 | 10 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; |
| 9 | 11 | import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; |
| ... | ... | @@ -71,4 +73,18 @@ public interface BrokerageUserConvert { |
| 71 | 73 | |
| 72 | 74 | void copyTo(MemberUserRespDTO from, @MappingTarget AppBrokerageUserRankByUserCountRespVO to); |
| 73 | 75 | |
| 76 | + default AppBrokerageUserMySummaryRespVO convert(Integer yesterdayPrice, Integer withdrawPrice, | |
| 77 | + Long firstBrokerageUserCount, Long secondBrokerageUserCount, | |
| 78 | + BrokerageUserDO brokerageUser) { | |
| 79 | + AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO() | |
| 80 | + .setYesterdayPrice(ObjUtil.defaultIfNull(yesterdayPrice, 0)) | |
| 81 | + .setWithdrawPrice(ObjUtil.defaultIfNull(withdrawPrice, 0)) | |
| 82 | + .setBrokeragePrice(0).setFrozenPrice(0) | |
| 83 | + .setFirstBrokerageUserCount(ObjUtil.defaultIfNull(firstBrokerageUserCount, 0L)) | |
| 84 | + .setSecondBrokerageUserCount(ObjUtil.defaultIfNull(secondBrokerageUserCount, 0L)); | |
| 85 | + // 设置 brokeragePrice、frozenPrice 字段 | |
| 86 | + Optional.ofNullable(brokerageUser) | |
| 87 | + .ifPresent(user -> respVO.setBrokeragePrice(user.getBrokeragePrice()).setFrozenPrice(user.getFrozenPrice())); | |
| 88 | + return respVO; | |
| 89 | + } | |
| 74 | 90 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.trade.dal.mysql.brokerage; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.bean.BeanUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | 6 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| ... | ... | @@ -9,12 +10,16 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; |
| 9 | 10 | import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; |
| 10 | 11 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| 11 | 12 | import com.baomidou.mybatisplus.core.metadata.IPage; |
| 13 | +import com.github.yulichang.toolkit.LambdaUtils; | |
| 14 | +import com.github.yulichang.toolkit.MPJWrappers; | |
| 12 | 15 | import org.apache.ibatis.annotations.Mapper; |
| 13 | 16 | import org.apache.ibatis.annotations.Param; |
| 14 | 17 | import org.apache.ibatis.annotations.Select; |
| 15 | 18 | |
| 16 | 19 | import java.time.LocalDateTime; |
| 20 | +import java.util.Collection; | |
| 17 | 21 | import java.util.List; |
| 22 | +import java.util.Map; | |
| 18 | 23 | |
| 19 | 24 | /** |
| 20 | 25 | * 佣金记录 Mapper |
| ... | ... | @@ -52,11 +57,27 @@ public interface BrokerageRecordMapper extends BaseMapperX<BrokerageRecordDO> { |
| 52 | 57 | BrokerageRecordDO::getUserId, userId); |
| 53 | 58 | } |
| 54 | 59 | |
| 55 | - @Select("SELECT COUNT(1), SUM(price) FROM trade_brokerage_record " + | |
| 56 | - "WHERE user_id = #{userId} AND biz_type = #{bizType} AND status = #{status} AND deleted = FALSE") | |
| 57 | - UserBrokerageSummaryBO selectCountAndSumPriceByUserIdAndBizTypeAndStatus(@Param("userId") Long userId, | |
| 58 | - @Param("bizType") Integer bizType, | |
| 59 | - @Param("status") Integer status); | |
| 60 | + default List<UserBrokerageSummaryBO> selectCountAndSumPriceByUserIdInAndBizTypeAndStatus(Collection<Long> userIds, | |
| 61 | + Integer bizType, | |
| 62 | + Integer status) { | |
| 63 | + List<Map<String, Object>> list = selectMaps(MPJWrappers.lambdaJoin(BrokerageRecordDO.class) | |
| 64 | + .select(BrokerageRecordDO::getUserId) | |
| 65 | + .selectCount(BrokerageRecordDO::getId, LambdaUtils.getName(UserBrokerageSummaryBO::getCount)) | |
| 66 | + .selectSum(BrokerageRecordDO::getPrice) | |
| 67 | + .in(BrokerageRecordDO::getUserId, userIds) | |
| 68 | + .eq(BrokerageRecordDO::getBizId, bizType) | |
| 69 | + .eq(BrokerageRecordDO::getStatus, status) | |
| 70 | + .groupBy(BrokerageRecordDO::getUserId)); | |
| 71 | + return BeanUtil.copyToList(list, UserBrokerageSummaryBO.class); | |
| 72 | +// return selectJoinList(UserBrokerageSummaryBO.class, MPJWrappers.lambdaJoin(BrokerageRecordDO.class) | |
| 73 | +// .select(BrokerageRecordDO::getUserId) | |
| 74 | +// .selectCount(BrokerageRecordDO::getId, LambdaUtils.getName(UserBrokerageSummaryBO::getCount)) | |
| 75 | +// .selectSum(BrokerageRecordDO::getPrice) | |
| 76 | +// .in(BrokerageRecordDO::getUserId, userIds) | |
| 77 | +// .eq(BrokerageRecordDO::getBizId, bizType) | |
| 78 | +// .eq(BrokerageRecordDO::getStatus, status) | |
| 79 | +// .groupBy(BrokerageRecordDO::getUserId)); | |
| 80 | + } | |
| 60 | 81 | |
| 61 | 82 | @Select("SELECT SUM(price) FROM trade_brokerage_record " + |
| 62 | 83 | "WHERE user_id = #{userId} AND biz_type = #{bizType} " + | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.trade.dal.mysql.brokerage; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.bean.BeanUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | 6 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| ... | ... | @@ -7,9 +8,13 @@ import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.Brok |
| 7 | 8 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; |
| 8 | 9 | import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO; |
| 9 | 10 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| 11 | +import com.github.yulichang.toolkit.LambdaUtils; | |
| 12 | +import com.github.yulichang.wrapper.MPJLambdaWrapper; | |
| 10 | 13 | import org.apache.ibatis.annotations.Mapper; |
| 11 | -import org.apache.ibatis.annotations.Param; | |
| 12 | -import org.apache.ibatis.annotations.Select; | |
| 14 | + | |
| 15 | +import java.util.Collection; | |
| 16 | +import java.util.List; | |
| 17 | +import java.util.Map; | |
| 13 | 18 | |
| 14 | 19 | /** |
| 15 | 20 | * 佣金提现 Mapper |
| ... | ... | @@ -37,9 +42,23 @@ public interface BrokerageWithdrawMapper extends BaseMapperX<BrokerageWithdrawDO |
| 37 | 42 | .eq(BrokerageWithdrawDO::getStatus, status)); |
| 38 | 43 | } |
| 39 | 44 | |
| 40 | - @Select("SELECT COUNT(1) AS count, SUM(price) AS price FROM trade_brokerage_withdraw " + | |
| 41 | - "WHERE user_id = #{userId} AND status = #{status} AND deleted = FALSE") | |
| 42 | - UserWithdrawSummaryBO selectCountAndSumPriceByUserIdAndStatus(@Param("userId") Long userId, | |
| 43 | - @Param("status") Integer status); | |
| 45 | + default List<UserWithdrawSummaryBO> selectCountAndSumPriceByUserIdAndStatus(Collection<Long> userIds, Integer status) { | |
| 46 | + List<Map<String, Object>> list = selectMaps(new MPJLambdaWrapper<BrokerageWithdrawDO>() | |
| 47 | + .select(BrokerageWithdrawDO::getUserId) | |
| 48 | + .selectCount(BrokerageWithdrawDO::getId, LambdaUtils.getName(UserWithdrawSummaryBO::getCount)) | |
| 49 | + .selectSum(BrokerageWithdrawDO::getPrice) | |
| 50 | + .in(BrokerageWithdrawDO::getUserId, userIds) | |
| 51 | + .eq(BrokerageWithdrawDO::getStatus, status) | |
| 52 | + .groupBy(BrokerageWithdrawDO::getUserId)); | |
| 53 | + return BeanUtil.copyToList(list, UserWithdrawSummaryBO.class); | |
| 54 | + // selectJoinList有BUG,会与租户插件冲突:解析SQL时,发生异常 https://gitee.com/best_handsome/mybatis-plus-join/issues/I84GYW | |
| 55 | +// return selectJoinList(UserWithdrawSummaryBO.class, new MPJLambdaWrapper<BrokerageWithdrawDO>() | |
| 56 | +// .select(BrokerageWithdrawDO::getUserId) | |
| 57 | +// .selectCount(BrokerageWithdrawDO::getId, LambdaUtils.getName(UserWithdrawSummaryBO::getCount)) | |
| 58 | +// .selectSum(BrokerageWithdrawDO::getPrice) | |
| 59 | +// .in(BrokerageWithdrawDO::getUserId, userIds) | |
| 60 | +// .eq(BrokerageWithdrawDO::getStatus, status) | |
| 61 | +// .groupBy(BrokerageWithdrawDO::getUserId)); | |
| 62 | + } | |
| 44 | 63 | |
| 45 | 64 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java
| ... | ... | @@ -12,7 +12,11 @@ import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO |
| 12 | 12 | |
| 13 | 13 | import javax.validation.Valid; |
| 14 | 14 | import java.time.LocalDateTime; |
| 15 | +import java.util.Collection; | |
| 15 | 16 | import java.util.List; |
| 17 | +import java.util.Map; | |
| 18 | + | |
| 19 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | |
| 16 | 20 | |
| 17 | 21 | /** |
| 18 | 22 | * 佣金记录 Service 接口 |
| ... | ... | @@ -76,12 +80,24 @@ public interface BrokerageRecordService { |
| 76 | 80 | /** |
| 77 | 81 | * 汇总用户佣金 |
| 78 | 82 | * |
| 79 | - * @param userId 用户编号 | |
| 83 | + * @param userIds 用户编号 | |
| 84 | + * @param bizType 业务类型 | |
| 85 | + * @param status 佣金状态 | |
| 86 | + * @return 用户佣金汇总 | |
| 87 | + */ | |
| 88 | + List<UserBrokerageSummaryBO> getUserBrokerageSummaryByUserId(Collection<Long> userIds, Integer bizType, Integer status); | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * 汇总用户佣金 | |
| 92 | + * | |
| 93 | + * @param userIds 用户编号 | |
| 80 | 94 | * @param bizType 业务类型 |
| 81 | 95 | * @param status 佣金状态 |
| 82 | 96 | * @return 用户佣金汇总 |
| 83 | 97 | */ |
| 84 | - UserBrokerageSummaryBO getUserBrokerageSummaryByUserId(Long userId, Integer bizType, Integer status); | |
| 98 | + default Map<Long, UserBrokerageSummaryBO> getUserBrokerageSummaryMapByUserId(Collection<Long> userIds, Integer bizType, Integer status) { | |
| 99 | + return convertMap(getUserBrokerageSummaryByUserId(userIds, bizType, status), UserBrokerageSummaryBO::getUserId); | |
| 100 | + } | |
| 85 | 101 | |
| 86 | 102 | /** |
| 87 | 103 | * 获得用户佣金合计 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java
| ... | ... | @@ -36,10 +36,7 @@ import org.springframework.validation.annotation.Validated; |
| 36 | 36 | |
| 37 | 37 | import javax.annotation.Resource; |
| 38 | 38 | import java.time.LocalDateTime; |
| 39 | -import java.util.ArrayList; | |
| 40 | -import java.util.List; | |
| 41 | -import java.util.Objects; | |
| 42 | -import java.util.Optional; | |
| 39 | +import java.util.*; | |
| 43 | 40 | |
| 44 | 41 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 45 | 42 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getMaxValue; |
| ... | ... | @@ -235,9 +232,8 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { |
| 235 | 232 | } |
| 236 | 233 | |
| 237 | 234 | @Override |
| 238 | - public UserBrokerageSummaryBO getUserBrokerageSummaryByUserId(Long userId, Integer bizType, Integer status) { | |
| 239 | - UserBrokerageSummaryBO summaryBO = brokerageRecordMapper.selectCountAndSumPriceByUserIdAndBizTypeAndStatus(userId, bizType, status); | |
| 240 | - return summaryBO != null ? summaryBO : new UserBrokerageSummaryBO(0, 0); | |
| 235 | + public List<UserBrokerageSummaryBO> getUserBrokerageSummaryByUserId(Collection<Long> userIds, Integer bizType, Integer status) { | |
| 236 | + return brokerageRecordMapper.selectCountAndSumPriceByUserIdInAndBizTypeAndStatus(userIds, bizType, status); | |
| 241 | 237 | } |
| 242 | 238 | |
| 243 | 239 | @Override |
| ... | ... | @@ -338,7 +334,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { |
| 338 | 334 | if (BooleanUtil.isTrue(spu.getSubCommissionType())) { |
| 339 | 335 | fixedMinPrice = getMinValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice); |
| 340 | 336 | fixedMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice); |
| 341 | - // 3.2 全局分佣模式(根据商品价格比例计算) | |
| 337 | + // 3.2 全局分佣模式(根据商品价格比例计算) | |
| 342 | 338 | } else { |
| 343 | 339 | spuMinPrice = getMinValue(skuList, ProductSkuRespDTO::getPrice); |
| 344 | 340 | spuMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getPrice); | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java
| 1 | 1 | package cn.iocoder.yudao.module.trade.service.brokerage; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; | |
| 5 | 4 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO; |
| 6 | 5 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryPageReqVO; |
| 7 | 6 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO; |
| ... | ... | @@ -111,21 +110,7 @@ public interface BrokerageUserService { |
| 111 | 110 | * @param registerTime 用户注册时间 |
| 112 | 111 | * @return 是否绑定 |
| 113 | 112 | */ |
| 114 | - default boolean bindBrokerageUser(@NotNull Long userId, @NotNull Long bindUserId, @NotNull LocalDateTime registerTime) { | |
| 115 | - // 注册时间在30秒内的,都算新用户 | |
| 116 | - boolean isNewUser = LocalDateTimeUtils.afterNow(registerTime.minusSeconds(30)); | |
| 117 | - return bindBrokerageUser(userId, bindUserId, isNewUser); | |
| 118 | - } | |
| 119 | - | |
| 120 | - /** | |
| 121 | - * 【会员】绑定推广员 | |
| 122 | - * | |
| 123 | - * @param userId 用户编号 | |
| 124 | - * @param bindUserId 推广员编号 | |
| 125 | - * @param isNewUser 是否为新用户 | |
| 126 | - * @return 是否绑定 | |
| 127 | - */ | |
| 128 | - boolean bindBrokerageUser(Long userId, Long bindUserId, Boolean isNewUser); | |
| 113 | + boolean bindBrokerageUser(@NotNull Long userId, @NotNull Long bindUserId, @NotNull LocalDateTime registerTime); | |
| 129 | 114 | |
| 130 | 115 | /** |
| 131 | 116 | * 获取用户是否有分销资格 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java
| ... | ... | @@ -5,6 +5,7 @@ import cn.hutool.core.lang.Assert; |
| 5 | 5 | import cn.hutool.core.util.ArrayUtil; |
| 6 | 6 | import cn.hutool.core.util.BooleanUtil; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | +import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; | |
| 8 | 9 | import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; |
| 9 | 10 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO; |
| 10 | 11 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryPageReqVO; |
| ... | ... | @@ -154,7 +155,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { |
| 154 | 155 | } |
| 155 | 156 | |
| 156 | 157 | @Override |
| 157 | - public boolean bindBrokerageUser(Long userId, Long bindUserId, Boolean isNewUser) { | |
| 158 | + public boolean bindBrokerageUser(Long userId, Long bindUserId, LocalDateTime registerTime) { | |
| 158 | 159 | // 1. 获得分销用户 |
| 159 | 160 | boolean isNewBrokerageUser = false; |
| 160 | 161 | BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(userId); |
| ... | ... | @@ -164,7 +165,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { |
| 164 | 165 | } |
| 165 | 166 | |
| 166 | 167 | // 2.1 校验是否能绑定用户 |
| 167 | - boolean validated = isUserCanBind(brokerageUser, isNewUser); | |
| 168 | + boolean validated = isUserCanBind(brokerageUser, registerTime); | |
| 168 | 169 | if (!validated) { |
| 169 | 170 | return false; |
| 170 | 171 | } |
| ... | ... | @@ -222,7 +223,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { |
| 222 | 223 | return new PageResult<>(pageResult.getRecords(), pageResult.getTotal()); |
| 223 | 224 | } |
| 224 | 225 | |
| 225 | - private boolean isUserCanBind(BrokerageUserDO user, Boolean isNewUser) { | |
| 226 | + private boolean isUserCanBind(BrokerageUserDO user, LocalDateTime registerTime) { | |
| 226 | 227 | // 校验分销功能是否启用 |
| 227 | 228 | TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig(); |
| 228 | 229 | if (tradeConfig == null || !BooleanUtil.isTrue(tradeConfig.getBrokerageEnabled())) { |
| ... | ... | @@ -236,8 +237,9 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { |
| 236 | 237 | |
| 237 | 238 | // 校验分销关系绑定模式 |
| 238 | 239 | if (BrokerageBindModeEnum.REGISTER.getMode().equals(tradeConfig.getBrokerageBindMode())) { |
| 239 | - // TODO @疯狂:是不是把 isNewUser 挪到这里好点呀? | |
| 240 | - if (!BooleanUtil.isTrue(isNewUser)) { | |
| 240 | + // 判断是否为新用户:注册时间在30秒内的,都算新用户 | |
| 241 | + boolean isNotNewUser = LocalDateTimeUtils.beforeNow(registerTime.plusSeconds(30)); | |
| 242 | + if (isNotNewUser) { | |
| 241 | 243 | throw exception(BROKERAGE_BIND_MODE_REGISTER); // 只有在注册时可以绑定 |
| 242 | 244 | } |
| 243 | 245 | } else if (BrokerageBindModeEnum.ANYTIME.getMode().equals(tradeConfig.getBrokerageBindMode())) { | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java
| ... | ... | @@ -7,6 +7,13 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawD |
| 7 | 7 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; |
| 8 | 8 | import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO; |
| 9 | 9 | |
| 10 | +import java.util.Collection; | |
| 11 | +import java.util.List; | |
| 12 | +import java.util.Map; | |
| 13 | +import java.util.Set; | |
| 14 | + | |
| 15 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | |
| 16 | + | |
| 10 | 17 | /** |
| 11 | 18 | * 佣金提现 Service 接口 |
| 12 | 19 | * |
| ... | ... | @@ -51,10 +58,20 @@ public interface BrokerageWithdrawService { |
| 51 | 58 | /** |
| 52 | 59 | * 汇总用户提现 |
| 53 | 60 | * |
| 54 | - * @param userId 用户编号 | |
| 55 | - * @param status 提现状态 | |
| 61 | + * @param userIds 用户编号 | |
| 62 | + * @param status 提现状态 | |
| 56 | 63 | * @return 用户提现汇总 |
| 57 | 64 | */ |
| 58 | - UserWithdrawSummaryBO getWithdrawSummaryByUserId(Long userId, BrokerageWithdrawStatusEnum status); | |
| 65 | + List<UserWithdrawSummaryBO> getWithdrawSummaryByUserId(Collection<Long> userIds, BrokerageWithdrawStatusEnum status); | |
| 59 | 66 | |
| 67 | + /** | |
| 68 | + * 汇总用户提现 | |
| 69 | + * | |
| 70 | + * @param userIds 用户编号 | |
| 71 | + * @param status 提现状态 | |
| 72 | + * @return 用户提现汇总 | |
| 73 | + */ | |
| 74 | + default Map<Long, UserWithdrawSummaryBO> getWithdrawSummaryMapByUserId(Set<Long> userIds, BrokerageWithdrawStatusEnum status) { | |
| 75 | + return convertMap(getWithdrawSummaryByUserId(userIds, status), UserWithdrawSummaryBO::getUserId); | |
| 76 | + } | |
| 60 | 77 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java
| ... | ... | @@ -26,6 +26,8 @@ import org.springframework.validation.annotation.Validated; |
| 26 | 26 | import javax.annotation.Resource; |
| 27 | 27 | import javax.validation.Validator; |
| 28 | 28 | import java.time.LocalDateTime; |
| 29 | +import java.util.Collection; | |
| 30 | +import java.util.List; | |
| 29 | 31 | import java.util.Map; |
| 30 | 32 | |
| 31 | 33 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| ... | ... | @@ -142,9 +144,8 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { |
| 142 | 144 | } |
| 143 | 145 | |
| 144 | 146 | @Override |
| 145 | - public UserWithdrawSummaryBO getWithdrawSummaryByUserId(Long userId, BrokerageWithdrawStatusEnum status) { | |
| 146 | - UserWithdrawSummaryBO summaryBO = brokerageWithdrawMapper.selectCountAndSumPriceByUserIdAndStatus(userId, status.getStatus()); | |
| 147 | - return summaryBO != null ? summaryBO : new UserWithdrawSummaryBO(0, 0); | |
| 147 | + public List<UserWithdrawSummaryBO> getWithdrawSummaryByUserId(Collection<Long> userIds, BrokerageWithdrawStatusEnum status) { | |
| 148 | + return brokerageWithdrawMapper.selectCountAndSumPriceByUserIdAndStatus(userIds, status.getStatus()); | |
| 148 | 149 | } |
| 149 | 150 | |
| 150 | 151 | /** | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryBO.java
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserWithdrawSummaryBO.java