Commit 565a8e0e6bfd8b50d12fcd404f4075d2ac926a1b

Authored by owen
2 parents be426235 b9018baa

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

Showing 23 changed files with 552 additions and 69 deletions
yudao-module-mall/pom.xml
... ... @@ -15,7 +15,7 @@
15 15 <name>${project.artifactId}</name>
16 16  
17 17 <description>
18   - 商城大模块,由 product 商品、promotion 营销、trade 交易等组成
  18 + 商城大模块,由 product 商品、promotion 营销、trade 交易、statistics 统计等组成
19 19 </description>
20 20 <modules>
21 21 <module>yudao-module-promotion-api</module>
... ... @@ -24,6 +24,8 @@
24 24 <module>yudao-module-product-biz</module>
25 25 <module>yudao-module-trade-api</module>
26 26 <module>yudao-module-trade-biz</module>
  27 + <module>yudao-module-statistics-api</module>
  28 + <module>yudao-module-statistics-biz</module>
27 29 </modules>
28 30  
29 31 </project>
... ...
yudao-module-mall/yudao-module-statistics-api/pom.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns="http://maven.apache.org/POM/4.0.0"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5 + <parent>
  6 + <groupId>cn.iocoder.boot</groupId>
  7 + <artifactId>yudao-module-mall</artifactId>
  8 + <version>${revision}</version>
  9 + </parent>
  10 + <modelVersion>4.0.0</modelVersion>
  11 + <artifactId>yudao-module-statistics-api</artifactId>
  12 + <packaging>jar</packaging>
  13 +
  14 + <name>${project.artifactId}</name>
  15 + <description>
  16 + statistics 模块 API,暴露给其它模块调用
  17 + </description>
  18 +
  19 + <dependencies>
  20 + <dependency>
  21 + <groupId>cn.iocoder.boot</groupId>
  22 + <artifactId>yudao-common</artifactId>
  23 + </dependency>
  24 +
  25 + <!-- 参数校验 -->
  26 + <dependency>
  27 + <groupId>org.springframework.boot</groupId>
  28 + <artifactId>spring-boot-starter-validation</artifactId>
  29 + <optional>true</optional>
  30 + </dependency>
  31 + </dependencies>
  32 +
  33 +</project>
... ...
yudao-module-mall/yudao-module-statistics-api/src/main/java/cn/iocoder/yudao/module/statistics/api/package-info.java 0 → 100644
  1 +/**
  2 + * TODO 占位,无特殊含义
  3 + */
  4 +package cn.iocoder.yudao.module.statistics.api;
... ...
yudao-module-mall/yudao-module-statistics-api/src/main/java/cn/iocoder/yudao/module/statistics/enums/package-info.java 0 → 100644
  1 +/**
  2 + * TODO 占位,无特殊含义
  3 + */
  4 +package cn.iocoder.yudao.module.statistics.enums;
