Commit c92365128a49ecc939ae57bfe0f5539811782619

Authored by 芋道源码
Committed by Gitee
2 parents 421bb7d1 16af31d9

!635 分销Review代码修改

Merge pull request !635 from 疯狂的世界/feature/mall_product
Showing 35 changed files with 309 additions and 161 deletions
sql/mysql/brokerage.sql
1 1 -- 增加配置表
2   -create table trade_config
  2 +CREATE TABLE trade_config
3 3 (
4   - id bigint auto_increment comment '自增主键' primary key,
5   - brokerage_enabled bit default 1 not null comment '是否启用分佣',
6   - brokerage_enabled_condition tinyint default 1 not null comment '分佣模式:1-人人分销 2-指定分销',
7   - brokerage_bind_mode tinyint default 1 not null comment '分销关系绑定模式: 1-没有推广人,2-新用户, 3-扫码覆盖',
8   - brokerage_post_urls varchar(2000) default '' null comment '分销海报图地址数组',
9   - brokerage_first_percent int default 0 not null comment '一级返佣比例',
10   - brokerage_second_percent int default 0 not null comment '二级返佣比例',
11   - brokerage_withdraw_min_price int default 0 not null comment '用户提现最低金额',
12   - brokerage_withdraw_fee_percent int default 0 not null comment '提现手续费百分比',
13   - brokerage_bank_names varchar(200) default '' not null comment '提现银行(字典类型=brokerage_bank_name)',
14   - brokerage_frozen_days int default 7 not null comment '佣金冻结时间(天)',
15   - brokerage_withdraw_type varchar(32) default '1,2,3,4' not null comment '提现方式:1-钱包;2-银行卡;3-微信;4-支付宝',
16   - creator varchar(64) default '' null comment '创建者',
17   - create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
18   - updater varchar(64) default '' null comment '更新者',
19   - update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
20   - deleted bit default b'0' not null comment '是否删除',
21   - tenant_id bigint default 0 not null comment '租户编号'
22   -) comment '交易中心配置';
  4 + id BIGINT AUTO_INCREMENT COMMENT '自增主键' PRIMARY KEY,
  5 + brokerage_enabled BIT DEFAULT 1 NOT NULL COMMENT '是否启用分佣',
  6 + brokerage_enabled_condition TINYINT DEFAULT 1 NOT NULL COMMENT '分佣模式:1-人人分销 2-指定分销',
  7 + brokerage_bind_mode TINYINT DEFAULT 1 NOT NULL COMMENT '分销关系绑定模式: 1-没有推广人,2-新用户, 3-扫码覆盖',
  8 + brokerage_poster_urls VARCHAR(2000) DEFAULT '' NULL COMMENT '分销海报图地址数组',
  9 + brokerage_first_percent INT DEFAULT 0 NOT NULL COMMENT '一级返佣比例',
  10 + brokerage_second_percent INT DEFAULT 0 NOT NULL COMMENT '二级返佣比例',
  11 + brokerage_withdraw_min_price INT DEFAULT 0 NOT NULL COMMENT '用户提现最低金额',
  12 + brokerage_withdraw_fee_percent INT DEFAULT 0 NOT NULL COMMENT '提现手续费百分比',
  13 + brokerage_bank_names VARCHAR(200) DEFAULT '' NOT NULL COMMENT '提现银行(字典类型=brokerage_bank_name)',
  14 + brokerage_frozen_days INT DEFAULT 7 NOT NULL COMMENT '佣金冻结时间(天)',
  15 + brokerage_withdraw_types VARCHAR(32) DEFAULT '1,2,3,4' NOT NULL COMMENT '提现方式:1-钱包;2-银行卡;3-微信;4-支付宝',
  16 + creator VARCHAR(64) DEFAULT '' NULL COMMENT '创建者',
  17 + create_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '创建时间',
  18 + updater VARCHAR(64) DEFAULT '' NULL COMMENT '更新者',
  19 + update_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  20 + deleted BIT DEFAULT b'0' NOT NULL COMMENT '是否删除',
  21 + tenant_id BIGINT DEFAULT 0 NOT NULL COMMENT '租户编号'
  22 +) COMMENT '交易中心配置';
23 23  
24 24 # alter table trade_config
25 25 # add brokerage_withdraw_fee_percent int default 0 not null comment '提现手续费百分比' after brokerage_withdraw_min_price;
... ...
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java
1 1 package cn.iocoder.yudao.framework.common.util.number;
2 2  
  3 +import cn.hutool.core.math.Money;
