Commit aaa01de21d5937451c3282ad58e4efc117a041aa
1 parent
d0d21b27
分销:修改佣金排名查询算法
Showing
4 changed files
with
32 additions
and
19 deletions
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java
| ... | ... | @@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert; |
| 11 | 11 | import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageUserConvert; |
| 12 | 12 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; |
| 13 | 13 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; |
| 14 | +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; | |
| 14 | 15 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; |
| 15 | 16 | import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService; |
| 16 | 17 | import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService; |
| ... | ... | @@ -84,7 +85,7 @@ public class AppBrokerageUserController { |
| 84 | 85 | LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday); |
| 85 | 86 | LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday); |
| 86 | 87 | Integer yesterdayPrice = brokerageRecordService.getSummaryPriceByUserId(brokerageUser.getId(), |
| 87 | - BrokerageRecordBizTypeEnum.ORDER.getType(), beginTime, endTime); | |
| 88 | + BrokerageRecordBizTypeEnum.ORDER, BrokerageRecordStatusEnum.SETTLEMENT, beginTime, endTime); | |
| 88 | 89 | // 统计用户提现的佣金 |
| 89 | 90 | Integer withdrawPrice = brokerageWithdrawService.getWithdrawSummaryListByUserId(Collections.singleton(brokerageUser.getId()), |
| 90 | 91 | BrokerageWithdrawStatusEnum.AUDIT_SUCCESS).stream() | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java
| ... | ... | @@ -80,10 +80,11 @@ public interface BrokerageRecordMapper extends BaseMapperX<BrokerageRecordDO> { |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | @Select("SELECT SUM(price) FROM trade_brokerage_record " + |
| 83 | - "WHERE user_id = #{userId} AND biz_type = #{bizType} " + | |
| 84 | - "AND create_time BETWEEN #{beginTime} AND #{endTime} AND deleted = FALSE") | |
| 83 | + "WHERE user_id = #{userId} AND biz_type = #{bizType} AND status = #{status} " + | |
| 84 | + "AND unfreeze_time BETWEEN #{beginTime} AND #{endTime} AND deleted = FALSE") | |
| 85 | 85 | Integer selectSummaryPriceByUserIdAndBizTypeAndCreateTimeBetween(@Param("userId") Long userId, |
| 86 | 86 | @Param("bizType") Integer bizType, |
| 87 | + @Param("status") Integer status, | |
| 87 | 88 | @Param("beginTime") LocalDateTime beginTime, |
| 88 | 89 | @Param("endTime") LocalDateTime endTime); |
| 89 | 90 | |
| ... | ... | @@ -98,4 +99,13 @@ public interface BrokerageRecordMapper extends BaseMapperX<BrokerageRecordDO> { |
| 98 | 99 | @Param("beginTime") LocalDateTime beginTime, |
| 99 | 100 | @Param("endTime") LocalDateTime endTime); |
| 100 | 101 | |
| 102 | + @Select("SELECT COUNT(1) FROM trade_brokerage_record " + | |
| 103 | + "WHERE biz_type = #{bizType} AND status = #{status} AND deleted = FALSE " + | |
| 104 | + "AND unfreeze_time BETWEEN #{beginTime} AND #{endTime} " + | |
| 105 | + "GROUP BY user_id HAVING SUM(price) > #{brokeragePrice}") | |
| 106 | + Integer selectCountByPriceGt(@Param("brokeragePrice") Integer brokeragePrice, | |
| 107 | + @Param("bizType") Integer bizType, | |
| 108 | + @Param("status") Integer status, | |
| 109 | + @Param("beginTime") LocalDateTime beginTime, | |
| 110 | + @Param("endTime") LocalDateTime endTime); | |
| 101 | 111 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java
| ... | ... | @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokera |
| 7 | 7 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO; |
| 8 | 8 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; |
| 9 | 9 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; |
| 10 | +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; | |
| 10 | 11 | import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; |
| 11 | 12 | import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryRespBO; |
| 12 | 13 | |
| ... | ... | @@ -120,11 +121,13 @@ public interface BrokerageRecordService { |
| 120 | 121 | * |
| 121 | 122 | * @param userId 用户编号 |
| 122 | 123 | * @param bizType 业务类型 |
| 124 | + * @param status 状态 | |
| 123 | 125 | * @param beginTime 开始时间 |
| 124 | 126 | * @param endTime 截止时间 |
| 125 | 127 | * @return 用户佣金合计 |
| 126 | 128 | */ |
| 127 | - Integer getSummaryPriceByUserId(Long userId, Integer bizType, LocalDateTime beginTime, LocalDateTime endTime); | |
| 129 | + Integer getSummaryPriceByUserId(Long userId, BrokerageRecordBizTypeEnum bizType, BrokerageRecordStatusEnum status, | |
| 130 | + LocalDateTime beginTime, LocalDateTime endTime); | |
| 128 | 131 | |
| 129 | 132 | /** |
| 130 | 133 | * 获得用户佣金排行分页列表(基于佣金总数) | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java
| ... | ... | @@ -2,10 +2,7 @@ package cn.iocoder.yudao.module.trade.service.brokerage; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.collection.ListUtil; |
| 5 | -import cn.hutool.core.util.ArrayUtil; | |
| 6 | -import cn.hutool.core.util.BooleanUtil; | |
| 7 | -import cn.hutool.core.util.ObjectUtil; | |
| 8 | -import cn.hutool.core.util.StrUtil; | |
| 5 | +import cn.hutool.core.util.*; | |
| 9 | 6 | import cn.hutool.extra.spring.SpringUtil; |
| 10 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 11 | 8 | import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; |
| ... | ... | @@ -265,9 +262,10 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { |
| 265 | 262 | } |
| 266 | 263 | |
| 267 | 264 | @Override |
| 268 | - public Integer getSummaryPriceByUserId(Long userId, Integer bizType, LocalDateTime beginTime, LocalDateTime endTime) { | |
| 269 | - return brokerageRecordMapper.selectSummaryPriceByUserIdAndBizTypeAndCreateTimeBetween(userId, bizType, | |
| 270 | - beginTime, endTime); | |
| 265 | + public Integer getSummaryPriceByUserId(Long userId, BrokerageRecordBizTypeEnum bizType, BrokerageRecordStatusEnum status, | |
| 266 | + LocalDateTime beginTime, LocalDateTime endTime) { | |
| 267 | + return brokerageRecordMapper.selectSummaryPriceByUserIdAndBizTypeAndCreateTimeBetween(userId, | |
| 268 | + bizType.getType(), status.getStatus(), beginTime, endTime); | |
| 271 | 269 | } |
| 272 | 270 | |
| 273 | 271 | @Override |
| ... | ... | @@ -279,17 +277,18 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { |
| 279 | 277 | return new PageResult<>(pageResult.getRecords(), pageResult.getTotal()); |
| 280 | 278 | } |
| 281 | 279 | |
| 282 | - // TODO @疯狂:这个要不我们先做精准的?先查询自己的推广金额,然后查询比该金额多的有多少人? | |
| 283 | 280 | @Override |
| 284 | 281 | public Integer getUserRankByPrice(Long userId, LocalDateTime[] times) { |
| 285 | - AppBrokerageUserRankPageReqVO pageParam = new AppBrokerageUserRankPageReqVO().setTimes(times); | |
| 286 | - // 取前 100 名 | |
| 287 | - pageParam.setPageSize(100); | |
| 288 | - PageResult<AppBrokerageUserRankByPriceRespVO> pageResult = getBrokerageUserChildSummaryPageByPrice(pageParam); | |
| 289 | - // 获得索引 | |
| 290 | - int index = CollUtil.indexOf(pageResult.getList(), user -> Objects.equals(userId, user.getId())); | |
| 282 | + // 用户的推广金额 | |
| 283 | + Integer price = brokerageRecordMapper.selectSummaryPriceByUserIdAndBizTypeAndCreateTimeBetween(userId, | |
| 284 | + BrokerageRecordBizTypeEnum.ORDER.getType(), BrokerageRecordStatusEnum.SETTLEMENT.getStatus(), | |
| 285 | + ArrayUtil.get(times, 0), ArrayUtil.get(times, 1)); | |
| 286 | + // 排在用户前面的人数 | |
| 287 | + Integer greaterCount = brokerageRecordMapper.selectCountByPriceGt(price, | |
| 288 | + BrokerageRecordBizTypeEnum.ORDER.getType(), BrokerageRecordStatusEnum.SETTLEMENT.getStatus(), | |
| 289 | + ArrayUtil.get(times, 0), ArrayUtil.get(times, 1)); | |
| 291 | 290 | // 获得排名 |
| 292 | - return index + 1; | |
| 291 | + return ObjUtil.defaultIfNull(greaterCount, 0) + 1; | |
| 293 | 292 | } |
| 294 | 293 | |
| 295 | 294 | @Override | ... | ... |