... ...
yudao-module-mall/yudao-module-statistics-biz/pom.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns="http://maven.apache.org/POM/4.0.0"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5 + <parent>
  6 + <groupId>cn.iocoder.boot</groupId>
  7 + <artifactId>yudao-module-mall</artifactId>
  8 + <version>${revision}</version>
  9 + </parent>
  10 + <modelVersion>4.0.0</modelVersion>
  11 + <artifactId>yudao-module-statistics-biz</artifactId>
  12 + <packaging>jar</packaging>
  13 +
  14 + <name>${project.artifactId}</name>
  15 + <description>
  16 + statistics 模块,主要实现统计相关功能
  17 + 例如:统计商品、会员、交易等功能。
  18 + </description>
  19 +
  20 + <dependencies>
  21 + <dependency>
  22 + <groupId>cn.iocoder.boot</groupId>
  23 + <artifactId>yudao-module-statistics-api</artifactId>
  24 + <version>${revision}</version>
  25 + </dependency>
  26 + <dependency>
  27 + <groupId>cn.iocoder.boot</groupId>
  28 + <artifactId>yudao-module-promotion-api</artifactId>
  29 + <version>${revision}</version>
  30 + </dependency>
  31 + <dependency>
  32 + <groupId>cn.iocoder.boot</groupId>
  33 + <artifactId>yudao-module-product-api</artifactId>
  34 + <version>${revision}</version>
  35 + </dependency>
  36 + <dependency>
  37 + <groupId>cn.iocoder.boot</groupId>
  38 + <artifactId>yudao-module-trade-api</artifactId>
  39 + <version>${revision}</version>
  40 + </dependency>
  41 + <dependency>
  42 + <groupId>cn.iocoder.boot</groupId>
  43 + <artifactId>yudao-module-member-api</artifactId>
  44 + <version>${revision}</version>
  45 + </dependency>
  46 +
  47 + <!-- 业务组件 -->
  48 + <dependency>
  49 + <groupId>cn.iocoder.boot</groupId>
  50 + <artifactId>yudao-spring-boot-starter-biz-operatelog</artifactId>
  51 + </dependency>
  52 +
  53 + <!-- Web 相关 -->
  54 + <dependency>
  55 + <groupId>cn.iocoder.boot</groupId>
  56 + <artifactId>yudao-spring-boot-starter-web</artifactId>
  57 + </dependency>
  58 + <dependency>
  59 + <groupId>cn.iocoder.boot</groupId>
  60 + <artifactId>yudao-spring-boot-starter-security</artifactId>
  61 + </dependency>
  62 +
  63 + <!-- DB 相关 -->
  64 + <dependency>
  65 + <groupId>cn.iocoder.boot</groupId>
  66 + <artifactId>yudao-spring-boot-starter-mybatis</artifactId>
  67 + </dependency>
  68 +
  69 + <!-- Test 测试相关 -->
  70 + <dependency>
  71 + <groupId>cn.iocoder.boot</groupId>
  72 + <artifactId>yudao-spring-boot-starter-test</artifactId>
  73 + </dependency>
  74 +
  75 + <!-- 工具类相关 -->
  76 + <dependency>
  77 + <groupId>cn.iocoder.boot</groupId>
  78 + <artifactId>yudao-spring-boot-starter-excel</artifactId>
  79 + </dependency>
  80 + <dependency>
  81 + <groupId>cn.iocoder.boot</groupId>
  82 + <artifactId>yudao-spring-boot-starter-biz-dict</artifactId>
  83 + </dependency>
  84 + </dependencies>
  85 +
  86 +</project>
... ...
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/member/package-info.java 0 → 100644
  1 +/**
  2 + * TODO
  3 + * 1. 会员总数据
  4 + * 2. 性别统计
  5 + * 3. 渠道统计
  6 + * 4. 地域统计
  7 + * 5. 会员概览
  8 + */
  9 +package cn.iocoder.yudao.module.statistics.controller.member;
... ...
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/package-info.java 0 → 100644
  1 +package cn.iocoder.yudao.module.statistics.controller;
... ...
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/product/ProductStatisticsController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.statistics.controller.product;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  4 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  5 +import cn.iocoder.yudao.module.statistics.dal.mysql.product.ProductSpuStatisticsDO;
  6 +import cn.iocoder.yudao.module.statistics.dal.mysql.product.ProductStatisticsDO;
  7 +import io.swagger.v3.oas.annotations.tags.Tag;
  8 +import lombok.extern.slf4j.Slf4j;
  9 +import org.springframework.validation.annotation.Validated;
  10 +import org.springframework.web.bind.annotation.RequestMapping;
  11 +import org.springframework.web.bind.annotation.RestController;
  12 +
  13 +import java.time.LocalDateTime;
  14 +import java.util.List;
  15 +
  16 +@Tag(name = "管理后台 - 商品统计")
  17 +@RestController
  18 +@RequestMapping("/statistics/product")
  19 +@Validated
  20 +@Slf4j
  21 +public class ProductStatisticsController {
  22 +
  23 + // TODO @麦子:返回 ProductStatisticsComparisonResp, 里面有两个字段,一个是选择的时间范围的合计结果,一个是对比的时间范围的合计结果;
  24 + // 例如说,选择时间范围是 2023-10-01 ~ 2023-10-02,那么对比就是 2023-09-30,再倒推 2 天;
  25 + public CommonResult<Object> getProductStatisticsComparison() {
  26 + return null;
  27 + }
  28 +
  29 + // TODO @麦子:查询指定时间范围内的商品统计数据;DO 到时需要改成 VO 哈
  30 + public CommonResult<List<ProductStatisticsDO>> getProductStatisticsList(
  31 + LocalDateTime[] times) {
  32 + return null;
  33 + }
  34 +
  35 + // TODO @麦子:查询指定时间范围内的商品 SPU 统计数据;DO 到时需要改成 VO 哈
  36 + // 入参是分页参数 + 时间范围 + 排序字段
  37 + public CommonResult<PageResult<ProductSpuStatisticsDO>> getProductSpuStatisticsPage() {
  38 + return null;
  39 + }
  40 +
  41 +}