3 4 import cn.hutool.core.util.NumberUtil;
4 5  
5 6 import java.math.BigDecimal;
... ... @@ -16,7 +17,7 @@ public class MoneyUtils {
16 17 * 计算百分比金额,四舍五入
17 18 *
18 19 * @param price 金额
19   - * @param rate 百分比,例如说 56.77% 则传入 56.77
  20 + * @param rate 百分比,例如说 56.77% 则传入 56.77
20 21 * @return 百分比金额
21 22 */
22 23 public static Integer calculateRatePrice(Integer price, Double rate) {
... ... @@ -27,24 +28,43 @@ public class MoneyUtils {
27 28 * 计算百分比金额,向下传入
28 29 *
29 30 * @param price 金额
30   - * @param rate 百分比,例如说 56.77% 则传入 56.77
  31 + * @param rate 百分比,例如说 56.77% 则传入 56.77
31 32 * @return 百分比金额
32 33 */
33 34 public static Integer calculateRatePriceFloor(Integer price, Double rate) {
34 35 return calculateRatePrice(price, rate, 0, RoundingMode.FLOOR).intValue();
35 36 }
36 37  
37   - /**
38   - * 计算百分比金额
39   - *
40   - * @param price 金额
41   - * @param rate 百分比,例如说 56.77% 则传入 56.77
42   - * @param scale 保留小数位数
43   - * @param roundingMode 舍入模式
44   - */
45   - public static BigDecimal calculateRatePrice(Number price, Number rate, int scale, RoundingMode roundingMode) {
46   - return NumberUtil.toBigDecimal(price).multiply(NumberUtil.toBigDecimal(rate)) // 乘以
47   - .divide(BigDecimal.valueOf(100), scale, roundingMode); // 除以 100
48   - }
  38 + /**
  39 + * 计算百分比金额
  40 + *
  41 + * @param price 金额
  42 + * @param rate 百分比,例如说 56.77% 则传入 56.77
  43 + * @param scale 保留小数位数
  44 + * @param roundingMode 舍入模式
  45 + */
  46 + public static BigDecimal calculateRatePrice(Number price, Number rate, int scale, RoundingMode roundingMode) {
  47 + return NumberUtil.toBigDecimal(price).multiply(NumberUtil.toBigDecimal(rate)) // 乘以
  48 + .divide(BigDecimal.valueOf(100), scale, roundingMode); // 除以 100
  49 + }
49 50  
  51 + /**
  52 + * 分转元
  53 + *
  54 + * @param fen 分
  55 + * @return 元
  56 + */
  57 + public static BigDecimal fenToYuan(int fen) {
  58 + return new Money(0, fen).getAmount();
  59 + }
  60 +
  61 + /**
  62 + * 分转元(字符串)
  63 + *
  64 + * @param fen 分
  65 + * @return 元
  66 + */
  67 + public static String fenToYuanStr(int fen) {
  68 + return new Money(0, fen).toString();
  69 + }
50 70 }
... ...
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java
... ... @@ -137,4 +137,14 @@ public class ProductSpuRespDTO {
137 137 */
138 138 private Integer clickCount;
139 139  
  140 +
  141 + // ========== 分销相关字段 =========
  142 +
  143 + /**
  144 + * 分销类型
  145 + *
  146 + * false - 默认
  147 + * true - 自行设置
  148 + */
  149 + private Boolean subCommissionType;
140 150 }
... ...
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/DictTypeConstants.java 0 → 100644
  1 +package cn.iocoder.yudao.module.trade.enums;
  2 +
  3 +/**
  4 + * Trade 字典类型的枚举类
  5 + *
  6 + * @author owen
  7 + */
  8 +public interface DictTypeConstants {
  9 +
  10 + String BROKERAGE_WITHDRAW_STATUS = "brokerage_withdraw_status"; // 佣金提现状态
  11 +}
... ...
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java
... ... @@ -22,9 +22,6 @@ public enum BrokerageWithdrawStatusEnum implements IntArrayValuable {
22 22 WITHDRAW_FAIL(21, "提现失败"),
23 23 ;
24 24  
25   - // TODO @疯狂:字典现在枚举在每个模块的 DictTypeConstants 里哈;可以创建一个出来;主要是想,治理每个模块到底有多少个枚举;
26   - public static final String DICT_TYPE = "BROKERAGE_WITHDRAW_STATUS";
27   -
28 25 public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageWithdrawStatusEnum::getStatus).toArray();
29 26  
30 27 /**
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java
... ... @@ -9,9 +9,12 @@ import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageUserConvert;
9 9 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 +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
  13 +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService;
12 14 import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO;
13 15 import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService;
14 16 import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService;
  17 +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO;
15 18 import io.swagger.v3.oas.annotations.Operation;
16 19 import io.swagger.v3.oas.annotations.Parameter;
17 20 import io.swagger.v3.oas.annotations.tags.Tag;
... ... @@ -38,6 +41,8 @@ public class BrokerageUserController {
38 41 private BrokerageUserService brokerageUserService;
39 42 @Resource
40 43 private BrokerageRecordService brokerageRecordService;
  44 + @Resource
  45 + private BrokerageWithdrawService brokerageWithdrawService;
41 46  
42 47 @Resource
43 48 private MemberUserApi memberUserApi;
... ... @@ -97,9 +102,12 @@ public class BrokerageUserController {
97 102 userId -> userId,
98 103 userId -> brokerageUserService.getBrokerageUserCountByBindUserId(userId, null));
99 104  
100   - // todo 合计提现
  105 + // 合计提现
  106 + Map<Long, UserWithdrawSummaryBO> withdrawMap = convertMap(userIds,
  107 + userId -> userId,
  108 + userId -> brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS));
101 109  
102   - return success(BrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap));
  110 + return success(BrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap, withdrawMap));
103 111 }
104 112  
105 113 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java
... ... @@ -48,7 +48,7 @@ public class TradeConfigBaseVO {
48 48 private Integer brokerageBindMode;
49 49  
50 50 @Schema(description = "分销海报图地址数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/yudao.jpg]")
51   - private List<String> brokeragePostUrls;
  51 + private List<String> brokeragePosterUrls;
52 52  
53 53 @Schema(description = "一级返佣比例", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
54 54 @NotNull(message = "一级返佣比例不能为空")
... ... @@ -82,6 +82,6 @@ public class TradeConfigBaseVO {
82 82 @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]")
83 83 @NotNull(message = "提现方式不能为空")
84 84 @InEnum(value = BrokerageWithdrawTypeEnum.class, message = "提现方式必须是 {value}")
85   - private List<Integer> brokerageWithdrawType;
  85 + private List<Integer> brokerageWithdrawTypes;
86 86  
87 87 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java
... ... @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBroke
9 9 import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert;
10 10 import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO;
11 11 import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService;
12   -import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService;
13 12 import io.swagger.v3.oas.annotations.Operation;
14 13 import io.swagger.v3.oas.annotations.tags.Tag;
15 14 import lombok.extern.slf4j.Slf4j;
... ... @@ -32,8 +31,6 @@ import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLogi
32 31 @Slf4j
33 32 public class AppBrokerageRecordController {
34 33 @Resource
35   - private BrokerageUserService brokerageUserService;
36   - @Resource
37 34 private BrokerageRecordService brokerageRecordService;
38 35  
39 36 @GetMapping("/page")
... ... @@ -45,15 +42,10 @@ public class AppBrokerageRecordController {
45 42 return success(BrokerageRecordConvert.INSTANCE.convertPage02(pageResult));
46 43 }
47 44  
48   - // TODO @疯狂:这里还有一个漏网之鱼~
49 45 @GetMapping("/get-product-brokerage-price")
50 46 @Operation(summary = "获得商品的分销金额")
51 47 public CommonResult<AppBrokerageProductPriceRespVO> getProductBrokeragePrice(@RequestParam("spuId") Long spuId) {
52   - AppBrokerageProductPriceRespVO respVO = new AppBrokerageProductPriceRespVO();
53   - respVO.setEnabled(brokerageUserService.getUserBrokerageEnabled(getLoginUserId()));
54   - respVO.setBrokerageMinPrice(1);
55   - respVO.setBrokerageMaxPrice(2);
56   - return success(respVO);
  48 + return success(brokerageRecordService.calculateProductBrokeragePrice(spuId, getLoginUserId()));
57 49 }
58 50  
59 51 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java
... ... @@ -15,6 +15,7 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum
15 15 import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService;
16 16 import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService;
17 17 import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService;
  18 +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO;
18 19 import io.swagger.v3.oas.annotations.Operation;
19 20 import io.swagger.v3.oas.annotations.Parameter;
20 21 import io.swagger.v3.oas.annotations.tags.Tag;
... ... @@ -67,8 +68,8 @@ public class AppBrokerageUserController {
67 68 @Operation(summary = "绑定推广员")
68 69 @PreAuthenticated
69 70 public CommonResult<Boolean> bindBrokerageUser(@Valid @RequestBody AppBrokerageUserBindReqVO reqVO) {
70   - // TODO @疯狂:是不是 isNewUser 不用传递哈,交给 service 自己计算出来?
71   - return success(brokerageUserService.bindBrokerageUser(getLoginUserId(), reqVO.getBindUserId(), false));
  71 + MemberUserRespDTO user = memberUserApi.getUser(getLoginUserId());
  72 + return success(brokerageUserService.bindBrokerageUser(user.getId(), reqVO.getBindUserId(), user.getCreateTime()));
72 73 }
73 74  
74 75 @GetMapping("/get-summary")
... ... @@ -82,7 +83,7 @@ public class AppBrokerageUserController {
82 83 LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday);
83 84 AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO()
84 85 .setYesterdayPrice(brokerageRecordService.getSummaryPriceByUserId(userId, BrokerageRecordBizTypeEnum.ORDER.getType(), beginTime, endTime))
85   - .setWithdrawPrice(brokerageWithdrawService.getSummaryPriceByUserIdAndStatus(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS.getStatus()))
  86 + .setWithdrawPrice(Optional.ofNullable(brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS)).map(UserWithdrawSummaryBO::getPrice).orElse(0))
86 87 .setBrokeragePrice(0).setFrozenPrice(0)
87 88 .setFirstBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1))
88 89 .setSecondBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2));
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java
... ... @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBro
9 9 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO;
10 10 import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageWithdrawConvert;
11 11 import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO;
12   -import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
13 12 import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService;
14 13 import io.swagger.v3.oas.annotations.Operation;
15 14 import io.swagger.v3.oas.annotations.tags.Tag;
... ... @@ -19,7 +18,6 @@ import org.springframework.web.bind.annotation.*;
19 18  
20 19 import javax.annotation.Resource;
21 20 import javax.validation.Valid;
22   -import java.util.Map;
23 21  
24 22 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
25 23 import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId;
... ... @@ -44,10 +42,7 @@ public class AppBrokerageWithdrawController {
44 42 // 分页查询
45 43 PageResult<BrokerageWithdrawDO> pageResult = brokerageWithdrawService.getBrokerageWithdrawPage(
46 44 BrokerageWithdrawConvert.INSTANCE.convert(pageReqVO, getLoginUserId()));
47   - // 拼接信息
48   - // TODO @疯狂:后端可以直接用 DictFrameworkUtils.getDictDataLabel() 去渲染哈;这样就不用 getDictDataLabelMap 方法了;
49   - Map<String, String> statusNameMap = dictDataApi.getDictDataLabelMap(BrokerageWithdrawStatusEnum.DICT_TYPE);
50   - return success(BrokerageWithdrawConvert.INSTANCE.convertPage02(pageResult, statusNameMap));
  45 + return success(BrokerageWithdrawConvert.INSTANCE.convertPage03(pageResult));
51 46 }
52 47  
53 48 @PostMapping("/create")
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java
... ... @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.trade.controller.app.config;
3 3 import cn.hutool.core.util.ObjUtil;
4 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 5 import cn.iocoder.yudao.module.trade.controller.app.config.vo.AppTradeConfigRespVO;
  6 +import cn.iocoder.yudao.module.trade.convert.config.TradeConfigConvert;
6 7 import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
7 8 import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
8 9 import io.swagger.v3.oas.annotations.Operation;
... ... @@ -33,13 +34,7 @@ public class AppTradeConfigController {
33 34 @Operation(summary = "获得交易配置")
34 35 public CommonResult<AppTradeConfigRespVO> getTradeConfig() {
35 36 TradeConfigDO tradeConfig = ObjUtil.defaultIfNull(tradeConfigService.getTradeConfig(), new TradeConfigDO());
36   - // TODO @疯狂:是不是直接 convert 就好啦;
37   - AppTradeConfigRespVO respVO = new AppTradeConfigRespVO()
38   - .setBrokeragePosterUrls(tradeConfig.getBrokeragePostUrls())
39   - .setBrokerageFrozenDays(tradeConfig.getBrokerageFrozenDays())
40   - .setBrokerageWithdrawMinPrice(tradeConfig.getBrokerageWithdrawMinPrice())
41   - .setBrokerageWithdrawType(tradeConfig.getBrokerageWithdrawType());
42   - return success(respVO);
  37 + return success(TradeConfigConvert.INSTANCE.convert02(tradeConfig));
43 38 }
44 39  
45 40 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java
... ... @@ -18,8 +18,7 @@ public class AppTradeConfigRespVO {
18 18 @Schema(description = "佣金提现最小金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
19 19 private Integer brokerageWithdrawMinPrice;
20 20  
21   - // TODO @疯狂:如果是 list,要不加个 s,复数;
22 21 @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1, 2]")
23   - private List<Integer> brokerageWithdrawType;
  22 + private List<Integer> brokerageWithdrawTypes;
24 23  
25 24 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java
... ... @@ -4,6 +4,7 @@ import cn.hutool.core.math.Money;
4 4 import cn.hutool.core.util.ObjectUtil;
5 5 import cn.hutool.core.util.StrUtil;
6 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  7 +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
7 8 import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
8 9 import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO;
9 10 import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordRespVO;
... ... @@ -51,7 +52,7 @@ public interface BrokerageRecordConvert {
51 52 .setBizType(bizType.getType()).setBizId(bizId)
52 53 .setPrice(brokeragePrice).setTotalPrice(user.getBrokeragePrice())
53 54 .setTitle(title)
54   - .setDescription(StrUtil.format(bizType.getDescription(), new Money(0, Math.abs(brokeragePrice))))
  55 + .setDescription(StrUtil.format(bizType.getDescription(), MoneyUtils.fenToYuanStr(Math.abs(brokeragePrice))))
55 56 .setStatus(status).setFrozenDays(brokerageFrozenDays).setUnfreezeTime(unfreezeTime)
56 57 .setSourceUserLevel(sourceUserLevel).setSourceUserId(sourceUserId);
57 58 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java
... ... @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.Brokerag
7 7 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO;
8 8 import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
9 9 import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO;
  10 +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO;
10 11 import org.mapstruct.Mapper;
11 12 import org.mapstruct.MappingTarget;
12 13 import org.mapstruct.factory.Mappers;
... ... @@ -29,13 +30,14 @@ public interface BrokerageUserConvert {
29 30  
30 31 List<BrokerageUserRespVO> convertList(List<BrokerageUserDO> list);
31 32  
32   - PageResult<BrokerageUserRespVO> convertPage(PageResult<BrokerageUserDO> page);
  33 + PageResult<BrokerageUserRespVO> convertPage(PageResult<BrokerageUserDO> page, Map<Long, MemberUserRespDTO> userMap, Map<Long, Long> brokerageUserCountMap, Map<Long, UserBrokerageSummaryBO> userOrderSummaryMap);
33 34  
34 35 default PageResult<BrokerageUserRespVO> convertPage(PageResult<BrokerageUserDO> pageResult,
35 36 Map<Long, MemberUserRespDTO> userMap,
36 37 Map<Long, Long> brokerageUserCountMap,
37   - Map<Long, UserBrokerageSummaryBO> userOrderSummaryMap) {
38   - PageResult<BrokerageUserRespVO> result = convertPage(pageResult);
  38 + Map<Long, UserBrokerageSummaryBO> userOrderSummaryMap,
  39 + Map<Long, UserWithdrawSummaryBO> withdrawMap) {
  40 + PageResult<BrokerageUserRespVO> result = convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap);
39 41 for (BrokerageUserRespVO userVO : result.getList()) {
40 42 // 用户信息
41 43 copyTo(userMap.get(userVO.getId()), userVO);
... ... @@ -46,7 +48,10 @@ public interface BrokerageUserConvert {
46 48 Optional<UserBrokerageSummaryBO> orderSummaryOptional = Optional.ofNullable(userOrderSummaryMap.get(userVO.getId()));
47 49 userVO.setBrokerageOrderCount(orderSummaryOptional.map(UserBrokerageSummaryBO::getCount).orElse(0))
48 50 .setBrokerageOrderPrice(orderSummaryOptional.map(UserBrokerageSummaryBO::getPrice).orElse(0));
49   - // todo 已提现次数、已提现金额
  51 + // 已提现次数、已提现金额
  52 + Optional<UserWithdrawSummaryBO> withdrawSummaryOptional = Optional.ofNullable(withdrawMap.get(userVO.getId()));
  53 + userVO.setWithdrawCount(withdrawSummaryOptional.map(UserWithdrawSummaryBO::getCount).orElse(0))
  54 + .setWithdrawPrice(withdrawSummaryOptional.map(UserWithdrawSummaryBO::getPrice).orElse(0));
50 55 userVO.setWithdrawCount(0).setWithdrawPrice(0);
51 56 }
52 57 return result;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java
1 1 package cn.iocoder.yudao.module.trade.convert.brokerage;
2 2  
3   -import cn.hutool.core.map.MapUtil;
4 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils;
5 5 import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
6 6 import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO;
7 7 import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawRespVO;
... ... @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBro
9 9 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawPageReqVO;
10 10 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO;
11 11 import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO;
  12 +import cn.iocoder.yudao.module.trade.enums.DictTypeConstants;
12 13 import org.mapstruct.Mapper;
13 14 import org.mapstruct.factory.Mappers;
14 15  
... ... @@ -44,10 +45,10 @@ public interface BrokerageWithdrawConvert {
44 45  
45 46 PageResult<AppBrokerageWithdrawRespVO> convertPage02(PageResult<BrokerageWithdrawDO> pageResult);
46 47  
47   - default PageResult<AppBrokerageWithdrawRespVO> convertPage02(PageResult<BrokerageWithdrawDO> pageResult, Map<String, String> statusNameMap) {
  48 + default PageResult<AppBrokerageWithdrawRespVO> convertPage03(PageResult<BrokerageWithdrawDO> pageResult) {
48 49 PageResult<AppBrokerageWithdrawRespVO> result = convertPage02(pageResult);
49 50 for (AppBrokerageWithdrawRespVO vo : result.getList()) {
50   - vo.setStatusName(MapUtil.getStr(statusNameMap, String.valueOf(vo.getStatus()), ""));
  51 + vo.setStatusName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.BROKERAGE_WITHDRAW_STATUS, vo.getStatus()));
51 52 }
52 53 return result;
53 54 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/config/TradeConfigConvert.java
... ... @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.trade.convert.config;
2 2  
3 3 import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigRespVO;
4 4 import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigSaveReqVO;
  5 +import cn.iocoder.yudao.module.trade.controller.app.config.vo.AppTradeConfigRespVO;
5 6 import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
6 7 import org.mapstruct.Mapper;
7 8 import org.mapstruct.factory.Mappers;
... ... @@ -20,4 +21,5 @@ public interface TradeConfigConvert {
20 21  
21 22 TradeConfigRespVO convert(TradeConfigDO bean);
22 23  
  24 + AppTradeConfigRespVO convert02(TradeConfigDO tradeConfig);
23 25 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java
1 1 package cn.iocoder.yudao.module.trade.convert.order;
2 2  
  3 +import cn.hutool.core.util.BooleanUtil;
3 4 import cn.hutool.core.util.StrUtil;
4 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 6 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
... ... @@ -14,6 +15,7 @@ import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDT
14 15 import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
15 16 import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
16 17 import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO;
  18 +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
17 19 import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO;
18 20 import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO;
19 21 import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUserRespVO;
... ... @@ -266,11 +268,16 @@ public interface TradeOrderConvert {
266 268  
267 269 TradeOrderDO convert(TradeOrderRemarkReqVO reqVO);
268 270  
269   - default BrokerageAddReqBO convert(MemberUserRespDTO user, TradeOrderItemDO item, ProductSkuRespDTO sku) {
270   - return new BrokerageAddReqBO().setBizId(String.valueOf(item.getId())).setSourceUserId(item.getUserId())
  271 + default BrokerageAddReqBO convert(MemberUserRespDTO user, TradeOrderItemDO item,
  272 + ProductSpuRespDTO spu, ProductSkuRespDTO sku) {
  273 + BrokerageAddReqBO bo = new BrokerageAddReqBO().setBizId(String.valueOf(item.getId())).setSourceUserId(item.getUserId())
271 274 .setBasePrice(item.getPayPrice() * item.getCount())
272 275 .setTitle(StrUtil.format("{}成功购买{}", user.getNickname(), item.getSpuName()))
273   - .setFirstFixedPrice(sku.getFirstBrokeragePrice()).setSecondFixedPrice(sku.getSecondBrokeragePrice());
  276 + .setFirstFixedPrice(0).setSecondFixedPrice(0);
  277 + if (BooleanUtil.isTrue(spu.getSubCommissionType())) {
  278 + bo.setFirstFixedPrice(sku.getFirstBrokeragePrice()).setSecondFixedPrice(sku.getSecondBrokeragePrice());
  279 + }
  280 + return bo;
274 281 }
275 282  
276 283 TradeBeforeOrderCreateReqBO convert(AppTradeOrderCreateReqVO createReqVO);
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java
... ... @@ -68,7 +68,7 @@ public class TradeConfigDO extends BaseDO {
68 68 * 分销海报图地址数组
69 69 */
70 70 @TableField(typeHandler = JacksonTypeHandler.class)
71   - private List<String> brokeragePostUrls;
  71 + private List<String> brokeragePosterUrls;
72 72 /**
73 73 * 一级返佣比例
74 74 */
... ... @@ -100,6 +100,6 @@ public class TradeConfigDO extends BaseDO {
100 100 * 枚举 {@link BrokerageWithdrawTypeEnum 对应的类}
101 101 */
102 102 @TableField(typeHandler = IntegerListTypeHandler.class)
103   - private List<Integer> brokerageWithdrawType;
  103 + private List<Integer> brokerageWithdrawTypes;
104 104  
105 105 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java
... ... @@ -53,14 +53,14 @@ public interface BrokerageRecordMapper extends BaseMapperX&lt;BrokerageRecordDO&gt; {
53 53 }
54 54  
55 55 @Select("SELECT COUNT(1), SUM(price) FROM trade_brokerage_record " +
56   - "WHERE user_id = #{userId} AND biz_type = #{bizType} AND status = #{status}")
  56 + "WHERE user_id = #{userId} AND biz_type = #{bizType} AND status = #{status} AND deleted = FALSE")
57 57 UserBrokerageSummaryBO selectCountAndSumPriceByUserIdAndBizTypeAndStatus(@Param("userId") Long userId,
58 58 @Param("bizType") Integer bizType,
59 59 @Param("status") Integer status);
60 60  
61 61 @Select("SELECT SUM(price) FROM trade_brokerage_record " +
62 62 "WHERE user_id = #{userId} AND biz_type = #{bizType} " +
63   - "AND create_time BETWEEN #{beginTime} AND #{endTime}")
  63 + "AND create_time BETWEEN #{beginTime} AND #{endTime} AND deleted = FALSE")
64 64 Integer selectSummaryPriceByUserIdAndBizTypeAndCreateTimeBetween(@Param("userId") Long userId,
65 65 @Param("bizType") Integer bizType,
66 66 @Param("beginTime") LocalDateTime beginTime,
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java
... ... @@ -5,6 +5,7 @@ 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.withdraw.BrokerageWithdrawPageReqVO;
7 7 import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO;
  8 +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO;
8 9 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
9 10 import org.apache.ibatis.annotations.Mapper;
10 11 import org.apache.ibatis.annotations.Param;
... ... @@ -36,8 +37,8 @@ public interface BrokerageWithdrawMapper extends BaseMapperX&lt;BrokerageWithdrawDO
36 37 .eq(BrokerageWithdrawDO::getStatus, status));
37 38 }
38 39  
39   - @Select("SELECT SUM(price) FROM trade_brokerage_withdraw " +
40   - "WHERE user_id = #{userId} AND status = #{status}")
41   - Integer selectSummaryPriceByUserIdAndStatus(@Param("userId") Long userId, @Param("status") Integer status);
42   -
  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);
