Commit f72a087007266c68de56e4e58882c7994686f93e

Authored by owen
1 parent 594e4d5f

分佣: 我的推广统计接口

yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java
1 package cn.iocoder.yudao.module.trade.controller.app.brokerage; 1 package cn.iocoder.yudao.module.trade.controller.app.brokerage;
2 2
  3 +import cn.hutool.core.date.LocalDateTimeUtil;
3 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; 6 import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
6 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.*; 7 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.*;
  8 +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
  9 +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
  10 +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService;
7 import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService; 11 import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService;
  12 +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService;
8 import io.swagger.v3.oas.annotations.Operation; 13 import io.swagger.v3.oas.annotations.Operation;
9 import io.swagger.v3.oas.annotations.Parameter; 14 import io.swagger.v3.oas.annotations.Parameter;
10 import io.swagger.v3.oas.annotations.tags.Tag; 15 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -16,6 +21,7 @@ import org.springframework.web.bind.annotation.*; @@ -16,6 +21,7 @@ import org.springframework.web.bind.annotation.*;
16 import javax.annotation.Resource; 21 import javax.annotation.Resource;
17 import javax.validation.Valid; 22 import javax.validation.Valid;
18 import java.time.LocalDateTime; 23 import java.time.LocalDateTime;
  24 +import java.util.Optional;
19 25
20 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 26 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
21 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; 27 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@@ -30,6 +36,10 @@ import static java.util.Arrays.asList; @@ -30,6 +36,10 @@ import static java.util.Arrays.asList;
30 public class AppBrokerageUserController { 36 public class AppBrokerageUserController {
31 @Resource 37 @Resource
32 private BrokerageUserService brokerageUserService; 38 private BrokerageUserService brokerageUserService;
  39 + @Resource
  40 + private BrokerageRecordService brokerageRecordService;
  41 + @Resource
  42 + private BrokerageWithdrawService brokerageWithdrawService;
33 43
34 // TODO 芋艿:临时 mock => 44 // TODO 芋艿:临时 mock =>
35 @GetMapping("/get") 45 @GetMapping("/get")
@@ -50,18 +60,24 @@ public class AppBrokerageUserController { @@ -50,18 +60,24 @@ public class AppBrokerageUserController {
50 return success(brokerageUserService.bindBrokerageUser(getLoginUserId(), reqVO.getBindUserId(), false)); 60 return success(brokerageUserService.bindBrokerageUser(getLoginUserId(), reqVO.getBindUserId(), false));
51 } 61 }
52 62
53 - // TODO 芋艿:临时 mock =>  
54 @GetMapping("/get-summary") 63 @GetMapping("/get-summary")
55 @Operation(summary = "获得个人分销统计") 64 @Operation(summary = "获得个人分销统计")
56 @PreAuthenticated 65 @PreAuthenticated
57 public CommonResult<AppBrokerageUserMySummaryRespVO> getBrokerageUserSummary() { 66 public CommonResult<AppBrokerageUserMySummaryRespVO> getBrokerageUserSummary() {
  67 + Long userId = getLoginUserId();
  68 + LocalDateTime yesterday = LocalDateTime.now().minusDays(1);
  69 + LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday);
  70 + LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday);
  71 +
58 AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO() 72 AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO()
59 - .setYesterdayPrice(1)  
60 - .setBrokeragePrice(2)  
61 - .setFrozenPrice(3)  
62 - .setWithdrawPrice(4)  
63 - .setFirstBrokerageUserCount(166)  
64 - .setSecondBrokerageUserCount(233); 73 + .setYesterdayPrice(brokerageRecordService.getSummaryPriceByUserId(userId, BrokerageRecordBizTypeEnum.ORDER.getType(), beginTime, endTime))
  74 + .setWithdrawPrice(brokerageWithdrawService.getSummaryPriceByUserIdAndStatus(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS.getStatus()))
  75 + .setBrokeragePrice(0)
  76 + .setFrozenPrice(0)
  77 + .setFirstBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1))
  78 + .setSecondBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2));
  79 + Optional.ofNullable(brokerageUserService.getBrokerageUser(userId))
  80 + .ifPresent(user -> respVO.setBrokeragePrice(user.getBrokeragePrice()).setFrozenPrice(user.getFrozenPrice()));