... ...
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/trade/TradeStatisticsController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.statistics.controller.trade;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  4 +import cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeStatisticsDO;
  5 +import io.swagger.v3.oas.annotations.tags.Tag;
  6 +import lombok.extern.slf4j.Slf4j;
  7 +import org.springframework.validation.annotation.Validated;
  8 +import org.springframework.web.bind.annotation.RequestMapping;
  9 +import org.springframework.web.bind.annotation.RestController;
  10 +
  11 +import java.time.LocalDateTime;
  12 +import java.util.List;
  13 +
  14 +@Tag(name = "管理后台 - 交易统计")
  15 +@RestController
  16 +@RequestMapping("/statistics/product")
  17 +@Validated
  18 +@Slf4j
  19 +public class TradeStatisticsController {
  20 +
  21 + // TODO @疯狂:有个 summary 接口,返回昨日、本月、支付金额、本月订单金额等数据;具体看 ui 哈;
  22 +
  23 + // TODO @疯狂:返回 ProductStatisticsComparisonResp, 里面有两个字段,一个是选择的时间范围的合计结果,一个是对比的时间范围的合计结果;
  24 + // 例如说,选择时间范围是 2023-10-01 ~ 2023-10-02,那么对比就是 2023-09-30,再倒推 2 天;
  25 + public CommonResult<Object> getTradeStatisticsComparison() {
  26 + return null;
  27 + }
  28 +
  29 + // TODO @疯狂:查询指定时间范围内的交易统计数据;DO 到时需要改成 VO 哈
  30 + // 总收入(营业额)= 订单、充值的支付 - 订单、充值的退款
  31 + public CommonResult<List<TradeStatisticsDO>> getTradeStatisticsList(
  32 + LocalDateTime[] times) {
  33 + return null;
  34 + }
  35 +
  36 +}
... ...
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/dataobject/package-info.java 0 → 100644
  1 +/**
  2 + * 占位 todo
  3 + */
  4 +package cn.iocoder.yudao.module.statistics.dal.dataobject;
