Commit 437185cb1d5fa96fd7fe35a413f40882a15034f3

Authored by jason
2 parents 6fcff086 e384b810

Merge remote-tracking branch 'origin/feature/mall_product' into feature/mall_product

Showing 159 changed files with 2428 additions and 972 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 0 not null comment '分佣模式:1-人人分销 2-指定分销',
7   - brokerage_bind_mode tinyint default 0 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_bank_names varchar(200) default '' not null comment '提现银行(字典类型=brokerage_bank_name)',
13   - brokerage_frozen_days int default 7 not null comment '佣金冻结时间(天)',
14   - brokerage_withdraw_type varchar(32) default '1,2,3,4' not null comment '提现方式:1-钱包;2-银行卡;3-微信;4-支付宝',
15   - creator varchar(64) default '' null comment '创建者',
16   - create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
17   - updater varchar(64) default '' null comment '更新者',
18   - update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
19   - deleted bit default b'0' not null comment '是否删除',
20   - tenant_id bigint default 0 not null comment '租户编号'
21   -) 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 +
  24 +# alter table trade_config
  25 +# add brokerage_withdraw_fee_percent int default 0 not null comment '提现手续费百分比' after brokerage_withdraw_min_price;
22 26  
23 27 # alter table trade_brokerage_user
24 28 # add level int not null default 1 comment '等级' after frozen_price;
... ... @@ -36,8 +40,6 @@ create table trade_brokerage_user
36 40 brokerage_time datetime null comment '成为分销员时间',
37 41 price int default 0 not null comment '可用佣金',
38 42 frozen_price int default 0 not null comment '冻结佣金',
39   - level int default 1 not null comment '等级',
40   - path varchar(2000) null comment '路径',
41 43 creator varchar(64) default '' null comment '创建者',
42 44 create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
43 45 updater varchar(64) default '' null comment '更新者',
... ... @@ -83,7 +85,7 @@ create index idx_status on trade_brokerage_record (status) comment '状态';
83 85  
84 86 create table trade_brokerage_withdraw
85 87 (
86   - id int auto_increment comment '编号'
  88 + id bigint auto_increment comment '编号'
87 89 primary key,
88 90 user_id bigint not null comment '用户编号',
89 91 price int default 0 not null comment '提现金额',
... ... @@ -137,7 +139,8 @@ insert into system_dict_type(type, name)
137 139 values ('brokerage_record_biz_type', '佣金记录业务类型');
138 140 insert into system_dict_data(dict_type, label, value, sort)
139 141 values ('brokerage_record_biz_type', '订单返佣', 1, 1),
140   - ('brokerage_record_biz_type', '申请提现', 2, 2);
  142 + ('brokerage_record_biz_type', '申请提现', 2, 2),
  143 + ('brokerage_record_biz_type', '申请提现驳回', 3, 3);
141 144  
142 145 insert into system_dict_type(type, name)
143 146 values ('brokerage_record_status', '佣金记录状态');
... ...
sql/mysql/point.sql 0 → 100644
  1 +ALTER TABLE trade_order ADD COLUMN use_point int NOT NULL DEFAULT 0 COMMENT '使用的积分' AFTER point_price;
  2 +ALTER TABLE trade_order ADD COLUMN refund_point int NOT NULL DEFAULT 0 COMMENT '退还的使用积分' AFTER use_point;
  3 +ALTER TABLE trade_order ADD COLUMN give_point int NOT NULL DEFAULT 0 COMMENT '赠送的积分' AFTER refund_point;
  4 +
  5 +ALTER TABLE trade_order_item ADD COLUMN use_point int NOT NULL DEFAULT 0 COMMENT '使用的积分' AFTER point_price;
  6 +ALTER TABLE trade_order_item ADD COLUMN give_point int NOT NULL DEFAULT 0 COMMENT '赠送的积分' AFTER use_point;
... ...
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java
... ... @@ -43,17 +43,6 @@ public class LocalDateTimeUtils {
43 43 return LocalDateTime.of(year, mouth, day, 0, 0, 0);
44 44 }
45 45  
46   - /**
47   - * 创建指定时间
48   - *
49   - * @param timeStr 时间字符串
50   - * @return 指定时间
51   - */
52   - public static LocalDateTime buildTime(String timeStr) {
53   - // TODO @puhui999:这个方法的实现,和 LocalDateTimeUtil.parse() 的差异点是啥呀
54   - return LocalDateTime.of(LocalDate.now(), LocalTime.parse(timeStr));
55   - }
56   -
57 46 public static LocalDateTime[] buildBetweenTime(int year1, int mouth1, int day1,
58 47 int year2, int mouth2, int day2) {
59 48 return new LocalDateTime[]{buildTime(year1, mouth1, day1), buildTime(year2, mouth2, day2)};
... ...
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,46 @@ 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 + }
  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 + * 例如说 fen 为 1 时,则结果为 0.01
  65 + *
  66 + * @param fen 分
  67 + * @return 元
  68 + */
  69 + public static String fenToYuanStr(int fen) {
  70 + return new Money(0, fen).toString();
  71 + }
49 72  
50 73 }
... ...
yudao-framework/yudao-spring-boot-starter-biz-error-code/pom.xml
... ... @@ -14,7 +14,7 @@
14 14 <name>${project.artifactId}</name>
15 15 <description>
16 16 错误码 ErrorCode 的自动配置功能,提供如下功能:
17   - 1. 远程读取:项目启动时,从 system-server 服务,读取数据库中的 ErrorCode 错误码,实现错误码的提水可配置;
  17 + 1. 远程读取:项目启动时,从 system-server 服务,读取数据库中的 ErrorCode 错误码,实现错误码的提示可配置;
18 18 2. 自动更新:管理员在管理后台修数据库中的 ErrorCode 错误码时,项目自动从 system-server 服务加载最新的 ErrorCode 错误码;
19 19 3. 自动写入:项目启动时,将项目本地的错误码写到 system-server 服务中,方便管理员在管理后台编辑;
20 20 </description>
... ...
yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java
... ... @@ -100,14 +100,6 @@ public class LambdaQueryWrapperX&lt;T&gt; extends LambdaQueryWrapper&lt;T&gt; {
100 100 return betweenIfPresent(column, val1, val2);
101 101 }
102 102  
103   - // TODO @疯狂:这个是 mysql 独有的,不好做成通用的哈。如果多层级,有没可能先查询一个层级,再查询一个层级;形成 set 后,直接去 in?
104   - public LambdaQueryWrapperX<T> findInSetIfPresent(SFunction<T, ?> column, Object val) {
105   - if (val != null) {
106   - return (LambdaQueryWrapperX<T>) super.apply("FIND_IN_SET({0}, " + columnToString(column) + ")", val);
107   - }
108   - return this;
109   - }
110   -
111 103 // ========== 重写父类方法,方便链式调用 ==========
112 104  
113 105 @Override
... ...
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/config/YudaoJacksonAutoConfiguration.java
1 1 package cn.iocoder.yudao.framework.jackson.config;
2 2  
3   -import cn.iocoder.yudao.framework.jackson.core.databind.NumberSerializer;
  3 +import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
4 4 import cn.iocoder.yudao.framework.jackson.core.databind.LocalDateTimeDeserializer;
5 5 import cn.iocoder.yudao.framework.jackson.core.databind.LocalDateTimeSerializer;
6   -import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
  6 +import cn.iocoder.yudao.framework.jackson.core.databind.NumberSerializer;
7 7 import com.fasterxml.jackson.databind.ObjectMapper;
8 8 import com.fasterxml.jackson.databind.module.SimpleModule;
  9 +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
  10 +import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
  11 +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
  12 +import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
9 13 import lombok.extern.slf4j.Slf4j;
10 14 import org.springframework.beans.BeansException;
11 15 import org.springframework.beans.factory.config.BeanPostProcessor;
12 16 import org.springframework.boot.autoconfigure.AutoConfiguration;
13 17 import org.springframework.context.annotation.Bean;
14 18  
  19 +import java.time.LocalDate;
15 20 import java.time.LocalDateTime;
  21 +import java.time.LocalTime;