43 44 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java
... ... @@ -2,6 +2,7 @@ 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.record.AppBrokerageProductPriceRespVO;
5 6 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO;
6 7 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO;
7 8 import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO;
... ... @@ -110,4 +111,12 @@ public interface BrokerageRecordService {
110 111 */
111 112 Integer getUserRankByPrice(Long userId, LocalDateTime[] times);
112 113  
  114 + /**
  115 + * 计算商品被购买后,推广员可以得到的佣金
  116 + *
  117 + * @param spuId 商品编号
  118 + * @param userId 用户编号
  119 + * @return 用户佣金
  120 + */
  121 + AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long spuId, Long userId);
113 122 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java
1 1 package cn.iocoder.yudao.module.trade.service.brokerage;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4   -import cn.hutool.core.math.Money;
  4 +import cn.hutool.core.collection.ListUtil;
5 5 import cn.hutool.core.util.ArrayUtil;
6 6 import cn.hutool.core.util.BooleanUtil;
7 7 import cn.hutool.core.util.ObjectUtil;
... ... @@ -10,7 +10,12 @@ import cn.hutool.extra.spring.SpringUtil;
10 10 import cn.iocoder.yudao.framework.common.pojo.PageResult;
11 11 import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
12 12 import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
  13 +import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
  14 +import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
  15 +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
  16 +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