65 return success(respVO); 81 return success(respVO);
66 } 82 }
67 83
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java
@@ -20,9 +20,9 @@ public class AppBrokerageUserMySummaryRespVO { @@ -20,9 +20,9 @@ public class AppBrokerageUserMySummaryRespVO {
20 private Integer frozenPrice; 20 private Integer frozenPrice;
21 21
22 @Schema(description = "分销用户数量(一级)", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") 22 @Schema(description = "分销用户数量(一级)", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
23 - private Integer firstBrokerageUserCount; 23 + private Long firstBrokerageUserCount;
24 24
25 @Schema(description = "分销用户数量(二级)", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") 25 @Schema(description = "分销用户数量(二级)", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
26 - private Integer secondBrokerageUserCount; 26 + private Long secondBrokerageUserCount;
27 27
28 } 28 }
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java
@@ -57,4 +57,10 @@ public interface BrokerageRecordMapper extends BaseMapperX&lt;BrokerageRecordDO&gt; { @@ -57,4 +57,10 @@ public interface BrokerageRecordMapper extends BaseMapperX&lt;BrokerageRecordDO&gt; {
57 @Param("bizType") Integer bizType, 57 @Param("bizType") Integer bizType,
58 @Param("status") Integer status); 58 @Param("status") Integer status);
59 59
  60 + @Select("SELECT SUM(price) FROM trade_brokerage_record WHERE user_id = #{userId} AND biz_type = #{bizType} " +
  61 + "AND create_time BETWEEN #{beginTime} AND #{endTime}")
  62 + Integer selectSummaryPriceByUserIdAndBizTypeAndCreateTimeBetween(@Param("userId") Long userId,
  63 + @Param("bizType") Integer bizType,
  64 + @Param("beginTime") LocalDateTime beginTime,
  65 + @Param("endTime") LocalDateTime endTime);
60 } 66 }
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java
@@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.Brok @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.Brok
7 import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; 7 import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO;
8 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; 8 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
9 import org.apache.ibatis.annotations.Mapper; 9 import org.apache.ibatis.annotations.Mapper;
  10 +import org.apache.ibatis.annotations.Param;
  11 +import org.apache.ibatis.annotations.Select;
10 12
11 /** 13 /**
12 * 佣金提现 Mapper 14 * 佣金提现 Mapper
@@ -34,4 +36,6 @@ public interface BrokerageWithdrawMapper extends BaseMapperX&lt;BrokerageWithdrawDO @@ -34,4 +36,6 @@ public interface BrokerageWithdrawMapper extends BaseMapperX&lt;BrokerageWithdrawDO
34 .eq(BrokerageWithdrawDO::getStatus, status)); 36 .eq(BrokerageWithdrawDO::getStatus, status));
35 } 37 }
36 38
  39 + @Select("SELECT SUM(price) FROM trade_brokerage_withdraw WHERE user_id = #{userId} AND status = #{status}")
  40 + Integer selectSummaryPriceByUserIdAndStatus(@Param("userId") Long userId, @Param("status") Integer status);
37 } 41 }
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java
@@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO;
8 import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; 8 import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO;
9 9
10 import javax.validation.Valid; 10 import javax.validation.Valid;
  11 +import java.time.LocalDateTime;
11 import java.util.List; 12 import java.util.List;
12 13
13 /** 14 /**
@@ -78,4 +79,15 @@ public interface BrokerageRecordService { @@ -78,4 +79,15 @@ public interface BrokerageRecordService {
78 * @return 用户佣金汇总 79 * @return 用户佣金汇总
79 */ 80 */
80 UserBrokerageSummaryBO getUserBrokerageSummaryByUserId(Long userId, Integer bizType, Integer status); 81 UserBrokerageSummaryBO getUserBrokerageSummaryByUserId(Long userId, Integer bizType, Integer status);
  82 +
  83 + /**
  84 + * 获得用户佣金合计
  85 + *
  86 + * @param userId 用户编号
  87 + * @param bizType 业务类型
  88 + * @param beginTime 开始时间
  89 + * @param endTime 截止时间
  90 + * @return 用户佣金合计
  91 + */
  92 + Integer getSummaryPriceByUserId(Long userId, Integer bizType, LocalDateTime beginTime, LocalDateTime endTime);
81 } 93 }
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java
@@ -223,6 +223,11 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { @@ -223,6 +223,11 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
223 } 223 }
224 224
225 @Override 225 @Override
  226 + public Integer getSummaryPriceByUserId(Long userId, Integer bizType, LocalDateTime beginTime, LocalDateTime endTime) {
  227 + return brokerageRecordMapper.selectSummaryPriceByUserIdAndBizTypeAndCreateTimeBetween(userId, bizType, beginTime, endTime);
  228 + }
  229 +
  230 + @Override
226 @Transactional(rollbackFor = Exception.class) 231 @Transactional(rollbackFor = Exception.class)
227 public void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, int brokeragePrice, String title) { 232 public void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, int brokeragePrice, String title) {
228 // 校验佣金余额 233 // 校验佣金余额
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java
@@ -47,4 +47,14 @@ public interface BrokerageWithdrawService { @@ -47,4 +47,14 @@ public interface BrokerageWithdrawService {
47 * @return 佣金提现编号 47 * @return 佣金提现编号
48 */ 48 */
49 Long createBrokerageWithdraw(AppBrokerageWithdrawCreateReqVO createReqVO, Long userId); 49 Long createBrokerageWithdraw(AppBrokerageWithdrawCreateReqVO createReqVO, Long userId);
  50 +
  51 + /**
  52 + * 获得用户已提现金额
  53 + *
  54 + * @param userId 用户编号
  55 + * @param status 状态
  56 + * @return 用户已提现金额
  57 + */
  58 + Integer getSummaryPriceByUserIdAndStatus(Long userId, Integer status);
  59 +
50 } 60 }
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java
@@ -141,6 +141,11 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { @@ -141,6 +141,11 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
141 return withdraw.getId(); 141 return withdraw.getId();
142 } 142 }
143 143
  144 + @Override
  145 + public Integer getSummaryPriceByUserIdAndStatus(Long userId, Integer status) {
  146 + return brokerageWithdrawMapper.selectSummaryPriceByUserIdAndStatus(userId, status);
  147 + }
  148 +
144 /** 149 /**
145 * 计算提现手续费 150 * 计算提现手续费
146 * 151 *