16 22  
17 23 @AutoConfiguration
18 24 @Slf4j
... ... @@ -36,6 +42,10 @@ public class YudaoJacksonAutoConfiguration {
36 42 simpleModule
37 43 .addSerializer(Long.class, NumberSerializer.INSTANCE)
38 44 .addSerializer(Long.TYPE, NumberSerializer.INSTANCE)
  45 + .addSerializer(LocalDate.class, LocalDateSerializer.INSTANCE)
  46 + .addDeserializer(LocalDate.class, LocalDateDeserializer.INSTANCE)
  47 + .addSerializer(LocalTime.class, LocalTimeSerializer.INSTANCE)
  48 + .addDeserializer(LocalTime.class, LocalTimeDeserializer.INSTANCE)
39 49 .addSerializer(LocalDateTime.class, LocalDateTimeSerializer.INSTANCE)
40 50 .addDeserializer(LocalDateTime.class, LocalDateTimeDeserializer.INSTANCE);
41 51  
... ...
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java
... ... @@ -111,6 +111,11 @@ public class ProductSpuRespDTO {
111 111 // ========== 物流相关字段 =========
112 112  
113 113 /**
  114 + * 赠送积分
  115 + */
  116 + private Integer giveIntegral;
  117 +
  118 + /**
114 119 * 物流配置模板编号
115 120 *
116 121 * 对应 TradeDeliveryExpressTemplateDO 的 id 编号
... ... @@ -132,4 +137,15 @@ public class ProductSpuRespDTO {
132 137 */
133 138 private Integer clickCount;
134 139  
  140 +
  141 + // ========== 分销相关字段 =========
  142 +
  143 + /**
  144 + * 分销类型
  145 + *
  146 + * false - 默认
  147 + * true - 自行设置
  148 + */
  149 + private Boolean subCommissionType;
  150 +
135 151 }
... ...
yudao-module-mall/yudao-module-product-biz/pom.xml
... ... @@ -23,12 +23,6 @@
23 23 <artifactId>yudao-module-product-api</artifactId>
24 24 <version>${revision}</version>
25 25 </dependency>
26   - <!-- TODO 芋艿:看看~~~ -->
27   - <dependency>
28   - <groupId>cn.iocoder.boot</groupId>
29   - <artifactId>yudao-module-trade-api</artifactId>
30   - <version>${revision}</version>
31   - </dependency>
32 26 <dependency>
33 27 <groupId>cn.iocoder.boot</groupId>
34 28 <artifactId>yudao-module-member-api</artifactId>
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/property/ProductPropertyValueApiImpl.java
1 1 package cn.iocoder.yudao.module.product.api.property;
2 2  
3 3 import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
4   -import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert;
  4 +import cn.iocoder.yudao.module.product.convert.property.ProductPropertyValueConvert;
5 5 import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService;
6 6 import org.springframework.stereotype.Service;
7 7 import org.springframework.validation.annotation.Validated;
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyValueController.java
1 1 package cn.iocoder.yudao.module.product.controller.admin.property;
2 2  
3   -import cn.hutool.core.collection.CollectionUtil;
4   -import cn.hutool.crypto.symmetric.AES;
5 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
6 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
7 5 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO;
8 6 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO;
9 7 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO;
10 8 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO;
11   -import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert;
  9 +import cn.iocoder.yudao.module.product.convert.property.ProductPropertyValueConvert;
12 10 import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService;
13 11 import io.swagger.v3.oas.annotations.Operation;
14 12 import io.swagger.v3.oas.annotations.Parameter;
... ... @@ -20,9 +18,6 @@ import org.springframework.web.bind.annotation.*;
20 18 import javax.annotation.Resource;
21 19 import javax.validation.Valid;
22 20  
23   -import java.util.Arrays;
24   -import java.util.List;
25   -
26 21 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
27 22  
28 23 @Tag(name = "管理后台 - 商品属性值")
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java
1 1 package cn.iocoder.yudao.module.product.controller.app.spu;
2 2  
  3 +import cn.hutool.core.collection.CollUtil;
3 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.module.member.api.level.MemberLevelApi;
  7 +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO;
  8 +import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
  9 +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
5 10 import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuDetailRespVO;
6   -import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageRespVO;
7 11 import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO;
  12 +import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageRespVO;
8 13 import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert;
9 14 import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
10 15 import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
... ... @@ -23,10 +28,12 @@ import org.springframework.web.bind.annotation.RestController;
23 28  
24 29 import javax.annotation.Resource;
25 30 import javax.validation.Valid;
  31 +import java.util.Collections;
26 32 import java.util.List;
27 33  
28 34 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
29 35 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  36 +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
30 37 import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_ENABLE;
31 38 import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS;
32 39  
... ... @@ -41,6 +48,11 @@ public class AppProductSpuController {
41 48 @Resource
42 49 private ProductSkuService productSkuService;
43 50  
  51 + @Resource
  52 + private MemberLevelApi memberLevelApi;
  53 + @Resource
  54 + private MemberUserApi memberUserApi;
  55 +
44 56 @GetMapping("/list")
45 57 @Operation(summary = "获得商品 SPU 列表")
46 58 @Parameters({
... ... @@ -51,14 +63,32 @@ public class AppProductSpuController {
51 63 @RequestParam("recommendType") String recommendType,
52 64 @RequestParam(value = "count", defaultValue = "10") Integer count) {
53 65 List<ProductSpuDO> list = productSpuService.getSpuList(recommendType, count);
54   - return success(ProductSpuConvert.INSTANCE.convertListForGetSpuList(list));
  66 + if (CollUtil.isEmpty(list)) {
  67 + return success(Collections.emptyList());
  68 + }
  69 +
  70 + // 拼接返回
  71 + List<AppProductSpuPageRespVO> voList = ProductSpuConvert.INSTANCE.convertListForGetSpuList(list);
  72 + // 处理 vip 价格
  73 + MemberLevelRespDTO memberLevel = getMemberLevel();
  74 + voList.forEach(vo -> vo.setVipPrice(calculateVipPrice(vo.getPrice(), memberLevel)));
  75 + return success(voList);
55 76 }
56 77  
57 78 @GetMapping("/page")
58 79 @Operation(summary = "获得商品 SPU 分页")
59 80 public CommonResult<PageResult<AppProductSpuPageRespVO>> getSpuPage(@Valid AppProductSpuPageReqVO pageVO) {
60 81 PageResult<ProductSpuDO> pageResult = productSpuService.getSpuPage(pageVO);
61   - return success(ProductSpuConvert.INSTANCE.convertPageForGetSpuPage(pageResult));
  82 + if (CollUtil.isEmpty(pageResult.getList())) {
  83 + return success(PageResult.empty(pageResult.getTotal()));
  84 + }
  85 +
  86 + // 拼接返回
  87 + PageResult<AppProductSpuPageRespVO> voPageResult = ProductSpuConvert.INSTANCE.convertPageForGetSpuPage(pageResult);
  88 + // 处理 vip 价格
  89 + MemberLevelRespDTO memberLevel = getMemberLevel();
  90 + voPageResult.getList().forEach(vo -> vo.setVipPrice(calculateVipPrice(vo.getPrice(), memberLevel)));
  91 + return success(voPageResult);
62 92 }
63 93  
64 94 @GetMapping("/get-detail")
... ... @@ -74,10 +104,40 @@ public class AppProductSpuController {
74 104 throw exception(SPU_NOT_ENABLE);
75 105 }
76 106  
77   - // 查询商品 SKU
  107 + // 拼接返回
78 108 List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spu.getId());
79   - // 拼接
80   - return success(ProductSpuConvert.INSTANCE.convertForGetSpuDetail(spu, skus));
  109 + AppProductSpuDetailRespVO detailVO = ProductSpuConvert.INSTANCE.convertForGetSpuDetail(spu, skus);
  110 + // 处理 vip 价格
  111 + MemberLevelRespDTO memberLevel = getMemberLevel();
  112 + detailVO.setVipPrice(calculateVipPrice(detailVO.getPrice(), memberLevel));
  113 + return success(detailVO);
  114 + }
  115 +
  116 + private MemberLevelRespDTO getMemberLevel() {
  117 + Long userId = getLoginUserId();
  118 + if (userId == null) {
  119 + return null;
  120 + }
  121 + MemberUserRespDTO user = memberUserApi.getUser(userId);
  122 + if (user.getLevelId() == null || user.getLevelId() <= 0) {
  123 + return null;
  124 + }
  125 + return memberLevelApi.getMemberLevel(user.getLevelId());
  126 + }
  127 +
  128 + /**
  129 + * 计算会员 VIP 优惠价格
  130 + *
  131 + * @param price 原价
  132 + * @param memberLevel 会员等级
  133 + * @return 优惠价格
  134 + */
  135 + public Integer calculateVipPrice(Integer price, MemberLevelRespDTO memberLevel) {
  136 + if (memberLevel == null || memberLevel.getDiscountPercent() == null) {
  137 + return 0;
  138 + }
  139 + Integer newPrice = price * memberLevel.getDiscountPercent() / 100;
  140 + return price - newPrice;
81 141 }
82 142  
83 143 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/propertyvalue/ProductPropertyValueConvert.java renamed to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/property/ProductPropertyValueConvert.java
1   -package cn.iocoder.yudao.module.product.convert.propertyvalue;
  1 +package cn.iocoder.yudao.module.product.convert.property;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 4 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java
... ... @@ -79,8 +79,6 @@ public interface ProductSpuConvert {
79 79 ProductSpuDO spu = list.get(i);
80 80 AppProductSpuPageRespVO spuVO = voList.get(i);
81 81 spuVO.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()));
82   - // 计算 vip 价格 TODO 芋艿:临时的逻辑,等 vip 支持后
83   - spuVO.setVipPrice((int) (spuVO.getPrice() * 0.9));
84 82 }
85 83 return voList;
86 84 }
... ... @@ -95,11 +93,6 @@ public interface ProductSpuConvert {
95 93 .setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()));
96 94 // 处理 SKU
97 95 spuVO.setSkus(convertListForGetSpuDetail(skus));
98   - // 计算 vip 价格 TODO 芋艿:临时的逻辑,等 vip 支持后
99   - if (true) {
100   - spuVO.setVipPrice((int) (spuVO.getPrice() * 0.9));
101   - spuVO.getSkus().forEach(sku -> sku.setVipPrice((int) (sku.getPrice() * 0.9)));
102   - }
103 96 return spuVO;
104 97 }
105 98  
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java
... ... @@ -179,6 +179,7 @@ public class ProductSpuDO extends BaseDO {
179 179 @TableField(typeHandler = JacksonTypeHandler.class)
180 180 private List<Long> giveCouponTemplateIds;
181 181  
  182 + // TODO @puhui999:字段估计要改成 brokerageType
182 183 /**
183 184 * 分销类型
184 185 *
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/package-info.java
1 1 /**
2   - * trade 模块,主要实现交易相关功能
  2 + * product 模块,主要实现交易相关功能
3 3 * 例如:订单、退款、购物车等功能。
4 4 *
5 5 * 1. Controller URL:以 /product/ 开头,避免和其它 Module 冲突
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java
... ... @@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 5 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO;
6 6 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO;
7 7 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO;
8   -import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert;
  8 +import cn.iocoder.yudao.module.product.convert.property.ProductPropertyValueConvert;
9 9 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
10 10 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
11 11 import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyValueMapper;
... ...
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApi.java
... ... @@ -11,7 +11,7 @@ public interface BargainActivityApi {
11 11 * 更新砍价活动库存
12 12 *
13 13 * @param id 砍价活动编号
14   - * @param count 购买数量
  14 + * @param count 购买数量
15 15 */
16 16 void updateBargainActivityStock(Long id, Integer count);
17 17  
... ...
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java
... ... @@ -7,14 +7,13 @@ package cn.iocoder.yudao.module.promotion.api.seckill;
7 7 */
8 8 public interface SeckillActivityApi {
9 9  
10   - // TODO @puhui999:activityId 改成 id 好点哈;
11 10 /**
12 11 * 更新秒杀库存
13 12 *
14   - * @param activityId 活动编号
  13 + * @param id 活动编号
15 14 * @param skuId sku 编号
16 15 * @param count 数量
17 16 */
18   - void updateSeckillStock(Long activityId, Long skuId, Integer count);
  17 + void updateSeckillStock(Long id, Long skuId, Integer count);
19 18  
20 19 }
... ...
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java
... ... @@ -56,7 +56,6 @@ public interface ErrorCodeConstants {
56 56 ErrorCode SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013008004, "秒杀活动未关闭或未结束,不能删除");
57 57 ErrorCode SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED = new ErrorCode(1013008005, "秒杀活动已关闭,不能重复关闭");
58 58 ErrorCode SECKILL_ACTIVITY_UPDATE_STOCK_FAIL = new ErrorCode(1013008006, "秒杀失败,原因秒杀库存不足");
59   - ErrorCode SECKILL_ACTIVITY_FAIL_STATUS_CLOSED = new ErrorCode(1013008007, "秒杀活动已关闭");
60 59  
61 60 // ========== 秒杀时段 1013009000 ==========
62 61 ErrorCode SECKILL_CONFIG_NOT_EXISTS = new ErrorCode(1013009000, "秒杀时段不存在");
... ...
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionTypeEnum.java
... ... @@ -22,8 +22,9 @@ public enum PromotionTypeEnum implements IntArrayValuable {
22 22 DISCOUNT_ACTIVITY(4, "限时折扣"),
23 23 REWARD_ACTIVITY(5, "满减送"),
24 24  
25   - MEMBER(6, "会员折扣"),
26   - COUPON(7, "优惠劵")
  25 + MEMBER_LEVEL(6, "会员折扣"),
  26 + COUPON(7, "优惠劵"),
  27 + POINT(8, "积分")
27 28 ;
28 29  
29 30 public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionTypeEnum::getType).toArray();
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java
... ... @@ -17,8 +17,8 @@ public class SeckillActivityApiImpl implements SeckillActivityApi {
17 17 private SeckillActivityService activityService;
18 18  
19 19 @Override
20   - public void updateSeckillStock(Long activityId, Long skuId, Integer count) {
21   - activityService.updateSeckillStock(activityId, skuId, count);
  20 + public void updateSeckillStock(Long id, Long skuId, Integer count) {
  21 + activityService.updateSeckillStock(id, skuId, count);
22 22 }
23 23  
24 24 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainActivityController.java
... ... @@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
23 23 import javax.annotation.Resource;
24 24 import java.util.List;
25 25  
  26 +import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
26 27 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
27 28 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
28 29  
... ... @@ -39,7 +40,7 @@ public class AppBargainActivityController {
39 40 @GetMapping("/page")
40 41 @Operation(summary = "获得砍价活动分页")
41 42 public CommonResult<PageResult<AppBargainActivityRespVO>> getBargainActivityPage(PageParam pageReqVO) {
42   - PageResult<BargainActivityDO> result = bargainActivityService.getBargainActivityPageForApp(pageReqVO);
  43 + PageResult<BargainActivityDO> result = bargainActivityService.getBargainActivityPage(pageReqVO);
43 44 if (CollUtil.isEmpty(result.getList())) {
44 45 return success(PageResult.empty(result.getTotal()));
45 46 }
... ... @@ -54,7 +55,7 @@ public class AppBargainActivityController {
54 55 @Parameter(name = "count", description = "需要展示的数量", example = "6")
55 56 public CommonResult<List<AppBargainActivityRespVO>> getBargainActivityList(
56 57 @RequestParam(name = "count", defaultValue = "6") Integer count) {
57   - List<BargainActivityDO> list = bargainActivityService.getBargainActivityListForApp(count);
  58 + List<BargainActivityDO> list = bargainActivityService.getBargainActivityListByCount(defaultIfNull(count, 6));
58 59 if (CollUtil.isEmpty(list)) {
59 60 return success(BargainActivityConvert.INSTANCE.convertAppList(list));
60 61 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java
1 1 package cn.iocoder.yudao.module.promotion.controller.app.combination;
2 2  
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.util.ObjectUtil;
  5 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
3 6 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 7 import cn.iocoder.yudao.framework.common.pojo.PageParam;
5 8 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  9 +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
  10 +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
6 11 import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityDetailRespVO;
7 12 import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityRespVO;
  13 +import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert;
  14 +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO;
  15 +import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO;
  16 +import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService;
8 17 import io.swagger.v3.oas.annotations.Operation;
9 18 import io.swagger.v3.oas.annotations.Parameter;
10 19 import io.swagger.v3.oas.annotations.tags.Tag;
... ... @@ -14,11 +23,13 @@ import org.springframework.web.bind.annotation.RequestMapping;
14 23 import org.springframework.web.bind.annotation.RequestParam;
15 24 import org.springframework.web.bind.annotation.RestController;
16 25  
17   -import java.time.LocalDateTime;
18   -import java.util.ArrayList;
  26 +import javax.annotation.Resource;
  27 +import java.util.Collections;
19 28 import java.util.List;
20 29  
  30 +import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
21 31 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  32 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
22 33  
23 34 @Tag(name = "用户 APP - 拼团活动")
24 35 @RestController
... ... @@ -26,104 +37,51 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
26 37 @Validated
27 38 public class AppCombinationActivityController {
28 39  
  40 + @Resource
  41 + private CombinationActivityService activityService;
  42 + @Resource
  43 + private ProductSpuApi spuApi;
  44 +
  45 + // TODO 芋艿:增加 Spring Cache
29 46 @GetMapping("/list")
30 47 @Operation(summary = "获得拼团活动列表", description = "用于小程序首页")
31   - // TODO 芋艿:增加 Spring Cache
32   - // TODO 芋艿:缺少 swagger 注解
  48 + @Parameter(name = "count", description = "需要展示的数量", example = "6")
33 49 public CommonResult<List<AppCombinationActivityRespVO>> getCombinationActivityList(
34 50 @RequestParam(name = "count", defaultValue = "6") Integer count) {
35   - List<AppCombinationActivityRespVO> activityList = new ArrayList<>();
36   - AppCombinationActivityRespVO activity1 = new AppCombinationActivityRespVO();
37   - activity1.setId(1L);
38   - activity1.setName("618 大拼团");
39   - activity1.setUserSize(3);
40   - activity1.setSpuId(2048L);
41   - activity1.setPicUrl("https://static.iocoder.cn/mall/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg");
42   - activity1.setMarketPrice(50);
43   - activity1.setCombinationPrice(100);
44   - activityList.add(activity1);
45   -
46   - AppCombinationActivityRespVO activity2 = new AppCombinationActivityRespVO();
47   - activity2.setId(2L);
48   - activity2.setName("双十一拼团");
49   - activity2.setUserSize(5);
50   - activity2.setSpuId(4096L);
51   - activity2.setPicUrl("https://static.iocoder.cn/mall/132.jpeg");
52   - activity2.setMarketPrice(100);
53   - activity2.setCombinationPrice(200);
54   - activityList.add(activity2);
55   -
56   - return success(activityList);
  51 + List<CombinationActivityDO> list = activityService.getCombinationActivityListByCount(defaultIfNull(count, 6));
  52 + if (CollUtil.isEmpty(list)) {
  53 + return success(Collections.emptyList());
  54 + }
  55 + // 拼接返回
  56 + List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(list, CombinationActivityDO::getSpuId));
  57 + return success(CombinationActivityConvert.INSTANCE.convertAppList(list, spuList));
57 58 }
58 59  
59 60 @GetMapping("/page")
60 61 @Operation(summary = "获得拼团活动分页")
61 62 public CommonResult<PageResult<AppCombinationActivityRespVO>> getCombinationActivityPage(PageParam pageParam) {
62   - List<AppCombinationActivityRespVO> activityList = new ArrayList<>();
63   - AppCombinationActivityRespVO activity1 = new AppCombinationActivityRespVO();
64   - activity1.setId(1L);
65   - activity1.setName("618 大拼团");
66   - activity1.setUserSize(3);
67   - activity1.setSpuId(2048L);
68   - activity1.setPicUrl("商品图片地址");
69   - activity1.setMarketPrice(50);
70   - activity1.setCombinationPrice(100);
71   - activityList.add(activity1);
72   -
73   - AppCombinationActivityRespVO activity2 = new AppCombinationActivityRespVO();
74   - activity2.setId(2L);
75   - activity2.setName("双十一拼团");
76   - activity2.setUserSize(5);
77   - activity2.setSpuId(4096L);
78   - activity2.setPicUrl("商品图片地址");
79   - activity2.setMarketPrice(100);
80   - activity2.setCombinationPrice(200);
81   - activityList.add(activity2);
82   -
83   - return success(new PageResult<>(activityList, 2L));
  63 + PageResult<CombinationActivityDO> result = activityService.getCombinationActivityPage(pageParam);
  64 + if (CollUtil.isEmpty(result.getList())) {
  65 + return success(PageResult.empty(result.getTotal()));
  66 + }
  67 + // 拼接返回
  68 + List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(result.getList(), CombinationActivityDO::getSpuId));
  69 + return success(CombinationActivityConvert.INSTANCE.convertAppPage(result, spuList));
84 70 }
85 71  
86 72 @GetMapping("/get-detail")
87 73 @Operation(summary = "获得拼团活动明细")
88 74 @Parameter(name = "id", description = "活动编号", required = true, example = "1024")
89 75 public CommonResult<AppCombinationActivityDetailRespVO> getCombinationActivityDetail(@RequestParam("id") Long id) {
90   - // TODO 芋艿:如果禁用的时候,需要抛出异常;
91   - AppCombinationActivityDetailRespVO obj = new AppCombinationActivityDetailRespVO();
92   - // 设置其属性的值
93   - obj.setId(id);
94   - obj.setName("晚九点限时秒杀");
95   - obj.setStatus(1);
96   - obj.setStartTime(LocalDateTime.of(2023, 6, 15, 0, 0, 0));
97   - obj.setEndTime(LocalDateTime.of(2023, 6, 20, 23, 59, 0));
98   - obj.setUserSize(2);
99   - obj.setSuccessCount(100);
100   - obj.setSpuId(633L);
101   - obj.setSingleLimitCount(2);
102   - obj.setTotalLimitCount(3);
103   -
104   - // 创建一个Product对象的列表
105   - List<AppCombinationActivityDetailRespVO.Product> productList = new ArrayList<>();
106   - // 创建三个新的Product对象并设置其属性的值
107   - AppCombinationActivityDetailRespVO.Product product1 = new AppCombinationActivityDetailRespVO.Product();
108   - product1.setSkuId(1L);
109   - product1.setCombinationPrice(100);
110   - // 将第一个Product对象添加到列表中
111   - productList.add(product1);
112   - // 创建第二个Product对象并设置其属性的值
113   - AppCombinationActivityDetailRespVO.Product product2 = new AppCombinationActivityDetailRespVO.Product();
114   - product2.setSkuId(2L);
115   - product2.setCombinationPrice(200);
116   - // 将第二个Product对象添加到列表中
117   - productList.add(product2);
118   - // 创建第三个Product对象并设置其属性的值
119   - AppCombinationActivityDetailRespVO.Product product3 = new AppCombinationActivityDetailRespVO.Product();
120   - product3.setSkuId(3L);
121   - product3.setCombinationPrice(300);
122   - // 将第三个Product对象添加到列表中
123   - productList.add(product3);
124   - // 将Product列表设置为对象的属性值
125   - obj.setProducts(productList);
126   - return success(obj);
  76 + // 1、获取活动
  77 + CombinationActivityDO combinationActivity = activityService.getCombinationActivity(id);
  78 + if (combinationActivity == null
  79 + || ObjectUtil.equal(combinationActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
  80 + return success(null);
  81 + }
  82 + // 2、获取活动商品
  83 + List<CombinationProductDO> products = activityService.getCombinationProductsByActivityId(combinationActivity.getId());
  84 + return success(CombinationActivityConvert.INSTANCE.convert3(combinationActivity, products));
127 85 }
128 86  
129 87 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityRespVO.java
... ... @@ -28,7 +28,6 @@ public class AppCombinationActivityRespVO {
28 28 private Integer marketPrice;
29 29  
30 30 @Schema(description = "拼团金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
31   - // 从拼团商品里取最低价
32 31 private Integer combinationPrice;
33 32  
34 33 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java
1 1 package cn.iocoder.yudao.module.promotion.controller.app.seckill;
2 2  
  3 +import cn.hutool.core.collection.CollUtil;
3 4 import cn.hutool.core.util.ObjectUtil;
4 5 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
5 6 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
... ... @@ -27,14 +28,10 @@ import org.springframework.web.bind.annotation.RequestParam;
27 28 import org.springframework.web.bind.annotation.RestController;
28 29  
29 30 import javax.annotation.Resource;
30   -import java.util.Arrays;
31 31 import java.util.List;
32 32  
33   -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
34 33 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
35   -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
36   -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.isBetween;
37   -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL_ACTIVITY_FAIL_STATUS_CLOSED;
  34 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
38 35  
39 36 @Tag(name = "用户 App - 秒杀活动")
40 37 @RestController
... ... @@ -50,27 +47,21 @@ public class AppSeckillActivityController {
50 47 @Resource
51 48 private ProductSpuApi spuApi;
52 49  
53   - @GetMapping("/get-now")
54   - @Operation(summary = "获得当前秒杀活动") // 提供给首页使用
55 50 // TODO 芋艿:需要增加 spring cache
  51 + @GetMapping("/get-now")
  52 + @Operation(summary = "获得当前秒杀活动", description = "获取当前正在进行的活动,提供给首页使用")
56 53 public CommonResult<AppSeckillActivityNowRespVO> getNowSeckillActivity() {
57 54 // 1. 获取当前时间处在哪个秒杀阶段
58   - // TODO @puhui999:可以考虑在 service 写个方法;这样 controller 不用关注过多逻辑
59   - List<SeckillConfigDO> configList = configService.getSeckillConfigList();
60   - SeckillConfigDO filteredConfig = findFirst(configList, config -> ObjectUtil.equal(config.getStatus(),
61   - CommonStatusEnum.ENABLE.getStatus()) && isBetween(config.getStartTime(), config.getEndTime()));
62   - if (filteredConfig == null) { // 时段不存在直接返回 null
  55 + SeckillConfigDO configList = configService.getSeckillConfigListByStatusOnCurrentTime(CommonStatusEnum.ENABLE.getStatus());
  56 + if (configList == null) { // 时段不存在直接返回 null
63 57 return success(null);
64 58 }
65 59  
66 60 // 2. 查询满足当前阶段的活动
67   - // TODO @puhui999:最好直接返回开启的;不多查询数据
68   - List<SeckillActivityDO> activityList = activityService.getSeckillActivityListByConfigIds(Arrays.asList(filteredConfig.getId()));
69   - List<SeckillActivityDO> filteredList = filterList(activityList, item -> ObjectUtil.equal(item.getStatus(), CommonStatusEnum.ENABLE.getStatus()));
70   -
71   - // 3. 拼接数据
72   - List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(filteredList, SeckillActivityDO::getSpuId));
73   - return success(SeckillActivityConvert.INSTANCE.convert(filteredConfig, filteredList, spuList));
  61 + List<SeckillActivityDO> activityList = activityService.getSeckillActivityListByConfigIdAndStatus(configList.getId(), CommonStatusEnum.ENABLE.getStatus());
  62 + // 3 获取 spu 信息
  63 + List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId));
  64 + return success(SeckillActivityConvert.INSTANCE.convert(configList, activityList, spuList));
74 65 }
75 66  
76 67 @GetMapping("/page")
... ... @@ -78,7 +69,9 @@ public class AppSeckillActivityController {
78 69 public CommonResult<PageResult<AppSeckillActivityRespVO>> getSeckillActivityPage(AppSeckillActivityPageReqVO pageReqVO) {
79 70 // 1. 查询满足当前阶段的活动
80 71 PageResult<SeckillActivityDO> pageResult = activityService.getSeckillActivityAppPageByConfigId(pageReqVO);
81   -
  72 + if (CollUtil.isEmpty(pageResult.getList())) {
  73 + return success(PageResult.empty(pageResult.getTotal()));
  74 + }
82 75 // 2. 拼接数据
83 76 List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(pageResult.getList(), SeckillActivityDO::getSpuId));
84 77 return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult, spuList));
... ... @@ -88,28 +81,22 @@ public class AppSeckillActivityController {
88 81 @Operation(summary = "获得秒杀活动明细")
89 82 @Parameter(name = "id", description = "活动编号", required = true, example = "1024")
90 83 public CommonResult<AppSeckillActivityDetailRespVO> getSeckillActivity(@RequestParam("id") Long id) {
91   - // 1、获取当前时间处在哪个秒杀阶段
92   - // TODO puhui999:这里,和 58 行是雷同的
93   - List<SeckillConfigDO> configList = configService.getSeckillConfigList();
94   - SeckillConfigDO filteredConfig = findFirst(configList, config -> ObjectUtil.equal(config.getStatus(),
95   - CommonStatusEnum.ENABLE.getStatus()) && isBetween(config.getStartTime(), config.getEndTime()));
96   - if (filteredConfig == null) { // 时段不存在直接返回 null
  84 + // 1. 获取当前时间处在哪个秒杀阶段
  85 + SeckillConfigDO configList = configService.getSeckillConfigListByStatusOnCurrentTime(CommonStatusEnum.ENABLE.getStatus());
  86 + if (configList == null) { // 时段不存在直接返回 null
97 87 return success(null);
98 88 }
99 89  
100 90 // 2. 获取活动
101 91 SeckillActivityDO seckillActivity = activityService.getSeckillActivity(id);
102   - if (seckillActivity == null) {
  92 + if (seckillActivity == null
  93 + || ObjectUtil.equal(seckillActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
103 94 return success(null);
104 95 }
105   - // TODO 芋艿:如果禁用的时候,需要抛出异常;
106   - if (ObjectUtil.equal(seckillActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
107   - throw exception(SECKILL_ACTIVITY_FAIL_STATUS_CLOSED);
108   - }
109 96  
110 97 // 3. 拼接数据
111   - List<SeckillProductDO> products = activityService.getSeckillProductListByActivityId(seckillActivity.getId());
112   - return success(SeckillActivityConvert.INSTANCE.convert3(seckillActivity, products, filteredConfig));
  98 + List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityId(seckillActivity.getId());
  99 + return success(SeckillActivityConvert.INSTANCE.convert3(seckillActivity, productList, configList));
113 100 }
114 101  
115 102 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillConfigController.java
1 1 package cn.iocoder.yudao.module.promotion.controller.app.seckill;
2 2  
3   -import cn.hutool.core.collection.CollectionUtil;
4 3 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
5 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
6 5 import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.config.AppSeckillConfigRespVO;
7 6 import cn.iocoder.yudao.module.promotion.convert.seckill.seckillconfig.SeckillConfigConvert;
8   -import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillconfig.SeckillConfigDO;
9 7 import cn.iocoder.yudao.module.promotion.service.seckill.SeckillConfigService;
10 8 import io.swagger.v3.oas.annotations.Operation;
11 9 import io.swagger.v3.oas.annotations.tags.Tag;
... ... @@ -15,7 +13,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
15 13 import org.springframework.web.bind.annotation.RestController;
16 14  
17 15 import javax.annotation.Resource;
18   -import java.util.Collections;
19 16 import java.util.List;
20 17  
21 18 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
... ... @@ -31,13 +28,8 @@ public class AppSeckillConfigController {
31 28 @GetMapping("/list")
32 29 @Operation(summary = "获得秒杀时间段列表")
33 30 public CommonResult<List<AppSeckillConfigRespVO>> getSeckillConfigList() {
34   - List<SeckillConfigDO> list = configService.getSeckillConfigListByStatus(CommonStatusEnum.ENABLE.getStatus());
35   - // TODO @puhui999:如果这种,不用判空也问题不大;
36   - if (CollectionUtil.isEmpty(list)) {
37   - return success(Collections.emptyList());
38   - }
39   -
40   - return success(SeckillConfigConvert.INSTANCE.convertList2(list));
  31 + return success(SeckillConfigConvert.INSTANCE.convertList2(
  32 + configService.getSeckillConfigListByStatus(CommonStatusEnum.ENABLE.getStatus())));
41 33 }
42 34  
43 35 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/activity/AppSeckillActivityRespVO.java
... ... @@ -25,6 +25,9 @@ public class AppSeckillActivityRespVO {
25 25 // 从 SPU 的 marketPrice 读取
26 26 private Integer marketPrice;
27 27  
  28 + @Schema(description = "秒杀活动状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  29 + private Integer status;
  30 +
28 31 @Schema(description = "秒杀库存(剩余)", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
29 32 private Integer stock;
30 33 @Schema(description = "秒杀库存(总共)", requiredMode = Schema.RequiredMode.REQUIRED, example = "200")
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java
... ... @@ -46,9 +46,7 @@ public interface BargainActivityConvert {
46 46 Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
47 47 List<BargainActivityRespVO> list = CollectionUtils.convertList(result.getList(), item -> {
48 48 findAndThen(spuMap, item.getSpuId(), spu -> {
49   - // TODO @puhui999:这里可以使用链式哈
50   - item.setPicUrl(spu.getPicUrl());
51   - item.setSpuName(spu.getName());
  49 + item.setPicUrl(spu.getPicUrl()).setSpuName(spu.getName());
52 50 });
53 51 return item;
54 52 });
... ... @@ -75,11 +73,7 @@ public interface BargainActivityConvert {
75 73 // 拼接关联属性
76 74 Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
77 75 List<AppBargainActivityRespVO> list = CollectionUtils.convertList(result.getList(), item -> {
78   - findAndThen(spuMap, item.getSpuId(), spu -> {
79   - // TODO @puhui999:这里可以使用链式哈
80   - item.setPicUrl(spu.getPicUrl());
81   - item.setMarketPrice(spu.getMarketPrice());
82   - });
  76 + findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()));
83 77 return item;
84 78 });
85 79 result.setList(list);
... ... @@ -92,11 +86,7 @@ public interface BargainActivityConvert {
92 86 List<AppBargainActivityRespVO> activityList = convertAppList(list);
93 87 Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
94 88 return CollectionUtils.convertList(activityList, item -> {
95   - findAndThen(spuMap, item.getSpuId(), spu -> {
96   - // TODO @puhui999:这里可以使用链式哈
97   - item.setPicUrl(spu.getPicUrl());
98   - item.setMarketPrice(spu.getMarketPrice());
99   - });
  89 + findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()));
100 90 return item;
101 91 });
102 92 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java
... ... @@ -13,6 +13,8 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activit
13 13 import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO;
14 14 import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductBaseVO;
15 15 import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductRespVO;
  16 +import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityDetailRespVO;
  17 +import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityRespVO;
16 18 import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO;
17 19 import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO;
18 20 import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO;
... ... @@ -25,6 +27,7 @@ import java.util.List;
25 27 import java.util.Map;
26 28  
27 29 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
  30 +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
28 31  
29 32 /**
30 33 * 拼团活动 Convert
... ... @@ -58,10 +61,7 @@ public interface CombinationActivityConvert {
58 61 Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
59 62 PageResult<CombinationActivityRespVO> pageResult = convertPage(page);
60 63 pageResult.getList().forEach(item -> {
61   - MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> {
62   - item.setSpuName(spu.getName());
63   - item.setPicUrl(spu.getPicUrl());
64   - });
  64 + MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> item.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl()));
65 65 item.setProducts(convertList2(productList));
66 66 });
67 67 return pageResult;
... ... @@ -97,18 +97,51 @@ public interface CombinationActivityConvert {
97 97 default CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO,
98 98 CombinationActivityDO activity, MemberUserRespDTO user,
99 99 ProductSpuRespDTO spu, ProductSkuRespDTO sku) {
100   - // TODO @puhui999:搞成链式的 set;这样会更规整一点;
101   - CombinationRecordDO record = convert(reqDTO);
102   - record.setVirtualGroup(false);
103   - record.setExpireTime(record.getStartTime().plusHours(activity.getLimitDuration()));
104   - record.setUserSize(activity.getUserSize());
105   - record.setNickname(user.getNickname());
106   - record.setAvatar(user.getAvatar());
107   - record.setSpuName(spu.getName());
108   - record.setPicUrl(sku.getPicUrl());
109   - return record;
  100 + // TODO @puhui999:订单付款后需要设置开始时间和结束时间;
  101 + return convert(reqDTO)
  102 + .setVirtualGroup(false)
  103 + .setExpireTime(activity.getStartTime().plusHours(activity.getLimitDuration()))
  104 + .setUserSize(activity.getUserSize())
  105 + .setNickname(user.getNickname())
  106 + .setAvatar(user.getAvatar())
  107 + .setSpuName(spu.getName())
  108 + .setPicUrl(sku.getPicUrl());
110 109 }
111 110  
112 111 List<CombinationRecordRespDTO> convert(List<CombinationRecordDO> bean);
113 112  
  113 + List<AppCombinationActivityRespVO> convertAppList(List<CombinationActivityDO> list);
  114 +
  115 + default List<AppCombinationActivityRespVO> convertAppList(List<CombinationActivityDO> list, List<ProductSpuRespDTO> spuList) {
  116 + List<AppCombinationActivityRespVO> activityList = convertAppList(list);
  117 + Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
  118 + return CollectionUtils.convertList(activityList, item -> {
  119 + findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()));
  120 + return item;
  121 + });
  122 + }
  123 +
  124 + PageResult<AppCombinationActivityRespVO> convertAppPage(PageResult<CombinationActivityDO> result);
  125 +
  126 + default PageResult<AppCombinationActivityRespVO> convertAppPage(PageResult<CombinationActivityDO> result, List<ProductSpuRespDTO> spuList) {
  127 + PageResult<AppCombinationActivityRespVO> appPage = convertAppPage(result);
  128 + Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
  129 + List<AppCombinationActivityRespVO> list = CollectionUtils.convertList(appPage.getList(), item -> {
  130 + findAndThen(spuMap, item.getSpuId(), spu -> {
  131 + item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice());
  132 + });
  133 + return item;
  134 + });
  135 + appPage.setList(list);
  136 + return appPage;
  137 + }
  138 +
  139 + AppCombinationActivityDetailRespVO convert2(CombinationActivityDO combinationActivity);
  140 +
  141 + List<AppCombinationActivityDetailRespVO.Product> convertList1(List<CombinationProductDO> products);
  142 +
  143 + default AppCombinationActivityDetailRespVO convert3(CombinationActivityDO combinationActivity, List<CombinationProductDO> products) {
  144 + return convert2(combinationActivity).setProducts(convertList1(products));
  145 + }
  146 +
114 147 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java
1 1 package cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity;
2 2  
  3 +import cn.hutool.core.date.LocalDateTimeUtil;
3 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 5 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
5 6 import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
... ... @@ -29,7 +30,6 @@ import java.util.Map;
29 30  
30 31 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
31 32 import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
32   -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
33 33  
34 34 /**
35 35 * 秒杀活动 Convert
... ... @@ -98,10 +98,9 @@ public interface SeckillActivityConvert {
98 98 Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
99 99 respVO.setActivities(CollectionUtils.convertList(convertList3(activityList), item -> {
100 100 findAndThen(spuMap, item.getSpuId(), spu -> {
101   - // TODO @puhui999:可以尝试链式 set 哈;
102   - item.setPicUrl(spu.getPicUrl());
103   - item.setMarketPrice(spu.getMarketPrice());
104   - item.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()));
  101 + item.setPicUrl(spu.getPicUrl())
  102 + .setMarketPrice(spu.getMarketPrice())
  103 + .setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()));
105 104 });
106 105 return item;
107 106 }));
... ... @@ -114,12 +113,8 @@ public interface SeckillActivityConvert {
114 113 PageResult<AppSeckillActivityRespVO> result = convertPage1(pageResult);
115 114 Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
116 115 List<AppSeckillActivityRespVO> list = CollectionUtils.convertList(result.getList(), item -> {
117   - findAndThen(spuMap, item.getSpuId(), spu -> {
118   - // TODO @puhui999:可以尝试链式 set 哈;
119   - item.setPicUrl(spu.getPicUrl());
120   - item.setMarketPrice(spu.getMarketPrice());
121   - item.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()));
122   - });
  116 + findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice())
  117 + .setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit())));
123 118 return item;
124 119 });
125 120 result.setList(list);
... ... @@ -131,12 +126,13 @@ public interface SeckillActivityConvert {
131 126 List<AppSeckillActivityDetailRespVO.Product> convertList1(List<SeckillProductDO> products);
132 127  
133 128 default AppSeckillActivityDetailRespVO convert3(SeckillActivityDO seckillActivity, List<SeckillProductDO> products, SeckillConfigDO filteredConfig) {
134   - AppSeckillActivityDetailRespVO respVO = convert2(seckillActivity);
135   - respVO.setProducts(convertList1(products));
136   - // TODO @puhui999:可以尝试链式 set 哈;
137   - respVO.setStartTime(buildTime(filteredConfig.getStartTime()));
138   - respVO.setEndTime(buildTime(filteredConfig.getEndTime()));
139   - return respVO;
  129 + return convert2(seckillActivity)
  130 + .setProducts(convertList1(products))
  131 + // TODO @puhui999:要不要在里面 default 一个方法,处理这个事件;简洁一点;
  132 + .setStartTime(LocalDateTimeUtil.parse(LocalDateTimeUtil.format(seckillActivity.getStartTime(), "yyyy-MM-dd") + " " + filteredConfig.getStartTime(),
  133 + "yyyy-MM-dd HH:mm:ss")) // 活动开始日期和时段结合
  134 + .setEndTime(LocalDateTimeUtil.parse(LocalDateTimeUtil.format(seckillActivity.getEndTime(), "yyyy-MM-dd") + " " + filteredConfig.getEndTime(),
  135 + "yyyy-MM-dd HH:mm:ss")); // 活动结束日期和时段结合
140 136 }
141 137  
142 138 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java
... ... @@ -38,18 +38,41 @@ public interface BargainActivityMapper extends BaseMapperX&lt;BargainActivityDO&gt; {
38 38 * @param count 扣减的库存数量
39 39 * @return 影响的行数
40 40 */
41   - default int updateActivityStock(Long id, int count) {
  41 + default int updateStock(Long id, int count) {
42 42 return update(null, new LambdaUpdateWrapper<BargainActivityDO>()
43 43 .eq(BargainActivityDO::getId, id)
44 44 .ge(BargainActivityDO::getStock, count)
45 45 .setSql("stock = stock - " + count));
46 46 }
47 47  
48   - default PageResult<BargainActivityDO> selectAppPage(PageParam pageReqVO, Integer status, LocalDateTime now) {
  48 + /**
  49 + * 查询处在 now 日期时间且是 status 状态的活动分页
  50 + *
  51 + * @param pageReqVO 分页参数
  52 + * @param status 状态
  53 + * @param now 当前日期时间
  54 + * @return 活动分页
  55 + */
  56 + default PageResult<BargainActivityDO> selectPage(PageParam pageReqVO, Integer status, LocalDateTime now) {
49 57 return selectPage(pageReqVO, new LambdaQueryWrapperX<BargainActivityDO>()
50 58 .eq(BargainActivityDO::getStatus, status)
51 59 .le(BargainActivityDO::getStartTime, now)
52 60 .ge(BargainActivityDO::getEndTime, now));
53 61 }
54 62  
  63 + /**
  64 + * 查询处在 now 日期时间且是 status 状态的活动分页
  65 + *
  66 + * @param status 状态
  67 + * @param now 当前日期时间
  68 + * @return 活动分页
  69 + */
  70 + default List<BargainActivityDO> selectList(Integer count, Integer status, LocalDateTime now) {
  71 + return selectList(new LambdaQueryWrapperX<BargainActivityDO>()
  72 + .eq(BargainActivityDO::getStatus, status)
  73 + .le(BargainActivityDO::getStartTime, now)
  74 + .ge(BargainActivityDO::getEndTime, now)
  75 + .last("LIMIT " + count));
  76 + }
  77 +
55 78 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java
1 1 package cn.iocoder.yudao.module.promotion.dal.mysql.combination;
2 2  
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
3 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 5 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
5 6 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
... ... @@ -28,4 +29,15 @@ public interface CombinationActivityMapper extends BaseMapperX&lt;CombinationActivi
28 29 return selectList(CombinationActivityDO::getStatus, status);
29 30 }
30 31  
  32 + default PageResult<CombinationActivityDO> selectPage(PageParam pageParam, Integer status) {
  33 + return selectPage(pageParam, new LambdaQueryWrapperX<CombinationActivityDO>()
  34 + .eq(CombinationActivityDO::getStatus, status));
  35 + }
  36 +
  37 + default List<CombinationActivityDO> selectListByStatus(Integer status, Integer count) {
  38 + return selectList(new LambdaQueryWrapperX<CombinationActivityDO>()
  39 + .eq(CombinationActivityDO::getStatus, status)
  40 + .last("LIMIT " + count));
  41 + }
  42 +
31 43 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java
... ... @@ -41,7 +41,7 @@ public interface SeckillActivityMapper extends BaseMapperX&lt;SeckillActivityDO&gt; {
41 41 * @param count 扣减的库存数量
42 42 * @return 影响的行数
43 43 */
44   - default int updateActivityStock(Long id, int count) {
  44 + default int updateStock(Long id, int count) {
45 45 return update(null, new LambdaUpdateWrapper<SeckillActivityDO>()
46 46 .eq(SeckillActivityDO::getId, id)
47 47 .gt(SeckillActivityDO::getTotalStock, 0)
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java
... ... @@ -16,8 +16,13 @@ import java.util.List;
16 16 @Mapper
17 17 public interface SeckillProductMapper extends BaseMapperX<SeckillProductDO> {
18 18  
19   - default List<SeckillProductDO> selectListByActivityId(Long id) {
20   - return selectList(SeckillProductDO::getActivityId, id);
  19 + default List<SeckillProductDO> selectListByActivityId(Long activityId) {
  20 + return selectList(SeckillProductDO::getActivityId, activityId);
  21 + }
  22 +
  23 + default SeckillProductDO selectByActivityIdAndSkuId(Long activityId, Long skuId) {
  24 + return selectOne(SeckillProductDO::getActivityId, activityId,
  25 + SeckillProductDO::getSkuId, skuId);
21 26 }
22 27  
23 28 default List<SeckillProductDO> selectListByActivityId(Collection<Long> ids) {
... ... @@ -31,7 +36,7 @@ public interface SeckillProductMapper extends BaseMapperX&lt;SeckillProductDO&gt; {
31 36 * @param count 扣减的库存数量
32 37 * @return 影响的行数
33 38 */
34   - default int updateActivityStock(Long id, int count) {
  39 + default int updateStock(Long id, int count) {
35 40 return update(null, new LambdaUpdateWrapper<SeckillProductDO>()
36 41 .eq(SeckillProductDO::getId, id)
37 42 .gt(SeckillProductDO::getStock, count)
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java
... ... @@ -63,22 +63,20 @@ public interface BargainActivityService {
63 63 */
64 64 PageResult<BargainActivityDO> getBargainActivityPage(BargainActivityPageReqVO pageReqVO);
65 65  
66   - // TODO @puhui999:这里可以改成进行中的活动;尽量避免专门为 app 定制,或者类似的名字哈;mapper 那也是
67   -
68 66 /**
69   - * 获取 APP 端活动分页数据
  67 + * 获取正在进行的活动分页数据
70 68 *
71 69 * @param pageReqVO 分页请求
72 70 * @return 砍价活动分页
73 71 */
74   - PageResult<BargainActivityDO> getBargainActivityPageForApp(PageParam pageReqVO);
  72 + PageResult<BargainActivityDO> getBargainActivityPage(PageParam pageReqVO);
75 73  
76 74 /**
77   - * 获取 APP 端活动展示数据
  75 + * 获取正在进行的活动分页数据
78 76 *
79 77 * @param count 需要的数量
80 78 * @return 砍价活动分页
81 79 */
82   - List<BargainActivityDO> getBargainActivityListForApp(Integer count);
  80 + List<BargainActivityDO> getBargainActivityListByCount(Integer count);
83 81  
84 82 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java
... ... @@ -75,16 +75,18 @@ public class BargainActivityServiceImpl implements BargainActivityService {
75 75 }
76 76  
77 77 @Override
78   - @Transactional(rollbackFor = Exception.class)
79 78 public void updateBargainActivityStock(Long id, Integer count) {
80 79 // 查询砍价活动
81 80 BargainActivityDO activity = getBargainActivity(id);
82 81 if (activity == null) {
83 82 throw exception(BARGAIN_ACTIVITY_NOT_EXISTS);
84 83 }
  84 + if (count > activity.getStock()) {
  85 + throw exception(BARGAIN_ACTIVITY_UPDATE_STOCK_FAIL);
  86 + }
85 87  
86 88 // 更新砍价库存
87   - int updateCount = bargainActivityMapper.updateActivityStock(id, count);
  89 + int updateCount = bargainActivityMapper.updateStock(id, count);
88 90 if (updateCount == 0) {
89 91 throw exception(BARGAIN_ACTIVITY_UPDATE_STOCK_FAIL);
90 92 }
... ... @@ -114,7 +116,7 @@ public class BargainActivityServiceImpl implements BargainActivityService {
114 116 public void deleteBargainActivity(Long id) {
115 117 // 校验存在
116 118 BargainActivityDO activityDO = validateBargainActivityExists(id);
117   - // 校验状态
  119 + // 校验状态 TODO puhui: 测试完成后需要恢复校验
118 120 //if (ObjectUtil.equal(activityDO.getStatus(), CommonStatusEnum.ENABLE.getStatus())) {
119 121 // throw exception(BARGAIN_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END);
120 122 //}
... ... @@ -142,21 +144,14 @@ public class BargainActivityServiceImpl implements BargainActivityService {
142 144 }
143 145  
144 146 @Override
145   - public PageResult<BargainActivityDO> getBargainActivityPageForApp(PageParam pageReqVO) {
  147 + public PageResult<BargainActivityDO> getBargainActivityPage(PageParam pageReqVO) {
146 148 // 只查询进行中,且在时间范围内的
147   - return bargainActivityMapper.selectAppPage(pageReqVO, CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now());
  149 + return bargainActivityMapper.selectPage(pageReqVO, CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now());
148 150 }
149 151  
150 152 @Override
151   - public List<BargainActivityDO> getBargainActivityListForApp(Integer count) {
152   - // TODO @puhui999:这种 default count 的逻辑,可以放到 controller 哈;然后可以使用 ObjectUtils.default 方法
153   - if (count == null) {
154   - count = 6;
155   - }
156   - // TODO @puhui999:这种不要用 page;会浪费一次 count;
157   - PageResult<BargainActivityDO> result = bargainActivityMapper.selectAppPage(new PageParam().setPageSize(count),
158   - CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now());
159   - return result.getList();
  153 + public List<BargainActivityDO> getBargainActivityListByCount(Integer count) {
  154 + return bargainActivityMapper.selectList(count, CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now());
160 155 }
161 156  
162 157 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java
1 1 package cn.iocoder.yudao.module.promotion.service.combination;
2 2  
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
3 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 5 import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO;
5 6 import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO;
... ... @@ -9,6 +10,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationP
9 10  
10 11 import javax.validation.Valid;
11 12 import java.util.Collection;
  13 +import java.util.Collections;
12 14 import java.util.List;
13 15  
14 16 /**
... ... @@ -67,6 +69,16 @@ public interface CombinationActivityService {
67 69 /**
68 70 * 获得拼团活动商品列表
69 71 *
  72 + * @param activityId 拼团活动 id
  73 + * @return 拼团活动的商品列表
  74 + */
  75 + default List<CombinationProductDO> getCombinationProductsByActivityId(Long activityId) {
  76 + return getCombinationProductsByActivityIds(Collections.singletonList(activityId));
  77 + }
  78 +
  79 + /**
  80 + * 获得拼团活动商品列表
  81 + *
70 82 * @param activityIds 拼团活动 ids
71 83 * @return 拼团活动的商品列表
72 84 */
... ... @@ -83,4 +95,20 @@ public interface CombinationActivityService {
83 95 */
84 96 void validateCombination(Long activityId, Long userId, Long skuId, Integer count);
85 97  
  98 + /**
  99 + * 获取正在进行的活动分页数据
  100 + *
  101 + * @param count 需要的数量
  102 + * @return 拼团活动分页
  103 + */
  104 + List<CombinationActivityDO> getCombinationActivityListByCount(Integer count);
  105 +
  106 + /**
  107 + * 获取正在进行的活动分页数据
  108 + *
  109 + * @param pageParam 分页请求
  110 + * @return 拼团活动分页
  111 + */
  112 + PageResult<CombinationActivityDO> getCombinationActivityPage(PageParam pageParam);
  113 +
86 114 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java
... ... @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.service.combination;
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.util.ObjectUtil;
5 5 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
  6 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
6 7 import cn.iocoder.yudao.framework.common.pojo.PageResult;
7 8 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
8 9 import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
... ... @@ -223,8 +224,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
223 224 throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE);
224 225 }
225 226 // 1.3 校验是否超出单次限购数量
226   - // TODO puhui999:count > activity.getSingleLimitCount() 会更好理解点;
227   - if (activity.getSingleLimitCount() < count) {
  227 + if (count > activity.getSingleLimitCount()) {
228 228 throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED);
229 229 }
230 230  
... ... @@ -245,4 +245,14 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
245 245 }
246 246 }
247 247  
  248 + @Override
  249 + public List<CombinationActivityDO> getCombinationActivityListByCount(Integer count) {
  250 + return combinationActivityMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus(), count);
  251 + }
  252 +
  253 + @Override
  254 + public PageResult<CombinationActivityDO> getCombinationActivityPage(PageParam pageParam) {
  255 + return combinationActivityMapper.selectPage(pageParam, CommonStatusEnum.ENABLE.getStatus());
  256 + }
  257 +
248 258 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
... ... @@ -96,12 +96,15 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
96 96 return recordDO;
97 97 }
98 98  
  99 + // TODO @puhui999:有一个应该在创建那要做下;就是当前 activityId 已经有未支付的订单,不允许在发起新的;要么支付,要么去掉先;
  100 +
99 101 @Override
100 102 @Transactional(rollbackFor = Exception.class)
101 103 public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
102 104 // 1.1 校验拼团活动
103 105 CombinationActivityDO activity = combinationActivityService.validateCombinationActivityExists(reqDTO.getActivityId());
104 106 // 1.2 需要校验下,他当前是不是已经参加了该拼团;
  107 + // TODO @puhui999:拼团应该可以重复参加;应该去校验总共的上限哈,就是 activity.totalLimitCount
105 108 CombinationRecordDO recordDO = recordMapper.selectByUserIdAndOrderId(reqDTO.getUserId(), reqDTO.getOrderId());
106 109 if (recordDO != null) {
107 110 throw exception(COMBINATION_RECORD_EXISTS);
... ... @@ -111,6 +114,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
111 114 if (CollUtil.isNotEmpty(recordDOList)) {
112 115 throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED);
113 116 }
  117 + // TODO @puhui999:有个开始时间未校验
114 118 // 1.4 校验当前活动是否过期
115 119 if (LocalDateTime.now().isAfter(activity.getEndTime())) {
116 120 throw exception(COMBINATION_RECORD_FAILED_TIME_END);
... ... @@ -128,6 +132,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
128 132 }
129 133 }
130 134  
  135 + // TODO @puhui999:单次限购
  136 +
131 137 // 2. 创建拼团记录
132 138 MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId());
133 139 ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId());
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java
... ... @@ -37,11 +37,11 @@ public interface SeckillActivityService {
37 37 /**
38 38 * 更新秒杀库存
39 39 *
40   - * @param activityId 活动编号
  40 + * @param id 活动编号
41 41 * @param skuId sku 编号
42 42 * @param count 数量
43 43 */
44   - void updateSeckillStock(Long activityId, Long skuId, Integer count);
  44 + void updateSeckillStock(Long id, Long skuId, Integer count);
45 45  
46 46 /**
47 47 * 关闭秒杀活动
... ... @@ -98,6 +98,15 @@ public interface SeckillActivityService {
98 98 List<SeckillActivityDO> getSeckillActivityListByConfigIds(Collection<Long> ids);
99 99  
100 100 /**
  101 + * 通过活动时段编号获取指定 status 的秒杀活动
  102 + *
  103 + * @param configId 时段配置编号
  104 + * @param status 状态
  105 + * @return 秒杀活动列表
  106 + */
  107 + List<SeckillActivityDO> getSeckillActivityListByConfigIdAndStatus(Long configId, Integer status);
  108 +
  109 + /**
101 110 * 通过活动时段获取秒杀活动
102 111 *
103 112 * @param pageReqVO 请求
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java
... ... @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.promotion.service.seckill;
3 3 import cn.hutool.core.util.ObjectUtil;
4 4 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
5 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6   -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
7 6 import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
8 7 import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
9 8 import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
... ... @@ -31,6 +30,7 @@ import java.util.Map;
31 30 import static cn.hutool.core.collection.CollUtil.isNotEmpty;
32 31 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
33 32 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
  33 +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.isBetween;
34 34 import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS;
35 35 import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS;
36 36 import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
... ... @@ -148,32 +148,26 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
148 148  
149 149 @Override
150 150 @Transactional(rollbackFor = Exception.class)
151   - public void updateSeckillStock(Long activityId, Long skuId, Integer count) {
152   - // 1、校验秒杀活动是否存在
153   - SeckillActivityDO seckillActivity = getSeckillActivity(activityId);
154   - // 1.1、校验库存是否充足
155   - if (seckillActivity.getTotalStock() < count) {
  151 + public void updateSeckillStock(Long id, Long skuId, Integer count) {
  152 + // 1.1 校验活动库存是否充足
  153 + SeckillActivityDO seckillActivity = getSeckillActivity(id);
  154 + if (count > seckillActivity.getTotalStock()) {
156 155 throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL);
157 156 }
158   -
159   - // 2、获取活动商品
160   - List<SeckillProductDO> products = getSeckillProductListByActivityId(activityId);
161   - // 2.1、过滤出购买的商品
162   - SeckillProductDO product = findFirst(products, item -> ObjectUtil.equal(skuId, item.getSkuId()));
163   - // 2.2、检查活动商品库存是否充足
164   - boolean isSufficient = product == null || (product.getStock() == 0 || (product.getStock() < count) || (product.getStock() - count) < 0);
165   - if (isSufficient) {
  157 + // 1.2 校验商品库存是否充足
  158 + SeckillProductDO product = seckillProductMapper.selectByActivityIdAndSkuId(id, skuId);
  159 + if (product == null || count > product.getStock()) {
166 160 throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL);
167 161 }
168 162  
169   - // 3、更新活动商品库存
170   - int updateCount = seckillProductMapper.updateActivityStock(product.getId(), count);
  163 + // 2.1 更新活动商品库存
  164 + int updateCount = seckillProductMapper.updateStock(product.getId(), count);
171 165 if (updateCount == 0) {
172 166 throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL);
173 167 }
174 168  
175   - // 4、更新活动库存
176   - updateCount = seckillActivityMapper.updateActivityStock(seckillActivity.getId(), count);
  169 + // 2.2 更新活动库存
  170 + updateCount = seckillActivityMapper.updateStock(seckillActivity.getId(), count);
177 171 if (updateCount == 0) {
178 172 throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL);
179 173 }
... ... @@ -268,8 +262,15 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
268 262  
269 263 @Override
270 264 public List<SeckillActivityDO> getSeckillActivityListByConfigIds(Collection<Long> ids) {
271   - return CollectionUtils.filterList(seckillActivityMapper.selectList(),
272   - item -> CollectionUtils.anyMatch(item.getConfigIds(), ids::contains));
  265 + return filterList(seckillActivityMapper.selectList(),
  266 + item -> anyMatch(item.getConfigIds(), ids::contains));
  267 + }
  268 +
  269 + @Override
  270 + public List<SeckillActivityDO> getSeckillActivityListByConfigIdAndStatus(Long configId, Integer status) {
  271 + return filterList(seckillActivityMapper.selectList(SeckillActivityDO::getStatus, status),
  272 + item -> anyMatch(item.getConfigIds(), id -> ObjectUtil.equal(id, configId)) // 校验时段
  273 + && isBetween(item.getStartTime(), item.getEndTime())); // 追加当前日期是否处在活动日期之间的校验条件
273 274 }
274 275  
275 276 @Override
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillConfigService.java
... ... @@ -54,6 +54,7 @@ public interface SeckillConfigService {
54 54 */
55 55 List<SeckillConfigDO> getSeckillConfigList();
56 56  
  57 +
57 58 /**
58 59 * 校验秒杀时段是否存在
59 60 *
... ... @@ -85,4 +86,12 @@ public interface SeckillConfigService {
85 86 */
86 87 void updateSeckillConfigStatus(Long id, Integer status);
87 88  
  89 + /**
  90 + * 获取当前日期时间处于的秒杀时段且状态为 status
  91 + *
  92 + * @param status 状态
  93 + * @return 时段
  94 + */
  95 + SeckillConfigDO getSeckillConfigListByStatusOnCurrentTime(Integer status);
  96 +
88 97 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillConfigServiceImpl.java
... ... @@ -20,6 +20,8 @@ import java.util.Collection;
20 20 import java.util.List;
21 21  
22 22 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  23 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.findFirst;
  24 +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.isBetween;
23 25 import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
24 26  
25 27 /**
... ... @@ -68,6 +70,12 @@ public class SeckillConfigServiceImpl implements SeckillConfigService {
68 70 }
69 71  
70 72 @Override
  73 + public SeckillConfigDO getSeckillConfigListByStatusOnCurrentTime(Integer status) {
  74 + return findFirst(seckillConfigMapper.selectList(SeckillConfigDO::getStatus, status),
  75 + config -> isBetween(config.getStartTime(), config.getEndTime()));
  76 + }
  77 +
  78 + @Override
71 79 public void deleteSeckillConfig(Long id) {
72 80 // 校验存在
73 81 validateSeckillConfigExists(id);
... ...
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 +
  12 +}
... ...
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java
... ... @@ -12,12 +12,6 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
12 12 public interface ErrorCodeConstants {
13 13  
14 14 // ========== Order 模块 1011000000 ==========
15   - ErrorCode ORDER_CREATE_SKU_NOT_FOUND = new ErrorCode(1011000001, "商品 SKU 不存在");
16   - ErrorCode ORDER_CREATE_SPU_NOT_SALE = new ErrorCode(1011000002, "商品 SPU 不可售卖");
17   - ErrorCode ORDER_CREATE_SKU_STOCK_NOT_ENOUGH = new ErrorCode(1011000004, "商品 SKU 库存不足");
18   - ErrorCode ORDER_CREATE_SPU_NOT_FOUND = new ErrorCode(1011000005, "商品 SPU 不可售卖");
19   - ErrorCode ORDER_CREATE_ADDRESS_NOT_FOUND = new ErrorCode(1011000006, "收货地址不存在");
20   -
21 15 ErrorCode ORDER_ITEM_NOT_FOUND = new ErrorCode(1011000010, "交易订单项不存在");
22 16 ErrorCode ORDER_NOT_FOUND = new ErrorCode(1011000011, "交易订单不存在");
23 17 ErrorCode ORDER_ITEM_UPDATE_AFTER_SALE_STATUS_FAIL = new ErrorCode(1011000012, "交易订单项更新售后状态失败,请重试");
... ... @@ -37,6 +31,7 @@ public interface ErrorCodeConstants {
37 31 ErrorCode ORDER_UPDATE_PRICE_FAIL_PAID = new ErrorCode(1011000026, "支付订单调价失败,原因:支付订单已付款,不能调价");
38 32 ErrorCode ORDER_UPDATE_PRICE_FAIL_EQUAL = new ErrorCode(1011000027, "支付订单调价失败,原因:价格没有变化");
39 33 ErrorCode ORDER_UPDATE_PRICE_FAIL_NOT_ITEM = new ErrorCode(1011000028, "支付订单调价失败,原因:订单项不存在");
  34 + ErrorCode ORDER_DELETE_FAIL_STATUS_NOT_CANCEL = new ErrorCode(1011000029, "交易订单删除失败,订单不是【已取消】状态");
40 35  
41 36 // ========== After Sale 模块 1011000100 ==========
42 37 ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在");
... ... @@ -58,9 +53,8 @@ public interface ErrorCodeConstants {
58 53  
59 54 // ========== Price 相关 1011003000 ============
60 55 ErrorCode PRICE_CALCULATE_PAY_PRICE_ILLEGAL = new ErrorCode(1011003000, "支付价格计算异常,原因:价格小于等于 0");
61   - ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDRESS_IS_EMPTY = new ErrorCode(1011003001, "计算快递运费异常,收件人地址编号为空");
62 56 ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND = new ErrorCode(1011003002, "计算快递运费异常,找不到对应的运费模板");
63   - ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_PICK_UP_STORE_IS_EMPTY = new ErrorCode(1011003003, "计算快递运费异常,自提点为空");
  57 + ErrorCode PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER = new ErrorCode(1011003004, "参与秒杀、拼团、砍价的营销商品,无法使用优惠劵");
64 58  
65 59 // ========== 物流 Express 模块 1011004000 ==========
66 60 ErrorCode EXPRESS_NOT_EXISTS = new ErrorCode(1011004000, "快递公司不存在");
... ... @@ -93,5 +87,7 @@ public interface ErrorCodeConstants {
93 87 // ========== 分销提现 模块 1011008000 ==========
94 88 ErrorCode BROKERAGE_WITHDRAW_NOT_EXISTS = new ErrorCode(1011008000, "佣金提现记录不存在");
95 89 ErrorCode BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING = new ErrorCode(1011008001, "佣金提现记录状态不是审核中");
  90 + ErrorCode BROKERAGE_WITHDRAW_MIN_PRICE = new ErrorCode(1011008002, "提现金额不能低于 {} 元");
  91 + ErrorCode BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH = new ErrorCode(1011008003, "您当前最多可提现 {} 元");
96 92  
97 93 }
... ...
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java
... ... @@ -17,6 +17,7 @@ public enum BrokerageRecordBizTypeEnum implements IntArrayValuable {
17 17  
18 18 ORDER(1, "获得推广佣金", "获得推广佣金 {}", true),
19 19 WITHDRAW(2, "提现申请", "提现申请扣除佣金 {}", false),
  20 + WITHDRAW_REJECT(3, "提现申请驳回", "提现申请驳回返还佣金 {}", true),
20 21 ;
21 22  
22 23 public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageRecordBizTypeEnum::getType).toArray();
... ...
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/delivery/DeliveryExpressChargeModeEnum.java
... ... @@ -16,7 +16,7 @@ import java.util.Arrays;
16 16 @Getter
17 17 public enum DeliveryExpressChargeModeEnum implements IntArrayValuable {
18 18  
19   - PIECE(1, "按件"),
  19 + COUNT(1, "按件"),
20 20 WEIGHT(2,"按重量"),
21 21 VOLUME(3, "按体积");
22 22  
... ...
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java
... ... @@ -14,7 +14,10 @@ import lombok.RequiredArgsConstructor;
14 14 public enum TradeOrderOperateTypeEnum {
15 15  
16 16 MEMBER_CREATE(1, "用户下单"),
17   - TEST(2, "用户({nickname})做了({thing})"),
  17 + MEMBER_RECEIVE(30, "用户已收货"),
  18 + MEMBER_COMMENT(31, "用户评价"),
  19 + MEMBER_CANCEL(40, "取消订单"),
  20 + MEMBER_DELETE(41, "删除订单"),
18 21 ;
19 22  
20 23 /**
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java
... ... @@ -8,11 +8,11 @@ import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
8 8 import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
9 9 import cn.iocoder.yudao.module.pay.api.notify.dto.PayRefundNotifyReqDTO;
10 10 import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.*;
  11 +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.log.TradeAfterSaleLogRespVO;
11 12 import cn.iocoder.yudao.module.trade.convert.aftersale.TradeAfterSaleConvert;
12 13 import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO;
13 14 import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
14 15 import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
15   -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespDTO;
16 16 import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService;
17 17 import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService;
18 18 import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService;
... ... @@ -87,13 +87,13 @@ public class TradeAfterSaleController {
87 87 // 拼接数据
88 88 MemberUserRespDTO user = memberUserApi.getUser(afterSale.getUserId());
89 89 // 获取售后日志
90   - List<TradeAfterSaleLogRespDTO> logs = afterSaleLogService.getLog(afterSale.getId());
  90 + List<TradeAfterSaleLogRespVO> logs = afterSaleLogService.getLog(afterSale.getId());
91 91 // TODO 方便测试看效果,review 后移除
92 92 if (logs == null) {
93 93 logs = new ArrayList<>();
94 94 }
95 95 for (int i = 1; i <= 6; i++) {
96   - TradeAfterSaleLogRespDTO respVO = new TradeAfterSaleLogRespDTO();
  96 + TradeAfterSaleLogRespVO respVO = new TradeAfterSaleLogRespVO();
97 97 respVO.setId((long) i);
98 98 respVO.setUserId((long) i);
99 99 respVO.setUserType(i % 2 == 0 ? 2 : 1);
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/BrokerageRecordController.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageRecordController.java
1   -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record;
  1 +package cn.iocoder.yudao.module.trade.controller.admin.brokerage;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 5 import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
6 6 import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
7   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO;
8   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordRespVO;
9   -import cn.iocoder.yudao.module.trade.convert.brokerage.record.BrokerageRecordConvert;
10   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO;
11   -import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService;
  7 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO;
  8 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordRespVO;
  9 +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert;
  10 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO;
  11 +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService;
12 12 import io.swagger.v3.oas.annotations.Operation;
13 13 import io.swagger.v3.oas.annotations.Parameter;
14 14 import io.swagger.v3.oas.annotations.tags.Tag;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java
1   -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user;
  1 +package cn.iocoder.yudao.module.trade.controller.admin.brokerage;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 5 import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
6 6 import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
7   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.*;
8   -import cn.iocoder.yudao.module.trade.convert.brokerage.user.BrokerageUserConvert;
9   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO;
  7 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.*;
  8 +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageUserConvert;
  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   -import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService;
14   -import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService;
  15 +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService;
  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;
... ... @@ -87,6 +92,7 @@ public class BrokerageUserController {
87 92 Set<Long> userIds = convertSet(pageResult.getList(), BrokerageUserDO::getId);
88 93 // 查询用户信息
89 94 Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(userIds);
  95 + // TODO @疯狂:看看下面两个 getBrokerageUserCountByBindUserId、getWithdrawSummaryByUserId 有没可能一次性出结果,不然 n 次有点太花性能了;
90 96 // 合计分佣订单
91 97 Map<Long, UserBrokerageSummaryBO> userOrderSummaryMap = convertMap(userIds,
92 98 userId -> userId,
... ... @@ -96,10 +102,13 @@ public class BrokerageUserController {
96 102 Map<Long, Long> brokerageUserCountMap = convertMap(userIds,
97 103 userId -> userId,
98 104 userId -> brokerageUserService.getBrokerageUserCountByBindUserId(userId, null));
99   -
100   - // todo 合计提现
101   -
102   - return success(BrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap));
  105 + // 合计提现
  106 + Map<Long, UserWithdrawSummaryBO> withdrawMap = convertMap(userIds,
  107 + userId -> userId,
  108 + userId -> brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS));
  109 + // 拼接返回
  110 + return success(BrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap,
  111 + userOrderSummaryMap, withdrawMap));
103 112 }
104 113  
105 114 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/BrokerageWithdrawController.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageWithdrawController.java
1   -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw;
  1 +package cn.iocoder.yudao.module.trade.controller.admin.brokerage;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 5 import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
6 6 import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
7   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawRejectReqVO;
8   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawPageReqVO;
9   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawRespVO;
10   -import cn.iocoder.yudao.module.trade.convert.brokerage.withdraw.BrokerageWithdrawConvert;
11   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.withdraw.BrokerageWithdrawDO;
  7 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawRejectReqVO;
  8 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO;
  9 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawRespVO;
  10 +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageWithdrawConvert;
  11 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO;
12 12 import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
13   -import cn.iocoder.yudao.module.trade.service.brokerage.withdraw.BrokerageWithdrawService;
  13 +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService;
14 14 import io.swagger.v3.oas.annotations.Operation;
15 15 import io.swagger.v3.oas.annotations.Parameter;
16 16 import io.swagger.v3.oas.annotations.tags.Tag;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordBaseVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/record/BrokerageRecordBaseVO.java
1   -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo;
  1 +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4 4 import lombok.Data;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordPageReqVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/record/BrokerageRecordPageReqVO.java
1   -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo;
  1 +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageParam;
4 4 import io.swagger.v3.oas.annotations.media.Schema;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordRespVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/record/BrokerageRecordRespVO.java
1   -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo;
  1 +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4 4 import lombok.Data;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserBaseVO.java
1   -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo;
  1 +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4 4 import lombok.Data;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserClearBrokerageUserReqVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserClearBrokerageUserReqVO.java
1   -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo;
  1 +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4 4 import lombok.Data;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserPageReqVO.java
1   -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo;
  1 +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageParam;
4 4 import io.swagger.v3.oas.annotations.media.Schema;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserRespVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserRespVO.java
1   -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo;
  1 +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4 4 import lombok.Data;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserUpdateBrokerageEnabledReqVO.java
1   -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo;
  1 +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4 4 import lombok.Data;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserUpdateBrokerageUserReqVO.java
1   -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo;
  1 +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4 4 import lombok.Data;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/vo/BrokerageWithdrawBaseVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/withdraw/BrokerageWithdrawBaseVO.java
1   -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo;
  1 +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4 4 import lombok.Data;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/vo/BrokerageWithdrawPageReqVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/withdraw/BrokerageWithdrawPageReqVO.java
1   -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo;
  1 +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageParam;
4 4 import cn.iocoder.yudao.framework.common.validation.InEnum;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/vo/BrokerageWithdrawRejectReqVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/withdraw/BrokerageWithdrawRejectReqVO.java
1   -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo;
  1 +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4 4 import lombok.Data;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/vo/BrokerageWithdrawRespVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/withdraw/BrokerageWithdrawRespVO.java
1   -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo;
  1 +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4 4 import lombok.Data;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java
... ... @@ -19,6 +19,17 @@ import java.util.List;
19 19 */
20 20 @Data
21 21 public class TradeConfigBaseVO {
  22 + /**
  23 + * 是否启用全场包邮
  24 + */
  25 + @Schema(description = "是否启用全场包邮", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
  26 + @NotNull(message = "是否启用全场包邮不能为空")
  27 + private Boolean deliveryExpressFreeEnabled;
  28 +
  29 + @Schema(description = "全场包邮的最小金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
  30 + @NotNull(message = "全场包邮的最小金额不能为空")
  31 + @PositiveOrZero(message = "全场包邮的最小金额不能是负数")
  32 + private Integer deliveryExpressFreePrice;
22 33  
23 34 // ========== 分销相关 ==========
24 35  
... ... @@ -37,7 +48,7 @@ public class TradeConfigBaseVO {
37 48 private Integer brokerageBindMode;
38 49  
39 50 @Schema(description = "分销海报图地址数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/yudao.jpg]")
40   - private List<String> brokeragePostUrls;
  51 + private List<String> brokeragePosterUrls;
41 52  
42 53 @Schema(description = "一级返佣比例", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
43 54 @NotNull(message = "一级返佣比例不能为空")
... ... @@ -54,6 +65,11 @@ public class TradeConfigBaseVO {
54 65 @PositiveOrZero(message = "用户提现最低金额不能是负数")
55 66 private Integer brokerageWithdrawMinPrice;
56 67  
  68 + @Schema(description = "用户提现手续费百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
  69 + @NotNull(message = "用户提现手续费百分比不能为空")
  70 + @PositiveOrZero(message = "用户提现手续费百分比不能是负数")
  71 + private Integer brokerageWithdrawFeePercent;
  72 +
57 73 @Schema(description = "提现银行", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]")
58 74 @NotEmpty(message = "提现银行不能为空")
59 75 private List<Integer> brokerageBankNames;
... ... @@ -66,6 +82,6 @@ public class TradeConfigBaseVO {
66 82 @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]")
67 83 @NotNull(message = "提现方式不能为空")
68 84 @InEnum(value = BrokerageWithdrawTypeEnum.class, message = "提现方式必须是 {value}")
69   - private List<Integer> brokerageWithdrawType;
  85 + private List<Integer> brokerageWithdrawTypes;
70 86  
71 87 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java
... ... @@ -6,7 +6,9 @@ import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
6 6 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageProductPriceRespVO;
7 7 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordPageReqVO;
8 8 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordRespVO;
9   -import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService;
  9 +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert;
  10 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO;
  11 +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService;
10 12 import io.swagger.v3.oas.annotations.Operation;
11 13 import io.swagger.v3.oas.annotations.tags.Tag;
12 14 import lombok.extern.slf4j.Slf4j;
... ... @@ -18,11 +20,9 @@ import org.springframework.web.bind.annotation.RestController;
18 20  
19 21 import javax.annotation.Resource;
20 22 import javax.validation.Valid;
21   -import java.time.LocalDateTime;
22 23  
23 24 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
24 25 import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId;
25   -import static java.util.Arrays.asList;
26 26  
27 27 @Tag(name = "用户 APP - 分销用户")
28 28 @RestController
... ... @@ -31,30 +31,21 @@ import static java.util.Arrays.asList;
31 31 @Slf4j
32 32 public class AppBrokerageRecordController {
33 33 @Resource
34   - private BrokerageUserService brokerageUserService;
  34 + private BrokerageRecordService brokerageRecordService;
35 35  
36   - // TODO 芋艿:临时 mock =>
37 36 @GetMapping("/page")
38 37 @Operation(summary = "获得分销记录分页")
39 38 @PreAuthenticated
40 39 public CommonResult<PageResult<AppBrokerageRecordRespVO>> getBrokerageRecordPage(@Valid AppBrokerageRecordPageReqVO pageReqVO) {
41   - AppBrokerageRecordRespVO vo1 = new AppBrokerageRecordRespVO()
42   - .setId(1L).setPrice(10).setTitle("收到钱").setCreateTime(LocalDateTime.now())
43   - .setFinishTime(LocalDateTime.now());
44   - AppBrokerageRecordRespVO vo2 = new AppBrokerageRecordRespVO()
45   - .setId(2L).setPrice(-20).setTitle("提现钱").setCreateTime(LocalDateTime.now())
46   - .setFinishTime(LocalDateTime.now());
47   - return success(new PageResult<>(asList(vo1, vo2), 10L));
  40 + PageResult<BrokerageRecordDO> pageResult = brokerageRecordService.getBrokerageRecordPage(
  41 + BrokerageRecordConvert.INSTANCE.convert(pageReqVO, getLoginUserId()));
  42 + return success(BrokerageRecordConvert.INSTANCE.convertPage02(pageResult));
48 43 }
49 44  
50 45 @GetMapping("/get-product-brokerage-price")
51 46 @Operation(summary = "获得商品的分销金额")
52 47 public CommonResult<AppBrokerageProductPriceRespVO> getProductBrokeragePrice(@RequestParam("spuId") Long spuId) {
53   - AppBrokerageProductPriceRespVO respVO = new AppBrokerageProductPriceRespVO();
54   - respVO.setEnabled(brokerageUserService.getUserBrokerageEnabled(getLoginUserId()));
55   - respVO.setBrokerageMinPrice(1);
56   - respVO.setBrokerageMaxPrice(2);
57   - return success(respVO);
  48 + return success(brokerageRecordService.calculateProductBrokeragePrice(spuId, getLoginUserId()));
58 49 }
59 50  
60 51 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java
1 1 package cn.iocoder.yudao.module.trade.controller.app.brokerage;
2 2  
  3 +import cn.hutool.core.date.LocalDateTimeUtil;
3 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 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;
6 9 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.*;
7   -import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService;
  10 +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert;
  11 +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageUserConvert;
  12 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
  13 +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
  14 +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
  15 +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService;
  16 +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService;
  17 +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService;
  18 +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO;
8 19 import io.swagger.v3.oas.annotations.Operation;
9 20 import io.swagger.v3.oas.annotations.Parameter;
10 21 import io.swagger.v3.oas.annotations.tags.Tag;
... ... @@ -16,11 +27,13 @@ import org.springframework.web.bind.annotation.*;
16 27 import javax.annotation.Resource;
17 28 import javax.validation.Valid;
18 29 import java.time.LocalDateTime;
  30 +import java.util.Map;
  31 +import java.util.Optional;
19 32  
20 33 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  34 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
21 35 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
22 36 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
23   -import static java.util.Arrays.asList;
24 37  
25 38 @Tag(name = "用户 APP - 分销用户")
26 39 @RestController
... ... @@ -30,16 +43,24 @@ import static java.util.Arrays.asList;
30 43 public class AppBrokerageUserController {
31 44 @Resource
32 45 private BrokerageUserService brokerageUserService;
  46 + @Resource
  47 + private BrokerageRecordService brokerageRecordService;
  48 + @Resource
  49 + private BrokerageWithdrawService brokerageWithdrawService;
  50 +
  51 + @Resource
  52 + private MemberUserApi memberUserApi;
33 53  
34   - // TODO 芋艿:临时 mock =>
35 54 @GetMapping("/get")
36 55 @Operation(summary = "获得个人分销信息")
37 56 @PreAuthenticated
38 57 public CommonResult<AppBrokerageUserRespVO> getBrokerageUser() {
  58 + Optional<BrokerageUserDO> user = Optional.ofNullable(brokerageUserService.getBrokerageUser(getLoginUserId()));
  59 + // 返回数据
39 60 AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO()
40   - .setBrokerageEnabled(true)
41   - .setPrice(2000)
42   - .setFrozenPrice(3000);
  61 + .setBrokerageEnabled(user.map(BrokerageUserDO::getBrokerageEnabled).orElse(false))
  62 + .setBrokeragePrice(user.map(BrokerageUserDO::getBrokeragePrice).orElse(0))
  63 + .setFrozenPrice(user.map(BrokerageUserDO::getFrozenPrice).orElse(0));
43 64 return success(respVO);
44 65 }
45 66  
... ... @@ -47,88 +68,70 @@ public class AppBrokerageUserController {
47 68 @Operation(summary = "绑定推广员")
48 69 @PreAuthenticated
49 70 public CommonResult<Boolean> bindBrokerageUser(@Valid @RequestBody AppBrokerageUserBindReqVO reqVO) {
50   - 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()));
51 73 }
52 74  
53   - // TODO 芋艿:临时 mock =>
54 75 @GetMapping("/get-summary")
55 76 @Operation(summary = "获得个人分销统计")
56 77 @PreAuthenticated
57 78 public CommonResult<AppBrokerageUserMySummaryRespVO> getBrokerageUserSummary() {
  79 + Long userId = getLoginUserId();
  80 + // TODO @疯狂:后面这种,要不也改成 convert;感觉 controller 这样更容易看到整体;核心其实是 86、8/87、9/90、9/91 这阶段
  81 + // 统计 yesterdayPrice、withdrawPrice、firstBrokerageUserCount、secondBrokerageUserCount 字段
  82 + LocalDateTime yesterday = LocalDateTime.now().minusDays(1);
  83 + LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday);
  84 + LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday);
58 85 AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO()
59   - .setYesterdayPrice(1)
60   - .setBrokeragePrice(2)
61   - .setFrozenPrice(3)
62   - .setWithdrawPrice(4)
63   - .setFirstBrokerageUserCount(166)
64   - .setSecondBrokerageUserCount(233);
  86 + .setYesterdayPrice(brokerageRecordService.getSummaryPriceByUserId(userId, BrokerageRecordBizTypeEnum.ORDER.getType(), beginTime, endTime))
  87 + .setWithdrawPrice(Optional.ofNullable(brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS))
  88 + .map(UserWithdrawSummaryBO::getPrice).orElse(0))
  89 + .setBrokeragePrice(0).setFrozenPrice(0)
  90 + .setFirstBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1))
  91 + .setSecondBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2));
  92 + // 设置 brokeragePrice、frozenPrice 字段
  93 + Optional.ofNullable(brokerageUserService.getBrokerageUser(userId))
  94 + .ifPresent(user -> respVO.setBrokeragePrice(user.getBrokeragePrice()).setFrozenPrice(user.getFrozenPrice()));
65 95 return success(respVO);
66 96 }
67 97  
68   - // TODO 芋艿:临时 mock =>
69 98 @GetMapping("/rank-page-by-user-count")
70 99 @Operation(summary = "获得分销用户排行分页(基于用户量)")
71 100 @PreAuthenticated
72 101 public CommonResult<PageResult<AppBrokerageUserRankByUserCountRespVO>> getBrokerageUserRankPageByUserCount(AppBrokerageUserRankPageReqVO pageReqVO) {
73   - AppBrokerageUserRankByUserCountRespVO vo1 = new AppBrokerageUserRankByUserCountRespVO()
74   - .setId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg")
75   - .setBrokerageUserCount(10);
76   - AppBrokerageUserRankByUserCountRespVO vo2 = new AppBrokerageUserRankByUserCountRespVO()
77   - .setId(2L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg")
78   - .setBrokerageUserCount(6);
79   - AppBrokerageUserRankByUserCountRespVO vo3 = new AppBrokerageUserRankByUserCountRespVO()
80   - .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg")
81   - .setBrokerageUserCount(4);
82   - AppBrokerageUserRankByUserCountRespVO vo4 = new AppBrokerageUserRankByUserCountRespVO()
83   - .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg")
84   - .setBrokerageUserCount(4);
85   - return success(new PageResult<>(asList(vo1, vo2, vo3, vo4), 10L));
  102 + // 分页查询
  103 + PageResult<AppBrokerageUserRankByUserCountRespVO> pageResult = brokerageUserService.getBrokerageUserRankPageByUserCount(pageReqVO);
  104 + // 拼接数据
  105 + Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(convertSet(pageResult.getList(), AppBrokerageUserRankByUserCountRespVO::getId));
  106 + return success(BrokerageUserConvert.INSTANCE.convertPage03(pageResult, userMap));
86 107 }
87 108  
88   - // TODO 芋艿:临时 mock =>
89 109 @GetMapping("/rank-page-by-price")
90 110 @Operation(summary = "获得分销用户排行分页(基于佣金)")
91 111 @PreAuthenticated
92 112 public CommonResult<PageResult<AppBrokerageUserRankByPriceRespVO>> getBrokerageUserChildSummaryPageByPrice(AppBrokerageUserRankPageReqVO pageReqVO) {
93   - AppBrokerageUserRankByPriceRespVO vo1 = new AppBrokerageUserRankByPriceRespVO()
94   - .setId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg")
95   - .setBrokeragePrice(10);
96   - AppBrokerageUserRankByPriceRespVO vo2 = new AppBrokerageUserRankByPriceRespVO()
97   - .setId(2L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg")
98   - .setBrokeragePrice(6);
99   - AppBrokerageUserRankByPriceRespVO vo3 = new AppBrokerageUserRankByPriceRespVO()
100   - .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg")
101   - .setBrokeragePrice(4);
102   - AppBrokerageUserRankByPriceRespVO vo4 = new AppBrokerageUserRankByPriceRespVO()
103   - .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg")
104   - .setBrokeragePrice(4);
105   - return success(new PageResult<>(asList(vo1, vo2, vo3, vo4), 10L));
  113 + // 分页查询
  114 + PageResult<AppBrokerageUserRankByPriceRespVO> pageResult = brokerageRecordService.getBrokerageUserChildSummaryPageByPrice(pageReqVO);
  115 + // 拼接数据
  116 + Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(convertSet(pageResult.getList(), AppBrokerageUserRankByPriceRespVO::getId));
  117 + return success(BrokerageRecordConvert.INSTANCE.convertPage03(pageResult, userMap));
106 118 }
107 119  
108   - // TODO 芋艿:临时 mock =>
109 120 @GetMapping("/child-summary-page")
110 121 @Operation(summary = "获得下级分销统计分页")
111 122 @PreAuthenticated
112 123 public CommonResult<PageResult<AppBrokerageUserChildSummaryRespVO>> getBrokerageUserChildSummaryPage(
113 124 AppBrokerageUserChildSummaryPageReqVO pageReqVO) {
114   - AppBrokerageUserChildSummaryRespVO vo1 = new AppBrokerageUserChildSummaryRespVO()
115   - .setId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg")
116   - .setBrokeragePrice(10).setBrokeragePrice(20).setBrokerageOrderCount(30)
117   - .setBrokerageTime(LocalDateTime.now());
118   - AppBrokerageUserChildSummaryRespVO vo2 = new AppBrokerageUserChildSummaryRespVO()
119   - .setId(1L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg")
120   - .setBrokeragePrice(20).setBrokeragePrice(30).setBrokerageOrderCount(40)
121   - .setBrokerageTime(LocalDateTime.now());
122   - return success(new PageResult<>(asList(vo1, vo2), 10L));
  125 + PageResult<AppBrokerageUserChildSummaryRespVO> pageResult = brokerageUserService.getBrokerageUserChildSummaryPage(pageReqVO, getLoginUserId());
  126 + return success(pageResult);
123 127 }
124 128  
125   - // TODO 芋艿:临时 mock =>
126 129 @GetMapping("/get-rank-by-price")
127 130 @Operation(summary = "获得分销用户排行(基于佣金)")
128 131 @Parameter(name = "times", description = "时间段", required = true)
129   - public CommonResult<Integer> bindBrokerageUser(
  132 + public CommonResult<Integer> getRankByPrice(
130 133 @RequestParam("times") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) LocalDateTime[] times) {
131   - return success(1);
  134 + return success(brokerageRecordService.getUserRankByPrice(getLoginUserId(), times));
132 135 }
133 136  
134 137 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java
... ... @@ -3,19 +3,24 @@ package cn.iocoder.yudao.module.trade.controller.app.brokerage;
3 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 5 import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
  6 +import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
6 7 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO;
  8 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawPageReqVO;
7 9 import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO;
  10 +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageWithdrawConvert;
  11 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO;
  12 +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService;
8 13 import io.swagger.v3.oas.annotations.Operation;
9 14 import io.swagger.v3.oas.annotations.tags.Tag;
10 15 import lombok.extern.slf4j.Slf4j;
11 16 import org.springframework.validation.annotation.Validated;
12 17 import org.springframework.web.bind.annotation.*;
13 18  
  19 +import javax.annotation.Resource;
14 20 import javax.validation.Valid;
15   -import java.time.LocalDateTime;
16 21  
17 22 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
18   -import static java.util.Arrays.asList;
  23 +import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId;
19 24  
20 25 @Tag(name = "用户 APP - 分销提现")
21 26 @RestController
... ... @@ -24,24 +29,27 @@ import static java.util.Arrays.asList;
24 29 @Slf4j
25 30 public class AppBrokerageWithdrawController {
26 31  
27   - // TODO 芋艿:临时 mock =>
  32 + @Resource
  33 + private BrokerageWithdrawService brokerageWithdrawService;
  34 +
  35 + @Resource
  36 + private DictDataApi dictDataApi;
  37 +
28 38 @GetMapping("/page")
29 39 @Operation(summary = "获得分销提现分页")
30 40 @PreAuthenticated
31   - public CommonResult<PageResult<AppBrokerageWithdrawRespVO>> getBrokerageWithdrawPage() {
32   - AppBrokerageWithdrawRespVO vo1 = new AppBrokerageWithdrawRespVO()
33   - .setId(1L).setStatus(10).setPrice(10).setStatusName("审批通过").setCreateTime(LocalDateTime.now());
34   - AppBrokerageWithdrawRespVO vo2 = new AppBrokerageWithdrawRespVO()
35   - .setId(2L).setStatus(0).setPrice(20).setStatusName("审批中").setCreateTime(LocalDateTime.now());
36   - return success(new PageResult<>(asList(vo1, vo2), 10L));
  41 + public CommonResult<PageResult<AppBrokerageWithdrawRespVO>> getBrokerageWithdrawPage(AppBrokerageWithdrawPageReqVO pageReqVO) {
  42 + // 分页查询
  43 + PageResult<BrokerageWithdrawDO> pageResult = brokerageWithdrawService.getBrokerageWithdrawPage(
  44 + BrokerageWithdrawConvert.INSTANCE.convert(pageReqVO, getLoginUserId()));
  45 + return success(BrokerageWithdrawConvert.INSTANCE.convertPage03(pageResult));
37 46 }
38 47  
39   - // TODO 芋艿:临时 mock =>
40 48 @PostMapping("/create")
41 49 @Operation(summary = "创建分销提现")
42 50 @PreAuthenticated
43 51 public CommonResult<Long> createBrokerageWithdraw(@RequestBody @Valid AppBrokerageWithdrawCreateReqVO createReqVO) {
44   - return success(1L);
  52 + return success(brokerageWithdrawService.createBrokerageWithdraw(createReqVO, getLoginUserId()));
45 53 }
46 54  
47 55 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java
... ... @@ -27,7 +27,7 @@ public class AppBrokerageUserChildSummaryRespVO {
27 27 @Schema(description = "分销用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "30")
28 28 private Integer brokerageUserCount;
29 29  
30   - @Schema(description = "成为分销员时间", requiredMode = Schema.RequiredMode.REQUIRED)
  30 + @Schema(description = "绑定推广员的时间", requiredMode = Schema.RequiredMode.REQUIRED)
31 31 private LocalDateTime brokerageTime;
32 32  
33 33 }
... ...
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 20 private Integer frozenPrice;
21 21  
22 22 @Schema(description = "分销用户数量(一级)", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
23   - private Integer firstBrokerageUserCount;
  23 + private Long firstBrokerageUserCount;
24 24  
25 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/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java
... ... @@ -11,7 +11,7 @@ public class AppBrokerageUserRespVO {
11 11 private Boolean brokerageEnabled;
12 12  
13 13 @Schema(description = "可用的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2408")
14   - private Integer price;
  14 + private Integer brokeragePrice;
15 15  
16 16 @Schema(description = "冻结的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "234")
17 17 private Integer frozenPrice;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java
... ... @@ -8,8 +8,9 @@ import lombok.Data;
8 8 import org.hibernate.validator.constraints.URL;
9 9  
10 10 import javax.validation.Validator;
11   -import javax.validation.constraints.Min;
12 11 import javax.validation.constraints.NotBlank;
  12 +import javax.validation.constraints.NotNull;
  13 +import javax.validation.constraints.PositiveOrZero;
13 14  
14 15 @Schema(description = "用户 App - 分销提现创建 Request VO")
15 16 @Data
... ... @@ -20,7 +21,8 @@ public class AppBrokerageWithdrawCreateReqVO {
20 21 private Integer type;
21 22  
22 23 @Schema(description = "提现金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
23   - @Min(value = 1, message = "提现金额不能小于 1")
  24 + @PositiveOrZero(message = "提现金额不能小于 0")
  25 + @NotNull(message = "提现金额不能为空")
24 26 private Integer price;
25 27  
26 28 // ========== 银行卡、微信、支付宝 提现相关字段 ==========
... ... @@ -41,7 +43,7 @@ public class AppBrokerageWithdrawCreateReqVO {
41 43 @NotBlank(message = "持卡人姓名不能为空", groups = {Bank.class})
42 44 private String name;
43 45 @Schema(description = "提现银行", example = "1")
44   - @NotBlank(message = "提现银行不能为空", groups = {Bank.class})
  46 + @NotNull(message = "提现银行不能为空", groups = {Bank.class})
45 47 private Integer bankName;
46 48 @Schema(description = "开户地址", example = "海淀支行")
47 49 private String bankAddress;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import cn.iocoder.yudao.framework.common.validation.InEnum;
  5 +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
  6 +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawTypeEnum;
  7 +import io.swagger.v3.oas.annotations.media.Schema;
  8 +import lombok.Data;
  9 +
  10 +@Schema(description = "应用 App - 分销提现分页 Request VO")
  11 +@Data
  12 +public class AppBrokerageWithdrawPageReqVO extends PageParam {
  13 +
  14 + @Schema(description = "类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  15 + @InEnum(value = BrokerageWithdrawTypeEnum.class, message = "类型必须是 {value}")
  16 + private Integer type;
  17 +
  18 + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  19 + @InEnum(value = BrokerageWithdrawStatusEnum.class, message = "状态必须是 {value}")
  20 + private Integer status;
  21 +
  22 +}
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java
1 1 package cn.iocoder.yudao.module.trade.controller.app.config;
2 2  
  3 +import cn.hutool.core.util.ObjUtil;
3 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 5 import cn.iocoder.yudao.module.trade.controller.app.config.vo.AppTradeConfigRespVO;
  6 +import cn.iocoder.yudao.module.trade.convert.config.TradeConfigConvert;
  7 +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
  8 +import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
  9 +import io.swagger.v3.oas.annotations.Operation;
5 10 import io.swagger.v3.oas.annotations.tags.Tag;
6 11 import lombok.RequiredArgsConstructor;
7 12 import lombok.extern.slf4j.Slf4j;
... ... @@ -10,8 +15,9 @@ import org.springframework.web.bind.annotation.GetMapping;
10 15 import org.springframework.web.bind.annotation.RequestMapping;
11 16 import org.springframework.web.bind.annotation.RestController;
12 17  
  18 +import javax.annotation.Resource;
  19 +
13 20 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
14   -import static java.util.Arrays.asList;
15 21  
16 22 @Tag(name = "用户 App - 交易配置")
17 23 @RestController
... ... @@ -21,17 +27,14 @@ import static java.util.Arrays.asList;
21 27 @Slf4j
22 28 public class AppTradeConfigController {
23 29  
  30 + @Resource
  31 + private TradeConfigService tradeConfigService;
  32 +
24 33 @GetMapping("/get")
  34 + @Operation(summary = "获得交易配置")
25 35 public CommonResult<AppTradeConfigRespVO> getTradeConfig() {
26   - AppTradeConfigRespVO respVO = new AppTradeConfigRespVO();
27   - respVO.setBrokeragePosterUrls(asList(
28   - "https://api.java.crmeb.net/crmebimage/product/2020/08/03/755bf516b1ca4b6db3bfeaa4dd5901cdh71kob20re.jpg",
29   - "https://api.java.crmeb.net/crmebimage/maintain/2021/03/01/406d729b84ed4ec9a2171bfcf6fd0634ughzbz9kfi.jpg",
30   - "https://api.java.crmeb.net/crmebimage/maintain/2021/03/01/efb1e4e7fe604fe1988b4213ce08cb11tdsyijtd2r.jpg"
31   - ));
32   - respVO.setBrokerageFrozenDays(10);
33   - respVO.setBrokerageWithdrawMinPrice(100);
34   - return success(respVO);
  36 + TradeConfigDO tradeConfig = ObjUtil.defaultIfNull(tradeConfigService.getTradeConfig(), new TradeConfigDO());
  37 + return success(TradeConfigConvert.INSTANCE.convert02(tradeConfig));
35 38 }
36 39  
37 40 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java
... ... @@ -18,4 +18,7 @@ public class AppTradeConfigRespVO {
18 18 @Schema(description = "佣金提现最小金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
19 19 private Integer brokerageWithdrawMinPrice;
20 20  
  21 + @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1, 2]")
  22 + private List<Integer> brokerageWithdrawTypes;
  23 +
21 24 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverConfigController.java
... ... @@ -17,6 +17,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
17 17 @Validated
18 18 public class AppDeliverConfigController {
19 19  
  20 + // TODO @芋艿:这里后面干掉,合并到 AppTradeConfigController 中
20 21 @GetMapping("/get")
21 22 @Operation(summary = "获得配送配置")
22 23 public CommonResult<AppDeliveryConfigRespVO> getDeliveryConfig() {
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java
... ... @@ -156,7 +156,7 @@ public class AppTradeOrderController {
156 156 @Operation(summary = "删除交易订单")
157 157 @Parameter(name = "id", description = "交易订单编号")
158 158 public CommonResult<Boolean> deleteOrder(@RequestParam("id") Long id) {
159   - // TODO @芋艿:未实现,mock 用
  159 + tradeOrderUpdateService.deleteOrder(getLoginUserId(), id);
160 160 return success(true);
161 161 }
162 162  
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementRespVO.java
... ... @@ -82,6 +82,9 @@ public class AppTradeOrderSettlementRespVO {
82 82 @Schema(description = "积分抵扣的金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "50")
83 83 private Integer pointPrice;
84 84  
  85 + @Schema(description = "VIP 减免金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "30")
  86 + private Integer vipPrice;
  87 +
85 88 @Schema(description = "实际支付金额(总),单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "450")
86 89 private Integer payPrice;
87 90  
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java
... ... @@ -16,7 +16,6 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO;
16 16 import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleLogDO;
17 17 import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
18 18 import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
19   -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespDTO;
20 19 import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties;
21 20 import org.mapstruct.Mapper;
22 21 import org.mapstruct.Mapping;
... ... @@ -68,10 +67,10 @@ public interface TradeAfterSaleConvert {
68 67  
69 68 PageResult<AppTradeAfterSaleRespVO> convertPage02(PageResult<TradeAfterSaleDO> page);
70 69  
71   - List<TradeAfterSaleLogRespDTO> convertList(List<TradeAfterSaleLogDO> list);
72   -
  70 + List<TradeAfterSaleLogRespVO> convertList(List<TradeAfterSaleLogDO> list);
  71 +
73 72 default TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, TradeOrderDO order, List<TradeOrderItemDO> orderItems,
74   - MemberUserRespDTO user, List<TradeAfterSaleLogRespDTO> logs) {
  73 + MemberUserRespDTO user, List<TradeAfterSaleLogRespVO> logs) {
75 74 TradeAfterSaleDetailRespVO respVO = convert(afterSale, orderItems);
76 75 // 处理用户信息
77 76 respVO.setUser(convert(user));
... ... @@ -81,7 +80,8 @@ public interface TradeAfterSaleConvert {
81 80 respVO.setLogs(convertList1(logs));
82 81 return respVO;
83 82 }
84   - List<TradeAfterSaleLogRespVO> convertList1(List<TradeAfterSaleLogRespDTO> list);
  83 +
  84 + List<TradeAfterSaleLogRespVO> convertList1(List<TradeAfterSaleLogRespVO> list);
85 85 @Mapping(target = "id", source = "afterSale.id")
86 86 TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, List<TradeOrderItemDO> orderItems);
87 87 TradeOrderBaseVO convert(TradeOrderDO order);
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java
1   -package cn.iocoder.yudao.module.trade.convert.brokerage.record;
  1 +package cn.iocoder.yudao.module.trade.convert.brokerage;
2 2  
  3 +import cn.hutool.core.math.Money;
3 4 import cn.hutool.core.util.ObjectUtil;
4 5 import cn.hutool.core.util.StrUtil;
5 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  7 +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
6 8 import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
7   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordRespVO;
8   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO;
9   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO;
  9 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO;
  10 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordRespVO;
  11 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordPageReqVO;
  12 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordRespVO;
  13 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO;
  14 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO;
  15 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
10 16 import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
11 17 import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum;
12 18 import org.mapstruct.Mapper;
  19 +import org.mapstruct.MappingTarget;
13 20 import org.mapstruct.factory.Mappers;
14 21  
15 22 import java.time.LocalDateTime;
... ... @@ -45,7 +52,7 @@ public interface BrokerageRecordConvert {
45 52 .setBizType(bizType.getType()).setBizId(bizId)
46 53 .setPrice(brokeragePrice).setTotalPrice(user.getBrokeragePrice())
47 54 .setTitle(title)
48   - .setDescription(StrUtil.format(bizType.getDescription(), String.format("¥%.2f", brokeragePrice / 100d)))
  55 + .setDescription(StrUtil.format(bizType.getDescription(), MoneyUtils.fenToYuanStr(Math.abs(brokeragePrice))))
49 56 .setStatus(status).setFrozenDays(brokerageFrozenDays).setUnfreezeTime(unfreezeTime)
50 57 .setSourceUserLevel(sourceUserLevel).setSourceUserId(sourceUserId);
51 58 }
... ... @@ -60,4 +67,17 @@ public interface BrokerageRecordConvert {
60 67 }
61 68 return result;
62 69 }
  70 +
  71 + BrokerageRecordPageReqVO convert(AppBrokerageRecordPageReqVO pageReqVO, Long userId);
  72 +
  73 + PageResult<AppBrokerageRecordRespVO> convertPage02(PageResult<BrokerageRecordDO> pageResult);
  74 +
  75 + default PageResult<AppBrokerageUserRankByPriceRespVO> convertPage03(PageResult<AppBrokerageUserRankByPriceRespVO> pageResult, Map<Long, MemberUserRespDTO> userMap) {
  76 + for (AppBrokerageUserRankByPriceRespVO vo : pageResult.getList()) {
  77 + copyTo(userMap.get(vo.getId()), vo);
  78 + }
  79 + return pageResult;
  80 + }
  81 +
  82 + void copyTo(MemberUserRespDTO from, @MappingTarget AppBrokerageUserRankByPriceRespVO to);
63 83 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java
1   -package cn.iocoder.yudao.module.trade.convert.brokerage.user;
  1 +package cn.iocoder.yudao.module.trade.convert.brokerage;
2 2  
3 3 import cn.hutool.core.map.MapUtil;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 5 import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
6   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserRespVO;
7   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO;
  6 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserRespVO;
  7 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO;
  8 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
8 9 import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO;
  10 +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO;
9 11 import org.mapstruct.Mapper;
  12 +import org.mapstruct.MappingTarget;
10 13 import org.mapstruct.factory.Mappers;
11 14  
12 15 import java.util.List;
... ... @@ -27,13 +30,14 @@ public interface BrokerageUserConvert {
27 30  
28 31 List<BrokerageUserRespVO> convertList(List<BrokerageUserDO> list);
29 32  
30   - 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);
31 34  
32 35 default PageResult<BrokerageUserRespVO> convertPage(PageResult<BrokerageUserDO> pageResult,
33 36 Map<Long, MemberUserRespDTO> userMap,
34 37 Map<Long, Long> brokerageUserCountMap,
35   - Map<Long, UserBrokerageSummaryBO> userOrderSummaryMap) {
36   - PageResult<BrokerageUserRespVO> result = convertPage(pageResult);
  38 + Map<Long, UserBrokerageSummaryBO> userOrderSummaryMap,
  39 + Map<Long, UserWithdrawSummaryBO> withdrawMap) {
  40 + PageResult<BrokerageUserRespVO> result = convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap);
37 41 for (BrokerageUserRespVO userVO : result.getList()) {
38 42 // 用户信息
39 43 copyTo(userMap.get(userVO.getId()), userVO);
... ... @@ -44,7 +48,10 @@ public interface BrokerageUserConvert {
44 48 Optional<UserBrokerageSummaryBO> orderSummaryOptional = Optional.ofNullable(userOrderSummaryMap.get(userVO.getId()));
45 49 userVO.setBrokerageOrderCount(orderSummaryOptional.map(UserBrokerageSummaryBO::getCount).orElse(0))
46 50 .setBrokerageOrderPrice(orderSummaryOptional.map(UserBrokerageSummaryBO::getPrice).orElse(0));
47   - // 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));
48 55 userVO.setWithdrawCount(0).setWithdrawPrice(0);
49 56 }
50 57 return result;
... ... @@ -55,4 +62,13 @@ public interface BrokerageUserConvert {
55 62 user -> target.setNickname(user.getNickname()).setAvatar(user.getAvatar()));
56 63 return target;
57 64 }
  65 +
  66 + default PageResult<AppBrokerageUserRankByUserCountRespVO> convertPage03(PageResult<AppBrokerageUserRankByUserCountRespVO> pageResult,
  67 + Map<Long, MemberUserRespDTO> userMap) {
  68 + pageResult.getList().forEach(vo -> copyTo(userMap.get(vo.getId()), vo));
  69 + return pageResult;
  70 + }
  71 +
  72 + void copyTo(MemberUserRespDTO from, @MappingTarget AppBrokerageUserRankByUserCountRespVO to);
  73 +
58 74 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/withdraw/BrokerageWithdrawConvert.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java
1   -package cn.iocoder.yudao.module.trade.convert.brokerage.withdraw;
  1 +package cn.iocoder.yudao.module.trade.convert.brokerage;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils;
4 5 import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
5   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawRejectReqVO;
6   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawRespVO;
7   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.withdraw.BrokerageWithdrawDO;
  6 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO;
  7 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawRespVO;
  8 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO;
  9 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawPageReqVO;
  10 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO;
  11 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO;
  12 +import cn.iocoder.yudao.module.trade.enums.DictTypeConstants;
8 13 import org.mapstruct.Mapper;
9 14 import org.mapstruct.factory.Mappers;
10 15  
... ... @@ -22,7 +27,7 @@ public interface BrokerageWithdrawConvert {
22 27  
23 28 BrokerageWithdrawConvert INSTANCE = Mappers.getMapper(BrokerageWithdrawConvert.class);
24 29  
25   - BrokerageWithdrawDO convert(BrokerageWithdrawRejectReqVO bean);
  30 + BrokerageWithdrawDO convert(AppBrokerageWithdrawCreateReqVO createReqVO, Long userId, Integer feePrice);
26 31  
27 32 BrokerageWithdrawRespVO convert(BrokerageWithdrawDO bean);
28 33  
... ... @@ -38,4 +43,15 @@ public interface BrokerageWithdrawConvert {
38 43 return result;
39 44 }
40 45  
  46 + PageResult<AppBrokerageWithdrawRespVO> convertPage02(PageResult<BrokerageWithdrawDO> pageResult);
  47 +
  48 + default PageResult<AppBrokerageWithdrawRespVO> convertPage03(PageResult<BrokerageWithdrawDO> pageResult) {
  49 + PageResult<AppBrokerageWithdrawRespVO> result = convertPage02(pageResult);
  50 + for (AppBrokerageWithdrawRespVO vo : result.getList()) {
  51 + vo.setStatusName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.BROKERAGE_WITHDRAW_STATUS, vo.getStatus()));
  52 + }
  53 + return result;
  54 + }
  55 +
  56 + BrokerageWithdrawPageReqVO convert(AppBrokerageWithdrawPageReqVO pageReqVO, Long userId);
41 57 }
... ...
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;
... ... @@ -65,6 +67,7 @@ public interface TradeOrderConvert {
65 67 @Mapping(source = "calculateRespBO.price.deliveryPrice", target = "deliveryPrice"),
66 68 @Mapping(source = "calculateRespBO.price.couponPrice", target = "couponPrice"),
67 69 @Mapping(source = "calculateRespBO.price.pointPrice", target = "pointPrice"),
  70 + @Mapping(source = "calculateRespBO.price.vipPrice", target = "vipPrice"),
68 71 @Mapping(source = "calculateRespBO.price.payPrice", target = "payPrice")
69 72 })
70 73 TradeOrderDO convert(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO,
... ... @@ -265,11 +268,16 @@ public interface TradeOrderConvert {
265 268  
266 269 TradeOrderDO convert(TradeOrderRemarkReqVO reqVO);
267 270  
268   - default BrokerageAddReqBO convert(MemberUserRespDTO user, TradeOrderItemDO item, ProductSkuRespDTO sku) {
269   - 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())
270 274 .setBasePrice(item.getPayPrice() * item.getCount())
271 275 .setTitle(StrUtil.format("{}成功购买{}", user.getNickname(), item.getSpuName()))
272   - .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;
273 281 }
274 282  
275 283 TradeBeforeOrderCreateReqBO convert(AppTradeOrderCreateReqVO createReqVO);
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/BrokerageRecordDO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageRecordDO.java
1   -package cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record;
  1 +package cn.iocoder.yudao.module.trade.dal.dataobject.brokerage;
2 2  
3 3 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
4 4 import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageUserDO.java
1   -package cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user;
  1 +package cn.iocoder.yudao.module.trade.dal.dataobject.brokerage;
2 2  
3 3 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
4 4 import com.baomidou.mybatisplus.annotation.KeySequence;
... ... @@ -59,13 +59,4 @@ public class BrokerageUserDO extends BaseDO {
59 59 * 冻结佣金
60 60 */
61 61 private Integer frozenPrice;
62   -
63   - /**
64   - * 等级
65   - */
66   - private Integer level;
67   - /**
68   - * 路径
69   - */
70   - private String path;
71 62 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/withdraw/BrokerageWithdrawDO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageWithdrawDO.java
1   -package cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.withdraw;
  1 +package cn.iocoder.yudao.module.trade.dal.dataobject.brokerage;
2 2  
3 3 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
4 4 import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
... ... @@ -29,7 +29,7 @@ public class BrokerageWithdrawDO extends BaseDO {
29 29 * 编号
30 30 */
31 31 @TableId
32   - private Integer id;
  32 + private Long id;
33 33 /**
34 34 * 用户编号
35 35 *
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java
... ... @@ -36,7 +36,7 @@ public class TradeConfigDO extends BaseDO {
36 36 private Long id;
37 37  
38 38 // ========== 配送相关 ==========
39   - // TODO 芋艿:未配置
  39 +
40 40 /**
41 41 * 是否启用全场包邮
42 42 */
... ... @@ -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 */
... ... @@ -82,6 +82,10 @@ public class TradeConfigDO extends BaseDO {
82 82 */
83 83 private Integer brokerageWithdrawMinPrice;
84 84 /**
  85 + * 用户提现手续费百分比
  86 + */
  87 + private Integer brokerageWithdrawFeePercent;
  88 + /**
85 89 * 提现银行
86 90 */
87 91 @TableField(typeHandler = IntegerListTypeHandler.class)
... ... @@ -96,6 +100,6 @@ public class TradeConfigDO extends BaseDO {
96 100 * 枚举 {@link BrokerageWithdrawTypeEnum 对应的类}
97 101 */
98 102 @TableField(typeHandler = IntegerListTypeHandler.class)
99   - private List<Integer> brokerageWithdrawType;
  103 + private List<Integer> brokerageWithdrawTypes;
100 104  
101 105 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java
... ... @@ -168,6 +168,7 @@ public class TradeOrderDO extends BaseDO {
168 168 * - {@link #discountPrice}
169 169 * + {@link #deliveryPrice}
170 170 * + {@link #adjustPrice}
  171 + * - {@link #vipPrice}
171 172 */
172 173 private Integer payPrice;
173 174  
... ... @@ -265,9 +266,17 @@ public class TradeOrderDO extends BaseDO {
265 266 * 对应 taobao 的 trade.point_fee 字段
266 267 */
267 268 private Integer pointPrice;
268   -// /**
269   -// * 奖励的积分 TODO 疯狂:可以使用这个字段哈;
270   -// */
271   -// private Integer rewardPoint;
  269 + /**
  270 + * 赠送的积分
  271 + */
  272 + private Integer givePoint;
  273 + /**
  274 + * 退还的使用的积分
  275 + */
  276 + private Integer refundPoint;
  277 + /**
  278 + * VIP 减免金额,单位:分
  279 + */
  280 + private Integer vipPrice;
272 281  
273 282 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java
... ... @@ -126,6 +126,7 @@ public class TradeOrderItemDO extends BaseDO {
126 126 * - {@link #discountPrice}
127 127 * + {@link #deliveryPrice}
128 128 * + {@link #adjustPrice}
  129 + * - {@link #vipPrice}
129 130 */
130 131 private Integer payPrice;
131 132  
... ... @@ -143,6 +144,18 @@ public class TradeOrderItemDO extends BaseDO {
143 144 * 对应 taobao 的 trade.point_fee 字段
144 145 */
145 146 private Integer pointPrice;
  147 + /**
  148 + * 使用的积分
  149 + */
  150 + private Integer usePoint;
  151 + /**
  152 + * 赠送的积分
  153 + */
  154 + private Integer givePoint;
  155 + /**
  156 + * VIP 减免金额,单位:分
  157 + */
  158 + private Integer vipPrice;
146 159 // TODO @芋艿:如果商品 vip 折扣时,到底是新增一个 vipPrice 记录优惠记录,还是 vipDiscountPrice,记录 vip 的优惠;还是直接使用 vipPrice;
147 160 // 目前 crmeb 的选择,单独一个 vipPrice 记录优惠价格;感觉不一定合理,可以在看看有赞的;
148 161  
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/BrokerageRecordMapper.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java
1   -package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record;
  1 +package cn.iocoder.yudao.module.trade.dal.mysql.brokerage;
2 2  
3 3 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   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO;
7   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO;
  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;
  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;
... ... @@ -23,7 +25,6 @@ import java.util.List;
23 25 public interface BrokerageRecordMapper extends BaseMapperX<BrokerageRecordDO> {
24 26  
25 27 default PageResult<BrokerageRecordDO> selectPage(BrokerageRecordPageReqVO reqVO) {
26   - // 分页查询
27 28 return selectPage(reqVO, new LambdaQueryWrapperX<BrokerageRecordDO>()
28 29 .eqIfPresent(BrokerageRecordDO::getUserId, reqVO.getUserId())
29 30 .eqIfPresent(BrokerageRecordDO::getBizType, reqVO.getBizType())
... ... @@ -52,9 +53,28 @@ public interface BrokerageRecordMapper extends BaseMapperX&lt;BrokerageRecordDO&gt; {
52 53 }
53 54  
54 55 @Select("SELECT COUNT(1), SUM(price) FROM trade_brokerage_record " +
55   - "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")
56 57 UserBrokerageSummaryBO selectCountAndSumPriceByUserIdAndBizTypeAndStatus(@Param("userId") Long userId,
57 58 @Param("bizType") Integer bizType,
58 59 @Param("status") Integer status);
59 60  
  61 + @Select("SELECT SUM(price) FROM trade_brokerage_record " +
  62 + "WHERE user_id = #{userId} AND biz_type = #{bizType} " +
  63 + "AND create_time BETWEEN #{beginTime} AND #{endTime} AND deleted = FALSE")
  64 + Integer selectSummaryPriceByUserIdAndBizTypeAndCreateTimeBetween(@Param("userId") Long userId,
  65 + @Param("bizType") Integer bizType,
  66 + @Param("beginTime") LocalDateTime beginTime,
  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 deleted = FALSE " +
  71 + "AND unfreeze_time BETWEEN #{beginTime} AND #{endTime} " +
  72 + "GROUP BY user_id " +
  73 + "ORDER BY brokeragePrice DESC")
  74 + IPage<AppBrokerageUserRankByPriceRespVO> selectSummaryPricePageGroupByUserId(IPage<?> page,
  75 + @Param("bizType") Integer bizType,
  76 + @Param("status") Integer status,
  77 + @Param("beginTime") LocalDateTime beginTime,
  78 + @Param("endTime") LocalDateTime endTime);
  79 +
60 80 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java
1   -package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user;
  1 +package cn.iocoder.yudao.module.trade.dal.mysql.brokerage;
2 2  
3 3 import cn.hutool.core.lang.Assert;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 5 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
6 6 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
7   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO;
8   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO;
  7 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO;
  8 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryPageReqVO;
  9 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO;
  10 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO;
  11 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
9 12 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  13 +import com.baomidou.mybatisplus.core.metadata.IPage;
  14 +import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
10 15 import org.apache.ibatis.annotations.Mapper;
  16 +import org.apache.ibatis.annotations.Param;
  17 +import org.apache.ibatis.annotations.Select;
11 18  
  19 +import java.time.LocalDateTime;
12 20 import java.util.List;
13 21  
14 22 /**
... ... @@ -19,13 +27,12 @@ import java.util.List;
19 27 @Mapper
20 28 public interface BrokerageUserMapper extends BaseMapperX<BrokerageUserDO> {
21 29  
22   - default PageResult<BrokerageUserDO> selectPage(BrokerageUserPageReqVO reqVO, List<Integer> levels) {
  30 + default PageResult<BrokerageUserDO> selectPage(BrokerageUserPageReqVO reqVO, List<Long> bindUserIds) {
23 31 return selectPage(reqVO, new LambdaQueryWrapperX<BrokerageUserDO>()
24 32 .eqIfPresent(BrokerageUserDO::getBrokerageEnabled, reqVO.getBrokerageEnabled())
25 33 .betweenIfPresent(BrokerageUserDO::getCreateTime, reqVO.getCreateTime())
26 34 .betweenIfPresent(BrokerageUserDO::getBindUserTime, reqVO.getBindUserTime())
27   - .findInSetIfPresent(BrokerageUserDO::getPath, reqVO.getBindUserId())
28   - .inIfPresent(BrokerageUserDO::getLevel, levels)
  35 + .inIfPresent(BrokerageUserDO::getBindUserId, bindUserIds)
29 36 .orderByDesc(BrokerageUserDO::getId));
30 37 }
31 38  
... ... @@ -38,7 +45,7 @@ public interface BrokerageUserMapper extends BaseMapperX&lt;BrokerageUserDO&gt; {
38 45 default void updatePriceIncr(Long id, Integer incrCount) {
39 46 Assert.isTrue(incrCount > 0);
40 47 LambdaUpdateWrapper<BrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<BrokerageUserDO>()
41   - .setSql(" price = price + " + incrCount)
  48 + .setSql(" brokerage_price = brokerage_price + " + incrCount)
42 49 .eq(BrokerageUserDO::getId, id);
43 50 update(null, lambdaUpdateWrapper);
44 51 }
... ... @@ -49,13 +56,14 @@ public interface BrokerageUserMapper extends BaseMapperX&lt;BrokerageUserDO&gt; {
49 56 *
50 57 * @param id 用户编号
51 58 * @param incrCount 增加佣金(负数)
  59 + * @return 更新行数
52 60 */
53   - default void updatePriceDecr(Long id, Integer incrCount) {
  61 + default int updatePriceDecr(Long id, Integer incrCount) {
54 62 Assert.isTrue(incrCount < 0);
55 63 LambdaUpdateWrapper<BrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<BrokerageUserDO>()
56   - .setSql(" price = price + " + incrCount) // 负数,所以使用 + 号
  64 + .setSql(" brokerage_price = brokerage_price + " + incrCount) // 负数,所以使用 + 号
57 65 .eq(BrokerageUserDO::getId, id);
58   - update(null, lambdaUpdateWrapper);
  66 + return update(null, lambdaUpdateWrapper);
59 67 }
60 68  
61 69 /**
... ... @@ -98,7 +106,7 @@ public interface BrokerageUserMapper extends BaseMapperX&lt;BrokerageUserDO&gt; {
98 106 Assert.isTrue(incrCount < 0);
99 107 LambdaUpdateWrapper<BrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<BrokerageUserDO>()
100 108 .setSql(" frozen_price = frozen_price + " + incrCount + // 负数,所以使用 + 号
101   - ", price = price + " + -incrCount) // 负数,所以使用 - 号
  109 + ", brokerage_price = brokerage_price + " + -incrCount) // 负数,所以使用 - 号
102 110 .eq(BrokerageUserDO::getId, id)
103 111 .ge(BrokerageUserDO::getFrozenPrice, -incrCount); // cas 逻辑
104 112 return update(null, lambdaUpdateWrapper);
... ... @@ -107,8 +115,7 @@ public interface BrokerageUserMapper extends BaseMapperX&lt;BrokerageUserDO&gt; {
107 115 default void updateBindUserIdAndBindUserTimeToNull(Long id) {
108 116 update(null, new LambdaUpdateWrapper<BrokerageUserDO>()
109 117 .eq(BrokerageUserDO::getId, id)
110   - .set(BrokerageUserDO::getBindUserId, null).set(BrokerageUserDO::getBindUserTime, null)
111   - .set(BrokerageUserDO::getLevel, 1).set(BrokerageUserDO::getPath, ""));
  118 + .set(BrokerageUserDO::getBindUserId, null).set(BrokerageUserDO::getBindUserTime, null));
112 119 }
113 120  
114 121 default void updateEnabledFalseAndBrokerageTimeToNull(Long id) {
... ... @@ -117,10 +124,26 @@ public interface BrokerageUserMapper extends BaseMapperX&lt;BrokerageUserDO&gt; {
117 124 .set(BrokerageUserDO::getBrokerageEnabled, false).set(BrokerageUserDO::getBrokerageTime, null));
118 125 }
119 126  
120   - default Long selectCountByBindUserIdAndLevelIn(Long bindUserId, List<Integer> levels) {
  127 + default Long selectCountByBindUserIdIn(List<Long> bindUserIds) {
121 128 return selectCount(new LambdaQueryWrapperX<BrokerageUserDO>()
122   - .findInSetIfPresent(BrokerageUserDO::getPath, bindUserId)
123   - .inIfPresent(BrokerageUserDO::getLevel, levels));
  129 + .inIfPresent(BrokerageUserDO::getBindUserId, bindUserIds));
  130 + }
  131 +
  132 + @Select("SELECT bind_user_id AS id, COUNT(1) AS brokerageUserCount FROM trade_brokerage_user " +
  133 + "WHERE bind_user_id IS NOT NULL AND deleted = FALSE " +
  134 + "AND bind_user_time BETWEEN #{beginTime} AND #{endTime} " +
  135 + "GROUP BY bind_user_id " +
  136 + "ORDER BY brokerageUserCount DESC")
  137 + IPage<AppBrokerageUserRankByUserCountRespVO> selectCountPageGroupByBindUserId(Page<?> page,
  138 + @Param("beginTime") LocalDateTime beginTime,
  139 + @Param("endTime") LocalDateTime endTime);
  140 +
  141 + IPage<AppBrokerageUserChildSummaryRespVO> selectSummaryPageByUserId(Page<?> page,
  142 + @Param("param") AppBrokerageUserChildSummaryPageReqVO param,
  143 + @Param("userId") Long userId);
  144 +
  145 + default List<BrokerageUserDO> selectListByBindUserId(Long bindUserId) {
  146 + return selectList(BrokerageUserDO::getBindUserId, bindUserId);
124 147 }
125 148  
126 149 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/withdraw/BrokerageWithdrawMapper.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java
1   -package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.withdraw;
  1 +package cn.iocoder.yudao.module.trade.dal.mysql.brokerage;
2 2  
3 3 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   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawPageReqVO;
7   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.withdraw.BrokerageWithdrawDO;
  6 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO;
  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;
  11 +import org.apache.ibatis.annotations.Param;
  12 +import org.apache.ibatis.annotations.Select;
10 13  
11 14 /**
12 15 * 佣金提现 Mapper
... ... @@ -34,4 +37,9 @@ public interface BrokerageWithdrawMapper extends BaseMapperX&lt;BrokerageWithdrawDO
34 37 .eq(BrokerageWithdrawDO::getStatus, status));
35 38 }
36 39  
  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);
  44 +
37 45 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespDTO.java deleted
1   -package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto;
2   -
3   -import io.swagger.v3.oas.annotations.media.Schema;
4   -import lombok.AllArgsConstructor;
5   -import lombok.Data;
6   -import lombok.NoArgsConstructor;
7   -
8   -import javax.validation.constraints.NotNull;
9   -import java.time.LocalDateTime;
10   -
11   -// TODO @puhui999:这个是不是应该搞成 vo 啊?
12   -/**
13   - * 贸易售后日志详情 DTO
14   - *
15   - * @author HUIHUI
16   - */
17   -@Data
18   -@NoArgsConstructor
19   -@AllArgsConstructor
20   -public class TradeAfterSaleLogRespDTO {
21   -
22   - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20669")
23   - private Long id;
24   -
25   - @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22634")
26   - @NotNull(message = "用户编号不能为空")
27   - private Long userId;
28   -
29   - @Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
30   - @NotNull(message = "用户类型不能为空")
31   - private Integer userType;
32   -
33   - @Schema(description = "售后编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3023")
34   - @NotNull(message = "售后编号不能为空")
35   - private Long afterSaleId;
36   -
37   - @Schema(description = "订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25870")
38   - @NotNull(message = "订单编号不能为空")
39   - private Long orderId;
40   -
41   - @Schema(description = "订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23154")
42   - @NotNull(message = "订单项编号不能为空")
43   - private Long orderItemId;
44   -
45   - @Schema(description = "售后状态(之前)", example = "2")
46   - private Integer beforeStatus;
47   -
48   - @Schema(description = "售后状态(之后)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
49   - @NotNull(message = "售后状态(之后)不能为空")
50   - private Integer afterStatus;
51   -
52   - @Schema(description = "操作明细", requiredMode = Schema.RequiredMode.REQUIRED, example = "维权完成,退款金额:¥37776.00")
53   - @NotNull(message = "操作明细不能为空")
54   - private String content;
55   -
56   - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
57   - private LocalDateTime createTime;
58   -
59   -}
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java
1 1 package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service;
2 2  
3 3  
  4 +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.log.TradeAfterSaleLogRespVO;
4 5 import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO;
5   -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespDTO;
6 6  
7 7 import java.util.List;
8 8  
... ... @@ -29,6 +29,6 @@ public interface AfterSaleLogService {
29 29 * @param afterSaleId 售后编号
30 30 * @return 售后日志
31 31 */
32   - List<TradeAfterSaleLogRespDTO> getLog(Long afterSaleId);
  32 + List<TradeAfterSaleLogRespVO> getLog(Long afterSaleId);
33 33  
34 34 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/aop/TradeOrderLogAspect.java
... ... @@ -63,6 +63,9 @@ public class TradeOrderLogAspect {
63 63 Long userId = getUserId();
64 64 // 1.2 订单信息
65 65 Long orderId = ORDER_ID.get();
  66 + if (orderId == null) { // 如果未设置,只有注解,说明不需要记录订单日志
  67 + return;
  68 + }
66 69 Integer beforeStatus = BEFORE_STATUS.get();
67 70 Integer afterStatus = AFTER_STATUS.get();
68 71 Map<String, Object> exts = ObjectUtil.defaultIfNull(EXTS.get(), emptyMap());
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/BrokerageRecordUnfreezeJob.java
... ... @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.trade.job.brokerage;
3 3 import cn.hutool.core.util.StrUtil;
4 4 import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
5 5 import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
6   -import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService;
  6 +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService;
7 7 import org.springframework.stereotype.Component;
8 8  
9 9 import javax.annotation.Resource;
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java
... ... @@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO;
11 11 import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleDisagreeReqVO;
12 12 import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSalePageReqVO;
13 13 import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRefuseReqVO;
  14 +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.log.TradeAfterSaleLogRespVO;
14 15 import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleCreateReqVO;
15 16 import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleDeliveryReqVO;
16 17 import cn.iocoder.yudao.module.trade.convert.aftersale.TradeAfterSaleConvert;
... ... @@ -26,7 +27,6 @@ import cn.iocoder.yudao.module.trade.enums.aftersale.TradeAfterSaleWayEnum;
26 27 import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum;
27 28 import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
28 29 import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO;
29   -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespDTO;
30 30 import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService;
31 31 import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties;
32 32 import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService;
... ... @@ -449,8 +449,9 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
449 449 }
450 450 }
451 451  
  452 + // TODO @puhui999:应该返回 do 哈。
452 453 @Override
453   - public List<TradeAfterSaleLogRespDTO> getLog(Long afterSaleId) {
  454 + public List<TradeAfterSaleLogRespVO> getLog(Long afterSaleId) {
454 455 // TODO 不熟悉流程先这么滴
455 456 List<TradeAfterSaleLogDO> saleLogDOs = tradeAfterSaleLogMapper.selectList(TradeAfterSaleLogDO::getAfterSaleId, afterSaleId);
456 457 return TradeAfterSaleConvert.INSTANCE.convertList(saleLogDOs);
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java
1   -package cn.iocoder.yudao.module.trade.service.brokerage.record;
  1 +package cn.iocoder.yudao.module.trade.service.brokerage;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO;
5   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO;
  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;
  6 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO;
  7 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO;
  8 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO;
6 9 import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
7 10 import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO;
8 11 import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO;
9 12  
10 13 import javax.validation.Valid;
  14 +import java.time.LocalDateTime;
11 15 import java.util.List;
12 16  
13 17 /**
... ... @@ -34,7 +38,7 @@ public interface BrokerageRecordService {
34 38 PageResult<BrokerageRecordDO> getBrokerageRecordPage(BrokerageRecordPageReqVO pageReqVO);
35 39  
36 40 /**
37   - * 增加佣金
  41 + * 增加佣金【多级分佣】
38 42 *
39 43 * @param userId 会员编号
40 44 * @param bizType 业务类型
... ... @@ -43,6 +47,17 @@ public interface BrokerageRecordService {
43 47 void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, @Valid List<BrokerageAddReqBO> list);
44 48  
45 49 /**
  50 + * 增加佣金【只针对自己】
  51 + *
  52 + * @param userId 会员编号
  53 + * @param bizType 业务类型
  54 + * @param bizId 业务编号
  55 + * @param brokeragePrice 佣金
  56 + * @param title 标题
  57 + */
  58 + void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, Integer brokeragePrice, String title);
  59 +
  60 + /**
46 61 * 取消佣金:将佣金记录,状态修改为已失效
47 62 *
48 63 * @param userId 会员编号
... ... @@ -67,4 +82,41 @@ public interface BrokerageRecordService {
67 82 * @return 用户佣金汇总
68 83 */
69 84 UserBrokerageSummaryBO getUserBrokerageSummaryByUserId(Long userId, Integer bizType, Integer status);
  85 +
  86 + /**
  87 + * 获得用户佣金合计
  88 + *
  89 + * @param userId 用户编号
  90 + * @param bizType 业务类型
  91 + * @param beginTime 开始时间
  92 + * @param endTime 截止时间
  93 + * @return 用户佣金合计
  94 + */
  95 + Integer getSummaryPriceByUserId(Long userId, Integer bizType, LocalDateTime beginTime, LocalDateTime endTime);
  96 +
  97 + /**
  98 + * 获得用户佣金排行分页列表(基于佣金总数)
  99 + *
  100 + * @param pageReqVO 分页查询
  101 + * @return 排行榜分页
  102 + */
  103 + PageResult<AppBrokerageUserRankByPriceRespVO> getBrokerageUserChildSummaryPageByPrice(AppBrokerageUserRankPageReqVO pageReqVO);
  104 +
  105 + /**
  106 + * 获取用户的排名(基于佣金总数)
  107 + *
  108 + * @param userId 用户编号
  109 + * @param times 时间范围
  110 + * @return 用户的排名
  111 + */
  112 + Integer getUserRankByPrice(Long userId, LocalDateTime[] times);
  113 +
  114 + /**
  115 + * 计算商品被购买后,推广员可以得到的佣金
  116 + *
  117 + * @param spuId 商品编号
  118 + * @param userId 用户编号
  119 + * @return 用户佣金
  120 + */
  121 + AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long spuId, Long userId);
70 122 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java
1   -package cn.iocoder.yudao.module.trade.service.brokerage.record;
  1 +package cn.iocoder.yudao.module.trade.service.brokerage;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.collection.ListUtil;
  5 +import cn.hutool.core.util.ArrayUtil;
4 6 import cn.hutool.core.util.BooleanUtil;
5 7 import cn.hutool.core.util.ObjectUtil;
6 8 import cn.hutool.core.util.StrUtil;
7 9 import cn.hutool.extra.spring.SpringUtil;
8 10 import cn.iocoder.yudao.framework.common.pojo.PageResult;
9 11 import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
10   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO;
11   -import cn.iocoder.yudao.module.trade.convert.brokerage.record.BrokerageRecordConvert;
12   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO;
13   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO;
  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;
  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;
  19 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO;
  20 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO;
  21 +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert;
  22 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO;
  23 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
14 24 import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
15   -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.BrokerageRecordMapper;
  25 +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageRecordMapper;
16 26 import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
17 27 import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum;
18 28 import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO;
19 29 import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO;
20   -import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService;
21 30 import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
  31 +import com.baomidou.mybatisplus.core.metadata.IPage;
22 32 import lombok.extern.slf4j.Slf4j;
23 33 import org.springframework.stereotype.Service;
24 34 import org.springframework.transaction.annotation.Transactional;
... ... @@ -29,6 +39,13 @@ import java.time.LocalDateTime;
29 39 import java.util.ArrayList;
30 40 import java.util.List;
31 41 import java.util.Objects;
  42 +import java.util.Optional;
  43 +
  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;
  48 +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH;
32 49  
33 50 /**
34 51 * 佣金记录 Service 实现类
... ... @@ -47,6 +64,11 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
47 64 @Resource
48 65 private BrokerageUserService brokerageUserService;
49 66  
  67 + @Resource
  68 + private ProductSpuApi productSpuApi;
  69 + @Resource
  70 + private ProductSkuApi productSkuApi;
  71 +
50 72 @Override
51 73 public BrokerageRecordDO getBrokerageRecord(Integer id) {
52 74 return brokerageRecordMapper.selectById(id);
... ... @@ -218,6 +240,55 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
218 240 return summaryBO != null ? summaryBO : new UserBrokerageSummaryBO(0, 0);
219 241 }
220 242  
  243 + @Override
  244 + public Integer getSummaryPriceByUserId(Long userId, Integer bizType, LocalDateTime beginTime, LocalDateTime endTime) {
  245 + return brokerageRecordMapper.selectSummaryPriceByUserIdAndBizTypeAndCreateTimeBetween(userId, bizType, beginTime, endTime);
  246 + }
  247 +
  248 + @Override
  249 + public PageResult<AppBrokerageUserRankByPriceRespVO> getBrokerageUserChildSummaryPageByPrice(AppBrokerageUserRankPageReqVO pageReqVO) {
  250 + IPage<AppBrokerageUserRankByPriceRespVO> pageResult = brokerageRecordMapper.selectSummaryPricePageGroupByUserId(MyBatisUtils.buildPage(pageReqVO),
  251 + BrokerageRecordBizTypeEnum.ORDER.getType(), BrokerageRecordStatusEnum.SETTLEMENT.getStatus(),
  252 + ArrayUtil.get(pageReqVO.getTimes(), 0), ArrayUtil.get(pageReqVO.getTimes(), 1));
  253 + return new PageResult<>(pageResult.getRecords(), pageResult.getTotal());
  254 + }
  255 +
  256 + @Override
  257 + public Integer getUserRankByPrice(Long userId, LocalDateTime[] times) {
  258 + AppBrokerageUserRankPageReqVO pageParam = new AppBrokerageUserRankPageReqVO().setTimes(times);
  259 + // 取前 100 名
  260 + pageParam.setPageSize(100);
  261 + PageResult<AppBrokerageUserRankByPriceRespVO> pageResult = getBrokerageUserChildSummaryPageByPrice(pageParam);
  262 + // 获得索引
  263 + int index = CollUtil.indexOf(pageResult.getList(), user -> Objects.equals(userId, user.getId()));
  264 + // 获得排名
  265 + return index + 1;
  266 + }
  267 +
  268 + @Override
  269 + @Transactional(rollbackFor = Exception.class)
  270 + public void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, Integer brokeragePrice, String title) {
  271 + // 1. 校验佣金余额
  272 + BrokerageUserDO user = brokerageUserService.getBrokerageUser(userId);
  273 + int balance = Optional.of(user)
  274 + .map(BrokerageUserDO::getBrokeragePrice).orElse(0);
  275 + if (balance + brokeragePrice < 0) {
  276 + throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, MoneyUtils.fenToYuanStr(balance));
  277 + }
  278 +
  279 + // 2. 更新佣金余额
  280 + boolean success = brokerageUserService.updateUserPrice(userId, brokeragePrice);
  281 + if (!success) {
  282 + // 失败时,则抛出异常。只会出现扣减佣金时,余额不足的情况
  283 + throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, MoneyUtils.fenToYuanStr(balance));
  284 + }
  285 +
  286 + // 3. 新增记录
  287 + BrokerageRecordDO record = BrokerageRecordConvert.INSTANCE.convert(user, bizType, bizId, 0, brokeragePrice,
  288 + null, title, null, null);
  289 + brokerageRecordMapper.insert(record);
  290 + }
  291 +
221 292 @Transactional(rollbackFor = Exception.class)
222 293 public boolean unfreezeRecord(BrokerageRecordDO record) {
223 294 // 更新记录状态
... ... @@ -236,6 +307,47 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
236 307 return true;
237 308 }
238 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.isFalse(tradeConfig.getBrokerageEnabled())) {
  319 + return respVO;
  320 + }
  321 + // 2.2 校验用户是否有分销资格
  322 + respVO.setEnabled(brokerageUserService.getUserBrokerageEnabled(getLoginUserId()));
  323 + if (BooleanUtil.isFalse(respVO.getEnabled())) {
  324 + return respVO;
  325 + }
  326 + // 2.3 校验商品是否存在
  327 + ProductSpuRespDTO spu = productSpuApi.getSpu(spuId);
  328 + if (spu == null) {
  329 + return respVO;
  330 + }
  331 +
  332 + // 3.1 商品单独分佣模式
  333 + Integer fixedMinPrice = 0;
  334 + Integer fixedMaxPrice = 0;
  335 + Integer spuMinPrice = 0;
  336 + Integer spuMaxPrice = 0;
  337 + List<ProductSkuRespDTO> skuList = productSkuApi.getSkuListBySpuId(ListUtil.of(spuId));
  338 + if (BooleanUtil.isTrue(spu.getSubCommissionType())) {
  339 + fixedMinPrice = getMinValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice);
  340 + fixedMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice);
  341 + // 3.2 全局分佣模式(根据商品价格比例计算)
  342 + } else {
  343 + spuMinPrice = getMinValue(skuList, ProductSkuRespDTO::getPrice);
  344 + spuMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getPrice);
  345 + }
  346 + respVO.setBrokerageMinPrice(calculatePrice(spuMinPrice, tradeConfig.getBrokerageFirstPercent(), fixedMinPrice));
  347 + respVO.setBrokerageMaxPrice(calculatePrice(spuMaxPrice, tradeConfig.getBrokerageFirstPercent(), fixedMaxPrice));
  348 + return respVO;
  349 + }
  350 +
239 351 /**
240 352 * 获得自身的代理对象,解决 AOP 生效问题
241 353 *
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java
1   -package cn.iocoder.yudao.module.trade.service.brokerage.user;
  1 +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.framework.common.util.date.LocalDateTimeUtils;
5   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO;
6   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO;
  5 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO;
  6 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryPageReqVO;
  7 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO;
  8 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO;
  9 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO;
  10 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
7 11  
8 12 import javax.validation.constraints.NotNull;
9 13 import java.time.LocalDateTime;
... ... @@ -70,8 +74,9 @@ public interface BrokerageUserService {
70 74 *
71 75 * @param id 用户编号
72 76 * @param price 用户可用佣金
  77 + * @return 更新结果
73 78 */
74   - void updateUserPrice(Long id, Integer price);
  79 + boolean updateUserPrice(Long id, Integer price);
75 80  
76 81 /**
77 82 * 更新用户冻结佣金
... ... @@ -129,4 +134,21 @@ public interface BrokerageUserService {
129 134 * @return 是否有分销资格
130 135 */
131 136 Boolean getUserBrokerageEnabled(Long userId);
  137 +
  138 + /**
  139 + * 获得推广人排行
  140 + *
  141 + * @param pageReqVO 分页查询
  142 + * @return 推广人排行
  143 + */
  144 + PageResult<AppBrokerageUserRankByUserCountRespVO> getBrokerageUserRankPageByUserCount(AppBrokerageUserRankPageReqVO pageReqVO);
  145 +
  146 + /**
  147 + * 获得下级分销统计分页
  148 + *
  149 + * @param pageReqVO 分页查询
  150 + * @param userId 用户编号
  151 + * @return 下级分销统计分页
  152 + */
  153 + PageResult<AppBrokerageUserChildSummaryRespVO> getBrokerageUserChildSummaryPage(AppBrokerageUserChildSummaryPageReqVO pageReqVO, Long userId);
132 154 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java
1   -package cn.iocoder.yudao.module.trade.service.brokerage.user;
  1 +package cn.iocoder.yudao.module.trade.service.brokerage;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.lang.Assert;
  5 +import cn.hutool.core.util.ArrayUtil;
5 6 import cn.hutool.core.util.BooleanUtil;
6   -import cn.hutool.core.util.ObjectUtil;
7   -import cn.hutool.core.util.StrUtil;
8 7 import cn.iocoder.yudao.framework.common.pojo.PageResult;
9   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO;
10   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO;
  8 +import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
  9 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO;
  10 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryPageReqVO;
  11 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO;
  12 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO;
  13 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO;
  14 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
11 15 import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
12   -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.BrokerageUserMapper;
  16 +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageUserMapper;
13 17 import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageBindModeEnum;
14 18 import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageEnabledConditionEnum;
15 19 import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
  20 +import com.baomidou.mybatisplus.core.metadata.IPage;
16 21 import org.springframework.stereotype.Service;
17 22 import org.springframework.validation.annotation.Validated;
18 23  
19 24 import javax.annotation.Resource;
20 25 import java.time.LocalDateTime;
21   -import java.util.*;
  26 +import java.util.Collection;
  27 +import java.util.List;
  28 +import java.util.Objects;
  29 +import java.util.Optional;
22 30  
23 31 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  32 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
24 33 import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*;
25 34  
26 35 /**
... ... @@ -50,14 +59,18 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
50 59  
51 60 @Override
52 61 public PageResult<BrokerageUserDO> getBrokerageUserPage(BrokerageUserPageReqVO pageReqVO) {
53   - List<Integer> levels = buildUserQueryLevels(pageReqVO.getBindUserId(), pageReqVO.getLevel());
54   - return brokerageUserMapper.selectPage(pageReqVO, levels);
  62 + List<Long> bindUserIds = buildBindUserIdsByLevel(pageReqVO.getBindUserId(), pageReqVO.getLevel());
  63 + return brokerageUserMapper.selectPage(pageReqVO, bindUserIds);
55 64 }
56 65  
57 66 @Override
58 67 public void updateBrokerageUserId(Long id, Long bindUserId) {
59 68 // 校验存在
60 69 BrokerageUserDO brokerageUser = validateBrokerageUserExists(id);
  70 + // 绑定关系未发生变化
  71 + if (Objects.equals(brokerageUser.getBindUserId(), bindUserId)) {
  72 + return;
  73 + }
61 74  
62 75 // 情况一:清除推广员
63 76 if (bindUserId == null) {
... ... @@ -66,12 +79,6 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
66 79 return;
67 80 }
68 81  
69   - // 绑定关系未发生变化
70   - // TODO @疯狂:这个放到“情况一”之前,貌似也没关系?
71   - if (Objects.equals(brokerageUser.getBindUserId(), bindUserId)) {
72   - return;
73   - }
74   -
75 82 // 情况二:修改推广员
76 83 validateCanBindUser(brokerageUser, bindUserId);
77 84 brokerageUserMapper.updateById(fillBindUserData(bindUserId, new BrokerageUserDO().setId(id)));
... ... @@ -110,12 +117,13 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
110 117 }
111 118  
112 119 @Override
113   - public void updateUserPrice(Long id, Integer price) {
  120 + public boolean updateUserPrice(Long id, Integer price) {
114 121 if (price > 0) {
115 122 brokerageUserMapper.updatePriceIncr(id, price);
116 123 } else if (price < 0) {
117   - brokerageUserMapper.updatePriceDecr(id, price);
  124 + return brokerageUserMapper.updatePriceDecr(id, price) > 0;
118 125 }
  126 + return true;
119 127 }
120 128  
121 129 @Override
... ... @@ -138,11 +146,11 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
138 146  
139 147 @Override
140 148 public Long getBrokerageUserCountByBindUserId(Long bindUserId, Integer level) {
141   - List<Integer> levels = buildUserQueryLevels(bindUserId, level);
142   - if (CollUtil.isEmpty(levels)) {
  149 + List<Long> bindUserIds = buildBindUserIdsByLevel(bindUserId, level);
  150 + if (CollUtil.isEmpty(bindUserIds)) {
143 151 return 0L;
144 152 }
145   - return brokerageUserMapper.selectCountByBindUserIdAndLevelIn(bindUserId, levels);
  153 + return brokerageUserMapper.selectCountByBindUserIdIn(bindUserIds);
146 154 }
147 155  
148 156 @Override
... ... @@ -176,21 +184,15 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
176 184 return true;
177 185 }
178 186  
  187 + /**
  188 + * 补全绑定用户的字段
  189 + *
  190 + * @param bindUserId 绑定的用户编号
  191 + * @param brokerageUser update 对象
  192 + * @return 补全后的 update 对象
  193 + */
179 194 private BrokerageUserDO fillBindUserData(Long bindUserId, BrokerageUserDO brokerageUser) {
180   - BrokerageUserDO bindUser = getBrokerageUser(bindUserId);
181   -
182   - Integer bindUserLevel = 0;
183   - String bindUserPath = "";
184   - if (bindUser != null) {
185   - bindUserLevel = ObjectUtil.defaultIfNull(bindUser.getLevel(), 0);
186   - bindUserPath = bindUser.getPath();
187   - }
188   -
189   - String path = StrUtil.isEmpty(bindUserPath)
190   - ? String.valueOf(bindUserId)
191   - : String.format("%s,%s", bindUserPath, bindUserId);
192   - return brokerageUser.setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now())
193   - .setLevel(bindUserLevel + 1).setPath(path);
  195 + return brokerageUser.setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now());
194 196 }
195 197  
196 198 @Override
... ... @@ -207,6 +209,19 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
207 209 .orElse(false);
208 210 }
209 211  
  212 + @Override
  213 + public PageResult<AppBrokerageUserRankByUserCountRespVO> getBrokerageUserRankPageByUserCount(AppBrokerageUserRankPageReqVO pageReqVO) {
  214 + IPage<AppBrokerageUserRankByUserCountRespVO> pageResult = brokerageUserMapper.selectCountPageGroupByBindUserId(MyBatisUtils.buildPage(pageReqVO),
  215 + ArrayUtil.get(pageReqVO.getTimes(), 0), ArrayUtil.get(pageReqVO.getTimes(), 1));
  216 + return new PageResult<>(pageResult.getRecords(), pageResult.getTotal());
  217 + }
  218 +
  219 + @Override
  220 + public PageResult<AppBrokerageUserChildSummaryRespVO> getBrokerageUserChildSummaryPage(AppBrokerageUserChildSummaryPageReqVO pageReqVO, Long userId) {
  221 + IPage<AppBrokerageUserChildSummaryRespVO> pageResult = brokerageUserMapper.selectSummaryPageByUserId(MyBatisUtils.buildPage(pageReqVO), pageReqVO, userId);
  222 + return new PageResult<>(pageResult.getRecords(), pageResult.getTotal());
  223 + }
  224 +
210 225 private boolean isUserCanBind(BrokerageUserDO user, Boolean isNewUser) {
211 226 // 校验分销功能是否启用
212 227 TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig();
... ... @@ -221,6 +236,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
221 236  
222 237 // 校验分销关系绑定模式
223 238 if (BrokerageBindModeEnum.REGISTER.getMode().equals(tradeConfig.getBrokerageBindMode())) {
  239 + // TODO @疯狂:是不是把 isNewUser 挪到这里好点呀?
224 240 if (!BooleanUtil.isTrue(isNewUser)) {
225 241 throw exception(BROKERAGE_BIND_MODE_REGISTER); // 只有在注册时可以绑定
226 242 }
... ... @@ -246,29 +262,36 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
246 262 }
247 263  
248 264 // 下级不能绑定自己的上级
249   - if (StrUtil.split(bindUser.getPath(), ",").contains(String.valueOf(user.getId()))) {
250   - throw exception(BROKERAGE_BIND_LOOP);
  265 + for (int i = 0; i <= Short.MAX_VALUE; i++) {
  266 + if (Objects.equals(bindUser.getBindUserId(), user.getId())) {
  267 + throw exception(BROKERAGE_BIND_LOOP);
  268 + }
  269 + bindUser = getBrokerageUser(bindUser.getBindUserId());
  270 + // 找到根节点,结束循环
  271 + if (bindUser == null || bindUser.getBindUserId() == null) {
  272 + break;
  273 + }
251 274 }
252 275 }
253 276  
254   - // TODO @芋艿:这个层级,要微信讨论下;
255   - private List<Integer> buildUserQueryLevels(Long bindUserId, Integer level) {
256   - List<Integer> levels = new ArrayList<>(2);
257   -
258   - BrokerageUserDO bindUser = getBrokerageUser(bindUserId);
259   - if (bindUser == null) {
260   - return levels;
  277 + /**
  278 + * 根据绑定用户编号,获得绑定用户编号列表
  279 + *
  280 + * @param bindUserId 绑定用户编号
  281 + * @param level 绑定用户的层级。
  282 + * 如果 level 为空,则查询 1+2 两个层级
  283 + * @return 绑定用户编号列表
  284 + */
  285 + private List<Long> buildBindUserIdsByLevel(Long bindUserId, Integer level) {
  286 + Assert.isTrue(level == null || level <= 2, "目前只支持 level 小于等于 2");
  287 + List<Long> bindUserIds = CollUtil.newArrayList();
  288 + if (level == null || level == 1) {
  289 + bindUserIds.add(bindUserId);
261 290 }
262   -
263   - if (level == null) {
264   - // 默认查两层
265   - levels.add(bindUser.getLevel() + 1);
266   - levels.add(bindUser.getLevel() + 2);
267   - } else {
268   - levels.add(bindUser.getLevel() + level);
  291 + if (level == null || level == 2) {
  292 + bindUserIds.addAll(convertList(brokerageUserMapper.selectListByBindUserId(bindUserId), BrokerageUserDO::getId));
269 293 }
270   - return levels;
271   -
  294 + return bindUserIds;
272 295 }
273 296  
274 297 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/withdraw/BrokerageWithdrawService.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java
1   -package cn.iocoder.yudao.module.trade.service.brokerage.withdraw;
  1 +package cn.iocoder.yudao.module.trade.service.brokerage;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawPageReqVO;
5   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.withdraw.BrokerageWithdrawDO;
  4 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO;
  5 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO;
  6 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO;
6 7 import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
  8 +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO;
7 9  
8 10 /**
9 11 * 佣金提现 Service 接口
... ... @@ -13,13 +15,12 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum
13 15 public interface BrokerageWithdrawService {
14 16  
15 17 /**
16   - * 审核佣金提现
  18 + * 【管理员】审核佣金提现
17 19 *
18 20 * @param id 佣金编号
19 21 * @param status 审核状态
20 22 * @param auditReason 驳回原因
21 23 */
22   -
23 24 void auditBrokerageWithdraw(Integer id, BrokerageWithdrawStatusEnum status, String auditReason);
24 25  
25 26 /**
... ... @@ -37,4 +38,23 @@ public interface BrokerageWithdrawService {
37 38 * @return 佣金提现分页
38 39 */
39 40 PageResult<BrokerageWithdrawDO> getBrokerageWithdrawPage(BrokerageWithdrawPageReqVO pageReqVO);
  41 +
  42 + /**
  43 + * 【会员】创建佣金提现
  44 + *
  45 + * @param createReqVO 创建信息
  46 + * @param userId 会员用户编号
  47 + * @return 佣金提现编号
  48 + */
  49 + Long createBrokerageWithdraw(AppBrokerageWithdrawCreateReqVO createReqVO, Long userId);
  50 +
  51 + /**
  52 + * 汇总用户提现
  53 + *
  54 + * @param userId 用户编号
  55 + * @param status 提现状态
  56 + * @return 用户提现汇总
  57 + */
  58 + UserWithdrawSummaryBO getWithdrawSummaryByUserId(Long userId, BrokerageWithdrawStatusEnum status);
  59 +
40 60 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/withdraw/BrokerageWithdrawServiceImpl.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java
1   -package cn.iocoder.yudao.module.trade.service.brokerage.withdraw;
  1 +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 5 import cn.hutool.core.util.ObjectUtil;
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.system.api.notify.NotifyMessageSendApi;
8 9 import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
9   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawPageReqVO;
10   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.withdraw.BrokerageWithdrawDO;
11   -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.withdraw.BrokerageWithdrawMapper;
  10 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO;
  11 +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO;
  12 +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageWithdrawConvert;
  13 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO;
  14 +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
  15 +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageWithdrawMapper;
12 16 import cn.iocoder.yudao.module.trade.enums.MessageTemplateConstants;
  17 +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
13 18 import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
14   -import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService;
  19 +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawTypeEnum;
  20 +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO;
  21 +import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
15 22 import org.springframework.stereotype.Service;
16 23 import org.springframework.transaction.annotation.Transactional;
17 24 import org.springframework.validation.annotation.Validated;
18 25  
19 26 import javax.annotation.Resource;
  27 +import javax.validation.Validator;
20 28 import java.time.LocalDateTime;
21 29 import java.util.Map;
22 30  
23 31 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
24   -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_WITHDRAW_NOT_EXISTS;
25   -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING;
  32 +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*;
26 33  
27 34 /**
28 35 * 佣金提现 Service 实现类
... ... @@ -38,10 +45,15 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
38 45  
39 46 @Resource
40 47 private BrokerageRecordService brokerageRecordService;
  48 + @Resource
  49 + private TradeConfigService tradeConfigService;
41 50  
42 51 @Resource
43 52 private NotifyMessageSendApi notifyMessageSendApi;
44 53  
  54 + @Resource
  55 + private Validator validator;
  56 +
45 57 @Override
46 58 @Transactional(rollbackFor = Exception.class)
47 59 public void auditBrokerageWithdraw(Integer id, BrokerageWithdrawStatusEnum status, String auditReason) {
... ... @@ -62,19 +74,26 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
62 74 throw exception(BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING);
63 75 }
64 76  
65   - // 3. 驳回时需要退还用户佣金
66 77 String templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_APPROVE;
67   - if (BrokerageWithdrawStatusEnum.AUDIT_FAIL.equals(status)) {
  78 + if (BrokerageWithdrawStatusEnum.AUDIT_SUCCESS.equals(status)) {
  79 + // 3.1 通过时佣金转余额
  80 + if (BrokerageWithdrawTypeEnum.WALLET.getType().equals(withdraw.getType())) {
  81 + // todo
  82 + }
  83 + } else if (BrokerageWithdrawStatusEnum.AUDIT_FAIL.equals(status)) {
68 84 templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_REJECT;
69 85  
70   - // todo @owen
71   -// brokerageRecordService.addBrokerage(withdraw.getUserId(), BrokerageRecordBizTypeEnum.WITHDRAW, withdraw.getPrice(), "");
  86 + // 3.2 驳回时需要退还用户佣金
  87 + brokerageRecordService.addBrokerage(withdraw.getUserId(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT,
  88 + String.valueOf(withdraw.getId()), withdraw.getPrice(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT.getTitle());
  89 + } else {
  90 + throw new IllegalArgumentException("不支持的提现状态");
72 91 }
73 92  
74 93 // 4. 通知用户
75 94 Map<String, Object> templateParams = MapUtil.<String, Object>builder()
76 95 .put("createTime", LocalDateTimeUtil.formatNormal(withdraw.getCreateTime()))
77   - .put("price", String.format("%.2f", withdraw.getPrice() / 100d))
  96 + .put("price", MoneyUtils.fenToYuanStr(withdraw.getPrice()))
78 97 .put("reason", withdraw.getAuditReason())
79 98 .build();
80 99 NotifySendSingleToUserReqDTO reqDTO = new NotifySendSingleToUserReqDTO()
... ... @@ -101,4 +120,59 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
101 120 return brokerageWithdrawMapper.selectPage(pageReqVO);
102 121 }
103 122  
  123 + @Override
  124 + @Transactional(rollbackFor = Exception.class)
  125 + public Long createBrokerageWithdraw(AppBrokerageWithdrawCreateReqVO createReqVO, Long userId) {
  126 + // 校验提现金额
  127 + TradeConfigDO tradeConfig = validateWithdrawPrice(createReqVO.getPrice());
  128 + // 校验提现参数
  129 + createReqVO.validate(validator);
  130 +
  131 + // 计算手续费
  132 + Integer feePrice = calculateFeePrice(createReqVO.getPrice(), tradeConfig.getBrokerageWithdrawFeePercent());
  133 + // 创建佣金提现记录
  134 + BrokerageWithdrawDO withdraw = BrokerageWithdrawConvert.INSTANCE.convert(createReqVO, userId, feePrice);
  135 + brokerageWithdrawMapper.insert(withdraw);
  136 +
  137 + // 创建用户佣金记录
  138 + brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.WITHDRAW, String.valueOf(withdraw.getId()),
  139 + -createReqVO.getPrice(), BrokerageRecordBizTypeEnum.WITHDRAW.getTitle());
  140 +
  141 + return withdraw.getId();
  142 + }
  143 +
  144 + @Override
  145 + public UserWithdrawSummaryBO getWithdrawSummaryByUserId(Long userId, BrokerageWithdrawStatusEnum status) {
  146 + UserWithdrawSummaryBO summaryBO = brokerageWithdrawMapper.selectCountAndSumPriceByUserIdAndStatus(userId, status.getStatus());
  147 + return summaryBO != null ? summaryBO : new UserWithdrawSummaryBO(0, 0);
  148 + }
  149 +
  150 + /**
  151 + * 计算提现手续费
  152 + *
  153 + * @param withdrawPrice 提现金额
  154 + * @param percent 手续费百分比
  155 + * @return 提现手续费
  156 + */
  157 + Integer calculateFeePrice(Integer withdrawPrice, Integer percent) {
  158 + Integer feePrice = 0;
  159 + if (percent != null && percent > 0) {
  160 + feePrice = MoneyUtils.calculateRatePrice(withdrawPrice, Double.valueOf(percent));
  161 + }
  162 + return feePrice;
  163 + }
  164 +
  165 + /**
  166 + * 校验提现金额要求
  167 + *
  168 + * @param withdrawPrice 提现金额
  169 + * @return 分销配置
  170 + */
  171 + TradeConfigDO validateWithdrawPrice(Integer withdrawPrice) {
  172 + TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig();
  173 + if (tradeConfig.getBrokerageWithdrawMinPrice() != null && withdrawPrice < tradeConfig.getBrokerageWithdrawMinPrice()) {
  174 + throw exception(BROKERAGE_WITHDRAW_MIN_PRICE, MoneyUtils.fenToYuanStr(tradeConfig.getBrokerageWithdrawMinPrice()));
  175 + }
  176 + return tradeConfig;
  177 + }
104 178 }
... ...
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/TradeOrderQueryServiceImpl.java
... ... @@ -106,7 +106,7 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
106 106 if (order == null) {
107 107 throw exception(ORDER_NOT_FOUND);
108 108 }
109   -
  109 + // 查询物流
110 110 return getExpressTrackList(order);
111 111 }
112 112  
... ... @@ -117,7 +117,7 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
117 117 if (order == null) {
118 118 throw exception(ORDER_NOT_FOUND);
119 119 }
120   -
  120 + // 查询物流
121 121 return getExpressTrackList(order);
122 122 }
123 123  
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java
... ... @@ -63,6 +63,22 @@ public interface TradeOrderUpdateService {
63 63 void receiveOrder(Long userId, Long id);
64 64  
65 65 /**
  66 + * 【会员】取消订单
  67 + *
  68 + * @param userId 用户编号
  69 + * @param id 订单编号
  70 + */
  71 + void cancelOrder(Long userId, Long id);
  72 +
  73 + /**
  74 + * 【会员】删除订单
  75 + *
  76 + * @param userId 用户编号
  77 + * @param id 订单编号
  78 + */
  79 + void deleteOrder(Long userId, Long id);
  80 +
  81 + /**
66 82 * 【管理员】交易订单备注
67 83 *
68 84 * @param reqVO 请求
... ... @@ -117,11 +133,4 @@ public interface TradeOrderUpdateService {
117 133 */
118 134 Long createOrderItemComment(Long userId, AppTradeOrderItemCommentCreateReqVO createReqVO);
119 135  
120   - /**
121   - * 【会员】取消订单
122   - *
123   - * @param userId 用户ID
124   - * @param id 订单编号
125   - */
126   - void cancelOrder(Long userId, Long id);
127 136 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
... ... @@ -24,6 +24,7 @@ import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum;
24 24 import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi;
25 25 import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
26 26 import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
  27 +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
27 28 import cn.iocoder.yudao.module.promotion.api.bargain.BargainRecordApi;
28 29 import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi;
29 30 import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi;
... ... @@ -48,8 +49,9 @@ import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum;
48 49 import cn.iocoder.yudao.module.trade.enums.order.*;
49 50 import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties;
50 51 import cn.iocoder.yudao.module.trade.framework.order.core.annotations.TradeOrderLog;
  52 +import cn.iocoder.yudao.module.trade.framework.order.core.utils.TradeOrderLogUtils;
  53 +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService;
51 54 import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO;
52   -import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService;
53 55 import cn.iocoder.yudao.module.trade.service.cart.CartService;
54 56 import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService;
55 57 import cn.iocoder.yudao.module.trade.service.message.TradeMessageService;
... ... @@ -106,6 +108,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
106 108 private TradeMessageService tradeMessageService;
107 109  
108 110 @Resource
  111 + private ProductSpuApi productSpuApi;
  112 + @Resource
109 113 private ProductSkuApi productSkuApi;
110 114 @Resource
111 115 private PayOrderApi payOrderApi;
... ... @@ -240,8 +244,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
240 244 /**
241 245 * 订单创建前,执行前置逻辑
242 246 *
243   - * @param userId 用户编号
244   - * @param createReqVO 创建订单请求
  247 + * @param userId 用户编号
  248 + * @param createReqVO 创建订单请求
245 249 * @param calculateRespBO 订单价格计算结果
246 250 */
247 251 private void beforeCreateTradeOrder(Long userId, AppTradeOrderCreateReqVO createReqVO,
... ... @@ -260,12 +264,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
260 264  
261 265 /**
262 266 * 订单创建后,执行后置逻辑
263   - *
  267 + * <p>
264 268 * 例如说:优惠劵的扣减、积分的扣减、支付单的创建等等
265 269 *
266 270 * @param userId 用户编号
267 271 * @param createReqVO 创建订单请求
268   - * @param order 交易订单
  272 + * @param order 交易订单
269 273 * @param calculateRespBO 订单价格计算结果
270 274 */
271 275 private void afterCreateTradeOrder(Long userId, AppTradeOrderCreateReqVO createReqVO,
... ... @@ -283,12 +287,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
283 287 .setOrderId(order.getId()));
284 288 }
285 289  
286   - // 3. 扣减积分
  290 + // 3. 扣减积分(抵扣)
287 291 // 不在前置扣减的原因,是因为积分扣减时,需要记录关联业务
288   - if (order.getUsePoint() != null && order.getUsePoint() > 0) {
289   - memberPointApi.reducePoint(userId, calculateRespBO.getUsePoint(),
290   - MemberPointBizTypeEnum.ORDER_USE.getType(), String.valueOf(order.getId()));
291   - }
  292 + reduceUserPoint(order.getUserId(), order.getUsePoint(), MemberPointBizTypeEnum.ORDER_USE, order.getId());
292 293  
293 294 // 4. 删除购物车商品
294 295 Set<Long> cartIds = convertSet(createReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCartId);
... ... @@ -299,6 +300,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
299 300 // 5. 生成预支付
300 301 createPayOrder(order, orderItems, calculateRespBO);
301 302  
  303 + // 6. 插入订单日志
  304 + TradeOrderLogUtils.setOrderInfo(order.getId(), null, order.getStatus());
  305 +
302 306 // TODO @LeeYan9: 是可以思考下, 订单的营销优惠记录, 应该记录在哪里, 微信讨论起来!
303 307 }
304 308  
... ... @@ -342,8 +346,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
342 346  
343 347 // TODO 芋艿:OrderLog
344 348  
345   - // 增加用户积分
346   - getSelf().addUserPointAsync(order.getUserId(), order.getPayPrice(), order.getId());
  349 + // 增加用户积分(赠送)
  350 + addUserPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_REWARD, order.getId());
347 351 // 增加用户经验
348 352 getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId());
349 353 // 增加用户佣金
... ... @@ -482,6 +486,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
482 486  
483 487 @Override
484 488 @Transactional(rollbackFor = Exception.class)
  489 + @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_RECEIVE)
485 490 public void receiveOrder(Long userId, Long id) {
486 491 // 校验并获得交易订单(可收货)
487 492 TradeOrderDO order = validateOrderReceivable(userId, id);
... ... @@ -492,7 +497,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
492 497 if (updateCount == 0) {
493 498 throw exception(ORDER_RECEIVE_FAIL_STATUS_NOT_DELIVERED);
494 499 }
495   - // TODO 芋艿:OrderLog
496 500  
497 501 // TODO 芋艿:lili 发送订单变化的消息
498 502  
... ... @@ -500,7 +504,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
500 504  
501 505 // TODO 芋艿:销售佣金的记录;
502 506  
503   - // TODO 芋艿:获得积分;
  507 + // 插入订单日志
  508 + TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), TradeOrderStatusEnum.COMPLETED.getStatus());
504 509 }
505 510  
506 511 @Override
... ... @@ -541,41 +546,49 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
541 546 tradeOrderMapper.updateById(update);
542 547 // TODO @芋艿:改价时,赠送的积分,要不要做改动???
543 548  
544   - // TODO @puhui999:应该是按照 payPrice 分配;并且要考虑取余问题;payPrice 也要考虑,item 里的
545   - // TODO:先按 adjustPrice 实现,没明白 payPrice 怎么搞哈哈哈
546   - // TODO @puhui999:就是对比新老 adjustPrice 的差值,然后计算补充的 adjustPrice 最终值;另外,可以不用区分 items.size 是不是 > 1 哈;应该是一致的逻辑;分摊的逻辑,有点类似 dividePrice 方法噢;
547 549 // 5、更新 TradeOrderItem
548   - if (items.size() > 1) {
549   - // TradeOrderItemDO 需要做 adjustPrice 的分摊
550   - int price = reqVO.getAdjustPrice() / items.size();
551   - int remainderPrice = reqVO.getAdjustPrice() % items.size();
552   - List<TradeOrderItemDO> orders = new ArrayList<>();
553   - for (int i = 0; i < items.size(); i++) {
554   - // 把平摊后剩余的金额加到第一个订单项
555   - if (remainderPrice != 0 && i == 0) {
556   - orders.add(convertOrderItemPrice(items.get(i), price + remainderPrice));
557   - }
558   - orders.add(convertOrderItemPrice(items.get(i), price));
559   - }
560   - tradeOrderItemMapper.updateBatch(orders);
561   - } else {
562   - TradeOrderItemDO orderItem = items.get(0);
563   - TradeOrderItemDO updateItem = convertOrderItemPrice(orderItem, reqVO.getAdjustPrice());
564   - tradeOrderItemMapper.updateById(updateItem);
  550 + // TradeOrderItemDO 需要做 adjustPrice 的分摊
  551 + List<Integer> dividePrices = dividePrice(items, orderPayPrice);
  552 + List<TradeOrderItemDO> updateItems = new ArrayList<>();
  553 + for (int i = 0; i < items.size(); i++) {
  554 + TradeOrderItemDO item = items.get(i);
  555 + Integer adjustPrice = item.getPrice() - dividePrices.get(i); // 计算调整的金额
  556 + updateItems.add(new TradeOrderItemDO().setId(item.getId()).setAdjustPrice(adjustPrice)
  557 + .setPayPrice(item.getPayPrice() - adjustPrice));
565 558 }
  559 + tradeOrderItemMapper.updateBatch(updateItems);
  560 +
566 561  
567 562 // 6、更新支付订单
568 563 payOrderApi.updatePayOrderPrice(order.getPayOrderId(), update.getPayPrice());
569 564 }
570 565  
571   - private TradeOrderItemDO convertOrderItemPrice(TradeOrderItemDO orderItem, Integer price) {
572   - TradeOrderItemDO newOrderItem = new TradeOrderItemDO();
573   - newOrderItem.setId(orderItem.getId());
574   - newOrderItem.setAdjustPrice(price);
575   - int payPrice = orderItem.getAdjustPrice() != null ? (orderItem.getPayPrice() - orderItem.getAdjustPrice())
576   - + price : orderItem.getPayPrice() + price;
577   - newOrderItem.setPayPrice(payPrice);
578   - return newOrderItem;
  566 + /**
  567 + * 计算订单调价价格分摊
  568 + *
  569 + * @param items 订单项
  570 + * @param orderPayPrice 订单支付金额
  571 + * @return 分摊金额数组,和传入的 orderItems 一一对应
  572 + */
  573 + private List<Integer> dividePrice(List<TradeOrderItemDO> items, Integer orderPayPrice) {
  574 + Integer total = getSumValue(items, TradeOrderItemDO::getPrice, Integer::sum);
  575 + assert total != null;
  576 + // 遍历每一个,进行分摊
  577 + List<Integer> prices = new ArrayList<>(items.size());
  578 + int remainPrice = orderPayPrice;
  579 + for (int i = 0; i < items.size(); i++) {
  580 + TradeOrderItemDO orderItem = items.get(i);
  581 + int partPrice;
  582 + if (i < items.size() - 1) { // 减一的原因,是因为拆分时,如果按照比例,可能会出现.所以最后一个,使用反减
  583 + partPrice = (int) (orderPayPrice * (1.0D * orderItem.getPayPrice() / total));
  584 + remainPrice -= partPrice;
  585 + } else {
  586 + partPrice = remainPrice;
  587 + }
  588 + Assert.isTrue(partPrice >= 0, "分摊金额必须大于等于 0");
  589 + prices.add(partPrice);
  590 + }
  591 + return prices;
579 592 }
580 593  
581 594 @Override
... ... @@ -640,11 +653,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
640 653 return;
641 654 }
642 655 // 计算总的退款金额
643   - TradeOrderDO order = tradeOrderMapper.selectById(tradeOrderItemMapper.selectById(id).getOrderId());
  656 + TradeOrderItemDO orderItem = tradeOrderItemMapper.selectById(id);
  657 + TradeOrderDO order = tradeOrderMapper.selectById(orderItem.getOrderId());
644 658 Integer orderRefundPrice = order.getRefundPrice() + refundPrice;
645 659 if (isAllOrderItemAfterSaleSuccess(order.getId())) { // 如果都售后成功,则需要取消订单
646 660 tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId())
647   - .setRefundStatus(TradeOrderRefundStatusEnum.ALL.getStatus()).setRefundPrice(orderRefundPrice)
  661 + .setRefundStatus(TradeOrderRefundStatusEnum.ALL.getStatus()).setRefundPrice(orderRefundPrice).setRefundPoint(order.getRefundPoint() + orderItem.getUsePoint())
648 662 .setCancelType(TradeOrderCancelTypeEnum.AFTER_SALE_CLOSE.getType()).setCancelTime(LocalDateTime.now()));
649 663  
650 664 // TODO 芋艿:记录订单日志
... ... @@ -655,16 +669,22 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
655 669 .setRefundStatus(TradeOrderRefundStatusEnum.PART.getStatus()).setRefundPrice(orderRefundPrice));
656 670 }
657 671  
658   - // 扣减用户积分
659   - getSelf().reduceUserPointAsync(order.getUserId(), orderRefundPrice, afterSaleId);
660   - // 扣减用户经验
661   - getSelf().reduceUserExperienceAsync(order.getUserId(), orderRefundPrice, afterSaleId);
662   - // 更新分佣记录为已失效
663   - getSelf().cancelBrokerageAsync(order.getUserId(), id);
  672 + // 售后成功后,执行数据回滚逻辑
  673 + if (Objects.equals(newAfterSaleStatus, TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus())) {
  674 + // 扣减用户积分(赠送的)
  675 + reduceUserPoint(order.getUserId(), orderItem.getGivePoint(), MemberPointBizTypeEnum.AFTER_SALE_DEDUCT_GIVE, afterSaleId);
  676 + // 增加用户积分(返还抵扣)
  677 + addUserPoint(order.getUserId(), orderItem.getUsePoint(), MemberPointBizTypeEnum.AFTER_SALE_REFUND_USED, afterSaleId);
  678 + // 扣减用户经验
  679 + getSelf().reduceUserExperienceAsync(order.getUserId(), orderRefundPrice, afterSaleId);
  680 + // 更新分佣记录为已失效
  681 + getSelf().cancelBrokerageAsync(order.getUserId(), id);
  682 + }
664 683 }
665 684  
666 685 @Override
667 686 @Transactional(rollbackFor = Exception.class)
  687 + @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_COMMENT)
668 688 public Long createOrderItemComment(Long userId, AppTradeOrderItemCommentCreateReqVO createReqVO) {
669 689 // 先通过订单项 ID,查询订单项是否存在
670 690 TradeOrderItemDO orderItem = tradeOrderItemMapper.selectByIdAndUserId(createReqVO.getOrderItemId(), userId);
... ... @@ -692,24 +712,27 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
692 712 List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(order.getId());
693 713 if (!anyMatch(orderItems, item -> Objects.equals(item.getCommentStatus(), Boolean.FALSE))) {
694 714 tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId()).setCommentStatus(Boolean.TRUE));
695   - // TODO 待实现:已完成评价,要不要写一条订单日志?目前 crmeb 会写,有赞可以研究下
  715 + // 增加订单日志
  716 + TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), order.getStatus());
696 717 }
697 718 return comment;
698 719 }
699 720  
700 721 @Override
  722 + @Transactional(rollbackFor = Exception.class)
  723 + @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_CANCEL)
701 724 public void cancelOrder(Long userId, Long id) {
702   - // 校验存在
  725 + // 1.1 校验存在
703 726 TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(id, userId);
704 727 if (order == null) {
705 728 throw exception(ORDER_NOT_FOUND);
706 729 }
707   - // 校验状态
  730 + // 1.2 校验状态
708 731 if (ObjectUtil.notEqual(order.getStatus(), TradeOrderStatusEnum.UNPAID.getStatus())) {
709 732 throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID);
710 733 }
711 734  
712   - // 1.更新 TradeOrderDO 状态为已取消
  735 + // 2. 更新 TradeOrderDO 状态为已取消
713 736 int updateCount = tradeOrderMapper.updateByIdAndStatus(id, order.getStatus(),
714 737 new TradeOrderDO().setStatus(TradeOrderStatusEnum.CANCELED.getStatus())
715 738 .setCancelTime(LocalDateTime.now())
... ... @@ -718,22 +741,43 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
718 741 throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID);
719 742 }
720 743  
721   - // TODO 活动相关库存回滚需要活动 id,活动 id 怎么获取?app 端能否传过来
  744 + // 3. TODO 活动相关库存回滚需要活动 id,活动 id 怎么获取?app 端能否传过来;回复:从订单里拿呀
722 745 tradeOrderHandlers.forEach(handler -> handler.rollback());
723 746  
724   - // 2.回滚库存
  747 + // 4. 回滚库存
725 748 List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(id);
726 749 productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems));
727 750  
728   - // 3.回滚优惠券
729   - couponApi.returnUsedCoupon(order.getCouponId());
  751 + // 5. 回滚优惠券
  752 + if (order.getCouponId() > 0) {
  753 + couponApi.returnUsedCoupon(order.getCouponId());
  754 + }
730 755  
731   - // 4.回滚积分:积分是支付成功后才增加的吧? 回复:每个项目不同,目前看下来,确认收货貌似更合适,我再看看其它项目的业务选择;
732   - // TODO @疯狂:有赞是可配置(支付 or 确认收货),我们按照支付好列;然后这里的退积分,指的是下单时的积分抵扣。
  756 + // 6. 回滚积分(抵扣的)
  757 + addUserPoint(order.getUserId(), order.getUsePoint(), MemberPointBizTypeEnum.ORDER_CANCEL, order.getId());
733 758  
734   - // TODO 芋艿:OrderLog
  759 + // 7. 增加订单日志
  760 + TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), TradeOrderStatusEnum.CANCELED.getStatus());
  761 + }
735 762  
736   - // TODO 芋艿:lili 发送订单变化的消息
  763 + @Override
  764 + @Transactional(rollbackFor = Exception.class)
  765 + @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_DELETE)
  766 + public void deleteOrder(Long userId, Long id) {
  767 + // 1.1 校验存在
  768 + TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(id, userId);
  769 + if (order == null) {
  770 + throw exception(ORDER_NOT_FOUND);
  771 + }
  772 + // 1.2 校验状态
  773 + if (ObjectUtil.notEqual(order.getStatus(), TradeOrderStatusEnum.CANCELED.getStatus())) {
  774 + throw exception(ORDER_DELETE_FAIL_STATUS_NOT_CANCEL);
  775 + }
  776 + // 2. 删除订单
  777 + tradeOrderMapper.deleteById(id);
  778 +
  779 + // 3. 记录日志
  780 + TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), order.getStatus());
737 781 }
738 782  
739 783 /**
... ... @@ -760,29 +804,54 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
760 804 memberLevelApi.addExperience(userId, -refundPrice, bizType, String.valueOf(afterSaleId));
761 805 }
762 806  
763   - @Async
764   - protected void addUserPointAsync(Long userId, Integer payPrice, Long orderId) {
765   - // TODO @疯狂:具体多少积分,需要分成 2 不分:1. 支付金额;2. 商品金额
766   - int bizType = MemberPointBizTypeEnum.ORDER_REWARD.getType();
767   - memberPointApi.addPoint(userId, payPrice, bizType, String.valueOf(orderId));
  807 + /**
  808 + * 添加用户积分
  809 + * <p>
  810 + * 目前是支付成功后,就会创建积分记录。
  811 + * <p>
  812 + * 业内还有两种做法,可以根据自己的业务调整:
  813 + * 1. 确认收货后,才创建积分记录
  814 + * 2. 支付 or 下单成功时,创建积分记录(冻结),确认收货解冻或者 n 天后解冻
  815 + *
  816 + * @param userId 用户编号
  817 + * @param point 增加积分数量
  818 + * @param bizType 业务编号
  819 + * @param bizId 业务编号
  820 + */
  821 + protected void addUserPoint(Long userId, Integer point, MemberPointBizTypeEnum bizType, Long bizId) {
  822 + if (point != null && point > 0) {
  823 + memberPointApi.addPoint(userId, point, bizType.getType(), String.valueOf(bizId));
  824 + }
768 825 }
769 826  
770   - @Async
771   - protected void reduceUserPointAsync(Long userId, Integer refundPrice, Long afterSaleId) {
772   - // TODO @疯狂:退款时,按照金额比例,退还积分;https://help.youzan.com/displaylist/detail_4_4-1-49185
773   - int bizType = MemberPointBizTypeEnum.ORDER_CANCEL.getType();
774   - memberPointApi.addPoint(userId, -refundPrice, bizType, String.valueOf(afterSaleId));
  827 + protected void reduceUserPoint(Long userId, Integer point, MemberPointBizTypeEnum bizType, Long bizId) {
  828 + if (point != null && point > 0) {
  829 + memberPointApi.reducePoint(userId, point, bizType.getType(), String.valueOf(bizId));
  830 + }
775 831 }
776 832  
  833 + /**
  834 + * 创建分销记录
  835 + *
  836 + * 目前是支付成功后,就会创建分销记录。
  837 + *
  838 + * 业内还有两种做法,可以根据自己的业务调整:
  839 + * 1. 确认收货后,才创建分销记录
  840 + * 2. 支付 or 下单成功时,创建分销记录(冻结),确认收货解冻或者 n 天后解冻
  841 + *
  842 + * @param userId 用户编号
  843 + * @param orderId 订单编号
  844 + */
777 845 @Async
778 846 protected void addBrokerageAsync(Long userId, Long orderId) {
779 847 MemberUserRespDTO user = memberUserApi.getUser(userId);
780 848 Assert.notNull(user);
781   -
  849 + // 每一个订单项,都会去生成分销记录
782 850 List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(orderId);
783   - List<BrokerageAddReqBO> list = convertList(orderItems,
784   - item -> TradeOrderConvert.INSTANCE.convert(user, item, productSkuApi.getSku(item.getSkuId())));
785   - brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, list);
  851 + List<BrokerageAddReqBO> addList = convertList(orderItems,
  852 + item -> TradeOrderConvert.INSTANCE.convert(user, item,
  853 + productSpuApi.getSpu(item.getSpuId()), productSkuApi.getSku(item.getSkuId())));
  854 + brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, addList);
786 855 }
787 856  
788 857 @Async
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/bo/TradeBeforeOrderCreateReqBO.java
1 1 package cn.iocoder.yudao.module.trade.service.order.bo;
2 2  
  3 +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
3 4 import io.swagger.v3.oas.annotations.media.Schema;
4 5 import lombok.Data;
5 6  
... ... @@ -14,36 +15,73 @@ import javax.validation.constraints.NotNull;
14 15 @Data
15 16 public class TradeBeforeOrderCreateReqBO {
16 17  
17   - // TODO @puhui999:注释也写下哈;bo 还是写注释噢
18   -
  18 + /**
  19 + * 订单类型
  20 + *
  21 + * 枚举 {@link TradeOrderTypeEnum}
  22 + */
19 23 @NotNull(message = "订单类型不能为空")
20 24 private Integer orderType;
21 25  
  26 + /**
  27 + * 用户编号
  28 + *
  29 + * 关联 MemberUserDO 的 id 编号
  30 + */
  31 + @NotNull(message = "用户编号不能为空")
  32 + private Long userId;
  33 +
22 34 // ========== 秒杀活动相关字段 ==========
23 35  
  36 + /**
  37 + *
  38 + */
24 39 @Schema(description = "秒杀活动编号", example = "1024")
25 40 private Long seckillActivityId;
26 41  
27 42 // ========== 拼团活动相关字段 ==========
28 43  
  44 + /**
  45 + * 拼团活动编号
  46 + */
29 47 @Schema(description = "拼团活动编号", example = "1024")
30 48 private Long combinationActivityId;
31 49  
  50 + /**
  51 + * 拼团团长编号
  52 + */
32 53 @Schema(description = "拼团团长编号", example = "2048")
33 54 private Long combinationHeadId;
34 55  
  56 + // ========== 砍价活动相关字段 ==========
  57 +
  58 + /**
  59 + * 砍价活动编号
  60 + */
35 61 @Schema(description = "砍价活动编号", example = "123")
36 62 private Long bargainActivityId;
37 63  
  64 + // ========== 活动购买商品相关字段 ==========
  65 +
  66 + /**
  67 + * 商品 SPU 编号
  68 + *
  69 + * 关联 ProductSkuDO 的 spuId 编号
  70 + */
38 71 @NotNull(message = "SPU 编号不能为空")
39 72 private Long spuId;
40 73  
  74 + /**
  75 + * 商品 SKU 编号
  76 + *
  77 + * 关联 ProductSkuDO 的 id 编号
  78 + */
41 79 @NotNull(message = "SKU 编号活动商品不能为空")
42 80 private Long skuId;
43 81  
44   - @NotNull(message = "用户编号不能为空")
45   - private Long userId;
46   -
  82 + /**
  83 + * 购买的商品数量
  84 + */
47 85 @NotNull(message = "购买数量不能为空")
48 86 private Integer count;
49 87  
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java
... ... @@ -20,14 +20,17 @@ public class TradeBargainHandler implements TradeOrderHandler {
20 20 @Resource
21 21 private BargainActivityApi bargainActivityApi;
22 22  
  23 + // TODO @puhui999:先临时写在这里;在价格计算时,如果是秒杀商品,需要校验如下条件:
  24 + // 1. 商品存在、库存充足、单次限购;
  25 + // 2. 活动进行中、时间段符合
  26 +
23 27 @Override
24 28 public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) {
25 29 // 如果是砍价订单
26 30 if (ObjectUtil.notEqual(TradeOrderTypeEnum.BARGAIN.getType(), reqBO.getOrderType())) {
27 31 return;
28 32 }
29   -
30   - // 额外扣减砍价的库存
  33 + // 扣减砍价活动的库存
31 34 bargainActivityApi.updateBargainActivityStock(reqBO.getBargainActivityId(), reqBO.getCount());
32 35 }
33 36  
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java
... ... @@ -24,9 +24,12 @@ public interface TradeOrderHandler {
24 24 */
25 25 void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO);
26 26  
  27 + // TODO @puhui999:这个搞成订单取消
27 28 /**
28 29 * 回滚
29 30 */
30 31 void rollback();
31 32  
  33 + // TODO @puhui999:再搞个订单项取消哈
  34 +
32 35 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java
... ... @@ -20,13 +20,17 @@ public class TradeSeckillHandler implements TradeOrderHandler {
20 20 @Resource
21 21 private SeckillActivityApi seckillActivityApi;
22 22  
  23 + // TODO @puhui999:先临时写在这里;在价格计算时,如果是秒杀商品,需要校验如下条件:
  24 + // 1. 商品存在、库存充足、单次限购;
  25 + // 2. 活动进行中、时间段符合
  26 +
23 27 @Override
24 28 public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) {
25 29 // 如果是秒杀订单:额外扣减秒杀的库存;
26 30 if (ObjectUtil.notEqual(TradeOrderTypeEnum.SECKILL.getType(), reqBO.getOrderType())) {
27 31 return;
28 32 }
29   -
  33 + // 扣减秒杀活动的库存
30 34 seckillActivityApi.updateSeckillStock(reqBO.getSeckillActivityId(), reqBO.getSkuId(), reqBO.getCount());
31 35 }
32 36  
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java
... ... @@ -41,7 +41,6 @@ public class TradePriceServiceImpl implements TradePriceService {
41 41 @Resource
42 42 private List<TradePriceCalculator> priceCalculators;
43 43  
44   - // TODO @疯狂:需要搞个 TradePriceCalculator,计算赠送积分;
45 44 @Override
46 45 public TradePriceCalculateRespBO calculatePrice(TradePriceCalculateReqBO calculateReqBO) {
47 46 // 1.1 获得商品 SKU 数组
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java
... ... @@ -29,7 +29,7 @@ public class TradePriceCalculateReqBO {
29 29 * 对应 CouponDO 的 id 编号
30 30 */
31 31 private Long couponId;
32   - // TODO @疯狂:需要增加一个 PriceCalculator 实现积分扣减的计算;写回到 TradePriceCalculateRespBO 的 usePoint
  32 +
33 33 /**
34 34 * 是否使用积分
35 35 */
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java
... ... @@ -54,6 +54,11 @@ public class TradePriceCalculateRespBO {
54 54 private Integer usePoint;
55 55  
56 56 /**
  57 + * 使用的积分
  58 + */
  59 + private Integer givePoint;
  60 +
  61 + /**
57 62 * 订单价格
58 63 */
59 64 @Data
... ... @@ -90,6 +95,10 @@ public class TradePriceCalculateRespBO {
90 95 */
91 96 private Integer pointPrice;
92 97 /**
  98 + * VIP 减免金额,单位:分
  99 + */
  100 + private Integer vipPrice;
  101 + /**
93 102 * 最终购买金额(总),单位:分
94 103 *
95 104 * = {@link #totalPrice}
... ... @@ -97,6 +106,7 @@ public class TradePriceCalculateRespBO {
97 106 * - {@link #pointPrice}
98 107 * - {@link #discountPrice}
99 108 * + {@link #deliveryPrice}
  109 + * - {@link #vipPrice}
100 110 */
101 111 private Integer payPrice;
102 112  
... ... @@ -159,6 +169,14 @@ public class TradePriceCalculateRespBO {
159 169 */
160 170 private Integer pointPrice;
161 171 /**
  172 + * 使用的积分
  173 + */
  174 + private Integer usePoint;
  175 + /**
  176 + * VIP 减免金额,单位:分
  177 + */
  178 + private Integer vipPrice;
  179 + /**
162 180 * 应付金额(总),单位:分
163 181 *
164 182 * = {@link #price} * {@link #count}
... ... @@ -166,6 +184,7 @@ public class TradePriceCalculateRespBO {
166 184 * - {@link #pointPrice}
167 185 * - {@link #discountPrice}
168 186 * + {@link #deliveryPrice}
  187 + * - {@link #vipPrice}
169 188 */
170 189 private Integer payPrice;
171 190  
... ... @@ -205,6 +224,11 @@ public class TradePriceCalculateRespBO {
205 224 */
206 225 private List<ProductPropertyValueDetailRespDTO> properties;
207 226  
  227 + /**
  228 + * 使用的积分
  229 + */
  230 + private Integer givePoint;
  231 +
208 232 }
209 233  
210 234 /**
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculator.java
... ... @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.trade.service.price.calculator;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.lang.Assert;
  5 +import cn.hutool.core.util.ObjectUtil;
5 6 import cn.hutool.core.util.StrUtil;
6 7 import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi;
7 8 import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO;
... ... @@ -9,6 +10,7 @@ import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponValidReqDTO;
9 10 import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum;
10 11 import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum;
11 12 import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
  13 +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
12 14 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
13 15 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
14 16 import org.springframework.core.annotation.Order;
... ... @@ -22,6 +24,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
22 24 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
23 25 import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_NO_MATCH_MIN_PRICE;
24 26 import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_NO_MATCH_SPU;
  27 +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER;
25 28  
26 29 /**
27 30 * 优惠劵的 {@link TradePriceCalculator} 实现类
... ... @@ -44,6 +47,10 @@ public class TradeCouponPriceCalculator implements TradePriceCalculator {
44 47 CouponRespDTO coupon = couponApi.validateCoupon(new CouponValidReqDTO()
45 48 .setId(param.getCouponId()).setUserId(param.getUserId()));
46 49 Assert.notNull(coupon, "校验通过的优惠劵({}),不能为空", param.getCouponId());
  50 + // 1.2 只有【普通】订单,才允许使用优惠劵
  51 + if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) {
  52 + throw exception(PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER);
  53 + }
47 54  
48 55 // 2.1 获得匹配的商品 SKU 数组
49 56 List<TradePriceCalculateRespBO.OrderItem> orderItems = filterMatchCouponOrderItems(result, coupon);
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java
... ... @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.trade.service.price.calculator;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.lang.Assert;
  5 +import cn.hutool.core.util.StrUtil;
5 6 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
6 7 import cn.iocoder.yudao.module.member.api.address.AddressApi;
7 8 import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO;
... ... @@ -55,15 +56,16 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
55 56 return;
56 57 }
57 58 if (DeliveryTypeEnum.PICK_UP.getType().equals(param.getDeliveryType())) {
58   - calculateByPickUp(param, result);
  59 + calculateByPickUp(param);
59 60 } else if (DeliveryTypeEnum.EXPRESS.getType().equals(param.getDeliveryType())) {
60 61 calculateExpress(param, result);
61 62 }
62 63 }
63 64  
64   - private void calculateByPickUp(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) {
  65 + private void calculateByPickUp(TradePriceCalculateReqBO param) {
65 66 if (param.getPickUpStoreId() == null) {
66   - throw exception(PRICE_CALCULATE_DELIVERY_PRICE_PICK_UP_STORE_IS_EMPTY);
  67 + // 价格计算时,如果为空就不算~最终下单,会校验该字段不允许空
  68 + return;
67 69 }
68 70 DeliveryPickUpStoreDO pickUpStore = deliveryPickUpStoreService.getDeliveryPickUpStore(param.getPickUpStoreId());
69 71 if (pickUpStore == null || CommonStatusEnum.DISABLE.getStatus().equals(pickUpStore.getStatus())) {
... ... @@ -76,18 +78,19 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
76 78 private void calculateExpress(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) {
77 79 // 0. 得到收件地址区域
78 80 if (param.getAddressId() == null) {
79   - throw exception(PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDRESS_IS_EMPTY);
  81 + // 价格计算时,如果为空就不算~最终下单,会校验该字段不允许空
  82 + return;
80 83 }
81 84 AddressRespDTO address = addressApi.getAddress(param.getAddressId(), param.getUserId());
82 85 Assert.notNull(address, "收件人({})的地址,不能为空", param.getUserId());
83 86  
84 87 // 情况一:全局包邮
85   - if (isGlobalExpressFree(param, result)) {
  88 + if (isGlobalExpressFree(result)) {
86 89 return;
87 90 }
88 91  
89   - // 情况二:
90   - // 2.1 过滤出已选中的商品SKU
  92 + // 情况二:快递模版
  93 + // 2.1 过滤出已选中的商品 SKU
91 94 List<OrderItem> selectedItem = filterList(result.getItems(), OrderItem::getSelected);
92 95 Set<Long> deliveryTemplateIds = convertSet(selectedItem, OrderItem::getDeliveryTemplateId);
93 96 Map<Long, DeliveryExpressTemplateRespBO> expressTemplateMap =
... ... @@ -103,11 +106,10 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
103 106 /**
104 107 * 是否全局包邮
105 108 *
106   - * @param param 计算信息
107 109 * @param result 计算结果
108 110 * @return 是否包邮
109 111 */
110   - private boolean isGlobalExpressFree(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) {
  112 + private boolean isGlobalExpressFree(TradePriceCalculateRespBO result) {
111 113 TradeConfigDO config = tradeConfigService.getTradeConfig();
112 114 return config != null
113 115 && Boolean.TRUE.equals(config.getDeliveryExpressFreeEnabled()) // 开启包邮
... ... @@ -118,9 +120,9 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
118 120 Map<Long, DeliveryExpressTemplateRespBO> expressTemplateMap,
119 121 TradePriceCalculateRespBO result) {
120 122 // 按商品运费模板来计算商品的运费:相同的运费模板可能对应多条订单商品 SKU
121   - Map<Long, List<OrderItem>> tplIdItemMap = convertMultiMap(selectedSkus, OrderItem::getDeliveryTemplateId);
  123 + Map<Long, List<OrderItem>> template2ItemMap = convertMultiMap(selectedSkus, OrderItem::getDeliveryTemplateId);
122 124 // 依次计算快递运费
123   - for (Map.Entry<Long, List<OrderItem>> entry : tplIdItemMap.entrySet()) {
  125 + for (Map.Entry<Long, List<OrderItem>> entry : template2ItemMap.entrySet()) {
124 126 Long templateId = entry.getKey();
125 127 List<OrderItem> orderItems = entry.getValue();
126 128 DeliveryExpressTemplateRespBO templateBO = expressTemplateMap.get(templateId);
... ... @@ -128,30 +130,12 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
128 130 log.error("[calculateDeliveryPrice][不能计算快递运费,找不到 templateId({}) 对应的运费模板配置]", templateId);
129 131 continue;
130 132 }
131   - // 总件数, 总金额, 总重量, 总体积
132   - int totalCount = 0;
133   - int totalPrice = 0;
134   - double totalWeight = 0;
135   - double totalVolume = 0;
136   - for (OrderItem orderItem : orderItems) {
137   - totalCount += orderItem.getCount();
138   - totalPrice += orderItem.getPayPrice();
139   - if (orderItem.getWeight() != null) {
140   - totalWeight += totalWeight + orderItem.getWeight() * orderItem.getCount();
141   - }
142   - if (orderItem.getVolume() != null) {
143   - totalVolume += totalVolume + orderItem.getVolume() * orderItem.getCount();
144   - }
145   - }
146   - // 优先判断是否包邮. 如果包邮不计算快递运费
147   - if (isExpressFree(templateBO.getChargeMode(), totalCount, totalWeight,
148   - totalVolume, totalPrice, templateBO.getFree())) {
  133 + // 1. 优先判断是否包邮。如果包邮不计算快递运费
  134 + if (isExpressTemplateFree(orderItems, templateBO.getChargeMode(), templateBO.getFree())) {
149 135 continue;
150 136 }
151   - // 计算快递运费
152   - calculateExpressFeeByChargeMode(totalCount, totalWeight, totalVolume,
153   - templateBO.getChargeMode(), templateBO.getCharge(), orderItems);
154   -
  137 + // 2. 计算快递运费
  138 + calculateExpressFeeByChargeMode(orderItems, templateBO.getChargeMode(), templateBO.getCharge());
155 139 }
156 140 TradePriceCalculatorHelper.recountAllPrice(result);
157 141 }
... ... @@ -159,73 +143,44 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
159 143 /**
160 144 * 按配送方式来计算运费
161 145 *
162   - * @param totalCount 总件数
163   - * @param totalWeight 总重量
164   - * @param totalVolume 总体积
  146 + * @param orderItems SKU 商品项目
165 147 * @param chargeMode 配送计费方式
166 148 * @param templateCharge 快递运费配置
167   - * @param orderItems SKU 商品项目
168 149 */
169   - private void calculateExpressFeeByChargeMode(double totalCount, double totalWeight, double totalVolume,
170   - int chargeMode, DeliveryExpressTemplateRespBO.Charge templateCharge,
171   - List<OrderItem> orderItems) {
  150 + private void calculateExpressFeeByChargeMode(List<OrderItem> orderItems, Integer chargeMode,
  151 + DeliveryExpressTemplateRespBO.Charge templateCharge) {
172 152 if (templateCharge == null) {
173 153 log.error("[calculateExpressFeeByChargeMode][计算快递运费时,找不到 SKU({}) 对应的运费模版]", orderItems);
174 154 return;
175 155 }
176   - DeliveryExpressChargeModeEnum chargeModeEnum = DeliveryExpressChargeModeEnum.valueOf(chargeMode);
177   - switch (chargeModeEnum) {
178   - case PIECE: {
179   - calculateExpressFee(totalCount, templateCharge, orderItems);
180   - break;
181   - }
182   - case WEIGHT: {
183   - calculateExpressFee(totalWeight, templateCharge, orderItems);
184   - break;
185   - }
186   - case VOLUME: {
187   - calculateExpressFee(totalVolume, templateCharge, orderItems);
188   - break;
189   - }
190   - }
191   - }
192   -
193   - /**
194   - * 计算 SKU 商品快递费用
195   - *
196   - * @param total 总件数/总重量/总体积
197   - * @param templateCharge 快递运费配置
198   - * @param orderItems SKU 商品项目
199   - */
200   - private void calculateExpressFee(double total, DeliveryExpressTemplateRespBO.Charge templateCharge, List<OrderItem> orderItems) {
  156 + double totalChargeValue = getTotalChargeValue(orderItems, chargeMode);
  157 + // 1. 计算 SKU 商品快递费用
201 158 int deliveryPrice;
202   - if (total <= templateCharge.getStartCount()) {
  159 + if (totalChargeValue <= templateCharge.getStartCount()) {
203 160 deliveryPrice = templateCharge.getStartPrice();
204 161 } else {
205   - double remainWeight = total - templateCharge.getStartCount();
  162 + double remainWeight = totalChargeValue - templateCharge.getStartCount();
206 163 // 剩余重量/ 续件 = 续件的次数. 向上取整
207 164 int extraNum = (int) Math.ceil(remainWeight / templateCharge.getExtraCount());
208 165 int extraPrice = templateCharge.getExtraPrice() * extraNum;
209 166 deliveryPrice = templateCharge.getStartPrice() + extraPrice;
210 167 }
211   - // 分摊快递费用到 SKU. 退费的时候,可能按照 SKU 考虑退费金额
212   - divideDeliveryPrice(deliveryPrice, orderItems);
213   - }
214 168  
215   - /**
216   - * 快递运费分摊到每个 SKU 商品上
217   - *
218   - * @param deliveryPrice 快递运费
219   - * @param orderItems SKU 商品
220   - */
221   - private void divideDeliveryPrice(int deliveryPrice, List<OrderItem> orderItems) {
222   - // TODO @jason:分摊的话,是不是要按照比例呀?重量、价格、数量等等,
223   - // 按比例是不是有点复杂。后面看看是否需要;
224   - // TODO 可以看看别的项目怎么搞的哈。
225   - int dividePrice = deliveryPrice / orderItems.size();
226   - for (OrderItem item : orderItems) {
  169 + // 2. 分摊快递费用到 SKU. 退费的时候,可能按照 SKU 考虑退费金额
  170 + int remainPrice = deliveryPrice;
  171 + for (int i = 0; i < orderItems.size(); i++) {
  172 + TradePriceCalculateRespBO.OrderItem item = orderItems.get(i);
  173 + int partPrice;
  174 + double chargeValue = getChargeValue(item, chargeMode);
  175 + if (i < orderItems.size() - 1) { // 减一的原因,是因为拆分时,如果按照比例,可能会出现.所以最后一个,使用反减
  176 + partPrice = (int) (deliveryPrice * (chargeValue / totalChargeValue));
  177 + remainPrice -= partPrice;
  178 + } else {
  179 + partPrice = remainPrice;
  180 + }
  181 + Assert.isTrue(partPrice >= 0, "分摊金额必须大于等于 0");
227 182 // 更新快递运费
228   - item.setDeliveryPrice(dividePrice);
  183 + item.setDeliveryPrice(partPrice);
229 184 TradePriceCalculatorHelper.recountPayPrice(item);
230 185 }
231 186 }
... ... @@ -234,42 +189,38 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
234 189 * 检查是否包邮
235 190 *
236 191 * @param chargeMode 配送计费方式
237   - * @param totalCount 总件数
238   - * @param totalWeight 总重量
239   - * @param totalVolume 总体积
240   - * @param totalPrice 总金额
241 192 * @param templateFree 包邮配置
242 193 */
243   - private boolean isExpressFree(Integer chargeMode, int totalCount, double totalWeight,
244   - double totalVolume, int totalPrice, DeliveryExpressTemplateRespBO.Free templateFree) {
  194 + private boolean isExpressTemplateFree(List<OrderItem> orderItems, Integer chargeMode,
  195 + DeliveryExpressTemplateRespBO.Free templateFree) {
245 196 if (templateFree == null) {
246 197 return false;
247 198 }
  199 + double totalChargeValue = getTotalChargeValue(orderItems, chargeMode);
  200 + double totalPrice = TradePriceCalculatorHelper.calculateTotalPayPrice(orderItems);
  201 + return totalChargeValue >= templateFree.getFreeCount() && totalPrice >= templateFree.getFreePrice();
  202 + }
  203 +
  204 + private double getTotalChargeValue(List<OrderItem> orderItems, Integer chargeMode) {
  205 + double total = 0;
  206 + for (OrderItem orderItem : orderItems) {
  207 + total += getChargeValue(orderItem, chargeMode);
  208 + }
  209 + return total;
  210 + }
  211 +
  212 + private double getChargeValue(OrderItem orderItem, Integer chargeMode) {
248 213 DeliveryExpressChargeModeEnum chargeModeEnum = DeliveryExpressChargeModeEnum.valueOf(chargeMode);
249 214 switch (chargeModeEnum) {
250   - case PIECE:
251   - // 两个条件都满足才包邮
252   - if (totalCount >= templateFree.getFreeCount() && totalPrice >= templateFree.getFreePrice()) {
253   - return true;
254   - }
255   - break;
  215 + case COUNT:
  216 + return orderItem.getCount();
256 217 case WEIGHT:
257   - // freeCount 是不是应该是 double ??
258   - // TODO @jason:要不配置的时候,把它的单位和商品对齐?到底是 kg、还是斤
259   - // TODO @芋艿 目前 包邮 件数/重量/体积 都用的是这个字段
260   - // TODO @jason:那要不快递模版也改成 kg?这样是不是就不用 double ?
261   - if (totalWeight >= templateFree.getFreeCount()
262   - && totalPrice >= templateFree.getFreePrice()) {
263   - return true;
264   - }
265   - break;
  218 + return orderItem.getWeight() != null ? orderItem.getWeight() * orderItem.getCount() : 0;
266 219 case VOLUME:
267   - if (totalVolume >= templateFree.getFreeCount()
268   - && totalPrice >= templateFree.getFreePrice()) {
269   - return true;
270   - }
271   - break;
  220 + return orderItem.getVolume() != null ? orderItem.getVolume() * orderItem.getCount() : 0;
  221 + default:
  222 + throw new IllegalArgumentException(StrUtil.format("未知的计费模式({})", chargeMode));
272 223 }
273   - return false;
274 224 }
  225 +
275 226 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculator.java
1 1 package cn.iocoder.yudao.module.trade.service.price.calculator;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.util.ObjectUtil;
4 5 import cn.hutool.core.util.StrUtil;
5 6 import cn.iocoder.yudao.module.promotion.api.discount.DiscountActivityApi;
6 7 import cn.iocoder.yudao.module.promotion.api.discount.dto.DiscountProductRespDTO;
7 8 import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum;
8 9 import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
  10 +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
9 11 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
10 12 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
11 13 import org.springframework.core.annotation.Order;
... ... @@ -33,6 +35,10 @@ public class TradeDiscountActivityPriceCalculator implements TradePriceCalculato
33 35  
34 36 @Override
35 37 public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) {
  38 + // 0. 只有【普通】订单,才计算该优惠
  39 + if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) {
  40 + return;
  41 + }
36 42 // 获得 SKU 对应的限时折扣活动
37 43 List<DiscountProductRespDTO> discountProducts = discountActivityApi.getMatchDiscountProductList(
38 44 convertSet(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSkuId));
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculator.java 0 → 100644
  1 +package cn.iocoder.yudao.module.trade.service.price.calculator;
  2 +
  3 +import cn.hutool.core.util.ObjectUtil;
  4 +import cn.iocoder.yudao.module.member.api.level.MemberLevelApi;
  5 +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO;
  6 +import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
  7 +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
  8 +import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
  9 +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
  10 +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
  11 +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
  12 +import org.springframework.core.annotation.Order;
  13 +import org.springframework.stereotype.Component;
  14 +
  15 +import javax.annotation.Resource;
  16 +
  17 +import static cn.iocoder.yudao.module.trade.service.price.calculator.TradePriceCalculatorHelper.formatPrice;
  18 +
  19 +/**
  20 + * 会员 VIP 折扣的 {@link TradePriceCalculator} 实现类
  21 + *
  22 + * @author 芋道源码
  23 + */
  24 +@Component
  25 +@Order(TradePriceCalculator.ORDER_MEMBER_LEVEL)
  26 +public class TradeMemberLevelPriceCalculator implements TradePriceCalculator {
  27 +
  28 + @Resource
  29 + private MemberLevelApi memberLevelApi;
  30 + @Resource
  31 + private MemberUserApi memberUserApi;
  32 +
  33 + @Override
  34 + public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) {
  35 + // 0. 只有【普通】订单,才计算该优惠
  36 + if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) {
  37 + return;
  38 + }
  39 + // 1. 获得用户的会员等级
  40 + MemberUserRespDTO user = memberUserApi.getUser(param.getUserId());
  41 + if (user.getLevelId() == null || user.getLevelId() <= 0) {
  42 + return;
  43 + }
  44 + MemberLevelRespDTO level = memberLevelApi.getMemberLevel(user.getLevelId());
  45 + if (level == null || level.getDiscountPercent() == null) {
  46 + return;
  47 + }
  48 +
  49 + // 2. 计算每个 SKU 的优惠金额
  50 + result.getItems().forEach(orderItem -> {
  51 + // 2.1 计算优惠金额
  52 + Integer vipPrice = calculateVipPrice(orderItem.getPayPrice(), level.getDiscountPercent());
  53 + if (vipPrice <= 0) {
  54 + return;
  55 + }
  56 +
  57 + // 2.2 记录优惠明细
  58 + if (orderItem.getSelected()) {
  59 + // 注意,只有在选中的情况下,才会记录到优惠明细。否则仅仅是更新 SKU 优惠金额,用于展示
  60 + TradePriceCalculatorHelper.addPromotion(result, orderItem,
  61 + level.getId(), level.getName(), PromotionTypeEnum.MEMBER_LEVEL.getType(),
  62 + String.format("会员等级折扣:省 %s 元", formatPrice(vipPrice)),
  63 + vipPrice);
  64 + }
  65 +
  66 + // 2.3 更新 SKU 的优惠金额
  67 + orderItem.setVipPrice(vipPrice);
  68 + TradePriceCalculatorHelper.recountPayPrice(orderItem);
  69 + });
  70 + TradePriceCalculatorHelper.recountAllPrice(result);
  71 + }
  72 +
  73 + /**
  74 + * 计算会员 VIP 优惠价格
  75 + *
  76 + * @param price 原价
  77 + * @param discountPercent 折扣
  78 + * @return 优惠价格
  79 + */
  80 + public Integer calculateVipPrice(Integer price, Integer discountPercent) {
  81 + if (discountPercent == null) {
  82 + return 0;
  83 + }
  84 + Integer newPrice = price * discountPercent / 100;
  85 + return price - newPrice;
  86 + }
  87 +
  88 +}
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointGiveCalculator.java 0 → 100644
  1 +package cn.iocoder.yudao.module.trade.service.price.calculator;
  2 +
  3 +import cn.hutool.core.util.BooleanUtil;
  4 +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
  5 +import cn.iocoder.yudao.module.member.api.point.MemberPointApi;
  6 +import cn.iocoder.yudao.module.member.api.point.dto.MemberPointConfigRespDTO;
  7 +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
  8 +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
  9 +import lombok.extern.slf4j.Slf4j;
  10 +import org.springframework.core.annotation.Order;
  11 +import org.springframework.stereotype.Component;
  12 +
  13 +import javax.annotation.Resource;
  14 +import java.util.List;
  15 +import java.util.Optional;
  16 +
  17 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
  18 +
  19 +/**
  20 + * 赠送积分的 {@link TradePriceCalculator} 实现类
  21 + *
  22 + * @author owen
  23 + */
  24 +@Component
  25 +@Order(TradePriceCalculator.ORDER_POINT_GIVE)
  26 +@Slf4j
  27 +public class TradePointGiveCalculator implements TradePriceCalculator {
  28 + @Resource
  29 + private MemberPointApi memberPointApi;
  30 +
  31 + @Override
  32 + public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) {
  33 + // 1.1 校验积分功能是否开启
  34 + int givePointPerYuan = Optional.ofNullable(memberPointApi.getConfig())
  35 + .filter(config -> BooleanUtil.isTrue(config.getTradeDeductEnable()))
  36 + .map(MemberPointConfigRespDTO::getTradeGivePoint)
  37 + .orElse(0);
  38 + if (givePointPerYuan <= 0) {
  39 + return;
  40 + }
  41 + // 1.2 校验支付金额
  42 + if (result.getPrice().getPayPrice() <= 0) {
  43 + return;
  44 + }
  45 +
  46 + // 2.1 计算赠送积分
  47 + int givePoint = MoneyUtils.calculateRatePriceFloor(result.getPrice().getPayPrice(), (double) givePointPerYuan);
  48 + // 2.2 计算分摊的赠送积分
  49 + List<TradePriceCalculateRespBO.OrderItem> orderItems = filterList(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSelected);
  50 + List<Integer> dividePoints = TradePriceCalculatorHelper.dividePrice(orderItems, givePoint);
  51 +
  52 + // 3.2 更新 SKU 赠送积分
  53 + for (int i = 0; i < orderItems.size(); i++) {
  54 + TradePriceCalculateRespBO.OrderItem orderItem = orderItems.get(i);
  55 + // 商品可能赠送了积分,所以这里要加上
  56 + orderItem.setGivePoint(orderItem.getGivePoint() + dividePoints.get(i));
  57 + TradePriceCalculatorHelper.recountPayPrice(orderItem);
  58 + }
  59 + // 3.3 更新订单赠送积分
  60 + TradePriceCalculatorHelper.recountAllGivePoint(result);
  61 + }
  62 +}
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointUsePriceCalculator.java
1 1 package cn.iocoder.yudao.module.trade.service.price.calculator;
2 2  
  3 +import cn.hutool.core.util.BooleanUtil;
  4 +import cn.hutool.core.util.NumberUtil;
  5 +import cn.hutool.core.util.StrUtil;
  6 +import cn.iocoder.yudao.module.member.api.point.MemberPointApi;
  7 +import cn.iocoder.yudao.module.member.api.point.dto.MemberPointConfigRespDTO;
  8 +import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
  9 +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
  10 +import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
3 11 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
4 12 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
5 13 import lombok.extern.slf4j.Slf4j;
6 14 import org.springframework.core.annotation.Order;
7 15 import org.springframework.stereotype.Component;
8 16  
  17 +import javax.annotation.Resource;
  18 +import java.math.RoundingMode;
  19 +import java.util.List;
  20 +
  21 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
  22 +
9 23 /**
10 24 * 使用积分的 {@link TradePriceCalculator} 实现类
11 25 *
... ... @@ -15,15 +29,81 @@ import org.springframework.stereotype.Component;
15 29 @Order(TradePriceCalculator.ORDER_POINT_USE)
16 30 @Slf4j
17 31 public class TradePointUsePriceCalculator implements TradePriceCalculator {
  32 + @Resource
  33 + private MemberPointApi memberPointApi;
  34 + @Resource
  35 + private MemberUserApi memberUserApi;
18 36  
19 37 @Override
20 38 public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) {
21   - // TODO 疯狂:待实现,嘿嘿;
22   - if (param.getPointStatus()) {
23   - result.setUsePoint(10);
24   - } else {
  39 + // 1.1 校验是否使用积分
  40 + if (!BooleanUtil.isTrue(param.getPointStatus())) {
25 41 result.setUsePoint(0);
  42 + return;
  43 + }
  44 + // 1.2 校验积分抵扣是否开启
  45 + MemberPointConfigRespDTO config = memberPointApi.getConfig();
  46 + if (!checkDeductPointEnable(config)) {
  47 + return;
  48 + }
  49 + // 1.3 校验用户积分余额
  50 + MemberUserRespDTO user = memberUserApi.getUser(param.getUserId());
  51 + if (user.getPoint() == null || user.getPoint() < 0) {
  52 + return;
  53 + }
  54 +
  55 + // 2.1 计算积分优惠金额
  56 + int pointPrice = calculatePointPrice(config, user.getPoint(), result);
  57 + // 2.1 计算分摊的积分、抵扣金额
  58 + List<TradePriceCalculateRespBO.OrderItem> orderItems = filterList(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSelected);
  59 + List<Integer> dividePointPrices = TradePriceCalculatorHelper.dividePrice(orderItems, pointPrice);
  60 + List<Integer> divideUsePoints = TradePriceCalculatorHelper.dividePrice(orderItems, result.getUsePoint());
  61 +
  62 + // 3.1 记录优惠明细
  63 + TradePriceCalculatorHelper.addPromotion(result, orderItems,
  64 + param.getUserId(), "积分抵扣", PromotionTypeEnum.POINT.getType(),
  65 + StrUtil.format("积分抵扣:省 {} 元", TradePriceCalculatorHelper.formatPrice(pointPrice)),
  66 + dividePointPrices);
  67 + // 3.2 更新 SKU 优惠金额
  68 + for (int i = 0; i < orderItems.size(); i++) {
  69 + TradePriceCalculateRespBO.OrderItem orderItem = orderItems.get(i);
  70 + orderItem.setPointPrice(dividePointPrices.get(i));
  71 + orderItem.setUsePoint(divideUsePoints.get(i));
  72 + TradePriceCalculatorHelper.recountPayPrice(orderItem);
  73 + }
  74 + TradePriceCalculatorHelper.recountAllPrice(result);
  75 + }
  76 +
  77 + private boolean checkDeductPointEnable(MemberPointConfigRespDTO config) {
  78 + if (config == null) {
  79 + return false;
26 80 }
  81 + if (!BooleanUtil.isTrue(config.getTradeDeductEnable())) {
  82 + return false;
  83 + }
  84 +
  85 + // 有没有配置:1 积分抵扣多少分
  86 + return config.getTradeDeductUnitPrice() != null && config.getTradeDeductUnitPrice() > 0;
27 87 }
28 88  
  89 + private Integer calculatePointPrice(MemberPointConfigRespDTO config, Integer usePoint, TradePriceCalculateRespBO result) {
  90 + // 每个订单最多可以使用的积分数量
  91 + if (config.getTradeDeductMaxPrice() != null && config.getTradeDeductMaxPrice() > 0) {
  92 + usePoint = Math.min(usePoint, config.getTradeDeductMaxPrice());
  93 + }
  94 + // 积分优惠金额(分)
  95 + int pointPrice = usePoint * config.getTradeDeductUnitPrice();
  96 + // 0元购!!!:用户积分比较多时,积分可以抵扣的金额要大于支付金额, 这时需要根据支付金额反推使用多少积分
  97 + if (result.getPrice().getPayPrice() < pointPrice) {
  98 + pointPrice = result.getPrice().getPayPrice();
  99 + // 反推需要扣除的积分
  100 + usePoint = NumberUtil.toBigDecimal(pointPrice)
  101 + .divide(NumberUtil.toBigDecimal(config.getTradeDeductUnitPrice()), 0, RoundingMode.HALF_UP)
  102 + .intValue();
  103 + }
  104 + // 记录使用的积分
  105 + result.setUsePoint(usePoint);
  106 +
  107 + return pointPrice;
  108 + }
29 109 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java
... ... @@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
13 13 */
14 14 public interface TradePriceCalculator {
15 15  
  16 + int ORDER_MEMBER_LEVEL = 5;
16 17 int ORDER_DISCOUNT_ACTIVITY = 10;
17 18 int ORDER_REWARD_ACTIVITY = 20;
18 19 int ORDER_COUPON = 30;
... ... @@ -23,6 +24,10 @@ public interface TradePriceCalculator {
23 24 * 放在各种营销活动、优惠劵后面 TODO
24 25 */
25 26 int ORDER_DELIVERY = 50;
  27 + /**
  28 + * 赠送积分,放最后
  29 + */
  30 + int ORDER_POINT_GIVE = 999;
26 31  
27 32 void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result);
28 33  
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java
... ... @@ -52,13 +52,14 @@ public class TradePriceCalculatorHelper {
52 52 .setCount(item.getCount()).setCartId(item.getCartId()).setSelected(item.getSelected());
53 53 // sku 价格
54 54 orderItem.setPrice(sku.getPrice()).setPayPrice(sku.getPrice() * item.getCount())
55   - .setDiscountPrice(0).setDeliveryPrice(0).setCouponPrice(0).setPointPrice(0);
  55 + .setDiscountPrice(0).setDeliveryPrice(0).setCouponPrice(0).setPointPrice(0).setVipPrice(0);
56 56 // sku 信息
57 57 orderItem.setPicUrl(sku.getPicUrl()).setProperties(sku.getProperties())
58 58 .setWeight(sku.getWeight()).setVolume(sku.getVolume());
59 59 // spu 信息
60 60 orderItem.setSpuName(spu.getName()).setCategoryId(spu.getCategoryId())
61   - .setDeliveryTemplateId(spu.getDeliveryTemplateId());
  61 + .setDeliveryTemplateId(spu.getDeliveryTemplateId())
  62 + .setGivePoint(spu.getGiveIntegral()).setUsePoint(0);
62 63 if (orderItem.getPicUrl() == null) {
63 64 orderItem.setPicUrl(spu.getPicUrl());
64 65 }
... ... @@ -67,6 +68,7 @@ public class TradePriceCalculatorHelper {
67 68 // 创建它的 Price 属性
68 69 result.setPrice(new TradePriceCalculateRespBO.Price());
69 70 recountAllPrice(result);
  71 + recountAllGivePoint(result);
70 72 return result;
71 73 }
72 74  
... ... @@ -96,7 +98,7 @@ public class TradePriceCalculatorHelper {
96 98 // 先重置
97 99 TradePriceCalculateRespBO.Price price = result.getPrice();
98 100 price.setTotalPrice(0).setDiscountPrice(0).setDeliveryPrice(0)
99   - .setCouponPrice(0).setPointPrice(0).setPayPrice(0);
  101 + .setCouponPrice(0).setPointPrice(0).setVipPrice(0).setPayPrice(0);
100 102 // 再合计 item
101 103 result.getItems().forEach(item -> {
102 104 if (!item.getSelected()) {
... ... @@ -107,21 +109,33 @@ public class TradePriceCalculatorHelper {
107 109 price.setDeliveryPrice(price.getDeliveryPrice() + item.getDeliveryPrice());
108 110 price.setCouponPrice(price.getCouponPrice() + item.getCouponPrice());
109 111 price.setPointPrice(price.getPointPrice() + item.getPointPrice());
  112 + price.setVipPrice(price.getVipPrice() + item.getVipPrice());
110 113 price.setPayPrice(price.getPayPrice() + item.getPayPrice());
111 114 });
112 115 }
113 116  
114 117 /**
  118 + * 基于订单项,重新计算赠送积分
  119 + *
  120 + * @param result 计算结果
  121 + */
  122 + public static void recountAllGivePoint(TradePriceCalculateRespBO result) {
  123 + result.setGivePoint(getSumValue(result.getItems(), item -> item.getSelected() ? item.getGivePoint() : 0, Integer::sum));
  124 + }
  125 +
  126 + /**
115 127 * 重新计算单个订单项的支付金额
116 128 *
117 129 * @param orderItem 订单项
118 130 */
119 131 public static void recountPayPrice(TradePriceCalculateRespBO.OrderItem orderItem) {
120   - orderItem.setPayPrice(orderItem.getPrice()* orderItem.getCount()
  132 + orderItem.setPayPrice(orderItem.getPrice() * orderItem.getCount()
121 133 - orderItem.getDiscountPrice()
122 134 + orderItem.getDeliveryPrice()
123 135 - orderItem.getCouponPrice()
124   - - orderItem.getPointPrice());
  136 + - orderItem.getPointPrice()
  137 + - orderItem.getVipPrice()
  138 + );
125 139 }
126 140  
127 141 /**
... ... @@ -145,6 +159,15 @@ public class TradePriceCalculatorHelper {
145 159 if (orderItem.getPointPrice() == null) {
146 160 orderItem.setPointPrice(0);
147 161 }
  162 + if (orderItem.getUsePoint() == null) {
  163 + orderItem.setUsePoint(0);
  164 + }
  165 + if (orderItem.getGivePoint() == null) {
  166 + orderItem.setGivePoint(0);
  167 + }
  168 + if (orderItem.getVipPrice() == null) {
  169 + orderItem.setVipPrice(0);
  170 + }
148 171 recountPayPrice(orderItem);
149 172 });
150 173 }
... ... @@ -169,7 +192,7 @@ public class TradePriceCalculatorHelper {
169 192 */
170 193 public static Integer calculateTotalCount(List<TradePriceCalculateRespBO.OrderItem> orderItems) {
171 194 return getSumValue(orderItems,
172   - orderItem -> orderItem.getSelected() ? orderItem.getCount() : 0, // 未选中的情况下,不计算数量
  195 + orderItem -> orderItem.getSelected() ? orderItem.getCount() : 0, // 未选中的情况下,不计算数量
173 196 Integer::sum);
174 197 }
175 198  
... ... @@ -177,7 +200,7 @@ public class TradePriceCalculatorHelper {
177 200 * 按照支付金额,返回每个订单项的分摊金额数组
178 201 *
179 202 * @param orderItems 订单项数组
180   - * @param price 金额
  203 + * @param price 金额
181 204 * @return 分摊金额数组,和传入的 orderItems 一一对应
182 205 */
183 206 public static List<Integer> dividePrice(List<TradePriceCalculateRespBO.OrderItem> orderItems, Integer price) {
... ... @@ -210,12 +233,12 @@ public class TradePriceCalculatorHelper {
210 233 /**
211 234 * 添加【匹配】单个 OrderItem 的营销明细
212 235 *
213   - * @param result 价格计算结果
  236 + * @param result 价格计算结果
214 237 * @param orderItem 单个订单商品 SKU
215   - * @param id 营销编号
216   - * @param name 营销名字
217   - * @param description 满足条件的提示
218   - * @param type 营销类型
  238 + * @param id 营销编号
  239 + * @param name 营销名字
  240 + * @param description 满足条件的提示
  241 + * @param type 营销类型
219 242 * @param discountPrice 单个订单商品 SKU 的优惠价格(总)
220 243 */
221 244 public static void addPromotion(TradePriceCalculateRespBO result, TradePriceCalculateRespBO.OrderItem orderItem,
... ... @@ -226,7 +249,7 @@ public class TradePriceCalculatorHelper {
226 249 /**
227 250 * 添加【匹配】多个 OrderItem 的营销明细
228 251 *
229   - * @param result 价格计算结果
  252 + * @param result 价格计算结果
230 253 * @param orderItems 多个订单商品 SKU
231 254 * @param id 营销编号
232 255 * @param name 营销名字
... ... @@ -235,7 +258,7 @@ public class TradePriceCalculatorHelper {
235 258 * @param discountPrices 多个订单商品 SKU 的优惠价格(总),和 orderItems 一一对应
236 259 */
237 260 public static void addPromotion(TradePriceCalculateRespBO result, List<TradePriceCalculateRespBO.OrderItem> orderItems,
238   - Long id, String name, Integer type, String description, List<Integer> discountPrices) {
  261 + Long id, String name, Integer type, String description, List<Integer> discountPrices) {
239 262 // 创建营销明细 Item
240 263 List<TradePriceCalculateRespBO.PromotionItem> promotionItems = new ArrayList<>(discountPrices.size());
241 264 for (int i = 0; i < orderItems.size(); i++) {
... ... @@ -255,12 +278,12 @@ public class TradePriceCalculatorHelper {
255 278 /**
256 279 * 添加【不匹配】多个 OrderItem 的营销明细
257 280 *
258   - * @param result 价格计算结果
259   - * @param orderItems 多个订单商品 SKU
260   - * @param id 营销编号
261   - * @param name 营销名字
262   - * @param description 满足条件的提示
263   - * @param type 营销类型
  281 + * @param result 价格计算结果
  282 + * @param orderItems 多个订单商品 SKU
  283 + * @param id 营销编号
  284 + * @param name 营销名字
  285 + * @param description 满足条件的提示
  286 + * @param type 营销类型
264 287 */
265 288 public static void addNotMatchPromotion(TradePriceCalculateRespBO result, List<TradePriceCalculateRespBO.OrderItem> orderItems,
266 289 Long id, String name, Integer type, String description) {
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculator.java
1 1 package cn.iocoder.yudao.module.trade.service.price.calculator;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.util.ObjectUtil;
4 5 import cn.hutool.core.util.StrUtil;
5 6 import cn.iocoder.yudao.module.promotion.api.reward.RewardActivityApi;
6 7 import cn.iocoder.yudao.module.promotion.api.reward.dto.RewardActivityMatchRespDTO;
7 8 import cn.iocoder.yudao.module.promotion.enums.common.PromotionConditionTypeEnum;
8 9 import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
  10 +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
9 11 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
10 12 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
11 13 import org.springframework.core.annotation.Order;
... ... @@ -32,6 +34,10 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator
32 34  
33 35 @Override
34 36 public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) {
  37 + // 0. 只有【普通】订单,才计算该优惠
  38 + if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) {
  39 + return;
  40 + }
35 41 // 获得 SKU 对应的满减送活动
36 42 List<RewardActivityMatchRespDTO> rewardActivities = rewardActivityApi.getMatchRewardActivityList(
37 43 convertSet(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSpuId));
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageUserMapper">
  4 +
  5 + <select id="selectSummaryPageByUserId"
  6 + resultType="cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO">
  7 + SELECT bu.id, bu.bind_user_time AS brokerageTime, u.nickname, u.avatar,
  8 + (SELECT SUM(price) FROM trade_brokerage_record r
  9 + WHERE r.user_id = u.id AND biz_type = 1 AND r.status = 1 AND r.deleted = FALSE) AS brokeragePrice,
  10 + (SELECT COUNT(1) FROM trade_brokerage_record r
  11 + WHERE r.user_id = u.id AND biz_type = 1 AND r.status = 1 AND r.deleted = FALSE) AS brokerageOrderCount,
  12 + (SELECT COUNT(1) FROM trade_brokerage_user c
  13 + WHERE c.bind_user_id = u.id AND c.deleted = FALSE) AS brokerageUserCount
  14 + FROM member_user AS u
  15 + JOIN trade_brokerage_user AS bu ON bu.id = u.id
  16 + <where>
  17 + <if test="param.nickname != null and param.nickname != ''">
  18 + AND u.nickname LIKE concat('', #{param.nickname}, '')
  19 + </if>
  20 + <if test="param.level == 1">
  21 + AND bu.bind_user_id = #{userId}
  22 + </if>
  23 + <if test="param.level == 2">
  24 + AND bu.bind_user_id IN (SELECT id FROM trade_brokerage_user c WHERE c.bind_user_id = #{userId})
  25 + </if>
  26 + </where>
  27 + <choose>
  28 + <when test="param.sortingField.field == 'userCount'">
  29 + ORDER BY brokerageUserCount ${param.sortingField.order}
  30 + </when>
  31 + <when test="param.sortingField.field == 'orderCount'">
  32 + ORDER BY brokerageOrderCount ${param.sortingField.order}
  33 + </when>
  34 + <when test="param.sortingField.field == 'price'">
  35 + ORDER BY brokeragePrice ${param.sortingField.order}
  36 + </when>
  37 + <otherwise>
  38 + ORDER BY bu.bind_user_time DESC
  39 + </otherwise>
  40 + </choose>
  41 + </select>
  42 +
  43 +</mapper>
... ...
yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImplTest.java renamed to yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImplTest.java
1   -package cn.iocoder.yudao.module.trade.service.brokerage.record;
  1 +package cn.iocoder.yudao.module.trade.service.brokerage;
2 2  
3 3 import cn.hutool.core.util.NumberUtil;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 5 import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
6   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO;
7   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO;
8   -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.BrokerageRecordMapper;
9   -import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService;
  6 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO;
  7 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO;
  8 +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageRecordMapper;
  9 +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordServiceImpl;
  10 +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService;
10 11 import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
11 12 import org.junit.jupiter.api.Disabled;
12 13 import org.junit.jupiter.api.Test;
... ...
yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java renamed to yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImplTest.java
1   -package cn.iocoder.yudao.module.trade.service.brokerage.user;
  1 +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.framework.test.core.ut.BaseDbUnitTest;
5   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO;
6   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO;
7   -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.BrokerageUserMapper;
  5 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO;
  6 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
  7 +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageUserMapper;
  8 +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserServiceImpl;
8 9 import org.junit.jupiter.api.Disabled;
9 10 import org.junit.jupiter.api.Test;
10 11 import org.springframework.context.annotation.Import;
... ...
yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/withdraw/BrokerageWithdrawServiceImplTest.java renamed to yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImplTest.java
1   -package cn.iocoder.yudao.module.trade.service.withdraw;
  1 +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.framework.test.core.ut.BaseDbUnitTest;
5   -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawPageReqVO;
6   -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.withdraw.BrokerageWithdrawDO;
7   -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.withdraw.BrokerageWithdrawMapper;
8   -import cn.iocoder.yudao.module.trade.service.brokerage.withdraw.BrokerageWithdrawServiceImpl;
  5 +import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
  6 +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO;
  7 +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO;
  8 +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageWithdrawMapper;
  9 +import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
9 10 import org.junit.jupiter.api.Disabled;
10 11 import org.junit.jupiter.api.Test;
  12 +import org.springframework.boot.test.mock.mockito.MockBean;
11 13 import org.springframework.context.annotation.Import;
12 14  
13 15 import javax.annotation.Resource;
  16 +import javax.validation.Validator;
14 17  
15 18 import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
16 19 import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
... ... @@ -33,6 +36,19 @@ public class BrokerageWithdrawServiceImplTest extends BaseDbUnitTest {
33 36 @Resource
34 37 private BrokerageWithdrawMapper brokerageWithdrawMapper;
35 38  
  39 + @MockBean
  40 + private BrokerageRecordService brokerageRecordService;
  41 + @MockBean
  42 + private BrokerageUserService brokerageUserService;
  43 + @MockBean
  44 + private TradeConfigService tradeConfigService;
  45 +
  46 + @MockBean
  47 + private NotifyMessageSendApi notifyMessageSendApi;
  48 +
  49 + @Resource
  50 + private Validator validator;
  51 +
36 52 @Test
37 53 @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
38 54 public void testGetBrokerageWithdrawPage() {
... ... @@ -85,4 +101,17 @@ public class BrokerageWithdrawServiceImplTest extends BaseDbUnitTest {
85 101 assertPojoEquals(dbBrokerageWithdraw, pageResult.getList().get(0));
86 102 }
87 103  
  104 + @Test
  105 + public void testCalculateFeePrice() {
  106 + Integer withdrawPrice = 100;
  107 + // 测试手续费比例未设置
  108 + Integer percent = null;
  109 + assertEquals(brokerageWithdrawService.calculateFeePrice(withdrawPrice, percent), 0);
  110 + // 测试手续费给为0
  111 + percent = 0;
  112 + assertEquals(brokerageWithdrawService.calculateFeePrice(withdrawPrice, percent), 0);
  113 + // 测试手续费
  114 + percent = 1;
  115 + assertEquals(brokerageWithdrawService.calculateFeePrice(withdrawPrice, percent), 1);
  116 + }
88 117 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculatorTest.java
... ... @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponValidReqDTO;
7 7 import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum;
8 8 import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum;
9 9 import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
  10 +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
10 11 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
11 12 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
12 13 import org.junit.jupiter.api.Test;
... ... @@ -47,6 +48,7 @@ public class TradeCouponPriceCalculatorTest extends BaseMockitoUnitTest {
47 48 new TradePriceCalculateReqBO.Item().setSkuId(40L).setCount(5).setSelected(false) // 匹配优惠劵,但是未选中
48 49 ));
49 50 TradePriceCalculateRespBO result = new TradePriceCalculateRespBO()
  51 + .setType(TradeOrderTypeEnum.NORMAL.getType())
50 52 .setPrice(new TradePriceCalculateRespBO.Price())
51 53 .setPromotions(new ArrayList<>())
52 54 .setItems(asList(
... ...
yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java
... ... @@ -91,7 +91,7 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest {
91 91 item -> item.setFreeCount(20).setFreePrice(100));
92 92 // 准备 SP 运费模板数据
93 93 templateRespBO = randomPojo(DeliveryExpressTemplateRespBO.class,
94   - item -> item.setChargeMode(DeliveryExpressChargeModeEnum.PIECE.getType())
  94 + item -> item.setChargeMode(DeliveryExpressChargeModeEnum.COUNT.getType())
95 95 .setCharge(chargeBO).setFree(freeBO));
96 96 }
97 97  
... ... @@ -144,11 +144,11 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest {
144 144 // 断言:SKU1
145 145 assertThat(resultBO.getItems().get(0))
146 146 .extracting("price", "count","discountPrice" ,"couponPrice", "pointPrice","deliveryPrice","payPrice")
147   - .containsExactly(100, 2, 0, 0, 0, 1500, 1700);
  147 + .containsExactly(100, 2, 0, 0, 0, 500, 700);
148 148 // 断言:SKU2
149 149 assertThat(resultBO.getItems().get(1))
150 150 .extracting("price", "count","discountPrice" ,"couponPrice", "pointPrice","deliveryPrice","payPrice")
151   - .containsExactly(200, 10, 0, 0, 0, 1500, 3500);
  151 + .containsExactly(200, 10, 0, 0, 0, 2500, 4500);
152 152 // 断言:SKU3 未选中
153 153 assertThat(resultBO.getItems().get(2))
154 154 .extracting("price", "count","discountPrice" ,"couponPrice", "pointPrice","deliveryPrice","payPrice")
... ...
yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculatorTest.java
... ... @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.promotion.api.discount.DiscountActivityApi;
5 5 import cn.iocoder.yudao.module.promotion.api.discount.dto.DiscountProductRespDTO;
6 6 import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum;
7 7 import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
  8 +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
8 9 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
9 10 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
10 11 import org.junit.jupiter.api.Test;
... ... @@ -42,6 +43,7 @@ public class TradeDiscountActivityPriceCalculatorTest extends BaseMockitoUnitTes
42 43 new TradePriceCalculateReqBO.Item().setSkuId(20L).setCount(3).setSelected(false) // 匹配活动,但未选中
43 44 ));
44 45 TradePriceCalculateRespBO result = new TradePriceCalculateRespBO()
  46 + .setType(TradeOrderTypeEnum.NORMAL.getType())
45 47 .setPrice(new TradePriceCalculateRespBO.Price())
46 48 .setPromotions(new ArrayList<>())
47 49 .setItems(asList(
... ...
yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculatorTest.java 0 → 100644
  1 +package cn.iocoder.yudao.module.trade.service.price.calculator;
  2 +
  3 +import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest;
  4 +import cn.iocoder.yudao.module.member.api.level.MemberLevelApi;
  5 +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO;
  6 +import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
  7 +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
  8 +import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
  9 +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
  10 +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
  11 +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
  12 +import org.junit.jupiter.api.Test;
  13 +import org.mockito.InjectMocks;
  14 +import org.mockito.Mock;
  15 +
  16 +import java.util.ArrayList;
  17 +
  18 +import static java.util.Arrays.asList;
  19 +import static org.junit.jupiter.api.Assertions.*;
  20 +import static org.mockito.ArgumentMatchers.eq;
  21 +import static org.mockito.Mockito.when;
  22 +
  23 +/**
  24 + * {@link TradeMemberLevelPriceCalculator} 的单元测试类
  25 + *
  26 + * @author 芋道源码
  27 + */
  28 +public class TradeMemberLevelPriceCalculatorTest extends BaseMockitoUnitTest {
  29 +
  30 + @InjectMocks
  31 + private TradeMemberLevelPriceCalculator memberLevelPriceCalculator;
  32 +
  33 + @Mock
  34 + private MemberLevelApi memberLevelApi;
  35 + @Mock
  36 + private MemberUserApi memberUserApi;
  37 +
  38 + @Test
  39 + public void testCalculate() {
  40 + // 准备参数
  41 + TradePriceCalculateReqBO param = new TradePriceCalculateReqBO()
  42 + .setUserId(1024L)
  43 + .setItems(asList(
  44 + new TradePriceCalculateReqBO.Item().setSkuId(10L).setCount(2).setSelected(true), // 匹配活动,且已选中
  45 + new TradePriceCalculateReqBO.Item().setSkuId(20L).setCount(3).setSelected(false) // 匹配活动,但未选中
  46 + ));
  47 + TradePriceCalculateRespBO result = new TradePriceCalculateRespBO()
  48 + .setType(TradeOrderTypeEnum.NORMAL.getType())
  49 + .setPrice(new TradePriceCalculateRespBO.Price())
  50 + .setPromotions(new ArrayList<>())
  51 + .setItems(asList(
  52 + new TradePriceCalculateRespBO.OrderItem().setSkuId(10L).setCount(2).setSelected(true)
  53 + .setPrice(100),
  54 + new TradePriceCalculateRespBO.OrderItem().setSkuId(20L).setCount(3).setSelected(false)
  55 + .setPrice(50)
  56 + ));
  57 + // 保证价格被初始化上
  58 + TradePriceCalculatorHelper.recountPayPrice(result.getItems());
  59 + TradePriceCalculatorHelper.recountAllPrice(result);
  60 +
  61 + // mock 方法(会员等级)
  62 + when(memberUserApi.getUser(eq(1024L))).thenReturn(new MemberUserRespDTO().setLevelId(2048L));
  63 + when(memberLevelApi.getMemberLevel(eq(2048L))).thenReturn(
  64 + new MemberLevelRespDTO().setId(2048L).setName("VIP 会员").setDiscountPercent(60));
  65 +
  66 + // 调用
  67 + memberLevelPriceCalculator.calculate(param, result);
  68 + // 断言:Price 部分
  69 + TradePriceCalculateRespBO.Price price = result.getPrice();
  70 + assertEquals(price.getTotalPrice(), 200);
  71 + assertEquals(price.getDiscountPrice(), 0);
  72 + assertEquals(price.getPointPrice(), 0);
  73 + assertEquals(price.getDeliveryPrice(), 0);
  74 + assertEquals(price.getCouponPrice(), 0);
  75 + assertEquals(price.getVipPrice(), 80);
  76 + assertEquals(price.getPayPrice(), 120);
  77 + assertNull(result.getCouponId());
  78 + // 断言:SKU 1
  79 + assertEquals(result.getItems().size(), 2);
  80 + TradePriceCalculateRespBO.OrderItem orderItem01 = result.getItems().get(0);
  81 + assertEquals(orderItem01.getSkuId(), 10L);
  82 + assertEquals(orderItem01.getCount(), 2);
  83 + assertEquals(orderItem01.getPrice(), 100);
  84 + assertEquals(orderItem01.getDiscountPrice(), 0);
  85 + assertEquals(orderItem01.getDeliveryPrice(), 0);
  86 + assertEquals(orderItem01.getCouponPrice(), 0);
  87 + assertEquals(orderItem01.getPointPrice(), 0);
  88 + assertEquals(orderItem01.getVipPrice(), 80);
  89 + assertEquals(orderItem01.getPayPrice(), 120);
  90 + // 断言:SKU 2
  91 + TradePriceCalculateRespBO.OrderItem orderItem02 = result.getItems().get(1);
  92 + assertEquals(orderItem02.getSkuId(), 20L);
  93 + assertEquals(orderItem02.getCount(), 3);
  94 + assertEquals(orderItem02.getPrice(), 50);
  95 + assertEquals(orderItem02.getDiscountPrice(), 0);
  96 + assertEquals(orderItem02.getDeliveryPrice(), 0);
  97 + assertEquals(orderItem02.getCouponPrice(), 0);
  98 + assertEquals(orderItem02.getPointPrice(), 0);
  99 + assertEquals(orderItem02.getVipPrice(), 60);
  100 + assertEquals(orderItem02.getPayPrice(), 90);
  101 + // 断言:Promotion 部分
  102 + assertEquals(result.getPromotions().size(), 1);
  103 + TradePriceCalculateRespBO.Promotion promotion01 = result.getPromotions().get(0);
  104 + assertEquals(promotion01.getId(), 2048L);
  105 + assertEquals(promotion01.getName(), "VIP 会员");
  106 + assertEquals(promotion01.getType(), PromotionTypeEnum.MEMBER_LEVEL.getType());
  107 + assertEquals(promotion01.getTotalPrice(), 200);
  108 + assertEquals(promotion01.getDiscountPrice(), 80);
  109 + assertTrue(promotion01.getMatch());
  110 + assertEquals(promotion01.getDescription(), "会员等级折扣:省 0.80 元");
  111 + TradePriceCalculateRespBO.PromotionItem promotionItem01 = promotion01.getItems().get(0);
  112 + assertEquals(promotion01.getItems().size(), 1);
  113 + assertEquals(promotionItem01.getSkuId(), 10L);
  114 + assertEquals(promotionItem01.getTotalPrice(), 200);
  115 + assertEquals(promotionItem01.getDiscountPrice(), 80);
  116 + }
  117 +
  118 +}
... ...
yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculatorTest.java
... ... @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.promotion.api.reward.RewardActivityApi;
5 5 import cn.iocoder.yudao.module.promotion.api.reward.dto.RewardActivityMatchRespDTO;
6 6 import cn.iocoder.yudao.module.promotion.enums.common.PromotionConditionTypeEnum;
7 7 import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
  8 +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
8 9 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
9 10 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
10 11 import org.junit.jupiter.api.Test;
... ... @@ -44,6 +45,7 @@ public class TradeRewardActivityPriceCalculatorTest extends BaseMockitoUnitTest
44 45 new TradePriceCalculateReqBO.Item().setSkuId(30L).setCount(4).setSelected(true) // 匹配活动 2
45 46 ));
46 47 TradePriceCalculateRespBO result = new TradePriceCalculateRespBO()
  48 + .setType(TradeOrderTypeEnum.NORMAL.getType())
47 49 .setPrice(new TradePriceCalculateRespBO.Price())
48 50 .setPromotions(new ArrayList<>())
49 51 .setItems(asList(
... ... @@ -157,6 +159,7 @@ public class TradeRewardActivityPriceCalculatorTest extends BaseMockitoUnitTest
157 159 new TradePriceCalculateReqBO.Item().setSkuId(30L).setCount(4).setSelected(true)
158 160 ));
159 161 TradePriceCalculateRespBO result = new TradePriceCalculateRespBO()
  162 + .setType(TradeOrderTypeEnum.NORMAL.getType())
160 163 .setPrice(new TradePriceCalculateRespBO.Price())
161 164 .setPromotions(new ArrayList<>())
162 165 .setItems(asList(
... ...
yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql
... ... @@ -186,6 +186,6 @@ CREATE TABLE IF NOT EXISTS &quot;trade_brokerage_withdraw&quot;
186 186 "updater" varchar DEFAULT '',
187 187 "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
188 188 "deleted" bit NOT NULL DEFAULT FALSE,
189   - "tenant_id" bigint not null default '0',目
  189 + "tenant_id" bigint not null default '0',
190 190 PRIMARY KEY ("id")
191 191 ) COMMENT '佣金提现';
192 192 \ No newline at end of file
... ...
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java
1 1 package cn.iocoder.yudao.module.member.api.level;
2 2  
  3 +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO;
3 4 import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum;
4 5  
5 6 /**
... ... @@ -10,6 +11,14 @@ import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum;
10 11 public interface MemberLevelApi {
11 12  
12 13 /**
  14 + * 获得会员等级
  15 + *
  16 + * @param id 会员等级编号
  17 + * @return 会员等级
  18 + */
  19 + MemberLevelRespDTO getMemberLevel(Long id);
  20 +
  21 + /**
13 22 * 增加会员经验
14 23 *
15 24 * @param userId 会员ID
... ...
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/dto/MemberLevelRespDTO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.member.api.level.dto;
  2 +
  3 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
  4 +import lombok.Data;
  5 +
  6 +/**
  7 + * 会员等级 Resp DTO
  8 + *
  9 + * @author 芋道源码
  10 + */
  11 +@Data
  12 +public class MemberLevelRespDTO {
  13 +
  14 + /**
  15 + * 编号
  16 + */
  17 + private Long id;
  18 + /**
  19 + * 等级名称
  20 + */
  21 + private String name;
  22 + /**
  23 + * 等级
  24 + */
  25 + private Integer level;
  26 + /**
  27 + * 升级经验
  28 + */
  29 + private Integer experience;
  30 + /**
  31 + * 享受折扣
  32 + */
  33 + private Integer discountPercent;
  34 + /**
  35 + * 状态
  36 + *
  37 + * 枚举 {@link CommonStatusEnum}
  38 + */
  39 + private Integer status;
  40 +
  41 +}
... ...
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApi.java
1 1 package cn.iocoder.yudao.module.member.api.point;
2 2  
  3 +import cn.iocoder.yudao.module.member.api.point.dto.MemberPointConfigRespDTO;
3 4 import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum;
4 5  
5 6 import javax.validation.constraints.Min;
... ... @@ -12,6 +13,13 @@ import javax.validation.constraints.Min;
12 13 public interface MemberPointApi {
13 14  
14 15 /**
  16 + * 获得积分配置
  17 + *
  18 + * @return 积分配置
  19 + */
  20 + MemberPointConfigRespDTO getConfig();
  21 +
  22 + /**
15 23 * 增加用户积分
16 24 *
17 25 * @param userId 用户编号
... ...
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/dto/MemberPointConfigRespDTO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.member.api.point.dto;
  2 +
  3 +import lombok.Data;
  4 +
  5 +/**
  6 + * 用户信息 Response DTO
  7 + *
  8 + * @author 芋道源码
  9 + */
  10 +@Data
  11 +public class MemberPointConfigRespDTO {
  12 + /**
  13 + * 积分抵扣开关
  14 + */
  15 + private Boolean tradeDeductEnable;
  16 + /**
  17 + * 积分抵扣,单位:分
  18 + * <p>
  19 + * 1 积分抵扣多少分
  20 + */
  21 + private Integer tradeDeductUnitPrice;
  22 + /**
  23 + * 积分抵扣最大值
  24 + */
  25 + private Integer tradeDeductMaxPrice;
  26 + /**
  27 + * 1 元赠送多少分
  28 + */
  29 + private Integer tradeGivePoint;
  30 +}
... ...
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,5 +35,20 @@ public class MemberUserRespDTO {
33 35 * 手机
34 36 */
35 37 private String mobile;
  38 + /**
  39 + * 创建时间(注册时间)
  40 + */
  41 + private LocalDateTime createTime;
36 42  
  43 + // ========== 其它信息 ==========
  44 +
  45 + /**
  46 + * 会员级别编号
  47 + */
  48 + private Long levelId;
  49 +
  50 + /**
  51 + * 积分
  52 + */
  53 + private Integer point;
37 54 }
... ...
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java
... ... @@ -13,6 +13,7 @@ public interface ErrorCodeConstants {
13 13 ErrorCode USER_NOT_EXISTS = new ErrorCode(1004001000, "用户不存在");
14 14 ErrorCode USER_MOBILE_NOT_EXISTS = new ErrorCode(1004001001, "手机号未注册用户");
15 15 ErrorCode USER_MOBILE_USED = new ErrorCode(1004001002, "修改手机失败,该手机号({})已经被使用");
  16 + ErrorCode USER_POINT_NOT_ENOUGH = new ErrorCode(1004001003, "用户积分余额不足");
16 17  
17 18 // ========== AUTH 模块 1004003000 ==========
18 19 ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1004003000, "登录失败,账号密码不正确");
... ...
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java
... ... @@ -18,8 +18,10 @@ public enum MemberPointBizTypeEnum implements IntArrayValuable {
18 18  
19 19 SIGN(1, "签到", "签到获得 {} 积分", true),
20 20 ORDER_REWARD(10, "订单奖励", "下单获得 {} 积分", true),
21   - ORDER_CANCEL(11, "订单取消", "退单获得 {} 积分", false), // 退回积分
  21 + ORDER_CANCEL(11, "订单取消", "订单取消,退还 {} 积分", true), // 退回积分
22 22 ORDER_USE(12, "订单使用", "下单使用 {} 积分", false), // 扣减积分
  23 + AFTER_SALE_REFUND_USED(13, "订单退款", "订单退款,退还 {} 积分", true), // 退回积分
  24 + AFTER_SALE_DEDUCT_GIVE(14, "订单退款", "订单退款,扣除赠送的 {} 积分", false), // 扣减积分
23 25 ;
24 26  
25 27 /**
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java
1 1 package cn.iocoder.yudao.module.member.api.level;
2 2  
  3 +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO;
  4 +import cn.iocoder.yudao.module.member.convert.level.MemberLevelConvert;
3 5 import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum;
4 6 import cn.iocoder.yudao.module.member.service.level.MemberLevelService;
5 7 import org.springframework.stereotype.Service;
... ... @@ -23,6 +25,11 @@ public class MemberLevelApiImpl implements MemberLevelApi {
23 25 private MemberLevelService memberLevelService;
24 26  
25 27 @Override
  28 + public MemberLevelRespDTO getMemberLevel(Long id) {
  29 + return MemberLevelConvert.INSTANCE.convert02(memberLevelService.getLevel(id));
  30 + }
  31 +
  32 + @Override
26 33 public void addExperience(Long userId, Integer experience, Integer bizType, String bizId) {
27 34 MemberExperienceBizTypeEnum bizTypeEnum = MemberExperienceBizTypeEnum.getByType(bizType);
28 35 if (bizTypeEnum == null) {
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApiImpl.java
1 1 package cn.iocoder.yudao.module.member.api.point;
2 2  
  3 +import cn.hutool.core.lang.Assert;
  4 +import cn.iocoder.yudao.module.member.api.point.dto.MemberPointConfigRespDTO;
  5 +import cn.iocoder.yudao.module.member.convert.point.MemberPointConfigConvert;
3 6 import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum;
  7 +import cn.iocoder.yudao.module.member.service.point.MemberPointConfigService;
4 8 import cn.iocoder.yudao.module.member.service.point.MemberPointRecordService;
5 9 import org.springframework.stereotype.Service;
6 10 import org.springframework.validation.annotation.Validated;
... ... @@ -21,9 +25,17 @@ public class MemberPointApiImpl implements MemberPointApi {
21 25  
22 26 @Resource
23 27 private MemberPointRecordService memberPointRecordService;
  28 + @Resource
  29 + private MemberPointConfigService memberPointConfigService;
  30 +
  31 + @Override
  32 + public MemberPointConfigRespDTO getConfig() {
  33 + return MemberPointConfigConvert.INSTANCE.convert01(memberPointConfigService.getPointConfig());
  34 + }
24 35  
25 36 @Override
26 37 public void addPoint(Long userId, Integer point, Integer bizType, String bizId) {
  38 + Assert.isTrue(point > 0);
27 39 MemberPointBizTypeEnum bizTypeEnum = MemberPointBizTypeEnum.getByType(bizType);
28 40 if (bizTypeEnum == null) {
29 41 throw exception(POINT_RECORD_BIZ_NOT_SUPPORT);
... ... @@ -33,11 +45,12 @@ public class MemberPointApiImpl implements MemberPointApi {
33 45  
34 46 @Override
35 47 public void reducePoint(Long userId, Integer point, Integer bizType, String bizId) {
  48 + Assert.isTrue(point > 0);
36 49 MemberPointBizTypeEnum bizTypeEnum = MemberPointBizTypeEnum.getByType(bizType);
37 50 if (bizTypeEnum == null) {
38 51 throw exception(POINT_RECORD_BIZ_NOT_SUPPORT);
39 52 }
40   - memberPointRecordService.createPointRecord(userId, point, bizTypeEnum, bizId);
  53 + memberPointRecordService.createPointRecord(userId, -point, bizTypeEnum, bizId);
41 54 }
42 55  
43 56 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelConvert.java
1 1 package cn.iocoder.yudao.module.member.convert.level;
2 2  
  3 +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO;
3 4 import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelCreateReqVO;
4 5 import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelRespVO;
5 6 import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelSimpleRespVO;
... ... @@ -33,4 +34,6 @@ public interface MemberLevelConvert {
33 34  
34 35 List<AppMemberLevelRespVO> convertList02(List<MemberLevelDO> list);
35 36  
  37 + MemberLevelRespDTO convert02(MemberLevelDO bean);
  38 +
36 39 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/point/MemberPointConfigConvert.java
1 1 package cn.iocoder.yudao.module.member.convert.point;
2 2  
  3 +import cn.iocoder.yudao.module.member.api.point.dto.MemberPointConfigRespDTO;
3 4 import cn.iocoder.yudao.module.member.controller.admin.point.vo.config.MemberPointConfigRespVO;
4 5 import cn.iocoder.yudao.module.member.controller.admin.point.vo.config.MemberPointConfigSaveReqVO;
5 6 import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointConfigDO;
... ... @@ -20,4 +21,5 @@ public interface MemberPointConfigConvert {
20 21  
21 22 MemberPointConfigDO convert(MemberPointConfigSaveReqVO bean);
22 23  
  24 + MemberPointConfigRespDTO convert01(MemberPointConfigDO pointConfig);
23 25 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java
1 1 package cn.iocoder.yudao.module.member.dal.mysql.user;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.lang.Assert;
4 5 import cn.hutool.core.util.StrUtil;
5 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 7 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
7 8 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
8 9 import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserPageReqVO;
9 10 import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
  11 +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
10 12 import org.apache.ibatis.annotations.Mapper;
11 13  
12 14 import java.util.List;
... ... @@ -62,4 +64,33 @@ public interface MemberUserMapper extends BaseMapperX&lt;MemberUserDO&gt; {
62 64 .apply("FIND_IN_SET({0}, tag_ids)", tagId));
63 65 }
64 66  
  67 + /**
  68 + * 更新用户积分(增加)
  69 + *
  70 + * @param id 用户编号
  71 + * @param incrCount 增加积分(正数)
  72 + */
  73 + default void updatePointIncr(Long id, Integer incrCount) {
  74 + Assert.isTrue(incrCount > 0);
  75 + LambdaUpdateWrapper<MemberUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<MemberUserDO>()
  76 + .setSql(" point = point + " + incrCount)
  77 + .eq(MemberUserDO::getId, id);
  78 + update(null, lambdaUpdateWrapper);
  79 + }
  80 +
  81 + /**
  82 + * 更新用户积分(减少)
  83 + *
  84 + * @param id 用户编号
  85 + * @param incrCount 增加积分(负数)
  86 + * @return 更新行数
  87 + */
  88 + default int updatePointDecr(Long id, Integer incrCount) {
  89 + Assert.isTrue(incrCount < 0);
  90 + LambdaUpdateWrapper<MemberUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<MemberUserDO>()
  91 + .setSql(" point = point + " + incrCount) // 负数,所以使用 + 号
  92 + .eq(MemberUserDO::getId, id);
  93 + return update(null, lambdaUpdateWrapper);
  94 + }
  95 +
65 96 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java
... ... @@ -5,7 +5,6 @@ import cn.hutool.core.util.StrUtil;
5 5 import cn.iocoder.yudao.framework.common.pojo.PageParam;
6 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
7 7 import cn.iocoder.yudao.module.member.controller.admin.point.vo.recrod.MemberPointRecordPageReqVO;
8   -import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointConfigDO;
9 8 import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointRecordDO;
10 9 import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
11 10 import cn.iocoder.yudao.module.member.dal.mysql.point.MemberPointRecordMapper;
... ... @@ -14,6 +13,7 @@ import cn.iocoder.yudao.module.member.service.user.MemberUserService;
14 13 import lombok.extern.slf4j.Slf4j;
15 14 import org.apache.commons.lang3.StringUtils;
16 15 import org.springframework.stereotype.Service;
  16 +import org.springframework.transaction.annotation.Transactional;
17 17 import org.springframework.util.CollectionUtils;
18 18 import org.springframework.validation.annotation.Validated;
19 19  
... ... @@ -21,7 +21,9 @@ import javax.annotation.Resource;
21 21 import java.util.List;
22 22 import java.util.Set;
23 23  
  24 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
24 25 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
  26 +import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.USER_POINT_NOT_ENOUGH;
25 27  
26 28  
27 29 /**
... ... @@ -36,8 +38,6 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService {
36 38  
37 39 @Resource
38 40 private MemberPointRecordMapper memberPointRecordMapper;
39   - @Resource
40   - private MemberPointConfigService memberPointConfigService;
41 41  
42 42 @Resource
43 43 private MemberUserService memberUserService;
... ... @@ -64,32 +64,28 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService {
64 64 }
65 65  
66 66 @Override
  67 + @Transactional(rollbackFor = Exception.class)
67 68 public void createPointRecord(Long userId, Integer point, MemberPointBizTypeEnum bizType, String bizId) {
68   - MemberPointConfigDO pointConfig = memberPointConfigService.getPointConfig();
69   - if (pointConfig == null || pointConfig.getTradeGivePoint() == null) {
70   - log.error("[createPointRecord][增加积分失败:tradeGivePoint 未配置,userId({}) point({}) bizType({}) bizId({})]",
71   - userId, point, bizType.getType(), bizId);
72   - return;
  69 + // 1. 校验用户积分余额
  70 + MemberUserDO user = memberUserService.getUser(userId);
  71 + Integer userPoint = ObjectUtil.defaultIfNull(user.getPoint(), 0);
  72 + int totalPoint = userPoint + point; // 用户变动后的积分
  73 + if (totalPoint < 0) {
  74 + throw exception(USER_POINT_NOT_ENOUGH);
73 75 }
74 76  
75   - // 1. 根据配置的比例,换算实际的积分
76   - point = point * pointConfig.getTradeGivePoint();
77   - if (!bizType.isAdd() && point > 0) {
78   - point = -point;
  77 + // 2. 更新用户积分
  78 + boolean success = memberUserService.updateUserPoint(userId, point);
  79 + if (!success) {
  80 + throw exception(USER_POINT_NOT_ENOUGH);
79 81 }
80 82  
81   - // 2. 增加积分记录
82   - MemberUserDO user = memberUserService.getUser(userId);
83   - Integer userPoint = ObjectUtil.defaultIfNull(user.getPoint(), 0);
84   - Integer totalPoint = userPoint + point; // 用户变动后的积分
  83 + // 3. 增加积分记录
85 84 MemberPointRecordDO record = new MemberPointRecordDO()
86 85 .setUserId(userId).setBizId(bizId).setBizType(bizType.getType())
87 86 .setTitle(bizType.getName()).setDescription(StrUtil.format(bizType.getDescription(), point))
88 87 .setPoint(point).setTotalPoint(totalPoint);
89 88 memberPointRecordMapper.insert(record);
90   -
91   - // 3. 更新用户积分
92   - memberUserService.updateUserPoint(userId, totalPoint);
93 89 }
94 90  
95 91 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java
... ... @@ -164,6 +164,7 @@ public interface MemberUserService {
164 164 *
165 165 * @param userId 用户编号
166 166 * @param point 积分数量
  167 + * @return 更新结果
167 168 */
168   - void updateUserPoint(Long userId, Integer point);
  169 + boolean updateUserPoint(Long userId, Integer point);
169 170 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java
... ... @@ -260,8 +260,13 @@ public class MemberUserServiceImpl implements MemberUserService {
260 260 }
261 261  
262 262 @Override
263   - public void updateUserPoint(Long userId, Integer point) {
264   - memberUserMapper.updateById(new MemberUserDO().setId(userId).setPoint(point));
  263 + public boolean updateUserPoint(Long id, Integer point) {
  264 + if (point > 0) {
  265 + memberUserMapper.updatePointIncr(id, point);
  266 + } else if (point < 0) {
  267 + return memberUserMapper.updatePointDecr(id, point) > 0;
  268 + }
  269 + return true;
265 270 }
266 271  
267 272 }
... ...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApi.java
... ... @@ -17,14 +17,14 @@ public interface DictDataApi {
17 17 * 2. 字典数据被禁用
18 18 *
19 19 * @param dictType 字典类型
20   - * @param values 字典数据值的数组
  20 + * @param values 字典数据值的数组
21 21 */
22 22 void validateDictDataList(String dictType, Collection<String> values);
23 23  
24 24 /**
25 25 * 获得指定的字典数据,从缓存中
26 26 *
27   - * @param type 字典类型
  27 + * @param type 字典类型
28 28 * @param value 字典数据值
29 29 * @return 字典数据
30 30 */
... ... @@ -33,7 +33,7 @@ public interface DictDataApi {
33 33 /**
34 34 * 解析获得指定的字典数据,从缓存中
35 35 *
36   - * @param type 字典类型
  36 + * @param type 字典类型
37 37 * @param label 字典数据标签
38 38 * @return 字典数据
39 39 */
... ...
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 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  4 +import cn.iocoder.yudao.module.system.controller.app.dict.vo.AppDictDataRespVO;
  5 +import cn.iocoder.yudao.module.system.convert.dict.DictDataConvert;
  6 +import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
  7 +import cn.iocoder.yudao.module.system.service.dict.DictDataService;
  8 +import io.swagger.v3.oas.annotations.Operation;
  9 +import io.swagger.v3.oas.annotations.Parameter;
  10 +import io.swagger.v3.oas.annotations.tags.Tag;
  11 +import org.springframework.validation.annotation.Validated;
  12 +import org.springframework.web.bind.annotation.GetMapping;
  13 +import org.springframework.web.bind.annotation.RequestMapping;
  14 +import org.springframework.web.bind.annotation.RequestParam;
  15 +import org.springframework.web.bind.annotation.RestController;
  16 +
  17 +import javax.annotation.Resource;
  18 +import java.util.List;
  19 +
  20 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  21 +
  22 +@Tag(name = "用户 App - 字典数据")
  23 +@RestController
  24 +@RequestMapping("/system/dict-data")
  25 +@Validated
3 26 public class AppDictDataController {
  27 +
  28 + @Resource
  29 + private DictDataService dictDataService;
  30 +
  31 + @GetMapping("/type")
  32 + @Operation(summary = "根据字典类型查询字典数据信息")
  33 + @Parameter(name = "type", description = "字典类型", required = true, example = "common_status")
  34 + public CommonResult<List<AppDictDataRespVO>> getDictDataListByType(@RequestParam("type") String type) {
  35 + List<DictDataDO> list = dictDataService.getEnabledDictDataListByType(type);
  36 + return success(DictDataConvert.INSTANCE.convertList03(list));
  37 + }
  38 +
4 39 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.system.controller.app.dict.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Data;
  6 +import lombok.NoArgsConstructor;
  7 +
  8 +import javax.validation.constraints.NotBlank;
  9 +import javax.validation.constraints.Size;
  10 +
  11 +@Schema(description = "用户 App - 字典数据信息 Response VO")
  12 +@Data
  13 +@NoArgsConstructor
  14 +@AllArgsConstructor
  15 +public class AppDictDataRespVO {
  16 +
  17 + @Schema(description = "字典数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
  18 + private Long id;
  19 +
  20 + @Schema(description = "字典标签", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
  21 + private String label;
  22 +
  23 + @Schema(description = "字典值", requiredMode = Schema.RequiredMode.REQUIRED, example = "iocoder")
  24 + private String value;
  25 +
  26 + @Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex")
  27 + private String dictType;
  28 +
  29 +}
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java
... ... @@ -3,11 +3,11 @@ package cn.iocoder.yudao.module.system.convert.dict;
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 4 import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO;
5 5 import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.*;
  6 +import cn.iocoder.yudao.module.system.controller.app.dict.vo.AppDictDataRespVO;
6 7 import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
7 8 import org.mapstruct.Mapper;
8 9 import org.mapstruct.factory.Mappers;
9 10  
10   -import java.util.Collection;
11 11 import java.util.List;
12 12  
13 13 @Mapper
... ... @@ -29,4 +29,7 @@ public interface DictDataConvert {
29 29  
30 30 DictDataRespDTO convert02(DictDataDO bean);
31 31  
  32 + List<AppDictDataRespVO> convertList03(List<DictDataDO> list);
  33 +
  34 + List<DictDataRespDTO> convertList04(List<DictDataDO> list);
32 35 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java
... ... @@ -48,4 +48,10 @@ 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)
  54 + .eq(DictDataDO::getStatus, status));
  55 + }
  56 +
51 57 }
... ...
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
... ... @@ -49,7 +49,7 @@ public class DictDataServiceImpl implements DictDataService {
49 49  
50 50 @Override
51 51 public List<DictDataDO> getDictDataList() {
52   - List<DictDataDO> list = dictDataMapper.selectList();
  52 + List<DictDataDO> list = dictDataMapper.selectList(DictDataDO::getStatus, CommonStatusEnum.ENABLE.getStatus());
53 53 list.sort(COMPARATOR_TYPE_AND_SORT);
54 54 return list;
55 55 }
... ... @@ -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 }
... ...
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImplTest.java
... ... @@ -43,10 +43,15 @@ public class DictDataServiceImplTest extends BaseDbUnitTest {
43 43 @Test
44 44 public void testGetDictDataList() {
45 45 // mock 数据
46   - DictDataDO dictDataDO01 = randomDictDataDO().setDictType("yunai").setSort(2);
  46 + DictDataDO dictDataDO01 = randomDictDataDO().setDictType("yunai").setSort(2)
  47 + .setStatus(CommonStatusEnum.ENABLE.getStatus());
47 48 dictDataMapper.insert(dictDataDO01);
48   - DictDataDO dictDataDO02 = randomDictDataDO().setDictType("yunai").setSort(1);
  49 + DictDataDO dictDataDO02 = randomDictDataDO().setDictType("yunai").setSort(1)
  50 + .setStatus(CommonStatusEnum.ENABLE.getStatus());
49 51 dictDataMapper.insert(dictDataDO02);
  52 + DictDataDO dictDataDO03 = randomDictDataDO().setDictType("yunai").setSort(3)
  53 + .setStatus(CommonStatusEnum.DISABLE.getStatus());
  54 + dictDataMapper.insert(dictDataDO03);
50 55 // 准备参数
51 56  
52 57 // 调用
... ...