13 17 import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO;
  18 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageProductPriceRespVO;
14 19 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO;
15 20 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO;
16 21 import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert;
... ... @@ -37,6 +42,9 @@ import java.util.Objects;
37 42 import java.util.Optional;
38 43  
39 44 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  45 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getMaxValue;
  46 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getMinValue;
  47 +import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId;
40 48 import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH;
41 49  
42 50 /**
... ... @@ -56,6 +64,11 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
56 64 @Resource
57 65 private BrokerageUserService brokerageUserService;
58 66  
  67 + @Resource
  68 + private ProductSpuApi productSpuApi;
  69 + @Resource
  70 + private ProductSkuApi productSkuApi;
  71 +
59 72 @Override
60 73 public BrokerageRecordDO getBrokerageRecord(Integer id) {
61 74 return brokerageRecordMapper.selectById(id);
... ... @@ -240,7 +253,6 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
240 253 return new PageResult<>(pageResult.getRecords(), pageResult.getTotal());
241 254 }
242 255  
243   - // TODO @疯狂:这个求出来,应该是不准的?例如说超过 100+ 名后?
244 256 @Override
245 257 public Integer getUserRankByPrice(Long userId, LocalDateTime[] times) {
246 258 AppBrokerageUserRankPageReqVO pageParam = new AppBrokerageUserRankPageReqVO().setTimes(times);
... ... @@ -261,15 +273,14 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
261 273 int balance = Optional.of(user)
262 274 .map(BrokerageUserDO::getBrokeragePrice).orElse(0);
263 275 if (balance + brokeragePrice < 0) {
264   - // TODO @疯狂:要不 MoneyUtils 那,统一搞个 format 金额的方法?然后把分到元的字符串,统一收口掉;
265   - throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, new Money(0, balance));
  276 + throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, MoneyUtils.fenToYuanStr(balance));
266 277 }
267 278  
268 279 // 2. 更新佣金余额
269 280 boolean success = brokerageUserService.updateUserPrice(userId, brokeragePrice);
270 281 if (!success) {
271 282 // 失败时,则抛出异常。只会出现扣减佣金时,余额不足的情况
272   - throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, new Money(0, balance));
  283 + throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, MoneyUtils.fenToYuanStr(balance));
273 284 }
274 285  
275 286 // 3. 新增记录
... ... @@ -296,6 +307,50 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
296 307 return true;
297 308 }
298 309  
  310 + @Override
  311 + public AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long spuId, Long userId) {
  312 + // 1. 构建默认的返回值
  313 + AppBrokerageProductPriceRespVO respVO = new AppBrokerageProductPriceRespVO().setEnabled(false)
  314 + .setBrokerageMinPrice(0).setBrokerageMaxPrice(0);
  315 +
  316 + // 2.1 校验分销功能是否开启
  317 + TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig();
  318 + if (tradeConfig == null || !BooleanUtil.isTrue(tradeConfig.getBrokerageEnabled())) {
  319 + return respVO;
  320 + }
  321 +
  322 + // 2.2 校验用户是否有分销资格
  323 + respVO.setEnabled(brokerageUserService.getUserBrokerageEnabled(getLoginUserId()));
  324 + if (!BooleanUtil.isTrue(respVO.getEnabled())) {
  325 + return respVO;
  326 + }
  327 +
  328 + Integer fixedMinPrice = 0;
  329 + Integer fixedMaxPrice = 0;
  330 + Integer spuMinPrice = 0;
  331 + Integer spuMaxPrice = 0;
  332 + // 2.3 校验商品是否存在
  333 + ProductSpuRespDTO spu = productSpuApi.getSpu(spuId);
  334 + if (spu == null) {
  335 + return respVO;
  336 + }
  337 +
  338 + List<ProductSkuRespDTO> skuList = productSkuApi.getSkuListBySpuId(ListUtil.of(spuId));
  339 + if (BooleanUtil.isTrue(spu.getSubCommissionType())) {
  340 + // 3.1 商品单独分佣模式
  341 + fixedMinPrice = getMinValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice);
  342 + fixedMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice);
  343 + } else {
  344 + // 3.2 全局分佣模式(根据商品价格比例计算)
  345 + spuMinPrice = getMinValue(skuList, ProductSkuRespDTO::getPrice);
  346 + spuMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getPrice);
  347 + }
  348 +
  349 + respVO.setBrokerageMinPrice(calculatePrice(spuMinPrice, tradeConfig.getBrokerageFirstPercent(), fixedMinPrice));
  350 + respVO.setBrokerageMaxPrice(calculatePrice(spuMaxPrice, tradeConfig.getBrokerageFirstPercent(), fixedMaxPrice));
  351 + return respVO;
  352 + }
  353 +
299 354 /**
300 355 * 获得自身的代理对象,解决 AOP 生效问题
301 356 *
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java
... ... @@ -187,7 +187,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
187 187 /**
188 188 * 补全绑定用户的字段
189 189 *
190   - * @param bindUserId 绑定的用户编号
  190 + * @param bindUserId 绑定的用户编号
191 191 * @param brokerageUser update 对象
192 192 * @return 补全后的 update 对象
193 193 */
... ... @@ -261,12 +261,15 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
261 261 }
262 262  
263 263 // 下级不能绑定自己的上级
264   - // TODO @疯狂:这里是不是查询不到的时候,应该有个 break 结束循环哈
265 264 for (int i = 0; i <= Short.MAX_VALUE; i++) {
266 265 if (Objects.equals(bindUser.getBindUserId(), user.getId())) {
267 266 throw exception(BROKERAGE_BIND_LOOP);
268 267 }
269 268 bindUser = getBrokerageUser(bindUser.getBindUserId());
  269 + // 找到根节点,结束循环
  270 + if (bindUser == null || bindUser.getBindUserId() == null) {
  271 + break;
  272 + }
270 273 }
271 274 }
272 275  
... ... @@ -274,8 +277,8 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
274 277 * 根据绑定用户编号,获得绑定用户编号列表
275 278 *
276 279 * @param bindUserId 绑定用户编号
277   - * @param level 绑定用户的层级。
278   - * 如果 level 为空,则查询 1+2 两个层级
  280 + * @param level 绑定用户的层级。
  281 + * 如果 level 为空,则查询 1+2 两个层级