... ...
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/product/ProductSpuStatisticsDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.statistics.dal.mysql.product;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import com.baomidou.mybatisplus.annotation.KeySequence;
  5 +import com.baomidou.mybatisplus.annotation.TableId;
  6 +import com.baomidou.mybatisplus.annotation.TableName;
  7 +import lombok.*;
  8 +
  9 +import java.time.LocalDateTime;
  10 +
  11 +/**
  12 + * 商品 SPU 统计 DO
  13 + *
  14 + * 以天为维度,统计商品 SPU 的数据
  15 + *
  16 + * @author 芋道源码
  17 + */
  18 +@TableName("product_spu_statistics")
  19 +@KeySequence("product_spu_statistics_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  20 +@Data
  21 +@EqualsAndHashCode(callSuper = true)
  22 +@ToString(callSuper = true)
  23 +@Builder
  24 +@NoArgsConstructor
  25 +@AllArgsConstructor
  26 +public class ProductSpuStatisticsDO extends BaseDO {
  27 +
  28 + /**
  29 + * 编号,主键自增
  30 + */
  31 + @TableId
  32 + private Long id;
  33 +
  34 + /**
  35 + * 商品 SPU 编号
  36 + *
  37 + * 关联 ProductSpuDO 的 id 字段
  38 + */
  39 + private Long spuId;
  40 + /**
  41 + * 统计日期
  42 + */
  43 + private LocalDateTime time;
  44 +
  45 + /**
  46 + * 浏览量
  47 + */
  48 + private Integer browseCount;
  49 + /**
  50 + * 收藏量
  51 + */
  52 + private Integer favoriteCount;
  53 +
  54 + /**
  55 + * 添加购物车次数
  56 + *
  57 + * 以商品被添加到购物车的 createTime 计算,后续多次添加,不会增加该值。
  58 + * 直到该次被下单、或者被删除,后续再次被添加到购物车。
  59 + */
  60 + private Integer addCartCount;
  61 + /**
  62 + * 创建订单商品数
  63 + */
  64 + private Integer createOrderCount;
  65 + /**
  66 + * 支付订单商品数
  67 + */
  68 + private Integer payOrderCount;
  69 + /**
  70 + * 总支付金额,单位:分
  71 + */
  72 + private Integer payPrice;
  73 +
  74 +}
... ...
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/product/ProductStatisticsDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.statistics.dal.mysql.product;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import com.baomidou.mybatisplus.annotation.KeySequence;
  5 +import com.baomidou.mybatisplus.annotation.TableId;
  6 +import com.baomidou.mybatisplus.annotation.TableName;
  7 +import lombok.*;
  8 +
  9 +import java.time.LocalDateTime;
  10 +
  11 +/**
  12 + * 商品统计 DO
  13 + *
  14 + * 以天为维度,统计全部的数据
  15 + *
  16 + * 和 {@link ProductSpuStatisticsDO} 的差异是,它是全局的统计
  17 + *
  18 + * @author 芋道源码
  19 + */
  20 +@TableName("product_spu_statistics")
  21 +@KeySequence("product_spu_statistics_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  22 +@Data
  23 +@EqualsAndHashCode(callSuper = true)
  24 +@ToString(callSuper = true)
  25 +@Builder
  26 +@NoArgsConstructor
  27 +@AllArgsConstructor
  28 +public class ProductStatisticsDO extends BaseDO {
  29 +
  30 + /**
  31 + * 编号,主键自增
  32 + */
  33 + @TableId
  34 + private Long id;
  35 +
  36 + /**
  37 + * 统计日期
  38 + */
  39 + private LocalDateTime time;
  40 +
  41 + /**
  42 + * 浏览量
  43 + */
  44 + private Integer browseCount;
  45 + /**
  46 + * 收藏量
  47 + */
  48 + private Integer favoriteCount;
  49 +
  50 + /**
  51 + * 添加购物车次数
  52 + *
  53 + * 以商品被添加到购物车的 createTime 计算,后续多次添加,不会增加该值。
  54 + * 直到该次被下单、或者被删除,后续再次被添加到购物车。
  55 + */
  56 + private Integer addCartCount;
  57 + /**
  58 + * 创建订单商品数
  59 + */
  60 + private Integer createOrderCount;
  61 + /**
  62 + * 支付订单商品数
  63 + */
  64 + private Integer payOrderCount;
  65 + /**
  66 + * 总支付金额,单位:分
  67 + */
  68 + private Integer payPrice;
  69 +
  70 +}
... ...
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/TradeStatisticsDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.statistics.dal.mysql.trade;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import com.baomidou.mybatisplus.annotation.KeySequence;
  5 +import com.baomidou.mybatisplus.annotation.TableId;
  6 +import com.baomidou.mybatisplus.annotation.TableName;
  7 +import lombok.*;
  8 +
  9 +import java.time.LocalDateTime;
  10 +
  11 +/**
  12 + * 交易统计 DO
  13 + *
  14 + * 以天为维度,统计全部的数据
  15 + *
  16 + * @author 芋道源码
  17 + */
  18 +@TableName("trade_statistics")
  19 +@KeySequence("trade_statistics_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  20 +@Data
  21 +@EqualsAndHashCode(callSuper = true)
  22 +@ToString(callSuper = true)
  23 +@Builder
  24 +@NoArgsConstructor
  25 +@AllArgsConstructor
  26 +public class TradeStatisticsDO extends BaseDO {
  27 +
  28 + /**
  29 + * 编号,主键自增
  30 + */
  31 + @TableId
  32 + private Long id;
  33 +
  34 + /**
  35 + * 统计日期
  36 + */
  37 + private LocalDateTime time;
  38 +
  39 + /**
  40 + * 创建订单数
  41 + */
  42 + private Integer orderCreateCount;
  43 + /**
  44 + * 支付订单商品数
  45 + */
  46 + private Integer orderPayCount;
  47 + /**
  48 + * 总支付金额,单位:分
  49 + */
  50 + private Integer orderPayPrice;
  51 + /**
  52 + * 总支付金额(余额),单位:分
  53 + */
  54 + private Integer orderWalletPayPrice;
  55 +
  56 + /**
  57 + * 退款订单数
  58 + */
  59 + private Integer afterSaleCount;
  60 + /**
  61 + * 总退款金额,单位:分
  62 + */
  63 + private Integer afterSaleRefundPrice;
  64 +
  65 + /**
  66 + * 佣金金额(已结算),单位:分
  67 + */
  68 + private Integer brokerageSettlementPrice;
  69 +
  70 + /**
  71 + * 充值订单数
  72 + *
  73 + * 从 PayWalletRechargeDO 计算
  74 + */
  75 + private Integer rechargePayCount;
  76 + /**
  77 + * 充值金额,单位:分
  78 + */
  79 + private Integer rechargePayPrice;
  80 + /**
  81 + * 充值退款订单数
  82 + */
  83 + private Integer rechargeRefundCount;
  84 + /**
  85 + * 充值退款金额,单位:分
  86 + */
  87 + private Integer rechargeRefundPrice;
  88 +
  89 +}
... ...
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/job/package-info.java 0 → 100644
  1 +/**
  2 + * TODO 芋艿,占坑,无特殊含义
  3 + */
  4 +package cn.iocoder.yudao.module.statistics.job;
... ...
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/package-info.java 0 → 100644
  1 +/**
  2 + * statistics 模块,主要实现统计相关功能。
  3 + * 例如:统计商品、会员、交易等功能。
  4 + *
  5 + * 1. Controller URL:以 /statistics/ 开头,避免和其它 Module 冲突
  6 + * 2. DataObject 表名:以 statistics_ 为后缀,方便在数据库中区分【特殊】
  7 + */
  8 +package cn.iocoder.yudao.module.statistics;
... ...
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java
... ... @@ -29,8 +29,8 @@ public interface ErrorCodeConstants {
29 29 ErrorCode ORDER_DELIVERY_FAIL_DELIVERY_TYPE_NOT_EXPRESS = new ErrorCode(1011000024, "交易订单发货失败,发货类型不是快递");
30 30 ErrorCode ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID = new ErrorCode(1011000025, "交易订单取消失败,订单不是【待支付】状态");
31 31 ErrorCode ORDER_UPDATE_PRICE_FAIL_PAID = new ErrorCode(1011000026, "支付订单调价失败,原因:支付订单已付款,不能调价");
32   - ErrorCode ORDER_UPDATE_PRICE_FAIL_EQUAL = new ErrorCode(1011000027, "支付订单调价失败,原因:价格没有变化");
33   - ErrorCode ORDER_UPDATE_PRICE_FAIL_NOT_ITEM = new ErrorCode(1011000028, "支付订单调价失败,原因:订单项不存在");
  32 + ErrorCode ORDER_UPDATE_PRICE_FAIL_ALREADY = new ErrorCode(1011000027, "支付订单调价失败,原因:已经修改过价格");
  33 + ErrorCode ORDER_UPDATE_PRICE_FAIL_PRICE_ERROR = new ErrorCode(1011000028, "支付订单调价失败,原因:调整后支付价格不能小于 0.01 元");
34 34 ErrorCode ORDER_DELETE_FAIL_STATUS_NOT_CANCEL = new ErrorCode(1011000029, "交易订单删除失败,订单不是【已取消】状态");
35 35  
36 36 // ========== After Sale 模块 1011000100 ==========
... ...
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java
... ... @@ -14,7 +14,9 @@ import lombok.RequiredArgsConstructor;
14 14 public enum TradeOrderOperateTypeEnum {
15 15  
16 16 MEMBER_CREATE(1, "用户下单"),
17   - MEMBER_PAY(20, "用户付款成功"),
  17 + ADMIN_UPDATE_PRICE(2, "订单价格 {oldPayPrice} 修改,实际支付金额为 {newPayPrice} 元"),
  18 + MEMBER_PAY(10, "用户付款成功"),
  19 + ADMIN_DELIVERY(20, "已发货,快递公司:{deliveryName},快递单号:{logisticsNo}"),
18 20 MEMBER_RECEIVE(30, "用户已收货"),
19 21 SYSTEM_RECEIVE(31, "到期未收货,系统自动确认收货"),
20 22 MEMBER_COMMENT(33, "用户评价"),
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/TradeOrderController.java
... ... @@ -73,7 +73,7 @@ public class TradeOrderController {
73 73  
74 74 // 查询订单项
75 75 List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(id);
76   - // orderLog
  76 + // TODO @puhui999:orderLog
77 77 // 拼接数据
78 78 MemberUserRespDTO user = memberUserApi.getUser(order.getUserId());
79 79 return success(TradeOrderConvert.INSTANCE.convert(order, orderItems, user));
... ... @@ -120,4 +120,6 @@ public class TradeOrderController {
120 120 return success(true);
121 121 }
122 122  
  123 + // TODO :核销逻辑
  124 +
123 125 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java
... ... @@ -75,6 +75,7 @@ public class AppTradeOrderController {
75 75 }
76 76  
77 77 // TODO @芋艿:如果拼团活动、秒杀活动、砍价活动时,是不是要额外在返回活动之类的信息;
  78 + // TODO @puhui999:需要的
78 79 @GetMapping("/get-detail")
79 80 @Operation(summary = "获得交易订单")
80 81 @Parameter(name = "id", description = "交易订单编号")
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
... ... @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.trade.service.order;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.lang.Assert;
  5 +import cn.hutool.core.map.MapUtil;
5 6 import cn.hutool.core.util.ObjectUtil;
6 7 import cn.hutool.core.util.RandomUtil;
7 8 import cn.hutool.core.util.StrUtil;
... ... @@ -10,6 +11,7 @@ import cn.iocoder.yudao.framework.common.core.KeyValue;
10 11 import cn.iocoder.yudao.framework.common.enums.TerminalEnum;
11 12 import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
12 13 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
  14 +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
13 15 import cn.iocoder.yudao.module.member.api.address.AddressApi;
14 16 import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO;
15 17 import cn.iocoder.yudao.module.member.api.level.MemberLevelApi;
... ... @@ -40,6 +42,7 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettle
40 42 import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO;
41 43 import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert;
42 44 import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO;
  45 +import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO;
43 46 import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
44 47 import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
45 48 import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper;
... ... @@ -62,6 +65,7 @@ import cn.iocoder.yudao.module.trade.service.order.handler.TradeOrderHandler;
62 65 import cn.iocoder.yudao.module.trade.service.price.TradePriceService;
63 66 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
64 67 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
  68 +import cn.iocoder.yudao.module.trade.service.price.calculator.TradePriceCalculatorHelper;
65 69 import lombok.extern.slf4j.Slf4j;
66 70 import org.jetbrains.annotations.NotNull;
67 71 import org.springframework.scheduling.annotation.Async;
... ... @@ -409,6 +413,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
409 413  
410 414 @Override
411 415 @Transactional(rollbackFor = Exception.class)
  416 + @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_CANCEL)
412 417 public void deliveryOrder(TradeOrderDeliveryReqVO deliveryReqVO) {
413 418 // 1.1 校验并获得交易订单(可发货)
414 419 TradeOrderDO order = validateOrderDeliverable(deliveryReqVO.getId());
... ... @@ -420,8 +425,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
420 425 // 2. 更新订单为已发货
421 426 TradeOrderDO updateOrderObj = new TradeOrderDO();
422 427 // 2.1 快递发货
  428 + DeliveryExpressDO express = null;
423 429 if (ObjectUtil.notEqual(deliveryReqVO.getLogisticsId(), TradeOrderDO.LOGISTICS_ID_NULL)) {
424   - deliveryExpressService.validateDeliveryExpress(deliveryReqVO.getLogisticsId());
  430 + express = deliveryExpressService.validateDeliveryExpress(deliveryReqVO.getLogisticsId());
425 431 updateOrderObj.setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo());
426 432 } else {
427 433 // 2.2 无需发货
... ... @@ -434,11 +440,14 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
434 440 throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED);
435 441 }
436 442  
437   - // 发送站内信
  443 + // 3. 记录订单日志
  444 + TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), TradeOrderStatusEnum.DELIVERED.getStatus(),
  445 + MapUtil.<String, Object>builder().put("expressName", express != null ? express.getName() : "")
  446 + .put("logisticsNo", express != null ? deliveryReqVO.getLogisticsNo() : "").build());
  447 +
  448 + // 4. 发送站内信
438 449 tradeMessageService.sendMessageWhenDeliveryOrder(new TradeOrderMessageWhenDeliveryOrderReqBO().setOrderId(order.getId())
439 450 .setUserId(order.getUserId()).setMessage(null));
440   -
441   - // TODO 芋艿:OrderLog
442 451 }
443 452  
444 453 /**
... ... @@ -465,6 +474,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
465 474 // 订单类类型:砍价
466 475 if (Objects.equals(TradeOrderTypeEnum.BARGAIN.getType(), order.getType())) {
467 476 // 校验订单砍价是否成功
  477 + // TODO @puhui999:砍价的话,应该不用校验。因为是砍价成功后,才可以下单
468 478 if (!bargainRecordApi.isBargainRecordSuccess(order.getUserId(), order.getId())) {
469 479 throw exception(ORDER_DELIVERY_FAIL_BARGAIN_RECORD_STATUS_NOT_SUCCESS);
470 480 }
... ... @@ -685,86 +695,58 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
685 695  
686 696 @Override
687 697 @Transactional(rollbackFor = Exception.class)
  698 + @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.ADMIN_UPDATE_PRICE)
688 699 public void updateOrderPrice(TradeOrderUpdatePriceReqVO reqVO) {
689   - // 1、校验交易订单
  700 + // 1.1 校验交易订单
690 701 TradeOrderDO order = validateOrderExists(reqVO.getId());
691 702 if (order.getPayStatus()) {
692 703 throw exception(ORDER_UPDATE_PRICE_FAIL_PAID);
693 704 }
694   - // 2、校验订单项
695   - List<TradeOrderItemDO> items = tradeOrderItemMapper.selectListByOrderId(order.getId());
696   - if (CollUtil.isEmpty(items)) {
697   - throw exception(ORDER_UPDATE_PRICE_FAIL_NOT_ITEM);
  705 + // 1.2 校验调价金额是否变化
  706 + if (order.getAdjustPrice() > 0) {
  707 + throw exception(ORDER_UPDATE_PRICE_FAIL_ALREADY);
698 708 }
699   - // 3、校验调价金额是否变化
700   - if (ObjectUtil.equal(order.getAdjustPrice(), reqVO.getAdjustPrice())) {
701   - throw exception(ORDER_UPDATE_PRICE_FAIL_EQUAL);
  709 + // 1.3 支付价格不能为 0
  710 + int newPayPrice = order.getPayPrice() + order.getAdjustPrice();
  711 + if (newPayPrice <= 0) {
  712 + throw exception(ORDER_UPDATE_PRICE_FAIL_PRICE_ERROR);
702 713 }
703 714  
704   - // 4、更新订单
705   - TradeOrderDO update = new TradeOrderDO();
706   - update.setId(order.getId());
707   - update.setAdjustPrice(reqVO.getAdjustPrice());
708   - int orderPayPrice = order.getAdjustPrice() != null ? (order.getPayPrice() - order.getAdjustPrice())
709   - + reqVO.getAdjustPrice() : order.getPayPrice() + reqVO.getAdjustPrice();
710   - update.setPayPrice(orderPayPrice);
711   - tradeOrderMapper.updateById(update);
712   - // TODO @芋艿:改价时,赠送的积分,要不要做改动???
713   -
714   - // 5、更新 TradeOrderItem
715   - // TradeOrderItemDO 需要做 adjustPrice 的分摊
716   - List<Integer> dividePrices = dividePrice(items, orderPayPrice);
  715 + // 2. 更新订单
  716 + tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId())
  717 + .setAdjustPrice(reqVO.getAdjustPrice()).setPayPrice(newPayPrice));
  718 +
  719 + // 3. 更新 TradeOrderItem,需要做 adjustPrice 的分摊
  720 + List<TradeOrderItemDO> orderOrderItems = tradeOrderItemMapper.selectListByOrderId(order.getId());
  721 + List<Integer> dividePrices = TradePriceCalculatorHelper.dividePrice2(orderOrderItems, newPayPrice);
717 722 List<TradeOrderItemDO> updateItems = new ArrayList<>();
718   - for (int i = 0; i < items.size(); i++) {
719   - TradeOrderItemDO item = items.get(i);
720   - Integer adjustPrice = item.getPrice() - dividePrices.get(i); // 计算调整的金额
721   - updateItems.add(new TradeOrderItemDO().setId(item.getId()).setAdjustPrice(adjustPrice)
722   - .setPayPrice(item.getPayPrice() - adjustPrice));
  723 + for (int i = 0; i < orderOrderItems.size(); i++) {
  724 + TradeOrderItemDO item = orderOrderItems.get(i);
  725 + updateItems.add(new TradeOrderItemDO().setId(item.getId()).setAdjustPrice(dividePrices.get(i))
  726 + .setPayPrice(item.getPayPrice() + dividePrices.get(i)));
723 727 }
724 728 tradeOrderItemMapper.updateBatch(updateItems);
725 729  
726   - // 6、更新支付订单
727   - payOrderApi.updatePayOrderPrice(order.getPayOrderId(), update.getPayPrice());
728   - }
  730 + // 4. 更新支付订单
  731 + payOrderApi.updatePayOrderPrice(order.getPayOrderId(), newPayPrice);
729 732  
730   - /**
731   - * 计算订单调价价格分摊
732   - *
733   - * @param items 订单项
734   - * @param orderPayPrice 订单支付金额
735   - * @return 分摊金额数组,和传入的 orderItems 一一对应
736   - */
737   - private List<Integer> dividePrice(List<TradeOrderItemDO> items, Integer orderPayPrice) {
738   - Integer total = getSumValue(items, TradeOrderItemDO::getPrice, Integer::sum);
739   - assert total != null;
740   - // 遍历每一个,进行分摊
741   - List<Integer> prices = new ArrayList<>(items.size());
742   - int remainPrice = orderPayPrice;
743   - for (int i = 0; i < items.size(); i++) {
744   - TradeOrderItemDO orderItem = items.get(i);
745   - int partPrice;
746   - if (i < items.size() - 1) { // 减一的原因,是因为拆分时,如果按照比例,可能会出现.所以最后一个,使用反减
747   - partPrice = (int) (orderPayPrice * (1.0D * orderItem.getPayPrice() / total));
748   - remainPrice -= partPrice;
749   - } else {
750   - partPrice = remainPrice;
751   - }
752   - Assert.isTrue(partPrice >= 0, "分摊金额必须大于等于 0");
753   - prices.add(partPrice);
754   - }
755   - return prices;
  733 + // 5. 记录订单日志
  734 + TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), order.getStatus(),
  735 + MapUtil.<String, Object>builder().put("oldPayPrice", MoneyUtils.fenToYuanStr(order.getPayPrice()))
  736 + .put("newPayPrice", MoneyUtils.fenToYuanStr(newPayPrice)).build());
