Commit 972b01c001e95edd83e9649c6e37a76ce2252154
1 parent
7a8a440e
分佣: 佣金排行
Showing
5 changed files
with
81 additions
and
17 deletions
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java
| ... | ... | @@ -4,7 +4,10 @@ import cn.hutool.core.date.LocalDateTimeUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 6 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; |
| 7 | +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; | |
| 8 | +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; | |
| 7 | 9 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.*; |
| 10 | +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert; | |
| 8 | 11 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; |
| 9 | 12 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; |
| 10 | 13 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; |
| ... | ... | @@ -22,9 +25,11 @@ import org.springframework.web.bind.annotation.*; |
| 22 | 25 | import javax.annotation.Resource; |
| 23 | 26 | import javax.validation.Valid; |
| 24 | 27 | import java.time.LocalDateTime; |
| 28 | +import java.util.Map; | |
| 25 | 29 | import java.util.Optional; |
| 26 | 30 | |
| 27 | 31 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 32 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | |
| 28 | 33 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
| 29 | 34 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 30 | 35 | import static java.util.Arrays.asList; |
| ... | ... | @@ -42,6 +47,9 @@ public class AppBrokerageUserController { |
| 42 | 47 | @Resource |
| 43 | 48 | private BrokerageWithdrawService brokerageWithdrawService; |
| 44 | 49 | |
| 50 | + @Resource | |
| 51 | + private MemberUserApi memberUserApi; | |
| 52 | + | |
| 45 | 53 | @GetMapping("/get") |
| 46 | 54 | @Operation(summary = "获得个人分销信息") |
| 47 | 55 | @PreAuthenticated |
| ... | ... | @@ -102,24 +110,15 @@ public class AppBrokerageUserController { |
| 102 | 110 | return success(new PageResult<>(asList(vo1, vo2, vo3, vo4), 10L)); |
| 103 | 111 | } |
| 104 | 112 | |
| 105 | - // TODO 芋艿:临时 mock => | |
| 106 | 113 | @GetMapping("/rank-page-by-price") |
| 107 | 114 | @Operation(summary = "获得分销用户排行分页(基于佣金)") |
| 108 | 115 | @PreAuthenticated |
| 109 | 116 | public CommonResult<PageResult<AppBrokerageUserRankByPriceRespVO>> getBrokerageUserChildSummaryPageByPrice(AppBrokerageUserRankPageReqVO pageReqVO) { |
| 110 | - AppBrokerageUserRankByPriceRespVO vo1 = new AppBrokerageUserRankByPriceRespVO() | |
| 111 | - .setId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") | |
| 112 | - .setBrokeragePrice(10); | |
| 113 | - AppBrokerageUserRankByPriceRespVO vo2 = new AppBrokerageUserRankByPriceRespVO() | |
| 114 | - .setId(2L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") | |
| 115 | - .setBrokeragePrice(6); | |
| 116 | - AppBrokerageUserRankByPriceRespVO vo3 = new AppBrokerageUserRankByPriceRespVO() | |
| 117 | - .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") | |
| 118 | - .setBrokeragePrice(4); | |
| 119 | - AppBrokerageUserRankByPriceRespVO vo4 = new AppBrokerageUserRankByPriceRespVO() | |
| 120 | - .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") | |
| 121 | - .setBrokeragePrice(4); | |
| 122 | - return success(new PageResult<>(asList(vo1, vo2, vo3, vo4), 10L)); | |
| 117 | + // 分页查询 | |
| 118 | + PageResult<AppBrokerageUserRankByPriceRespVO> pageResult = brokerageRecordService.getBrokerageUserChildSummaryPageByPrice(pageReqVO); | |
| 119 | + // 拼接数据 | |
| 120 | + Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(convertSet(pageResult.getList(), AppBrokerageUserRankByPriceRespVO::getId)); | |
| 121 | + return success(BrokerageRecordConvert.INSTANCE.convertPage03(pageResult, userMap)); | |
| 123 | 122 | } |
| 124 | 123 | |
| 125 | 124 | // TODO 芋艿:临时 mock => |
| ... | ... | @@ -139,13 +138,12 @@ public class AppBrokerageUserController { |
| 139 | 138 | return success(new PageResult<>(asList(vo1, vo2), 10L)); |
| 140 | 139 | } |
| 141 | 140 | |
| 142 | - // TODO 芋艿:临时 mock => | |
| 143 | 141 | @GetMapping("/get-rank-by-price") |
| 144 | 142 | @Operation(summary = "获得分销用户排行(基于佣金)") |
| 145 | 143 | @Parameter(name = "times", description = "时间段", required = true) |
| 146 | - public CommonResult<Integer> bindBrokerageUser( | |
| 144 | + public CommonResult<Integer> getRankByPrice( | |
| 147 | 145 | @RequestParam("times") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) LocalDateTime[] times) { |
| 148 | - return success(1); | |
| 146 | + return success(brokerageRecordService.getUserRankByPrice(getLoginUserId(), times)); | |
| 149 | 147 | } |
| 150 | 148 | |
| 151 | 149 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java
| ... | ... | @@ -9,11 +9,13 @@ import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.Broker |
| 9 | 9 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordRespVO; |
| 10 | 10 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordPageReqVO; |
| 11 | 11 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordRespVO; |
| 12 | +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO; | |
| 12 | 13 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; |
| 13 | 14 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; |
| 14 | 15 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; |
| 15 | 16 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; |
| 16 | 17 | import org.mapstruct.Mapper; |
| 18 | +import org.mapstruct.MappingTarget; | |
| 17 | 19 | import org.mapstruct.factory.Mappers; |
| 18 | 20 | |
| 19 | 21 | import java.time.LocalDateTime; |
| ... | ... | @@ -68,4 +70,13 @@ public interface BrokerageRecordConvert { |
| 68 | 70 | BrokerageRecordPageReqVO convert(AppBrokerageRecordPageReqVO pageReqVO, Long userId); |
| 69 | 71 | |
| 70 | 72 | PageResult<AppBrokerageRecordRespVO> convertPage02(PageResult<BrokerageRecordDO> pageResult); |
| 73 | + | |
| 74 | + default PageResult<AppBrokerageUserRankByPriceRespVO> convertPage03(PageResult<AppBrokerageUserRankByPriceRespVO> pageResult, Map<Long, MemberUserRespDTO> userMap) { | |
| 75 | + for (AppBrokerageUserRankByPriceRespVO vo : pageResult.getList()) { | |
| 76 | + copyTo(userMap.get(vo.getId()), vo); | |
| 77 | + } | |
| 78 | + return pageResult; | |
| 79 | + } | |
| 80 | + | |
| 81 | + void copyTo(MemberUserRespDTO from, @MappingTarget AppBrokerageUserRankByPriceRespVO to); | |
| 71 | 82 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java
| ... | ... | @@ -4,9 +4,11 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | 6 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO; |
| 7 | +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO; | |
| 7 | 8 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; |
| 8 | 9 | import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; |
| 9 | 10 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| 11 | +import com.baomidou.mybatisplus.core.metadata.IPage; | |
| 10 | 12 | import org.apache.ibatis.annotations.Mapper; |
| 11 | 13 | import org.apache.ibatis.annotations.Param; |
| 12 | 14 | import org.apache.ibatis.annotations.Select; |
| ... | ... | @@ -63,4 +65,14 @@ public interface BrokerageRecordMapper extends BaseMapperX<BrokerageRecordDO> { |
| 63 | 65 | @Param("bizType") Integer bizType, |
| 64 | 66 | @Param("beginTime") LocalDateTime beginTime, |
| 65 | 67 | @Param("endTime") LocalDateTime endTime); |
| 68 | + | |
| 69 | + @Select("SELECT user_id AS id, SUM(price) AS brokeragePrice FROM trade_brokerage_record " + | |
| 70 | + "WHERE biz_type = #{bizType} AND status = #{status} AND create_time BETWEEN #{beginTime} AND #{endTime} " + | |
| 71 | + "GROUP BY user_id " + | |
| 72 | + "ORDER BY SUM(price) DESC") | |
| 73 | + IPage<AppBrokerageUserRankByPriceRespVO> selectSummaryPricePageGroupByUserId(IPage<?> page, | |
| 74 | + @Param("bizType") Integer bizType, | |
| 75 | + @Param("status") Integer status, | |
| 76 | + @Param("beginTime") LocalDateTime beginTime, | |
| 77 | + @Param("endTime") LocalDateTime endTime); | |
| 66 | 78 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java
| ... | ... | @@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.trade.service.brokerage; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO; |
| 5 | +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO; | |
| 6 | +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO; | |
| 5 | 7 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; |
| 6 | 8 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; |
| 7 | 9 | import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; |
| ... | ... | @@ -90,4 +92,20 @@ public interface BrokerageRecordService { |
| 90 | 92 | * @return 用户佣金合计 |
| 91 | 93 | */ |
| 92 | 94 | Integer getSummaryPriceByUserId(Long userId, Integer bizType, LocalDateTime beginTime, LocalDateTime endTime); |
| 95 | + | |
| 96 | + /** | |
| 97 | + * 获得用户佣金排行分页列表(基于佣金总数) | |
| 98 | + * @param pageReqVO 分页查询 | |
| 99 | + * @return 排行榜分页 | |
| 100 | + */ | |
| 101 | + PageResult<AppBrokerageUserRankByPriceRespVO> getBrokerageUserChildSummaryPageByPrice(AppBrokerageUserRankPageReqVO pageReqVO); | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * 获取用户的排名(基于佣金总数) | |
| 105 | + * | |
| 106 | + * @param userId 用户编号 | |
| 107 | + * @param times 时间范围 | |
| 108 | + * @return 用户的排名 | |
| 109 | + */ | |
| 110 | + Integer getUserRankByPrice(Long userId, LocalDateTime[] times); | |
| 93 | 111 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java
| ... | ... | @@ -2,13 +2,17 @@ package cn.iocoder.yudao.module.trade.service.brokerage; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.math.Money; |
| 5 | +import cn.hutool.core.util.ArrayUtil; | |
| 5 | 6 | import cn.hutool.core.util.BooleanUtil; |
| 6 | 7 | import cn.hutool.core.util.ObjectUtil; |
| 7 | 8 | import cn.hutool.core.util.StrUtil; |
| 8 | 9 | import cn.hutool.extra.spring.SpringUtil; |
| 9 | 10 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 10 | 11 | import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; |
| 12 | +import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; | |
| 11 | 13 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO; |
| 14 | +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO; | |
| 15 | +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO; | |
| 12 | 16 | import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert; |
| 13 | 17 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; |
| 14 | 18 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; |
| ... | ... | @@ -19,6 +23,7 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; |
| 19 | 23 | import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; |
| 20 | 24 | import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; |
| 21 | 25 | import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; |
| 26 | +import com.baomidou.mybatisplus.core.metadata.IPage; | |
| 22 | 27 | import lombok.extern.slf4j.Slf4j; |
| 23 | 28 | import org.springframework.stereotype.Service; |
| 24 | 29 | import org.springframework.transaction.annotation.Transactional; |
| ... | ... | @@ -228,6 +233,26 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { |
| 228 | 233 | } |
| 229 | 234 | |
| 230 | 235 | @Override |
| 236 | + public PageResult<AppBrokerageUserRankByPriceRespVO> getBrokerageUserChildSummaryPageByPrice(AppBrokerageUserRankPageReqVO pageReqVO) { | |
| 237 | + IPage<AppBrokerageUserRankByPriceRespVO> pageResult = brokerageRecordMapper.selectSummaryPricePageGroupByUserId(MyBatisUtils.buildPage(pageReqVO), | |
| 238 | + BrokerageRecordBizTypeEnum.ORDER.getType(), BrokerageRecordStatusEnum.SETTLEMENT.getStatus(), | |
| 239 | + ArrayUtil.get(pageReqVO.getTimes(), 0), ArrayUtil.get(pageReqVO.getTimes(), 1)); | |
| 240 | + return new PageResult<>(pageResult.getRecords(), pageResult.getTotal()); | |
| 241 | + } | |
| 242 | + | |
| 243 | + @Override | |
| 244 | + public Integer getUserRankByPrice(Long userId, LocalDateTime[] times) { | |
| 245 | + AppBrokerageUserRankPageReqVO pageParam = new AppBrokerageUserRankPageReqVO().setTimes(times); | |
| 246 | + // 取前100名 | |
| 247 | + pageParam.setPageSize(100); | |
| 248 | + PageResult<AppBrokerageUserRankByPriceRespVO> pageResult = getBrokerageUserChildSummaryPageByPrice(pageParam); | |
| 249 | + // 获得索引 | |
| 250 | + int index = CollUtil.indexOf(pageResult.getList(), user -> Objects.equals(userId, user.getId())); | |
| 251 | + // 获得排名 | |
| 252 | + return index + 1; | |
| 253 | + } | |
| 254 | + | |
| 255 | + @Override | |
| 231 | 256 | @Transactional(rollbackFor = Exception.class) |
| 232 | 257 | public void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, Integer brokeragePrice, String title) { |
| 233 | 258 | // 校验佣金余额 | ... | ... |