279 282 * @return 绑定用户编号列表
280 283 */
281 284 private List<Long> buildBindUserIdsByLevel(Long bindUserId, Integer level) {
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java
... ... @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.Brok
5 5 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO;
6 6 import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO;
7 7 import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
  8 +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO;
8 9  
9 10 /**
10 11 * 佣金提现 Service 接口
... ... @@ -48,12 +49,12 @@ public interface BrokerageWithdrawService {
48 49 Long createBrokerageWithdraw(AppBrokerageWithdrawCreateReqVO createReqVO, Long userId);
49 50  
50 51 /**
51   - * 获得用户已提现金额
  52 + * 汇总用户提现
52 53 *
53 54 * @param userId 用户编号
54   - * @param status 状态
55   - * @return 用户已提现金额
  55 + * @param status 提现状态
  56 + * @return 用户提现汇总
56 57 */
57   - Integer getSummaryPriceByUserIdAndStatus(Long userId, Integer status);
  58 + UserWithdrawSummaryBO getWithdrawSummaryByUserId(Long userId, BrokerageWithdrawStatusEnum status);
58 59  
59 60 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java
... ... @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.trade.service.brokerage;
2 2  
3 3 import cn.hutool.core.date.LocalDateTimeUtil;
4 4 import cn.hutool.core.map.MapUtil;
5   -import cn.hutool.core.math.Money;
6 5 import cn.hutool.core.util.ObjectUtil;
7 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
8 7 import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
... ... @@ -18,6 +17,7 @@ import cn.iocoder.yudao.module.trade.enums.MessageTemplateConstants;
18 17 import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
19 18 import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
20 19 import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawTypeEnum;
  20 +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO;
21 21 import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
22 22 import org.springframework.stereotype.Service;
23 23 import org.springframework.transaction.annotation.Transactional;
... ... @@ -93,7 +93,7 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
93 93 // 4. 通知用户
94 94 Map<String, Object> templateParams = MapUtil.<String, Object>builder()
95 95 .put("createTime", LocalDateTimeUtil.formatNormal(withdraw.getCreateTime()))
96   - .put("price", new Money(0, withdraw.getPrice()).toString())
  96 + .put("price", MoneyUtils.fenToYuanStr(withdraw.getPrice()))
97 97 .put("reason", withdraw.getAuditReason())
98 98 .build();
99 99 NotifySendSingleToUserReqDTO reqDTO = new NotifySendSingleToUserReqDTO()
... ... @@ -142,8 +142,9 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
142 142 }
143 143  
144 144 @Override
145   - public Integer getSummaryPriceByUserIdAndStatus(Long userId, Integer status) {
146   - return brokerageWithdrawMapper.selectSummaryPriceByUserIdAndStatus(userId, status);
  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 148 }