756 737 }
757 738  
758 739 @Override
759 740 public void updateOrderAddress(TradeOrderUpdateAddressReqVO reqVO) {
760 741 // 校验交易订单
761 742 validateOrderExists(reqVO.getId());
762   - // TODO 是否需要校验订单是否发货
  743 + // TODO @puhui999:是否需要校验订单是否发货
763 744 // TODO 发货后是否支持修改收货地址
764 745  
765 746 // 更新
766   - TradeOrderDO update = TradeOrderConvert.INSTANCE.convert(reqVO);
767   - tradeOrderMapper.updateById(update);
  747 + tradeOrderMapper.updateById(TradeOrderConvert.INSTANCE.convert(reqVO));
  748 +
  749 + // TODO @puhui999:操作日志
768 750 }
769 751  
770 752 // =================== Order Item ===================
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java
... ... @@ -4,6 +4,7 @@ import cn.hutool.core.lang.Assert;
4 4 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
5 5 import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
6 6 import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
  7 +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
7 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;
... ... @@ -233,6 +234,36 @@ public class TradePriceCalculatorHelper {
233 234 }
234 235  
235 236 /**
  237 + * 计算订单调价价格分摊
  238 + *
  239 + * 和 {@link #dividePrice(List, Integer)} 逻辑一致,只是传入的是 TradeOrderItemDO 对象
  240 + *
  241 + * @param items 订单项
  242 + * @param price 订单支付金额
  243 + * @return 分摊金额数组,和传入的 orderItems 一一对应
  244 + */
  245 + public static List<Integer> dividePrice2(List<TradeOrderItemDO> items, Integer price) {
  246 + Integer total = getSumValue(items, TradeOrderItemDO::getPrice, Integer::sum);
  247 + assert total != null;
  248 + // 遍历每一个,进行分摊
  249 + List<Integer> prices = new ArrayList<>(items.size());
  250 + int remainPrice = price;
  251 + for (int i = 0; i < items.size(); i++) {
  252 + TradeOrderItemDO orderItem = items.get(i);
  253 + int partPrice;
  254 + if (i < items.size() - 1) { // 减一的原因,是因为拆分时,如果按照比例,可能会出现.所以最后一个,使用反减
  255 + partPrice = (int) (price * (1.0D * orderItem.getPayPrice() / total));
  256 + remainPrice -= partPrice;
  257 + } else {
  258 + partPrice = remainPrice;
  259 + }
  260 + Assert.isTrue(partPrice >= 0, "分摊金额必须大于等于 0");
  261 + prices.add(partPrice);
  262 + }
  263 + return prices;
  264 + }
  265 +
  266 + /**
236 267 * 添加【匹配】单个 OrderItem 的营销明细
237 268 *
238 269 * @param result 价格计算结果
... ...
yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClientIntegrationTest.java
... ... @@ -38,7 +38,7 @@ public class KdNiaoExpressClientIntegrationTest {
38 38 public void testGetExpressTrackList() {
39 39 ExpressTrackQueryReqDTO reqDTO = new ExpressTrackQueryReqDTO();
40 40 reqDTO.setExpressCode("STO");
41   - reqDTO.setLogisticsNo("663220402764314");
  41 + reqDTO.setLogisticsNo("777168349863987");
42 42 List<ExpressTrackRespDTO> tracks = client.getExpressTrackList(reqDTO);
43 43 System.out.println(JsonUtils.toJsonPrettyString(tracks));
44 44 }
... ...
yudao-server/src/main/resources/application-local.yaml
... ... @@ -78,7 +78,7 @@ spring:
78 78 # Quartz 配置项,对应 QuartzProperties 配置类
79 79 spring:
80 80 quartz:
81   - auto-startup: false # 本地开发环境,尽量不要开启 Job
  81 + auto-startup: true # 本地开发环境,尽量不要开启 Job
82 82 scheduler-name: schedulerName # Scheduler 名字。默认为 schedulerName
83 83 job-store-type: jdbc # Job 存储器类型。默认为 memory 表示内存,可选 jdbc 使用数据库。
84 84 wait-for-jobs-to-complete-on-shutdown: true # 应用关闭时,是否等待定时任务执行完成。默认为 false ,建议设置为 true
... ...