148 149  
149 150 /**
... ... @@ -170,7 +171,7 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
170 171 TradeConfigDO validateWithdrawPrice(Integer withdrawPrice) {
171 172 TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig();
172 173 if (tradeConfig.getBrokerageWithdrawMinPrice() != null && withdrawPrice < tradeConfig.getBrokerageWithdrawMinPrice()) {
173   - throw exception(BROKERAGE_WITHDRAW_MIN_PRICE, new Money(0, tradeConfig.getBrokerageWithdrawMinPrice()));
  174 + throw exception(BROKERAGE_WITHDRAW_MIN_PRICE, MoneyUtils.fenToYuanStr(tradeConfig.getBrokerageWithdrawMinPrice()));
174 175 }
175 176 return tradeConfig;
176 177 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserWithdrawSummaryBO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.trade.service.brokerage.bo;
  2 +
  3 +import lombok.AllArgsConstructor;
  4 +import lombok.Data;
  5 +import lombok.NoArgsConstructor;
  6 +
  7 +/**
  8 + * 用户佣金提现合计 BO
  9 + *
  10 + * @author owen
  11 + */
  12 +@Data
  13 +@NoArgsConstructor
  14 +@AllArgsConstructor
  15 +public class UserWithdrawSummaryBO {
  16 +
  17 + /**
  18 + * 提现次数
  19 + */
  20 + private Integer count;
  21 + /**
  22 + * 提现金额
  23 + */
  24 + private Integer price;
  25 +
  26 +}
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
... ... @@ -849,7 +849,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
849 849 // 每一个订单项,都会去生成分销记录
850 850 List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(orderId);
851 851 List<BrokerageAddReqBO> addList = convertList(orderItems,
852   - item -> TradeOrderConvert.INSTANCE.convert(user, item, productSkuApi.getSku(item.getSkuId())));
  852 + item -> TradeOrderConvert.INSTANCE.convert(user, item,
  853 + productSpuApi.getSpu(item.getSpuId()), productSkuApi.getSku(item.getSkuId())));
853 854 brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, addList);
854 855 }
855 856  
... ...
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java
... ... @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.member.api.user.dto;
3 3 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
4 4 import lombok.Data;
5 5  
  6 +import java.time.LocalDateTime;
  7 +
6 8 /**
7 9 * 用户信息 Response DTO
8 10 *
... ... @@ -33,6 +35,10 @@ public class MemberUserRespDTO {
33 35 * 手机
34 36 */
35 37 private String mobile;
  38 + /**
  39 + * 创建时间
  40 + */
  41 + private LocalDateTime createTime;
36 42  
37 43 // ========== 其它信息 ==========
38 44  
... ...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApi.java
... ... @@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.system.api.dict;
3 3 import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO;
4 4  
5 5 import java.util.Collection;
6   -import java.util.List;
7   -import java.util.Map;
8 6  
9 7 /**
10 8 * 字典数据 API 接口
... ... @@ -19,40 +17,23 @@ public interface DictDataApi {
19 17 * 2. 字典数据被禁用
20 18 *
21 19 * @param dictType 字典类型
22   - * @param values 字典数据值的数组
  20 + * @param values 字典数据值的数组
23 21 */
24 22 void validateDictDataList(String dictType, Collection<String> values);
25 23  
26 24 /**
27 25 * 获得指定的字典数据,从缓存中
28 26 *
29   - * @param type 字典类型
  27 + * @param type 字典类型
30 28 * @param value 字典数据值
31 29 * @return 字典数据
32 30 */
33 31 DictDataRespDTO getDictData(String type, String value);
34 32  
35 33 /**
36   - * 获得指定类型的字典数据,从缓存中
37   - *
38   - * @param type 字典类型
39   - * @return 字典数据
40   - */
41   - List<DictDataRespDTO> getDictDataList(String type);
42   -
43   - /**
44   - * 获得指定类型的字典数据 标签字典,从缓存中
45   - * key:value, value: label
46   - *
47   - * @param type 字典类型
48   - * @return 字典数据
49   - */
50   - Map<String, String> getDictDataLabelMap(String type);
51   -
52   - /**
53 34 * 解析获得指定的字典数据,从缓存中
54 35 *
55   - * @param type 字典类型
  36 + * @param type 字典类型
56 37 * @param label 字典数据标签
57 38 * @return 字典数据
58 39 */
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java
1 1 package cn.iocoder.yudao.module.system.api.dict;
2 2  
3 3 import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO;
4   -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO;
5 4 import cn.iocoder.yudao.module.system.convert.dict.DictDataConvert;
6 5 import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
7 6 import cn.iocoder.yudao.module.system.service.dict.DictDataService;
... ... @@ -9,10 +8,6 @@ import org.springframework.stereotype.Service;
9 8  
10 9 import javax.annotation.Resource;
11 10 import java.util.Collection;
12   -import java.util.List;
13   -import java.util.Map;
14   -
15   -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
16 11  
17 12 /**
18 13 * 字典数据 API 实现类
... ... @@ -37,19 +32,6 @@ public class DictDataApiImpl implements DictDataApi {
37 32 }
38 33  
39 34 @Override
40   - public List<DictDataRespDTO> getDictDataList(String type) {
41   - // TODO @疯狂:不用 DictDataExportReqVO 哈;可以考虑直接加个允许传递 type 传递的
42   - List<DictDataDO> list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(type));
43   - return DictDataConvert.INSTANCE.convertList04(list);
44   - }
45   -
46   - @Override
47   - public Map<String, String> getDictDataLabelMap(String type) {
48   - List<DictDataDO> list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(type));
49   - return convertMap(list, DictDataDO::getValue, DictDataDO::getLabel);
50   - }
51   -
52   - @Override
53 35 public DictDataRespDTO parseDictData(String dictType, String label) {
54 36 DictDataDO dictData = dictDataService.parseDictData(dictType, label);
55 37 return DictDataConvert.INSTANCE.convert02(dictData);
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java
1 1 package cn.iocoder.yudao.module.system.controller.app.dict;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4   -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO;
5 4 import cn.iocoder.yudao.module.system.controller.app.dict.vo.AppDictDataRespVO;
6 5 import cn.iocoder.yudao.module.system.convert.dict.DictDataConvert;
7 6 import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
8 7 import cn.iocoder.yudao.module.system.service.dict.DictDataService;
9 8 import io.swagger.v3.oas.annotations.Operation;
  9 +import io.swagger.v3.oas.annotations.Parameter;
10 10 import io.swagger.v3.oas.annotations.tags.Tag;
11 11 import org.springframework.validation.annotation.Validated;
12 12 import org.springframework.web.bind.annotation.GetMapping;
13   -import org.springframework.web.bind.annotation.PathVariable;
14 13 import org.springframework.web.bind.annotation.RequestMapping;
  14 +import org.springframework.web.bind.annotation.RequestParam;
15 15 import org.springframework.web.bind.annotation.RestController;
16 16  
17 17 import javax.annotation.Resource;
... ... @@ -28,11 +28,11 @@ public class AppDictDataController {
28 28 @Resource
29 29 private DictDataService dictDataService;
30 30  
31   - // TODO @疯狂:暂时不用 path 参数哈;主要考虑一些中间件支持的一般,例如说链路追踪之类的;还是作为一个参数噶;
32   - @GetMapping("/type/{dictType}")
  31 + @GetMapping("/type")
33 32 @Operation(summary = "根据字典类型查询字典数据信息")
34   - public CommonResult<List<AppDictDataRespVO>> getDictDataList(@PathVariable String dictType) {
35   - List<DictDataDO> list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(dictType));
  33 + @Parameter(name = "type", description = "字典类型", required = true, example = "common_status")
  34 + public CommonResult<List<AppDictDataRespVO>> getDictDataListByType(@RequestParam String type) {
  35 + List<DictDataDO> list = dictDataService.getEnabledDictDataListByType(type);
36 36 return success(DictDataConvert.INSTANCE.convertList03(list));
37 37 }
38 38  
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java
1 1 package cn.iocoder.yudao.module.system.controller.app.dict.vo;
2 2  
3   -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataBaseVO;
4 3 import io.swagger.v3.oas.annotations.media.Schema;
5 4 import lombok.AllArgsConstructor;
6 5 import lombok.Data;
7   -import lombok.EqualsAndHashCode;
8 6 import lombok.NoArgsConstructor;
9 7  
  8 +import javax.validation.constraints.NotBlank;
  9 +import javax.validation.constraints.NotNull;
  10 +import javax.validation.constraints.Size;
  11 +
10 12 @Schema(description = "用户 App - 字典数据信息 Response VO")
11 13 @Data
12 14 @NoArgsConstructor
13 15 @AllArgsConstructor
14   -@EqualsAndHashCode(callSuper = true)
15   -public class AppDictDataRespVO extends DictDataBaseVO {
16   -
17   - // TODO @疯狂:app 的接口,不集成 admin 接口的 vo 哈;看看是不是只返回必要的字段,类似 remark、sort 不好返回的哈;
  16 +public class AppDictDataRespVO {
18 17  
19 18 @Schema(description = "字典数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
20 19 private Long id;
21 20  
  21 + @Schema(description = "字典标签", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
  22 + @NotBlank(message = "字典标签不能为空")
  23 + @Size(max = 100, message = "字典标签长度不能超过100个字符")
  24 + private String label;
  25 +
  26 + @Schema(description = "字典值", requiredMode = Schema.RequiredMode.REQUIRED, example = "iocoder")
  27 + @NotBlank(message = "字典键值不能为空")
  28 + @Size(max = 100, message = "字典键值长度不能超过100个字符")
  29 + private String value;
  30 +
  31 + @Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex")
  32 + @NotBlank(message = "字典类型不能为空")
  33 + @Size(max = 100, message = "字典类型长度不能超过100个字符")
  34 + private String dictType;
  35 +
  36 + @Schema(description = "颜色类型,default、primary、success、info、warning、danger", example = "default")
  37 + private String colorType;
  38 + @Schema(description = "css 样式", example = "btn-visible")
  39 + private String cssClass;
  40 +
22 41 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java
... ... @@ -48,4 +48,8 @@ public interface DictDataMapper extends BaseMapperX&lt;DictDataDO&gt; {
48 48 .eqIfPresent(DictDataDO::getStatus, reqVO.getStatus()));
49 49 }
50 50  
  51 + default List<DictDataDO> selectListByTypeAndStatus(String dictType, Integer status) {
  52 + return selectList(new LambdaQueryWrapper<DictDataDO>()
  53 + .eq(DictDataDO::getDictType, dictType).eq(DictDataDO::getStatus, status));
  54 + }
51 55 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java
... ... @@ -63,6 +63,14 @@ public interface DictDataService {
63 63 List<DictDataDO> getDictDataList(DictDataExportReqVO reqVO);
64 64  
65 65 /**
  66 + * 获得字典数据列表
  67 + *
  68 + * @param dictType 字典类型
  69 + * @return 字典数据列表
  70 + */
  71 + List<DictDataDO> getEnabledDictDataListByType(String dictType);
  72 +
  73 + /**
66 74 * 获得字典数据详情
67 75 *
68 76 * @param id 字典数据编号
... ... @@ -84,7 +92,7 @@ public interface DictDataService {
84 92 * 2. 字典数据被禁用
85 93 *
86 94 * @param dictType 字典类型
87   - * @param values 字典数据值的数组
  95 + * @param values 字典数据值的数组
88 96 */
89 97 void validateDictDataList(String dictType, Collection<String> values);
90 98  
... ... @@ -92,7 +100,7 @@ public interface DictDataService {
92 100 * 获得指定的字典数据
93 101 *
94 102 * @param dictType 字典类型
95   - * @param value 字典数据值
  103 + * @param value 字典数据值
96 104 * @return 字典数据
97 105 */
98 106 DictDataDO getDictData(String dictType, String value);
... ... @@ -101,7 +109,7 @@ public interface DictDataService {
101 109 * 解析获得指定的字典数据,从缓存中
102 110 *
103 111 * @param dictType 字典类型
104   - * @param label 字典数据标签
  112 + * @param label 字典数据标签
105 113 * @return 字典数据
106 114 */
107 115 DictDataDO parseDictData(String dictType, String label);
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java
... ... @@ -67,6 +67,13 @@ public class DictDataServiceImpl implements DictDataService {
67 67 }
68 68  
69 69 @Override
  70 + public List<DictDataDO> getEnabledDictDataListByType(String dictType) {
  71 + List<DictDataDO> list = dictDataMapper.selectListByTypeAndStatus(dictType, CommonStatusEnum.ENABLE.getStatus());
  72 + list.sort(COMPARATOR_TYPE_AND_SORT);
  73 + return list;
  74 + }
  75 +
  76 + @Override
70 77 public DictDataDO getDictData(Long id) {
71 78 return dictDataMapper.selectById(id);
72 79 }
... ...