From 991b53649b2c2f015118f6583429eee8f340ef4d Mon Sep 17 00:00:00 2001 From: owen Date: Sun, 3 Sep 2023 21:19:42 +0800 Subject: [PATCH 01/48] =?UTF-8?q?member:=20=E5=88=86=E9=94=80=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../brokerage/BrokerageBindModeEnum.java | 44 +++++++++++++ .../BrokerageEnabledConditionEnum.java | 44 +++++++++++++ .../brokerage/BrokerageRecordBizTypeEnum.java | 46 ++++++++++++++ .../brokerage/BrokerageRecordStatusEnum.java | 39 ++++++++++++ .../BrokerageWithdrawStatusEnum.java | 41 ++++++++++++ .../brokerage/BrokerageWithdrawTypeEnum.java | 40 ++++++++++++ .../vo/config/MemberPointConfigBaseVO.java | 57 +++++++++++++++++ .../dataobject/point/MemberPointConfigDO.java | 62 ++++++++++++++++++- 8 files changed, 371 insertions(+), 2 deletions(-) create mode 100644 yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageBindModeEnum.java create mode 100644 yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageEnabledConditionEnum.java create mode 100644 yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageRecordBizTypeEnum.java create mode 100644 yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageRecordStatusEnum.java create mode 100644 yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageWithdrawStatusEnum.java create mode 100644 yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageWithdrawTypeEnum.java diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageBindModeEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageBindModeEnum.java new file mode 100644 index 0000000000..2ee7e891f8 --- /dev/null +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageBindModeEnum.java @@ -0,0 +1,44 @@ +package cn.iocoder.yudao.module.member.enums.brokerage; + +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * 分销关系绑定模式枚举 + * + * @author owen + */ +@AllArgsConstructor +@Getter +public enum BrokerageBindModeEnum implements IntArrayValuable { + + /** + * 只要用户没有推广人,随时都可以绑定分销关系 + */ + ANYTIME(0, "没有推广人"), + /** + * 仅新用户注册时才能绑定推广关系 + */ + REGISTER(1, "新用户"), + ; + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageBindModeEnum::getMode).toArray(); + + /** + * 模式 + */ + private final Integer mode; + /** + * 名字 + */ + private final String name; + + @Override + public int[] array() { + return ARRAYS; + } + +} diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageEnabledConditionEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageEnabledConditionEnum.java new file mode 100644 index 0000000000..5422b98b7f --- /dev/null +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageEnabledConditionEnum.java @@ -0,0 +1,44 @@ +package cn.iocoder.yudao.module.member.enums.brokerage; + +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * 分佣模式枚举 + * + * @author owen + */ +@AllArgsConstructor +@Getter +public enum BrokerageEnabledConditionEnum implements IntArrayValuable { + + /** + * 所有用户都可以分销 + */ + ALL(0, "人人分销"), + /** + * 仅可后台手动设置推广员 + */ + ADMIN(1, "指定分销"), + ; + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageEnabledConditionEnum::getCondition).toArray(); + + /** + * 模式 + */ + private final Integer condition; + /** + * 名字 + */ + private final String name; + + @Override + public int[] array() { + return ARRAYS; + } + +} diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageRecordBizTypeEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageRecordBizTypeEnum.java new file mode 100644 index 0000000000..d30758a880 --- /dev/null +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageRecordBizTypeEnum.java @@ -0,0 +1,46 @@ +package cn.iocoder.yudao.module.member.enums.brokerage; + +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * 佣金记录业务类型枚举 + * + * @author owen + */ +@AllArgsConstructor +@Getter +public enum BrokerageRecordBizTypeEnum implements IntArrayValuable { + + ORDER(0, "获得推广佣金", "获得推广佣金 {}", true), + WITHDRAW(1, "提现申请", "提现申请扣除佣金 {}", false), + ; + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageRecordBizTypeEnum::getType).toArray(); + + /** + * 类型 + */ + private final Integer type; + /** + * 标题 + */ + private final String title; + /** + * 描述 + */ + private final String description; + /** + * 是否为增加佣金 + */ + private final boolean add; + + @Override + public int[] array() { + return ARRAYS; + } + +} diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageRecordStatusEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageRecordStatusEnum.java new file mode 100644 index 0000000000..75ddc9e0a2 --- /dev/null +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageRecordStatusEnum.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.member.enums.brokerage; + +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * 佣金记录状态枚举 + * + * @author owen + */ +@AllArgsConstructor +@Getter +public enum BrokerageRecordStatusEnum implements IntArrayValuable { + + WAIT_SETTLEMENT(0, "待结算"), + SETTLEMENT(1, "已结算"), + CANCEL(2, "已取消"), + ; + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageRecordStatusEnum::getStatus).toArray(); + + /** + * 状态 + */ + private final Integer status; + /** + * 名字 + */ + private final String name; + + @Override + public int[] array() { + return ARRAYS; + } + +} diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageWithdrawStatusEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageWithdrawStatusEnum.java new file mode 100644 index 0000000000..6d0232deb5 --- /dev/null +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageWithdrawStatusEnum.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.member.enums.brokerage; + +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * 佣金提现状态枚举 + * + * @author owen + */ +@AllArgsConstructor +@Getter +public enum BrokerageWithdrawStatusEnum implements IntArrayValuable { + + AUDITING(0, "审核中"), + AUDIT_SUCCESS(10, "审核通过"), + WITHDRAW_SUCCESS(11, "提现成功"), + AUDIT_FAIL(20, "审核不通过"), + WITHDRAW_FAIL(21, "提现失败"), + ; + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageWithdrawStatusEnum::getStatus).toArray(); + + /** + * 状态 + */ + private final Integer status; + /** + * 名字 + */ + private final String name; + + @Override + public int[] array() { + return ARRAYS; + } + +} diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageWithdrawTypeEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageWithdrawTypeEnum.java new file mode 100644 index 0000000000..21d0712b91 --- /dev/null +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageWithdrawTypeEnum.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.member.enums.brokerage; + +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * 佣金提现类型枚举 + * + * @author owen + */ +@AllArgsConstructor +@Getter +public enum BrokerageWithdrawTypeEnum implements IntArrayValuable { + + WALLET(1, "钱包"), + BANK(2, "银行卡"), + WECHAT(3, "微信"), + ALIPAY(4, "支付宝"), + ; + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageWithdrawTypeEnum::getType).toArray(); + + /** + * 类型 + */ + private final Integer type; + /** + * 名字 + */ + private final String name; + + @Override + public int[] array() { + return ARRAYS; + } + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigBaseVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigBaseVO.java index f946e4a276..acdadb6bc4 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigBaseVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigBaseVO.java @@ -1,9 +1,17 @@ package cn.iocoder.yudao.module.member.controller.admin.point.vo.config; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageBindModeEnum; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageEnabledConditionEnum; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageWithdrawTypeEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import org.hibernate.validator.constraints.Range; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import javax.validation.constraints.PositiveOrZero; +import java.util.List; /** * 会员积分配置 Base VO,提供给添加、修改、详细的子 VO 使用 @@ -28,4 +36,53 @@ public class MemberPointConfigBaseVO { @NotNull(message = "1 元赠送积分不能为空") private Integer tradeGivePoint; + // ========== 分销相关 ========== + + @Schema(description = "是否启用分佣", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") + @NotNull(message = "是否启用分佣不能为空") + private Boolean brokerageEnabled; + + @Schema(description = "分佣模式", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") + @NotNull(message = "分佣模式不能为空") + @InEnum(value = BrokerageEnabledConditionEnum.class, message = "分佣模式必须是 {value}") + private Integer brokerageEnabledCondition; + + @Schema(description = "分销关系绑定模式", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") + @NotNull(message = "分销关系绑定模式不能为空") + @InEnum(value = BrokerageBindModeEnum.class, message = "分销关系绑定模式必须是 {value}") + private Integer brokerageBindMode; + + @Schema(description = "分销海报图地址数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/yudao.jpg]") + private List brokeragePostUrls; + + @Schema(description = "一级返佣比例", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") + @NotNull(message = "一级返佣比例不能为空") + @Range(min = 0, max = 100, message = "一级返佣比例必须在 0 - 100 之间") + private Integer brokerageFirstPercent; + + @Schema(description = "二级返佣比例", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") + @NotNull(message = "二级返佣比例不能为空") + @Range(min = 0, max = 100, message = "二级返佣比例必须在 0 - 100 之间") + private Integer brokerageSecondPercent; + + @Schema(description = "用户提现最低金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") + @NotNull(message = "用户提现最低金额不能为空") + @PositiveOrZero(message = "用户提现最低金额不能是负数") + private Integer brokerageWithdrawMinPrice; + + @Schema(description = "提现银行", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]") + @NotEmpty(message = "提现银行不能为空") + private List brokerageBankNames; + + @Schema(description = "佣金冻结时间(天)", requiredMode = Schema.RequiredMode.REQUIRED, example = "7") + @NotNull(message = "佣金冻结时间(天)不能为空") + @PositiveOrZero(message = "佣金冻结时间不能是负数") + private Integer brokerageFrozenDays; + + @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]") + @NotNull(message = "提现方式不能为空") + @InEnum(value = BrokerageWithdrawTypeEnum.class, message = "提现方式必须是 {value}") + private List brokerageWithdrawType; + + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/point/MemberPointConfigDO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/point/MemberPointConfigDO.java index 94fed9c53b..8f44bd9483 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/point/MemberPointConfigDO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/point/MemberPointConfigDO.java @@ -1,19 +1,25 @@ package cn.iocoder.yudao.module.member.dal.dataobject.point; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.framework.mybatis.core.type.IntegerListTypeHandler; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageBindModeEnum; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageEnabledConditionEnum; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageWithdrawTypeEnum; import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import lombok.*; -import java.math.BigDecimal; +import java.util.List; /** * 会员积分配置 DO * * @author QingX */ -@TableName("member_point_config") +@TableName(value = "member_point_config", autoResultMap = true) @KeySequence("member_point_config_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) @@ -47,4 +53,56 @@ public class MemberPointConfigDO extends BaseDO { */ private Integer tradeGivePoint; + // ========== 分销相关 ========== + + /** + * 是否启用分佣 + */ + private Boolean brokerageEnabled; + /** + * 分佣模式 + * + * 枚举 {@link BrokerageEnabledConditionEnum 对应的类} + */ + private Integer brokerageEnabledCondition; + /** + * 分销关系绑定模式 + * + * 枚举 {@link BrokerageBindModeEnum 对应的类} + */ + private Integer brokerageBindMode; + /** + * 分销海报图地址数组 + */ + @TableField(typeHandler = JacksonTypeHandler.class) + private List brokeragePostUrls; + /** + * 一级返佣比例 + */ + private Integer brokerageFirstPercent; + /** + * 二级返佣比例 + */ + private Integer brokerageSecondPercent; + /** + * 用户提现最低金额 + */ + private Integer brokerageWithdrawMinPrice; + /** + * 提现银行 + */ + @TableField(typeHandler = IntegerListTypeHandler.class) + private List brokerageBankNames; + /** + * 佣金冻结时间(天) + */ + private Integer brokerageFrozenDays; + /** + * 提现方式 + * + * 枚举 {@link BrokerageWithdrawTypeEnum 对应的类} + */ + @TableField(typeHandler = IntegerListTypeHandler.class) + private List brokerageWithdrawType; + } From 6a819da0b6cdd4b9f3eb8c67c519e2a6eb8498c6 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 3 Sep 2023 21:21:33 +0800 Subject: [PATCH 02/48] =?UTF-8?q?=E5=88=86=E4=BD=A3=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=94=A8=E6=88=B7=E5=88=86=E9=94=80=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=20API=20mock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 +-- .../AppCombinationRecordController.java | 10 ++--- .../brokerage/AppBrokerageUserController.java | 36 +++++++++++++++ .../vo/AppBrokerageUserSummaryRespVO.java | 22 ++++++++++ .../app/user/AppMemberUserController.java | 4 +- .../app/user/vo/AppMemberUserInfoRespVO.java | 3 ++ yudao-server/pom.xml | 44 +++++++++---------- 7 files changed, 94 insertions(+), 31 deletions(-) create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageUserController.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/AppBrokerageUserSummaryRespVO.java diff --git a/pom.xml b/pom.xml index d892b1a13b..b50fb8586b 100644 --- a/pom.xml +++ b/pom.xml @@ -16,11 +16,11 @@ yudao-module-member yudao-module-system yudao-module-infra - - + - + yudao-module-pay + yudao-module-mall yudao-example diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java index 7496e2e0ea..ef0e7ff994 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.promotion.controller.app.combination; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.util.date.DateUtils; +import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordDetailRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordSummaryRespVO; @@ -16,8 +16,8 @@ import org.springframework.web.bind.annotation.RestController; import javax.validation.constraints.Max; import java.time.Duration; +import java.time.LocalDateTime; import java.util.ArrayList; -import java.util.Date; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -58,7 +58,7 @@ public class AppCombinationRecordController { record.setId((long) i); record.setNickname("用户" + i); record.setAvatar("头像" + i); - record.setExpireTime(new Date()); + record.setExpireTime(LocalDateTime.now()); record.setUserSize(10); record.setUserCount(i); record.setPicUrl("https://static.iocoder.cn/mall/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg"); @@ -79,7 +79,7 @@ public class AppCombinationRecordController { headRecord.setId(1L); headRecord.setNickname("用户" + 1); headRecord.setAvatar("头像" + 1); - headRecord.setExpireTime(DateUtils.addTime(Duration.ofDays(1))); + headRecord.setExpireTime(LocalDateTimeUtils.addTime(Duration.ofDays(1))); headRecord.setUserSize(10); headRecord.setUserCount(3); headRecord.setStatus(1); @@ -94,7 +94,7 @@ public class AppCombinationRecordController { record.setId((long) i); record.setNickname("用户" + i); record.setAvatar("头像" + i); - record.setExpireTime(new Date()); + record.setExpireTime(LocalDateTime.now()); record.setUserSize(10); record.setUserCount(i); record.setStatus(1); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageUserController.java new file mode 100644 index 0000000000..6af65775e2 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageUserController.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.module.member.controller.app.brokerage; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; +import cn.iocoder.yudao.module.member.controller.app.brokerage.vo.AppBrokerageUserSummaryRespVO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "用户 APP - 分销用户") +@RestController +@RequestMapping("/member/brokerage-user") +@Validated +@Slf4j +public class AppBrokerageUserController { + + // TODO 芋艿:临时 mock => + @GetMapping("/get-summary") + @Operation(summary = "获得个人分销统计") + @PreAuthenticated + public CommonResult getBrokerageUserSummary() { + AppBrokerageUserSummaryRespVO respVO = new AppBrokerageUserSummaryRespVO() + .setYesterdayBrokeragePrice(1) + .setBrokeragePrice(2) + .setFrozenBrokeragePrice(3) + .setWithdrawBrokeragePrice(4); + return success(respVO); + } + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/AppBrokerageUserSummaryRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/AppBrokerageUserSummaryRespVO.java new file mode 100644 index 0000000000..ff1bea5840 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/AppBrokerageUserSummaryRespVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.member.controller.app.brokerage.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "用户 App - 个人分销统计 Response VO") +@Data +public class AppBrokerageUserSummaryRespVO { + + @Schema(description = "昨天的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Integer yesterdayBrokeragePrice; + + @Schema(description = "提现的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer withdrawBrokeragePrice; + + @Schema(description = "可用的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2408") + private Integer brokeragePrice; + + @Schema(description = "冻结的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "234") + private Integer frozenBrokeragePrice; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppMemberUserController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppMemberUserController.java index c957ceedc2..4d15aad1fc 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppMemberUserController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppMemberUserController.java @@ -39,7 +39,9 @@ public class AppMemberUserController { public CommonResult getUserInfo() { MemberUserDO user = userService.getUser(getLoginUserId()); MemberLevelDO level = levelService.getLevel(user.getLevelId()); - return success(MemberUserConvert.INSTANCE.convert(user, level)); + return success(MemberUserConvert.INSTANCE.convert(user, level) + .setBrokerageEnabled(true) // TODO @疯狂:这里我先写死,后面改成 db 返回; + ); } @PutMapping("/update") diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/vo/AppMemberUserInfoRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/vo/AppMemberUserInfoRespVO.java index fc3f427ca8..25cceedc27 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/vo/AppMemberUserInfoRespVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/vo/AppMemberUserInfoRespVO.java @@ -29,6 +29,9 @@ public class AppMemberUserInfoRespVO { @Schema(description = "用户等级") private Level level; + @Schema(description = "是否成为推广员", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") + private Boolean brokerageEnabled; + @Schema(description = "用户 App - 会员等级") @Data public static class Level { diff --git a/yudao-server/pom.xml b/yudao-server/pom.xml index cc383236c2..69f912096c 100644 --- a/yudao-server/pom.xml +++ b/yudao-server/pom.xml @@ -41,24 +41,24 @@ yudao-spring-boot-starter-biz-error-code - + - + - - - - - + + cn.iocoder.boot + yudao-module-pay-biz + ${revision} + @@ -68,21 +68,21 @@ - - - - - - - - - - - - - - - + + cn.iocoder.boot + yudao-module-promotion-biz + ${revision} + + + cn.iocoder.boot + yudao-module-product-biz + ${revision} + + + cn.iocoder.boot + yudao-module-trade-biz + ${revision} + From 91b03e7c93c9f027a3bb4b5b5984b98243c77d6e Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Mon, 4 Sep 2023 12:18:56 +0800 Subject: [PATCH 03/48] =?UTF-8?q?=E9=92=B1=E5=8C=85=20review=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/order/PayOrderController.java | 12 ++- .../pay/dal/mysql/wallet/PayWalletMapper.java | 51 ++++++++++ .../framework/pay/wallet/WalletPayClient.java | 9 +- .../pay/service/wallet/PayWalletService.java | 35 ++++++- .../service/wallet/PayWalletServiceImpl.java | 98 +++++++++++-------- 5 files changed, 157 insertions(+), 48 deletions(-) diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java index 9a2afbe66a..3350b58778 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java @@ -5,6 +5,8 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; +import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; import cn.iocoder.yudao.module.pay.controller.admin.order.vo.*; import cn.iocoder.yudao.module.pay.convert.order.PayOrderConvert; import cn.iocoder.yudao.module.pay.dal.dataobject.app.PayAppDO; @@ -23,9 +25,7 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; @@ -70,6 +70,12 @@ public class PayOrderController { @PostMapping("/submit") @Operation(summary = "提交支付订单") public CommonResult submitPayOrder(@RequestBody PayOrderSubmitReqVO reqVO) { + if (Objects.equals(reqVO.getChannelCode(), PayChannelEnum.WALLET.getCode())) { + Map channelExtras = reqVO.getChannelExtras() == null ? new HashMap<>(8) : reqVO.getChannelExtras(); + channelExtras.put("user_id", String.valueOf(WebFrameworkUtils.getLoginUserId())); + channelExtras.put("user_type", String.valueOf(WebFrameworkUtils.getLoginUserType())); + reqVO.setChannelExtras(channelExtras); + } PayOrderSubmitRespVO respVO = orderService.submitOrder(reqVO, getClientIP()); return success(respVO); } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java index a05b88fe53..ccacdd3768 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.pay.dal.mysql.wallet; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; +import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; @Mapper @@ -12,6 +14,55 @@ public interface PayWalletMapper extends BaseMapperX { return selectOne(PayWalletDO::getUserId, userId, PayWalletDO::getUserType, userType); } + + /** + * 当余额减少时候更新 + * + * @param bizType 业务类型 + * @param balance 当前余额 + * @param totalRecharge 当前累计充值 + * @param totalExpense 当前累计支出 + * @param price 支出的金额 + * @param id 钱包 id + */ + default int updateWhenDecBalance(PayWalletBizTypeEnum bizType, Integer balance, Long totalRecharge, + Long totalExpense, Integer price, Long id) { + PayWalletDO updateDO = new PayWalletDO().setBalance(balance - price); + if(bizType == PayWalletBizTypeEnum.PAYMENT){ + updateDO.setTotalExpense(totalExpense + price); + } + if (bizType == PayWalletBizTypeEnum.RECHARGE_REFUND) { + updateDO.setTotalRecharge(totalRecharge - price); + } + return update(updateDO, + new LambdaQueryWrapper().eq(PayWalletDO::getId, id) + .eq(PayWalletDO::getBalance, balance) + .ge(PayWalletDO::getBalance, price)); + } + + /** + * 当余额增加时候更新 + * + * @param bizType 业务类型 + * @param balance 当前余额 + * @param totalRecharge 当前累计充值 + * @param totalExpense 当前累计支出 + * @param price 金额 + * @param id 钱包 id + */ + default int updateWhenIncBalance(PayWalletBizTypeEnum bizType, Integer balance, Long totalRecharge, + Long totalExpense, Integer price, Long id) { + PayWalletDO updateDO = new PayWalletDO().setBalance(balance + price); + if (bizType == PayWalletBizTypeEnum.PAYMENT_REFUND) { + updateDO.setTotalExpense(totalExpense - price); + } + if (bizType == PayWalletBizTypeEnum.RECHARGE) { + updateDO.setTotalExpense(totalRecharge + price); + } + return update(updateDO, + new LambdaQueryWrapper().eq(PayWalletDO::getId, id) + .eq(PayWalletDO::getBalance, balance)); + } } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java index 7e23f5cf77..68985965fe 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.module.pay.framework.pay.wallet; +import cn.hutool.core.lang.Assert; +import cn.hutool.core.map.MapUtil; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; @@ -41,7 +43,12 @@ public class WalletPayClient extends AbstractPayClient { @Override protected PayOrderRespDTO doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) { try { - PayWalletTransactionDO transaction = wallService.pay(reqDTO.getOutTradeNo(), reqDTO.getPrice()); + String userId = MapUtil.getStr(reqDTO.getChannelExtras(), "user_id"); + String userType = MapUtil.getStr(reqDTO.getChannelExtras(), "user_type"); + Assert.notEmpty(userId, "用户 id 不能为空"); + Assert.notEmpty(userType, "用户类型不能为空"); + PayWalletTransactionDO transaction = wallService.pay(Long.valueOf(userId), Integer.valueOf(userType), + reqDTO.getOutTradeNo(), reqDTO.getPrice()); return PayOrderRespDTO.successOf(transaction.getNo(), transaction.getCreator(), transaction.getTransactionTime(), reqDTO.getOutTradeNo(), transaction); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java index 2f57fc465c..13cddaeeb1 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.pay.service.wallet; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; +import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; /** * 钱包 Service 接口 @@ -20,15 +21,43 @@ public interface PayWalletService { PayWalletDO getPayWallet(Long userId, Integer userType); /** - * 钱包支付 + * 钱包订单支付 * * @param outTradeNo 外部订单号 * @param price 金额 */ - PayWalletTransactionDO pay(String outTradeNo, Integer price); + PayWalletTransactionDO pay(Long userId, Integer userType, String outTradeNo, Integer price); + /** - * 钱包支付退款 + * 扣减钱包余额 + * + * @param userId 用户 id + * @param userType 用户类型 + * @param bizId 业务关联 id + * @param bizType 业务关联分类 + * @param price 扣减金额 + * @return 钱包流水 + */ + PayWalletTransactionDO reduceWalletBalance(Long userId, Integer userType, + Long bizId, PayWalletBizTypeEnum bizType, Integer price); + + + /** + * 增加钱包余额 + * + * @param userId 用户 id + * @param userType 用户类型 + * @param bizId 业务关联 id + * @param bizType 业务关联分类 + * @param price 增加金额 + * @return 钱包流水 + */ + PayWalletTransactionDO addWalletBalance(Long userId, Integer userType, + Long bizId, PayWalletBizTypeEnum bizType, Integer price); + + /** + * 钱包订单支付退款 * * @param outRefundNo 外部退款号 * @param refundPrice 退款金额 diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java index 6992d63f66..5ea1b4945a 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java @@ -1,11 +1,13 @@ package cn.iocoder.yudao.module.pay.service.wallet; +import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderExtensionDO; import cn.iocoder.yudao.module.pay.dal.dataobject.refund.PayRefundDO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletMapper; import cn.iocoder.yudao.module.pay.dal.redis.no.PayNoRedisDAO; +import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; import cn.iocoder.yudao.module.pay.service.order.PayOrderService; import cn.iocoder.yudao.module.pay.service.refund.PayRefundService; import lombok.extern.slf4j.Slf4j; @@ -16,9 +18,8 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.time.LocalDateTime; +import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.TOO_MANY_REQUESTS; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId; -import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserType; import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum.PAYMENT; import static cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum.PAYMENT_REFUND; @@ -60,42 +61,70 @@ public class PayWalletServiceImpl implements PayWalletService { return payWalletMapper.selectByUserIdAndType(userId, userType); } - // TODO @jason:可以做的更抽象一点;pay(bizType, bizId, price);reduceWalletBalance; - // TODO @jason:最好是,明确传入哪个 userId 或者 walletId; + @Override @Transactional(rollbackFor = Exception.class) - public PayWalletTransactionDO pay(String outTradeNo, Integer price) { - // 1.1 判断支付交易拓展单是否存 + public PayWalletTransactionDO pay(Long userId, Integer userType, String outTradeNo, Integer price) { + // 判断支付交易拓展单是否存 PayOrderExtensionDO orderExtension = payOrderService.getOrderExtensionByNo(outTradeNo); if (orderExtension == null) { throw exception(ORDER_EXTENSION_NOT_FOUND); } + return reduceWalletBalance(userId, userType, orderExtension.getOrderId(), PAYMENT, price); + } + + @Override + public PayWalletTransactionDO reduceWalletBalance(Long userId, Integer userType, + Long bizId, PayWalletBizTypeEnum bizType, Integer price) { + // 1.1 判断钱包是否有效 + PayWalletDO payWallet = validatePayWallet(userId, userType); // 1.2 判断余额是否足够 - PayWalletDO payWallet = validatePayWallet(); int afterBalance = payWallet.getBalance() - price; if (afterBalance < 0) { throw exception(WALLET_BALANCE_NOT_ENOUGH); } // 2.1 扣除余额 - // TODO @jason:不要直接整个更新;而是 new 一个出来更新;然后要考虑并发,要 where 余额 > price,以及 - price - payWallet.setBalance(afterBalance); - payWallet.setTotalExpense(payWallet.getTotalExpense() + price); - payWalletMapper.updateById(payWallet); + int number = payWalletMapper.updateWhenDecBalance(bizType,payWallet.getBalance(), payWallet.getTotalRecharge(), + payWallet.getTotalExpense(), price, payWallet.getId()); + if (number == 0) { + throw exception(TOO_MANY_REQUESTS); + } - // 2.2 生成钱包流水 + // 2.2 生成钱包流水 TODO 根据 bizType 生成 NO String walletNo = noRedisDAO.generate(WALLET_PAY_NO_PREFIX); PayWalletTransactionDO walletTransaction = new PayWalletTransactionDO().setWalletId(payWallet.getId()) - .setNo(walletNo).setAmount(price * -1).setBalance(afterBalance).setTransactionTime(LocalDateTime.now()) - .setBizId(orderExtension.getOrderId()).setBizType(PAYMENT.getType()); + .setNo(walletNo).setAmount(-price).setBalance(afterBalance).setTransactionTime(LocalDateTime.now()) + .setBizId(bizId).setBizType(bizType.getType()).setDescription(bizType.getDescription()); payWalletTransactionService.createWalletTransaction(walletTransaction); return walletTransaction; } - // TODO @jason:不要在 service 里去使用用户上下文,这样和 request 就耦合了。 - private PayWalletDO validatePayWallet() { - Long userId = getLoginUserId(); - Integer userType = getLoginUserType(); + @Override + public PayWalletTransactionDO addWalletBalance(Long userId, Integer userType, Long bizId, + PayWalletBizTypeEnum bizType, Integer price) { + // 1.1 判断钱包是否有效 + PayWalletDO payWallet = validatePayWallet(userId, userType); + + // 2.1 增加余额 + int number = payWalletMapper.updateWhenIncBalance(bizType, payWallet.getBalance(), payWallet.getTotalRecharge(), + payWallet.getTotalExpense(), price, payWallet.getId()); + if (number == 0) { + throw exception(TOO_MANY_REQUESTS); + } + + // 2.2 生成钱包流水 TODO 根据 bizType 生成 NO + String walletNo = noRedisDAO.generate(WALLET_REFUND_NO_PREFIX); + PayWalletTransactionDO newWalletTransaction = new PayWalletTransactionDO().setWalletId(payWallet.getId()) + .setNo(walletNo).setAmount(price).setBalance(payWallet.getBalance()+price).setTransactionTime(LocalDateTime.now()) + .setBizId(bizId).setBizType(bizType.getType()) + .setDescription(bizType.getDescription()); + payWalletTransactionService.createWalletTransaction(newWalletTransaction); + return newWalletTransaction; + } + + + private PayWalletDO validatePayWallet(Long userId, Integer userType) { PayWalletDO payWallet = getPayWallet(userId, userType); if (payWallet == null) { log.error("[validatePayWallet] 用户 {} 钱包不存在", userId); @@ -104,7 +133,7 @@ public class PayWalletServiceImpl implements PayWalletService { return payWallet; } - // TODO @jason:可以做的更抽象一点;pay(bizType, bizId, price);addWalletBalance;这样,如果后续充值,应该也是能复用这个方法的; + @Override @Transactional(rollbackFor = Exception.class) public PayWalletTransactionDO refund(String outRefundNo, Integer refundPrice, String reason) { @@ -114,23 +143,11 @@ public class PayWalletServiceImpl implements PayWalletService { throw exception(REFUND_NOT_FOUND); } // 1.2 校验是否可以退款 - PayWalletDO payWallet = validatePayWallet(); - validateWalletCanRefund(payRefund.getId(), payRefund.getChannelOrderNo(), payWallet.getId(), refundPrice); + Long walletId = validateWalletCanRefund(payRefund.getId(), payRefund.getChannelOrderNo(), refundPrice); - // TODO @jason:不要直接整个更新;而是 new 一个出来更新;然后要考虑并发,要 where 余额 + 金额 - Integer afterBalance = payWallet.getBalance() + refundPrice; - payWallet.setBalance(afterBalance); - payWallet.setTotalExpense(payWallet.getTotalExpense() + refundPrice * -1L); - payWalletMapper.updateById(payWallet); - - // 2.2 生成钱包流水 - String walletNo = noRedisDAO.generate(WALLET_REFUND_NO_PREFIX); - PayWalletTransactionDO newWalletTransaction = new PayWalletTransactionDO().setWalletId(payWallet.getId()) - .setNo(walletNo).setAmount(refundPrice).setBalance(afterBalance).setTransactionTime(LocalDateTime.now()) - .setBizId(payRefund.getId()).setBizType(PAYMENT_REFUND.getType()) - .setDescription(reason); - payWalletTransactionService.createWalletTransaction(newWalletTransaction); - return newWalletTransaction; + PayWalletDO payWallet = payWalletMapper.selectById(walletId); + Assert.notNull(payWallet, "钱包 {} 不存在", walletId); + return addWalletBalance(payWallet.getUserId(), payWallet.getUserType(),payRefund.getId(), PAYMENT_REFUND, refundPrice); } /** @@ -138,24 +155,23 @@ public class PayWalletServiceImpl implements PayWalletService { * * @param refundId 支付退款单 id * @param walletPayNo 钱包支付 no - * @param walletId 钱包 id */ - // TODO @jason:不要使用基本类型; - private void validateWalletCanRefund(long refundId, String walletPayNo, long walletId, int refundPrice) { + private Long validateWalletCanRefund(Long refundId, String walletPayNo, Integer refundPrice) { // 查询钱包支付交易 PayWalletTransactionDO payWalletTransaction = payWalletTransactionService.getWalletTransactionByNo(walletPayNo); if (payWalletTransaction == null) { throw exception(WALLET_TRANSACTION_NOT_FOUND); } // 原来的支付金额 - int amount = payWalletTransaction.getAmount() * -1; // TODO @jason:直接 - payWalletTransaction.getAmount() 即可; + int amount = - payWalletTransaction.getAmount(); if (refundPrice != amount) { throw exception(WALLET_REFUND_AMOUNT_ERROR); } - PayWalletTransactionDO refundTransaction = payWalletTransactionService.getWalletTransaction(walletId, refundId, PAYMENT_REFUND); + PayWalletTransactionDO refundTransaction = payWalletTransactionService.getWalletTransaction( + payWalletTransaction.getWalletId(), refundId, PAYMENT_REFUND); if (refundTransaction != null) { throw exception(WALLET_REFUND_EXIST); } + return payWalletTransaction.getWalletId(); } - } From cc4c924717b862a85765f918a8205cdcfcc80f41 Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Mon, 4 Sep 2023 14:54:38 +0800 Subject: [PATCH 04/48] =?UTF-8?q?=E9=92=B1=E5=8C=85=20review=20DO=20?= =?UTF-8?q?=E7=B1=BB=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/pay_wallet.sql | 37 ++++++----- .../app/wallet/AppPayWalletController.java | 2 +- .../AppPayWalletTransactionRespVO.java | 3 - .../wallet/PayWalletTransactionDO.java | 23 ++----- .../wallet/PayWalletTransactionMapper.java | 4 +- .../framework/pay/wallet/WalletPayClient.java | 4 +- .../pay/service/wallet/PayWalletService.java | 7 +- .../service/wallet/PayWalletServiceImpl.java | 64 +++++++++++-------- .../PayWalletTransactionServiceImpl.java | 9 +-- 9 files changed, 74 insertions(+), 79 deletions(-) diff --git a/sql/mysql/pay_wallet.sql b/sql/mysql/pay_wallet.sql index 1fda83769b..bc2ad183e0 100644 --- a/sql/mysql/pay_wallet.sql +++ b/sql/mysql/pay_wallet.sql @@ -1,5 +1,5 @@ -- ---------------------------- --- 支付-钱包表 +-- 会员钱包表 -- ---------------------------- DROP TABLE IF EXISTS `pay_wallet`; CREATE TABLE `pay_wallet` @@ -17,28 +17,27 @@ CREATE TABLE `pay_wallet` `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB COMMENT='支付钱包表'; +) ENGINE=InnoDB COMMENT='会员钱包表'; -- ---------------------------- --- 支付- 钱包余额明细表 +-- 会员钱包流水表 -- ---------------------------- DROP TABLE IF EXISTS `pay_wallet_transaction`; CREATE TABLE `pay_wallet_transaction` ( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', - `wallet_id` bigint NOT NULL COMMENT '会员钱包 id', - `biz_type` tinyint NOT NULL COMMENT '关联类型', - `biz_id` bigint NOT NULL COMMENT '关联业务编号', - `no` varchar(64) NOT NULL COMMENT '流水号', - `description` varchar(255) COMMENT '操作说明', - `amount` int NOT NULL COMMENT '交易金额, 单位分', - `balance` int NOT NULL COMMENT '余额, 单位分', - `transaction_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '交易时间', - `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', - `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', - `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', - `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', + `wallet_id` bigint NOT NULL COMMENT '会员钱包 id', + `biz_type` tinyint NOT NULL COMMENT '关联类型', + `biz_id` varchar(64) NOT NULL COMMENT '关联业务编号', + `no` varchar(64) NOT NULL COMMENT '流水号', + `title` varchar(128) NOT NULL COMMENT '流水标题', + `price` int NOT NULL COMMENT '交易金额, 单位分', + `balance` int NOT NULL COMMENT '余额, 单位分', + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', + `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB COMMENT='支付钱包余额明细表'; +) ENGINE=InnoDB COMMENT='会员钱包流水表'; diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletController.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletController.java index 23515ed330..2c5f2d5f4a 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletController.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletController.java @@ -37,7 +37,7 @@ public class AppPayWalletController { @Operation(summary = "获取钱包") @PreAuthenticated public CommonResult getPayWallet() { - PayWalletDO wallet = payWalletService.getPayWallet(getLoginUserId(), UserTypeEnum.MEMBER.getValue()); + PayWalletDO wallet = payWalletService.getOrCreatePayWallet(getLoginUserId(), UserTypeEnum.MEMBER.getValue()); return success(PayWalletConvert.INSTANCE.convert(wallet)); } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/transaction/AppPayWalletTransactionRespVO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/transaction/AppPayWalletTransactionRespVO.java index b89628bc24..9d17c346e9 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/transaction/AppPayWalletTransactionRespVO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/transaction/AppPayWalletTransactionRespVO.java @@ -15,9 +15,6 @@ public class AppPayWalletTransactionRespVO { @Schema(description = "业务分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") private Integer bizType; - @Schema(description = "交易时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") - private LocalDateTime transactionTime; - @Schema(description = "交易金额,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") private Long price; diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletTransactionDO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletTransactionDO.java index 677febb25f..04a869f32c 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletTransactionDO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletTransactionDO.java @@ -7,8 +7,6 @@ import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; -import java.time.LocalDateTime; - /** * 会员钱包流水 DO * @@ -24,6 +22,7 @@ public class PayWalletTransactionDO extends BaseDO { */ @TableId private Long id; + /** * 流水号 */ @@ -42,34 +41,26 @@ public class PayWalletTransactionDO extends BaseDO { * 枚举 {@link PayWalletBizTypeEnum#getType()} */ private Integer bizType; - // TODO @jason:使用 string;因为可能有业务是 string 接入哈。 + /** * 关联业务编号 */ - private Long bizId; + private String bizId; - // TODO @jason:想了下,改成 title;流水标题;因为账户明细那,会看到这个; /** - * 附加说明 + * 流水说明 */ - private String description; + private String title; - // TODO @jason:使用 price 哈。项目里,金额都是用这个为主; /** * 交易金额,单位分 * * 正值表示余额增加,负值表示余额减少 */ - private Integer amount; + private Integer price; + /** * 交易后余额,单位分 */ private Integer balance; - - // TODO @jason:使用 createTime 就够啦 - /** - * 交易时间 - */ - private LocalDateTime transactionTime; - } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java index 9e08b2caa7..3d329d1184 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java @@ -18,9 +18,9 @@ public interface PayWalletTransactionMapper extends BaseMapperX query = new LambdaQueryWrapperX() .eq(PayWalletTransactionDO::getWalletId, walletId); if (Objects.equals(pageReqVO.getType(), AppPayWalletTransactionPageReqVO.TYPE_INCOME)) { - query.gt(PayWalletTransactionDO::getAmount, 0); + query.gt(PayWalletTransactionDO::getPrice, 0); } else if (Objects.equals(pageReqVO.getType(), AppPayWalletTransactionPageReqVO.TYPE_EXPENSE)) { - query.lt(PayWalletTransactionDO::getAmount, 0); + query.lt(PayWalletTransactionDO::getPrice, 0); } query.orderByDesc(PayWalletTransactionDO::getId); return selectPage(pageReqVO, query); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java index 68985965fe..170fd6694c 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java @@ -50,7 +50,7 @@ public class WalletPayClient extends AbstractPayClient { PayWalletTransactionDO transaction = wallService.pay(Long.valueOf(userId), Integer.valueOf(userType), reqDTO.getOutTradeNo(), reqDTO.getPrice()); return PayOrderRespDTO.successOf(transaction.getNo(), transaction.getCreator(), - transaction.getTransactionTime(), + transaction.getCreateTime(), reqDTO.getOutTradeNo(), transaction); } catch (Throwable ex) { log.error("[doUnifiedOrder] 失败", ex); @@ -81,7 +81,7 @@ public class WalletPayClient extends AbstractPayClient { try { PayWalletTransactionDO payWalletTransaction = wallService.refund(reqDTO.getOutRefundNo(), reqDTO.getRefundPrice(), reqDTO.getReason()); - return PayRefundRespDTO.successOf(payWalletTransaction.getNo(), payWalletTransaction.getTransactionTime(), + return PayRefundRespDTO.successOf(payWalletTransaction.getNo(), payWalletTransaction.getCreateTime(), reqDTO.getOutRefundNo(), payWalletTransaction); } catch (Throwable ex) { log.error("[doUnifiedRefund] 失败", ex); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java index 13cddaeeb1..370b776a79 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java @@ -11,18 +11,19 @@ import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; */ public interface PayWalletService { - // TODO @jason:改成 getOrCreateWallet;因为目前解耦,用户注册时,不会创建钱包;需要这里兜底处理; /** - * 获取钱包信息 + * 获取钱包信息,如果不存在创建钱包。由于用户注册时候不会创建钱包 * * @param userId 用户编号 * @param userType 用户类型 */ - PayWalletDO getPayWallet(Long userId, Integer userType); + PayWalletDO getOrCreatePayWallet(Long userId, Integer userType); /** * 钱包订单支付 * + * @param userId 用户 id + * @param userType 用户类型 * @param outTradeNo 外部订单号 * @param price 金额 */ diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java index 5ea1b4945a..a3606323bd 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java @@ -57,8 +57,19 @@ public class PayWalletServiceImpl implements PayWalletService { private PayRefundService payRefundService; @Override - public PayWalletDO getPayWallet(Long userId, Integer userType) { - return payWalletMapper.selectByUserIdAndType(userId, userType); + public PayWalletDO getOrCreatePayWallet(Long userId, Integer userType) { + PayWalletDO payWalletDO = payWalletMapper.selectByUserIdAndType(userId, userType); + if (payWalletDO == null) { + payWalletDO = new PayWalletDO(); + payWalletDO.setUserId(userId); + payWalletDO.setUserType(userType); + payWalletDO.setBalance(0); + payWalletDO.setTotalExpense(0L); + payWalletDO.setTotalRecharge(0L); + payWalletDO.setCreateTime(LocalDateTime.now()); + payWalletMapper.insert(payWalletDO); + } + return payWalletDO; } @@ -76,8 +87,8 @@ public class PayWalletServiceImpl implements PayWalletService { @Override public PayWalletTransactionDO reduceWalletBalance(Long userId, Integer userType, Long bizId, PayWalletBizTypeEnum bizType, Integer price) { - // 1.1 判断钱包是否有效 - PayWalletDO payWallet = validatePayWallet(userId, userType); + // 1.1 获取钱包 + PayWalletDO payWallet = getOrCreatePayWallet(userId, userType); // 1.2 判断余额是否足够 int afterBalance = payWallet.getBalance() - price; if (afterBalance < 0) { @@ -90,12 +101,11 @@ public class PayWalletServiceImpl implements PayWalletService { if (number == 0) { throw exception(TOO_MANY_REQUESTS); } - - // 2.2 生成钱包流水 TODO 根据 bizType 生成 NO - String walletNo = noRedisDAO.generate(WALLET_PAY_NO_PREFIX); + // 2.2 生成钱包流水 + String walletNo = generateWalletNo(bizType); PayWalletTransactionDO walletTransaction = new PayWalletTransactionDO().setWalletId(payWallet.getId()) - .setNo(walletNo).setAmount(-price).setBalance(afterBalance).setTransactionTime(LocalDateTime.now()) - .setBizId(bizId).setBizType(bizType.getType()).setDescription(bizType.getDescription()); + .setNo(walletNo).setPrice(-price).setBalance(afterBalance) + .setBizId(String.valueOf(bizId)).setBizType(bizType.getType()).setTitle(bizType.getDescription()); payWalletTransactionService.createWalletTransaction(walletTransaction); return walletTransaction; } @@ -103,8 +113,8 @@ public class PayWalletServiceImpl implements PayWalletService { @Override public PayWalletTransactionDO addWalletBalance(Long userId, Integer userType, Long bizId, PayWalletBizTypeEnum bizType, Integer price) { - // 1.1 判断钱包是否有效 - PayWalletDO payWallet = validatePayWallet(userId, userType); + // 1.1 获取钱包 + PayWalletDO payWallet = getOrCreatePayWallet(userId, userType); // 2.1 增加余额 int number = payWalletMapper.updateWhenIncBalance(bizType, payWallet.getBalance(), payWallet.getTotalRecharge(), @@ -113,27 +123,31 @@ public class PayWalletServiceImpl implements PayWalletService { throw exception(TOO_MANY_REQUESTS); } - // 2.2 生成钱包流水 TODO 根据 bizType 生成 NO - String walletNo = noRedisDAO.generate(WALLET_REFUND_NO_PREFIX); + // 2.2 生成钱包流水 + String walletNo = generateWalletNo(bizType); PayWalletTransactionDO newWalletTransaction = new PayWalletTransactionDO().setWalletId(payWallet.getId()) - .setNo(walletNo).setAmount(price).setBalance(payWallet.getBalance()+price).setTransactionTime(LocalDateTime.now()) - .setBizId(bizId).setBizType(bizType.getType()) - .setDescription(bizType.getDescription()); + .setNo(walletNo).setPrice(price).setBalance(payWallet.getBalance()+price) + .setBizId(String.valueOf(bizId)).setBizType(bizType.getType()) + .setTitle(bizType.getDescription()); payWalletTransactionService.createWalletTransaction(newWalletTransaction); return newWalletTransaction; } - - private PayWalletDO validatePayWallet(Long userId, Integer userType) { - PayWalletDO payWallet = getPayWallet(userId, userType); - if (payWallet == null) { - log.error("[validatePayWallet] 用户 {} 钱包不存在", userId); - throw exception(WALLET_NOT_FOUND); + private String generateWalletNo(PayWalletBizTypeEnum bizType) { + String no = ""; + switch(bizType){ + case PAYMENT : + no = noRedisDAO.generate(WALLET_PAY_NO_PREFIX); + break; + case PAYMENT_REFUND : + no = noRedisDAO.generate(WALLET_REFUND_NO_PREFIX); + break; + default : + // TODO 待增加 } - return payWallet; + return no; } - @Override @Transactional(rollbackFor = Exception.class) public PayWalletTransactionDO refund(String outRefundNo, Integer refundPrice, String reason) { @@ -163,7 +177,7 @@ public class PayWalletServiceImpl implements PayWalletService { throw exception(WALLET_TRANSACTION_NOT_FOUND); } // 原来的支付金额 - int amount = - payWalletTransaction.getAmount(); + int amount = - payWalletTransaction.getPrice(); if (refundPrice != amount) { throw exception(WALLET_REFUND_AMOUNT_ERROR); } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java index e2338219d7..1b156576a2 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java @@ -11,9 +11,6 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.WALLET_NOT_FOUND; - /** * 钱包流水 Service 实现类 * @@ -32,11 +29,7 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ @Override public PageResult getWalletTransactionPage(Long userId, Integer userType, AppPayWalletTransactionPageReqVO pageVO) { - PayWalletDO wallet = payWalletService.getPayWallet(userId, userType); - if (wallet == null) { - log.error("[getWalletTransactionPage][用户({}/{}) 钱包不存在", userId, userType); - throw exception(WALLET_NOT_FOUND); - } + PayWalletDO wallet = payWalletService.getOrCreatePayWallet(userId, userType); return payWalletTransactionMapper.selectPage(wallet.getId(), pageVO); } From fc56a15f76815581191ba9e7afcb6411813c86b1 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 4 Sep 2023 21:00:03 +0800 Subject: [PATCH 05/48] =?UTF-8?q?=E5=88=86=E4=BD=A3=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=94=A8=E6=88=B7=E5=88=86=E9=94=80=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E3=80=81=E6=8F=90=E7=8E=B0=20API=20mock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppBrokerageRecordController.java | 39 +++++++++++++++++++ .../brokerage/AppBrokerageUserController.java | 2 +- .../AppBrokerageWithdrawController.java | 39 +++++++++++++++++++ .../vo/record/AppBrokerageRecordRespVO.java | 24 ++++++++++++ .../AppBrokerageUserSummaryRespVO.java | 2 +- .../withdraw/AppBrokerageWithdrawRespVO.java | 27 +++++++++++++ 6 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageRecordController.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageWithdrawController.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordRespVO.java rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/{ => user}/AppBrokerageUserSummaryRespVO.java (99%) create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawRespVO.java diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageRecordController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageRecordController.java new file mode 100644 index 0000000000..df46b561df --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageRecordController.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.member.controller.app.brokerage; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; +import cn.iocoder.yudao.module.member.controller.app.brokerage.vo.record.AppBrokerageRecordRespVO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static java.util.Arrays.asList; + +@Tag(name = "用户 APP - 分销用户") +@RestController +@RequestMapping("/member/brokerage-record") +@Validated +@Slf4j +public class AppBrokerageRecordController { + + // TODO 芋艿:临时 mock => + @GetMapping("/page") + @Operation(summary = "获得分销记录分页") + @PreAuthenticated + public CommonResult> getBrokerageRecordPage() { + AppBrokerageRecordRespVO vo1 = new AppBrokerageRecordRespVO() + .setId(1L).setPrice(10).setTitle("收到钱").setCreateTime(LocalDateTime.now()); + AppBrokerageRecordRespVO vo2 = new AppBrokerageRecordRespVO() + .setId(2L).setPrice(-20).setTitle("提现钱").setCreateTime(LocalDateTime.now()); + return success(new PageResult<>(asList(vo1, vo2), 10L)); + } + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageUserController.java index 6af65775e2..0b31c07bdc 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageUserController.java @@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.member.controller.app.brokerage; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; -import cn.iocoder.yudao.module.member.controller.app.brokerage.vo.AppBrokerageUserSummaryRespVO; +import cn.iocoder.yudao.module.member.controller.app.brokerage.vo.user.AppBrokerageUserSummaryRespVO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageWithdrawController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageWithdrawController.java new file mode 100644 index 0000000000..dde0a8a033 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageWithdrawController.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.member.controller.app.brokerage; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; +import cn.iocoder.yudao.module.member.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static java.util.Arrays.asList; + +@Tag(name = "用户 APP - 分销提现") +@RestController +@RequestMapping("/member/brokerage-withdraw") +@Validated +@Slf4j +public class AppBrokerageWithdrawController { + + // TODO 芋艿:临时 mock => + @GetMapping("/page") + @Operation(summary = "获得分销提现分页") + @PreAuthenticated + public CommonResult> getBrokerageWithdrawPage() { + AppBrokerageWithdrawRespVO vo1 = new AppBrokerageWithdrawRespVO() + .setId(1L).setStatus(10).setPrice(10).setStatusName("审批通过").setCreateTime(LocalDateTime.now()); + AppBrokerageWithdrawRespVO vo2 = new AppBrokerageWithdrawRespVO() + .setId(2L).setStatus(0).setPrice(20).setStatusName("审批中").setCreateTime(LocalDateTime.now()); + return success(new PageResult<>(asList(vo1, vo2), 10L)); + } + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordRespVO.java new file mode 100644 index 0000000000..fc85695d04 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordRespVO.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.module.member.controller.app.brokerage.vo.record; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +@Schema(description = "用户 App - 分销记录 Response VO") +@Data +public class AppBrokerageRecordRespVO { + + @Schema(description = "记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Long id; + + @Schema(description = "分销标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "用户下单") + private String title; + + @Schema(description = "分销金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") + private Integer price; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + private LocalDateTime createTime; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/AppBrokerageUserSummaryRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserSummaryRespVO.java similarity index 99% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/AppBrokerageUserSummaryRespVO.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserSummaryRespVO.java index ff1bea5840..6357052530 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/AppBrokerageUserSummaryRespVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserSummaryRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.member.controller.app.brokerage.vo; +package cn.iocoder.yudao.module.member.controller.app.brokerage.vo.user; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawRespVO.java new file mode 100644 index 0000000000..3a3670097a --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawRespVO.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.member.controller.app.brokerage.vo.withdraw; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +@Schema(description = "用户 App - 分销提现 Response VO") +@Data +public class AppBrokerageWithdrawRespVO { + + @Schema(description = "提现编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Long id; + + @Schema(description = "提现状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Integer status; + + @Schema(description = "提现状态名", requiredMode = Schema.RequiredMode.REQUIRED, example = "审核中") + private String statusName; + + @Schema(description = "提现金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") + private Integer price; + + @Schema(description = "提现时间", requiredMode = Schema.RequiredMode.REQUIRED) + private LocalDateTime createTime; + +} From 7389e4fb650be0b51a8a6d38fca0b165b3754c26 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 4 Sep 2023 22:48:26 +0800 Subject: [PATCH 06/48] =?UTF-8?q?=E5=88=86=E4=BD=A3=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=8E=B7=E5=BE=97=E5=88=86=E9=94=80=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=88=86=E9=A1=B5=20API=20mock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppBrokerageRecordController.java | 9 ++++++--- .../record/AppBrokerageRecordPageReqVO.java | 19 +++++++++++++++++++ .../vo/record/AppBrokerageRecordRespVO.java | 3 +++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageRecordController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageRecordController.java index df46b561df..de2460feed 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageRecordController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageRecordController.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.member.controller.app.brokerage; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; +import cn.iocoder.yudao.module.member.controller.app.brokerage.vo.record.AppBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.member.controller.app.brokerage.vo.record.AppBrokerageRecordRespVO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -28,11 +29,13 @@ public class AppBrokerageRecordController { @GetMapping("/page") @Operation(summary = "获得分销记录分页") @PreAuthenticated - public CommonResult> getBrokerageRecordPage() { + public CommonResult> getBrokerageRecordPage(AppBrokerageRecordPageReqVO pageReqVO) { AppBrokerageRecordRespVO vo1 = new AppBrokerageRecordRespVO() - .setId(1L).setPrice(10).setTitle("收到钱").setCreateTime(LocalDateTime.now()); + .setId(1L).setPrice(10).setTitle("收到钱").setCreateTime(LocalDateTime.now()) + .setFinishTime(LocalDateTime.now()); AppBrokerageRecordRespVO vo2 = new AppBrokerageRecordRespVO() - .setId(2L).setPrice(-20).setTitle("提现钱").setCreateTime(LocalDateTime.now()); + .setId(2L).setPrice(-20).setTitle("提现钱").setCreateTime(LocalDateTime.now()) + .setFinishTime(LocalDateTime.now()); return success(new PageResult<>(asList(vo1, vo2), 10L)); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java new file mode 100644 index 0000000000..c8bfabd5c1 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.member.controller.app.brokerage.vo.record; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "应用 App - 分销记录分页 Request VO") +@Data +public class AppBrokerageRecordPageReqVO extends PageParam { + + // TODO @疯狂:要加下枚举校验 + + @Schema(description = "业务类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer bizType; + + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer status; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordRespVO.java index fc85695d04..0459e15f92 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordRespVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordRespVO.java @@ -21,4 +21,7 @@ public class AppBrokerageRecordRespVO { @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; + @Schema(description = "完成时间", requiredMode = Schema.RequiredMode.REQUIRED) + private LocalDateTime finishTime; + } From eae8218f0dda538d7117b63ef1ec558af3db242a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 5 Sep 2023 00:11:41 +0800 Subject: [PATCH 07/48] =?UTF-8?q?=E5=88=86=E4=BD=A3=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=8E=B7=E5=BE=97=E5=88=86=E9=94=80=E6=8E=92=E8=A1=8C?= =?UTF-8?q?=E5=88=86=E9=A1=B5=20API=20mock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppBrokerageRecordController.java | 3 ++- .../brokerage/AppBrokerageUserController.java | 23 +++++++++++++++++++ .../user/AppBrokerageUserRankPageReqVO.java | 22 ++++++++++++++++++ .../vo/user/AppBrokerageUserRankRespVO.java | 22 ++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserRankPageReqVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserRankRespVO.java diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageRecordController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageRecordController.java index de2460feed..8cf4d81e8d 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageRecordController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageRecordController.java @@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.validation.Valid; import java.time.LocalDateTime; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -29,7 +30,7 @@ public class AppBrokerageRecordController { @GetMapping("/page") @Operation(summary = "获得分销记录分页") @PreAuthenticated - public CommonResult> getBrokerageRecordPage(AppBrokerageRecordPageReqVO pageReqVO) { + public CommonResult> getBrokerageRecordPage(@Valid AppBrokerageRecordPageReqVO pageReqVO) { AppBrokerageRecordRespVO vo1 = new AppBrokerageRecordRespVO() .setId(1L).setPrice(10).setTitle("收到钱").setCreateTime(LocalDateTime.now()) .setFinishTime(LocalDateTime.now()); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageUserController.java index 0b31c07bdc..1b5bc6184e 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageUserController.java @@ -1,7 +1,10 @@ package cn.iocoder.yudao.module.member.controller.app.brokerage; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; +import cn.iocoder.yudao.module.member.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO; +import cn.iocoder.yudao.module.member.controller.app.brokerage.vo.user.AppBrokerageUserRankRespVO; import cn.iocoder.yudao.module.member.controller.app.brokerage.vo.user.AppBrokerageUserSummaryRespVO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -12,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static java.util.Arrays.asList; @Tag(name = "用户 APP - 分销用户") @RestController @@ -33,4 +37,23 @@ public class AppBrokerageUserController { return success(respVO); } + @GetMapping("/rank-page") + @Operation(summary = "获得分销用户排行分页") + @PreAuthenticated + public CommonResult> getBrokerageUserRankPage(AppBrokerageUserRankPageReqVO pageReqVO) { + AppBrokerageUserRankRespVO vo1 = new AppBrokerageUserRankRespVO() + .setUserId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setBrokerageUserCount(10); + AppBrokerageUserRankRespVO vo2 = new AppBrokerageUserRankRespVO() + .setUserId(2L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setBrokerageUserCount(6); + AppBrokerageUserRankRespVO vo3 = new AppBrokerageUserRankRespVO() + .setUserId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setBrokerageUserCount(4); + AppBrokerageUserRankRespVO vo4 = new AppBrokerageUserRankRespVO() + .setUserId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setBrokerageUserCount(4); + return success(new PageResult<>(asList(vo1, vo2, vo3, vo4), 10L)); + } + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserRankPageReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserRankPageReqVO.java new file mode 100644 index 0000000000..0ba1e9c75c --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserRankPageReqVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.member.controller.app.brokerage.vo.user; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.NotEmpty; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "应用 App - 分销用户排行 Request VO") +@Data +public class AppBrokerageUserRankPageReqVO extends PageParam { + + @Schema(description = "开始 + 结束时间", requiredMode = Schema.RequiredMode.REQUIRED) + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @NotEmpty(message = "时间不能为空") + private LocalDateTime[] times; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserRankRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserRankRespVO.java new file mode 100644 index 0000000000..7835f55321 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserRankRespVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.member.controller.app.brokerage.vo.user; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "用户 App - 分销排行用户 Response VO") +@Data +public class AppBrokerageUserRankRespVO { + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Long userId; + + @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小王") + private String nickname; + + @Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "http://www.iocoder.cn/xxx.jpg") + private String avatar; + + @Schema(description = "邀请用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Integer brokerageUserCount; + +} From c7ef8519c83dc6f0339dd6600ec62ecc37ac4d85 Mon Sep 17 00:00:00 2001 From: owen Date: Tue, 5 Sep 2023 08:56:39 +0800 Subject: [PATCH 08/48] =?UTF-8?q?member:=20=E5=88=86=E9=94=80=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BD=A3=E9=87=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/brokerage.sql | 189 ++++++++++++++++++ .../api/sku/dto/ProductSkuRespDTO.java | 9 + .../convert/order/TradeOrderConvert.java | 8 + .../order/TradeOrderUpdateServiceImpl.java | 15 ++ .../member/api/brokerage/BrokerageApi.java | 30 +++ .../api/brokerage/dto/BrokerageAddReqDTO.java | 35 ++++ .../api/brokerage/BrokerageApiImpl.java | 32 +++ .../MemberBrokerageRecordController.java | 51 +++++ .../vo/MemberBrokerageRecordBaseVO.java | 59 ++++++ .../vo/MemberBrokerageRecordPageReqVO.java | 33 +++ .../vo/MemberBrokerageRecordRespVO.java | 22 ++ .../record/MemberBrokerageRecordConvert.java | 46 +++++ .../record/MemberBrokerageRecordDO.java | 78 ++++++++ .../dal/dataobject/user/MemberUserDO.java | 27 +++ .../record/MemberBrokerageRecordMapper.java | 27 +++ .../dal/mysql/user/MemberUserMapper.java | 30 +++ .../record/MemberBrokerageRecordService.java | 40 ++++ .../MemberBrokerageRecordServiceImpl.java | 151 ++++++++++++++ .../service/user/MemberUserService.java | 24 +++ .../service/user/MemberUserServiceImpl.java | 22 ++ .../MemberBrokerageRecordServiceImplTest.java | 116 +++++++++++ .../src/test/resources/sql/clean.sql | 3 +- .../src/test/resources/sql/create_tables.sql | 23 ++- 23 files changed, 1068 insertions(+), 2 deletions(-) create mode 100644 sql/mysql/brokerage.sql create mode 100644 yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApi.java create mode 100644 yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/dto/BrokerageAddReqDTO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApiImpl.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/MemberBrokerageRecordController.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordBaseVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordPageReqVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordRespVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/brokerage/record/MemberBrokerageRecordConvert.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/brokerage/record/MemberBrokerageRecordDO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordService.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImplTest.java diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql new file mode 100644 index 0000000000..187e07621d --- /dev/null +++ b/sql/mysql/brokerage.sql @@ -0,0 +1,189 @@ +-- 增加配置 +alter table member_point_config + add column brokerage_enabled bit default 1 not null comment '是否启用分佣'; +alter table member_point_config + add column brokerage_enabled_condition tinyint default 0 not null comment '分佣模式:0-人人分销 1-指定分销'; +alter table member_point_config + add column brokerage_bind_mode tinyint default 0 not null comment '分销关系绑定模式: 0-没有推广人,1-新用户'; +alter table member_point_config + add column brokerage_post_urls varchar(2000) null comment '分销海报图地址数组'; +alter table member_point_config + add column brokerage_first_percent int not null comment '一级返佣比例'; +alter table member_point_config + add column brokerage_second_percent int not null comment '二级返佣比例'; +alter table member_point_config + add column brokerage_withdraw_min_price int not null comment '用户提现最低金额'; +alter table member_point_config + add column brokerage_bank_names varchar(200) not null comment '提现银行(字典类型=brokerage_bank_name)'; +alter table member_point_config + add column brokerage_frozen_days int default 7 not null comment '佣金冻结时间(天)'; +alter table member_point_config + add column brokerage_withdraw_type varchar(32) default '1,2,3,4' not null comment '提现方式:1-钱包;2-银行卡;3-微信;4-支付宝'; + +-- 用户表增加分销相关字段 +alter table member_user + add column brokerage_user_id bigint not null comment '推广员编号'; +alter table member_user + add column brokerage_bind_time datetime null comment '推广员绑定时间'; +alter table member_user + add column brokerage_enabled bit default 1 not null comment '是否成为推广员'; +alter table member_user + add column brokerage_time datetime null comment '成为分销员时间'; +alter table member_user + add column brokerage_price int default 0 not null comment '可用佣金'; +alter table member_user + add column frozen_brokerage_price int default 0 not null comment '冻结佣金'; + +create index idx_invite_user_id on member_user (brokerage_user_id) comment '推广员编号'; +create index idx_agent on member_user (brokerage_enabled) comment '是否成为推广员'; + + +create table member_brokerage_record +( + id int auto_increment comment '编号' + primary key, + user_id bigint not null comment '用户编号', + biz_id varchar(64) default '' not null comment '业务编号', + biz_type tinyint default 0 not null comment '业务类型:0-订单,1-提现', + title varchar(64) default '' not null comment '标题', + price int default 0 not null comment '金额', + total_price int default 0 not null comment '当前总佣金', + description varchar(500) default '' not null comment '说明', + status tinyint default 0 not null comment '状态:0-待结算,1-已结算,2-已取消', + frozen_days int default 0 not null comment '冻结时间(天)', + unfreeze_time datetime null comment '解冻时间', + creator varchar(64) collate utf8mb4_general_ci default '' null comment '创建者', + create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', + updater varchar(64) collate utf8mb4_general_ci default '' null comment '更新者', + update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', + deleted bit default b'0' not null comment '是否删除', + tenant_id bigint default 0 not null comment '租户编号' +) + comment '佣金记录'; + +create index idx_user_id on member_brokerage_record (user_id) comment '用户编号'; +create index idx_biz on member_brokerage_record (biz_type, biz_id) comment '业务'; +create index idx_status on member_brokerage_record (status) comment '状态'; + + +create table member_brokerage_withdraw +( + id int auto_increment comment '编号' + primary key, + user_id bigint not null comment '用户编号', + price int default 0 not null comment '提现金额', + fee_price int default 0 not null comment '提现手续费', + total_price int default 0 not null comment '当前总佣金', + type tinyint default 0 not null comment '提现类型:1-钱包;2-银行卡;3-微信;4-支付宝', + name varchar(64) null comment '真实姓名', + account_no varchar(64) null comment '账号', + bank_name varchar(100) null comment '银行名称', + bank_address varchar(200) null comment '开户地址', + account_qr_code_url varchar(512) null comment '收款码', + status tinyint(2) default 0 not null comment '状态:0-审核中,10-审核通过 20-审核不通过;预留:11 - 提现成功;21-提现失败', + audit_reason varchar(128) null comment '审核驳回原因', + audit_time datetime null comment '审核时间', + remark varchar(500) null comment '备注', + creator varchar(64) collate utf8mb4_general_ci default '' null comment '创建者', + create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', + updater varchar(64) collate utf8mb4_general_ci default '' null comment '更新者', + update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', + deleted bit default b'0' not null comment '是否删除', + tenant_id bigint default 0 not null comment '租户编号' +) + comment '佣金提现'; + +create index idx_user_id on member_brokerage_withdraw (user_id) comment '用户编号'; +create index idx_audit_status on member_brokerage_withdraw (status) comment '状态'; + +-- 增加字典 +insert into system_dict_type(type, name) +values ('brokerage_enabled_condition', '分佣模式'); +insert into system_dict_data(dict_type, label, value, sort, remark) +values ('brokerage_enabled_condition', '人人分销', 0, 0, '所有用户都可以分销'), + ('brokerage_enabled_condition', '指定分销', 1, 1, '仅可后台手动设置推广员'); + +insert into system_dict_type(type, name) +values ('brokerage_bind_mode', '分销关系绑定模式'); +insert into system_dict_data(dict_type, label, value, sort, remark) +values ('brokerage_bind_mode', '没有推广人', 0, 0, '只要用户没有推广人,随时都可以绑定推广关系'), + ('brokerage_bind_mode', '新用户', 1, 1, '仅新用户注册时才能绑定推广关系'); + +insert into system_dict_type(type, name) +values ('brokerage_withdraw_type', '佣金提现类型'); +insert into system_dict_data(dict_type, label, value, sort) +values ('brokerage_withdraw_type', '钱包', 1, 1), + ('brokerage_withdraw_type', '银行卡', 2, 2), + ('brokerage_withdraw_type', '微信', 3, 3), + ('brokerage_withdraw_type', '支付宝', 4, 4); + +insert into system_dict_type(type, name) +values ('brokerage_record_biz_type', '佣金记录业务类型'); +insert into system_dict_data(dict_type, label, value, sort) +values ('brokerage_record_biz_type', '订单返佣', 0, 0), + ('brokerage_record_biz_type', '申请提现', 1, 1); + +insert into system_dict_type(type, name) +values ('brokerage_record_status', '佣金记录状态'); +insert into system_dict_data(dict_type, label, value, sort) +values ('brokerage_record_status', '待结算', 0, 0), + ('brokerage_record_status', '已结算', 1, 1), + ('brokerage_record_status', '已取消', 2, 2); + +insert into system_dict_type(type, name) +values ('brokerage_withdraw_status', '佣金提现状态'); +insert into system_dict_data(dict_type, label, value, sort) +values ('brokerage_withdraw_status', '审核中', 0, 0), + ('brokerage_withdraw_status', '审核通过', 10, 10), + ('brokerage_withdraw_status', '提现成功', 11, 11), + ('brokerage_withdraw_status', '审核不通过', 20, 20), + ('brokerage_withdraw_status', '提现失败', 21, 21); + +insert into system_dict_type(type, name) +values ('brokerage_bank_name', '佣金提现银行'); +insert into system_dict_data(dict_type, label, value, sort) +values ('brokerage_bank_name', '工商银行', 0, 0), + ('brokerage_bank_name', '建设银行', 1, 1), + ('brokerage_bank_name', '农业银行', 2, 2), + ('brokerage_bank_name', '中国银行', 3, 3), + ('brokerage_bank_name', '交通银行', 4, 4), + ('brokerage_bank_name', '招商银行', 5, 5); + +-- 增加菜单:分销员管理 +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name) +VALUES ('分销员', '', 2, 7, 2262, 'brokerage', 'user', 'member/brokerage/user/index', 0, 'MemberBrokerageUser'); +-- 按钮父菜单ID +SELECT @parentId := LAST_INSERT_ID(); +-- 按钮 SQL +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('分销员查询', 'member:brokerage-user:query', 3, 1, @parentId, '', '', '', 0); +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('分销员创建', 'member:brokerage-user:create', 3, 2, @parentId, '', '', '', 0); +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('分销员更新', 'member:brokerage-user:update', 3, 3, @parentId, '', '', '', 0); +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('分销员删除', 'member:brokerage-user:delete', 3, 4, @parentId, '', '', '', 0); + +-- 增加菜单:佣金记录 +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name) +VALUES ('佣金记录', '', 2, 8, 2262, 'brokerage-record', 'list', 'member/brokerage/record/index', 0, + 'MemberBrokerageRecord'); +-- 按钮父菜单ID +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 +SELECT @parentId := LAST_INSERT_ID(); +-- 按钮 SQL +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('佣金记录查询', 'member:member-brokerage-record:query', 3, 1, @parentId, '', 'table', '', 0); + +-- 增加菜单:佣金提现 +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name) +VALUES ('佣金提现', '', 2, 9, 2262, 'brokerage-withdraw', '', 'member/brokerage/withdraw/index', 0, + 'MemberBrokerageWithdraw'); + +-- 按钮父菜单ID +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 +SELECT @parentId := LAST_INSERT_ID(); + +-- 按钮 SQL +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('佣金提现查询', 'member:brokerage-withdraw:query', 3, 1, @parentId, '', '', '', 0); diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/dto/ProductSkuRespDTO.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/dto/ProductSkuRespDTO.java index 20f84f87c6..2899fc0759 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/dto/ProductSkuRespDTO.java +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/dto/ProductSkuRespDTO.java @@ -60,4 +60,13 @@ public class ProductSkuRespDTO { */ private Double volume; + /** + * 一级分销的佣金,单位:分 + */ + private Integer subCommissionFirstPrice; + /** + * 二级分销的佣金,单位:分 + */ + private Integer subCommissionSecondPrice; + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index df7b296f0c..e46ce66b6c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -7,11 +7,13 @@ import cn.iocoder.yudao.framework.common.util.string.StrUtils; import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; +import cn.iocoder.yudao.module.member.api.brokerage.dto.BrokerageAddReqDTO; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; import cn.iocoder.yudao.module.pay.enums.DictTypeConstants; import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; +import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; @@ -273,4 +275,10 @@ public interface TradeOrderConvert { TradeOrderDO convert(TradeOrderRemarkReqVO reqVO); + default BrokerageAddReqDTO convert(TradeOrderItemDO item, ProductSkuRespDTO sku) { + return new BrokerageAddReqDTO().setBizId(String.valueOf(item.getId())) + .setPayPrice(item.getPayPrice()).setCount(item.getCount()) + .setSkuFirstBrokeragePrice(sku.getSubCommissionFirstPrice()) + .setSkuSecondBrokeragePrice(sku.getSubCommissionSecondPrice()); + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index f887b71e86..afb125e083 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -12,6 +12,8 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; +import cn.iocoder.yudao.module.member.api.brokerage.BrokerageApi; +import cn.iocoder.yudao.module.member.api.brokerage.dto.BrokerageAddReqDTO; import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; import cn.iocoder.yudao.module.member.api.point.MemberPointApi; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; @@ -118,6 +120,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Resource private MemberPointApi memberPointApi; @Resource + private BrokerageApi brokerageApi; + @Resource private ProductCommentApi productCommentApi; @Resource @@ -365,6 +369,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { getSelf().addUserPointAsync(order.getUserId(), order.getPayPrice(), order.getId()); // 增加用户经验 getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); + // 增加用户佣金 + getSelf().addBrokerageAsync(order.getUserId(), order.getId()); } /** @@ -742,6 +748,15 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { memberPointApi.addPoint(userId, -refundPrice, bizType, String.valueOf(afterSaleId)); } + + @Async + protected void addBrokerageAsync(Long userId, Long orderId) { + List orderItems = tradeOrderItemMapper.selectListByOrderId(orderId); + List list = convertList(orderItems, + item -> TradeOrderConvert.INSTANCE.convert(item, productSkuApi.getSku(item.getSkuId()))); + brokerageApi.addBrokerage(userId, list); + } + /** * 获得自身的代理对象,解决 AOP 生效问题 * diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApi.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApi.java new file mode 100644 index 0000000000..d01ce58456 --- /dev/null +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApi.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.member.api.brokerage; + +import cn.iocoder.yudao.module.member.api.brokerage.dto.BrokerageAddReqDTO; + +import java.util.List; + +/** + * 佣金 API 接口 + * + * @author owen + */ +public interface BrokerageApi { + + /** + * 增加佣金 + * + * @param userId 会员ID + * @param list 请求参数列表 + */ + void addBrokerage(Long userId, List list); + + /** + * 取消佣金 + * + * @param userId 会员ID + * @param bizId 业务编号 + */ + void cancelBrokerage(Long userId, String bizId); + +} diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/dto/BrokerageAddReqDTO.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/dto/BrokerageAddReqDTO.java new file mode 100644 index 0000000000..c466452012 --- /dev/null +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/dto/BrokerageAddReqDTO.java @@ -0,0 +1,35 @@ +package cn.iocoder.yudao.module.member.api.brokerage.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 佣金 增加 Request DTO + * @author owen + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class BrokerageAddReqDTO { + /** + * 业务ID + */ + private String bizId; + /** + * 商品支付价格 + */ + private Integer payPrice; + /** + * SKU 一级佣金 + */ + private Integer skuFirstBrokeragePrice; + /** + * SKU 二级佣金 + */ + private Integer skuSecondBrokeragePrice; + /** + * 购买数量 + */ + private Integer count; +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApiImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApiImpl.java new file mode 100644 index 0000000000..2891bdcc1e --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApiImpl.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.member.api.brokerage; + +import cn.iocoder.yudao.module.member.api.brokerage.dto.BrokerageAddReqDTO; +import cn.iocoder.yudao.module.member.service.brokerage.record.MemberBrokerageRecordService; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 佣金 API 实现类 + * + * @author owen + */ +@Service +@Validated +public class BrokerageApiImpl implements BrokerageApi { + + @Resource + private MemberBrokerageRecordService memberBrokerageRecordService; + + @Override + public void addBrokerage(Long userId, List list) { + memberBrokerageRecordService.addBrokerage(userId, list); + } + + @Override + public void cancelBrokerage(Long userId, String bizId) { + + } +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/MemberBrokerageRecordController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/MemberBrokerageRecordController.java new file mode 100644 index 0000000000..92cb0ae1aa --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/MemberBrokerageRecordController.java @@ -0,0 +1,51 @@ +package cn.iocoder.yudao.module.member.controller.admin.brokerage.record; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo.MemberBrokerageRecordRespVO; +import cn.iocoder.yudao.module.member.convert.brokerage.record.MemberBrokerageRecordConvert; +import cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +import cn.iocoder.yudao.module.member.service.brokerage.record.MemberBrokerageRecordService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.validation.Valid; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "管理后台 - 佣金记录") +@RestController +@RequestMapping("/member/member-brokerage-record") +@Validated +public class MemberBrokerageRecordController { + + @Resource + private MemberBrokerageRecordService memberBrokerageRecordService; + + @GetMapping("/get") + @Operation(summary = "获得佣金记录") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('member:member-brokerage-record:query')") + public CommonResult getMemberBrokerageRecord(@RequestParam("id") Integer id) { + MemberBrokerageRecordDO memberBrokerageRecord = memberBrokerageRecordService.getMemberBrokerageRecord(id); + return success(MemberBrokerageRecordConvert.INSTANCE.convert(memberBrokerageRecord)); + } + + @GetMapping("/page") + @Operation(summary = "获得佣金记录分页") + @PreAuthorize("@ss.hasPermission('member:member-brokerage-record:query')") + public CommonResult> getMemberBrokerageRecordPage(@Valid MemberBrokerageRecordPageReqVO pageVO) { + PageResult pageResult = memberBrokerageRecordService.getMemberBrokerageRecordPage(pageVO); + return success(MemberBrokerageRecordConvert.INSTANCE.convertPage(pageResult)); + } + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordBaseVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordBaseVO.java new file mode 100644 index 0000000000..ef6762be1d --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordBaseVO.java @@ -0,0 +1,59 @@ +package cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.NotNull; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +/** + * 佣金记录 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ +@Data +public class MemberBrokerageRecordBaseVO { + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25973") + @NotNull(message = "用户编号不能为空") + private Long userId; + + @Schema(description = "业务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23353") + @NotNull(message = "业务编号不能为空") + private String bizId; + + @Schema(description = "业务类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "业务类型不能为空") + private Integer bizType; + + @Schema(description = "标题", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "标题不能为空") + private String title; + + @Schema(description = "金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "28731") + @NotNull(message = "金额不能为空") + private Integer price; + + @Schema(description = "当前总佣金", requiredMode = Schema.RequiredMode.REQUIRED, example = "13226") + @NotNull(message = "当前总佣金不能为空") + private Integer totalPrice; + + @Schema(description = "说明", requiredMode = Schema.RequiredMode.REQUIRED, example = "你说的对") + @NotNull(message = "说明不能为空") + private String description; + + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "状态不能为空") + private Integer status; + + @Schema(description = "冻结时间(天)", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "冻结时间(天)不能为空") + private Integer frozenDays; + + @Schema(description = "解冻时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime unfreezeTime; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordPageReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordPageReqVO.java new file mode 100644 index 0000000000..04a9ed94cb --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordPageReqVO.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 佣金记录分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MemberBrokerageRecordPageReqVO extends PageParam { + + @Schema(description = "用户编号", example = "25973") + private Long userId; + + @Schema(description = "业务类型", example = "1") + private Integer bizType; + + @Schema(description = "状态", example = "1") + private Integer status; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordRespVO.java new file mode 100644 index 0000000000..417b5320d4 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordRespVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 佣金记录 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MemberBrokerageRecordRespVO extends MemberBrokerageRecordBaseVO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "28896") + private Integer id; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + private LocalDateTime createTime; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/brokerage/record/MemberBrokerageRecordConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/brokerage/record/MemberBrokerageRecordConvert.java new file mode 100644 index 0000000000..d36ef1c038 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/brokerage/record/MemberBrokerageRecordConvert.java @@ -0,0 +1,46 @@ +package cn.iocoder.yudao.module.member.convert.brokerage.record; + +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo.MemberBrokerageRecordRespVO; +import cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageRecordBizTypeEnum; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageRecordStatusEnum; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 佣金记录 Convert + * + * @author owen + */ +@Mapper +public interface MemberBrokerageRecordConvert { + + MemberBrokerageRecordConvert INSTANCE = Mappers.getMapper(MemberBrokerageRecordConvert.class); + + MemberBrokerageRecordRespVO convert(MemberBrokerageRecordDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + default MemberBrokerageRecordDO convert(MemberUserDO user, String bizId, int brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime) { + return new MemberBrokerageRecordDO() + .setUserId(user.getId()) + .setBizType(BrokerageRecordBizTypeEnum.ORDER.getType()) + .setBizId(bizId) + .setPrice(brokerage) + .setTotalPrice(user.getBrokeragePrice()) + .setTitle(BrokerageRecordBizTypeEnum.ORDER.getTitle()) + .setDescription(StrUtil.format(BrokerageRecordBizTypeEnum.ORDER.getDescription(), String.valueOf(brokerage / 100.0))) + .setStatus(BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus()) + .setFrozenDays(brokerageFrozenDays) + .setUnfreezeTime(unfreezeTime); + } + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/brokerage/record/MemberBrokerageRecordDO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/brokerage/record/MemberBrokerageRecordDO.java new file mode 100644 index 0000000000..88e6ba7d9c --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/brokerage/record/MemberBrokerageRecordDO.java @@ -0,0 +1,78 @@ +package cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageRecordBizTypeEnum; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageRecordStatusEnum; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; + +import java.time.LocalDateTime; + +/** + * 佣金记录 DO + * + * @author owen + */ +@TableName("member_brokerage_record") +@KeySequence("member_brokerage_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class MemberBrokerageRecordDO extends BaseDO { + + /** + * 编号 + */ + @TableId + private Integer id; + /** + * 用户编号 + */ + private Long userId; + /** + * 业务编号 + */ + private String bizId; + /** + * 业务类型 + *

+ * 枚举 {@link BrokerageRecordBizTypeEnum 对应的类} + */ + private Integer bizType; + /** + * 标题 + */ + private String title; + /** + * 金额 + */ + private Integer price; + /** + * 当前总佣金 + */ + private Integer totalPrice; + /** + * 说明 + */ + private String description; + /** + * 状态 + *

+ * 枚举 {@link BrokerageRecordStatusEnum 对应的类} + */ + private Integer status; + /** + * 冻结时间(天) + */ + private Integer frozenDays; + /** + * 解冻时间 + */ + private LocalDateTime unfreezeTime; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java index 520d5a7d17..8e6c99aac0 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java @@ -136,4 +136,31 @@ public class MemberUserDO extends TenantBaseDO { */ private Long groupId; + // ========== 分销相关 ========== + + /** + * 推广员编号 + */ + private Long brokerageUserId; + /** + * 推广员绑定时间 + */ + private LocalDateTime brokerageBindTime; + /** + * 是否成为推广员 + */ + private Boolean brokerageEnabled; + /** + * 成为分销员时间 + */ + private LocalDateTime brokerageTime; + /** + * 可用佣金 + */ + private Integer brokeragePrice; + /** + * 冻结佣金 + */ + private Integer frozenBrokeragePrice; + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java new file mode 100644 index 0000000000..52f85c1a1f --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.member.dal.mysql.brokerage.record; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 佣金记录 Mapper + * + * @author owen + */ +@Mapper +public interface MemberBrokerageRecordMapper extends BaseMapperX { + + default PageResult selectPage(MemberBrokerageRecordPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(MemberBrokerageRecordDO::getUserId, reqVO.getUserId()) + .eqIfPresent(MemberBrokerageRecordDO::getBizType, reqVO.getBizType()) + .eqIfPresent(MemberBrokerageRecordDO::getStatus, reqVO.getStatus()) + .betweenIfPresent(MemberBrokerageRecordDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(MemberBrokerageRecordDO::getId)); + } + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java index 902057272c..39a7307c11 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java @@ -1,12 +1,14 @@ package cn.iocoder.yudao.module.member.dal.mysql.user; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.lang.Assert; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserPageReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -62,4 +64,32 @@ public interface MemberUserMapper extends BaseMapperX { .apply("FIND_IN_SET({0}, tag_ids)", tagId)); } + /** + * 更新用户可用佣金(增加) + * + * @param id 用户编号 + * @param incrCount 增加佣金(正数) + */ + default void updateBrokeragePriceIncr(Long id, int incrCount) { + Assert.isTrue(incrCount > 0); + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" brokerage_price = brokerage_price + " + incrCount) + .eq(MemberUserDO::getId, id); + update(null, lambdaUpdateWrapper); + } + + /** + * 更新用户冻结佣金(增加) + * + * @param id 用户编号 + * @param incrCount 增加冻结佣金(正数) + */ + default void updateFrozenBrokeragePriceIncr(Long id, int incrCount) { + Assert.isTrue(incrCount > 0); + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) + .eq(MemberUserDO::getId, id); + update(null, lambdaUpdateWrapper); + } + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordService.java new file mode 100644 index 0000000000..16b82f78f5 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordService.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.member.service.brokerage.record; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.member.api.brokerage.dto.BrokerageAddReqDTO; +import cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; + +import java.util.List; + +/** + * 佣金记录 Service 接口 + * + * @author owen + */ +public interface MemberBrokerageRecordService { + + /** + * 获得佣金记录 + * + * @param id 编号 + * @return 佣金记录 + */ + MemberBrokerageRecordDO getMemberBrokerageRecord(Integer id); + + /** + * 获得佣金记录分页 + * + * @param pageReqVO 分页查询 + * @return 佣金记录分页 + */ + PageResult getMemberBrokerageRecordPage(MemberBrokerageRecordPageReqVO pageReqVO); + + /** + * 增加佣金 + * + * @param userId 会员ID + * @param list 请求参数列表 + */ + void addBrokerage(Long userId, List list); +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java new file mode 100644 index 0000000000..80c753fb59 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java @@ -0,0 +1,151 @@ +package cn.iocoder.yudao.module.member.service.brokerage.record; + +import cn.hutool.core.util.BooleanUtil; +import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.member.api.brokerage.dto.BrokerageAddReqDTO; +import cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.member.convert.brokerage.record.MemberBrokerageRecordConvert; +import cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointConfigDO; +import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; +import cn.iocoder.yudao.module.member.dal.mysql.brokerage.record.MemberBrokerageRecordMapper; +import cn.iocoder.yudao.module.member.service.point.MemberPointConfigService; +import cn.iocoder.yudao.module.member.service.user.MemberUserService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.math.RoundingMode; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; + +/** + * 佣金记录 Service 实现类 + * + * @author owen + */ +@Slf4j +@Service +@Validated +public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordService { + + @Resource + private MemberBrokerageRecordMapper memberBrokerageRecordMapper; + @Resource + private MemberPointConfigService memberConfigService; + @Resource + private MemberUserService memberUserService; + + @Override + public MemberBrokerageRecordDO getMemberBrokerageRecord(Integer id) { + return memberBrokerageRecordMapper.selectById(id); + } + + @Override + public PageResult getMemberBrokerageRecordPage(MemberBrokerageRecordPageReqVO pageReqVO) { + return memberBrokerageRecordMapper.selectPage(pageReqVO); + } + + @Override + public void addBrokerage(Long buyerId, List list) { + MemberPointConfigDO memberConfig = memberConfigService.getPointConfig(); + // 0 未启用分销功能 + if (memberConfig == null || !BooleanUtil.isTrue(memberConfig.getBrokerageEnabled())) { + log.warn("[addBrokerage][增加佣金失败:brokerageEnabled 未配置,buyerId({})", buyerId); + return; + } + + // 1.1 获得一级推广人 + MemberUserDO firstUser = memberUserService.getBrokerageUser(buyerId); + if (firstUser == null || !BooleanUtil.isTrue(firstUser.getBrokerageEnabled())) { + return; + } + + // 1.2 计算一级分佣 + addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqDTO::getSkuFirstBrokeragePrice); + + + // 2.1 获得二级推广员 + MemberUserDO secondUser = memberUserService.getUser(firstUser.getBrokerageUserId()); + if (secondUser == null || !BooleanUtil.isTrue(secondUser.getBrokerageEnabled())) { + return; + } + + // 2.2 计算二级分佣 + addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqDTO::getSkuSecondBrokeragePrice); + } + + /** + * 计算佣金 + * + * @param payPrice 订单支付金额 + * @param percent 商品 SKU 设置的佣金 + * @param skuBrokeragePrice 商品的佣金 + * @return 佣金 + */ + int calculateBrokerage(Integer payPrice, Integer percent, Integer skuBrokeragePrice) { + // 1. 优先使用商品 SKU 设置的佣金 + if (skuBrokeragePrice != null && skuBrokeragePrice > 0) { + return ObjectUtil.defaultIfNull(skuBrokeragePrice, 0); + } + + // 2. 根据订单支付金额计算佣金 + if (payPrice != null && payPrice > 0 && percent != null && percent > 0) { + return NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue(); + } + + return 0; + } + + /** + * 增加用户佣金 + * + * @param user 用户 + * @param list 佣金增加参数列表 + * @param brokerageFrozenDays 冻结天数 + * @param brokeragePercent 佣金比例 + * @param skuBrokeragePriceFun 商品 SKU 设置的佣金 + */ + private void addBrokerage(MemberUserDO user, List list, Integer brokerageFrozenDays, + Integer brokeragePercent, Function skuBrokeragePriceFun) { + // 处理冻结时间 + brokerageFrozenDays = ObjectUtil.defaultIfNull(brokerageFrozenDays, 0); + LocalDateTime unfreezeTime = null; + if (brokerageFrozenDays > 0) { + unfreezeTime = LocalDateTime.now().plusDays(brokerageFrozenDays); + } + + // 计算分佣 + int totalBrokerage = 0; + List records = new ArrayList<>(); + for (BrokerageAddReqDTO dto : list) { + int brokeragePerItem = calculateBrokerage(dto.getPayPrice(), brokeragePercent, skuBrokeragePriceFun.apply(dto)); + if (brokeragePerItem > 0) { + int brokerage = brokeragePerItem * dto.getCount(); + records.add(MemberBrokerageRecordConvert.INSTANCE.convert(user, dto.getBizId(), brokerageFrozenDays, brokerage, unfreezeTime)); + totalBrokerage += brokerage; + } + } + + if (records.isEmpty()) { + return; + } + + // 保存佣金记录 + memberBrokerageRecordMapper.insertBatch(records); + + if (brokerageFrozenDays > 0) { + // 更新用户冻结佣金 + memberUserService.updateUserFrozenBrokeragePrice(user.getId(), totalBrokerage); + } else { + // 更新用户可用佣金 + memberUserService.updateUserBrokeragePrice(user.getId(), totalBrokerage); + } + } + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java index f1a0a72651..206f9f1c7c 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java @@ -166,4 +166,28 @@ public interface MemberUserService { * @param point 积分数量 */ void updateUserPoint(Long userId, Integer point); + + /** + * 获得用户的推广人 + * + * @param id 用户编号 + * @return 用户的推广人 + */ + MemberUserDO getBrokerageUser(Long id); + + /** + * 增加用户佣金 + * + * @param id 用户编号 + * @param brokeragePrice 用户可用佣金 + */ + void updateUserBrokeragePrice(Long id, int brokeragePrice); + + /** + * 增加用户佣金 + * + * @param id 用户编号 + * @param frozenBrokeragePrice 用户冻结佣金 + */ + void updateUserFrozenBrokeragePrice(Long id, int frozenBrokeragePrice); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index c5b674cc8a..db80661c62 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -30,6 +30,7 @@ import javax.validation.Valid; import java.time.LocalDateTime; import java.util.Collection; import java.util.List; +import java.util.Optional; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; @@ -259,4 +260,25 @@ public class MemberUserServiceImpl implements MemberUserService { memberUserMapper.updateById(new MemberUserDO().setId(userId).setPoint(point)); } + @Override + public MemberUserDO getBrokerageUser(Long id) { + return Optional.ofNullable(id) + .map(this::getUser) + .map(MemberUserDO::getBrokerageUserId) + .map(this::getUser) + .orElse(null); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateUserBrokeragePrice(Long id, int brokeragePrice) { + memberUserMapper.updateBrokeragePriceIncr(id, brokeragePrice); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateUserFrozenBrokeragePrice(Long id, int frozenBrokeragePrice) { + memberUserMapper.updateFrozenBrokeragePriceIncr(id, frozenBrokeragePrice); + } + } diff --git a/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImplTest.java b/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImplTest.java new file mode 100644 index 0000000000..d5991b4e8c --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImplTest.java @@ -0,0 +1,116 @@ +package cn.iocoder.yudao.module.member.service.brokerage.record; + +import cn.hutool.core.util.NumberUtil; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; +import cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +import cn.iocoder.yudao.module.member.dal.mysql.brokerage.record.MemberBrokerageRecordMapper; +import cn.iocoder.yudao.module.member.service.point.MemberPointConfigService; +import cn.iocoder.yudao.module.member.service.user.MemberUserService; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; +import java.math.RoundingMode; + +import static cn.hutool.core.util.RandomUtil.randomEle; +import static cn.hutool.core.util.RandomUtil.randomInt; +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomInteger; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * {@link MemberBrokerageRecordServiceImpl} 的单元测试类 + * + * @author owen + */ +@Import(MemberBrokerageRecordServiceImpl.class) +public class MemberBrokerageRecordServiceImplTest extends BaseDbUnitTest { + + @Resource + private MemberBrokerageRecordServiceImpl memberBrokerageRecordService; + @Resource + private MemberBrokerageRecordMapper memberBrokerageRecordMapper; + + @MockBean + private MemberPointConfigService memberPointConfigService; + @MockBean + private MemberUserService memberUserService; + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetMemberBrokerageRecordPage() { + // mock 数据 + MemberBrokerageRecordDO dbMemberBrokerageRecord = randomPojo(MemberBrokerageRecordDO.class, o -> { // 等会查询到 + o.setUserId(null); + o.setBizType(null); + o.setStatus(null); + o.setCreateTime(null); + }); + memberBrokerageRecordMapper.insert(dbMemberBrokerageRecord); + // 测试 userId 不匹配 + memberBrokerageRecordMapper.insert(cloneIgnoreId(dbMemberBrokerageRecord, o -> o.setUserId(null))); + // 测试 bizType 不匹配 + memberBrokerageRecordMapper.insert(cloneIgnoreId(dbMemberBrokerageRecord, o -> o.setBizType(null))); + // 测试 status 不匹配 + memberBrokerageRecordMapper.insert(cloneIgnoreId(dbMemberBrokerageRecord, o -> o.setStatus(null))); + // 测试 createTime 不匹配 + memberBrokerageRecordMapper.insert(cloneIgnoreId(dbMemberBrokerageRecord, o -> o.setCreateTime(null))); + // 准备参数 + MemberBrokerageRecordPageReqVO reqVO = new MemberBrokerageRecordPageReqVO(); + reqVO.setUserId(null); + reqVO.setBizType(null); + reqVO.setStatus(null); + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); + + // 调用 + PageResult pageResult = memberBrokerageRecordService.getMemberBrokerageRecordPage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbMemberBrokerageRecord, pageResult.getList().get(0)); + } + + @Test + public void testCalculateBrokerage_useSkuBrokeragePrice() { + // mock 数据 + Integer payPrice = randomInteger(); + Integer percent = randomInt(1, 101); + Integer skuBrokeragePrice = randomInt(); + // 调用 + int brokerage = memberBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); + // 断言 + assertEquals(brokerage, skuBrokeragePrice); + } + + @Test + public void testCalculateBrokerage_usePercent() { + // mock 数据 + Integer payPrice = randomInteger(); + Integer percent = randomInt(1, 101); + Integer skuBrokeragePrice = randomEle(new Integer[]{0, null}); + System.out.println("skuBrokeragePrice=" + skuBrokeragePrice); + // 调用 + int brokerage = memberBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); + // 断言 + assertEquals(brokerage, NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue()); + } + + @Test + public void testCalculateBrokerage_equalsZero() { + // mock 数据 + Integer payPrice = null; + Integer percent = null; + Integer skuBrokeragePrice = null; + // 调用 + int brokerage = memberBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); + // 断言 + assertEquals(brokerage, 0); + } +} diff --git a/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/clean.sql b/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/clean.sql index f972e048d3..6981982c44 100644 --- a/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/clean.sql +++ b/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/clean.sql @@ -2,4 +2,5 @@ DELETE FROM "member_user"; DELETE FROM "member_address"; DELETE FROM "member_tag"; DELETE FROM "member_level"; -DELETE FROM "member_group"; \ No newline at end of file +DELETE FROM "member_group"; +DELETE FROM "member_brokerage_record"; \ No newline at end of file diff --git a/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/create_tables.sql b/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/create_tables.sql index 5fdc526b03..ccefc4bf1b 100644 --- a/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/create_tables.sql @@ -89,4 +89,25 @@ CREATE TABLE IF NOT EXISTS "member_group" "deleted" bit NOT NULL DEFAULT FALSE, "tenant_id" bigint not null default '0', PRIMARY KEY ("id") -) COMMENT '用户分组'; \ No newline at end of file +) COMMENT '用户分组'; +CREATE TABLE IF NOT EXISTS "member_brokerage_record" +( + "id" int NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "user_id" bigint NOT NULL, + "biz_id" varchar NOT NULL, + "biz_type" varchar NOT NULL, + "title" varchar NOT NULL, + "price" int NOT NULL, + "total_price" int NOT NULL, + "description" varchar NOT NULL, + "status" varchar NOT NULL, + "frozen_days" int NOT NULL, + "unfreeze_time" varchar, + "creator" varchar DEFAULT '', + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar DEFAULT '', + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + "tenant_id" bigint not null default '0', + PRIMARY KEY ("id") +) COMMENT '佣金记录'; \ No newline at end of file From 090058a2ba16bee4f9321dcf7a9839c78c4cf2a2 Mon Sep 17 00:00:00 2001 From: owen Date: Tue, 5 Sep 2023 09:27:12 +0800 Subject: [PATCH 09/48] =?UTF-8?q?member:=20=E4=BD=A3=E9=87=91=E4=B8=8D?= =?UTF-8?q?=E5=86=BB=E7=BB=93=E6=97=B6=EF=BC=8C=E7=9B=B4=E6=8E=A5=E5=B0=B1?= =?UTF-8?q?=E6=98=AF=E7=BB=93=E7=AE=97=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../brokerage/record/MemberBrokerageRecordConvert.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/brokerage/record/MemberBrokerageRecordConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/brokerage/record/MemberBrokerageRecordConvert.java index d36ef1c038..393bacb724 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/brokerage/record/MemberBrokerageRecordConvert.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/brokerage/record/MemberBrokerageRecordConvert.java @@ -30,6 +30,10 @@ public interface MemberBrokerageRecordConvert { PageResult convertPage(PageResult page); default MemberBrokerageRecordDO convert(MemberUserDO user, String bizId, int brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime) { + // 不冻结时,佣金直接就是结算状态 + Integer status = brokerageFrozenDays > 0 + ? BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus() + : BrokerageRecordStatusEnum.SETTLEMENT.getStatus(); return new MemberBrokerageRecordDO() .setUserId(user.getId()) .setBizType(BrokerageRecordBizTypeEnum.ORDER.getType()) @@ -38,7 +42,7 @@ public interface MemberBrokerageRecordConvert { .setTotalPrice(user.getBrokeragePrice()) .setTitle(BrokerageRecordBizTypeEnum.ORDER.getTitle()) .setDescription(StrUtil.format(BrokerageRecordBizTypeEnum.ORDER.getDescription(), String.valueOf(brokerage / 100.0))) - .setStatus(BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus()) + .setStatus(status) .setFrozenDays(brokerageFrozenDays) .setUnfreezeTime(unfreezeTime); } From f3ca0f066b64d43c3b35c9b204e135a18c9529c9 Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Tue, 5 Sep 2023 12:44:34 +0800 Subject: [PATCH 10/48] =?UTF-8?q?=E4=BC=9A=E5=91=98=E9=92=B1=E5=8C=85=20?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=AE=A2=E5=8D=95=E5=92=8C=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=80=80=E6=AC=BE=E5=8D=95=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wallet/PayWalletTransactionMapper.java | 5 +- .../framework/pay/wallet/WalletPayClient.java | 75 ++++++++++++++++++- .../pay/service/wallet/PayWalletService.java | 4 +- .../service/wallet/PayWalletServiceImpl.java | 6 +- .../wallet/PayWalletTransactionService.java | 4 +- .../PayWalletTransactionServiceImpl.java | 6 +- 6 files changed, 81 insertions(+), 19 deletions(-) diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java index 3d329d1184..7831e77bd7 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java @@ -30,9 +30,8 @@ public interface PayWalletTransactionMapper extends BaseMapperX { private PayWalletService wallService; + private PayWalletTransactionService walletTransactionService; + + private PayOrderService payOrderService; + + private PayRefundService payRefundService; + public WalletPayClient(Long channelId, NonePayClientConfig config) { super(channelId, PayChannelEnum.WALLET.getCode(), config); } @@ -38,6 +54,9 @@ public class WalletPayClient extends AbstractPayClient { if (wallService == null) { wallService = SpringUtil.getBean(PayWalletService.class); } + if (walletTransactionService == null) { + walletTransactionService = SpringUtil.getBean(PayWalletTransactionService.class); + } } @Override @@ -47,7 +66,7 @@ public class WalletPayClient extends AbstractPayClient { String userType = MapUtil.getStr(reqDTO.getChannelExtras(), "user_type"); Assert.notEmpty(userId, "用户 id 不能为空"); Assert.notEmpty(userType, "用户类型不能为空"); - PayWalletTransactionDO transaction = wallService.pay(Long.valueOf(userId), Integer.valueOf(userType), + PayWalletTransactionDO transaction = wallService.orderPay(Long.valueOf(userId), Integer.valueOf(userType), reqDTO.getOutTradeNo(), reqDTO.getPrice()); return PayOrderRespDTO.successOf(transaction.getNo(), transaction.getCreator(), transaction.getCreateTime(), @@ -73,13 +92,37 @@ public class WalletPayClient extends AbstractPayClient { @Override protected PayOrderRespDTO doGetOrder(String outTradeNo) { - throw new UnsupportedOperationException("待实现"); + if (payOrderService == null) { + payOrderService = SpringUtil.getBean(PayOrderService.class); + } + PayOrderExtensionDO orderExtension = payOrderService.getOrderExtensionByNo(outTradeNo); + // 支付交易拓展单不存在, 返回关闭状态 + if (orderExtension == null) { + return PayOrderRespDTO.closedOf(String.valueOf(ORDER_EXTENSION_NOT_FOUND.getCode()), + ORDER_EXTENSION_NOT_FOUND.getMsg(), outTradeNo, ""); + } + // 关闭状态 + if (PayOrderStatusEnum.isClosed(orderExtension.getStatus())) { + return PayOrderRespDTO.closedOf(orderExtension.getChannelErrorCode(), + orderExtension.getChannelErrorMsg(), outTradeNo, ""); + } + // 成功状态 + if (PayOrderStatusEnum.isSuccess(orderExtension.getStatus())) { + PayWalletTransactionDO walletTransaction = walletTransactionService.getWalletTransaction( + String.valueOf(orderExtension.getOrderId()), PayWalletBizTypeEnum.PAYMENT); + Assert.notNull(walletTransaction, "支付单 {} 钱包流水不能为空", outTradeNo); + return PayOrderRespDTO.successOf(walletTransaction.getNo(), walletTransaction.getCreator(), + walletTransaction.getCreateTime(), outTradeNo, walletTransaction); + } + // 其它状态为无效状态 + log.error("[doGetOrder] 支付单 {} 的状态不正确", outTradeNo); + throw new IllegalStateException(String.format("支付单[%s] 状态不正确", outTradeNo)); } @Override protected PayRefundRespDTO doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) { try { - PayWalletTransactionDO payWalletTransaction = wallService.refund(reqDTO.getOutRefundNo(), + PayWalletTransactionDO payWalletTransaction = wallService.orderRefund(reqDTO.getOutRefundNo(), reqDTO.getRefundPrice(), reqDTO.getReason()); return PayRefundRespDTO.successOf(payWalletTransaction.getNo(), payWalletTransaction.getCreateTime(), reqDTO.getOutRefundNo(), payWalletTransaction); @@ -104,7 +147,31 @@ public class WalletPayClient extends AbstractPayClient { @Override protected PayRefundRespDTO doGetRefund(String outTradeNo, String outRefundNo) { - throw new UnsupportedOperationException("待实现"); + if (payRefundService == null) { + payRefundService = SpringUtil.getBean(PayRefundService.class); + } + PayRefundDO payRefund = payRefundService.getRefundByNo(outRefundNo); + // 支付退款单不存在, 返回退款失败状态 + if (payRefund == null) { + return PayRefundRespDTO.failureOf(String.valueOf(REFUND_NOT_FOUND), REFUND_NOT_FOUND.getMsg(), + outRefundNo, ""); + } + // 退款失败 + if (PayRefundStatusRespEnum.isFailure(payRefund.getStatus())) { + return PayRefundRespDTO.failureOf(payRefund.getChannelErrorCode(), payRefund.getChannelErrorMsg(), + outRefundNo, ""); + } + // 退款成功 + if (PayRefundStatusRespEnum.isSuccess(payRefund.getStatus())) { + PayWalletTransactionDO walletTransaction = walletTransactionService.getWalletTransaction( + String.valueOf(payRefund.getId()), PayWalletBizTypeEnum.PAYMENT_REFUND); + Assert.notNull(walletTransaction, "支付退款单 {} 钱包流水不能为空", outRefundNo); + return PayRefundRespDTO.successOf(walletTransaction.getNo(), walletTransaction.getCreateTime(), + outRefundNo, walletTransaction); + } + // 其它状态为无效状态 + log.error("[doGetRefund] 支付退款单 {} 的状态不正确", outRefundNo); + throw new IllegalStateException(String.format("支付退款单[%s] 状态不正确", outRefundNo)); } } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java index 370b776a79..3ea75ad09f 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java @@ -27,7 +27,7 @@ public interface PayWalletService { * @param outTradeNo 外部订单号 * @param price 金额 */ - PayWalletTransactionDO pay(Long userId, Integer userType, String outTradeNo, Integer price); + PayWalletTransactionDO orderPay(Long userId, Integer userType, String outTradeNo, Integer price); /** @@ -64,6 +64,6 @@ public interface PayWalletService { * @param refundPrice 退款金额 * @param reason 退款原因 */ - PayWalletTransactionDO refund(String outRefundNo, Integer refundPrice, String reason); + PayWalletTransactionDO orderRefund(String outRefundNo, Integer refundPrice, String reason); } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java index a3606323bd..ea607c0e8c 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java @@ -75,7 +75,7 @@ public class PayWalletServiceImpl implements PayWalletService { @Override @Transactional(rollbackFor = Exception.class) - public PayWalletTransactionDO pay(Long userId, Integer userType, String outTradeNo, Integer price) { + public PayWalletTransactionDO orderPay(Long userId, Integer userType, String outTradeNo, Integer price) { // 判断支付交易拓展单是否存 PayOrderExtensionDO orderExtension = payOrderService.getOrderExtensionByNo(outTradeNo); if (orderExtension == null) { @@ -150,7 +150,7 @@ public class PayWalletServiceImpl implements PayWalletService { @Override @Transactional(rollbackFor = Exception.class) - public PayWalletTransactionDO refund(String outRefundNo, Integer refundPrice, String reason) { + public PayWalletTransactionDO orderRefund(String outRefundNo, Integer refundPrice, String reason) { // 1.1 判断退款单是否存在 PayRefundDO payRefund = payRefundService.getRefundByNo(outRefundNo); if (payRefund == null) { @@ -182,7 +182,7 @@ public class PayWalletServiceImpl implements PayWalletService { throw exception(WALLET_REFUND_AMOUNT_ERROR); } PayWalletTransactionDO refundTransaction = payWalletTransactionService.getWalletTransaction( - payWalletTransaction.getWalletId(), refundId, PAYMENT_REFUND); + String.valueOf(refundId), PAYMENT_REFUND); if (refundTransaction != null) { throw exception(WALLET_REFUND_EXIST); } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java index e0714081bf..432e2f2e00 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java @@ -40,11 +40,9 @@ public interface PayWalletTransactionService { /** * 获取钱包流水 * - * @param walletId 钱包编号 * @param bizId 业务编号 * @param type 业务类型 * @return 钱包流水 */ - PayWalletTransactionDO getWalletTransaction(Long walletId, Long bizId, PayWalletBizTypeEnum type); - + PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type); } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java index 1b156576a2..971f594167 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java @@ -22,7 +22,6 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ @Resource private PayWalletService payWalletService; - @Resource private PayWalletTransactionMapper payWalletTransactionMapper; @@ -45,8 +44,7 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ } @Override - public PayWalletTransactionDO getWalletTransaction(Long walletId, Long bizId, PayWalletBizTypeEnum type) { - return payWalletTransactionMapper.selectByWalletIdAndBiz(walletId, bizId, type.getType()); + public PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type) { + return payWalletTransactionMapper.selectByBiz(bizId, type.getType()); } - } From 2f6092005b09aac72896f67adab6716aa2363083 Mon Sep 17 00:00:00 2001 From: owen Date: Tue, 5 Sep 2023 18:54:00 +0800 Subject: [PATCH 11/48] =?UTF-8?q?member:=20=E4=BD=A3=E9=87=91=E8=A7=A3?= =?UTF-8?q?=E5=86=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/enums/ErrorCodeConstants.java | 1 + .../record/MemberBrokerageRecordMapper.java | 15 +++++ .../dal/mysql/user/MemberUserMapper.java | 16 ++++++ .../MemberBrokerageRecordUnfreezeJob.java | 29 ++++++++++ .../record/MemberBrokerageRecordService.java | 8 +++ .../MemberBrokerageRecordServiceImpl.java | 57 +++++++++++++++++++ .../service/user/MemberUserService.java | 4 +- .../service/user/MemberUserServiceImpl.java | 9 ++- 8 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/job/brokerage/MemberBrokerageRecordUnfreezeJob.java diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java index ba283ab0ce..dc6439e744 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java +++ b/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 { ErrorCode USER_NOT_EXISTS = new ErrorCode(1004001000, "用户不存在"); ErrorCode USER_MOBILE_NOT_EXISTS = new ErrorCode(1004001001, "手机号未注册用户"); ErrorCode USER_MOBILE_USED = new ErrorCode(1004001002, "修改手机失败,该手机号({})已经被使用"); + ErrorCode MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH = new ErrorCode(1004001003, "用户冻结佣金({})数量不足"); // ========== AUTH 模块 1004003000 ========== ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1004003000, "登录失败,账号密码不正确"); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java index 52f85c1a1f..fd3ce05fce 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java @@ -5,8 +5,12 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; +import java.time.LocalDateTime; +import java.util.List; + /** * 佣金记录 Mapper * @@ -24,4 +28,15 @@ public interface MemberBrokerageRecordMapper extends BaseMapperX selectListByStatusAndUnfreezeTimeLt(Integer status, LocalDateTime unfreezeTime) { + return selectList(new LambdaQueryWrapper() + .eq(MemberBrokerageRecordDO::getStatus, status) + .lt(MemberBrokerageRecordDO::getUnfreezeTime, unfreezeTime)); + } + + default int updateByIdAndStatus(Integer id, Integer status, MemberBrokerageRecordDO updateObj) { + return update(updateObj, new LambdaQueryWrapper() + .eq(MemberBrokerageRecordDO::getId, id) + .eq(MemberBrokerageRecordDO::getStatus, status)); + } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java index 39a7307c11..cafe10285b 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java @@ -92,4 +92,20 @@ public interface MemberUserMapper extends BaseMapperX { update(null, lambdaUpdateWrapper); } + /** + * 更新用户冻结佣金(减少) + * + * @param id 用户编号 + * @param incrCount 减少冻结佣金(负数) + * @return 更新条数 + */ + default int updateFrozenBrokeragePriceDecr(Long id, int incrCount) { + Assert.isTrue(incrCount < 0); + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount + // 负数,所以使用 + 号 + ", brokerage_price = brokerage_price + " + -incrCount) // 负数,所以使用 - 号 + .eq(MemberUserDO::getId, id) + .ge(MemberUserDO::getFrozenBrokeragePrice, -incrCount); // cas 逻辑 + return update(null, lambdaUpdateWrapper); + } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/job/brokerage/MemberBrokerageRecordUnfreezeJob.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/job/brokerage/MemberBrokerageRecordUnfreezeJob.java new file mode 100644 index 0000000000..f4512cf089 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/job/brokerage/MemberBrokerageRecordUnfreezeJob.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.member.job.brokerage; + +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; +import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; +import cn.iocoder.yudao.module.member.service.brokerage.record.MemberBrokerageRecordService; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * 佣金解冻 Job + * + * @author owen + */ +@Component +@TenantJob +public class MemberBrokerageRecordUnfreezeJob implements JobHandler { + + @Resource + private MemberBrokerageRecordService memberBrokerageRecordService; + + @Override + public String execute(String param) { + int count = memberBrokerageRecordService.unfreezeRecord(); + return StrUtil.format("解冻佣金 {} 个", count); + } + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordService.java index 16b82f78f5..1d0f4e8168 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordService.java @@ -37,4 +37,12 @@ public interface MemberBrokerageRecordService { * @param list 请求参数列表 */ void addBrokerage(Long userId, List list); + + /** + * 解冻佣金:将待结算的佣金记录,状态修改为已结算 + * + * @return 解冻佣金的数量 + */ + int unfreezeRecord(); + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java index 80c753fb59..58dc25af51 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java @@ -1,8 +1,10 @@ package cn.iocoder.yudao.module.member.service.brokerage.record; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.brokerage.dto.BrokerageAddReqDTO; import cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; @@ -11,10 +13,12 @@ import cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record.MemberBrok import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointConfigDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.dal.mysql.brokerage.record.MemberBrokerageRecordMapper; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageRecordStatusEnum; import cn.iocoder.yudao.module.member.service.point.MemberPointConfigService; import cn.iocoder.yudao.module.member.service.user.MemberUserService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; @@ -52,6 +56,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe } @Override + @Transactional(rollbackFor = Exception.class) public void addBrokerage(Long buyerId, List list) { MemberPointConfigDO memberConfig = memberConfigService.getPointConfig(); // 0 未启用分销功能 @@ -148,4 +153,56 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe } } + @Override + public int unfreezeRecord() { + // 1. 查询待结算的佣金记录 + List records = memberBrokerageRecordMapper.selectListByStatusAndUnfreezeTimeLt( + BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus(), LocalDateTime.now()); + if (CollUtil.isEmpty(records)) { + return 0; + } + + // 2. 遍历执行 + int count = 0; + for (MemberBrokerageRecordDO record : records) { + try { + boolean successful = getSelf().unfreezeRecord(record); + if (successful) { + count++; + } + } catch (Exception e) { + log.error("[unfreezeRecord][record({}) 更新为已结算失败]", record.getId(), e); + } + } + return count; + } + + @Transactional(rollbackFor = Exception.class) + public boolean unfreezeRecord(MemberBrokerageRecordDO record) { + // 更新记录状态 + MemberBrokerageRecordDO updateObj = new MemberBrokerageRecordDO() + .setStatus(BrokerageRecordStatusEnum.SETTLEMENT.getStatus()) + .setUnfreezeTime(LocalDateTime.now()); + int updateRows = memberBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); + if (updateRows == 0) { + log.error("[unfreezeRecord][record({}) 更新为已结算失败]", record.getId()); + return false; + } + + // 更新用户冻结佣金 + memberUserService.updateUserFrozenBrokeragePrice(record.getUserId(), record.getPrice()); + + log.info("[unfreezeRecord][record({}) 更新为已结算成功]", record.getId()); + return true; + } + + /** + * 获得自身的代理对象,解决 AOP 生效问题 + * + * @return 自己 + */ + private MemberBrokerageRecordServiceImpl getSelf() { + return SpringUtil.getBean(getClass()); + } + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java index 206f9f1c7c..380ad2c6c9 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java @@ -176,7 +176,7 @@ public interface MemberUserService { MemberUserDO getBrokerageUser(Long id); /** - * 增加用户佣金 + * 更新用户佣金 * * @param id 用户编号 * @param brokeragePrice 用户可用佣金 @@ -184,7 +184,7 @@ public interface MemberUserService { void updateUserBrokeragePrice(Long id, int brokeragePrice); /** - * 增加用户佣金 + * 更新用户冻结佣金 * * @param id 用户编号 * @param frozenBrokeragePrice 用户冻结佣金 diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index db80661c62..0bd17facfd 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -278,7 +278,14 @@ public class MemberUserServiceImpl implements MemberUserService { @Override @Transactional(rollbackFor = Exception.class) public void updateUserFrozenBrokeragePrice(Long id, int frozenBrokeragePrice) { - memberUserMapper.updateFrozenBrokeragePriceIncr(id, frozenBrokeragePrice); + if (frozenBrokeragePrice > 0) { + memberUserMapper.updateFrozenBrokeragePriceIncr(id, frozenBrokeragePrice); + } else if (frozenBrokeragePrice < 0) { + int updateRows = memberUserMapper.updateFrozenBrokeragePriceDecr(id, frozenBrokeragePrice); + if (updateRows == 0) { + throw exception(MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH); + } + } } } From a708521b9d010bb960eb3434c8007df7ead9e21f Mon Sep 17 00:00:00 2001 From: owen Date: Tue, 5 Sep 2023 19:05:01 +0800 Subject: [PATCH 12/48] =?UTF-8?q?member:=20=E4=BD=A3=E9=87=91=E8=A7=A3?= =?UTF-8?q?=E5=86=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../brokerage/record/MemberBrokerageRecordServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java index 58dc25af51..c3d6bcebcb 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java @@ -190,7 +190,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe } // 更新用户冻结佣金 - memberUserService.updateUserFrozenBrokeragePrice(record.getUserId(), record.getPrice()); + memberUserService.updateUserFrozenBrokeragePrice(record.getUserId(), -record.getPrice()); log.info("[unfreezeRecord][record({}) 更新为已结算成功]", record.getId()); return true; From 9eb7837b67c0ed8b9d4e85efac33372a0a79ae27 Mon Sep 17 00:00:00 2001 From: owen Date: Tue, 5 Sep 2023 19:43:07 +0800 Subject: [PATCH 13/48] =?UTF-8?q?member:=20=E4=BD=A3=E9=87=91=E5=A4=B1?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/TradeOrderUpdateServiceImpl.java | 9 ++++-- .../api/brokerage/BrokerageApiImpl.java | 2 +- .../record/MemberBrokerageRecordMapper.java | 5 +++ .../dal/mysql/user/MemberUserMapper.java | 32 ++++++++++++++++++- .../record/MemberBrokerageRecordService.java | 10 ++++-- .../MemberBrokerageRecordServiceImpl.java | 26 ++++++++++++++- .../service/user/MemberUserService.java | 8 +++++ .../service/user/MemberUserServiceImpl.java | 22 ++++++++++--- 8 files changed, 102 insertions(+), 12 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index afb125e083..e2a0f6baf9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -635,12 +635,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { .setRefundStatus(TradeOrderRefundStatusEnum.PART.getStatus()).setRefundPrice(orderRefundPrice)); } - // TODO 芋艿:未来如果有分佣,需要更新相关分佣订单为已失效 - // 扣减用户积分 getSelf().reduceUserPointAsync(order.getUserId(), orderRefundPrice, afterSaleId); // 扣减用户经验 getSelf().reduceUserExperienceAsync(order.getUserId(), orderRefundPrice, afterSaleId); + // 更新分佣记录为已失效 + getSelf().cancelBrokerageAsync(order.getUserId(), id); } @Override @@ -757,6 +757,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { brokerageApi.addBrokerage(userId, list); } + @Async + protected void cancelBrokerageAsync(Long userId, Long orderItemId) { + brokerageApi.cancelBrokerage(userId, String.valueOf(orderItemId)); + } + /** * 获得自身的代理对象,解决 AOP 生效问题 * diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApiImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApiImpl.java index 2891bdcc1e..662c5165a8 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApiImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApiImpl.java @@ -27,6 +27,6 @@ public class BrokerageApiImpl implements BrokerageApi { @Override public void cancelBrokerage(Long userId, String bizId) { - + memberBrokerageRecordService.cancelBrokerage(userId, bizId); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java index fd3ce05fce..52154aea50 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java @@ -39,4 +39,9 @@ public interface MemberBrokerageRecordMapper extends BaseMapperX { update(null, lambdaUpdateWrapper); } + /** + * 更新用户可用佣金(减少) + * 注意:理论上佣金可能已经提现,这时会扣出负数,确保平台不会造成损失 + * + * @param id 用户编号 + * @param incrCount 增加佣金(负数) + */ + default void updateBrokeragePriceDecr(Long id, int incrCount) { + Assert.isTrue(incrCount < 0); + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" brokerage_price = brokerage_price + " + incrCount) // 负数,所以使用 + 号 + .eq(MemberUserDO::getId, id); + update(null, lambdaUpdateWrapper); + } + /** * 更新用户冻结佣金(增加) * @@ -94,12 +109,27 @@ public interface MemberUserMapper extends BaseMapperX { /** * 更新用户冻结佣金(减少) + * 注意:理论上冻结佣金可能已经解冻,这时会扣出负数,确保平台不会造成损失 + * + * @param id 用户编号 + * @param incrCount 减少冻结佣金(负数) + */ + default void updateFrozenBrokeragePriceDecr(Long id, int incrCount) { + Assert.isTrue(incrCount < 0); + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) // 负数,所以使用 + 号 + .eq(MemberUserDO::getId, id); + update(null, lambdaUpdateWrapper); + } + + /** + * 更新用户冻结佣金(减少), 更新用户佣金(增加) * * @param id 用户编号 * @param incrCount 减少冻结佣金(负数) * @return 更新条数 */ - default int updateFrozenBrokeragePriceDecr(Long id, int incrCount) { + default int updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int incrCount) { Assert.isTrue(incrCount < 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount + // 负数,所以使用 + 号 diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordService.java index 1d0f4e8168..cd966e670c 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordService.java @@ -33,16 +33,22 @@ public interface MemberBrokerageRecordService { /** * 增加佣金 * - * @param userId 会员ID + * @param userId 会员编号 * @param list 请求参数列表 */ void addBrokerage(Long userId, List list); + /** + * 取消佣金:将佣金记录,状态修改为已失效 + * @param userId 会员编号 + * @param bizId 业务编号 + */ + void cancelBrokerage(Long userId, String bizId); + /** * 解冻佣金:将待结算的佣金记录,状态修改为已结算 * * @return 解冻佣金的数量 */ int unfreezeRecord(); - } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java index c3d6bcebcb..32656910c1 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java @@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record.MemberBrok import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointConfigDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.dal.mysql.brokerage.record.MemberBrokerageRecordMapper; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageRecordStatusEnum; import cn.iocoder.yudao.module.member.service.point.MemberPointConfigService; import cn.iocoder.yudao.module.member.service.user.MemberUserService; @@ -85,6 +86,29 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqDTO::getSkuSecondBrokeragePrice); } + @Override + @Transactional(rollbackFor = Exception.class) + public void cancelBrokerage(Long userId, String bizId) { + MemberBrokerageRecordDO record = memberBrokerageRecordMapper.selectByUserIdAndBizTypeAndBizId(BrokerageRecordBizTypeEnum.ORDER.getType(), bizId); + if (record == null || ObjectUtil.notEqual(record.getUserId(), userId)) { + log.error("[cancelBrokerage][userId({})][bizId({}) 更新为已失效失败:记录不存在]", userId, bizId); + return; + } + + MemberBrokerageRecordDO updateObj = new MemberBrokerageRecordDO().setStatus(BrokerageRecordStatusEnum.CANCEL.getStatus()); + int updateRows = memberBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); + if (updateRows == 0) { + log.error("[cancelBrokerage][record({}) 更新为已失效失败]", record.getId()); + return; + } + + if (BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus().equals(record.getStatus())) { + memberUserService.updateUserFrozenBrokeragePrice(userId, -record.getPrice()); + } else if (BrokerageRecordStatusEnum.SETTLEMENT.getStatus().equals(record.getStatus())) { + memberUserService.updateUserBrokeragePrice(userId, -record.getPrice()); + } + } + /** * 计算佣金 * @@ -190,7 +214,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe } // 更新用户冻结佣金 - memberUserService.updateUserFrozenBrokeragePrice(record.getUserId(), -record.getPrice()); + memberUserService.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(record.getUserId(), -record.getPrice()); log.info("[unfreezeRecord][record({}) 更新为已结算成功]", record.getId()); return true; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java index 380ad2c6c9..7f599a0499 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java @@ -190,4 +190,12 @@ public interface MemberUserService { * @param frozenBrokeragePrice 用户冻结佣金 */ void updateUserFrozenBrokeragePrice(Long id, int frozenBrokeragePrice); + + /** + * 更新用户冻结佣金(减少), 更新用户佣金(增加) + * + * @param id 用户编号 + * @param frozenBrokeragePrice 减少冻结佣金(负数) + */ + void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index 0bd17facfd..53b452d7c4 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.member.service.user; +import cn.hutool.core.lang.Assert; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; @@ -272,7 +273,11 @@ public class MemberUserServiceImpl implements MemberUserService { @Override @Transactional(rollbackFor = Exception.class) public void updateUserBrokeragePrice(Long id, int brokeragePrice) { - memberUserMapper.updateBrokeragePriceIncr(id, brokeragePrice); + if (brokeragePrice > 0) { + memberUserMapper.updateBrokeragePriceIncr(id, brokeragePrice); + } else if (brokeragePrice < 0) { + memberUserMapper.updateBrokeragePriceDecr(id, brokeragePrice); + } } @Override @@ -281,10 +286,17 @@ public class MemberUserServiceImpl implements MemberUserService { if (frozenBrokeragePrice > 0) { memberUserMapper.updateFrozenBrokeragePriceIncr(id, frozenBrokeragePrice); } else if (frozenBrokeragePrice < 0) { - int updateRows = memberUserMapper.updateFrozenBrokeragePriceDecr(id, frozenBrokeragePrice); - if (updateRows == 0) { - throw exception(MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH); - } + memberUserMapper.updateFrozenBrokeragePriceDecr(id, frozenBrokeragePrice); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice) { + Assert.isTrue(frozenBrokeragePrice < 0); + int updateRows = memberUserMapper.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(id, frozenBrokeragePrice); + if (updateRows == 0) { + throw exception(MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH); } } From 0329f13fbf89c2026b2ab590d461f1f6c94e7224 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 5 Sep 2023 21:32:34 +0800 Subject: [PATCH 14/48] =?UTF-8?q?=E5=88=86=E4=BD=A3=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=8E=B7=E5=BE=97=E5=88=86=E9=94=80=E6=8E=92=E8=A1=8C?= =?UTF-8?q?=E5=88=86=E9=A1=B5=20API=20mock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppBrokerageRecordController.java | 8 +- .../brokerage/AppBrokerageUserController.java | 93 +++++++++++++++++++ .../AppBrokerageWithdrawController.java | 6 +- .../record/AppBrokerageRecordPageReqVO.java | 2 +- .../vo/record/AppBrokerageRecordRespVO.java | 2 +- .../AppBrokerageUserRankByPriceRespVO.java | 22 +++++ ...AppBrokerageUserRankByUserCountRespVO.java | 6 +- .../user/AppBrokerageUserRankPageReqVO.java | 2 +- .../user/AppBrokerageUserSummaryRespVO.java | 2 +- .../withdraw/AppBrokerageWithdrawRespVO.java | 2 +- .../brokerage/AppBrokerageUserController.java | 59 ------------ 11 files changed, 130 insertions(+), 74 deletions(-) rename {yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade}/controller/app/brokerage/AppBrokerageRecordController.java (84%) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java rename {yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade}/controller/app/brokerage/AppBrokerageWithdrawController.java (87%) rename {yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade}/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java (88%) rename {yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade}/controller/app/brokerage/vo/record/AppBrokerageRecordRespVO.java (92%) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserRankRespVO.java => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByUserCountRespVO.java (75%) rename {yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade}/controller/app/brokerage/vo/user/AppBrokerageUserRankPageReqVO.java (91%) rename {yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade}/controller/app/brokerage/vo/user/AppBrokerageUserSummaryRespVO.java (92%) rename {yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade}/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawRespVO.java (92%) delete mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageUserController.java diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageRecordController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java similarity index 84% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageRecordController.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java index 8cf4d81e8d..d4c72028fd 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageRecordController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java @@ -1,10 +1,10 @@ -package cn.iocoder.yudao.module.member.controller.app.brokerage; +package cn.iocoder.yudao.module.trade.controller.app.brokerage; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; -import cn.iocoder.yudao.module.member.controller.app.brokerage.vo.record.AppBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.member.controller.app.brokerage.vo.record.AppBrokerageRecordRespVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordRespVO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; @@ -21,7 +21,7 @@ import static java.util.Arrays.asList; @Tag(name = "用户 APP - 分销用户") @RestController -@RequestMapping("/member/brokerage-record") +@RequestMapping("/trade/brokerage-record") @Validated @Slf4j public class AppBrokerageRecordController { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java new file mode 100644 index 0000000000..dd3d17ff70 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -0,0 +1,93 @@ +package cn.iocoder.yudao.module.trade.controller.app.brokerage; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserSummaryRespVO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; +import static java.util.Arrays.asList; + +@Tag(name = "用户 APP - 分销用户") +@RestController +@RequestMapping("/trade/brokerage-user") +@Validated +@Slf4j +public class AppBrokerageUserController { + + // TODO 芋艿:临时 mock => + @GetMapping("/get-summary") + @Operation(summary = "获得个人分销统计") + @PreAuthenticated + public CommonResult getBrokerageUserSummary() { + AppBrokerageUserSummaryRespVO respVO = new AppBrokerageUserSummaryRespVO() + .setYesterdayBrokeragePrice(1) + .setBrokeragePrice(2) + .setFrozenBrokeragePrice(3) + .setWithdrawBrokeragePrice(4); + return success(respVO); + } + + @GetMapping("/rank-page-by-user-count") + @Operation(summary = "获得分销用户排行分页(基于用户量)") + @PreAuthenticated + public CommonResult> getBrokerageUserRankPageByUserCount(AppBrokerageUserRankPageReqVO pageReqVO) { + AppBrokerageUserRankByUserCountRespVO vo1 = new AppBrokerageUserRankByUserCountRespVO() + .setUserId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setBrokerageUserCount(10); + AppBrokerageUserRankByUserCountRespVO vo2 = new AppBrokerageUserRankByUserCountRespVO() + .setUserId(2L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setBrokerageUserCount(6); + AppBrokerageUserRankByUserCountRespVO vo3 = new AppBrokerageUserRankByUserCountRespVO() + .setUserId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setBrokerageUserCount(4); + AppBrokerageUserRankByUserCountRespVO vo4 = new AppBrokerageUserRankByUserCountRespVO() + .setUserId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setBrokerageUserCount(4); + return success(new PageResult<>(asList(vo1, vo2, vo3, vo4), 10L)); + } + + @GetMapping("/rank-page-by-price") + @Operation(summary = "获得分销用户排行分页(基于佣金)") + @PreAuthenticated + public CommonResult> getBrokerageUserRankPageByPrice(AppBrokerageUserRankPageReqVO pageReqVO) { + AppBrokerageUserRankByPriceRespVO vo1 = new AppBrokerageUserRankByPriceRespVO() + .setUserId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setBrokeragePrice(10); + AppBrokerageUserRankByPriceRespVO vo2 = new AppBrokerageUserRankByPriceRespVO() + .setUserId(2L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setBrokeragePrice(6); + AppBrokerageUserRankByPriceRespVO vo3 = new AppBrokerageUserRankByPriceRespVO() + .setUserId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setBrokeragePrice(4); + AppBrokerageUserRankByPriceRespVO vo4 = new AppBrokerageUserRankByPriceRespVO() + .setUserId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setBrokeragePrice(4); + return success(new PageResult<>(asList(vo1, vo2, vo3, vo4), 10L)); + } + + @GetMapping("/get-rank-by-price") + @Operation(summary = "获得分销用户排行(基于佣金)") + @Parameter(name = "times", description = "时间段", required = true) + public CommonResult getBrokerageUserRankByPrice( + @RequestParam("times") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) LocalDateTime[] times) { + return success(1); + } + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageWithdrawController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java similarity index 87% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageWithdrawController.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java index dde0a8a033..1f69b35937 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageWithdrawController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java @@ -1,9 +1,9 @@ -package cn.iocoder.yudao.module.member.controller.app.brokerage; +package cn.iocoder.yudao.module.trade.controller.app.brokerage; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; -import cn.iocoder.yudao.module.member.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; @@ -19,7 +19,7 @@ import static java.util.Arrays.asList; @Tag(name = "用户 APP - 分销提现") @RestController -@RequestMapping("/member/brokerage-withdraw") +@RequestMapping("/trade/brokerage-withdraw") @Validated @Slf4j public class AppBrokerageWithdrawController { diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java similarity index 88% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java index c8bfabd5c1..b7675e6ec1 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.member.controller.app.brokerage.vo.record; +package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record; import cn.iocoder.yudao.framework.common.pojo.PageParam; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageRecordRespVO.java similarity index 92% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordRespVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageRecordRespVO.java index 0459e15f92..221d197587 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/record/AppBrokerageRecordRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageRecordRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.member.controller.app.brokerage.vo.record; +package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java new file mode 100644 index 0000000000..28dab5f8f8 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "用户 App - 分销排行用户(基于用户量) Response VO") +@Data +public class AppBrokerageUserRankByPriceRespVO { + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Long userId; + + @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小王") + private String nickname; + + @Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "http://www.iocoder.cn/xxx.jpg") + private String avatar; + + @Schema(description = "佣金金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Integer brokeragePrice; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserRankRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByUserCountRespVO.java similarity index 75% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserRankRespVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByUserCountRespVO.java index 7835f55321..f0ea2e6c32 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserRankRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByUserCountRespVO.java @@ -1,11 +1,11 @@ -package cn.iocoder.yudao.module.member.controller.app.brokerage.vo.user; +package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -@Schema(description = "用户 App - 分销排行用户 Response VO") +@Schema(description = "用户 App - 分销排行用户(基于用户量) Response VO") @Data -public class AppBrokerageUserRankRespVO { +public class AppBrokerageUserRankByUserCountRespVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") private Long userId; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserRankPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankPageReqVO.java similarity index 91% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserRankPageReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankPageReqVO.java index 0ba1e9c75c..de1d61a7b4 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserRankPageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankPageReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.member.controller.app.brokerage.vo.user; +package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user; import cn.iocoder.yudao.framework.common.pojo.PageParam; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserSummaryRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserSummaryRespVO.java similarity index 92% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserSummaryRespVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserSummaryRespVO.java index 6357052530..5779d80108 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/user/AppBrokerageUserSummaryRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserSummaryRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.member.controller.app.brokerage.vo.user; +package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawRespVO.java similarity index 92% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawRespVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawRespVO.java index 3a3670097a..4cfe930c8a 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.member.controller.app.brokerage.vo.withdraw; +package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageUserController.java deleted file mode 100644 index 1b5bc6184e..0000000000 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/brokerage/AppBrokerageUserController.java +++ /dev/null @@ -1,59 +0,0 @@ -package cn.iocoder.yudao.module.member.controller.app.brokerage; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; -import cn.iocoder.yudao.module.member.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO; -import cn.iocoder.yudao.module.member.controller.app.brokerage.vo.user.AppBrokerageUserRankRespVO; -import cn.iocoder.yudao.module.member.controller.app.brokerage.vo.user.AppBrokerageUserSummaryRespVO; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.extern.slf4j.Slf4j; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static java.util.Arrays.asList; - -@Tag(name = "用户 APP - 分销用户") -@RestController -@RequestMapping("/member/brokerage-user") -@Validated -@Slf4j -public class AppBrokerageUserController { - - // TODO 芋艿:临时 mock => - @GetMapping("/get-summary") - @Operation(summary = "获得个人分销统计") - @PreAuthenticated - public CommonResult getBrokerageUserSummary() { - AppBrokerageUserSummaryRespVO respVO = new AppBrokerageUserSummaryRespVO() - .setYesterdayBrokeragePrice(1) - .setBrokeragePrice(2) - .setFrozenBrokeragePrice(3) - .setWithdrawBrokeragePrice(4); - return success(respVO); - } - - @GetMapping("/rank-page") - @Operation(summary = "获得分销用户排行分页") - @PreAuthenticated - public CommonResult> getBrokerageUserRankPage(AppBrokerageUserRankPageReqVO pageReqVO) { - AppBrokerageUserRankRespVO vo1 = new AppBrokerageUserRankRespVO() - .setUserId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokerageUserCount(10); - AppBrokerageUserRankRespVO vo2 = new AppBrokerageUserRankRespVO() - .setUserId(2L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokerageUserCount(6); - AppBrokerageUserRankRespVO vo3 = new AppBrokerageUserRankRespVO() - .setUserId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokerageUserCount(4); - AppBrokerageUserRankRespVO vo4 = new AppBrokerageUserRankRespVO() - .setUserId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokerageUserCount(4); - return success(new PageResult<>(asList(vo1, vo2, vo3, vo4), 10L)); - } - -} From 64745027380a7e4d99cda3d5af2d393c084171c5 Mon Sep 17 00:00:00 2001 From: owen Date: Tue, 5 Sep 2023 22:31:36 +0800 Subject: [PATCH 15/48] =?UTF-8?q?trade:=20=E5=A2=9E=E5=8A=A0=E4=BA=A4?= =?UTF-8?q?=E6=98=93=E4=B8=AD=E5=BF=83=E9=85=8D=E7=BD=AE=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/brokerage.sql | 55 +++++++----- .../admin/config/TradeConfigController.java | 45 ++++++++++ .../admin/config/vo/TradeConfigBaseVO.java | 71 +++++++++++++++ .../admin/config/vo/TradeConfigRespVO.java | 17 ++++ .../admin/config/vo/TradeConfigSaveReqVO.java | 14 +++ .../convert/config/TradeConfigConvert.java | 23 +++++ .../dal/dataobject/config/TradeConfigDO.java | 90 +++++++++++++++++++ .../dal/mysql/config/TradeConfigMapper.java | 15 ++++ .../service/config/TradeConfigService.java | 30 +++++++ .../config/TradeConfigServiceImpl.java | 44 +++++++++ 10 files changed, 384 insertions(+), 20 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/TradeConfigController.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigRespVO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigSaveReqVO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/config/TradeConfigConvert.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/config/TradeConfigMapper.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigService.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigServiceImpl.java diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index 187e07621d..ed8c5fcbe1 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -1,24 +1,25 @@ -- 增加配置 -alter table member_point_config - add column brokerage_enabled bit default 1 not null comment '是否启用分佣'; -alter table member_point_config - add column brokerage_enabled_condition tinyint default 0 not null comment '分佣模式:0-人人分销 1-指定分销'; -alter table member_point_config - add column brokerage_bind_mode tinyint default 0 not null comment '分销关系绑定模式: 0-没有推广人,1-新用户'; -alter table member_point_config - add column brokerage_post_urls varchar(2000) null comment '分销海报图地址数组'; -alter table member_point_config - add column brokerage_first_percent int not null comment '一级返佣比例'; -alter table member_point_config - add column brokerage_second_percent int not null comment '二级返佣比例'; -alter table member_point_config - add column brokerage_withdraw_min_price int not null comment '用户提现最低金额'; -alter table member_point_config - add column brokerage_bank_names varchar(200) not null comment '提现银行(字典类型=brokerage_bank_name)'; -alter table member_point_config - add column brokerage_frozen_days int default 7 not null comment '佣金冻结时间(天)'; -alter table member_point_config - add column brokerage_withdraw_type varchar(32) default '1,2,3,4' not null comment '提现方式:1-钱包;2-银行卡;3-微信;4-支付宝'; +create table trade_config +( + id bigint auto_increment comment '自增主键' + primary key, + brokerage_enabled bit default 1 not null comment '是否启用分佣', + brokerage_enabled_condition tinyint default 0 not null comment '分佣模式:0-人人分销 1-指定分销', + brokerage_bind_mode tinyint default 0 not null comment '分销关系绑定模式: 0-没有推广人,1-新用户', + brokerage_post_urls varchar(2000) default '' null comment '分销海报图地址数组', + brokerage_first_percent int default 0 not null comment '一级返佣比例', + brokerage_second_percent int default 0 not null comment '二级返佣比例', + brokerage_withdraw_min_price int default 0 not null comment '用户提现最低金额', + brokerage_bank_names varchar(200) default '' not null comment '提现银行(字典类型=brokerage_bank_name)', + brokerage_frozen_days int default 7 not null comment '佣金冻结时间(天)', + brokerage_withdraw_type varchar(32) default '1,2,3,4' not null comment '提现方式:1-钱包;2-银行卡;3-微信;4-支付宝', + creator varchar(64) collate utf8mb4_unicode_ci default '' null comment '创建者', + create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', + updater varchar(64) collate utf8mb4_unicode_ci default '' null comment '更新者', + update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', + deleted bit default b'0' not null comment '是否删除', + tenant_id bigint default 0 not null comment '租户编号' +) comment '交易中心配置'; -- 用户表增加分销相关字段 alter table member_user @@ -187,3 +188,17 @@ SELECT @parentId := LAST_INSERT_ID(); -- 按钮 SQL INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) VALUES ('佣金提现查询', 'member:brokerage-withdraw:query', 3, 1, @parentId, '', '', '', 0); + +-- 交易中心配置:菜单 SQL +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name) +VALUES ('交易中心配置', '', 2, 0, 2072, 'config', '', 'trade/config/index', 0, 'TradeConfig'); + +-- 按钮父菜单ID +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 +SELECT @parentId := LAST_INSERT_ID(); + +-- 按钮 SQL +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('交易中心配置查询', 'trade:config:query', 3, 1, @parentId, '', '', '', 0); +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('交易中心配置保存', 'trade:config:save', 3, 2, @parentId, '', '', '', 0); \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/TradeConfigController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/TradeConfigController.java new file mode 100644 index 0000000000..e41f980816 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/TradeConfigController.java @@ -0,0 +1,45 @@ +package cn.iocoder.yudao.module.trade.controller.admin.config; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigRespVO; +import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigSaveReqVO; +import cn.iocoder.yudao.module.trade.convert.config.TradeConfigConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; +import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "管理后台 - 交易中心配置") +@RestController +@RequestMapping("/trade/config") +@Validated +public class TradeConfigController { + + @Resource + private TradeConfigService tradeConfigService; + + @PutMapping("/save") + @Operation(summary = "更新交易中心配置") + @PreAuthorize("@ss.hasPermission('trade:config:save')") + public CommonResult updateConfig(@Valid @RequestBody TradeConfigSaveReqVO updateReqVO) { + tradeConfigService.saveTradeConfig(updateReqVO); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得交易中心配置") + @PreAuthorize("@ss.hasPermission('trade:config:query')") + public CommonResult getConfig() { + TradeConfigDO config = tradeConfigService.getTradeConfig(); + return success(TradeConfigConvert.INSTANCE.convert(config)); + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java new file mode 100644 index 0000000000..4ee51e3b84 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java @@ -0,0 +1,71 @@ +package cn.iocoder.yudao.module.trade.controller.admin.config.vo; + +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageBindModeEnum; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageEnabledConditionEnum; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageWithdrawTypeEnum; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.hibernate.validator.constraints.Range; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.PositiveOrZero; +import java.util.List; + +/** + * 交易中心配置 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ +@Data +public class TradeConfigBaseVO { + + // ========== 分销相关 ========== + + @Schema(description = "是否启用分佣", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") + @NotNull(message = "是否启用分佣不能为空") + private Boolean brokerageEnabled; + + @Schema(description = "分佣模式", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") + @NotNull(message = "分佣模式不能为空") + @InEnum(value = BrokerageEnabledConditionEnum.class, message = "分佣模式必须是 {value}") + private Integer brokerageEnabledCondition; + + @Schema(description = "分销关系绑定模式", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") + @NotNull(message = "分销关系绑定模式不能为空") + @InEnum(value = BrokerageBindModeEnum.class, message = "分销关系绑定模式必须是 {value}") + private Integer brokerageBindMode; + + @Schema(description = "分销海报图地址数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/yudao.jpg]") + private List brokeragePostUrls; + + @Schema(description = "一级返佣比例", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") + @NotNull(message = "一级返佣比例不能为空") + @Range(min = 0, max = 100, message = "一级返佣比例必须在 0 - 100 之间") + private Integer brokerageFirstPercent; + + @Schema(description = "二级返佣比例", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") + @NotNull(message = "二级返佣比例不能为空") + @Range(min = 0, max = 100, message = "二级返佣比例必须在 0 - 100 之间") + private Integer brokerageSecondPercent; + + @Schema(description = "用户提现最低金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") + @NotNull(message = "用户提现最低金额不能为空") + @PositiveOrZero(message = "用户提现最低金额不能是负数") + private Integer brokerageWithdrawMinPrice; + + @Schema(description = "提现银行", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]") + @NotEmpty(message = "提现银行不能为空") + private List brokerageBankNames; + + @Schema(description = "佣金冻结时间(天)", requiredMode = Schema.RequiredMode.REQUIRED, example = "7") + @NotNull(message = "佣金冻结时间(天)不能为空") + @PositiveOrZero(message = "佣金冻结时间不能是负数") + private Integer brokerageFrozenDays; + + @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]") + @NotNull(message = "提现方式不能为空") + @InEnum(value = BrokerageWithdrawTypeEnum.class, message = "提现方式必须是 {value}") + private List brokerageWithdrawType; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigRespVO.java new file mode 100644 index 0000000000..52aff751fb --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigRespVO.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.module.trade.controller.admin.config.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +@Schema(description = "管理后台 - 交易中心配置 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class TradeConfigRespVO extends TradeConfigBaseVO { + + @Schema(description = "自增主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Long id; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigSaveReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigSaveReqVO.java new file mode 100644 index 0000000000..03a0c41dfb --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigSaveReqVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.trade.controller.admin.config.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +@Schema(description = "管理后台 - 交易中心配置更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class TradeConfigSaveReqVO extends TradeConfigBaseVO { + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/config/TradeConfigConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/config/TradeConfigConvert.java new file mode 100644 index 0000000000..031f1198aa --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/config/TradeConfigConvert.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.module.trade.convert.config; + +import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigRespVO; +import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigSaveReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * 交易中心配置 Convert + * + * @author owen + */ +@Mapper +public interface TradeConfigConvert { + + TradeConfigConvert INSTANCE = Mappers.getMapper(TradeConfigConvert.class); + + TradeConfigDO convert(TradeConfigSaveReqVO bean); + + TradeConfigRespVO convert(TradeConfigDO bean); + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java new file mode 100644 index 0000000000..5538186e1e --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java @@ -0,0 +1,90 @@ +package cn.iocoder.yudao.module.trade.dal.dataobject.config; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.framework.mybatis.core.type.IntegerListTypeHandler; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageBindModeEnum; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageEnabledConditionEnum; +import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageWithdrawTypeEnum; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; +import lombok.*; + +import java.util.List; + +/** + * 交易中心配置 DO + * + * @author owen + */ +@TableName(value = "trade_config", autoResultMap = true) +@KeySequence("trade_config_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class TradeConfigDO extends BaseDO { + + /** + * 自增主键 + */ + @TableId + private Long id; + + // ========== 分销相关 ========== + + /** + * 是否启用分佣 + */ + private Boolean brokerageEnabled; + /** + * 分佣模式 + *

+ * 枚举 {@link BrokerageEnabledConditionEnum 对应的类} + */ + private Integer brokerageEnabledCondition; + /** + * 分销关系绑定模式 + *

+ * 枚举 {@link BrokerageBindModeEnum 对应的类} + */ + private Integer brokerageBindMode; + /** + * 分销海报图地址数组 + */ + @TableField(typeHandler = JacksonTypeHandler.class) + private List brokeragePostUrls; + /** + * 一级返佣比例 + */ + private Integer brokerageFirstPercent; + /** + * 二级返佣比例 + */ + private Integer brokerageSecondPercent; + /** + * 用户提现最低金额 + */ + private Integer brokerageWithdrawMinPrice; + /** + * 提现银行 + */ + @TableField(typeHandler = IntegerListTypeHandler.class) + private List brokerageBankNames; + /** + * 佣金冻结时间(天) + */ + private Integer brokerageFrozenDays; + /** + * 提现方式 + *

+ * 枚举 {@link BrokerageWithdrawTypeEnum 对应的类} + */ + @TableField(typeHandler = IntegerListTypeHandler.class) + private List brokerageWithdrawType; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/config/TradeConfigMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/config/TradeConfigMapper.java new file mode 100644 index 0000000000..18a3f4df76 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/config/TradeConfigMapper.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.module.trade.dal.mysql.config; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 交易中心配置 Mapper + * + * @author owen + */ +@Mapper +public interface TradeConfigMapper extends BaseMapperX { + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigService.java new file mode 100644 index 0000000000..c00825f2e5 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigService.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.trade.service.config; + +import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigSaveReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; + +import javax.validation.Valid; + +/** + * 交易中心配置 Service 接口 + * + * @author owen + */ +public interface TradeConfigService { + + + /** + * 更新交易中心配置 + * + * @param updateReqVO 更新信息 + */ + void saveTradeConfig(@Valid TradeConfigSaveReqVO updateReqVO); + + /** + * 获得交易中心配置 + * + * @return 交易中心配置 + */ + TradeConfigDO getTradeConfig(); + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigServiceImpl.java new file mode 100644 index 0000000000..c859cdee6a --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigServiceImpl.java @@ -0,0 +1,44 @@ +package cn.iocoder.yudao.module.trade.service.config; + +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigSaveReqVO; +import cn.iocoder.yudao.module.trade.convert.config.TradeConfigConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; +import cn.iocoder.yudao.module.trade.dal.mysql.config.TradeConfigMapper; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 交易中心配置 Service 实现类 + * + * @author owen + */ +@Service +@Validated +public class TradeConfigServiceImpl implements TradeConfigService { + + @Resource + private TradeConfigMapper tradeConfigMapper; + + @Override + public void saveTradeConfig(TradeConfigSaveReqVO saveReqVO) { + // 存在,则进行更新 + TradeConfigDO dbConfig = getTradeConfig(); + if (dbConfig != null) { + tradeConfigMapper.updateById(TradeConfigConvert.INSTANCE.convert(saveReqVO).setId(dbConfig.getId())); + return; + } + // 不存在,则进行插入 + tradeConfigMapper.insert(TradeConfigConvert.INSTANCE.convert(saveReqVO)); + } + + @Override + public TradeConfigDO getTradeConfig() { + List list = tradeConfigMapper.selectList(); + return CollectionUtils.getFirst(list); + } + +} From a68691f2d93623404628fce2d7f222c4240cec5d Mon Sep 17 00:00:00 2001 From: owen Date: Tue, 5 Sep 2023 23:45:53 +0800 Subject: [PATCH 16/48] =?UTF-8?q?trade:=20=E5=A2=9E=E5=8A=A0=E5=88=86?= =?UTF-8?q?=E9=94=80=E7=94=A8=E6=88=B7=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/brokerage.sql | 133 ++++++++++-------- .../trade/enums/ErrorCodeConstants.java | 4 + .../user/TradeBrokerageUserController.java | 71 ++++++++++ .../user/vo/TradeBrokerageUserBaseVO.java | 43 ++++++ ...eBrokerageUserClearBrokerageUserReqVO.java | 18 +++ .../user/vo/TradeBrokerageUserPageReqVO.java | 30 ++++ .../user/vo/TradeBrokerageUserRespVO.java | 22 +++ ...kerageUserUpdateBrokerageEnabledReqVO.java | 22 +++ ...BrokerageUserUpdateBrokerageUserReqVO.java | 22 +++ .../user/TradeBrokerageUserConvert.java | 27 ++++ .../brokerage/user/TradeBrokerageUserDO.java | 56 ++++++++ .../user/TradeBrokerageUserMapper.java | 26 ++++ .../user/TradeBrokerageUserService.java | 56 ++++++++ .../user/TradeBrokerageUserServiceImpl.java | 63 +++++++++ .../TradeBrokerageUserServiceImplTest.java | 64 +++++++++ .../src/test/resources/sql/clean.sql | 1 + .../src/test/resources/sql/create_tables.sql | 18 +++ 17 files changed, 616 insertions(+), 60 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserBaseVO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserClearBrokerageUserReqVO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserPageReqVO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageUserReqVO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/TradeBrokerageUserMapper.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index ed8c5fcbe1..161dfa2567 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -1,8 +1,7 @@ --- 增加配置 +-- 增加配置表 create table trade_config ( - id bigint auto_increment comment '自增主键' - primary key, + id bigint auto_increment comment '自增主键' primary key, brokerage_enabled bit default 1 not null comment '是否启用分佣', brokerage_enabled_condition tinyint default 0 not null comment '分佣模式:0-人人分销 1-指定分销', brokerage_bind_mode tinyint default 0 not null comment '分销关系绑定模式: 0-没有推广人,1-新用户', @@ -21,22 +20,26 @@ create table trade_config tenant_id bigint default 0 not null comment '租户编号' ) comment '交易中心配置'; --- 用户表增加分销相关字段 -alter table member_user - add column brokerage_user_id bigint not null comment '推广员编号'; -alter table member_user - add column brokerage_bind_time datetime null comment '推广员绑定时间'; -alter table member_user - add column brokerage_enabled bit default 1 not null comment '是否成为推广员'; -alter table member_user - add column brokerage_time datetime null comment '成为分销员时间'; -alter table member_user - add column brokerage_price int default 0 not null comment '可用佣金'; -alter table member_user - add column frozen_brokerage_price int default 0 not null comment '冻结佣金'; +-- 增加分销用户扩展表 +create table trade_brokerage_user +( + id bigint auto_increment comment '用户编号' primary key, + brokerage_user_id bigint not null comment '推广员编号', + brokerage_bind_time datetime null comment '推广员绑定时间', + brokerage_enabled bit default 1 not null comment '是否成为推广员', + brokerage_time datetime null comment '成为分销员时间', + brokerage_price int default 0 not null comment '可用佣金', + frozen_brokerage_price int default 0 not null comment '冻结佣金', + creator varchar(64) collate utf8mb4_unicode_ci default '' null comment '创建者', + create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', + updater varchar(64) collate utf8mb4_unicode_ci default '' null comment '更新者', + update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', + deleted bit default b'0' not null comment '是否删除', + tenant_id bigint default 0 not null comment '租户编号' +) comment '分销用户'; -create index idx_invite_user_id on member_user (brokerage_user_id) comment '推广员编号'; -create index idx_agent on member_user (brokerage_enabled) comment '是否成为推广员'; +create index idx_invite_user_id on trade_brokerage_user (brokerage_user_id) comment '推广员编号'; +create index idx_agent on trade_brokerage_user (brokerage_enabled) comment '是否成为推广员'; create table member_brokerage_record @@ -150,55 +153,65 @@ values ('brokerage_bank_name', '工商银行', 0, 0), ('brokerage_bank_name', '交通银行', 4, 4), ('brokerage_bank_name', '招商银行', 5, 5); --- 增加菜单:分销员管理 -INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name) -VALUES ('分销员', '', 2, 7, 2262, 'brokerage', 'user', 'member/brokerage/user/index', 0, 'MemberBrokerageUser'); --- 按钮父菜单ID -SELECT @parentId := LAST_INSERT_ID(); --- 按钮 SQL -INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) -VALUES ('分销员查询', 'member:brokerage-user:query', 3, 1, @parentId, '', '', '', 0); -INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) -VALUES ('分销员创建', 'member:brokerage-user:create', 3, 2, @parentId, '', '', '', 0); -INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) -VALUES ('分销员更新', 'member:brokerage-user:update', 3, 3, @parentId, '', '', '', 0); -INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) -VALUES ('分销员删除', 'member:brokerage-user:delete', 3, 4, @parentId, '', '', '', 0); - --- 增加菜单:佣金记录 -INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name) -VALUES ('佣金记录', '', 2, 8, 2262, 'brokerage-record', 'list', 'member/brokerage/record/index', 0, - 'MemberBrokerageRecord'); --- 按钮父菜单ID --- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 -SELECT @parentId := LAST_INSERT_ID(); --- 按钮 SQL -INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) -VALUES ('佣金记录查询', 'member:member-brokerage-record:query', 3, 1, @parentId, '', 'table', '', 0); - --- 增加菜单:佣金提现 -INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name) -VALUES ('佣金提现', '', 2, 9, 2262, 'brokerage-withdraw', '', 'member/brokerage/withdraw/index', 0, - 'MemberBrokerageWithdraw'); - --- 按钮父菜单ID --- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 -SELECT @parentId := LAST_INSERT_ID(); - --- 按钮 SQL -INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) -VALUES ('佣金提现查询', 'member:brokerage-withdraw:query', 3, 1, @parentId, '', '', '', 0); -- 交易中心配置:菜单 SQL INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name) -VALUES ('交易中心配置', '', 2, 0, 2072, 'config', '', 'trade/config/index', 0, 'TradeConfig'); - +VALUES ('交易中心配置', '', 2, 0, 2072, 'config', 'ep:setting', 'trade/config/index', 0, 'TradeConfig'); -- 按钮父菜单ID -- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 SELECT @parentId := LAST_INSERT_ID(); - -- 按钮 SQL INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) VALUES ('交易中心配置查询', 'trade:config:query', 3, 1, @parentId, '', '', '', 0); INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) -VALUES ('交易中心配置保存', 'trade:config:save', 3, 2, @parentId, '', '', '', 0); \ No newline at end of file +VALUES ('交易中心配置保存', 'trade:config:save', 3, 2, @parentId, '', '', '', 0); + + +-- 增加菜单:分销 +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name) +VALUES ('分销', '', 1, 5, 2072, 'brokerage', 'fa-solid:project-diagram', '', 0, ''); +-- 按钮父菜单ID +SELECT @brokerageMenuId := LAST_INSERT_ID(); + +-- 增加菜单:分销员 +-- 菜单 SQL +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name) +VALUES ('分销用户', '', 2, 0, @brokerageMenuId, 'brokerage-user', 'fa-solid:user-tie', 'trade/brokerage/user/index', 0, + 'TradeBrokerageUser'); +-- 按钮父菜单ID +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 +SELECT @parentId := LAST_INSERT_ID(); +-- 按钮 SQL +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('分销用户查询', 'trade:brokerage-user:query', 3, 1, @parentId, '', '', '', 0); +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('分销用户修改推广员', 'trade:brokerage-user:update-brokerage-user', 3, 2, @parentId, '', '', '', 0); +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('分销用户清除推广员', 'trade:brokerage-user:clear-brokerage-user', 3, 3, @parentId, '', '', '', 0); +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('分销用户修改推广资格', 'trade:brokerage-user:update-brokerage-enable', 3, 4, @parentId, '', '', '', 0); + + +-- 增加菜单:佣金记录 +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name) +VALUES ('佣金记录', '', 2, 1, @brokerageMenuId, 'brokerage-record', 'fa:money', 'trade/brokerage/record/index', 0, + 'TradeBrokerageRecord'); +-- 按钮父菜单ID +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 +SELECT @parentId := LAST_INSERT_ID(); +-- 按钮 SQL +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('佣金记录查询', 'trade:brokerage-record:query', 3, 1, @parentId, '', '', '', 0); + +-- 增加菜单:佣金提现 +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name) +VALUES ('佣金提现', '', 2, 2, @brokerageMenuId, 'brokerage-withdraw', 'fa:credit-card', + 'trade/brokerage/withdraw/index', 0, 'TradeBrokerageWithdraw'); +-- 按钮父菜单ID +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 +SELECT @parentId := LAST_INSERT_ID(); +-- 按钮 SQL +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('佣金提现查询', 'trade:brokerage-withdraw:query', 3, 1, @parentId, '', '', '', 0); +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('佣金提现审核', 'trade:brokerage-withdraw:audit', 3, 2, @parentId, '', '', '', 0); \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 40f604e94e..3107dbedf0 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -74,4 +74,8 @@ public interface ErrorCodeConstants { // ========== 物流 PICK_UP 模块 1011006000 ========== ErrorCode PICK_UP_STORE_NOT_EXISTS = new ErrorCode(1011006000, "自提门店不存在"); + + // ========== 分销 分销用户 模块 1011007000 ========== + ErrorCode BROKERAGE_USER_NOT_EXISTS = new ErrorCode(1011007000, "分销用户不存在"); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java new file mode 100644 index 0000000000..e4cc63fb91 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java @@ -0,0 +1,71 @@ +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.*; +import cn.iocoder.yudao.module.trade.convert.brokerage.user.TradeBrokerageUserConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "管理后台 - 分销用户") +@RestController +@RequestMapping("/trade/brokerage-user") +@Validated +public class TradeBrokerageUserController { + + @Resource + private TradeBrokerageUserService brokerageUserService; + + @PutMapping("/update-brokerage-user") + @Operation(summary = "修改推广员") + @PreAuthorize("@ss.hasPermission('trade:brokerage-user:update-brokerage-user')") + public CommonResult updateBrokerageUser(@Valid @RequestBody TradeBrokerageUserUpdateBrokerageUserReqVO updateReqVO) { + brokerageUserService.updateBrokerageUserId(updateReqVO.getId(), updateReqVO.getBrokerageUserId()); + return success(true); + } + + @PutMapping("/clear-brokerage-user") + @Operation(summary = "清除推广员") + @PreAuthorize("@ss.hasPermission('trade:brokerage-user:clear-brokerage-user')") + public CommonResult clearBrokerageUser(@Valid @RequestBody TradeBrokerageUserClearBrokerageUserReqVO updateReqVO) { + brokerageUserService.updateBrokerageUserId(updateReqVO.getId(), null); + return success(true); + } + + @PutMapping("/update-brokerage-enable") + @Operation(summary = "修改推广资格") + @PreAuthorize("@ss.hasPermission('trade:brokerage-user:update-brokerage-enable')") + public CommonResult updateBrokerageEnabled(@Valid @RequestBody TradeBrokerageUserUpdateBrokerageEnabledReqVO updateReqVO) { + brokerageUserService.updateBrokerageEnabled(updateReqVO.getId(), updateReqVO.getBrokerageEnabled()); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得分销用户") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('trade:brokerage-user:query')") + public CommonResult getBrokerageUser(@RequestParam("id") Long id) { + TradeBrokerageUserDO brokerageUser = brokerageUserService.getBrokerageUser(id); + return success(TradeBrokerageUserConvert.INSTANCE.convert(brokerageUser)); + } + + @GetMapping("/page") + @Operation(summary = "获得分销用户分页") + @PreAuthorize("@ss.hasPermission('trade:brokerage-user:query')") + public CommonResult> getBrokerageUserPage(@Valid TradeBrokerageUserPageReqVO pageVO) { + PageResult pageResult = brokerageUserService.getBrokerageUserPage(pageVO); + return success(TradeBrokerageUserConvert.INSTANCE.convertPage(pageResult)); + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserBaseVO.java new file mode 100644 index 0000000000..d75e6a1b13 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserBaseVO.java @@ -0,0 +1,43 @@ +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.NotNull; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +/** + * 分销用户 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ +@Data +public class TradeBrokerageUserBaseVO { + + @Schema(description = "推广员编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4587") + @NotNull(message = "推广员编号不能为空") + private Long brokerageUserId; + + @Schema(description = "推广员绑定时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime brokerageBindTime; + + @Schema(description = "推广资格", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "推广资格不能为空") + private Boolean brokerageEnabled; + + @Schema(description = "成为分销员时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime brokerageTime; + + @Schema(description = "可用佣金", requiredMode = Schema.RequiredMode.REQUIRED, example = "11089") + @NotNull(message = "可用佣金不能为空") + private Integer brokeragePrice; + + @Schema(description = "冻结佣金", requiredMode = Schema.RequiredMode.REQUIRED, example = "30916") + @NotNull(message = "冻结佣金不能为空") + private Integer frozenBrokeragePrice; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserClearBrokerageUserReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserClearBrokerageUserReqVO.java new file mode 100644 index 0000000000..18a5a5e853 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserClearBrokerageUserReqVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.ToString; + +import javax.validation.constraints.NotNull; + +@Schema(description = "管理后台 - 分销用户 - 清除推广员 Request VO") +@Data +@ToString(callSuper = true) +public class TradeBrokerageUserClearBrokerageUserReqVO { + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20019") + @NotNull(message = "用户编号不能为空") + private Long id; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserPageReqVO.java new file mode 100644 index 0000000000..ec63775d34 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserPageReqVO.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 分销用户分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class TradeBrokerageUserPageReqVO extends PageParam { + + @Schema(description = "推广员编号", example = "4587") + private Long brokerageUserId; + + @Schema(description = "推广资格") + private Boolean brokerageEnabled; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java new file mode 100644 index 0000000000..090eb04b53 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 分销用户 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class TradeBrokerageUserRespVO extends TradeBrokerageUserBaseVO { + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20019") + private Long id; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + private LocalDateTime createTime; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java new file mode 100644 index 0000000000..002eed371b --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.ToString; + +import javax.validation.constraints.NotNull; + +@Schema(description = "管理后台 - 分销用户 - 修改推广员 Request VO") +@Data +@ToString(callSuper = true) +public class TradeBrokerageUserUpdateBrokerageEnabledReqVO { + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20019") + @NotNull(message = "用户编号不能为空") + private Long id; + + @Schema(description = "推广资格", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "推广资格不能为空") + private Boolean brokerageEnabled; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageUserReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageUserReqVO.java new file mode 100644 index 0000000000..28ea301c13 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageUserReqVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.ToString; + +import javax.validation.constraints.NotNull; + +@Schema(description = "管理后台 - 分销用户 - 修改推广员 Request VO") +@Data +@ToString(callSuper = true) +public class TradeBrokerageUserUpdateBrokerageUserReqVO { + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20019") + @NotNull(message = "用户编号不能为空") + private Long id; + + @Schema(description = "推广员编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4587") + @NotNull(message = "推广员编号不能为空") + private Long brokerageUserId; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java new file mode 100644 index 0000000000..1a62bded0b --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.trade.convert.brokerage.user; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserRespVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + * 分销用户 Convert + * + * @author owen + */ +@Mapper +public interface TradeBrokerageUserConvert { + + TradeBrokerageUserConvert INSTANCE = Mappers.getMapper(TradeBrokerageUserConvert.class); + + TradeBrokerageUserRespVO convert(TradeBrokerageUserDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java new file mode 100644 index 0000000000..0bc552dca0 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java @@ -0,0 +1,56 @@ +package cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; + +import java.time.LocalDateTime; + +/** + * 分销用户 DO + * + * @author owen + */ +@TableName("trade_brokerage_user") +@KeySequence("trade_brokerage_user_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class TradeBrokerageUserDO extends BaseDO { + + /** + * 用户编号 + */ + @TableId + private Long id; + /** + * 推广员编号 + */ + private Long brokerageUserId; + /** + * 推广员绑定时间 + */ + private LocalDateTime brokerageBindTime; + /** + * 推广资格 + */ + private Boolean brokerageEnabled; + /** + * 成为分销员时间 + */ + private LocalDateTime brokerageTime; + /** + * 可用佣金 + */ + private Integer brokeragePrice; + /** + * 冻结佣金 + */ + private Integer frozenBrokeragePrice; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/TradeBrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/TradeBrokerageUserMapper.java new file mode 100644 index 0000000000..93656837ae --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/TradeBrokerageUserMapper.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 分销用户 Mapper + * + * @author owen + */ +@Mapper +public interface TradeBrokerageUserMapper extends BaseMapperX { + + default PageResult selectPage(TradeBrokerageUserPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(TradeBrokerageUserDO::getBrokerageUserId, reqVO.getBrokerageUserId()) + .eqIfPresent(TradeBrokerageUserDO::getBrokerageEnabled, reqVO.getBrokerageEnabled()) + .betweenIfPresent(TradeBrokerageUserDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(TradeBrokerageUserDO::getId)); + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java new file mode 100644 index 0000000000..58970d724a --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java @@ -0,0 +1,56 @@ +package cn.iocoder.yudao.module.trade.service.brokerage.user; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; + +import java.util.Collection; +import java.util.List; + +/** + * 分销用户 Service 接口 + * + * @author owen + */ +public interface TradeBrokerageUserService { + + /** + * 获得分销用户 + * + * @param id 编号 + * @return 分销用户 + */ + TradeBrokerageUserDO getBrokerageUser(Long id); + + /** + * 获得分销用户列表 + * + * @param ids 编号 + * @return 分销用户列表 + */ + List getBrokerageUserList(Collection ids); + + /** + * 获得分销用户分页 + * + * @param pageReqVO 分页查询 + * @return 分销用户分页 + */ + PageResult getBrokerageUserPage(TradeBrokerageUserPageReqVO pageReqVO); + + /** + * 修改推广员编号 + * + * @param id 用户编号 + * @param brokerageUserId 推广员编号 + */ + void updateBrokerageUserId(Long id, Long brokerageUserId); + + /** + * 修改推广资格 + * + * @param id 用户编号 + * @param brokerageEnabled 推广资格 + */ + void updateBrokerageEnabled(Long id, Boolean brokerageEnabled); +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java new file mode 100644 index 0000000000..acbda456bf --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java @@ -0,0 +1,63 @@ +package cn.iocoder.yudao.module.trade.service.brokerage.user; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.TradeBrokerageUserMapper; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.util.Collection; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_USER_NOT_EXISTS; + +/** + * 分销用户 Service 实现类 + * + * @author owen + */ +@Service +@Validated +public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService { + + @Resource + private TradeBrokerageUserMapper brokerageUserMapper; + + private void validateBrokerageUserExists(Long id) { + if (brokerageUserMapper.selectById(id) == null) { + throw exception(BROKERAGE_USER_NOT_EXISTS); + } + } + + @Override + public TradeBrokerageUserDO getBrokerageUser(Long id) { + return brokerageUserMapper.selectById(id); + } + + @Override + public List getBrokerageUserList(Collection ids) { + return brokerageUserMapper.selectBatchIds(ids); + } + + @Override + public PageResult getBrokerageUserPage(TradeBrokerageUserPageReqVO pageReqVO) { + return brokerageUserMapper.selectPage(pageReqVO); + } + + @Override + public void updateBrokerageUserId(Long id, Long brokerageUserId) { + // 校验存在 + validateBrokerageUserExists(id); + + } + + @Override + public void updateBrokerageEnabled(Long id, Boolean brokerageEnabled) { + // 校验存在 + validateBrokerageUserExists(id); + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java new file mode 100644 index 0000000000..49e8aa351f --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java @@ -0,0 +1,64 @@ +package cn.iocoder.yudao.module.trade.service.brokerage.user; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.TradeBrokerageUserMapper; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; + +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * {@link TradeBrokerageUserServiceImpl} 的单元测试类 + * + * @author owen + */ +@Import(TradeBrokerageUserServiceImpl.class) +public class TradeBrokerageUserServiceImplTest extends BaseDbUnitTest { + + @Resource + private TradeBrokerageUserServiceImpl brokerageUserService; + + @Resource + private TradeBrokerageUserMapper brokerageUserMapper; + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetBrokerageUserPage() { + // mock 数据 + TradeBrokerageUserDO dbBrokerageUser = randomPojo(TradeBrokerageUserDO.class, o -> { // 等会查询到 + o.setBrokerageUserId(null); + o.setBrokerageEnabled(null); + o.setCreateTime(null); + }); + brokerageUserMapper.insert(dbBrokerageUser); + // 测试 brokerageUserId 不匹配 + brokerageUserMapper.insert(cloneIgnoreId(dbBrokerageUser, o -> o.setBrokerageUserId(null))); + // 测试 brokerageEnabled 不匹配 + brokerageUserMapper.insert(cloneIgnoreId(dbBrokerageUser, o -> o.setBrokerageEnabled(null))); + // 测试 createTime 不匹配 + brokerageUserMapper.insert(cloneIgnoreId(dbBrokerageUser, o -> o.setCreateTime(null))); + // 准备参数 + TradeBrokerageUserPageReqVO reqVO = new TradeBrokerageUserPageReqVO(); + reqVO.setBrokerageUserId(null); + reqVO.setBrokerageEnabled(null); + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); + + // 调用 + PageResult pageResult = brokerageUserService.getBrokerageUserPage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbBrokerageUser, pageResult.getList().get(0)); + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/clean.sql b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/clean.sql index dfa4a5b421..b0715ca164 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/clean.sql +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/clean.sql @@ -2,3 +2,4 @@ DELETE FROM trade_order; DELETE FROM trade_order_item; DELETE FROM trade_after_sale; DELETE FROM trade_after_sale_log; +DELETE FROM "trade_brokerage_user"; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql index e30b0d2254..df68fd53b4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql @@ -125,3 +125,21 @@ CREATE TABLE IF NOT EXISTS "trade_after_sale_log" ( "deleted" bit NOT NULL DEFAULT FALSE, PRIMARY KEY ("id") ) COMMENT '交易售后日志'; + +CREATE TABLE IF NOT EXISTS "trade_brokerage_user" +( + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "brokerage_user_id" bigint NOT NULL, + "brokerage_bind_time" varchar, + "brokerage_enabled" bit NOT NULL, + "brokerage_time" varchar, + "brokerage_price" int NOT NULL, + "frozen_brokerage_price" int NOT NULL, + "creator" varchar DEFAULT '', + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar DEFAULT '', + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + "tenant_id" bigint NOT NULL DEFAULT '0', + PRIMARY KEY ("id") +) COMMENT '分销用户'; \ No newline at end of file From e4b153a866903ffcbbec803a97b05867991a5515 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 5 Sep 2023 23:49:35 +0800 Subject: [PATCH 17/48] =?UTF-8?q?=E5=88=86=E4=BD=A3=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=8E=B7=E5=BE=97=E5=88=86=E9=94=80=E6=8E=92=E8=A1=8C?= =?UTF-8?q?=E5=88=86=E9=A1=B5=20API=20mock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/pojo/SortingField.java | 33 +++--------- .../brokerage/AppBrokerageUserController.java | 51 +++++++++++++------ ...AppBrokerageUserChildSummaryPageReqVO.java | 25 +++++++++ .../AppBrokerageUserChildSummaryRespVO.java | 33 ++++++++++++ ...a => AppBrokerageUserMySummaryRespVO.java} | 8 ++- .../AppBrokerageUserRankByPriceRespVO.java | 4 +- ...AppBrokerageUserRankByUserCountRespVO.java | 4 +- 7 files changed, 111 insertions(+), 47 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryPageReqVO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/{AppBrokerageUserSummaryRespVO.java => AppBrokerageUserMySummaryRespVO.java} (69%) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/SortingField.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/SortingField.java index 98411730ed..07a68b0643 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/SortingField.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/SortingField.java @@ -1,5 +1,9 @@ package cn.iocoder.yudao.framework.common.pojo; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + import java.io.Serializable; /** @@ -7,6 +11,9 @@ import java.io.Serializable; * * 类名加了 ing 的原因是,避免和 ES SortField 重名。 */ +@Data +@NoArgsConstructor +@AllArgsConstructor public class SortingField implements Serializable { /** @@ -27,30 +34,4 @@ public class SortingField implements Serializable { */ private String order; - // 空构造方法,解决反序列化 - public SortingField() { - } - - public SortingField(String field, String order) { - this.field = field; - this.order = order; - } - - public String getField() { - return field; - } - - public SortingField setField(String field) { - this.field = field; - return this; - } - - public String getOrder() { - return order; - } - - public SortingField setOrder(String order) { - this.order = order; - return this; - } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index dd3d17ff70..31de03ea13 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -3,10 +3,7 @@ package cn.iocoder.yudao.module.trade.controller.app.brokerage; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; -import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO; -import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO; -import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO; -import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserSummaryRespVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.*; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -35,53 +32,75 @@ public class AppBrokerageUserController { @GetMapping("/get-summary") @Operation(summary = "获得个人分销统计") @PreAuthenticated - public CommonResult getBrokerageUserSummary() { - AppBrokerageUserSummaryRespVO respVO = new AppBrokerageUserSummaryRespVO() + public CommonResult getBrokerageUserSummary() { + AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO() .setYesterdayBrokeragePrice(1) .setBrokeragePrice(2) .setFrozenBrokeragePrice(3) - .setWithdrawBrokeragePrice(4); + .setWithdrawBrokeragePrice(4) + .setFirstBrokerageUserCount(166) + .setSecondBrokerageUserCount(233); return success(respVO); } + // TODO 芋艿:临时 mock => @GetMapping("/rank-page-by-user-count") @Operation(summary = "获得分销用户排行分页(基于用户量)") @PreAuthenticated public CommonResult> getBrokerageUserRankPageByUserCount(AppBrokerageUserRankPageReqVO pageReqVO) { AppBrokerageUserRankByUserCountRespVO vo1 = new AppBrokerageUserRankByUserCountRespVO() - .setUserId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") .setBrokerageUserCount(10); AppBrokerageUserRankByUserCountRespVO vo2 = new AppBrokerageUserRankByUserCountRespVO() - .setUserId(2L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setId(2L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") .setBrokerageUserCount(6); AppBrokerageUserRankByUserCountRespVO vo3 = new AppBrokerageUserRankByUserCountRespVO() - .setUserId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") .setBrokerageUserCount(4); AppBrokerageUserRankByUserCountRespVO vo4 = new AppBrokerageUserRankByUserCountRespVO() - .setUserId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") .setBrokerageUserCount(4); return success(new PageResult<>(asList(vo1, vo2, vo3, vo4), 10L)); } + // TODO 芋艿:临时 mock => @GetMapping("/rank-page-by-price") @Operation(summary = "获得分销用户排行分页(基于佣金)") @PreAuthenticated - public CommonResult> getBrokerageUserRankPageByPrice(AppBrokerageUserRankPageReqVO pageReqVO) { + public CommonResult> getBrokerageUserChildSummaryPageByPrice(AppBrokerageUserRankPageReqVO pageReqVO) { AppBrokerageUserRankByPriceRespVO vo1 = new AppBrokerageUserRankByPriceRespVO() - .setUserId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") .setBrokeragePrice(10); AppBrokerageUserRankByPriceRespVO vo2 = new AppBrokerageUserRankByPriceRespVO() - .setUserId(2L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setId(2L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") .setBrokeragePrice(6); AppBrokerageUserRankByPriceRespVO vo3 = new AppBrokerageUserRankByPriceRespVO() - .setUserId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") .setBrokeragePrice(4); AppBrokerageUserRankByPriceRespVO vo4 = new AppBrokerageUserRankByPriceRespVO() - .setUserId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") .setBrokeragePrice(4); return success(new PageResult<>(asList(vo1, vo2, vo3, vo4), 10L)); } + // TODO 芋艿:临时 mock => + @GetMapping("/child-summary-page") + @Operation(summary = "获得下级分销统计分页") + @PreAuthenticated + public CommonResult> getBrokerageUserChildSummaryPage( + AppBrokerageUserChildSummaryPageReqVO pageReqVO) { + AppBrokerageUserChildSummaryRespVO vo1 = new AppBrokerageUserChildSummaryRespVO() + .setId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setBrokeragePrice(10).setBrokeragePrice(20).setBrokerageOrderCount(30) + .setBrokerageTime(LocalDateTime.now()); + AppBrokerageUserChildSummaryRespVO vo2 = new AppBrokerageUserChildSummaryRespVO() + .setId(1L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") + .setBrokeragePrice(20).setBrokeragePrice(30).setBrokerageOrderCount(40) + .setBrokerageTime(LocalDateTime.now()); + return success(new PageResult<>(asList(vo1, vo2), 10L)); + } + + // TODO 芋艿:临时 mock => @GetMapping("/get-rank-by-price") @Operation(summary = "获得分销用户排行(基于佣金)") @Parameter(name = "times", description = "时间段", required = true) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryPageReqVO.java new file mode 100644 index 0000000000..066fc09123 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryPageReqVO.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.SortingField; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "用户 App - 下级分销统计分页 Request VO") +@Data +public class AppBrokerageUserChildSummaryPageReqVO extends PageParam { + + public static final String SORT_FIELD_USER_COUNT = "userCount"; + public static final String SORT_FIELD_ORDER_COUNT = "orderCount"; + public static final String SORT_FIELD_PRICE = "price"; + + @Schema(description = "用户昵称", example = "李") // 模糊匹配 + private String nickname; + + @Schema(description = "排序字段", example = "userCount") + private SortingField sortingField; + + @Schema(description = "下级的级别", example = "1") // 1 - 直接下级;2 - 间接下级 + private Integer level; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java new file mode 100644 index 0000000000..1beb1b5e2a --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +@Schema(description = "用户 App - 下级分销统计 Response VO") +@Data +public class AppBrokerageUserChildSummaryRespVO { + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Long id; + + @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小王") + private String nickname; + + @Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xxx.jpg") + private String avatar; + + @Schema(description = "佣金金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Integer brokeragePrice; + + @Schema(description = "分销订单数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "20") + private Integer brokerageOrderCount; + + @Schema(description = "分销用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "30") + private Integer brokerageUserCount; + + @Schema(description = "成为分销员时间", requiredMode = Schema.RequiredMode.REQUIRED) + private LocalDateTime brokerageTime; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserSummaryRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java similarity index 69% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserSummaryRespVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java index 5779d80108..64fafe3294 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserSummaryRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java @@ -5,7 +5,7 @@ import lombok.Data; @Schema(description = "用户 App - 个人分销统计 Response VO") @Data -public class AppBrokerageUserSummaryRespVO { +public class AppBrokerageUserMySummaryRespVO { @Schema(description = "昨天的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") private Integer yesterdayBrokeragePrice; @@ -19,4 +19,10 @@ public class AppBrokerageUserSummaryRespVO { @Schema(description = "冻结的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "234") private Integer frozenBrokeragePrice; + @Schema(description = "分销用户数量(一级)", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Integer firstBrokerageUserCount; + + @Schema(description = "分销用户数量(二级)", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Integer secondBrokerageUserCount; + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java index 28dab5f8f8..91345ea789 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java @@ -8,12 +8,12 @@ import lombok.Data; public class AppBrokerageUserRankByPriceRespVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Long userId; + private Long id; @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小王") private String nickname; - @Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "http://www.iocoder.cn/xxx.jpg") + @Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xxx.jpg") private String avatar; @Schema(description = "佣金金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByUserCountRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByUserCountRespVO.java index f0ea2e6c32..1a6de81385 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByUserCountRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByUserCountRespVO.java @@ -8,12 +8,12 @@ import lombok.Data; public class AppBrokerageUserRankByUserCountRespVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Long userId; + private Long id; @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小王") private String nickname; - @Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "http://www.iocoder.cn/xxx.jpg") + @Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xxx.jpg") private String avatar; @Schema(description = "邀请用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") From 9336a0a1024ccdc5dd30a1d56cf054a884082477 Mon Sep 17 00:00:00 2001 From: owen Date: Wed, 6 Sep 2023 00:16:47 +0800 Subject: [PATCH 18/48] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E4=BB=8E=20member=20=E6=A8=A1=E5=9D=97=20=E8=BD=AC?= =?UTF-8?q?=E7=A7=BB=E5=88=B0=20trade=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../brokerage/BrokerageBindModeEnum.java | 2 +- .../BrokerageEnabledConditionEnum.java | 2 +- .../brokerage/BrokerageRecordBizTypeEnum.java | 2 +- .../brokerage/BrokerageRecordStatusEnum.java | 2 +- .../BrokerageWithdrawStatusEnum.java | 2 +- .../brokerage/BrokerageWithdrawTypeEnum.java | 2 +- .../yudao-module-trade-biz/pom.xml | 4 + .../MemberBrokerageRecordController.java | 14 ++-- .../vo/MemberBrokerageRecordBaseVO.java | 2 +- .../vo/MemberBrokerageRecordPageReqVO.java | 2 +- .../vo/MemberBrokerageRecordRespVO.java | 2 +- .../admin/config/vo/TradeConfigBaseVO.java | 6 +- .../record/MemberBrokerageRecordConvert.java | 14 ++-- .../convert/order/TradeOrderConvert.java | 2 +- .../record/MemberBrokerageRecordDO.java | 6 +- .../dal/dataobject/config/TradeConfigDO.java | 6 +- .../record/MemberBrokerageRecordMapper.java | 6 +- .../user/TradeBrokerageUserMapper.java | 77 +++++++++++++++++++ .../MemberBrokerageRecordUnfreezeJob.java | 4 +- .../record/MemberBrokerageRecordService.java | 8 +- .../MemberBrokerageRecordServiceImpl.java | 46 +++++------ .../record/bo}/BrokerageAddReqDTO.java | 2 +- .../user/TradeBrokerageUserService.java | 32 ++++++++ .../user/TradeBrokerageUserServiceImpl.java | 43 +++++++++++ .../order/TradeOrderUpdateServiceImpl.java | 10 +-- .../MemberBrokerageRecordServiceImplTest.java | 16 ++-- .../member/api/brokerage/BrokerageApi.java | 30 -------- .../api/brokerage/BrokerageApiImpl.java | 32 -------- .../vo/config/MemberPointConfigBaseVO.java | 57 -------------- .../dataobject/point/MemberPointConfigDO.java | 60 --------------- .../dal/mysql/user/MemberUserMapper.java | 77 ------------------- .../service/user/MemberUserService.java | 32 -------- .../service/user/MemberUserServiceImpl.java | 41 ---------- 33 files changed, 235 insertions(+), 408 deletions(-) rename {yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade}/enums/brokerage/BrokerageBindModeEnum.java (93%) rename {yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade}/enums/brokerage/BrokerageEnabledConditionEnum.java (93%) rename {yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade}/enums/brokerage/BrokerageRecordBizTypeEnum.java (94%) rename {yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade}/enums/brokerage/BrokerageRecordStatusEnum.java (92%) rename {yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade}/enums/brokerage/BrokerageWithdrawStatusEnum.java (93%) rename {yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade}/enums/brokerage/BrokerageWithdrawTypeEnum.java (92%) rename {yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade}/controller/admin/brokerage/record/MemberBrokerageRecordController.java (76%) rename {yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade}/controller/admin/brokerage/record/vo/MemberBrokerageRecordBaseVO.java (96%) rename {yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade}/controller/admin/brokerage/record/vo/MemberBrokerageRecordPageReqVO.java (92%) rename {yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade}/controller/admin/brokerage/record/vo/MemberBrokerageRecordRespVO.java (89%) rename {yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade}/convert/brokerage/record/MemberBrokerageRecordConvert.java (70%) rename {yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade}/dal/dataobject/brokerage/record/MemberBrokerageRecordDO.java (86%) rename {yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade}/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java (88%) rename {yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade}/job/brokerage/MemberBrokerageRecordUnfreezeJob.java (81%) rename {yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade}/service/brokerage/record/MemberBrokerageRecordService.java (76%) rename {yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade}/service/brokerage/record/MemberBrokerageRecordServiceImpl.java (79%) rename {yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/dto => yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo}/BrokerageAddReqDTO.java (89%) rename {yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member => yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade}/service/brokerage/record/MemberBrokerageRecordServiceImplTest.java (87%) delete mode 100644 yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApi.java delete mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApiImpl.java diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageBindModeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java similarity index 93% rename from yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageBindModeEnum.java rename to yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java index 2ee7e891f8..6946167bc6 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageBindModeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.member.enums.brokerage; +package cn.iocoder.yudao.module.trade.enums.brokerage; import cn.iocoder.yudao.framework.common.core.IntArrayValuable; import lombok.AllArgsConstructor; diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageEnabledConditionEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java similarity index 93% rename from yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageEnabledConditionEnum.java rename to yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java index 5422b98b7f..6d984a284d 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageEnabledConditionEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.member.enums.brokerage; +package cn.iocoder.yudao.module.trade.enums.brokerage; import cn.iocoder.yudao.framework.common.core.IntArrayValuable; import lombok.AllArgsConstructor; diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageRecordBizTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java similarity index 94% rename from yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageRecordBizTypeEnum.java rename to yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java index d30758a880..ce449f0b84 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageRecordBizTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.member.enums.brokerage; +package cn.iocoder.yudao.module.trade.enums.brokerage; import cn.iocoder.yudao.framework.common.core.IntArrayValuable; import lombok.AllArgsConstructor; diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageRecordStatusEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordStatusEnum.java similarity index 92% rename from yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageRecordStatusEnum.java rename to yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordStatusEnum.java index 75ddc9e0a2..827390998e 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageRecordStatusEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordStatusEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.member.enums.brokerage; +package cn.iocoder.yudao.module.trade.enums.brokerage; import cn.iocoder.yudao.framework.common.core.IntArrayValuable; import lombok.AllArgsConstructor; diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageWithdrawStatusEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java similarity index 93% rename from yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageWithdrawStatusEnum.java rename to yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java index 6d0232deb5..a80aad02ab 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageWithdrawStatusEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.member.enums.brokerage; +package cn.iocoder.yudao.module.trade.enums.brokerage; import cn.iocoder.yudao.framework.common.core.IntArrayValuable; import lombok.AllArgsConstructor; diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageWithdrawTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawTypeEnum.java similarity index 92% rename from yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageWithdrawTypeEnum.java rename to yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawTypeEnum.java index 21d0712b91..46edf010e9 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/brokerage/BrokerageWithdrawTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawTypeEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.member.enums.brokerage; +package cn.iocoder.yudao.module.trade.enums.brokerage; import cn.iocoder.yudao.framework.common.core.IntArrayValuable; import lombok.AllArgsConstructor; diff --git a/yudao-module-mall/yudao-module-trade-biz/pom.xml b/yudao-module-mall/yudao-module-trade-biz/pom.xml index 810446fa94..02f31a9f0f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/pom.xml +++ b/yudao-module-mall/yudao-module-trade-biz/pom.xml @@ -54,6 +54,10 @@ cn.iocoder.boot yudao-spring-boot-starter-biz-operatelog + + cn.iocoder.boot + yudao-spring-boot-starter-biz-tenant + cn.iocoder.boot yudao-spring-boot-starter-biz-ip diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/MemberBrokerageRecordController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/MemberBrokerageRecordController.java similarity index 76% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/MemberBrokerageRecordController.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/MemberBrokerageRecordController.java index 92cb0ae1aa..c4bc9bb37a 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/MemberBrokerageRecordController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/MemberBrokerageRecordController.java @@ -1,12 +1,12 @@ -package cn.iocoder.yudao.module.member.controller.admin.brokerage.record; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo.MemberBrokerageRecordRespVO; -import cn.iocoder.yudao.module.member.convert.brokerage.record.MemberBrokerageRecordConvert; -import cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; -import cn.iocoder.yudao.module.member.service.brokerage.record.MemberBrokerageRecordService; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordRespVO; +import cn.iocoder.yudao.module.trade.convert.brokerage.record.MemberBrokerageRecordConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +import cn.iocoder.yudao.module.trade.service.brokerage.record.MemberBrokerageRecordService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -24,7 +24,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Tag(name = "管理后台 - 佣金记录") @RestController -@RequestMapping("/member/member-brokerage-record") +@RequestMapping("/trade/member-brokerage-record") @Validated public class MemberBrokerageRecordController { diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordBaseVO.java similarity index 96% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordBaseVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordBaseVO.java index ef6762be1d..51cd4a6319 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordBaseVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordPageReqVO.java similarity index 92% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordPageReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordPageReqVO.java index 04a9ed94cb..3a5e05527d 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordPageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordPageReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo; import cn.iocoder.yudao.framework.common.pojo.PageParam; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordRespVO.java similarity index 89% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordRespVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordRespVO.java index 417b5320d4..3550a64bad 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/brokerage/record/vo/MemberBrokerageRecordRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java index 4ee51e3b84..ee20156f15 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java @@ -1,9 +1,9 @@ package cn.iocoder.yudao.module.trade.controller.admin.config.vo; import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageBindModeEnum; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageEnabledConditionEnum; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageWithdrawTypeEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageBindModeEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageEnabledConditionEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawTypeEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import org.hibernate.validator.constraints.Range; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/brokerage/record/MemberBrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/MemberBrokerageRecordConvert.java similarity index 70% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/brokerage/record/MemberBrokerageRecordConvert.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/MemberBrokerageRecordConvert.java index 393bacb724..48af52cf5b 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/brokerage/record/MemberBrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/MemberBrokerageRecordConvert.java @@ -1,12 +1,12 @@ -package cn.iocoder.yudao.module.member.convert.brokerage.record; +package cn.iocoder.yudao.module.trade.convert.brokerage.record; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo.MemberBrokerageRecordRespVO; -import cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; -import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageRecordBizTypeEnum; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageRecordStatusEnum; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordRespVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -29,7 +29,7 @@ public interface MemberBrokerageRecordConvert { PageResult convertPage(PageResult page); - default MemberBrokerageRecordDO convert(MemberUserDO user, String bizId, int brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime) { + default MemberBrokerageRecordDO convert(TradeBrokerageUserDO user, String bizId, int brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime) { // 不冻结时,佣金直接就是结算状态 Integer status = brokerageFrozenDays > 0 ? BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus() diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index e46ce66b6c..d17b81124c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.common.util.string.StrUtils; import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; -import cn.iocoder.yudao.module.member.api.brokerage.dto.BrokerageAddReqDTO; +import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqDTO; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; import cn.iocoder.yudao.module.pay.enums.DictTypeConstants; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/brokerage/record/MemberBrokerageRecordDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/MemberBrokerageRecordDO.java similarity index 86% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/brokerage/record/MemberBrokerageRecordDO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/MemberBrokerageRecordDO.java index 88e6ba7d9c..94d37ff89c 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/brokerage/record/MemberBrokerageRecordDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/MemberBrokerageRecordDO.java @@ -1,8 +1,8 @@ -package cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record; +package cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageRecordBizTypeEnum; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageRecordStatusEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java index 5538186e1e..a0c6d3858b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java @@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.trade.dal.dataobject.config; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.type.IntegerListTypeHandler; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageBindModeEnum; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageEnabledConditionEnum; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageWithdrawTypeEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageBindModeEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageEnabledConditionEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawTypeEnum; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java similarity index 88% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java index 52154aea50..da89b8bba9 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java @@ -1,10 +1,10 @@ -package cn.iocoder.yudao.module.member.dal.mysql.brokerage.record; +package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/TradeBrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/TradeBrokerageUserMapper.java index 93656837ae..f0c221311f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/TradeBrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/TradeBrokerageUserMapper.java @@ -1,10 +1,12 @@ package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user; +import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; /** @@ -23,4 +25,79 @@ public interface TradeBrokerageUserMapper extends BaseMapperX 0); + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" brokerage_price = brokerage_price + " + incrCount) + .eq(TradeBrokerageUserDO::getId, id); + update(null, lambdaUpdateWrapper); + } + + /** + * 更新用户可用佣金(减少) + * 注意:理论上佣金可能已经提现,这时会扣出负数,确保平台不会造成损失 + * + * @param id 用户编号 + * @param incrCount 增加佣金(负数) + */ + default void updateBrokeragePriceDecr(Long id, int incrCount) { + Assert.isTrue(incrCount < 0); + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" brokerage_price = brokerage_price + " + incrCount) // 负数,所以使用 + 号 + .eq(TradeBrokerageUserDO::getId, id); + update(null, lambdaUpdateWrapper); + } + + /** + * 更新用户冻结佣金(增加) + * + * @param id 用户编号 + * @param incrCount 增加冻结佣金(正数) + */ + default void updateFrozenBrokeragePriceIncr(Long id, int incrCount) { + Assert.isTrue(incrCount > 0); + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) + .eq(TradeBrokerageUserDO::getId, id); + update(null, lambdaUpdateWrapper); + } + + /** + * 更新用户冻结佣金(减少) + * 注意:理论上冻结佣金可能已经解冻,这时会扣出负数,确保平台不会造成损失 + * + * @param id 用户编号 + * @param incrCount 减少冻结佣金(负数) + */ + default void updateFrozenBrokeragePriceDecr(Long id, int incrCount) { + Assert.isTrue(incrCount < 0); + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) // 负数,所以使用 + 号 + .eq(TradeBrokerageUserDO::getId, id); + update(null, lambdaUpdateWrapper); + } + + /** + * 更新用户冻结佣金(减少), 更新用户佣金(增加) + * + * @param id 用户编号 + * @param incrCount 减少冻结佣金(负数) + * @return 更新条数 + */ + default int updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int incrCount) { + Assert.isTrue(incrCount < 0); + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount + // 负数,所以使用 + 号 + ", brokerage_price = brokerage_price + " + -incrCount) // 负数,所以使用 - 号 + .eq(TradeBrokerageUserDO::getId, id) + .ge(TradeBrokerageUserDO::getFrozenBrokeragePrice, -incrCount); // cas 逻辑 + return update(null, lambdaUpdateWrapper); + } + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/job/brokerage/MemberBrokerageRecordUnfreezeJob.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/MemberBrokerageRecordUnfreezeJob.java similarity index 81% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/job/brokerage/MemberBrokerageRecordUnfreezeJob.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/MemberBrokerageRecordUnfreezeJob.java index f4512cf089..d41bc840ce 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/job/brokerage/MemberBrokerageRecordUnfreezeJob.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/MemberBrokerageRecordUnfreezeJob.java @@ -1,9 +1,9 @@ -package cn.iocoder.yudao.module.member.job.brokerage; +package cn.iocoder.yudao.module.trade.job.brokerage; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; -import cn.iocoder.yudao.module.member.service.brokerage.record.MemberBrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.record.MemberBrokerageRecordService; import org.springframework.stereotype.Component; import javax.annotation.Resource; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordService.java similarity index 76% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordService.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordService.java index cd966e670c..5cdd9e1b55 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordService.java @@ -1,9 +1,9 @@ -package cn.iocoder.yudao.module.member.service.brokerage.record; +package cn.iocoder.yudao.module.trade.service.brokerage.record; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.member.api.brokerage.dto.BrokerageAddReqDTO; -import cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqDTO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; import java.util.List; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImpl.java similarity index 79% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImpl.java index 32656910c1..e56ae5dab0 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImpl.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.member.service.brokerage.record; +package cn.iocoder.yudao.module.trade.service.brokerage.record; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.BooleanUtil; @@ -6,17 +6,17 @@ import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.member.api.brokerage.dto.BrokerageAddReqDTO; -import cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.member.convert.brokerage.record.MemberBrokerageRecordConvert; -import cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; -import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointConfigDO; -import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; -import cn.iocoder.yudao.module.member.dal.mysql.brokerage.record.MemberBrokerageRecordMapper; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageRecordBizTypeEnum; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageRecordStatusEnum; -import cn.iocoder.yudao.module.member.service.point.MemberPointConfigService; -import cn.iocoder.yudao.module.member.service.user.MemberUserService; +import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqDTO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.convert.brokerage.record.MemberBrokerageRecordConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.MemberBrokerageRecordMapper; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; +import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; +import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -42,9 +42,9 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe @Resource private MemberBrokerageRecordMapper memberBrokerageRecordMapper; @Resource - private MemberPointConfigService memberConfigService; + private TradeConfigService tradeConfigService; @Resource - private MemberUserService memberUserService; + private TradeBrokerageUserService tradeBrokerageUserService; @Override public MemberBrokerageRecordDO getMemberBrokerageRecord(Integer id) { @@ -59,7 +59,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe @Override @Transactional(rollbackFor = Exception.class) public void addBrokerage(Long buyerId, List list) { - MemberPointConfigDO memberConfig = memberConfigService.getPointConfig(); + TradeConfigDO memberConfig = tradeConfigService.getTradeConfig(); // 0 未启用分销功能 if (memberConfig == null || !BooleanUtil.isTrue(memberConfig.getBrokerageEnabled())) { log.warn("[addBrokerage][增加佣金失败:brokerageEnabled 未配置,buyerId({})", buyerId); @@ -67,7 +67,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe } // 1.1 获得一级推广人 - MemberUserDO firstUser = memberUserService.getBrokerageUser(buyerId); + TradeBrokerageUserDO firstUser = tradeBrokerageUserService.getInviteBrokerageUser(buyerId); if (firstUser == null || !BooleanUtil.isTrue(firstUser.getBrokerageEnabled())) { return; } @@ -77,7 +77,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe // 2.1 获得二级推广员 - MemberUserDO secondUser = memberUserService.getUser(firstUser.getBrokerageUserId()); + TradeBrokerageUserDO secondUser = tradeBrokerageUserService.getBrokerageUser(firstUser.getBrokerageUserId()); if (secondUser == null || !BooleanUtil.isTrue(secondUser.getBrokerageEnabled())) { return; } @@ -103,9 +103,9 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe } if (BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus().equals(record.getStatus())) { - memberUserService.updateUserFrozenBrokeragePrice(userId, -record.getPrice()); + tradeBrokerageUserService.updateUserFrozenBrokeragePrice(userId, -record.getPrice()); } else if (BrokerageRecordStatusEnum.SETTLEMENT.getStatus().equals(record.getStatus())) { - memberUserService.updateUserBrokeragePrice(userId, -record.getPrice()); + tradeBrokerageUserService.updateUserBrokeragePrice(userId, -record.getPrice()); } } @@ -140,7 +140,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe * @param brokeragePercent 佣金比例 * @param skuBrokeragePriceFun 商品 SKU 设置的佣金 */ - private void addBrokerage(MemberUserDO user, List list, Integer brokerageFrozenDays, + private void addBrokerage(TradeBrokerageUserDO user, List list, Integer brokerageFrozenDays, Integer brokeragePercent, Function skuBrokeragePriceFun) { // 处理冻结时间 brokerageFrozenDays = ObjectUtil.defaultIfNull(brokerageFrozenDays, 0); @@ -170,10 +170,10 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe if (brokerageFrozenDays > 0) { // 更新用户冻结佣金 - memberUserService.updateUserFrozenBrokeragePrice(user.getId(), totalBrokerage); + tradeBrokerageUserService.updateUserFrozenBrokeragePrice(user.getId(), totalBrokerage); } else { // 更新用户可用佣金 - memberUserService.updateUserBrokeragePrice(user.getId(), totalBrokerage); + tradeBrokerageUserService.updateUserBrokeragePrice(user.getId(), totalBrokerage); } } @@ -214,7 +214,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe } // 更新用户冻结佣金 - memberUserService.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(record.getUserId(), -record.getPrice()); + tradeBrokerageUserService.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(record.getUserId(), -record.getPrice()); log.info("[unfreezeRecord][record({}) 更新为已结算成功]", record.getId()); return true; diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/dto/BrokerageAddReqDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqDTO.java similarity index 89% rename from yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/dto/BrokerageAddReqDTO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqDTO.java index c466452012..a15ef76c03 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/dto/BrokerageAddReqDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqDTO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.member.api.brokerage.dto; +package cn.iocoder.yudao.module.trade.service.brokerage.record.bo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java index 58970d724a..773342e554 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java @@ -53,4 +53,36 @@ public interface TradeBrokerageUserService { * @param brokerageEnabled 推广资格 */ void updateBrokerageEnabled(Long id, Boolean brokerageEnabled); + + /** + * 获得用户的推广人 + * + * @param id 用户编号 + * @return 用户的推广人 + */ + TradeBrokerageUserDO getInviteBrokerageUser(Long id); + + /** + * 更新用户佣金 + * + * @param id 用户编号 + * @param brokeragePrice 用户可用佣金 + */ + void updateUserBrokeragePrice(Long id, int brokeragePrice); + + /** + * 更新用户冻结佣金 + * + * @param id 用户编号 + * @param frozenBrokeragePrice 用户冻结佣金 + */ + void updateUserFrozenBrokeragePrice(Long id, int frozenBrokeragePrice); + + /** + * 更新用户冻结佣金(减少), 更新用户佣金(增加) + * + * @param id 用户编号 + * @param frozenBrokeragePrice 减少冻结佣金(负数) + */ + void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java index acbda456bf..9691a81542 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java @@ -1,17 +1,21 @@ package cn.iocoder.yudao.module.trade.service.brokerage.user; +import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.TradeBrokerageUserMapper; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.Collection; import java.util.List; +import java.util.Optional; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_USER_NOT_EXISTS; /** @@ -60,4 +64,43 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService validateBrokerageUserExists(id); } + @Override + public TradeBrokerageUserDO getInviteBrokerageUser(Long id) { + return Optional.ofNullable(id) + .map(this::getBrokerageUser) + .map(TradeBrokerageUserDO::getBrokerageUserId) + .map(this::getBrokerageUser) + .orElse(null); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateUserBrokeragePrice(Long id, int brokeragePrice) { + if (brokeragePrice > 0) { + brokerageUserMapper.updateBrokeragePriceIncr(id, brokeragePrice); + } else if (brokeragePrice < 0) { + brokerageUserMapper.updateBrokeragePriceDecr(id, brokeragePrice); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateUserFrozenBrokeragePrice(Long id, int frozenBrokeragePrice) { + if (frozenBrokeragePrice > 0) { + brokerageUserMapper.updateFrozenBrokeragePriceIncr(id, frozenBrokeragePrice); + } else if (frozenBrokeragePrice < 0) { + brokerageUserMapper.updateFrozenBrokeragePriceDecr(id, frozenBrokeragePrice); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice) { + Assert.isTrue(frozenBrokeragePrice < 0); + int updateRows = brokerageUserMapper.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(id, frozenBrokeragePrice); + if (updateRows == 0) { + throw exception(MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH); + } + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index e2a0f6baf9..9ab4842b8c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -12,8 +12,8 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; -import cn.iocoder.yudao.module.member.api.brokerage.BrokerageApi; -import cn.iocoder.yudao.module.member.api.brokerage.dto.BrokerageAddReqDTO; +import cn.iocoder.yudao.module.trade.service.brokerage.record.MemberBrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqDTO; import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; import cn.iocoder.yudao.module.member.api.point.MemberPointApi; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; @@ -120,7 +120,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Resource private MemberPointApi memberPointApi; @Resource - private BrokerageApi brokerageApi; + private MemberBrokerageRecordService memberBrokerageRecordService; @Resource private ProductCommentApi productCommentApi; @@ -754,12 +754,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { List orderItems = tradeOrderItemMapper.selectListByOrderId(orderId); List list = convertList(orderItems, item -> TradeOrderConvert.INSTANCE.convert(item, productSkuApi.getSku(item.getSkuId()))); - brokerageApi.addBrokerage(userId, list); + memberBrokerageRecordService.addBrokerage(userId, list); } @Async protected void cancelBrokerageAsync(Long userId, Long orderItemId) { - brokerageApi.cancelBrokerage(userId, String.valueOf(orderItemId)); + memberBrokerageRecordService.cancelBrokerage(userId, String.valueOf(orderItemId)); } /** diff --git a/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImplTest.java similarity index 87% rename from yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImplTest.java rename to yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImplTest.java index d5991b4e8c..ae367ae635 100644 --- a/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/brokerage/record/MemberBrokerageRecordServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImplTest.java @@ -1,13 +1,13 @@ -package cn.iocoder.yudao.module.member.service.brokerage.record; +package cn.iocoder.yudao.module.trade.service.brokerage.record; import cn.hutool.core.util.NumberUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.member.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; -import cn.iocoder.yudao.module.member.dal.mysql.brokerage.record.MemberBrokerageRecordMapper; -import cn.iocoder.yudao.module.member.service.point.MemberPointConfigService; -import cn.iocoder.yudao.module.member.service.user.MemberUserService; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.MemberBrokerageRecordMapper; +import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; +import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.boot.test.mock.mockito.MockBean; @@ -39,9 +39,9 @@ public class MemberBrokerageRecordServiceImplTest extends BaseDbUnitTest { private MemberBrokerageRecordMapper memberBrokerageRecordMapper; @MockBean - private MemberPointConfigService memberPointConfigService; + private TradeConfigService tradeConfigService; @MockBean - private MemberUserService memberUserService; + private TradeBrokerageUserService tradeBrokerageUserService; @Test @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApi.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApi.java deleted file mode 100644 index d01ce58456..0000000000 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApi.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.member.api.brokerage; - -import cn.iocoder.yudao.module.member.api.brokerage.dto.BrokerageAddReqDTO; - -import java.util.List; - -/** - * 佣金 API 接口 - * - * @author owen - */ -public interface BrokerageApi { - - /** - * 增加佣金 - * - * @param userId 会员ID - * @param list 请求参数列表 - */ - void addBrokerage(Long userId, List list); - - /** - * 取消佣金 - * - * @param userId 会员ID - * @param bizId 业务编号 - */ - void cancelBrokerage(Long userId, String bizId); - -} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApiImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApiImpl.java deleted file mode 100644 index 662c5165a8..0000000000 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/brokerage/BrokerageApiImpl.java +++ /dev/null @@ -1,32 +0,0 @@ -package cn.iocoder.yudao.module.member.api.brokerage; - -import cn.iocoder.yudao.module.member.api.brokerage.dto.BrokerageAddReqDTO; -import cn.iocoder.yudao.module.member.service.brokerage.record.MemberBrokerageRecordService; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import javax.annotation.Resource; -import java.util.List; - -/** - * 佣金 API 实现类 - * - * @author owen - */ -@Service -@Validated -public class BrokerageApiImpl implements BrokerageApi { - - @Resource - private MemberBrokerageRecordService memberBrokerageRecordService; - - @Override - public void addBrokerage(Long userId, List list) { - memberBrokerageRecordService.addBrokerage(userId, list); - } - - @Override - public void cancelBrokerage(Long userId, String bizId) { - memberBrokerageRecordService.cancelBrokerage(userId, bizId); - } -} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigBaseVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigBaseVO.java index acdadb6bc4..f946e4a276 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigBaseVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigBaseVO.java @@ -1,17 +1,9 @@ package cn.iocoder.yudao.module.member.controller.admin.point.vo.config; -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageBindModeEnum; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageEnabledConditionEnum; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageWithdrawTypeEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import org.hibernate.validator.constraints.Range; -import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -import javax.validation.constraints.PositiveOrZero; -import java.util.List; /** * 会员积分配置 Base VO,提供给添加、修改、详细的子 VO 使用 @@ -36,53 +28,4 @@ public class MemberPointConfigBaseVO { @NotNull(message = "1 元赠送积分不能为空") private Integer tradeGivePoint; - // ========== 分销相关 ========== - - @Schema(description = "是否启用分佣", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") - @NotNull(message = "是否启用分佣不能为空") - private Boolean brokerageEnabled; - - @Schema(description = "分佣模式", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") - @NotNull(message = "分佣模式不能为空") - @InEnum(value = BrokerageEnabledConditionEnum.class, message = "分佣模式必须是 {value}") - private Integer brokerageEnabledCondition; - - @Schema(description = "分销关系绑定模式", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") - @NotNull(message = "分销关系绑定模式不能为空") - @InEnum(value = BrokerageBindModeEnum.class, message = "分销关系绑定模式必须是 {value}") - private Integer brokerageBindMode; - - @Schema(description = "分销海报图地址数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/yudao.jpg]") - private List brokeragePostUrls; - - @Schema(description = "一级返佣比例", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") - @NotNull(message = "一级返佣比例不能为空") - @Range(min = 0, max = 100, message = "一级返佣比例必须在 0 - 100 之间") - private Integer brokerageFirstPercent; - - @Schema(description = "二级返佣比例", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") - @NotNull(message = "二级返佣比例不能为空") - @Range(min = 0, max = 100, message = "二级返佣比例必须在 0 - 100 之间") - private Integer brokerageSecondPercent; - - @Schema(description = "用户提现最低金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") - @NotNull(message = "用户提现最低金额不能为空") - @PositiveOrZero(message = "用户提现最低金额不能是负数") - private Integer brokerageWithdrawMinPrice; - - @Schema(description = "提现银行", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]") - @NotEmpty(message = "提现银行不能为空") - private List brokerageBankNames; - - @Schema(description = "佣金冻结时间(天)", requiredMode = Schema.RequiredMode.REQUIRED, example = "7") - @NotNull(message = "佣金冻结时间(天)不能为空") - @PositiveOrZero(message = "佣金冻结时间不能是负数") - private Integer brokerageFrozenDays; - - @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]") - @NotNull(message = "提现方式不能为空") - @InEnum(value = BrokerageWithdrawTypeEnum.class, message = "提现方式必须是 {value}") - private List brokerageWithdrawType; - - } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/point/MemberPointConfigDO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/point/MemberPointConfigDO.java index 8f44bd9483..4a6354b039 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/point/MemberPointConfigDO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/point/MemberPointConfigDO.java @@ -1,19 +1,11 @@ package cn.iocoder.yudao.module.member.dal.dataobject.point; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.framework.mybatis.core.type.IntegerListTypeHandler; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageBindModeEnum; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageEnabledConditionEnum; -import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageWithdrawTypeEnum; import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import lombok.*; -import java.util.List; - /** * 会员积分配置 DO * @@ -53,56 +45,4 @@ public class MemberPointConfigDO extends BaseDO { */ private Integer tradeGivePoint; - // ========== 分销相关 ========== - - /** - * 是否启用分佣 - */ - private Boolean brokerageEnabled; - /** - * 分佣模式 - * - * 枚举 {@link BrokerageEnabledConditionEnum 对应的类} - */ - private Integer brokerageEnabledCondition; - /** - * 分销关系绑定模式 - * - * 枚举 {@link BrokerageBindModeEnum 对应的类} - */ - private Integer brokerageBindMode; - /** - * 分销海报图地址数组 - */ - @TableField(typeHandler = JacksonTypeHandler.class) - private List brokeragePostUrls; - /** - * 一级返佣比例 - */ - private Integer brokerageFirstPercent; - /** - * 二级返佣比例 - */ - private Integer brokerageSecondPercent; - /** - * 用户提现最低金额 - */ - private Integer brokerageWithdrawMinPrice; - /** - * 提现银行 - */ - @TableField(typeHandler = IntegerListTypeHandler.class) - private List brokerageBankNames; - /** - * 佣金冻结时间(天) - */ - private Integer brokerageFrozenDays; - /** - * 提现方式 - * - * 枚举 {@link BrokerageWithdrawTypeEnum 对应的类} - */ - @TableField(typeHandler = IntegerListTypeHandler.class) - private List brokerageWithdrawType; - } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java index 2dc47be906..7e35cdf2a7 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java @@ -1,14 +1,12 @@ package cn.iocoder.yudao.module.member.dal.mysql.user; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.lang.Assert; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserPageReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -63,79 +61,4 @@ public interface MemberUserMapper extends BaseMapperX { return selectCount(new LambdaQueryWrapperX() .apply("FIND_IN_SET({0}, tag_ids)", tagId)); } - - /** - * 更新用户可用佣金(增加) - * - * @param id 用户编号 - * @param incrCount 增加佣金(正数) - */ - default void updateBrokeragePriceIncr(Long id, int incrCount) { - Assert.isTrue(incrCount > 0); - LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" brokerage_price = brokerage_price + " + incrCount) - .eq(MemberUserDO::getId, id); - update(null, lambdaUpdateWrapper); - } - - /** - * 更新用户可用佣金(减少) - * 注意:理论上佣金可能已经提现,这时会扣出负数,确保平台不会造成损失 - * - * @param id 用户编号 - * @param incrCount 增加佣金(负数) - */ - default void updateBrokeragePriceDecr(Long id, int incrCount) { - Assert.isTrue(incrCount < 0); - LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" brokerage_price = brokerage_price + " + incrCount) // 负数,所以使用 + 号 - .eq(MemberUserDO::getId, id); - update(null, lambdaUpdateWrapper); - } - - /** - * 更新用户冻结佣金(增加) - * - * @param id 用户编号 - * @param incrCount 增加冻结佣金(正数) - */ - default void updateFrozenBrokeragePriceIncr(Long id, int incrCount) { - Assert.isTrue(incrCount > 0); - LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) - .eq(MemberUserDO::getId, id); - update(null, lambdaUpdateWrapper); - } - - /** - * 更新用户冻结佣金(减少) - * 注意:理论上冻结佣金可能已经解冻,这时会扣出负数,确保平台不会造成损失 - * - * @param id 用户编号 - * @param incrCount 减少冻结佣金(负数) - */ - default void updateFrozenBrokeragePriceDecr(Long id, int incrCount) { - Assert.isTrue(incrCount < 0); - LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) // 负数,所以使用 + 号 - .eq(MemberUserDO::getId, id); - update(null, lambdaUpdateWrapper); - } - - /** - * 更新用户冻结佣金(减少), 更新用户佣金(增加) - * - * @param id 用户编号 - * @param incrCount 减少冻结佣金(负数) - * @return 更新条数 - */ - default int updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int incrCount) { - Assert.isTrue(incrCount < 0); - LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount + // 负数,所以使用 + 号 - ", brokerage_price = brokerage_price + " + -incrCount) // 负数,所以使用 - 号 - .eq(MemberUserDO::getId, id) - .ge(MemberUserDO::getFrozenBrokeragePrice, -incrCount); // cas 逻辑 - return update(null, lambdaUpdateWrapper); - } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java index 7f599a0499..f1a0a72651 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java @@ -166,36 +166,4 @@ public interface MemberUserService { * @param point 积分数量 */ void updateUserPoint(Long userId, Integer point); - - /** - * 获得用户的推广人 - * - * @param id 用户编号 - * @return 用户的推广人 - */ - MemberUserDO getBrokerageUser(Long id); - - /** - * 更新用户佣金 - * - * @param id 用户编号 - * @param brokeragePrice 用户可用佣金 - */ - void updateUserBrokeragePrice(Long id, int brokeragePrice); - - /** - * 更新用户冻结佣金 - * - * @param id 用户编号 - * @param frozenBrokeragePrice 用户冻结佣金 - */ - void updateUserFrozenBrokeragePrice(Long id, int frozenBrokeragePrice); - - /** - * 更新用户冻结佣金(减少), 更新用户佣金(增加) - * - * @param id 用户编号 - * @param frozenBrokeragePrice 减少冻结佣金(负数) - */ - void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index 53b452d7c4..c5b674cc8a 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.member.service.user; -import cn.hutool.core.lang.Assert; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; @@ -31,7 +30,6 @@ import javax.validation.Valid; import java.time.LocalDateTime; import java.util.Collection; import java.util.List; -import java.util.Optional; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; @@ -261,43 +259,4 @@ public class MemberUserServiceImpl implements MemberUserService { memberUserMapper.updateById(new MemberUserDO().setId(userId).setPoint(point)); } - @Override - public MemberUserDO getBrokerageUser(Long id) { - return Optional.ofNullable(id) - .map(this::getUser) - .map(MemberUserDO::getBrokerageUserId) - .map(this::getUser) - .orElse(null); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void updateUserBrokeragePrice(Long id, int brokeragePrice) { - if (brokeragePrice > 0) { - memberUserMapper.updateBrokeragePriceIncr(id, brokeragePrice); - } else if (brokeragePrice < 0) { - memberUserMapper.updateBrokeragePriceDecr(id, brokeragePrice); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void updateUserFrozenBrokeragePrice(Long id, int frozenBrokeragePrice) { - if (frozenBrokeragePrice > 0) { - memberUserMapper.updateFrozenBrokeragePriceIncr(id, frozenBrokeragePrice); - } else if (frozenBrokeragePrice < 0) { - memberUserMapper.updateFrozenBrokeragePriceDecr(id, frozenBrokeragePrice); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice) { - Assert.isTrue(frozenBrokeragePrice < 0); - int updateRows = memberUserMapper.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(id, frozenBrokeragePrice); - if (updateRows == 0) { - throw exception(MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH); - } - } - } From fa53a3b15e4f214df3cddf8950907b4232b39649 Mon Sep 17 00:00:00 2001 From: owen Date: Wed, 6 Sep 2023 00:35:40 +0800 Subject: [PATCH 19/48] =?UTF-8?q?trade:=20MemberBrokerageRecord=20?= =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=E4=B8=BA=20TradeBrokerageRecord?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/brokerage.sql | 14 ++--- ...va => TradeBrokerageRecordController.java} | 32 +++++----- ...O.java => TradeBrokerageRecordBaseVO.java} | 2 +- ...ava => TradeBrokerageRecordPageReqVO.java} | 2 +- ...O.java => TradeBrokerageRecordRespVO.java} | 2 +- ....java => TradeBrokerageRecordConvert.java} | 18 +++--- .../convert/order/TradeOrderConvert.java | 6 +- ...ordDO.java => TradeBrokerageRecordDO.java} | 6 +- .../record/MemberBrokerageRecordMapper.java | 47 --------------- .../record/TradeBrokerageRecordMapper.java | 47 +++++++++++++++ ...a => TradeBrokerageRecordUnfreezeJob.java} | 8 +-- ....java => TradeBrokerageRecordService.java} | 14 ++--- ...a => TradeBrokerageRecordServiceImpl.java} | 58 +++++++++---------- ...eAddReqDTO.java => BrokerageAddReqBO.java} | 4 +- .../order/TradeOrderUpdateServiceImpl.java | 12 ++-- ... TradeBrokerageRecordServiceImplTest.java} | 42 +++++++------- .../src/test/resources/sql/clean.sql | 3 +- .../src/test/resources/sql/create_tables.sql | 23 +++++++- .../src/test/resources/sql/clean.sql | 3 +- .../src/test/resources/sql/create_tables.sql | 23 +------- 20 files changed, 183 insertions(+), 183 deletions(-) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/{MemberBrokerageRecordController.java => TradeBrokerageRecordController.java} (51%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/{MemberBrokerageRecordBaseVO.java => TradeBrokerageRecordBaseVO.java} (98%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/{MemberBrokerageRecordPageReqVO.java => TradeBrokerageRecordPageReqVO.java} (94%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/{MemberBrokerageRecordRespVO.java => TradeBrokerageRecordRespVO.java} (88%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/{MemberBrokerageRecordConvert.java => TradeBrokerageRecordConvert.java} (69%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/{MemberBrokerageRecordDO.java => TradeBrokerageRecordDO.java} (85%) delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/{MemberBrokerageRecordUnfreezeJob.java => TradeBrokerageRecordUnfreezeJob.java} (63%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/{MemberBrokerageRecordService.java => TradeBrokerageRecordService.java} (74%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/{MemberBrokerageRecordServiceImpl.java => TradeBrokerageRecordServiceImpl.java} (78%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/{BrokerageAddReqDTO.java => BrokerageAddReqBO.java} (90%) rename yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/{MemberBrokerageRecordServiceImplTest.java => TradeBrokerageRecordServiceImplTest.java} (66%) diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index 161dfa2567..127fcb7286 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -42,7 +42,7 @@ create index idx_invite_user_id on trade_brokerage_user (brokerage_user_id) comm create index idx_agent on trade_brokerage_user (brokerage_enabled) comment '是否成为推广员'; -create table member_brokerage_record +create table trade_brokerage_record ( id int auto_increment comment '编号' primary key, @@ -65,12 +65,12 @@ create table member_brokerage_record ) comment '佣金记录'; -create index idx_user_id on member_brokerage_record (user_id) comment '用户编号'; -create index idx_biz on member_brokerage_record (biz_type, biz_id) comment '业务'; -create index idx_status on member_brokerage_record (status) comment '状态'; +create index idx_user_id on trade_brokerage_record (user_id) comment '用户编号'; +create index idx_biz on trade_brokerage_record (biz_type, biz_id) comment '业务'; +create index idx_status on trade_brokerage_record (status) comment '状态'; -create table member_brokerage_withdraw +create table trade_brokerage_withdraw ( id int auto_increment comment '编号' primary key, @@ -97,8 +97,8 @@ create table member_brokerage_withdraw ) comment '佣金提现'; -create index idx_user_id on member_brokerage_withdraw (user_id) comment '用户编号'; -create index idx_audit_status on member_brokerage_withdraw (status) comment '状态'; +create index idx_user_id on trade_brokerage_withdraw (user_id) comment '用户编号'; +create index idx_audit_status on trade_brokerage_withdraw (status) comment '状态'; -- 增加字典 insert into system_dict_type(type, name) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/MemberBrokerageRecordController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/TradeBrokerageRecordController.java similarity index 51% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/MemberBrokerageRecordController.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/TradeBrokerageRecordController.java index c4bc9bb37a..38b2f4d71e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/MemberBrokerageRecordController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/TradeBrokerageRecordController.java @@ -2,11 +2,11 @@ package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordRespVO; -import cn.iocoder.yudao.module.trade.convert.brokerage.record.MemberBrokerageRecordConvert; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.MemberBrokerageRecordService; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordRespVO; +import cn.iocoder.yudao.module.trade.convert.brokerage.record.TradeBrokerageRecordConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; +import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -24,28 +24,28 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Tag(name = "管理后台 - 佣金记录") @RestController -@RequestMapping("/trade/member-brokerage-record") +@RequestMapping("/trade/brokerage-record") @Validated -public class MemberBrokerageRecordController { +public class TradeBrokerageRecordController { @Resource - private MemberBrokerageRecordService memberBrokerageRecordService; + private TradeBrokerageRecordService tradeBrokerageRecordService; @GetMapping("/get") @Operation(summary = "获得佣金记录") @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('member:member-brokerage-record:query')") - public CommonResult getMemberBrokerageRecord(@RequestParam("id") Integer id) { - MemberBrokerageRecordDO memberBrokerageRecord = memberBrokerageRecordService.getMemberBrokerageRecord(id); - return success(MemberBrokerageRecordConvert.INSTANCE.convert(memberBrokerageRecord)); + @PreAuthorize("@ss.hasPermission('trade:brokerage-record:query')") + public CommonResult getBrokerageRecord(@RequestParam("id") Integer id) { + TradeBrokerageRecordDO tradeBrokerageRecord = tradeBrokerageRecordService.getBrokerageRecord(id); + return success(TradeBrokerageRecordConvert.INSTANCE.convert(tradeBrokerageRecord)); } @GetMapping("/page") @Operation(summary = "获得佣金记录分页") - @PreAuthorize("@ss.hasPermission('member:member-brokerage-record:query')") - public CommonResult> getMemberBrokerageRecordPage(@Valid MemberBrokerageRecordPageReqVO pageVO) { - PageResult pageResult = memberBrokerageRecordService.getMemberBrokerageRecordPage(pageVO); - return success(MemberBrokerageRecordConvert.INSTANCE.convertPage(pageResult)); + @PreAuthorize("@ss.hasPermission('trade:brokerage-record:query')") + public CommonResult> getBrokerageRecordPage(@Valid TradeBrokerageRecordPageReqVO pageVO) { + PageResult pageResult = tradeBrokerageRecordService.getBrokerageRecordPage(pageVO); + return success(TradeBrokerageRecordConvert.INSTANCE.convertPage(pageResult)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java similarity index 98% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordBaseVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java index 51cd4a6319..1fb87f2949 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java @@ -14,7 +14,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 */ @Data -public class MemberBrokerageRecordBaseVO { +public class TradeBrokerageRecordBaseVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25973") @NotNull(message = "用户编号不能为空") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordPageReqVO.java similarity index 94% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordPageReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordPageReqVO.java index 3a5e05527d..abd948f09e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordPageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordPageReqVO.java @@ -15,7 +15,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class MemberBrokerageRecordPageReqVO extends PageParam { +public class TradeBrokerageRecordPageReqVO extends PageParam { @Schema(description = "用户编号", example = "25973") private Long userId; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordRespVO.java similarity index 88% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordRespVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordRespVO.java index 3550a64bad..724d7d3e59 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordRespVO.java @@ -11,7 +11,7 @@ import java.time.LocalDateTime; @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class MemberBrokerageRecordRespVO extends MemberBrokerageRecordBaseVO { +public class TradeBrokerageRecordRespVO extends TradeBrokerageRecordBaseVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "28896") private Integer id; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/MemberBrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java similarity index 69% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/MemberBrokerageRecordConvert.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java index 48af52cf5b..b84e513543 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/MemberBrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java @@ -2,8 +2,8 @@ package cn.iocoder.yudao.module.trade.convert.brokerage.record; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordRespVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordRespVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; @@ -19,22 +19,22 @@ import java.util.List; * @author owen */ @Mapper -public interface MemberBrokerageRecordConvert { +public interface TradeBrokerageRecordConvert { - MemberBrokerageRecordConvert INSTANCE = Mappers.getMapper(MemberBrokerageRecordConvert.class); + TradeBrokerageRecordConvert INSTANCE = Mappers.getMapper(TradeBrokerageRecordConvert.class); - MemberBrokerageRecordRespVO convert(MemberBrokerageRecordDO bean); + TradeBrokerageRecordRespVO convert(TradeBrokerageRecordDO bean); - List convertList(List list); + List convertList(List list); - PageResult convertPage(PageResult page); + PageResult convertPage(PageResult page); - default MemberBrokerageRecordDO convert(TradeBrokerageUserDO user, String bizId, int brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime) { + default TradeBrokerageRecordDO convert(TradeBrokerageUserDO user, String bizId, int brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime) { // 不冻结时,佣金直接就是结算状态 Integer status = brokerageFrozenDays > 0 ? BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus() : BrokerageRecordStatusEnum.SETTLEMENT.getStatus(); - return new MemberBrokerageRecordDO() + return new TradeBrokerageRecordDO() .setUserId(user.getId()) .setBizType(BrokerageRecordBizTypeEnum.ORDER.getType()) .setBizId(bizId) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index d17b81124c..f42af2d73d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.common.util.string.StrUtils; import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqDTO; +import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; import cn.iocoder.yudao.module.pay.enums.DictTypeConstants; @@ -275,8 +275,8 @@ public interface TradeOrderConvert { TradeOrderDO convert(TradeOrderRemarkReqVO reqVO); - default BrokerageAddReqDTO convert(TradeOrderItemDO item, ProductSkuRespDTO sku) { - return new BrokerageAddReqDTO().setBizId(String.valueOf(item.getId())) + default BrokerageAddReqBO convert(TradeOrderItemDO item, ProductSkuRespDTO sku) { + return new BrokerageAddReqBO().setBizId(String.valueOf(item.getId())) .setPayPrice(item.getPayPrice()).setCount(item.getCount()) .setSkuFirstBrokeragePrice(sku.getSubCommissionFirstPrice()) .setSkuSecondBrokeragePrice(sku.getSubCommissionSecondPrice()); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/MemberBrokerageRecordDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java similarity index 85% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/MemberBrokerageRecordDO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java index 94d37ff89c..0bf7c0cf29 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/MemberBrokerageRecordDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java @@ -15,15 +15,15 @@ import java.time.LocalDateTime; * * @author owen */ -@TableName("member_brokerage_record") -@KeySequence("member_brokerage_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@TableName("trade_brokerage_record") +@KeySequence("trade_brokerage_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) @Builder @NoArgsConstructor @AllArgsConstructor -public class MemberBrokerageRecordDO extends BaseDO { +public class TradeBrokerageRecordDO extends BaseDO { /** * 编号 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java deleted file mode 100644 index da89b8bba9..0000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java +++ /dev/null @@ -1,47 +0,0 @@ -package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import org.apache.ibatis.annotations.Mapper; - -import java.time.LocalDateTime; -import java.util.List; - -/** - * 佣金记录 Mapper - * - * @author owen - */ -@Mapper -public interface MemberBrokerageRecordMapper extends BaseMapperX { - - default PageResult selectPage(MemberBrokerageRecordPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(MemberBrokerageRecordDO::getUserId, reqVO.getUserId()) - .eqIfPresent(MemberBrokerageRecordDO::getBizType, reqVO.getBizType()) - .eqIfPresent(MemberBrokerageRecordDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(MemberBrokerageRecordDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(MemberBrokerageRecordDO::getId)); - } - - default List selectListByStatusAndUnfreezeTimeLt(Integer status, LocalDateTime unfreezeTime) { - return selectList(new LambdaQueryWrapper() - .eq(MemberBrokerageRecordDO::getStatus, status) - .lt(MemberBrokerageRecordDO::getUnfreezeTime, unfreezeTime)); - } - - default int updateByIdAndStatus(Integer id, Integer status, MemberBrokerageRecordDO updateObj) { - return update(updateObj, new LambdaQueryWrapper() - .eq(MemberBrokerageRecordDO::getId, id) - .eq(MemberBrokerageRecordDO::getStatus, status)); - } - - default MemberBrokerageRecordDO selectByUserIdAndBizTypeAndBizId(Integer bizType, String bizId) { - return selectOne(MemberBrokerageRecordDO::getBizType, bizType, - MemberBrokerageRecordDO::getBizId, bizId); - } -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java new file mode 100644 index 0000000000..78efbc53a1 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import org.apache.ibatis.annotations.Mapper; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 佣金记录 Mapper + * + * @author owen + */ +@Mapper +public interface TradeBrokerageRecordMapper extends BaseMapperX { + + default PageResult selectPage(TradeBrokerageRecordPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(TradeBrokerageRecordDO::getUserId, reqVO.getUserId()) + .eqIfPresent(TradeBrokerageRecordDO::getBizType, reqVO.getBizType()) + .eqIfPresent(TradeBrokerageRecordDO::getStatus, reqVO.getStatus()) + .betweenIfPresent(TradeBrokerageRecordDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(TradeBrokerageRecordDO::getId)); + } + + default List selectListByStatusAndUnfreezeTimeLt(Integer status, LocalDateTime unfreezeTime) { + return selectList(new LambdaQueryWrapper() + .eq(TradeBrokerageRecordDO::getStatus, status) + .lt(TradeBrokerageRecordDO::getUnfreezeTime, unfreezeTime)); + } + + default int updateByIdAndStatus(Integer id, Integer status, TradeBrokerageRecordDO updateObj) { + return update(updateObj, new LambdaQueryWrapper() + .eq(TradeBrokerageRecordDO::getId, id) + .eq(TradeBrokerageRecordDO::getStatus, status)); + } + + default TradeBrokerageRecordDO selectByUserIdAndBizTypeAndBizId(Integer bizType, String bizId) { + return selectOne(TradeBrokerageRecordDO::getBizType, bizType, + TradeBrokerageRecordDO::getBizId, bizId); + } +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/MemberBrokerageRecordUnfreezeJob.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/TradeBrokerageRecordUnfreezeJob.java similarity index 63% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/MemberBrokerageRecordUnfreezeJob.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/TradeBrokerageRecordUnfreezeJob.java index d41bc840ce..94218d47e7 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/MemberBrokerageRecordUnfreezeJob.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/TradeBrokerageRecordUnfreezeJob.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.trade.job.brokerage; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; -import cn.iocoder.yudao.module.trade.service.brokerage.record.MemberBrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; import org.springframework.stereotype.Component; import javax.annotation.Resource; @@ -15,14 +15,14 @@ import javax.annotation.Resource; */ @Component @TenantJob -public class MemberBrokerageRecordUnfreezeJob implements JobHandler { +public class TradeBrokerageRecordUnfreezeJob implements JobHandler { @Resource - private MemberBrokerageRecordService memberBrokerageRecordService; + private TradeBrokerageRecordService tradeBrokerageRecordService; @Override public String execute(String param) { - int count = memberBrokerageRecordService.unfreezeRecord(); + int count = tradeBrokerageRecordService.unfreezeRecord(); return StrUtil.format("解冻佣金 {} 个", count); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java similarity index 74% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordService.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java index 5cdd9e1b55..6b83bdbc03 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java @@ -1,9 +1,9 @@ package cn.iocoder.yudao.module.trade.service.brokerage.record; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqDTO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; +import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; import java.util.List; @@ -12,7 +12,7 @@ import java.util.List; * * @author owen */ -public interface MemberBrokerageRecordService { +public interface TradeBrokerageRecordService { /** * 获得佣金记录 @@ -20,7 +20,7 @@ public interface MemberBrokerageRecordService { * @param id 编号 * @return 佣金记录 */ - MemberBrokerageRecordDO getMemberBrokerageRecord(Integer id); + TradeBrokerageRecordDO getBrokerageRecord(Integer id); /** * 获得佣金记录分页 @@ -28,7 +28,7 @@ public interface MemberBrokerageRecordService { * @param pageReqVO 分页查询 * @return 佣金记录分页 */ - PageResult getMemberBrokerageRecordPage(MemberBrokerageRecordPageReqVO pageReqVO); + PageResult getBrokerageRecordPage(TradeBrokerageRecordPageReqVO pageReqVO); /** * 增加佣金 @@ -36,7 +36,7 @@ public interface MemberBrokerageRecordService { * @param userId 会员编号 * @param list 请求参数列表 */ - void addBrokerage(Long userId, List list); + void addBrokerage(Long userId, List list); /** * 取消佣金:将佣金记录,状态修改为已失效 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java similarity index 78% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImpl.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java index e56ae5dab0..5502bcbf75 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java @@ -6,13 +6,13 @@ import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqDTO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.convert.brokerage.record.MemberBrokerageRecordConvert; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +import cn.iocoder.yudao.module.trade.convert.brokerage.record.TradeBrokerageRecordConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; +import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.MemberBrokerageRecordMapper; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.TradeBrokerageRecordMapper; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; @@ -37,28 +37,28 @@ import java.util.function.Function; @Slf4j @Service @Validated -public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordService { +public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordService { @Resource - private MemberBrokerageRecordMapper memberBrokerageRecordMapper; + private TradeBrokerageRecordMapper tradeBrokerageRecordMapper; @Resource private TradeConfigService tradeConfigService; @Resource private TradeBrokerageUserService tradeBrokerageUserService; @Override - public MemberBrokerageRecordDO getMemberBrokerageRecord(Integer id) { - return memberBrokerageRecordMapper.selectById(id); + public TradeBrokerageRecordDO getBrokerageRecord(Integer id) { + return tradeBrokerageRecordMapper.selectById(id); } @Override - public PageResult getMemberBrokerageRecordPage(MemberBrokerageRecordPageReqVO pageReqVO) { - return memberBrokerageRecordMapper.selectPage(pageReqVO); + public PageResult getBrokerageRecordPage(TradeBrokerageRecordPageReqVO pageReqVO) { + return tradeBrokerageRecordMapper.selectPage(pageReqVO); } @Override @Transactional(rollbackFor = Exception.class) - public void addBrokerage(Long buyerId, List list) { + public void addBrokerage(Long buyerId, List list) { TradeConfigDO memberConfig = tradeConfigService.getTradeConfig(); // 0 未启用分销功能 if (memberConfig == null || !BooleanUtil.isTrue(memberConfig.getBrokerageEnabled())) { @@ -73,7 +73,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe } // 1.2 计算一级分佣 - addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqDTO::getSkuFirstBrokeragePrice); + addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqBO::getSkuFirstBrokeragePrice); // 2.1 获得二级推广员 @@ -83,20 +83,20 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe } // 2.2 计算二级分佣 - addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqDTO::getSkuSecondBrokeragePrice); + addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqBO::getSkuSecondBrokeragePrice); } @Override @Transactional(rollbackFor = Exception.class) public void cancelBrokerage(Long userId, String bizId) { - MemberBrokerageRecordDO record = memberBrokerageRecordMapper.selectByUserIdAndBizTypeAndBizId(BrokerageRecordBizTypeEnum.ORDER.getType(), bizId); + TradeBrokerageRecordDO record = tradeBrokerageRecordMapper.selectByUserIdAndBizTypeAndBizId(BrokerageRecordBizTypeEnum.ORDER.getType(), bizId); if (record == null || ObjectUtil.notEqual(record.getUserId(), userId)) { log.error("[cancelBrokerage][userId({})][bizId({}) 更新为已失效失败:记录不存在]", userId, bizId); return; } - MemberBrokerageRecordDO updateObj = new MemberBrokerageRecordDO().setStatus(BrokerageRecordStatusEnum.CANCEL.getStatus()); - int updateRows = memberBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); + TradeBrokerageRecordDO updateObj = new TradeBrokerageRecordDO().setStatus(BrokerageRecordStatusEnum.CANCEL.getStatus()); + int updateRows = tradeBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); if (updateRows == 0) { log.error("[cancelBrokerage][record({}) 更新为已失效失败]", record.getId()); return; @@ -140,8 +140,8 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe * @param brokeragePercent 佣金比例 * @param skuBrokeragePriceFun 商品 SKU 设置的佣金 */ - private void addBrokerage(TradeBrokerageUserDO user, List list, Integer brokerageFrozenDays, - Integer brokeragePercent, Function skuBrokeragePriceFun) { + private void addBrokerage(TradeBrokerageUserDO user, List list, Integer brokerageFrozenDays, + Integer brokeragePercent, Function skuBrokeragePriceFun) { // 处理冻结时间 brokerageFrozenDays = ObjectUtil.defaultIfNull(brokerageFrozenDays, 0); LocalDateTime unfreezeTime = null; @@ -151,12 +151,12 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe // 计算分佣 int totalBrokerage = 0; - List records = new ArrayList<>(); - for (BrokerageAddReqDTO dto : list) { + List records = new ArrayList<>(); + for (BrokerageAddReqBO dto : list) { int brokeragePerItem = calculateBrokerage(dto.getPayPrice(), brokeragePercent, skuBrokeragePriceFun.apply(dto)); if (brokeragePerItem > 0) { int brokerage = brokeragePerItem * dto.getCount(); - records.add(MemberBrokerageRecordConvert.INSTANCE.convert(user, dto.getBizId(), brokerageFrozenDays, brokerage, unfreezeTime)); + records.add(TradeBrokerageRecordConvert.INSTANCE.convert(user, dto.getBizId(), brokerageFrozenDays, brokerage, unfreezeTime)); totalBrokerage += brokerage; } } @@ -166,7 +166,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe } // 保存佣金记录 - memberBrokerageRecordMapper.insertBatch(records); + tradeBrokerageRecordMapper.insertBatch(records); if (brokerageFrozenDays > 0) { // 更新用户冻结佣金 @@ -180,7 +180,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe @Override public int unfreezeRecord() { // 1. 查询待结算的佣金记录 - List records = memberBrokerageRecordMapper.selectListByStatusAndUnfreezeTimeLt( + List records = tradeBrokerageRecordMapper.selectListByStatusAndUnfreezeTimeLt( BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus(), LocalDateTime.now()); if (CollUtil.isEmpty(records)) { return 0; @@ -188,7 +188,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe // 2. 遍历执行 int count = 0; - for (MemberBrokerageRecordDO record : records) { + for (TradeBrokerageRecordDO record : records) { try { boolean successful = getSelf().unfreezeRecord(record); if (successful) { @@ -202,12 +202,12 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe } @Transactional(rollbackFor = Exception.class) - public boolean unfreezeRecord(MemberBrokerageRecordDO record) { + public boolean unfreezeRecord(TradeBrokerageRecordDO record) { // 更新记录状态 - MemberBrokerageRecordDO updateObj = new MemberBrokerageRecordDO() + TradeBrokerageRecordDO updateObj = new TradeBrokerageRecordDO() .setStatus(BrokerageRecordStatusEnum.SETTLEMENT.getStatus()) .setUnfreezeTime(LocalDateTime.now()); - int updateRows = memberBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); + int updateRows = tradeBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); if (updateRows == 0) { log.error("[unfreezeRecord][record({}) 更新为已结算失败]", record.getId()); return false; @@ -225,7 +225,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe * * @return 自己 */ - private MemberBrokerageRecordServiceImpl getSelf() { + private TradeBrokerageRecordServiceImpl getSelf() { return SpringUtil.getBean(getClass()); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java similarity index 90% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqDTO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java index a15ef76c03..a968d14eac 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java @@ -5,13 +5,13 @@ import lombok.Data; import lombok.NoArgsConstructor; /** - * 佣金 增加 Request DTO + * 佣金 增加 Request BO * @author owen */ @Data @NoArgsConstructor @AllArgsConstructor -public class BrokerageAddReqDTO { +public class BrokerageAddReqBO { /** * 业务ID */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 9ab4842b8c..b75b7ac7cf 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -12,8 +12,8 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.MemberBrokerageRecordService; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqDTO; +import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; import cn.iocoder.yudao.module.member.api.point.MemberPointApi; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; @@ -120,7 +120,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Resource private MemberPointApi memberPointApi; @Resource - private MemberBrokerageRecordService memberBrokerageRecordService; + private TradeBrokerageRecordService tradeBrokerageRecordService; @Resource private ProductCommentApi productCommentApi; @@ -752,14 +752,14 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Async protected void addBrokerageAsync(Long userId, Long orderId) { List orderItems = tradeOrderItemMapper.selectListByOrderId(orderId); - List list = convertList(orderItems, + List list = convertList(orderItems, item -> TradeOrderConvert.INSTANCE.convert(item, productSkuApi.getSku(item.getSkuId()))); - memberBrokerageRecordService.addBrokerage(userId, list); + tradeBrokerageRecordService.addBrokerage(userId, list); } @Async protected void cancelBrokerageAsync(Long userId, Long orderItemId) { - memberBrokerageRecordService.cancelBrokerage(userId, String.valueOf(orderItemId)); + tradeBrokerageRecordService.cancelBrokerage(userId, String.valueOf(orderItemId)); } /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java similarity index 66% rename from yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImplTest.java rename to yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java index ae367ae635..a6d8dffb1f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java @@ -3,9 +3,9 @@ package cn.iocoder.yudao.module.trade.service.brokerage.record; import cn.hutool.core.util.NumberUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.MemberBrokerageRecordMapper; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.TradeBrokerageRecordMapper; import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import org.junit.jupiter.api.Disabled; @@ -26,17 +26,17 @@ import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; import static org.junit.jupiter.api.Assertions.assertEquals; /** - * {@link MemberBrokerageRecordServiceImpl} 的单元测试类 + * {@link TradeBrokerageRecordServiceImpl} 的单元测试类 * * @author owen */ -@Import(MemberBrokerageRecordServiceImpl.class) -public class MemberBrokerageRecordServiceImplTest extends BaseDbUnitTest { +@Import(TradeBrokerageRecordServiceImpl.class) +public class TradeBrokerageRecordServiceImplTest extends BaseDbUnitTest { @Resource - private MemberBrokerageRecordServiceImpl memberBrokerageRecordService; + private TradeBrokerageRecordServiceImpl tradeBrokerageRecordService; @Resource - private MemberBrokerageRecordMapper memberBrokerageRecordMapper; + private TradeBrokerageRecordMapper tradeBrokerageRecordMapper; @MockBean private TradeConfigService tradeConfigService; @@ -45,36 +45,36 @@ public class MemberBrokerageRecordServiceImplTest extends BaseDbUnitTest { @Test @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 - public void testGetMemberBrokerageRecordPage() { + public void testGetBrokerageRecordPage() { // mock 数据 - MemberBrokerageRecordDO dbMemberBrokerageRecord = randomPojo(MemberBrokerageRecordDO.class, o -> { // 等会查询到 + TradeBrokerageRecordDO dbBrokerageRecord = randomPojo(TradeBrokerageRecordDO.class, o -> { // 等会查询到 o.setUserId(null); o.setBizType(null); o.setStatus(null); o.setCreateTime(null); }); - memberBrokerageRecordMapper.insert(dbMemberBrokerageRecord); + tradeBrokerageRecordMapper.insert(dbBrokerageRecord); // 测试 userId 不匹配 - memberBrokerageRecordMapper.insert(cloneIgnoreId(dbMemberBrokerageRecord, o -> o.setUserId(null))); + tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setUserId(null))); // 测试 bizType 不匹配 - memberBrokerageRecordMapper.insert(cloneIgnoreId(dbMemberBrokerageRecord, o -> o.setBizType(null))); + tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setBizType(null))); // 测试 status 不匹配 - memberBrokerageRecordMapper.insert(cloneIgnoreId(dbMemberBrokerageRecord, o -> o.setStatus(null))); + tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setStatus(null))); // 测试 createTime 不匹配 - memberBrokerageRecordMapper.insert(cloneIgnoreId(dbMemberBrokerageRecord, o -> o.setCreateTime(null))); + tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setCreateTime(null))); // 准备参数 - MemberBrokerageRecordPageReqVO reqVO = new MemberBrokerageRecordPageReqVO(); + TradeBrokerageRecordPageReqVO reqVO = new TradeBrokerageRecordPageReqVO(); reqVO.setUserId(null); reqVO.setBizType(null); reqVO.setStatus(null); reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); // 调用 - PageResult pageResult = memberBrokerageRecordService.getMemberBrokerageRecordPage(reqVO); + PageResult pageResult = tradeBrokerageRecordService.getBrokerageRecordPage(reqVO); // 断言 assertEquals(1, pageResult.getTotal()); assertEquals(1, pageResult.getList().size()); - assertPojoEquals(dbMemberBrokerageRecord, pageResult.getList().get(0)); + assertPojoEquals(dbBrokerageRecord, pageResult.getList().get(0)); } @Test @@ -84,7 +84,7 @@ public class MemberBrokerageRecordServiceImplTest extends BaseDbUnitTest { Integer percent = randomInt(1, 101); Integer skuBrokeragePrice = randomInt(); // 调用 - int brokerage = memberBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); + int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); // 断言 assertEquals(brokerage, skuBrokeragePrice); } @@ -97,7 +97,7 @@ public class MemberBrokerageRecordServiceImplTest extends BaseDbUnitTest { Integer skuBrokeragePrice = randomEle(new Integer[]{0, null}); System.out.println("skuBrokeragePrice=" + skuBrokeragePrice); // 调用 - int brokerage = memberBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); + int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); // 断言 assertEquals(brokerage, NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue()); } @@ -109,7 +109,7 @@ public class MemberBrokerageRecordServiceImplTest extends BaseDbUnitTest { Integer percent = null; Integer skuBrokeragePrice = null; // 调用 - int brokerage = memberBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); + int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); // 断言 assertEquals(brokerage, 0); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/clean.sql b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/clean.sql index b0715ca164..f02fdcaf1a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/clean.sql +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/clean.sql @@ -2,4 +2,5 @@ DELETE FROM trade_order; DELETE FROM trade_order_item; DELETE FROM trade_after_sale; DELETE FROM trade_after_sale_log; -DELETE FROM "trade_brokerage_user"; +DELETE FROM trade_brokerage_user; +DELETE FROM trade_brokerage_record; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql index df68fd53b4..02045d2c29 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql @@ -142,4 +142,25 @@ CREATE TABLE IF NOT EXISTS "trade_brokerage_user" "deleted" bit NOT NULL DEFAULT FALSE, "tenant_id" bigint NOT NULL DEFAULT '0', PRIMARY KEY ("id") -) COMMENT '分销用户'; \ No newline at end of file +) COMMENT '分销用户'; +CREATE TABLE IF NOT EXISTS "trade_brokerage_record" +( + "id" int NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "user_id" bigint NOT NULL, + "biz_id" varchar NOT NULL, + "biz_type" varchar NOT NULL, + "title" varchar NOT NULL, + "price" int NOT NULL, + "total_price" int NOT NULL, + "description" varchar NOT NULL, + "status" varchar NOT NULL, + "frozen_days" int NOT NULL, + "unfreeze_time" varchar, + "creator" varchar DEFAULT '', + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar DEFAULT '', + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + "tenant_id" bigint not null default '0', + PRIMARY KEY ("id") +) COMMENT '佣金记录'; \ No newline at end of file diff --git a/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/clean.sql b/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/clean.sql index 6981982c44..f972e048d3 100644 --- a/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/clean.sql +++ b/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/clean.sql @@ -2,5 +2,4 @@ DELETE FROM "member_user"; DELETE FROM "member_address"; DELETE FROM "member_tag"; DELETE FROM "member_level"; -DELETE FROM "member_group"; -DELETE FROM "member_brokerage_record"; \ No newline at end of file +DELETE FROM "member_group"; \ No newline at end of file diff --git a/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/create_tables.sql b/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/create_tables.sql index ccefc4bf1b..5fdc526b03 100644 --- a/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/create_tables.sql @@ -89,25 +89,4 @@ CREATE TABLE IF NOT EXISTS "member_group" "deleted" bit NOT NULL DEFAULT FALSE, "tenant_id" bigint not null default '0', PRIMARY KEY ("id") -) COMMENT '用户分组'; -CREATE TABLE IF NOT EXISTS "member_brokerage_record" -( - "id" int NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "user_id" bigint NOT NULL, - "biz_id" varchar NOT NULL, - "biz_type" varchar NOT NULL, - "title" varchar NOT NULL, - "price" int NOT NULL, - "total_price" int NOT NULL, - "description" varchar NOT NULL, - "status" varchar NOT NULL, - "frozen_days" int NOT NULL, - "unfreeze_time" varchar, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint not null default '0', - PRIMARY KEY ("id") -) COMMENT '佣金记录'; \ No newline at end of file +) COMMENT '用户分组'; \ No newline at end of file From 3f51be6a2d26650f103f88d95a4cbe9ad942e2c3 Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Wed, 6 Sep 2023 08:50:22 +0800 Subject: [PATCH 20/48] =?UTF-8?q?=E9=92=B1=E5=8C=85=E3=80=82=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E4=B8=8D=E9=9C=80=E8=A6=81=E7=9A=84=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/delegate/DelegatePayClient.java | 63 ------------------- .../core/client/impl/mock/MockPayClient.java | 5 +- .../client/impl/mock/MockPayClientConfig.java | 28 --------- .../core/enums/channel/PayChannelEnum.java | 3 +- .../admin/order/PayOrderController.java | 1 + 5 files changed, 5 insertions(+), 95 deletions(-) delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/delegate/DelegatePayClient.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/mock/MockPayClientConfig.java diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/delegate/DelegatePayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/delegate/DelegatePayClient.java deleted file mode 100644 index 65958d5a3b..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/delegate/DelegatePayClient.java +++ /dev/null @@ -1,63 +0,0 @@ -package cn.iocoder.yudao.framework.pay.core.client.impl.delegate; - -import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; -import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; -import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; -import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO; -import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; -import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; - -import java.util.Map; - -// TODO @jason:其它模块,主要是无法 pay client 初始化存在问题,所以我感觉,是不是可以搞个 PayClientInitializer 接口。这样,PayClientFactory 去 get 这个支付模式对应的 PayClientInitializer,通过它来创建。具体注入的地方,可以在 PayChannel init 方法那; -/** - * 代理支付 Client 的抽象类。 - * - * 用于支付 Client 由其它模块实现,例如钱包支付 - * - * @author jason - */ -public abstract class DelegatePayClient extends AbstractPayClient { - - private final DelegatePayClient delegate; - - public DelegatePayClient(Long channelId, String channelCode, PayClientConfig config) { - super(channelId, channelCode, config); - delegate = this; - } - - @Override - protected void doInit() { - delegate.doInit(); - } - - @Override - protected PayOrderRespDTO doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) { - return delegate.doUnifiedOrder(reqDTO); - } - - @Override - protected PayOrderRespDTO doGetOrder(String outTradeNo) { - return delegate.doGetOrder(outTradeNo); - } - - @Override - protected PayRefundRespDTO doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) { - return delegate.doUnifiedRefund(reqDTO); - } - - @Override - protected PayRefundRespDTO doGetRefund(String outTradeNo, String outRefundNo) { - return delegate.doGetRefund(outTradeNo, outRefundNo); - } - - @Override - protected PayRefundRespDTO doParseRefundNotify(Map params, String body) { - return delegate.doParseRefundNotify(params, body); - } - - @Override - protected PayOrderRespDTO doParseOrderNotify(Map params, String body) { - return delegate.doParseOrderNotify(params, body); - } -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/mock/MockPayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/mock/MockPayClient.java index 1d3f4d48b1..f26e76c288 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/mock/MockPayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/mock/MockPayClient.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDT import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; +import cn.iocoder.yudao.framework.pay.core.client.impl.NonePayClientConfig; import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; import java.time.LocalDateTime; @@ -17,11 +18,11 @@ import java.util.Map; * * @author jason */ -public class MockPayClient extends AbstractPayClient { +public class MockPayClient extends AbstractPayClient { private static final String MOCK_RESP_SUCCESS_DATA = "MOCK_SUCCESS"; - public MockPayClient(Long channelId, MockPayClientConfig config) { + public MockPayClient(Long channelId, NonePayClientConfig config) { super(channelId, PayChannelEnum.MOCK.getCode(), config); } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/mock/MockPayClientConfig.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/mock/MockPayClientConfig.java deleted file mode 100644 index 3e35c52dc0..0000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/mock/MockPayClientConfig.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.framework.pay.core.client.impl.mock; - -import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; -import lombok.Data; - -import javax.validation.Validator; - -/** - * 模拟支付的 PayClientConfig 实现类 - * - * @author jason - */ -@Data -public class MockPayClientConfig implements PayClientConfig { - - /** - * 配置名称 - * - * 如果不加任何属性,JsonUtils.parseObject2 解析会报错,所以暂时加个名称 - */ - private String name; - - @Override - public void validate(Validator validator) { - // 模拟支付配置无需校验 - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/channel/PayChannelEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/channel/PayChannelEnum.java index cbe0a242aa..4116441538 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/channel/PayChannelEnum.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/channel/PayChannelEnum.java @@ -4,7 +4,6 @@ import cn.hutool.core.util.ArrayUtil; import cn.iocoder.yudao.framework.pay.core.client.impl.NonePayClientConfig; import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayPayClientConfig; -import cn.iocoder.yudao.framework.pay.core.client.impl.mock.MockPayClientConfig; import cn.iocoder.yudao.framework.pay.core.client.impl.weixin.WxPayClientConfig; import lombok.AllArgsConstructor; import lombok.Getter; @@ -30,7 +29,7 @@ public enum PayChannelEnum { ALIPAY_QR("alipay_qr", "支付宝扫码支付", AlipayPayClientConfig.class), ALIPAY_BAR("alipay_bar", "支付宝条码支付", AlipayPayClientConfig.class), - MOCK("mock", "模拟支付", MockPayClientConfig.class), + MOCK("mock", "模拟支付", NonePayClientConfig.class), WALLET("wallet", "钱包支付", NonePayClientConfig.class); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java index 3350b58778..a47031a2a9 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java @@ -70,6 +70,7 @@ public class PayOrderController { @PostMapping("/submit") @Operation(summary = "提交支付订单") public CommonResult submitPayOrder(@RequestBody PayOrderSubmitReqVO reqVO) { + // 钱包支付需要 额外传 user_id 和 user_type if (Objects.equals(reqVO.getChannelCode(), PayChannelEnum.WALLET.getCode())) { Map channelExtras = reqVO.getChannelExtras() == null ? new HashMap<>(8) : reqVO.getChannelExtras(); channelExtras.put("user_id", String.valueOf(WebFrameworkUtils.getLoginUserId())); From 9074312fe301b54a093448427209529622e7b4d9 Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Wed, 6 Sep 2023 10:34:24 +0800 Subject: [PATCH 21/48] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=8E=A5=E5=85=A5?= =?UTF-8?q?=E9=92=B1=E5=8C=85=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-ui-admin/src/utils/constants.js | 4 ++ ...nnelForm.vue => noneConfigChannelForm.vue} | 53 ++++++++++--------- yudao-ui-admin/src/views/pay/app/index.vue | 25 +++++++-- .../src/views/pay/cashier/index.vue | 4 ++ 4 files changed, 56 insertions(+), 30 deletions(-) rename yudao-ui-admin/src/views/pay/app/components/{mockChannelForm.vue => noneConfigChannelForm.vue} (71%) diff --git a/yudao-ui-admin/src/utils/constants.js b/yudao-ui-admin/src/utils/constants.js index d62b1f8fcb..2ce6d00415 100644 --- a/yudao-ui-admin/src/utils/constants.js +++ b/yudao-ui-admin/src/utils/constants.js @@ -163,6 +163,10 @@ export const PayChannelEnum = { MOCK : { "code": "mock", "name": "模拟支付" + }, + WALLET : { + "code": "wallet", + "name": "钱包支付" } } diff --git a/yudao-ui-admin/src/views/pay/app/components/mockChannelForm.vue b/yudao-ui-admin/src/views/pay/app/components/noneConfigChannelForm.vue similarity index 71% rename from yudao-ui-admin/src/views/pay/app/components/mockChannelForm.vue rename to yudao-ui-admin/src/views/pay/app/components/noneConfigChannelForm.vue index e2d6162f1f..51fcc53dd8 100644 --- a/yudao-ui-admin/src/views/pay/app/components/mockChannelForm.vue +++ b/yudao-ui-admin/src/views/pay/app/components/noneConfigChannelForm.vue @@ -5,7 +5,8 @@ + :label="parseInt(dict.value)" + > {{ dict.label }} @@ -22,16 +23,16 @@ diff --git a/yudao-ui-admin/src/views/pay/app/index.vue b/yudao-ui-admin/src/views/pay/app/index.vue index 67a15fe66b..6819af7111 100644 --- a/yudao-ui-admin/src/views/pay/app/index.vue +++ b/yudao-ui-admin/src/views/pay/app/index.vue @@ -170,6 +170,19 @@ + + + + + @@ -228,14 +241,14 @@ import { createApp, updateApp, changeAppStatus, deleteApp, getApp, getAppPage } import { PayChannelEnum, CommonStatusEnum } from "@/utils/constants"; import weixinChannelForm from "@/views/pay/app/components/weixinChannelForm"; import alipayChannelForm from "@/views/pay/app/components/alipayChannelForm"; -import mockChannelForm from '@/views/pay/app/components/mockChannelForm'; +import noneConfigChannelForm from '@/views/pay/app/components/noneConfigChannelForm'; export default { name: "PayApp", components: { weixinChannelForm, alipayChannelForm, - mockChannelForm + noneConfigChannelForm }, data() { return { @@ -391,7 +404,11 @@ export default { return } if (code === 'mock') { - this.$refs['mockChannelFormRef'].open(row.id, code); + this.$refs['noneConfigChannelFormRef'].open(row.id, code); + return + } + if (code === 'wallet') { + this.$refs['noneConfigChannelFormRef'].open(row.id, code); return } }, diff --git a/yudao-ui-admin/src/views/pay/cashier/index.vue b/yudao-ui-admin/src/views/pay/cashier/index.vue index 85d702760a..c10c154aa1 100644 --- a/yudao-ui-admin/src/views/pay/cashier/index.vue +++ b/yudao-ui-admin/src/views/pay/cashier/index.vue @@ -136,6 +136,10 @@ export default { name: '模拟支付', icon: require("@/assets/images/pay/icon/mock.svg"), code: "mock" + }, { + name: '钱包支付', + icon: require("@/assets/images/pay/icon/mock.svg"), + code: "wallet" }], submitLoading: false, // 提交支付的 loading interval: undefined, // 定时任务,轮询是否完成支付 From 2591ab5d36a19ece7b3acff1574410af80c4e3cd Mon Sep 17 00:00:00 2001 From: puhui999 Date: Wed, 6 Sep 2023 11:29:51 +0800 Subject: [PATCH 22/48] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E4=B8=AD=E5=BF=83+?= =?UTF-8?q?=E8=90=A5=E9=94=80=E6=B4=BB=E5=8A=A8=EF=BC=9A=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E9=83=A8=E5=88=86=20TODO=20=E6=8F=90=E5=88=B0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/pojo/CommonResult.java | 10 ++++- .../dto/BargainRecordCreateReqDTO.java | 25 +----------- .../api/combination/CombinationRecordApi.java | 26 ++++++++++--- .../CombinationRecordUpdateStatusReqDTO.java | 39 ------------------- .../promotion/enums/ErrorCodeConstants.java | 2 +- .../combination/CombinationRecordApiImpl.java | 21 ++++++---- .../combination/CombinationRecordDO.java | 6 +-- .../combination/CombinationRecordService.java | 15 ++++--- .../CombinationRecordServiceImpl.java | 21 +++++----- .../seckill/SeckillActivityServiceImpl.java | 12 ++---- .../module/promotion/util/PromotionUtils.java | 26 ------------- .../aftersale/TradeAfterSaleController.java | 10 ++++- .../vo/TradeAfterSaleDetailRespVO.java | 2 +- .../order/vo/TradeOrderDetailRespVO.java | 17 ++++---- .../aftersale/TradeAfterSaleConvert.java | 2 +- .../convert/order/TradeOrderConvert.java | 4 +- .../aftersale/TradeAfterSaleServiceImpl.java | 7 +--- .../order/TradeOrderUpdateServiceImpl.java | 4 +- 18 files changed, 97 insertions(+), 152 deletions(-) delete mode 100644 yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordUpdateStatusReqDTO.java diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/CommonResult.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/CommonResult.java index bfb291b6d8..3a974456e3 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/CommonResult.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/CommonResult.java @@ -41,7 +41,7 @@ public class CommonResult implements Serializable { * 因为 A 方法返回的 CommonResult 对象,不满足调用其的 B 方法的返回,所以需要进行转换。 * * @param result 传入的 result 对象 - * @param 返回的泛型 + * @param 返回的泛型 * @return 新的 CommonResult 对象 */ public static CommonResult error(CommonResult result) { @@ -68,6 +68,14 @@ public class CommonResult implements Serializable { return result; } + public static CommonResult success(T data, String msg) { + CommonResult result = new CommonResult<>(); + result.code = GlobalErrorCodeConstants.SUCCESS.getCode(); + result.data = data; + result.msg = msg; + return result; + } + public static boolean isSuccess(Integer code) { return Objects.equals(code, GlobalErrorCodeConstants.SUCCESS.getCode()); } diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/dto/BargainRecordCreateReqDTO.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/dto/BargainRecordCreateReqDTO.java index 22ef80a1ea..d7835b23c2 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/dto/BargainRecordCreateReqDTO.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/dto/BargainRecordCreateReqDTO.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.promotion.api.bargain.dto; import lombok.Data; -import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; // TODO @芋艿:这块要在看看 @@ -40,17 +39,7 @@ public class BargainRecordCreateReqDTO { */ @NotNull(message = "订单编号不能为空") private Long orderId; - // TODO @puhui999:spuName、picUrl、 之类字段不用传递; - /** - * 商品名字 - */ - @NotEmpty(message = "商品名字不能为空") - private String spuName; - /** - * 商品图片 - */ - @NotEmpty(message = "商品图片不能为空") - private String picUrl; + /** * 砍价商品单价 */ @@ -61,17 +50,7 @@ public class BargainRecordCreateReqDTO { */ @NotNull(message = "商品原价不能为空") private Integer price; - // TODO @puhui999:nickname、avatar 不用传递,去查询; - /** - * 用户昵称 - */ - @NotEmpty(message = "用户昵称不能为空") - private String nickname; - /** - * 用户头像 - */ - @NotEmpty(message = "用户头像不能为空") - private String avatar; + /** * 开团状态:进行中 砍价成功 砍价失败 */ diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java index 631a709069..c03559785d 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java @@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.promotion.api.combination; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordRespDTO; -import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO; import javax.validation.Valid; +import java.time.LocalDateTime; import java.util.List; // TODO @芋艿:后面也再撸撸这几个接口 @@ -51,13 +51,29 @@ public interface CombinationRecordApi { */ void validateCombinationLimitCount(Long activityId, Integer count, Integer sumCount); - // TODO @puhui999:是不是搞成具体的方法,拼团成功,拼团失败,这种方法; + /** + * 更新拼团状态为 成功 + * + * @param userId 用户编号 + * @param orderId 订单编号 + */ + void updateRecordStatusToSuccess(Long userId, Long orderId); /** - * 更新开团记录状态 + * 更新拼团状态为 失败 * - * @param reqDTO 请求 DTO + * @param userId 用户编号 + * @param orderId 订单编号 */ - void updateCombinationRecordStatus(CombinationRecordUpdateStatusReqDTO reqDTO); + void updateRecordStatusToFailed(Long userId, Long orderId); + + /** + * 更新拼团状态为 进行中 + * + * @param userId 用户编号 + * @param orderId 订单编号 + * @param startTime 开始时间 + */ + void updateRecordStatusToInProgress(Long userId, Long orderId, LocalDateTime startTime); } diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordUpdateStatusReqDTO.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordUpdateStatusReqDTO.java deleted file mode 100644 index 3ba49ff369..0000000000 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordUpdateStatusReqDTO.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.yudao.module.promotion.api.combination.dto; - -import lombok.Data; - -import javax.validation.constraints.NotNull; -import java.time.LocalDateTime; - -/** - * 拼团记录的更新状态 Request DTO - * - * @author HUIHUI - */ -@Data -public class CombinationRecordUpdateStatusReqDTO { - - /** - * 用户编号 - */ - @NotNull(message = "用户编号不能为空") - private Long userId; - - /** - * 订单编号 - */ - @NotNull(message = "订单编号不能为空") - private Long orderId; - - /** - * 开团状态:正在开团 拼团成功 拼团失败 - */ - @NotNull(message = "开团状态不能为空") - private Integer status; - - /** - * 团开始时间 - */ - private LocalDateTime startTime; - -} diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index 8f5b8c8036..dd4389d5df 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -51,7 +51,7 @@ public interface ErrorCodeConstants { // ========== 秒杀活动 1013008000 ========== ErrorCode SECKILL_ACTIVITY_NOT_EXISTS = new ErrorCode(1013008000, "秒杀活动不存在"); - ErrorCode SECKILL_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1013008002, "存在商品参加了其它秒杀活动"); + ErrorCode SECKILL_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1013008002, "存在商品参加了其它秒杀活动,秒杀时段冲突"); ErrorCode SECKILL_ACTIVITY_UPDATE_FAIL_STATUS_CLOSED = new ErrorCode(1013008003, "秒杀活动已关闭,不能修改"); ErrorCode SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013008004, "秒杀活动未关闭或未结束,不能删除"); ErrorCode SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED = new ErrorCode(1013008005, "秒杀活动已关闭,不能重复关闭"); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java index e9dd9d201b..7f7ec6170c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java @@ -2,13 +2,13 @@ package cn.iocoder.yudao.module.promotion.api.combination; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordRespDTO; -import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO; import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.time.LocalDateTime; import java.util.List; /** @@ -43,12 +43,19 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { } @Override - public void updateCombinationRecordStatus(CombinationRecordUpdateStatusReqDTO reqDTO) { - if (null == reqDTO.getStartTime()) { - recordService.updateCombinationRecordStatusByUserIdAndOrderId(reqDTO); - } else { - recordService.updateCombinationRecordStatusAndStartTimeByUserIdAndOrderId(reqDTO); - } + public void updateRecordStatusToSuccess(Long userId, Long orderId) { + recordService.updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordStatusEnum.SUCCESS.getStatus(), userId, orderId); + } + + @Override + public void updateRecordStatusToFailed(Long userId, Long orderId) { + recordService.updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordStatusEnum.FAILED.getStatus(), userId, orderId); + } + + @Override + public void updateRecordStatusToInProgress(Long userId, Long orderId, LocalDateTime startTime) { + recordService.updateRecordStatusAndStartTimeByUserIdAndOrderId(CombinationRecordStatusEnum.IN_PROGRESS.getStatus(), + userId, orderId, startTime); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java index f89c8f7eec..898d2a822c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java @@ -86,11 +86,11 @@ public class CombinationRecordDO extends BaseDO { */ private Boolean virtualGroup; /** - * 过期时间,单位:小时 + * 过期时间 * - * 关联 {@link CombinationActivityDO#getLimitDuration()} + * {@link CombinationRecordDO#getStartTime()} + {@link CombinationActivityDO#getLimitDuration()} 计算 */ - private Integer expireTime; + private LocalDateTime expireTime; /** * 开始时间 (订单付款后开始的时间) */ diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java index 6c12cb5510..fbc51c6b9e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java @@ -1,9 +1,9 @@ package cn.iocoder.yudao.module.promotion.service.combination; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; -import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; +import java.time.LocalDateTime; import java.util.List; /** @@ -16,9 +16,11 @@ public interface CombinationRecordService { /** * 更新拼团状态 * - * @param reqDTO 请求 DTO + * @param status 状态 + * @param userId 用户编号 + * @param orderId 订单编号 */ - void updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordUpdateStatusReqDTO reqDTO); + void updateCombinationRecordStatusByUserIdAndOrderId(Integer status, Long userId, Long orderId); /** * 创建拼团记录 @@ -30,9 +32,12 @@ public interface CombinationRecordService { /** * 更新拼团状态和开始时间 * - * @param reqDTO 请求 DTO + * @param status 状态 + * @param userId 用户编号 + * @param orderId 订单编号 + * @param startTime 开始时间 */ - void updateCombinationRecordStatusAndStartTimeByUserIdAndOrderId(CombinationRecordUpdateStatusReqDTO reqDTO); + void updateRecordStatusAndStartTimeByUserIdAndOrderId(Integer status, Long userId, Long orderId, LocalDateTime startTime); /** * 获得拼团状态 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index 4e2f85e274..bc9c1df4c0 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.promotion.service.combination; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; -import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO; import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; @@ -21,6 +20,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; // TODO 芋艿:等拼团记录做完,完整 review 下 + /** * 拼团记录 Service 实现类 * @@ -38,27 +38,27 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Override @Transactional(rollbackFor = Exception.class) - public void updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordUpdateStatusReqDTO reqDTO) { + public void updateCombinationRecordStatusByUserIdAndOrderId(Integer status, Long userId, Long orderId) { // 校验拼团是否存在 - CombinationRecordDO recordDO = validateCombinationRecord(reqDTO.getUserId(), reqDTO.getOrderId()); + CombinationRecordDO recordDO = validateCombinationRecord(userId, orderId); // 更新状态 - recordDO.setStatus(reqDTO.getStatus()); + recordDO.setStatus(status); recordMapper.updateById(recordDO); } @Override @Transactional(rollbackFor = Exception.class) - public void updateCombinationRecordStatusAndStartTimeByUserIdAndOrderId(CombinationRecordUpdateStatusReqDTO reqDTO) { - CombinationRecordDO recordDO = validateCombinationRecord(reqDTO.getUserId(), reqDTO.getOrderId()); + public void updateRecordStatusAndStartTimeByUserIdAndOrderId(Integer status, Long userId, Long orderId, LocalDateTime startTime) { + CombinationRecordDO recordDO = validateCombinationRecord(userId, orderId); // 更新状态 - recordDO.setStatus(reqDTO.getStatus()); + recordDO.setStatus(status); // 更新开始时间 - recordDO.setStartTime(reqDTO.getStartTime()); + recordDO.setStartTime(startTime); recordMapper.updateById(recordDO); // 更新拼团参入人数 - List recordDOs = recordMapper.selectListByHeadIdAndStatus(recordDO.getHeadId(), reqDTO.getStatus()); + List recordDOs = recordMapper.selectListByHeadIdAndStatus(recordDO.getHeadId(), status); if (CollUtil.isNotEmpty(recordDOs)) { recordDOs.forEach(item -> { item.setUserCount(recordDOs.size()); @@ -115,8 +115,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { // 2. 创建拼团记录 CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO); record.setVirtualGroup(false); - // TODO @puhui999:过期时间,应该是 Date 哈; - record.setExpireTime(activity.getLimitDuration()); + record.setExpireTime(record.getStartTime().plusHours(activity.getLimitDuration())); record.setUserSize(activity.getUserSize()); recordMapper.insert(record); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java index a3577a50bf..531c35fcba 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java @@ -92,15 +92,9 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { if (activityId != null) { // 排除自己 activityList.removeIf(item -> ObjectUtil.equal(item.getId(), activityId)); } - // TODO @puhui999:一个 spu,参与两个活动应该没关系,关键是活动时间不充能重叠; - // 2.2 过滤出所有 spuId 有交集的活动,判断是否存在重叠 - List activityDOs1 = filterList(activityList, s -> ObjectUtil.equal(s.getSpuId(), spuId)); - if (isNotEmpty(activityDOs1)) { - throw exception(SECKILL_ACTIVITY_SPU_CONFLICTS); - } - // 2.3 过滤出所有 configIds 有交集的活动,判断是否存在重叠 - List activityDOs2 = filterList(activityList, s -> containsAny(s.getConfigIds(), configIds)); - if (isNotEmpty(activityDOs2)) { + // 2.2 过滤出所有 configIds 有交集的活动,判断是否存在重叠 + List activityDOs = filterList(activityList, s -> containsAny(s.getConfigIds(), configIds)); + if (isNotEmpty(activityDOs)) { throw exception(SECKILL_ACTIVITY_SPU_CONFLICTS); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java index dd5551fe28..2ad362fe26 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/util/PromotionUtils.java @@ -1,18 +1,9 @@ package cn.iocoder.yudao.module.promotion.util; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; -import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import java.time.LocalDateTime; -import java.util.List; -import java.util.Set; -import java.util.function.Function; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.anyMatch; -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS; /** * 活动工具类 @@ -31,21 +22,4 @@ public class PromotionUtils { return LocalDateTimeUtils.beforeNow(endTime) ? CommonStatusEnum.DISABLE.getStatus() : CommonStatusEnum.ENABLE.getStatus(); } - /** - * 校验商品 sku 是否都存在 - * - * @param skus 数据库中的商品 skus - * @param products 需要校验的商品 - * @param func 获取需要校验的商品的 skuId - */ - public static void validateProductSkuAllExists(List skus, List products, Function func) { - // 校验 sku 个数是否一致 - Set skuIdsSet = CollectionUtils.convertSet(products, func); - Set skuIdsSet1 = CollectionUtils.convertSet(skus, ProductSkuRespDTO::getId); - // 校验 skuId 是否存在 - if (anyMatch(skuIdsSet, s -> !skuIdsSet1.contains(s))) { - throw exception(SKU_NOT_EXISTS); - } - } - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java index 689f3540b6..60afbc0ab0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java @@ -36,6 +36,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.AFTER_SALE_NOT_FOUND; @Tag(name = "管理后台 - 售后订单") @RestController @@ -76,6 +77,9 @@ public class TradeAfterSaleController { public CommonResult getOrderDetail(@RequestParam("id") Long id) { // 查询订单 TradeAfterSaleDO afterSale = afterSaleService.getAfterSale(id); + if (afterSale == null) { + return success(null, AFTER_SALE_NOT_FOUND.getMsg()); + } // 查询订单 TradeOrderDO order = tradeOrderQueryService.getOrder(afterSale.getOrderId()); // 查询订单项 @@ -92,7 +96,11 @@ public class TradeAfterSaleController { TradeAfterSaleLogRespDTO respVO = new TradeAfterSaleLogRespDTO(); respVO.setId((long) i); respVO.setUserId((long) i); - respVO.setUserType(1); + respVO.setUserType(i % 2 == 0 ? 2 : 1); + // 模拟系统操作 + if (i == 2) { + respVO.setUserType(3); + } respVO.setAfterSaleId(id); respVO.setOrderId((long) i); respVO.setOrderItemId((long) i); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleDetailRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleDetailRespVO.java index aff9f5087d..af6db85c7b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleDetailRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleDetailRespVO.java @@ -35,7 +35,7 @@ public class TradeAfterSaleDetailRespVO extends TradeAfterSaleBaseVO { /** * 售后日志 */ - private List afterSaleLog; + private List logs; @Schema(description = "管理后台 - 交易订单的详情的订单项目") @Data diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/vo/TradeOrderDetailRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/vo/TradeOrderDetailRespVO.java index fa1e77d0e7..4ba8ed4f88 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/vo/TradeOrderDetailRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/vo/TradeOrderDetailRespVO.java @@ -26,24 +26,23 @@ public class TradeOrderDetailRespVO extends TradeOrderBaseVO { private MemberUserRespVO user; /** - * TODO 订单操作日志, 先模拟一波;返回 logs,简洁,然后复数哈 + * TODO 订单操作日志, 先模拟一波 */ - private List orderLog; + private List logs; - // TODO @puhui999:swagger 注解 + @Schema(description = "管理后台 - 交易订单的操作日志") @Data public static class OrderLog { - /** - * 内容 - */ + @Schema(description = "操作详情", requiredMode = Schema.RequiredMode.REQUIRED, example = "订单发货") private String content; - /** - * 创建时间 - */ + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2023-06-01 10:50:20") private LocalDateTime createTime; + @Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer userType; + } @Schema(description = "管理后台 - 交易订单的详情的订单项目") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java index d4f481c371..0c84c69673 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java @@ -78,7 +78,7 @@ public interface TradeAfterSaleConvert { // 处理订单信息 respVO.setOrder(convert(order)); // 处理售后日志 - respVO.setAfterSaleLog(convertList1(logs)); + respVO.setLogs(convertList1(logs)); return respVO; } List convertList1(List list); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index df7b296f0c..07e9595fc4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -93,6 +93,7 @@ public interface TradeOrderConvert { items.forEach(item -> item.setIncrCount(-item.getIncrCount())); return new ProductSkuUpdateStockReqDTO(items); } + List convertList(List list); @Mappings({ @@ -151,9 +152,10 @@ public interface TradeOrderConvert { TradeOrderDetailRespVO.OrderLog orderLog = new TradeOrderDetailRespVO.OrderLog(); orderLog.setContent("订单操作" + i); orderLog.setCreateTime(LocalDateTime.now()); + orderLog.setUserType(i % 2 == 0 ? 2 : 1); orderLogs.add(orderLog); } - orderVO.setOrderLog(orderLogs); + orderVO.setLogs(orderLogs); return orderVO; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java index eae9837997..f54563d42d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java @@ -90,12 +90,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa @Override public TradeAfterSaleDO getAfterSale(Long id) { - TradeAfterSaleDO afterSale = tradeAfterSaleMapper.selectById(id); - // TODO @puhui999;读不到,不要这里报错哈;交给前端报错;一般是读取信息不到,message 提示,然后 close tab; - if (afterSale == null) { - throw exception(AFTER_SALE_NOT_FOUND); - } - return afterSale; + return tradeAfterSaleMapper.selectById(id); } // TODO 芋艿:拼团失败,要不要发起售后的方式退款?还是走取消逻辑? diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index f887b71e86..c4cfaee832 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -28,7 +28,6 @@ import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; import cn.iocoder.yudao.module.promotion.api.bargain.BargainRecordApi; import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordRespDTO; -import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO; import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; @@ -352,8 +351,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 1、拼团活动 if (Objects.equals(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { // 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录 - combinationRecordApi.updateCombinationRecordStatus(new CombinationRecordUpdateStatusReqDTO().setUserId(order.getUserId()) - .setOrderId(order.getId()).setStatus(CombinationRecordStatusEnum.IN_PROGRESS.getStatus()).setStartTime(LocalDateTime.now())); + combinationRecordApi.updateRecordStatusToInProgress(order.getUserId(), order.getId(), LocalDateTime.now()); } // TODO 芋艿:发送订单变化的消息 From 62a4e8242b924381501ced897e098d0789d81696 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 6 Sep 2023 23:50:23 +0800 Subject: [PATCH 23/48] =?UTF-8?q?=E5=88=86=E9=94=80=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=8F=90=E7=8E=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../brokerage/AppBrokerageUserController.java | 11 ++++++ .../AppBrokerageWithdrawController.java | 14 +++++-- .../vo/user/AppBrokerageUserRespVO.java | 16 ++++++++ .../AppBrokerageWithdrawCreateReqVO.java | 29 +++++++++++++++ .../app/config/AppTradeConfigController.java | 37 +++++++++++++++++++ .../app/config/vo/AppTradeConfigRespVO.java | 21 +++++++++++ .../vo/config/AppDeliveryConfigRespVO.java | 2 +- 7 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index 31de03ea13..1b760be059 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -28,6 +28,17 @@ import static java.util.Arrays.asList; @Slf4j public class AppBrokerageUserController { + // TODO 芋艿:临时 mock => + @GetMapping("/get") + @Operation(summary = "获得个人分销信息") + @PreAuthenticated + public CommonResult getBrokerageUser() { + AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO() + .setBrokeragePrice(2000) + .setFrozenBrokeragePrice(3000); + return success(respVO); + } + // TODO 芋艿:临时 mock => @GetMapping("/get-summary") @Operation(summary = "获得个人分销统计") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java index 1f69b35937..1f6d383eaf 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java @@ -3,15 +3,15 @@ package cn.iocoder.yudao.module.trade.controller.app.brokerage; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import javax.validation.Valid; import java.time.LocalDateTime; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -36,4 +36,12 @@ public class AppBrokerageWithdrawController { return success(new PageResult<>(asList(vo1, vo2), 10L)); } + // TODO 芋艿:临时 mock => + @PostMapping("/create") + @Operation(summary = "创建分销提现") + @PreAuthenticated + public CommonResult createBrokerageWithdraw(@RequestBody @Valid AppBrokerageWithdrawCreateReqVO createReqVO) { + return success(1L); + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java new file mode 100644 index 0000000000..04f1a72780 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "用户 App - 分销用户信息 Response VO") +@Data +public class AppBrokerageUserRespVO { + + @Schema(description = "可用的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2408") + private Integer brokeragePrice; + + @Schema(description = "冻结的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "234") + private Integer frozenBrokeragePrice; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java new file mode 100644 index 0000000000..75aec997be --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.hibernate.validator.constraints.URL; + +import javax.validation.constraints.Min; + +@Schema(description = "用户 App - 分销提现创建 Request VO") +@Data +public class AppBrokerageWithdrawCreateReqVO { + + // TODO @疯狂:参数校验逻辑,需要根据 type 进行不同的校验;感觉可以通过分组? + + @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer type; + + @Schema(description = "提现账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456789") // 银行卡号/微信账号/支付宝账号 + private String accountNo; + + @Schema(description = "收款码的图片", example = "https://www.iocoder.cn/1.png") + @URL(message = "收款码的图片,必须是一个 URL") + private String accountQrCodeUrl; + + @Schema(description = "提现金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") + @Min(value = 1, message = "提现金额必须大于 1") + private Integer price; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java new file mode 100644 index 0000000000..65c879a02d --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.trade.controller.app.config; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.trade.controller.app.config.vo.AppTradeConfigRespVO; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static java.util.Arrays.asList; + +@Tag(name = "用户 App - 交易配置") +@RestController +@RequestMapping("/trade/config") +@RequiredArgsConstructor +@Validated +@Slf4j +public class AppTradeConfigController { + + @GetMapping("/get") + public CommonResult getTradeConfig() { + AppTradeConfigRespVO respVO = new AppTradeConfigRespVO(); + respVO.setBrokeragePosterUrls(asList( + "https://api.java.crmeb.net/crmebimage/product/2020/08/03/755bf516b1ca4b6db3bfeaa4dd5901cdh71kob20re.jpg", + "https://api.java.crmeb.net/crmebimage/maintain/2021/03/01/406d729b84ed4ec9a2171bfcf6fd0634ughzbz9kfi.jpg", + "https://api.java.crmeb.net/crmebimage/maintain/2021/03/01/efb1e4e7fe604fe1988b4213ce08cb11tdsyijtd2r.jpg" + )); + respVO.setBrokerageFrozenDays(10); + respVO.setBrokerageWithdrawMinPrice(100); + return success(respVO); + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java new file mode 100644 index 0000000000..73abf7ab46 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.trade.controller.app.config.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.List; + +@Schema(description = "用户 App - 交易配置 Response VO") +@Data +public class AppTradeConfigRespVO { + + @Schema(description = "分销海报地址数组", requiredMode = Schema.RequiredMode.REQUIRED) + private List brokeragePosterUrls; + + @Schema(description = "佣金冻结时间(天)", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Integer brokerageFrozenDays; + + @Schema(description = "佣金提现最小金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") + private Integer brokerageWithdrawMinPrice; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/vo/config/AppDeliveryConfigRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/vo/config/AppDeliveryConfigRespVO.java index 44b1326c14..744ae97c83 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/vo/config/AppDeliveryConfigRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/vo/config/AppDeliveryConfigRespVO.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.trade.controller.app.delivery.vo.config; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -// TODO 芋艿:后续要实现下,配送配置 +// TODO 芋艿:后续要实现下,配送配置;后续融合到 AppTradeConfigRespVO 中 @Schema(description = "用户 App - 配送配置 Response VO") @Data public class AppDeliveryConfigRespVO { From b8a4d8cab2869e7e4d58b267c101f92c92dde319 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 7 Sep 2023 12:29:50 +0800 Subject: [PATCH 24/48] =?UTF-8?q?=E5=88=86=E9=94=80=EF=BC=9A=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/member/dal/dataobject/user/MemberUserDO.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java index 8e6c99aac0..cfa93c9835 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java @@ -141,26 +141,32 @@ public class MemberUserDO extends TenantBaseDO { /** * 推广员编号 */ + @TableField(exist = false) // TODO 芋艿:避免报错 private Long brokerageUserId; /** * 推广员绑定时间 */ + @TableField(exist = false) // TODO 芋艿:避免报错 private LocalDateTime brokerageBindTime; /** * 是否成为推广员 */ + @TableField(exist = false) // TODO 芋艿:避免报错 private Boolean brokerageEnabled; /** * 成为分销员时间 */ + @TableField(exist = false) // TODO 芋艿:避免报错 private LocalDateTime brokerageTime; /** * 可用佣金 */ + @TableField(exist = false) // TODO 芋艿:避免报错 private Integer brokeragePrice; /** * 冻结佣金 */ + @TableField(exist = false) // TODO 芋艿:避免报错 private Integer frozenBrokeragePrice; } From 5808f77ade3c0843c4119ea7e1744c2b638a6f81 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 8 Sep 2023 00:29:25 +0800 Subject: [PATCH 25/48] =?UTF-8?q?code=20review=EF=BC=9A=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=88=86=E4=BD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-dependencies/pom.xml | 4 +- .../mybatis/core/mapper/BaseMapperX.java | 8 ++- .../api/sku/dto/ProductSkuRespDTO.java | 1 + .../trade/enums/ErrorCodeConstants.java | 14 +++--- .../brokerage/BrokerageBindModeEnum.java | 2 + .../BrokerageEnabledConditionEnum.java | 1 + .../brokerage/BrokerageRecordBizTypeEnum.java | 1 + .../record/vo/TradeBrokerageRecordBaseVO.java | 5 +- ...kerageUserUpdateBrokerageEnabledReqVO.java | 2 + .../admin/config/vo/TradeConfigBaseVO.java | 1 + .../record/TradeBrokerageRecordConvert.java | 2 +- .../record/TradeBrokerageRecordDO.java | 16 +++--- .../brokerage/user/TradeBrokerageUserDO.java | 7 +++ .../record/TradeBrokerageRecordMapper.java | 2 + .../yudao/module/trade/job/package-info.java | 4 ++ .../record/TradeBrokerageRecordService.java | 4 ++ .../TradeBrokerageRecordServiceImpl.java | 49 ++++++++++--------- .../record/bo/BrokerageAddReqBO.java | 8 +++ .../user/TradeBrokerageUserService.java | 3 ++ .../user/TradeBrokerageUserServiceImpl.java | 20 +++++--- .../service/config/TradeConfigService.java | 1 - .../TradeBrokerageRecordServiceImplTest.java | 1 + .../TradeBrokerageUserServiceImplTest.java | 1 + .../member/enums/ErrorCodeConstants.java | 2 +- .../dal/dataobject/user/MemberUserDO.java | 1 + .../dal/mysql/user/MemberUserMapper.java | 1 + 26 files changed, 108 insertions(+), 53 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/package-info.java diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index f3273f02a9..849be7b87b 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -27,7 +27,7 @@ 3.5.3.2 3.5.3.2 3.6.1 - 1.4.5 + 1.4.6 3.18.0 8.1.2.141 @@ -220,7 +220,7 @@ com.github.yulichang mybatis-plus-join-boot-starter - ${mybatis-plus-join-boot-starter.version} + ${mybatis-plus-join.version} diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java index eebe42d11a..3383ec879f 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java @@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.baomidou.mybatisplus.extension.toolkit.Db; +import com.github.yulichang.base.MPJBaseMapper; import org.apache.ibatis.annotations.Param; import java.util.Collection; @@ -18,8 +19,11 @@ import java.util.List; /** * 在 MyBatis Plus 的 BaseMapper 的基础上拓展,提供更多的能力 + * + * 1. {@link BaseMapper} 为 MyBatis Plus 的基础接口,提供基础的 CRUD 能力 + * 2. {@link MPJBaseMapper} 为 MyBatis Plus Join 的基础接口,提供连表 Join 能力 */ -public interface BaseMapperX extends BaseMapper { +public interface BaseMapperX extends MPJBaseMapper { default PageResult selectPage(PageParam pageParam, @Param("ew") Wrapper queryWrapper) { // MyBatis Plus 查询 @@ -128,4 +132,4 @@ public interface BaseMapperX extends BaseMapper { Db.saveOrUpdateBatch(collection); } -} \ No newline at end of file +} diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/dto/ProductSkuRespDTO.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/dto/ProductSkuRespDTO.java index 2899fc0759..c412faf4e6 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/dto/ProductSkuRespDTO.java +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/dto/ProductSkuRespDTO.java @@ -60,6 +60,7 @@ public class ProductSkuRespDTO { */ private Double volume; + // TODO @puhui:这 2 字段,需要改下;firstBrokerageRecord、secondBrokerageRecord;和分佣保持一致; /** * 一级分销的佣金,单位:分 */ diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 3107dbedf0..f6c0ca7827 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -11,7 +11,7 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; */ public interface ErrorCodeConstants { - // ========== Order 模块 1011000000 ========== + // ========== Order 模块 1011000000 ========== ErrorCode ORDER_CREATE_SKU_NOT_FOUND = new ErrorCode(1011000001, "商品 SKU 不存在"); ErrorCode ORDER_CREATE_SPU_NOT_SALE = new ErrorCode(1011000002, "商品 SPU 不可售卖"); ErrorCode ORDER_CREATE_SKU_STOCK_NOT_ENOUGH = new ErrorCode(1011000004, "商品 SKU 库存不足"); @@ -35,7 +35,7 @@ public interface ErrorCodeConstants { ErrorCode ORDER_DELIVERY_FAIL_DELIVERY_TYPE_NOT_EXPRESS = new ErrorCode(1011000024, "交易订单发货失败,发货类型不是快递"); ErrorCode ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID = new ErrorCode(1011000025, "交易订单取消失败,订单不是【待支付】状态"); - // ========== After Sale 模块 1011000100 ========== + // ========== After Sale 模块 1011000100 ========== ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在"); ErrorCode AFTER_SALE_CREATE_FAIL_REFUND_PRICE_ERROR = new ErrorCode(1011000101, "申请退款金额错误"); ErrorCode AFTER_SALE_CREATE_FAIL_ORDER_STATUS_CANCELED = new ErrorCode(1011000102, "订单已关闭,无法申请售后"); @@ -50,7 +50,7 @@ public interface ErrorCodeConstants { ErrorCode AFTER_SALE_CANCEL_FAIL_STATUS_NOT_APPLY_OR_AGREE_OR_BUYER_DELIVERY = new ErrorCode(1011000111, "取消售后单失败,售后单状态不是【待审核】或【卖家同意】或【商家待收货】"); - // ========== Cart 模块 1011002000 ========== + // ========== Cart 模块 1011002000 ========== ErrorCode CARD_ITEM_NOT_FOUND = new ErrorCode(1011002000, "购物车项不存在"); // ========== Price 相关 1011003000 ============ @@ -58,7 +58,7 @@ public interface ErrorCodeConstants { ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDR_IS_EMPTY = new ErrorCode(1011003001, "计算快递运费异常,收件人地址编号为空"); ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND = new ErrorCode(1011003002, "计算快递运费异常,找不到对应的运费模板"); - // ========== 物流 Express 模块 1011004000 ========== + // ========== 物流 Express 模块 1011004000 ========== ErrorCode EXPRESS_NOT_EXISTS = new ErrorCode(1011004000, "快递公司不存在"); ErrorCode EXPRESS_CODE_DUPLICATE = new ErrorCode(1011004001, "已经存在该编码的快递公司"); ErrorCode EXPRESS_CLIENT_NOT_PROVIDE = new ErrorCode(1011004002, "需要接入快递服务商,比如【快递100】"); @@ -67,15 +67,15 @@ public interface ErrorCodeConstants { ErrorCode EXPRESS_API_QUERY_ERROR = new ErrorCode(1011004101, "快递查询接口异常"); ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011004102, "快递查询返回失败,原因:{}"); - // ========== 物流 Template 模块 1011005000 ========== + // ========== 物流 Template 模块 1011005000 ========== ErrorCode EXPRESS_TEMPLATE_NAME_DUPLICATE = new ErrorCode(1011005000, "已经存在该运费模板名"); ErrorCode EXPRESS_TEMPLATE_NOT_EXISTS = new ErrorCode(1011005001, "运费模板不存在"); - // ========== 物流 PICK_UP 模块 1011006000 ========== + // ========== 物流 PICK_UP 模块 1011006000 ========== ErrorCode PICK_UP_STORE_NOT_EXISTS = new ErrorCode(1011006000, "自提门店不存在"); - // ========== 分销 分销用户 模块 1011007000 ========== + // ========== 分销用户 模块 1011007000 ========== ErrorCode BROKERAGE_USER_NOT_EXISTS = new ErrorCode(1011007000, "分销用户不存在"); } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java index 6946167bc6..19bb53daad 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java @@ -15,6 +15,7 @@ import java.util.Arrays; @Getter public enum BrokerageBindModeEnum implements IntArrayValuable { + // TODO @疯狂:要不从 1 开始? /** * 只要用户没有推广人,随时都可以绑定分销关系 */ @@ -23,6 +24,7 @@ public enum BrokerageBindModeEnum implements IntArrayValuable { * 仅新用户注册时才能绑定推广关系 */ REGISTER(1, "新用户"), + // TODO @疯狂:要加个 2,每次扫码都覆盖 ; public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageBindModeEnum::getMode).toArray(); diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java index 6d984a284d..1d1ef0c817 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java @@ -15,6 +15,7 @@ import java.util.Arrays; @Getter public enum BrokerageEnabledConditionEnum implements IntArrayValuable { + // TODO @疯狂:这个也从 1 开始哇 /** * 所有用户都可以分销 */ diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java index ce449f0b84..50c83c05aa 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java @@ -15,6 +15,7 @@ import java.util.Arrays; @Getter public enum BrokerageRecordBizTypeEnum implements IntArrayValuable { + // TODO @疯狂:这个也从 1 开始哇 ORDER(0, "获得推广佣金", "获得推广佣金 {}", true), WITHDRAW(1, "提现申请", "提现申请扣除佣金 {}", false), ; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java index 1fb87f2949..f15d07706b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java @@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.time.LocalDateTime; @@ -21,7 +22,7 @@ public class TradeBrokerageRecordBaseVO { private Long userId; @Schema(description = "业务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23353") - @NotNull(message = "业务编号不能为空") + @NotEmpty(message = "业务编号不能为空") private String bizId; @Schema(description = "业务类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @@ -29,7 +30,7 @@ public class TradeBrokerageRecordBaseVO { private Integer bizType; @Schema(description = "标题", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "标题不能为空") + @NotEmpty(message = "标题不能为空") private String title; @Schema(description = "金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "28731") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java index 002eed371b..1fd38b028e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java @@ -15,6 +15,8 @@ public class TradeBrokerageUserUpdateBrokerageEnabledReqVO { @NotNull(message = "用户编号不能为空") private Long id; + // TODO @疯狂:是不是这个字段,可以改成 enabled + @Schema(description = "推广资格", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "推广资格不能为空") private Boolean brokerageEnabled; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java index ee20156f15..55b168582b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java @@ -54,6 +54,7 @@ public class TradeConfigBaseVO { @PositiveOrZero(message = "用户提现最低金额不能是负数") private Integer brokerageWithdrawMinPrice; + // TODO @疯狂:要不要做成字典?按道理都可以体现对哇?感觉是全局的配置哈; @Schema(description = "提现银行", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]") @NotEmpty(message = "提现银行不能为空") private List brokerageBankNames; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java index b84e513543..1e82904601 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java @@ -40,7 +40,7 @@ public interface TradeBrokerageRecordConvert { .setBizId(bizId) .setPrice(brokerage) .setTotalPrice(user.getBrokeragePrice()) - .setTitle(BrokerageRecordBizTypeEnum.ORDER.getTitle()) + .setTitle(BrokerageRecordBizTypeEnum.ORDER.getTitle()) // TODO @疯狂:可能 title 不是很固化,会存在类似:沐晴成功购买《XXX JVM 实战》 .setDescription(StrUtil.format(BrokerageRecordBizTypeEnum.ORDER.getDescription(), String.valueOf(brokerage / 100.0))) .setStatus(status) .setFrozenDays(brokerageFrozenDays) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java index 0bf7c0cf29..bb3f09c52a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java @@ -41,13 +41,19 @@ public class TradeBrokerageRecordDO extends BaseDO { /** * 业务类型 *

- * 枚举 {@link BrokerageRecordBizTypeEnum 对应的类} + * 枚举 {@link BrokerageRecordBizTypeEnum} */ private Integer bizType; + /** * 标题 */ private String title; + /** + * 说明 + */ + private String description; + /** * 金额 */ @@ -56,16 +62,14 @@ public class TradeBrokerageRecordDO extends BaseDO { * 当前总佣金 */ private Integer totalPrice; - /** - * 说明 - */ - private String description; + /** * 状态 *

- * 枚举 {@link BrokerageRecordStatusEnum 对应的类} + * 枚举 {@link BrokerageRecordStatusEnum} */ private Integer status; + /** * 冻结时间(天) */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java index 0bc552dca0..3f1cc73aa6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java @@ -8,6 +8,7 @@ import lombok.*; import java.time.LocalDateTime; +// TODO @疯狂:因为独立了表,是不是可以把字段的 brokerage 去掉了哈? /** * 分销用户 DO * @@ -28,14 +29,19 @@ public class TradeBrokerageUserDO extends BaseDO { */ @TableId private Long id; + + // TODO @疯狂:貌似改成 bindUserId,更明确? /** * 推广员编号 + * + * 关联 MemberUserDO 的 id 字段 */ private Long brokerageUserId; /** * 推广员绑定时间 */ private LocalDateTime brokerageBindTime; + /** * 推广资格 */ @@ -44,6 +50,7 @@ public class TradeBrokerageUserDO extends BaseDO { * 成为分销员时间 */ private LocalDateTime brokerageTime; + /** * 可用佣金 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java index 78efbc53a1..41ed8bad9b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java @@ -40,8 +40,10 @@ public interface TradeBrokerageRecordMapper extends BaseMapperX getBrokerageRecordPage(TradeBrokerageRecordPageReqVO pageReqVO); + // TODO @疯狂:是不是 bizType 得加下?方便未来拓展哈; /** * 增加佣金 * @@ -38,8 +39,10 @@ public interface TradeBrokerageRecordService { */ void addBrokerage(Long userId, List list); + // TODO @疯狂:是不是 bizType 得加下?方便未来拓展哈; /** * 取消佣金:将佣金记录,状态修改为已失效 + * * @param userId 会员编号 * @param bizId 业务编号 */ @@ -51,4 +54,5 @@ public interface TradeBrokerageRecordService { * @return 解冻佣金的数量 */ int unfreezeRecord(); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java index 5502bcbf75..8ced49abb2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java @@ -6,15 +6,15 @@ import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.convert.brokerage.record.TradeBrokerageRecordConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.TradeBrokerageRecordMapper; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; +import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import lombok.extern.slf4j.Slf4j; @@ -56,11 +56,13 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ return tradeBrokerageRecordMapper.selectPage(pageReqVO); } + // TODO @疯狂:buyerId 要不要统一改成 userId 哈; @Override @Transactional(rollbackFor = Exception.class) public void addBrokerage(Long buyerId, List list) { TradeConfigDO memberConfig = tradeConfigService.getTradeConfig(); // 0 未启用分销功能 + // TODO @疯狂:BooleanUtil.isFalse();逻辑里,尽量不做 !取反,这样要多思考一层; if (memberConfig == null || !BooleanUtil.isTrue(memberConfig.getBrokerageEnabled())) { log.warn("[addBrokerage][增加佣金失败:brokerageEnabled 未配置,buyerId({})", buyerId); return; @@ -72,11 +74,11 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ return; } - // 1.2 计算一级分佣 + // 1.2 计算一级分佣 // TODO 疯狂:类似 1.1 和 1.2 的空行,可以去掉;一般在代码里的空行,是为了逻辑分块;但是分块如果太多,就会导致代码里都是空行哈; addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqBO::getSkuFirstBrokeragePrice); - // 2.1 获得二级推广员 + // TODO @疯狂:这里可以加个 firstUser.getBrokerageUserId() 为空的判断 return TradeBrokerageUserDO secondUser = tradeBrokerageUserService.getBrokerageUser(firstUser.getBrokerageUserId()); if (secondUser == null || !BooleanUtil.isTrue(secondUser.getBrokerageEnabled())) { return; @@ -95,6 +97,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ return; } + // 1. 更新佣金记录为已失效 TradeBrokerageRecordDO updateObj = new TradeBrokerageRecordDO().setStatus(BrokerageRecordStatusEnum.CANCEL.getStatus()); int updateRows = tradeBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); if (updateRows == 0) { @@ -102,6 +105,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ return; } + // 2. 更新用户的佣金 if (BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus().equals(record.getStatus())) { tradeBrokerageUserService.updateUserFrozenBrokeragePrice(userId, -record.getPrice()); } else if (BrokerageRecordStatusEnum.SETTLEMENT.getStatus().equals(record.getStatus())) { @@ -109,6 +113,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ } } + // TODO @疯狂:是不是 calculateBrokeragePrice /** * 计算佣金 * @@ -122,12 +127,11 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ if (skuBrokeragePrice != null && skuBrokeragePrice > 0) { return ObjectUtil.defaultIfNull(skuBrokeragePrice, 0); } - // 2. 根据订单支付金额计算佣金 + // TODO @疯狂:要不要把 MoneyUtils 抽到 common 里,然后这里也使用这个类的方法; if (payPrice != null && payPrice > 0 && percent != null && percent > 0) { return NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue(); } - return 0; } @@ -142,37 +146,35 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ */ private void addBrokerage(TradeBrokerageUserDO user, List list, Integer brokerageFrozenDays, Integer brokeragePercent, Function skuBrokeragePriceFun) { - // 处理冻结时间 + // 1.1 处理冻结时间 + // TODO @疯狂:是不是 brokerageFrozenDays != null && brokerageFrozenDays > 0 ?然后计算;更简洁一点; brokerageFrozenDays = ObjectUtil.defaultIfNull(brokerageFrozenDays, 0); LocalDateTime unfreezeTime = null; if (brokerageFrozenDays > 0) { unfreezeTime = LocalDateTime.now().plusDays(brokerageFrozenDays); } - - // 计算分佣 + // 1.2 计算分佣 int totalBrokerage = 0; List records = new ArrayList<>(); - for (BrokerageAddReqBO dto : list) { - int brokeragePerItem = calculateBrokerage(dto.getPayPrice(), brokeragePercent, skuBrokeragePriceFun.apply(dto)); + for (BrokerageAddReqBO item : list) { + int brokeragePerItem = calculateBrokerage(item.getPayPrice(), brokeragePercent, skuBrokeragePriceFun.apply(item)); + // TODO @疯狂:其实可以 brokeragePerItem <= 0 ,continue;这样 { 层级更少;代码更简洁;} if (brokeragePerItem > 0) { - int brokerage = brokeragePerItem * dto.getCount(); - records.add(TradeBrokerageRecordConvert.INSTANCE.convert(user, dto.getBizId(), brokerageFrozenDays, brokerage, unfreezeTime)); + int brokerage = brokeragePerItem * item.getCount(); + records.add(TradeBrokerageRecordConvert.INSTANCE.convert(user, item.getBizId(), brokerageFrozenDays, brokerage, unfreezeTime)); totalBrokerage += brokerage; } } - - if (records.isEmpty()) { + if (CollUtil.isEmpty(records)) { return; } - - // 保存佣金记录 + // 1.3 保存佣金记录 tradeBrokerageRecordMapper.insertBatch(records); - if (brokerageFrozenDays > 0) { - // 更新用户冻结佣金 + // 2. 更新用户佣金 + if (brokerageFrozenDays > 0) { // 更新用户冻结佣金 tradeBrokerageUserService.updateUserFrozenBrokeragePrice(user.getId(), totalBrokerage); - } else { - // 更新用户可用佣金 + } else { // 更新用户可用佣金 tradeBrokerageUserService.updateUserBrokeragePrice(user.getId(), totalBrokerage); } } @@ -190,8 +192,8 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ int count = 0; for (TradeBrokerageRecordDO record : records) { try { - boolean successful = getSelf().unfreezeRecord(record); - if (successful) { + boolean success = getSelf().unfreezeRecord(record); + if (success) { count++; } } catch (Exception e) { @@ -215,7 +217,6 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ // 更新用户冻结佣金 tradeBrokerageUserService.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(record.getUserId(), -record.getPrice()); - log.info("[unfreezeRecord][record({}) 更新为已结算成功]", record.getId()); return true; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java index a968d14eac..d325118a9f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java @@ -4,22 +4,29 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +// TODO @疯狂:要不要 service 还是拍平;就是都放在 brokerage 包下,然后 bo 里面,稍微分分; /** * 佣金 增加 Request BO + * * @author owen */ @Data @NoArgsConstructor @AllArgsConstructor public class BrokerageAddReqBO { + + // TODO @疯狂:bo 的话,也可以考虑加下 @Validated 注解,校验下参数;防御性下哈,虽然不一定用的到 + /** * 业务ID */ private String bizId; + // TODO @疯狂:不需要 payPrice 和 count,计算成 price 就好啦; /** * 商品支付价格 */ private Integer payPrice; + // TODO @疯狂:可以去掉 sku 哈,更抽象一点; /** * SKU 一级佣金 */ @@ -32,4 +39,5 @@ public class BrokerageAddReqBO { * 购买数量 */ private Integer count; + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java index 773342e554..54913b98a6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerag import java.util.Collection; import java.util.List; +// TODO @疯狂:要不去掉 Trade 前缀哈;交易这块,我准备除了 tradeorder 保持下,类似 aftersale,都要取消前缀了;tradeorder 保持的原因,是避免 payorder 和它重复 /** * 分销用户 Service 接口 * @@ -70,6 +71,7 @@ public interface TradeBrokerageUserService { */ void updateUserBrokeragePrice(Long id, int brokeragePrice); + // TODO @疯狂:int 类型一般不用哈;尽量都用封装类型;不差这点内存哈; /** * 更新用户冻结佣金 * @@ -85,4 +87,5 @@ public interface TradeBrokerageUserService { * @param frozenBrokeragePrice 减少冻结佣金(负数) */ void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java index 9691a81542..c4300c1aec 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java @@ -30,12 +30,6 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService @Resource private TradeBrokerageUserMapper brokerageUserMapper; - private void validateBrokerageUserExists(Long id) { - if (brokerageUserMapper.selectById(id) == null) { - throw exception(BROKERAGE_USER_NOT_EXISTS); - } - } - @Override public TradeBrokerageUserDO getBrokerageUser(Long id) { return brokerageUserMapper.selectById(id); @@ -55,15 +49,23 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService public void updateBrokerageUserId(Long id, Long brokerageUserId) { // 校验存在 validateBrokerageUserExists(id); - + // TODO @疯狂:貌似没实现完 } @Override public void updateBrokerageEnabled(Long id, Boolean brokerageEnabled) { // 校验存在 validateBrokerageUserExists(id); + // TODO @疯狂:貌似没实现完 } + private void validateBrokerageUserExists(Long id) { + if (brokerageUserMapper.selectById(id) == null) { + throw exception(BROKERAGE_USER_NOT_EXISTS); + } + } + + // TODO @疯狂:getBindBrokerageUser 会不会好点,因为统一使用 Bind 替代了 Invite @Override public TradeBrokerageUserDO getInviteBrokerageUser(Long id) { return Optional.ofNullable(id) @@ -73,6 +75,7 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService .orElse(null); } + // TODO @疯狂:单个更新,不用事务哈; @Override @Transactional(rollbackFor = Exception.class) public void updateUserBrokeragePrice(Long id, int brokeragePrice) { @@ -83,6 +86,7 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService } } + // TODO @疯狂:单个更新,不用事务哈; @Override @Transactional(rollbackFor = Exception.class) public void updateUserFrozenBrokeragePrice(Long id, int frozenBrokeragePrice) { @@ -93,12 +97,14 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService } } + // TODO @疯狂:单个更新,不用事务哈; @Override @Transactional(rollbackFor = Exception.class) public void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice) { Assert.isTrue(frozenBrokeragePrice < 0); int updateRows = brokerageUserMapper.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(id, frozenBrokeragePrice); if (updateRows == 0) { + // TODO @疯狂:挪到 trade 这变的错误码哈; throw exception(MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigService.java index c00825f2e5..1edb4f30ba 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigService.java @@ -12,7 +12,6 @@ import javax.validation.Valid; */ public interface TradeConfigService { - /** * 更新交易中心配置 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java index a6d8dffb1f..9daf3cafb1 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java @@ -25,6 +25,7 @@ import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomIntege import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; import static org.junit.jupiter.api.Assertions.assertEquals; +// TODO @芋艿:单测后续看看 /** * {@link TradeBrokerageRecordServiceImpl} 的单元测试类 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java index 49e8aa351f..153bbb4267 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java @@ -17,6 +17,7 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEq import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; import static org.junit.jupiter.api.Assertions.assertEquals; +// TODO @芋艿:单测后续看看 /** * {@link TradeBrokerageUserServiceImpl} 的单元测试类 * diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java index dc6439e744..dc7a58770f 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java @@ -9,7 +9,7 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; */ public interface ErrorCodeConstants { - // ========== 用户相关 1004001000============ + // ========== 用户相关 1004001000============ ErrorCode USER_NOT_EXISTS = new ErrorCode(1004001000, "用户不存在"); ErrorCode USER_MOBILE_NOT_EXISTS = new ErrorCode(1004001001, "手机号未注册用户"); ErrorCode USER_MOBILE_USED = new ErrorCode(1004001002, "修改手机失败,该手机号({})已经被使用"); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java index cfa93c9835..242cb7110c 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java @@ -136,6 +136,7 @@ public class MemberUserDO extends TenantBaseDO { */ private Long groupId; + // TODO @疯狂:看看要不要删除掉哈 // ========== 分销相关 ========== /** diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java index 7e35cdf2a7..902057272c 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java @@ -61,4 +61,5 @@ public interface MemberUserMapper extends BaseMapperX { return selectCount(new LambdaQueryWrapperX() .apply("FIND_IN_SET({0}, tag_ids)", tagId)); } + } From 0e8755972c3c97edbd2897f841634fa374566fe4 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 8 Sep 2023 00:35:54 +0800 Subject: [PATCH 26/48] =?UTF-8?q?=E8=90=A5=E9=94=80=E6=B4=BB=E5=8A=A8+?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=EF=BC=9A=E5=AE=8C=E5=96=84=E5=A4=A7=E9=83=A8?= =?UTF-8?q?=E5=88=86=20TODO=20=E6=8F=90=E5=88=B0=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/bargain/BargainActivityApi.java | 18 +++ .../api/seckill/SeckillActivityApi.java | 20 ++++ .../dto/SeckillActivityUpdateStockReqDTO.java | 46 ++++++++ .../promotion/enums/ErrorCodeConstants.java | 1 + .../api/bargain/BargainActivityApiImpl.java | 39 +++++++ .../api/seckill/SeckillActivityApiImpl.java | 75 +++++++++++++ .../seckill/SeckillActivityService.java | 14 +++ .../seckill/SeckillActivityServiceImpl.java | 18 ++- .../yudao-module-trade-biz/pom.xml | 5 + .../admin/order/TradeOrderController.java | 4 + .../app/order/AppTradeOrderController.java | 4 +- .../vo/AppTradeOrderSettlementReqVO.java | 4 + .../dal/redis/no/TradeOrderNoRedisDAO.java | 35 ++++++ .../order/TradeOrderUpdateServiceImpl.java | 104 ++++++++++++------ .../module/pay/api/order/PayOrderApi.java | 7 ++ .../module/pay/enums/ErrorCodeConstants.java | 1 + .../module/pay/api/order/PayOrderApiImpl.java | 6 + .../pay/service/order/PayOrderService.java | 14 ++- .../service/order/PayOrderServiceImpl.java | 11 ++ 19 files changed, 381 insertions(+), 45 deletions(-) create mode 100644 yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApi.java create mode 100644 yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java create mode 100644 yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/dto/SeckillActivityUpdateStockReqDTO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApiImpl.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/redis/no/TradeOrderNoRedisDAO.java diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApi.java new file mode 100644 index 0000000000..5e62d6e9e0 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApi.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.promotion.api.bargain; + +/** + * 砍价活动 Api 接口 + * + * @author HUIHUI + */ +public interface BargainActivityApi { + + /** + * 更新砍价活动库存 + * + * @param activityId 砍价活动编号 + * @param count 购买数量 + */ + void updateBargainActivityStock(Long activityId, Integer count); + +} diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java new file mode 100644 index 0000000000..09ec051a33 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.promotion.api.seckill; + +import cn.iocoder.yudao.module.promotion.api.seckill.dto.SeckillActivityUpdateStockReqDTO; + +/** + * 秒杀活动 API 接口 + * + * @author HUIHUI + */ +public interface SeckillActivityApi { + + + /** + * 更新秒杀库存 + * + * @param updateStockReqDTO 请求 + */ + void updateSeckillStock(SeckillActivityUpdateStockReqDTO updateStockReqDTO); + +} diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/dto/SeckillActivityUpdateStockReqDTO.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/dto/SeckillActivityUpdateStockReqDTO.java new file mode 100644 index 0000000000..476ba8e159 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/dto/SeckillActivityUpdateStockReqDTO.java @@ -0,0 +1,46 @@ +package cn.iocoder.yudao.module.promotion.api.seckill.dto; + +import lombok.Data; + +import java.util.List; + +/** + * 更新秒杀库存 request DTO + * + * @author HUIHUI + */ +@Data +public class SeckillActivityUpdateStockReqDTO { + + /** + * 活动编号 + */ + private Long activityId; + /** + * 总购买数量 + */ + private Integer count; + /** + * 活动商品 + */ + private List items; + + @Data + public static class Item { + + /** + * SPU 编号 + */ + private Long spuId; + /** + * SKU 编号 + */ + private Long skuId; + /** + * 购买数量 + */ + private Integer count; + + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index dd4389d5df..8c873b5ad5 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -55,6 +55,7 @@ public interface ErrorCodeConstants { ErrorCode SECKILL_ACTIVITY_UPDATE_FAIL_STATUS_CLOSED = new ErrorCode(1013008003, "秒杀活动已关闭,不能修改"); ErrorCode SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013008004, "秒杀活动未关闭或未结束,不能删除"); ErrorCode SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED = new ErrorCode(1013008005, "秒杀活动已关闭,不能重复关闭"); + ErrorCode SECKILL_ACTIVITY_UPDATE_STOCK_FAIL = new ErrorCode(1013008006, "更新秒杀活动库存失败,原因秒杀库存不足"); // ========== 秒杀时段 1013009000 ========== ErrorCode SECKILL_CONFIG_NOT_EXISTS = new ErrorCode(1013009000, "秒杀时段不存在"); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApiImpl.java new file mode 100644 index 0000000000..826b4b2aa4 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApiImpl.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.promotion.api.bargain; + +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityUpdateReqVO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; +import cn.iocoder.yudao.module.promotion.service.bargain.BargainActivityService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.BARGAIN_ACTIVITY_NOT_EXISTS; + +/** + * 砍价活动 Api 接口实现类 + * + * @author HUIHUI + */ +@Service +public class BargainActivityApiImpl implements BargainActivityApi { + + @Resource + private BargainActivityService bargainActivityService; + + @Override + public void updateBargainActivityStock(Long activityId, Integer count) { + // 查询砍价活动 + BargainActivityDO activity = bargainActivityService.getBargainActivity(activityId); + if (activity == null) { + throw exception(BARGAIN_ACTIVITY_NOT_EXISTS); + } + + // 更新砍价库存 + BargainActivityUpdateReqVO reqVO = new BargainActivityUpdateReqVO(); + reqVO.setId(activityId); + reqVO.setStock(activity.getStock() - count); + bargainActivityService.updateBargainActivity(reqVO); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java new file mode 100644 index 0000000000..299316aa06 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java @@ -0,0 +1,75 @@ +package cn.iocoder.yudao.module.promotion.api.seckill; + +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.module.promotion.api.seckill.dto.SeckillActivityUpdateStockReqDTO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; +import cn.iocoder.yudao.module.promotion.service.seckill.SeckillActivityService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL_ACTIVITY_UPDATE_STOCK_FAIL; + +/** + * 秒杀活动接口 Api 接口实现类 + * + * @author HUIHUI + */ +@Service +public class SeckillActivityApiImpl implements SeckillActivityApi { + + @Resource + private SeckillActivityService activityService; + + @Override + public void updateSeckillStock(SeckillActivityUpdateStockReqDTO updateStockReqDTO) { + SeckillActivityDO seckillActivity = activityService.getSeckillActivity(updateStockReqDTO.getActivityId()); + if (seckillActivity.getStock() < updateStockReqDTO.getCount()) { + throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); + } + // 获取活动商品 + List productDOs = activityService.getSeckillProductListByActivityId(updateStockReqDTO.getActivityId()); + List items = updateStockReqDTO.getItems(); + Map> map = new HashMap<>(); + items.forEach(item -> { + if (map.containsKey(item.getSpuId())) { + List skuIds = map.get(item.getSpuId()); + skuIds.add(item.getSkuId()); + map.put(item.getSpuId(), skuIds); + } else { + List list = new ArrayList<>(); + list.add(item.getSkuId()); + map.put(item.getSpuId(), list); + } + }); + // 过滤出购买的商品 + List productDOList = CollectionUtils.filterList(productDOs, item -> map.get(item.getSpuId()).contains(item.getSkuId())); + Map productDOMap = CollectionUtils.convertMap(items, SeckillActivityUpdateStockReqDTO.Item::getSkuId, p -> p); + // 检查活动商品库存是否充足 + boolean b = CollectionUtils.anyMatch(productDOList, item -> { + SeckillActivityUpdateStockReqDTO.Item item1 = productDOMap.get(item.getSkuId()); + return (item.getStock() < item1.getCount()) || (item.getStock() - item1.getCount()) < 0; + }); + if (b) { + throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); + } + List doList = CollectionUtils.convertList(productDOList, item -> { + item.setStock(item.getStock() - productDOMap.get(item.getSkuId()).getCount()); + return item; + }); + + // 更新活动库存 + seckillActivity.setStock(seckillActivity.getStock() + updateStockReqDTO.getCount()); + seckillActivity.setTotalStock(seckillActivity.getTotalStock() - updateStockReqDTO.getCount()); + activityService.updateSeckillActivity(seckillActivity); + // 更新活动商品库存 + activityService.updateSeckillActivityProductByList(doList); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java index 2e33a944d9..052b595619 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java @@ -33,6 +33,20 @@ public interface SeckillActivityService { */ void updateSeckillActivity(@Valid SeckillActivityUpdateReqVO updateReqVO); + /** + * 更新秒杀活动 + * + * @param activityDO 秒杀活动 + */ + void updateSeckillActivity(SeckillActivityDO activityDO); + + /** + * 更新秒杀活动商品 + * + * @param productDOList 活动商品列表 + */ + void updateSeckillActivityProductByList(List productDOList); + /** * 关闭秒杀活动 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java index 531c35fcba..17fb9a90fe 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java @@ -79,8 +79,8 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { * 1. 校验秒杀时段是否存在 * 2. 秒杀商品是否参加其它活动 * - * @param configIds 秒杀时段数组 - * @param spuId 商品 SPU 编号 + * @param configIds 秒杀时段数组 + * @param spuId 商品 SPU 编号 * @param activityId 秒杀活动编号 */ private void validateProductConflict(List configIds, Long spuId, Long activityId) { @@ -102,7 +102,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { /** * 校验秒杀商品是否都存在 * - * @param spuId 商品 SPU 编号 + * @param spuId 商品 SPU 编号 * @param products 秒杀商品 */ private void validateProductExists(Long spuId, List products) { @@ -144,11 +144,21 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { updateSeckillProduct(updateObj, updateReqVO.getProducts()); } + @Override + public void updateSeckillActivity(SeckillActivityDO activityDO) { + seckillActivityMapper.updateById(activityDO); + } + + @Override + public void updateSeckillActivityProductByList(List productDOList) { + seckillProductMapper.updateBatch(productDOList); + } + /** * 更新秒杀商品 * * @param activity 秒杀活动 - * @param products 该活动的最新商品配置 + * @param products 该活动的最新商品配置 */ private void updateSeckillProduct(SeckillActivityDO activity, List products) { // 第一步,对比新老数据,获得添加、修改、删除的列表 diff --git a/yudao-module-mall/yudao-module-trade-biz/pom.xml b/yudao-module-mall/yudao-module-trade-biz/pom.xml index 810446fa94..fd105e31aa 100644 --- a/yudao-module-mall/yudao-module-trade-biz/pom.xml +++ b/yudao-module-mall/yudao-module-trade-biz/pom.xml @@ -82,6 +82,11 @@ yudao-spring-boot-starter-mybatis + + cn.iocoder.boot + yudao-spring-boot-starter-redis + + cn.iocoder.boot diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/TradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/TradeOrderController.java index 926c2408c1..728c70c675 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/TradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/TradeOrderController.java @@ -25,6 +25,7 @@ import java.util.Map; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND; @Tag(name = "管理后台 - 交易订单") @RestController @@ -67,6 +68,9 @@ public class TradeOrderController { public CommonResult getOrderDetail(@RequestParam("id") Long id) { // 查询订单 TradeOrderDO order = tradeOrderQueryService.getOrder(id); + if (order == null) { + return success(null, ORDER_NOT_FOUND.getMsg()); + } // 查询订单项 List orderItems = tradeOrderQueryService.getOrderItemListByOrderId(id); // orderLog diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index 5abb6a98cc..a65836c33c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.module.pay.api.notify.dto.PayOrderNotifyReqDTO; -import cn.iocoder.yudao.module.product.api.property.ProductPropertyValueApi; import cn.iocoder.yudao.module.trade.controller.app.order.vo.*; import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemRespVO; @@ -34,6 +33,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND; @Tag(name = "用户 App - 交易订单") @RestController @@ -83,7 +83,7 @@ public class AppTradeOrderController { // 查询订单 TradeOrderDO order = tradeOrderQueryService.getOrder(getLoginUserId(), id); if (order == null) { - return success(null); + return success(null, ORDER_NOT_FOUND.getMsg()); } // 查询订单项 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java index 3e322c7867..6b8c147253 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java @@ -56,6 +56,10 @@ public class AppTradeOrderSettlementReqVO { @Schema(description = "拼团团长编号", example = "2048") private Long combinationHeadId; + // ========== 砍价活动相关字段 ========== + @Schema(description = "砍价活动编号", example = "123") + private Long bargainActivityId; + @Data @Schema(description = "用户 App - 商品项") @Valid diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/redis/no/TradeOrderNoRedisDAO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/redis/no/TradeOrderNoRedisDAO.java new file mode 100644 index 0000000000..781975aca9 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/redis/no/TradeOrderNoRedisDAO.java @@ -0,0 +1,35 @@ +package cn.iocoder.yudao.module.trade.dal.redis.no; + +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateUtil; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Repository; + +import javax.annotation.Resource; +import java.time.LocalDateTime; + +/** + * 订单序号的 Redis DAO + * + * @author HUIHUI + */ +@Repository +public class TradeOrderNoRedisDAO { + public static final String TRADE_ORDER_NO_PREFIX = "O"; + + @Resource + private StringRedisTemplate stringRedisTemplate; + + /** + * 生成序号 + * + * @param prefix 前缀 + * @return 序号 + */ + public String generate(String prefix) { + String noPrefix = prefix + DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_PATTERN); + Long no = stringRedisTemplate.opsForValue().increment(noPrefix); + return noPrefix + no; + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index c4cfaee832..8b8ceef206 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.trade.service.order; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; -import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; @@ -25,11 +24,14 @@ import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum; import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi; import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; +import cn.iocoder.yudao.module.promotion.api.bargain.BargainActivityApi; import cn.iocoder.yudao.module.promotion.api.bargain.BargainRecordApi; import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordRespDTO; import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO; +import cn.iocoder.yudao.module.promotion.api.seckill.SeckillActivityApi; +import cn.iocoder.yudao.module.promotion.api.seckill.dto.SeckillActivityUpdateStockReqDTO; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderRemarkReqVO; @@ -45,6 +47,7 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper; +import cn.iocoder.yudao.module.trade.dal.redis.no.TradeOrderNoRedisDAO; import cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants; import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.*; @@ -70,7 +73,7 @@ import java.util.Set; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; -import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.ORDER_NOT_FOUND; +import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.ORDER_UPDATE_PRICE_FAIL_EQUAL; import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.ORDER_UPDATE_PRICE_FAIL_PAID; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; @@ -88,6 +91,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { private TradeOrderMapper tradeOrderMapper; @Resource private TradeOrderItemMapper tradeOrderItemMapper; + @Resource + private TradeOrderNoRedisDAO orderNoRedisDAO; @Resource private CartService cartService; @@ -111,6 +116,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Resource private BargainRecordApi bargainRecordApi; @Resource + private SeckillActivityApi seckillActivityApi; + @Resource + private BargainActivityApi bargainActivityApi; + @Resource private MemberUserApi memberUserApi; @Resource private MemberLevelApi memberLevelApi; @@ -189,22 +198,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // TODO @puhui999:这个逻辑,先抽个小方法;未来要通过设计模式,把这些拼团之类的逻辑,抽象出去 // 拼团 if (Objects.equals(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { - MemberUserRespDTO user = memberUserApi.getUser(userId); - List recordRespDTOS = combinationRecordApi.getRecordListByUserIdAndActivityId(userId, createReqVO.getCombinationActivityId()); - // TODO 拼团一次应该只能选择一种规格的商品 - TradeOrderItemDO orderItemDO = orderItems.get(0); - if (CollUtil.isNotEmpty(recordRespDTOS)) { - List skuIds = convertList(recordRespDTOS, CombinationRecordRespDTO::getSkuId, item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())); - List tradeOrderItemDOS = tradeOrderItemMapper.selectListByOrderIdAnSkuId(convertList(recordRespDTOS, - CombinationRecordRespDTO::getOrderId, item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())), skuIds); - combinationRecordApi.validateCombinationLimitCount(createReqVO.getCombinationActivityId(), - CollectionUtils.getSumValue(tradeOrderItemDOS, TradeOrderItemDO::getCount, Integer::sum), orderItemDO.getCount()); - } - - combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, orderItemDO, createReqVO, user)); + createCombinationRecord(userId, createReqVO, orderItems, order); } // 3.2 秒杀的特殊逻辑 - // TODO 秒杀扣减库存是下单就扣除还是等待订单支付成功再扣除 if (Objects.equals(TradeOrderTypeEnum.SECKILL.getType(), order.getType())) { } @@ -214,6 +210,22 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { return order; } + private void createCombinationRecord(Long userId, AppTradeOrderCreateReqVO createReqVO, List orderItems, TradeOrderDO order) { + MemberUserRespDTO user = memberUserApi.getUser(userId); + List recordRespDTOS = combinationRecordApi.getRecordListByUserIdAndActivityId(userId, createReqVO.getCombinationActivityId()); + // TODO 拼团一次应该只能选择一种规格的商品 + TradeOrderItemDO orderItemDO = orderItems.get(0); + if (CollUtil.isNotEmpty(recordRespDTOS)) { + List skuIds = convertList(recordRespDTOS, CombinationRecordRespDTO::getSkuId, item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())); + List tradeOrderItemDOS = tradeOrderItemMapper.selectListByOrderIdAnSkuId(convertList(recordRespDTOS, + CombinationRecordRespDTO::getOrderId, item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())), skuIds); + combinationRecordApi.validateCombinationLimitCount(createReqVO.getCombinationActivityId(), + CollectionUtils.getSumValue(tradeOrderItemDOS, TradeOrderItemDO::getCount, Integer::sum), orderItemDO.getCount()); + } + + combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, orderItemDO, createReqVO, user)); + } + // TODO @puhui999:订单超时,自动取消; /** @@ -240,8 +252,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { address = validateAddress(userId, createReqVO.getAddressId()); } TradeOrderDO order = TradeOrderConvert.INSTANCE.convert(userId, clientIp, createReqVO, calculateRespBO, address); + String no = orderNoRedisDAO.generate(TradeOrderNoRedisDAO.TRADE_ORDER_NO_PREFIX); order.setType(validateActivity(createReqVO)); - order.setNo(IdUtil.getSnowflakeNextId() + ""); // TODO @puhui999: 参考支付订单,的 no 生成哈; + order.setNo(no); order.setStatus(TradeOrderStatusEnum.UNPAID.getStatus()); order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()); order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum)); @@ -293,19 +306,23 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { private void afterCreateTradeOrder(Long userId, AppTradeOrderCreateReqVO createReqVO, TradeOrderDO tradeOrderDO, List orderItems, TradePriceCalculateRespBO calculateRespBO) { - // 下单时扣减商品库存 - // TODO @puhui999:扣库存,需要前置; + Integer count = getSumValue(orderItems, TradeOrderItemDO::getCount, Integer::sum); // 1)如果是秒杀商品:额外扣减秒杀的库存; - // 2)如果是拼团活动:额外扣减拼团的库存; - // 3)如果是砍价活动:额外扣减砍价的库存; - productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convertNegative(orderItems)); - - // 删除购物车商品 - Set cartIds = convertSet(createReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCartId); - if (CollUtil.isNotEmpty(cartIds)) { - cartService.deleteCart(userId, cartIds); + if (Objects.equals(TradeOrderTypeEnum.SECKILL.getType(), tradeOrderDO.getType())) { + SeckillActivityUpdateStockReqDTO updateStockReqDTO = new SeckillActivityUpdateStockReqDTO(); + updateStockReqDTO.setActivityId(createReqVO.getSeckillActivityId()); + updateStockReqDTO.setCount(count); + updateStockReqDTO.setItems(CollectionUtils.convertList(orderItems, item -> { + SeckillActivityUpdateStockReqDTO.Item item1 = new SeckillActivityUpdateStockReqDTO.Item(); + item1.setSpuId(item.getSpuId()); + item1.setSkuId(item.getSkuId()); + item1.setCount(item.getCount()); + return item1; + })); + seckillActivityApi.updateSeckillStock(updateStockReqDTO); } - + // 2)如果是砍价活动:额外扣减砍价的库存; + bargainActivityApi.updateBargainActivityStock(createReqVO.getBargainActivityId(), count); // 扣减积分 TODO 芋艿:待实现,需要前置; // 这个是不是应该放到支付成功之后?如果支付后的话,可能积分可以重复使用哈。资源类,都要预扣 @@ -315,6 +332,15 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { .setOrderId(tradeOrderDO.getId())); } + // 下单时扣减商品库存 + productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convertNegative(orderItems)); + + // 删除购物车商品 + Set cartIds = convertSet(createReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCartId); + if (CollUtil.isNotEmpty(cartIds)) { + cartService.deleteCart(userId, cartIds); + } + // 生成预支付 createPayOrder(tradeOrderDO, orderItems, calculateRespBO); @@ -464,11 +490,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { */ private TradeOrderDO validateOrderDeliverable(Long id) { TradeOrderDO order = validateOrderExists(id); - // 校验订单是否是待发货状态 - // TODO @puhui999:已经发货,可以重新发货,修改信息; - if (!TradeOrderStatusEnum.isUndelivered(order.getStatus())) { - throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED); - } // 校验订单是否退款 if (ObjectUtil.notEqual(TradeOrderRefundStatusEnum.NONE.getStatus(), order.getRefundStatus())) { throw exception(ORDER_DELIVERY_FAIL_REFUND_STATUS_NOT_NONE); @@ -540,14 +561,25 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { if (order.getPayStatus()) { throw exception(ORDER_UPDATE_PRICE_FAIL_PAID); } - // TODO @puhui999:如果改价,需要校验下是否真的变化; + if (ObjectUtil.equal(order.getAdjustPrice(), reqVO.getAdjustPrice())) { + throw exception(ORDER_UPDATE_PRICE_FAIL_EQUAL); + } - // 更新 - // TODO @puhui999:TradeOrderItemDO 需要做 adjustPrice 的分摊;另外,支付订单那的价格,需要 update 下; + List itemDOs = tradeOrderItemMapper.selectListByOrderId(order.getId()); + // TradeOrderItemDO 需要做 adjustPrice 的分摊 + int price = reqVO.getAdjustPrice() / itemDOs.size(); + itemDOs.forEach(item -> { + item.setAdjustPrice(price); + }); + // 更新 TradeOrderItem + tradeOrderItemMapper.updateBatch(itemDOs); + // 更新订单 TradeOrderDO update = TradeOrderConvert.INSTANCE.convert(reqVO); update.setPayPrice(update.getPayPrice() + update.getAdjustPrice()); // TODO @芋艿:改价时,赠送的积分,要不要做改动??? tradeOrderMapper.updateById(update); + // 更新支付订单 + payOrderApi.updatePayOrderPriceById(order.getPayOrderId(), update.getPayPrice()); } @Override diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApi.java b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApi.java index 5c1905ebe9..94a79ea3d7 100644 --- a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApi.java +++ b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApi.java @@ -29,4 +29,11 @@ public interface PayOrderApi { */ PayOrderRespDTO getOrder(Long id); + /** + * 更新支付订单价格 + * + * @param payOrderId 支付单编号 + * @param payPrice 支付单价格 + */ + void updatePayOrderPriceById(Long payOrderId, Integer payPrice); } diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java index ee8947286e..2ee11f1be4 100644 --- a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java +++ b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java @@ -28,6 +28,7 @@ public interface ErrorCodeConstants { ErrorCode ORDER_SUBMIT_CHANNEL_ERROR = new ErrorCode(1007002004, "发起支付报错,错误码:{},错误提示:{}"); ErrorCode ORDER_REFUND_FAIL_STATUS_ERROR = new ErrorCode(1007002005, "支付订单退款失败,原因:状态不是已支付或已退款"); ErrorCode ORDER_UPDATE_PRICE_FAIL_PAID = new ErrorCode(1007002006, "支付订单调价失败,原因:支付订单已付款,不能调价"); + ErrorCode ORDER_UPDATE_PRICE_FAIL_EQUAL = new ErrorCode(1007002007, "支付订单调价失败,原因:价格没有变化"); // ========== ORDER 模块(拓展单) 1007003000 ========== ErrorCode ORDER_EXTENSION_NOT_FOUND = new ErrorCode(1007003000, "支付交易拓展单不存在"); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApiImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApiImpl.java index a245880bac..18c9ff3ef0 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApiImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApiImpl.java @@ -31,4 +31,10 @@ public class PayOrderApiImpl implements PayOrderApi { return PayOrderConvert.INSTANCE.convert2(order); } + @Override + public void updatePayOrderPriceById(Long payOrderId, Integer payPrice) { + payOrderService.updatePayOrderPriceById(payOrderId, payPrice); + } + + } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderService.java index 3d66ae9b1e..e03bda117b 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderService.java @@ -33,7 +33,7 @@ public interface PayOrderService { /** * 获得支付订单 * - * @param appId 应用编号 + * @param appId 应用编号 * @param merchantOrderId 商户订单编号 * @return 支付订单 */ @@ -75,7 +75,7 @@ public interface PayOrderService { * 提交支付 * 此时,会发起支付渠道的调用 * - * @param reqVO 提交请求 + * @param reqVO 提交请求 * @param userIp 提交 IP * @return 提交结果 */ @@ -93,11 +93,19 @@ public interface PayOrderService { /** * 更新支付订单的退款金额 * - * @param id 编号 + * @param id 编号 * @param incrRefundPrice 增加的退款金额 */ void updateOrderRefundPrice(Long id, Integer incrRefundPrice); + /** + * 更新支付订单价格 + * + * @param payOrderId 支付单编号 + * @param payPrice 支付单价格 + */ + void updatePayOrderPriceById(Long payOrderId, Integer payPrice); + /** * 获得支付订单 * diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java index d560351878..bb43295c26 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java @@ -410,6 +410,17 @@ public class PayOrderServiceImpl implements PayOrderService { } } + @Override + public void updatePayOrderPriceById(Long payOrderId, Integer payPrice) { + PayOrderDO order = orderMapper.selectById(payOrderId); + if (order == null) { + throw exception(ORDER_NOT_FOUND); + } + + order.setPrice(payPrice); + orderMapper.updateById(order); + } + @Override public PayOrderExtensionDO getOrderExtension(Long id) { return orderExtensionMapper.selectById(id); From 166b1b31c0b20c3016fa2bebce376fdef96ea142 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 10:59:06 +0800 Subject: [PATCH 27/48] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/brokerage.sql | 11 +++--- .../user/TradeBrokerageUserController.java | 35 ++++++++++++++++++- .../user/vo/TradeBrokerageUserRespVO.java | 26 ++++++++++++++ .../user/TradeBrokerageUserConvert.java | 34 ++++++++++++++++++ .../record/TradeBrokerageRecordMapper.java | 7 ++++ .../record/TradeBrokerageRecordService.java | 14 ++++++-- .../TradeBrokerageRecordServiceImpl.java | 7 ++++ .../record/bo/UserBrokerageSummaryBO.java | 24 +++++++++++++ .../user/TradeBrokerageUserService.java | 7 ++++ .../user/TradeBrokerageUserServiceImpl.java | 5 +++ .../dal/dataobject/user/MemberUserDO.java | 34 ------------------ 11 files changed, 163 insertions(+), 41 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/UserBrokerageSummaryBO.java diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index 127fcb7286..48adc14e8c 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -24,7 +24,7 @@ create table trade_config create table trade_brokerage_user ( id bigint auto_increment comment '用户编号' primary key, - brokerage_user_id bigint not null comment '推广员编号', + brokerage_user_id bigint null comment '推广员编号', brokerage_bind_time datetime null comment '推广员绑定时间', brokerage_enabled bit default 1 not null comment '是否成为推广员', brokerage_time datetime null comment '成为分销员时间', @@ -185,12 +185,15 @@ SELECT @parentId := LAST_INSERT_ID(); INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) VALUES ('分销用户查询', 'trade:brokerage-user:query', 3, 1, @parentId, '', '', '', 0); INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) -VALUES ('分销用户修改推广员', 'trade:brokerage-user:update-brokerage-user', 3, 2, @parentId, '', '', '', 0); +VALUES ('分销用户推广人查询', 'trade:brokerage-user:user-query', 3, 2, @parentId, '', '', '', 0); INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) -VALUES ('分销用户清除推广员', 'trade:brokerage-user:clear-brokerage-user', 3, 3, @parentId, '', '', '', 0); +VALUES ('分销用户推广订单查询', 'trade:brokerage-user:order-query', 3, 3, @parentId, '', '', '', 0); INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) VALUES ('分销用户修改推广资格', 'trade:brokerage-user:update-brokerage-enable', 3, 4, @parentId, '', '', '', 0); - +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('分销用户修改推广员', 'trade:brokerage-user:update-brokerage-user', 3, 5, @parentId, '', '', '', 0); +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('分销用户清除推广员', 'trade:brokerage-user:clear-brokerage-user', 3, 6, @parentId, '', '', '', 0); -- 增加菜单:佣金记录 INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java index e4cc63fb91..5da3acb5b0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java @@ -2,9 +2,15 @@ package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.*; import cn.iocoder.yudao.module.trade.convert.brokerage.user.TradeBrokerageUserConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; +import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -15,8 +21,12 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.Map; +import java.util.Set; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; @Tag(name = "管理后台 - 分销用户") @RestController @@ -26,6 +36,11 @@ public class TradeBrokerageUserController { @Resource private TradeBrokerageUserService brokerageUserService; + @Resource + private TradeBrokerageRecordService brokerageRecordService; + + @Resource + private MemberUserApi memberUserApi; @PutMapping("/update-brokerage-user") @Operation(summary = "修改推广员") @@ -64,8 +79,26 @@ public class TradeBrokerageUserController { @Operation(summary = "获得分销用户分页") @PreAuthorize("@ss.hasPermission('trade:brokerage-user:query')") public CommonResult> getBrokerageUserPage(@Valid TradeBrokerageUserPageReqVO pageVO) { + // 分页查询 PageResult pageResult = brokerageUserService.getBrokerageUserPage(pageVO); - return success(TradeBrokerageUserConvert.INSTANCE.convertPage(pageResult)); + + // 涉及到的用户 + Set userIds = convertSet(pageResult.getList(), TradeBrokerageUserDO::getId); + // 查询用户信息 + Map userMap = memberUserApi.getUserMap(userIds); + // 合计分佣订单 + Map userOrderSummaryMap = convertMap(userIds, + userId -> userId, + userId -> brokerageRecordService.summaryByUserIdAndBizTypeAndStatus(userId, + BrokerageRecordBizTypeEnum.ORDER.getType(), BrokerageRecordStatusEnum.SETTLEMENT.getStatus())); + // 合计推广用户数量 + Map brokerageUserCountMap = convertMap(userIds, + userId -> userId, + userId -> brokerageUserService.getCountByBrokerageUserId(userId)); + + // todo 合计提现 + + return success(TradeBrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java index 090eb04b53..ee82efa0d8 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java @@ -19,4 +19,30 @@ public class TradeBrokerageUserRespVO extends TradeBrokerageUserBaseVO { @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; + + // ========== 用户信息 ========== + + @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png") + private String avatar; + @Schema(description = "用户昵称", example = "李四") + private String nickname; + + + // ========== 推广信息 ========== + + @Schema(description = "推广用户数量(一级)", example = "20019") + private Integer brokerageUserCount; + @Schema(description = "推广订单数量", example = "20019") + private Integer brokerageOrderCount; + @Schema(description = "推广订单金额", example = "20019") + private Integer brokerageOrderPrice; + + + // ========== 提现信息 ========== + + @Schema(description = "已提现金额", example = "20019") + private Integer withdrawPrice; + @Schema(description = "已提现次数", example = "20019") + private Integer withdrawCount; + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java index 1a62bded0b..b5800efed2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java @@ -1,12 +1,17 @@ package cn.iocoder.yudao.module.trade.convert.brokerage.user; +import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; import java.util.List; +import java.util.Map; +import java.util.Optional; /** * 分销用户 Convert @@ -24,4 +29,33 @@ public interface TradeBrokerageUserConvert { PageResult convertPage(PageResult page); + default PageResult convertPage(PageResult pageResult, + Map userMap, + Map brokerageUserCountMap, + Map userOrderSummaryMap) { + PageResult result = convertPage(pageResult); + for (TradeBrokerageUserRespVO vo : result.getList()) { + // 用户信息 + Optional.ofNullable(userMap.get(vo.getId())) + .ifPresent(user -> { + vo.setNickname(user.getNickname()); + vo.setAvatar(user.getAvatar()); + }); + + // 推广用户数量(一级) + vo.setBrokerageUserCount(MapUtil.getInt(brokerageUserCountMap, vo.getId(), 0)); + + Optional orderSummaryOptional = Optional.ofNullable(userOrderSummaryMap.get(vo.getId())); + // 推广订单数量 + vo.setBrokerageOrderCount(orderSummaryOptional.map(UserBrokerageSummaryBO::getCount).orElse(0)); + // 推广订单金额 + vo.setBrokerageOrderPrice(orderSummaryOptional.map(UserBrokerageSummaryBO::getPrice).orElse(0)); + + // todo 已提现次数 + vo.setWithdrawCount(0); + // todo 已提现金额 + vo.setWithdrawPrice(0); + } + return result; + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java index 41ed8bad9b..2adb488eb8 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java @@ -5,8 +5,11 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; +import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; import java.time.LocalDateTime; import java.util.List; @@ -46,4 +49,8 @@ public interface TradeBrokerageRecordMapper extends BaseMapperX Date: Fri, 8 Sep 2023 12:29:38 +0800 Subject: [PATCH 28/48] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80Review?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/brokerage.sql | 17 ++-- .../trade/enums/ErrorCodeConstants.java | 1 + .../brokerage/BrokerageBindModeEnum.java | 10 ++- .../BrokerageEnabledConditionEnum.java | 5 +- .../brokerage/BrokerageRecordBizTypeEnum.java | 5 +- .../user/TradeBrokerageUserController.java | 2 +- .../admin/config/vo/TradeConfigBaseVO.java | 1 - .../record/TradeBrokerageRecordConvert.java | 12 ++- .../user/TradeBrokerageUserConvert.java | 2 +- .../convert/order/TradeOrderConvert.java | 8 +- .../record/TradeBrokerageRecordMapper.java | 5 +- .../user/TradeBrokerageUserMapper.java | 10 +-- .../brokerage/bo/BrokerageAddReqBO.java | 36 +++++++++ .../bo/UserBrokerageSummaryBO.java | 2 +- .../record/TradeBrokerageRecordService.java | 21 ++--- .../TradeBrokerageRecordServiceImpl.java | 81 +++++++++---------- .../record/bo/BrokerageAddReqBO.java | 43 ---------- .../user/TradeBrokerageUserService.java | 9 +-- .../user/TradeBrokerageUserServiceImpl.java | 21 ++--- .../order/TradeOrderUpdateServiceImpl.java | 17 ++-- .../TradeBrokerageRecordServiceImplTest.java | 16 ++-- .../member/enums/ErrorCodeConstants.java | 1 - 22 files changed, 155 insertions(+), 170 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/{record => }/bo/UserBrokerageSummaryBO.java (84%) delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index 48adc14e8c..53b9dc04e8 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -3,8 +3,8 @@ create table trade_config ( id bigint auto_increment comment '自增主键' primary key, brokerage_enabled bit default 1 not null comment '是否启用分佣', - brokerage_enabled_condition tinyint default 0 not null comment '分佣模式:0-人人分销 1-指定分销', - brokerage_bind_mode tinyint default 0 not null comment '分销关系绑定模式: 0-没有推广人,1-新用户', + brokerage_enabled_condition tinyint default 0 not null comment '分佣模式:1-人人分销 2-指定分销', + brokerage_bind_mode tinyint default 0 not null comment '分销关系绑定模式: 1-没有推广人,2-新用户, 3-扫码覆盖', brokerage_post_urls varchar(2000) default '' null comment '分销海报图地址数组', brokerage_first_percent int default 0 not null comment '一级返佣比例', brokerage_second_percent int default 0 not null comment '二级返佣比例', @@ -104,14 +104,15 @@ create index idx_audit_status on trade_brokerage_withdraw (status) comment '状 insert into system_dict_type(type, name) values ('brokerage_enabled_condition', '分佣模式'); insert into system_dict_data(dict_type, label, value, sort, remark) -values ('brokerage_enabled_condition', '人人分销', 0, 0, '所有用户都可以分销'), - ('brokerage_enabled_condition', '指定分销', 1, 1, '仅可后台手动设置推广员'); +values ('brokerage_enabled_condition', '人人分销', 1, 1, '所有用户都可以分销'), + ('brokerage_enabled_condition', '指定分销', 2, 2, '仅可后台手动设置推广员'); insert into system_dict_type(type, name) values ('brokerage_bind_mode', '分销关系绑定模式'); insert into system_dict_data(dict_type, label, value, sort, remark) -values ('brokerage_bind_mode', '没有推广人', 0, 0, '只要用户没有推广人,随时都可以绑定推广关系'), - ('brokerage_bind_mode', '新用户', 1, 1, '仅新用户注册时才能绑定推广关系'); +values ('brokerage_bind_mode', '没有推广人', 1, 1, '只要用户没有推广人,随时都可以绑定推广关系'), + ('brokerage_bind_mode', '新用户', 2, 2, '仅新用户注册时才能绑定推广关系'), + ('brokerage_bind_mode', '扫码覆盖', 3, 3, '如果用户已经有推广人,推广人会被变更'); insert into system_dict_type(type, name) values ('brokerage_withdraw_type', '佣金提现类型'); @@ -124,8 +125,8 @@ values ('brokerage_withdraw_type', '钱包', 1, 1), insert into system_dict_type(type, name) values ('brokerage_record_biz_type', '佣金记录业务类型'); insert into system_dict_data(dict_type, label, value, sort) -values ('brokerage_record_biz_type', '订单返佣', 0, 0), - ('brokerage_record_biz_type', '申请提现', 1, 1); +values ('brokerage_record_biz_type', '订单返佣', 1, 1), + ('brokerage_record_biz_type', '申请提现', 2, 2); insert into system_dict_type(type, name) values ('brokerage_record_status', '佣金记录状态'); diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index f6c0ca7827..5ddff9b119 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -77,5 +77,6 @@ public interface ErrorCodeConstants { // ========== 分销用户 模块 1011007000 ========== ErrorCode BROKERAGE_USER_NOT_EXISTS = new ErrorCode(1011007000, "分销用户不存在"); + ErrorCode USER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH = new ErrorCode(1011007001, "用户冻结佣金({})数量不足"); } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java index 19bb53daad..3b6610ac9f 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java @@ -15,16 +15,18 @@ import java.util.Arrays; @Getter public enum BrokerageBindModeEnum implements IntArrayValuable { - // TODO @疯狂:要不从 1 开始? /** * 只要用户没有推广人,随时都可以绑定分销关系 */ - ANYTIME(0, "没有推广人"), + ANYTIME(1, "没有推广人"), /** * 仅新用户注册时才能绑定推广关系 */ - REGISTER(1, "新用户"), - // TODO @疯狂:要加个 2,每次扫码都覆盖 + REGISTER(2, "新用户"), + /** + * 每次扫码都覆盖 + */ + OVERRIDE(3, "扫码覆盖"), ; public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageBindModeEnum::getMode).toArray(); diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java index 1d1ef0c817..990d10e160 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java @@ -15,15 +15,14 @@ import java.util.Arrays; @Getter public enum BrokerageEnabledConditionEnum implements IntArrayValuable { - // TODO @疯狂:这个也从 1 开始哇 /** * 所有用户都可以分销 */ - ALL(0, "人人分销"), + ALL(1, "人人分销"), /** * 仅可后台手动设置推广员 */ - ADMIN(1, "指定分销"), + ADMIN(2, "指定分销"), ; public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageEnabledConditionEnum::getCondition).toArray(); diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java index 50c83c05aa..ae798a6ac0 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java @@ -15,9 +15,8 @@ import java.util.Arrays; @Getter public enum BrokerageRecordBizTypeEnum implements IntArrayValuable { - // TODO @疯狂:这个也从 1 开始哇 - ORDER(0, "获得推广佣金", "获得推广佣金 {}", true), - WITHDRAW(1, "提现申请", "提现申请扣除佣金 {}", false), + ORDER(1, "获得推广佣金", "获得推广佣金 {}", true), + WITHDRAW(2, "提现申请", "提现申请扣除佣金 {}", false), ; public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageRecordBizTypeEnum::getType).toArray(); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java index 5da3acb5b0..38a27d8c82 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java @@ -10,7 +10,7 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerag import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java index 55b168582b..ee20156f15 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java @@ -54,7 +54,6 @@ public class TradeConfigBaseVO { @PositiveOrZero(message = "用户提现最低金额不能是负数") private Integer brokerageWithdrawMinPrice; - // TODO @疯狂:要不要做成字典?按道理都可以体现对哇?感觉是全局的配置哈; @Schema(description = "提现银行", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]") @NotEmpty(message = "提现银行不能为空") private List brokerageBankNames; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java index 1e82904601..2d67f5f2e6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.trade.convert.brokerage.record; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordRespVO; @@ -29,19 +30,22 @@ public interface TradeBrokerageRecordConvert { PageResult convertPage(PageResult page); - default TradeBrokerageRecordDO convert(TradeBrokerageUserDO user, String bizId, int brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime) { + default TradeBrokerageRecordDO convert(TradeBrokerageUserDO user, BrokerageRecordBizTypeEnum bizType, String bizId, + Integer brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime, + String title) { + brokerageFrozenDays = ObjectUtil.defaultIfNull(brokerageFrozenDays, 0); // 不冻结时,佣金直接就是结算状态 Integer status = brokerageFrozenDays > 0 ? BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus() : BrokerageRecordStatusEnum.SETTLEMENT.getStatus(); return new TradeBrokerageRecordDO() .setUserId(user.getId()) - .setBizType(BrokerageRecordBizTypeEnum.ORDER.getType()) + .setBizType(bizType.getType()) .setBizId(bizId) .setPrice(brokerage) .setTotalPrice(user.getBrokeragePrice()) - .setTitle(BrokerageRecordBizTypeEnum.ORDER.getTitle()) // TODO @疯狂:可能 title 不是很固化,会存在类似:沐晴成功购买《XXX JVM 实战》 - .setDescription(StrUtil.format(BrokerageRecordBizTypeEnum.ORDER.getDescription(), String.valueOf(brokerage / 100.0))) + .setTitle(title) + .setDescription(StrUtil.format(bizType.getDescription(), String.valueOf(brokerage / 100.0))) .setStatus(status) .setFrozenDays(brokerageFrozenDays) .setUnfreezeTime(unfreezeTime); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java index b5800efed2..beda1571c6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java @@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index f42af2d73d..27854def6e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.common.util.string.StrUtils; import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; import cn.iocoder.yudao.module.pay.enums.DictTypeConstants; @@ -277,8 +277,8 @@ public interface TradeOrderConvert { default BrokerageAddReqBO convert(TradeOrderItemDO item, ProductSkuRespDTO sku) { return new BrokerageAddReqBO().setBizId(String.valueOf(item.getId())) - .setPayPrice(item.getPayPrice()).setCount(item.getCount()) - .setSkuFirstBrokeragePrice(sku.getSubCommissionFirstPrice()) - .setSkuSecondBrokeragePrice(sku.getSubCommissionSecondPrice()); + .setBasePrice(item.getPayPrice() * item.getCount()) + .setFirstBrokeragePrice(sku.getSubCommissionFirstPrice()) + .setSecondBrokeragePrice(sku.getSubCommissionSecondPrice()); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java index 2adb488eb8..9a8c6df76d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java @@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -43,8 +43,7 @@ public interface TradeBrokerageRecordMapper extends BaseMapperX 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" brokerage_price = brokerage_price + " + incrCount) @@ -46,7 +46,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" brokerage_price = brokerage_price + " + incrCount) // 负数,所以使用 + 号 @@ -60,7 +60,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) @@ -75,7 +75,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) // 负数,所以使用 + 号 @@ -90,7 +90,7 @@ public interface TradeBrokerageUserMapper extends BaseMapperX lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount + // 负数,所以使用 + 号 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java new file mode 100644 index 0000000000..7e17d9bda2 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.module.trade.service.brokerage.bo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 佣金 增加 Request BO + * + * @author owen + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class BrokerageAddReqBO { + + // TODO @疯狂:bo 的话,也可以考虑加下 @Validated 注解,校验下参数;防御性下哈,虽然不一定用的到 + + /** + * 业务ID + */ + private String bizId; + /** + * 佣金基数 + */ + private Integer basePrice; + /** + * 一级佣金(固定) + */ + private Integer firstBrokeragePrice; + /** + * 二级佣金(固定) + */ + private Integer secondBrokeragePrice; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/UserBrokerageSummaryBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryBO.java similarity index 84% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/UserBrokerageSummaryBO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryBO.java index 15f3e73fe8..ffbb3ed9a0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/UserBrokerageSummaryBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryBO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.service.brokerage.record.bo; +package cn.iocoder.yudao.module.trade.service.brokerage.bo; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java index 477e2c76e6..d02745e3b2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java @@ -3,8 +3,9 @@ package cn.iocoder.yudao.module.trade.service.brokerage.record; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import java.util.List; @@ -31,23 +32,23 @@ public interface TradeBrokerageRecordService { */ PageResult getBrokerageRecordPage(TradeBrokerageRecordPageReqVO pageReqVO); - // TODO @疯狂:是不是 bizType 得加下?方便未来拓展哈; /** * 增加佣金 * - * @param userId 会员编号 - * @param list 请求参数列表 + * @param userId 会员编号 + * @param bizType 业务类型 + * @param list 请求参数列表 */ - void addBrokerage(Long userId, List list); + void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, List list); - // TODO @疯狂:是不是 bizType 得加下?方便未来拓展哈; /** * 取消佣金:将佣金记录,状态修改为已失效 * - * @param userId 会员编号 - * @param bizId 业务编号 + * @param userId 会员编号 + * @param bizType 业务类型 + * @param bizId 业务编号 */ - void cancelBrokerage(Long userId, String bizId); + void cancelBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId); /** * 解冻佣金:将待结算的佣金记录,状态修改为已结算 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java index 72e85124ab..01946a060e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java @@ -14,8 +14,8 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.TradeBrokerageRecordMapper; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.UserBrokerageSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import lombok.extern.slf4j.Slf4j; @@ -57,42 +57,40 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ return tradeBrokerageRecordMapper.selectPage(pageReqVO); } - // TODO @疯狂:buyerId 要不要统一改成 userId 哈; @Override @Transactional(rollbackFor = Exception.class) - public void addBrokerage(Long buyerId, List list) { + public void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, List list) { TradeConfigDO memberConfig = tradeConfigService.getTradeConfig(); // 0 未启用分销功能 - // TODO @疯狂:BooleanUtil.isFalse();逻辑里,尽量不做 !取反,这样要多思考一层; if (memberConfig == null || !BooleanUtil.isTrue(memberConfig.getBrokerageEnabled())) { - log.warn("[addBrokerage][增加佣金失败:brokerageEnabled 未配置,buyerId({})", buyerId); + log.warn("[addBrokerage][增加佣金失败:brokerageEnabled 未配置,userId({})", userId); return; } // 1.1 获得一级推广人 - TradeBrokerageUserDO firstUser = tradeBrokerageUserService.getInviteBrokerageUser(buyerId); + TradeBrokerageUserDO firstUser = tradeBrokerageUserService.getBindBrokerageUser(userId); if (firstUser == null || !BooleanUtil.isTrue(firstUser.getBrokerageEnabled())) { return; } - - // 1.2 计算一级分佣 // TODO 疯狂:类似 1.1 和 1.2 的空行,可以去掉;一般在代码里的空行,是为了逻辑分块;但是分块如果太多,就会导致代码里都是空行哈; - addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqBO::getSkuFirstBrokeragePrice); + // 1.2 计算一级分佣 + addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqBO::getFirstBrokeragePrice, bizType); // 2.1 获得二级推广员 - // TODO @疯狂:这里可以加个 firstUser.getBrokerageUserId() 为空的判断 return + if (firstUser.getBrokerageUserId() == null) { + return; + } TradeBrokerageUserDO secondUser = tradeBrokerageUserService.getBrokerageUser(firstUser.getBrokerageUserId()); if (secondUser == null || !BooleanUtil.isTrue(secondUser.getBrokerageEnabled())) { return; } - // 2.2 计算二级分佣 - addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqBO::getSkuSecondBrokeragePrice); + addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqBO::getSecondBrokeragePrice, bizType); } @Override @Transactional(rollbackFor = Exception.class) - public void cancelBrokerage(Long userId, String bizId) { - TradeBrokerageRecordDO record = tradeBrokerageRecordMapper.selectByUserIdAndBizTypeAndBizId(BrokerageRecordBizTypeEnum.ORDER.getType(), bizId); + public void cancelBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId) { + TradeBrokerageRecordDO record = tradeBrokerageRecordMapper.selectByBizTypeAndBizId(bizType.getType(), bizId); if (record == null || ObjectUtil.notEqual(record.getUserId(), userId)) { log.error("[cancelBrokerage][userId({})][bizId({}) 更新为已失效失败:记录不存在]", userId, bizId); return; @@ -114,24 +112,23 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ } } - // TODO @疯狂:是不是 calculateBrokeragePrice /** * 计算佣金 * - * @param payPrice 订单支付金额 - * @param percent 商品 SKU 设置的佣金 - * @param skuBrokeragePrice 商品的佣金 + * @param basePrice 佣金基数 + * @param percent 佣金比例 + * @param fixedBrokeragePrice 固定佣金 * @return 佣金 */ - int calculateBrokerage(Integer payPrice, Integer percent, Integer skuBrokeragePrice) { - // 1. 优先使用商品 SKU 设置的佣金 - if (skuBrokeragePrice != null && skuBrokeragePrice > 0) { - return ObjectUtil.defaultIfNull(skuBrokeragePrice, 0); + int calculateBrokeragePrice(Integer basePrice, Integer percent, Integer fixedBrokeragePrice) { + // 1. 优先使用固定佣金 + if (fixedBrokeragePrice != null && fixedBrokeragePrice > 0) { + return ObjectUtil.defaultIfNull(fixedBrokeragePrice, 0); } - // 2. 根据订单支付金额计算佣金 + // 2. 根据比例计算佣金 // TODO @疯狂:要不要把 MoneyUtils 抽到 common 里,然后这里也使用这个类的方法; - if (payPrice != null && payPrice > 0 && percent != null && percent > 0) { - return NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue(); + if (basePrice != null && basePrice > 0 && percent != null && percent > 0) { + return NumberUtil.div(NumberUtil.mul(basePrice, percent), 100, 0, RoundingMode.DOWN).intValue(); } return 0; } @@ -139,32 +136,32 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ /** * 增加用户佣金 * - * @param user 用户 - * @param list 佣金增加参数列表 - * @param brokerageFrozenDays 冻结天数 - * @param brokeragePercent 佣金比例 - * @param skuBrokeragePriceFun 商品 SKU 设置的佣金 + * @param user 用户 + * @param list 佣金增加参数列表 + * @param brokerageFrozenDays 冻结天数 + * @param brokeragePercent 佣金比例 + * @param FixedBrokeragePriceFun 固定佣金 + * @param bizType 业务类型 */ private void addBrokerage(TradeBrokerageUserDO user, List list, Integer brokerageFrozenDays, - Integer brokeragePercent, Function skuBrokeragePriceFun) { + Integer brokeragePercent, Function FixedBrokeragePriceFun, + BrokerageRecordBizTypeEnum bizType) { // 1.1 处理冻结时间 - // TODO @疯狂:是不是 brokerageFrozenDays != null && brokerageFrozenDays > 0 ?然后计算;更简洁一点; - brokerageFrozenDays = ObjectUtil.defaultIfNull(brokerageFrozenDays, 0); LocalDateTime unfreezeTime = null; - if (brokerageFrozenDays > 0) { + if (brokerageFrozenDays != null && brokerageFrozenDays > 0) { unfreezeTime = LocalDateTime.now().plusDays(brokerageFrozenDays); } // 1.2 计算分佣 int totalBrokerage = 0; List records = new ArrayList<>(); for (BrokerageAddReqBO item : list) { - int brokeragePerItem = calculateBrokerage(item.getPayPrice(), brokeragePercent, skuBrokeragePriceFun.apply(item)); - // TODO @疯狂:其实可以 brokeragePerItem <= 0 ,continue;这样 { 层级更少;代码更简洁;} - if (brokeragePerItem > 0) { - int brokerage = brokeragePerItem * item.getCount(); - records.add(TradeBrokerageRecordConvert.INSTANCE.convert(user, item.getBizId(), brokerageFrozenDays, brokerage, unfreezeTime)); - totalBrokerage += brokerage; + int brokeragePerItem = calculateBrokeragePrice(item.getBasePrice(), brokeragePercent, FixedBrokeragePriceFun.apply(item)); + if (brokeragePerItem <= 0) { + continue; } + records.add(TradeBrokerageRecordConvert.INSTANCE.convert(user, bizType, item.getBizId(), + brokerageFrozenDays, brokeragePerItem, unfreezeTime, bizType.getTitle())); + totalBrokerage += brokeragePerItem; } if (CollUtil.isEmpty(records)) { return; @@ -173,7 +170,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ tradeBrokerageRecordMapper.insertBatch(records); // 2. 更新用户佣金 - if (brokerageFrozenDays > 0) { // 更新用户冻结佣金 + if (brokerageFrozenDays != null && brokerageFrozenDays > 0) { // 更新用户冻结佣金 tradeBrokerageUserService.updateUserFrozenBrokeragePrice(user.getId(), totalBrokerage); } else { // 更新用户可用佣金 tradeBrokerageUserService.updateUserBrokeragePrice(user.getId(), totalBrokerage); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java deleted file mode 100644 index d325118a9f..0000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java +++ /dev/null @@ -1,43 +0,0 @@ -package cn.iocoder.yudao.module.trade.service.brokerage.record.bo; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -// TODO @疯狂:要不要 service 还是拍平;就是都放在 brokerage 包下,然后 bo 里面,稍微分分; -/** - * 佣金 增加 Request BO - * - * @author owen - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class BrokerageAddReqBO { - - // TODO @疯狂:bo 的话,也可以考虑加下 @Validated 注解,校验下参数;防御性下哈,虽然不一定用的到 - - /** - * 业务ID - */ - private String bizId; - // TODO @疯狂:不需要 payPrice 和 count,计算成 price 就好啦; - /** - * 商品支付价格 - */ - private Integer payPrice; - // TODO @疯狂:可以去掉 sku 哈,更抽象一点; - /** - * SKU 一级佣金 - */ - private Integer skuFirstBrokeragePrice; - /** - * SKU 二级佣金 - */ - private Integer skuSecondBrokeragePrice; - /** - * 购买数量 - */ - private Integer count; - -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java index f817890e13..c62fc1947e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java @@ -61,7 +61,7 @@ public interface TradeBrokerageUserService { * @param id 用户编号 * @return 用户的推广人 */ - TradeBrokerageUserDO getInviteBrokerageUser(Long id); + TradeBrokerageUserDO getBindBrokerageUser(Long id); /** * 更新用户佣金 @@ -69,16 +69,15 @@ public interface TradeBrokerageUserService { * @param id 用户编号 * @param brokeragePrice 用户可用佣金 */ - void updateUserBrokeragePrice(Long id, int brokeragePrice); + void updateUserBrokeragePrice(Long id, Integer brokeragePrice); - // TODO @疯狂:int 类型一般不用哈;尽量都用封装类型;不差这点内存哈; /** * 更新用户冻结佣金 * * @param id 用户编号 * @param frozenBrokeragePrice 用户冻结佣金 */ - void updateUserFrozenBrokeragePrice(Long id, int frozenBrokeragePrice); + void updateUserFrozenBrokeragePrice(Long id, Integer frozenBrokeragePrice); /** * 更新用户冻结佣金(减少), 更新用户佣金(增加) @@ -86,7 +85,7 @@ public interface TradeBrokerageUserService { * @param id 用户编号 * @param frozenBrokeragePrice 减少冻结佣金(负数) */ - void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice); + void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, Integer frozenBrokeragePrice); /** * 获得推广用户数量(一级) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java index c6ec31b932..6851e522c3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java @@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBro import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.TradeBrokerageUserMapper; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; @@ -15,8 +14,8 @@ import java.util.List; import java.util.Optional; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_USER_NOT_EXISTS; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.USER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH; /** * 分销用户 Service 实现类 @@ -65,9 +64,8 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService } } - // TODO @疯狂:getBindBrokerageUser 会不会好点,因为统一使用 Bind 替代了 Invite @Override - public TradeBrokerageUserDO getInviteBrokerageUser(Long id) { + public TradeBrokerageUserDO getBindBrokerageUser(Long id) { return Optional.ofNullable(id) .map(this::getBrokerageUser) .map(TradeBrokerageUserDO::getBrokerageUserId) @@ -75,10 +73,8 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService .orElse(null); } - // TODO @疯狂:单个更新,不用事务哈; @Override - @Transactional(rollbackFor = Exception.class) - public void updateUserBrokeragePrice(Long id, int brokeragePrice) { + public void updateUserBrokeragePrice(Long id, Integer brokeragePrice) { if (brokeragePrice > 0) { brokerageUserMapper.updateBrokeragePriceIncr(id, brokeragePrice); } else if (brokeragePrice < 0) { @@ -86,10 +82,8 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService } } - // TODO @疯狂:单个更新,不用事务哈; @Override - @Transactional(rollbackFor = Exception.class) - public void updateUserFrozenBrokeragePrice(Long id, int frozenBrokeragePrice) { + public void updateUserFrozenBrokeragePrice(Long id, Integer frozenBrokeragePrice) { if (frozenBrokeragePrice > 0) { brokerageUserMapper.updateFrozenBrokeragePriceIncr(id, frozenBrokeragePrice); } else if (frozenBrokeragePrice < 0) { @@ -97,15 +91,12 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService } } - // TODO @疯狂:单个更新,不用事务哈; @Override - @Transactional(rollbackFor = Exception.class) - public void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice) { + public void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, Integer frozenBrokeragePrice) { Assert.isTrue(frozenBrokeragePrice < 0); int updateRows = brokerageUserMapper.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(id, frozenBrokeragePrice); if (updateRows == 0) { - // TODO @疯狂:挪到 trade 这变的错误码哈; - throw exception(MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH); + throw exception(USER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index b75b7ac7cf..199cfcbfdd 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -12,8 +12,6 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; import cn.iocoder.yudao.module.member.api.point.MemberPointApi; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; @@ -49,9 +47,12 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper; import cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.*; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; +import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.trade.service.cart.CartService; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; import cn.iocoder.yudao.module.trade.service.message.TradeMessageService; @@ -370,7 +371,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 增加用户经验 getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); // 增加用户佣金 - getSelf().addBrokerageAsync(order.getUserId(), order.getId()); + getSelf().addBrokerageAsync(order.getUserId(), BrokerageRecordBizTypeEnum.ORDER, order.getId()); } /** @@ -640,7 +641,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 扣减用户经验 getSelf().reduceUserExperienceAsync(order.getUserId(), orderRefundPrice, afterSaleId); // 更新分佣记录为已失效 - getSelf().cancelBrokerageAsync(order.getUserId(), id); + getSelf().cancelBrokerageAsync(order.getUserId(), BrokerageRecordBizTypeEnum.ORDER, id); } @Override @@ -750,16 +751,16 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Async - protected void addBrokerageAsync(Long userId, Long orderId) { + protected void addBrokerageAsync(Long userId, BrokerageRecordBizTypeEnum bizType, Long orderId) { List orderItems = tradeOrderItemMapper.selectListByOrderId(orderId); List list = convertList(orderItems, item -> TradeOrderConvert.INSTANCE.convert(item, productSkuApi.getSku(item.getSkuId()))); - tradeBrokerageRecordService.addBrokerage(userId, list); + tradeBrokerageRecordService.addBrokerage(userId, bizType, list); } @Async - protected void cancelBrokerageAsync(Long userId, Long orderItemId) { - tradeBrokerageRecordService.cancelBrokerage(userId, String.valueOf(orderItemId)); + protected void cancelBrokerageAsync(Long userId, BrokerageRecordBizTypeEnum bizType, Long orderItemId) { + tradeBrokerageRecordService.cancelBrokerage(userId, bizType, String.valueOf(orderItemId)); } /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java index 9daf3cafb1..eb51279d5a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java @@ -79,38 +79,38 @@ public class TradeBrokerageRecordServiceImplTest extends BaseDbUnitTest { } @Test - public void testCalculateBrokerage_useSkuBrokeragePrice() { + public void testCalculateBrokeragePrice_useFixedBrokeragePrice() { // mock 数据 Integer payPrice = randomInteger(); Integer percent = randomInt(1, 101); - Integer skuBrokeragePrice = randomInt(); + Integer fixedBrokeragePrice = randomInt(); // 调用 - int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); + int brokerage = tradeBrokerageRecordService.calculateBrokeragePrice(payPrice, percent, fixedBrokeragePrice); // 断言 - assertEquals(brokerage, skuBrokeragePrice); + assertEquals(brokerage, fixedBrokeragePrice); } @Test - public void testCalculateBrokerage_usePercent() { + public void testCalculateBrokeragePrice_usePercent() { // mock 数据 Integer payPrice = randomInteger(); Integer percent = randomInt(1, 101); Integer skuBrokeragePrice = randomEle(new Integer[]{0, null}); System.out.println("skuBrokeragePrice=" + skuBrokeragePrice); // 调用 - int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); + int brokerage = tradeBrokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); // 断言 assertEquals(brokerage, NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue()); } @Test - public void testCalculateBrokerage_equalsZero() { + public void testCalculateBrokeragePrice_equalsZero() { // mock 数据 Integer payPrice = null; Integer percent = null; Integer skuBrokeragePrice = null; // 调用 - int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); + int brokerage = tradeBrokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); // 断言 assertEquals(brokerage, 0); } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java index dc7a58770f..cf375f4e4d 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java @@ -13,7 +13,6 @@ public interface ErrorCodeConstants { ErrorCode USER_NOT_EXISTS = new ErrorCode(1004001000, "用户不存在"); ErrorCode USER_MOBILE_NOT_EXISTS = new ErrorCode(1004001001, "手机号未注册用户"); ErrorCode USER_MOBILE_USED = new ErrorCode(1004001002, "修改手机失败,该手机号({})已经被使用"); - ErrorCode MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH = new ErrorCode(1004001003, "用户冻结佣金({})数量不足"); // ========== AUTH 模块 1004003000 ========== ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1004003000, "登录失败,账号密码不正确"); From ddcebb1986c7c11457fb7f93fd142e4af3495e13 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 12:46:43 +0800 Subject: [PATCH 29/48] =?UTF-8?q?common:=20MoneyUtils=20=E7=A7=BB=E5=88=B0?= =?UTF-8?q?=20common=20=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/util/number}/MoneyUtils.java | 13 ++++++++++++- .../record/TradeBrokerageRecordServiceImpl.java | 6 ++---- .../pay/service/order/PayOrderServiceImpl.java | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) rename {yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/util => yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number}/MoneyUtils.java (71%) diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/util/MoneyUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java similarity index 71% rename from yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/util/MoneyUtils.java rename to yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java index 5e5d859e68..e2fd3fa6e4 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/util/MoneyUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.pay.util; +package cn.iocoder.yudao.framework.common.util.number; import cn.hutool.core.util.NumberUtil; @@ -23,6 +23,17 @@ public class MoneyUtils { return calculateRatePrice(price, rate, 0, RoundingMode.HALF_UP).intValue(); } + /** + * 计算百分比金额,向下传入 + * + * @param price 金额 + * @param rate 百分比,例如说 56.77% 则传入 56.77 + * @return 百分比金额 + */ + public static Integer calculateRatePriceFloor(Integer price, Double rate) { + return calculateRatePrice(price, rate, 0, RoundingMode.FLOOR).intValue(); + } + /** * 计算百分比金额 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java index 01946a060e..ad1a5c8ff2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java @@ -2,10 +2,10 @@ package cn.iocoder.yudao.module.trade.service.brokerage.record; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.BooleanUtil; -import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.convert.brokerage.record.TradeBrokerageRecordConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; @@ -24,7 +24,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.math.RoundingMode; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -126,9 +125,8 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ return ObjectUtil.defaultIfNull(fixedBrokeragePrice, 0); } // 2. 根据比例计算佣金 - // TODO @疯狂:要不要把 MoneyUtils 抽到 common 里,然后这里也使用这个类的方法; if (basePrice != null && basePrice > 0 && percent != null && percent > 0) { - return NumberUtil.div(NumberUtil.mul(basePrice, percent), 100, 0, RoundingMode.DOWN).intValue(); + return MoneyUtils.calculateRatePriceFloor(basePrice, Double.valueOf(percent)); } return 0; } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java index 944df1a101..0445df8a66 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java @@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; import cn.iocoder.yudao.framework.pay.core.client.PayClient; import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; @@ -31,7 +32,6 @@ import cn.iocoder.yudao.module.pay.framework.pay.config.PayProperties; import cn.iocoder.yudao.module.pay.service.app.PayAppService; import cn.iocoder.yudao.module.pay.service.channel.PayChannelService; import cn.iocoder.yudao.module.pay.service.notify.PayNotifyService; -import cn.iocoder.yudao.module.pay.util.MoneyUtils; import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; From 0a0c3c0ede6eec2266507684759784d8ad803a31 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 12:56:34 +0800 Subject: [PATCH 30/48] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E7=9B=B8=E5=85=B3=E7=B1=BB=E5=9E=8B=E7=A7=BB=E9=99=A4?= =?UTF-8?q?Trade=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...er.java => BrokerageRecordController.java} | 26 +++---- ...BaseVO.java => BrokerageRecordBaseVO.java} | 2 +- ...qVO.java => BrokerageRecordPageReqVO.java} | 2 +- ...RespVO.java => BrokerageRecordRespVO.java} | 2 +- ...ller.java => BrokerageUserController.java} | 34 +++++----- ...erBaseVO.java => BrokerageUserBaseVO.java} | 2 +- ...BrokerageUserClearBrokerageUserReqVO.java} | 2 +- ...ReqVO.java => BrokerageUserPageReqVO.java} | 2 +- ...erRespVO.java => BrokerageUserRespVO.java} | 2 +- ...erageUserUpdateBrokerageEnabledReqVO.java} | 2 +- ...rokerageUserUpdateBrokerageUserReqVO.java} | 2 +- ...nvert.java => BrokerageRecordConvert.java} | 24 +++---- ...Convert.java => BrokerageUserConvert.java} | 26 +++---- ...geRecordDO.java => BrokerageRecordDO.java} | 2 +- ...kerageUserDO.java => BrokerageUserDO.java} | 2 +- .../record/BrokerageRecordMapper.java | 55 +++++++++++++++ .../record/TradeBrokerageRecordMapper.java | 55 --------------- ...erMapper.java => BrokerageUserMapper.java} | 40 +++++------ ...b.java => BrokerageRecordUnfreezeJob.java} | 8 +-- ...rvice.java => BrokerageRecordService.java} | 10 +-- ...l.java => BrokerageRecordServiceImpl.java} | 68 +++++++++---------- ...Service.java => BrokerageUserService.java} | 15 ++-- ...mpl.java => BrokerageUserServiceImpl.java} | 22 +++--- .../order/TradeOrderUpdateServiceImpl.java | 8 +-- ...va => BrokerageRecordServiceImplTest.java} | 42 ++++++------ ...java => BrokerageUserServiceImplTest.java} | 22 +++--- 26 files changed, 238 insertions(+), 239 deletions(-) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/{TradeBrokerageRecordController.java => BrokerageRecordController.java} (59%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/{TradeBrokerageRecordBaseVO.java => BrokerageRecordBaseVO.java} (98%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/{TradeBrokerageRecordPageReqVO.java => BrokerageRecordPageReqVO.java} (94%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/{TradeBrokerageRecordRespVO.java => BrokerageRecordRespVO.java} (89%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/{TradeBrokerageUserController.java => BrokerageUserController.java} (73%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/{TradeBrokerageUserBaseVO.java => BrokerageUserBaseVO.java} (97%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/{TradeBrokerageUserClearBrokerageUserReqVO.java => BrokerageUserClearBrokerageUserReqVO.java} (90%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/{TradeBrokerageUserPageReqVO.java => BrokerageUserPageReqVO.java} (93%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/{TradeBrokerageUserRespVO.java => BrokerageUserRespVO.java} (95%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/{TradeBrokerageUserUpdateBrokerageEnabledReqVO.java => BrokerageUserUpdateBrokerageEnabledReqVO.java} (92%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/{TradeBrokerageUserUpdateBrokerageUserReqVO.java => BrokerageUserUpdateBrokerageUserReqVO.java} (92%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/{TradeBrokerageRecordConvert.java => BrokerageRecordConvert.java} (65%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/{TradeBrokerageUserConvert.java => BrokerageUserConvert.java} (62%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/{TradeBrokerageRecordDO.java => BrokerageRecordDO.java} (97%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/{TradeBrokerageUserDO.java => BrokerageUserDO.java} (96%) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/BrokerageRecordMapper.java delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/{TradeBrokerageUserMapper.java => BrokerageUserMapper.java} (65%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/{TradeBrokerageRecordUnfreezeJob.java => BrokerageRecordUnfreezeJob.java} (63%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/{TradeBrokerageRecordService.java => BrokerageRecordService.java} (86%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/{TradeBrokerageRecordServiceImpl.java => BrokerageRecordServiceImpl.java} (72%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/{TradeBrokerageUserService.java => BrokerageUserService.java} (78%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/{TradeBrokerageUserServiceImpl.java => BrokerageUserServiceImpl.java} (80%) rename yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/{TradeBrokerageRecordServiceImplTest.java => BrokerageRecordServiceImplTest.java} (67%) rename yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/{TradeBrokerageUserServiceImplTest.java => BrokerageUserServiceImplTest.java} (74%) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/TradeBrokerageRecordController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/BrokerageRecordController.java similarity index 59% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/TradeBrokerageRecordController.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/BrokerageRecordController.java index 38b2f4d71e..81034124ba 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/TradeBrokerageRecordController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/BrokerageRecordController.java @@ -2,11 +2,11 @@ package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordRespVO; -import cn.iocoder.yudao.module.trade.convert.brokerage.record.TradeBrokerageRecordConvert; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordRespVO; +import cn.iocoder.yudao.module.trade.convert.brokerage.record.BrokerageRecordConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; +import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -26,26 +26,26 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RestController @RequestMapping("/trade/brokerage-record") @Validated -public class TradeBrokerageRecordController { +public class BrokerageRecordController { @Resource - private TradeBrokerageRecordService tradeBrokerageRecordService; + private BrokerageRecordService brokerageRecordService; @GetMapping("/get") @Operation(summary = "获得佣金记录") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('trade:brokerage-record:query')") - public CommonResult getBrokerageRecord(@RequestParam("id") Integer id) { - TradeBrokerageRecordDO tradeBrokerageRecord = tradeBrokerageRecordService.getBrokerageRecord(id); - return success(TradeBrokerageRecordConvert.INSTANCE.convert(tradeBrokerageRecord)); + public CommonResult getBrokerageRecord(@RequestParam("id") Integer id) { + BrokerageRecordDO brokerageRecord = brokerageRecordService.getBrokerageRecord(id); + return success(BrokerageRecordConvert.INSTANCE.convert(brokerageRecord)); } @GetMapping("/page") @Operation(summary = "获得佣金记录分页") @PreAuthorize("@ss.hasPermission('trade:brokerage-record:query')") - public CommonResult> getBrokerageRecordPage(@Valid TradeBrokerageRecordPageReqVO pageVO) { - PageResult pageResult = tradeBrokerageRecordService.getBrokerageRecordPage(pageVO); - return success(TradeBrokerageRecordConvert.INSTANCE.convertPage(pageResult)); + public CommonResult> getBrokerageRecordPage(@Valid BrokerageRecordPageReqVO pageVO) { + PageResult pageResult = brokerageRecordService.getBrokerageRecordPage(pageVO); + return success(BrokerageRecordConvert.INSTANCE.convertPage(pageResult)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordBaseVO.java similarity index 98% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordBaseVO.java index f15d07706b..cce84a804a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordBaseVO.java @@ -15,7 +15,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 */ @Data -public class TradeBrokerageRecordBaseVO { +public class BrokerageRecordBaseVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25973") @NotNull(message = "用户编号不能为空") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordPageReqVO.java similarity index 94% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordPageReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordPageReqVO.java index abd948f09e..533fbd2ca1 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordPageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordPageReqVO.java @@ -15,7 +15,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class TradeBrokerageRecordPageReqVO extends PageParam { +public class BrokerageRecordPageReqVO extends PageParam { @Schema(description = "用户编号", example = "25973") private Long userId; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordRespVO.java similarity index 89% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordRespVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordRespVO.java index 724d7d3e59..aead00a08a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordRespVO.java @@ -11,7 +11,7 @@ import java.time.LocalDateTime; @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class TradeBrokerageRecordRespVO extends TradeBrokerageRecordBaseVO { +public class BrokerageRecordRespVO extends BrokerageRecordBaseVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "28896") private Integer id; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java similarity index 73% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java index 38a27d8c82..b6c9a1c844 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/TradeBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java @@ -5,13 +5,13 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.*; -import cn.iocoder.yudao.module.trade.convert.brokerage.user.TradeBrokerageUserConvert; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.convert.brokerage.user.BrokerageUserConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; -import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; -import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; +import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -32,12 +32,12 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. @RestController @RequestMapping("/trade/brokerage-user") @Validated -public class TradeBrokerageUserController { +public class BrokerageUserController { @Resource - private TradeBrokerageUserService brokerageUserService; + private BrokerageUserService brokerageUserService; @Resource - private TradeBrokerageRecordService brokerageRecordService; + private BrokerageRecordService brokerageRecordService; @Resource private MemberUserApi memberUserApi; @@ -45,7 +45,7 @@ public class TradeBrokerageUserController { @PutMapping("/update-brokerage-user") @Operation(summary = "修改推广员") @PreAuthorize("@ss.hasPermission('trade:brokerage-user:update-brokerage-user')") - public CommonResult updateBrokerageUser(@Valid @RequestBody TradeBrokerageUserUpdateBrokerageUserReqVO updateReqVO) { + public CommonResult updateBrokerageUser(@Valid @RequestBody BrokerageUserUpdateBrokerageUserReqVO updateReqVO) { brokerageUserService.updateBrokerageUserId(updateReqVO.getId(), updateReqVO.getBrokerageUserId()); return success(true); } @@ -53,7 +53,7 @@ public class TradeBrokerageUserController { @PutMapping("/clear-brokerage-user") @Operation(summary = "清除推广员") @PreAuthorize("@ss.hasPermission('trade:brokerage-user:clear-brokerage-user')") - public CommonResult clearBrokerageUser(@Valid @RequestBody TradeBrokerageUserClearBrokerageUserReqVO updateReqVO) { + public CommonResult clearBrokerageUser(@Valid @RequestBody BrokerageUserClearBrokerageUserReqVO updateReqVO) { brokerageUserService.updateBrokerageUserId(updateReqVO.getId(), null); return success(true); } @@ -61,7 +61,7 @@ public class TradeBrokerageUserController { @PutMapping("/update-brokerage-enable") @Operation(summary = "修改推广资格") @PreAuthorize("@ss.hasPermission('trade:brokerage-user:update-brokerage-enable')") - public CommonResult updateBrokerageEnabled(@Valid @RequestBody TradeBrokerageUserUpdateBrokerageEnabledReqVO updateReqVO) { + public CommonResult updateBrokerageEnabled(@Valid @RequestBody BrokerageUserUpdateBrokerageEnabledReqVO updateReqVO) { brokerageUserService.updateBrokerageEnabled(updateReqVO.getId(), updateReqVO.getBrokerageEnabled()); return success(true); } @@ -70,20 +70,20 @@ public class TradeBrokerageUserController { @Operation(summary = "获得分销用户") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('trade:brokerage-user:query')") - public CommonResult getBrokerageUser(@RequestParam("id") Long id) { - TradeBrokerageUserDO brokerageUser = brokerageUserService.getBrokerageUser(id); - return success(TradeBrokerageUserConvert.INSTANCE.convert(brokerageUser)); + public CommonResult getBrokerageUser(@RequestParam("id") Long id) { + BrokerageUserDO brokerageUser = brokerageUserService.getBrokerageUser(id); + return success(BrokerageUserConvert.INSTANCE.convert(brokerageUser)); } @GetMapping("/page") @Operation(summary = "获得分销用户分页") @PreAuthorize("@ss.hasPermission('trade:brokerage-user:query')") - public CommonResult> getBrokerageUserPage(@Valid TradeBrokerageUserPageReqVO pageVO) { + public CommonResult> getBrokerageUserPage(@Valid BrokerageUserPageReqVO pageVO) { // 分页查询 - PageResult pageResult = brokerageUserService.getBrokerageUserPage(pageVO); + PageResult pageResult = brokerageUserService.getBrokerageUserPage(pageVO); // 涉及到的用户 - Set userIds = convertSet(pageResult.getList(), TradeBrokerageUserDO::getId); + Set userIds = convertSet(pageResult.getList(), BrokerageUserDO::getId); // 查询用户信息 Map userMap = memberUserApi.getUserMap(userIds); // 合计分佣订单 @@ -98,7 +98,7 @@ public class TradeBrokerageUserController { // todo 合计提现 - return success(TradeBrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap)); + return success(BrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java similarity index 97% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserBaseVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java index d75e6a1b13..41ddd454cf 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java @@ -14,7 +14,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 */ @Data -public class TradeBrokerageUserBaseVO { +public class BrokerageUserBaseVO { @Schema(description = "推广员编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4587") @NotNull(message = "推广员编号不能为空") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserClearBrokerageUserReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserClearBrokerageUserReqVO.java similarity index 90% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserClearBrokerageUserReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserClearBrokerageUserReqVO.java index 18a5a5e853..edb0102a0a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserClearBrokerageUserReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserClearBrokerageUserReqVO.java @@ -9,7 +9,7 @@ import javax.validation.constraints.NotNull; @Schema(description = "管理后台 - 分销用户 - 清除推广员 Request VO") @Data @ToString(callSuper = true) -public class TradeBrokerageUserClearBrokerageUserReqVO { +public class BrokerageUserClearBrokerageUserReqVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20019") @NotNull(message = "用户编号不能为空") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java similarity index 93% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserPageReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java index ec63775d34..2b99d686ed 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserPageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java @@ -15,7 +15,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class TradeBrokerageUserPageReqVO extends PageParam { +public class BrokerageUserPageReqVO extends PageParam { @Schema(description = "推广员编号", example = "4587") private Long brokerageUserId; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserRespVO.java similarity index 95% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserRespVO.java index ee82efa0d8..c353b46145 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserRespVO.java @@ -11,7 +11,7 @@ import java.time.LocalDateTime; @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class TradeBrokerageUserRespVO extends TradeBrokerageUserBaseVO { +public class BrokerageUserRespVO extends BrokerageUserBaseVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20019") private Long id; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java similarity index 92% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java index 1fd38b028e..5e6d920be0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java @@ -9,7 +9,7 @@ import javax.validation.constraints.NotNull; @Schema(description = "管理后台 - 分销用户 - 修改推广员 Request VO") @Data @ToString(callSuper = true) -public class TradeBrokerageUserUpdateBrokerageEnabledReqVO { +public class BrokerageUserUpdateBrokerageEnabledReqVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20019") @NotNull(message = "用户编号不能为空") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageUserReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java similarity index 92% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageUserReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java index 28ea301c13..c6c72999d1 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageUserReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java @@ -9,7 +9,7 @@ import javax.validation.constraints.NotNull; @Schema(description = "管理后台 - 分销用户 - 修改推广员 Request VO") @Data @ToString(callSuper = true) -public class TradeBrokerageUserUpdateBrokerageUserReqVO { +public class BrokerageUserUpdateBrokerageUserReqVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20019") @NotNull(message = "用户编号不能为空") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java similarity index 65% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java index 2d67f5f2e6..d619c69264 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java @@ -3,9 +3,9 @@ package cn.iocoder.yudao.module.trade.convert.brokerage.record; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordRespVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordRespVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; import org.mapstruct.Mapper; @@ -20,25 +20,25 @@ import java.util.List; * @author owen */ @Mapper -public interface TradeBrokerageRecordConvert { +public interface BrokerageRecordConvert { - TradeBrokerageRecordConvert INSTANCE = Mappers.getMapper(TradeBrokerageRecordConvert.class); + BrokerageRecordConvert INSTANCE = Mappers.getMapper(BrokerageRecordConvert.class); - TradeBrokerageRecordRespVO convert(TradeBrokerageRecordDO bean); + BrokerageRecordRespVO convert(BrokerageRecordDO bean); - List convertList(List list); + List convertList(List list); - PageResult convertPage(PageResult page); + PageResult convertPage(PageResult page); - default TradeBrokerageRecordDO convert(TradeBrokerageUserDO user, BrokerageRecordBizTypeEnum bizType, String bizId, - Integer brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime, - String title) { + default BrokerageRecordDO convert(BrokerageUserDO user, BrokerageRecordBizTypeEnum bizType, String bizId, + Integer brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime, + String title) { brokerageFrozenDays = ObjectUtil.defaultIfNull(brokerageFrozenDays, 0); // 不冻结时,佣金直接就是结算状态 Integer status = brokerageFrozenDays > 0 ? BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus() : BrokerageRecordStatusEnum.SETTLEMENT.getStatus(); - return new TradeBrokerageRecordDO() + return new BrokerageRecordDO() .setUserId(user.getId()) .setBizType(bizType.getType()) .setBizId(bizId) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java similarity index 62% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java index beda1571c6..c4a31cc987 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/TradeBrokerageUserConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java @@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.trade.convert.brokerage.user; import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserRespVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserRespVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -19,22 +19,22 @@ import java.util.Optional; * @author owen */ @Mapper -public interface TradeBrokerageUserConvert { +public interface BrokerageUserConvert { - TradeBrokerageUserConvert INSTANCE = Mappers.getMapper(TradeBrokerageUserConvert.class); + BrokerageUserConvert INSTANCE = Mappers.getMapper(BrokerageUserConvert.class); - TradeBrokerageUserRespVO convert(TradeBrokerageUserDO bean); + BrokerageUserRespVO convert(BrokerageUserDO bean); - List convertList(List list); + List convertList(List list); - PageResult convertPage(PageResult page); + PageResult convertPage(PageResult page); - default PageResult convertPage(PageResult pageResult, - Map userMap, - Map brokerageUserCountMap, - Map userOrderSummaryMap) { - PageResult result = convertPage(pageResult); - for (TradeBrokerageUserRespVO vo : result.getList()) { + default PageResult convertPage(PageResult pageResult, + Map userMap, + Map brokerageUserCountMap, + Map userOrderSummaryMap) { + PageResult result = convertPage(pageResult); + for (BrokerageUserRespVO vo : result.getList()) { // 用户信息 Optional.ofNullable(userMap.get(vo.getId())) .ifPresent(user -> { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/BrokerageRecordDO.java similarity index 97% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/BrokerageRecordDO.java index bb3f09c52a..be69c60755 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/BrokerageRecordDO.java @@ -23,7 +23,7 @@ import java.time.LocalDateTime; @Builder @NoArgsConstructor @AllArgsConstructor -public class TradeBrokerageRecordDO extends BaseDO { +public class BrokerageRecordDO extends BaseDO { /** * 编号 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java similarity index 96% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java index 3f1cc73aa6..4b85dc3d0e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java @@ -22,7 +22,7 @@ import java.time.LocalDateTime; @Builder @NoArgsConstructor @AllArgsConstructor -public class TradeBrokerageUserDO extends BaseDO { +public class BrokerageUserDO extends BaseDO { /** * 用户编号 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/BrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/BrokerageRecordMapper.java new file mode 100644 index 0000000000..9f9aae824d --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/BrokerageRecordMapper.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 佣金记录 Mapper + * + * @author owen + */ +@Mapper +public interface BrokerageRecordMapper extends BaseMapperX { + + default PageResult selectPage(BrokerageRecordPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(BrokerageRecordDO::getUserId, reqVO.getUserId()) + .eqIfPresent(BrokerageRecordDO::getBizType, reqVO.getBizType()) + .eqIfPresent(BrokerageRecordDO::getStatus, reqVO.getStatus()) + .betweenIfPresent(BrokerageRecordDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(BrokerageRecordDO::getId)); + } + + default List selectListByStatusAndUnfreezeTimeLt(Integer status, LocalDateTime unfreezeTime) { + return selectList(new LambdaQueryWrapper() + .eq(BrokerageRecordDO::getStatus, status) + .lt(BrokerageRecordDO::getUnfreezeTime, unfreezeTime)); + } + + default int updateByIdAndStatus(Integer id, Integer status, BrokerageRecordDO updateObj) { + return update(updateObj, new LambdaQueryWrapper() + .eq(BrokerageRecordDO::getId, id) + .eq(BrokerageRecordDO::getStatus, status)); + } + + default BrokerageRecordDO selectByBizTypeAndBizId(Integer bizType, String bizId) { + return selectOne(BrokerageRecordDO::getBizType, bizType, + BrokerageRecordDO::getBizId, bizId); + } + + @Select("select count(1), sum(price) from trade_brokerage_record where user_id = #{userId} and biz_type = #{bizType} and status = #{status}") + UserBrokerageSummaryBO selectCountAndSumPriceByUserIdAndBizTypeAndStatus(@Param("userId") Long userId, + @Param("bizType") Integer bizType, + @Param("status") Integer status); +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java deleted file mode 100644 index 9a8c6df76d..0000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java +++ /dev/null @@ -1,55 +0,0 @@ -package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; - -import java.time.LocalDateTime; -import java.util.List; - -/** - * 佣金记录 Mapper - * - * @author owen - */ -@Mapper -public interface TradeBrokerageRecordMapper extends BaseMapperX { - - default PageResult selectPage(TradeBrokerageRecordPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(TradeBrokerageRecordDO::getUserId, reqVO.getUserId()) - .eqIfPresent(TradeBrokerageRecordDO::getBizType, reqVO.getBizType()) - .eqIfPresent(TradeBrokerageRecordDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(TradeBrokerageRecordDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(TradeBrokerageRecordDO::getId)); - } - - default List selectListByStatusAndUnfreezeTimeLt(Integer status, LocalDateTime unfreezeTime) { - return selectList(new LambdaQueryWrapper() - .eq(TradeBrokerageRecordDO::getStatus, status) - .lt(TradeBrokerageRecordDO::getUnfreezeTime, unfreezeTime)); - } - - default int updateByIdAndStatus(Integer id, Integer status, TradeBrokerageRecordDO updateObj) { - return update(updateObj, new LambdaQueryWrapper() - .eq(TradeBrokerageRecordDO::getId, id) - .eq(TradeBrokerageRecordDO::getStatus, status)); - } - - default TradeBrokerageRecordDO selectByBizTypeAndBizId(Integer bizType, String bizId) { - return selectOne(TradeBrokerageRecordDO::getBizType, bizType, - TradeBrokerageRecordDO::getBizId, bizId); - } - - @Select("select count(1), sum(price) from trade_brokerage_record where user_id = #{userId} and biz_type = #{bizType} and status = #{status}") - UserBrokerageSummaryBO selectCountAndSumPriceByUserIdAndBizTypeAndStatus(@Param("userId") Long userId, - @Param("bizType") Integer bizType, - @Param("status") Integer status); -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/TradeBrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java similarity index 65% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/TradeBrokerageUserMapper.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java index de163eb599..d5cc39523c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/TradeBrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java @@ -4,8 +4,8 @@ import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; @@ -15,14 +15,14 @@ import org.apache.ibatis.annotations.Mapper; * @author owen */ @Mapper -public interface TradeBrokerageUserMapper extends BaseMapperX { +public interface BrokerageUserMapper extends BaseMapperX { - default PageResult selectPage(TradeBrokerageUserPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(TradeBrokerageUserDO::getBrokerageUserId, reqVO.getBrokerageUserId()) - .eqIfPresent(TradeBrokerageUserDO::getBrokerageEnabled, reqVO.getBrokerageEnabled()) - .betweenIfPresent(TradeBrokerageUserDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(TradeBrokerageUserDO::getId)); + default PageResult selectPage(BrokerageUserPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(BrokerageUserDO::getBrokerageUserId, reqVO.getBrokerageUserId()) + .eqIfPresent(BrokerageUserDO::getBrokerageEnabled, reqVO.getBrokerageEnabled()) + .betweenIfPresent(BrokerageUserDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(BrokerageUserDO::getId)); } /** @@ -33,9 +33,9 @@ public interface TradeBrokerageUserMapper extends BaseMapperX 0); - LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" brokerage_price = brokerage_price + " + incrCount) - .eq(TradeBrokerageUserDO::getId, id); + .eq(BrokerageUserDO::getId, id); update(null, lambdaUpdateWrapper); } @@ -48,9 +48,9 @@ public interface TradeBrokerageUserMapper extends BaseMapperX lambdaUpdateWrapper = new LambdaUpdateWrapper() + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" brokerage_price = brokerage_price + " + incrCount) // 负数,所以使用 + 号 - .eq(TradeBrokerageUserDO::getId, id); + .eq(BrokerageUserDO::getId, id); update(null, lambdaUpdateWrapper); } @@ -62,9 +62,9 @@ public interface TradeBrokerageUserMapper extends BaseMapperX 0); - LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) - .eq(TradeBrokerageUserDO::getId, id); + .eq(BrokerageUserDO::getId, id); update(null, lambdaUpdateWrapper); } @@ -77,9 +77,9 @@ public interface TradeBrokerageUserMapper extends BaseMapperX lambdaUpdateWrapper = new LambdaUpdateWrapper() + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) // 负数,所以使用 + 号 - .eq(TradeBrokerageUserDO::getId, id); + .eq(BrokerageUserDO::getId, id); update(null, lambdaUpdateWrapper); } @@ -92,11 +92,11 @@ public interface TradeBrokerageUserMapper extends BaseMapperX lambdaUpdateWrapper = new LambdaUpdateWrapper() + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount + // 负数,所以使用 + 号 ", brokerage_price = brokerage_price + " + -incrCount) // 负数,所以使用 - 号 - .eq(TradeBrokerageUserDO::getId, id) - .ge(TradeBrokerageUserDO::getFrozenBrokeragePrice, -incrCount); // cas 逻辑 + .eq(BrokerageUserDO::getId, id) + .ge(BrokerageUserDO::getFrozenBrokeragePrice, -incrCount); // cas 逻辑 return update(null, lambdaUpdateWrapper); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/TradeBrokerageRecordUnfreezeJob.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/BrokerageRecordUnfreezeJob.java similarity index 63% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/TradeBrokerageRecordUnfreezeJob.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/BrokerageRecordUnfreezeJob.java index 94218d47e7..c221408e55 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/TradeBrokerageRecordUnfreezeJob.java +++ b/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; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; -import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService; import org.springframework.stereotype.Component; import javax.annotation.Resource; @@ -15,14 +15,14 @@ import javax.annotation.Resource; */ @Component @TenantJob -public class TradeBrokerageRecordUnfreezeJob implements JobHandler { +public class BrokerageRecordUnfreezeJob implements JobHandler { @Resource - private TradeBrokerageRecordService tradeBrokerageRecordService; + private BrokerageRecordService brokerageRecordService; @Override public String execute(String param) { - int count = tradeBrokerageRecordService.unfreezeRecord(); + int count = brokerageRecordService.unfreezeRecord(); return StrUtil.format("解冻佣金 {} 个", count); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java similarity index 86% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java index d02745e3b2..f0cadd7615 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.module.trade.service.brokerage.record; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; @@ -14,7 +14,7 @@ import java.util.List; * * @author owen */ -public interface TradeBrokerageRecordService { +public interface BrokerageRecordService { /** * 获得佣金记录 @@ -22,7 +22,7 @@ public interface TradeBrokerageRecordService { * @param id 编号 * @return 佣金记录 */ - TradeBrokerageRecordDO getBrokerageRecord(Integer id); + BrokerageRecordDO getBrokerageRecord(Integer id); /** * 获得佣金记录分页 @@ -30,7 +30,7 @@ public interface TradeBrokerageRecordService { * @param pageReqVO 分页查询 * @return 佣金记录分页 */ - PageResult getBrokerageRecordPage(TradeBrokerageRecordPageReqVO pageReqVO); + PageResult getBrokerageRecordPage(BrokerageRecordPageReqVO pageReqVO); /** * 增加佣金 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java similarity index 72% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java index ad1a5c8ff2..ae9f1ff883 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java @@ -6,17 +6,17 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.convert.brokerage.record.TradeBrokerageRecordConvert; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.convert.brokerage.record.BrokerageRecordConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.TradeBrokerageRecordMapper; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.BrokerageRecordMapper; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; -import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; +import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -37,23 +37,23 @@ import java.util.function.Function; @Slf4j @Service @Validated -public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordService { +public class BrokerageRecordServiceImpl implements BrokerageRecordService { @Resource - private TradeBrokerageRecordMapper tradeBrokerageRecordMapper; + private BrokerageRecordMapper brokerageRecordMapper; @Resource private TradeConfigService tradeConfigService; @Resource - private TradeBrokerageUserService tradeBrokerageUserService; + private BrokerageUserService brokerageUserService; @Override - public TradeBrokerageRecordDO getBrokerageRecord(Integer id) { - return tradeBrokerageRecordMapper.selectById(id); + public BrokerageRecordDO getBrokerageRecord(Integer id) { + return brokerageRecordMapper.selectById(id); } @Override - public PageResult getBrokerageRecordPage(TradeBrokerageRecordPageReqVO pageReqVO) { - return tradeBrokerageRecordMapper.selectPage(pageReqVO); + public PageResult getBrokerageRecordPage(BrokerageRecordPageReqVO pageReqVO) { + return brokerageRecordMapper.selectPage(pageReqVO); } @Override @@ -67,7 +67,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ } // 1.1 获得一级推广人 - TradeBrokerageUserDO firstUser = tradeBrokerageUserService.getBindBrokerageUser(userId); + BrokerageUserDO firstUser = brokerageUserService.getBindBrokerageUser(userId); if (firstUser == null || !BooleanUtil.isTrue(firstUser.getBrokerageEnabled())) { return; } @@ -78,7 +78,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ if (firstUser.getBrokerageUserId() == null) { return; } - TradeBrokerageUserDO secondUser = tradeBrokerageUserService.getBrokerageUser(firstUser.getBrokerageUserId()); + BrokerageUserDO secondUser = brokerageUserService.getBrokerageUser(firstUser.getBrokerageUserId()); if (secondUser == null || !BooleanUtil.isTrue(secondUser.getBrokerageEnabled())) { return; } @@ -89,15 +89,15 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ @Override @Transactional(rollbackFor = Exception.class) public void cancelBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId) { - TradeBrokerageRecordDO record = tradeBrokerageRecordMapper.selectByBizTypeAndBizId(bizType.getType(), bizId); + BrokerageRecordDO record = brokerageRecordMapper.selectByBizTypeAndBizId(bizType.getType(), bizId); if (record == null || ObjectUtil.notEqual(record.getUserId(), userId)) { log.error("[cancelBrokerage][userId({})][bizId({}) 更新为已失效失败:记录不存在]", userId, bizId); return; } // 1. 更新佣金记录为已失效 - TradeBrokerageRecordDO updateObj = new TradeBrokerageRecordDO().setStatus(BrokerageRecordStatusEnum.CANCEL.getStatus()); - int updateRows = tradeBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); + BrokerageRecordDO updateObj = new BrokerageRecordDO().setStatus(BrokerageRecordStatusEnum.CANCEL.getStatus()); + int updateRows = brokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); if (updateRows == 0) { log.error("[cancelBrokerage][record({}) 更新为已失效失败]", record.getId()); return; @@ -105,9 +105,9 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ // 2. 更新用户的佣金 if (BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus().equals(record.getStatus())) { - tradeBrokerageUserService.updateUserFrozenBrokeragePrice(userId, -record.getPrice()); + brokerageUserService.updateUserFrozenBrokeragePrice(userId, -record.getPrice()); } else if (BrokerageRecordStatusEnum.SETTLEMENT.getStatus().equals(record.getStatus())) { - tradeBrokerageUserService.updateUserBrokeragePrice(userId, -record.getPrice()); + brokerageUserService.updateUserBrokeragePrice(userId, -record.getPrice()); } } @@ -141,7 +141,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ * @param FixedBrokeragePriceFun 固定佣金 * @param bizType 业务类型 */ - private void addBrokerage(TradeBrokerageUserDO user, List list, Integer brokerageFrozenDays, + private void addBrokerage(BrokerageUserDO user, List list, Integer brokerageFrozenDays, Integer brokeragePercent, Function FixedBrokeragePriceFun, BrokerageRecordBizTypeEnum bizType) { // 1.1 处理冻结时间 @@ -151,13 +151,13 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ } // 1.2 计算分佣 int totalBrokerage = 0; - List records = new ArrayList<>(); + List records = new ArrayList<>(); for (BrokerageAddReqBO item : list) { int brokeragePerItem = calculateBrokeragePrice(item.getBasePrice(), brokeragePercent, FixedBrokeragePriceFun.apply(item)); if (brokeragePerItem <= 0) { continue; } - records.add(TradeBrokerageRecordConvert.INSTANCE.convert(user, bizType, item.getBizId(), + records.add(BrokerageRecordConvert.INSTANCE.convert(user, bizType, item.getBizId(), brokerageFrozenDays, brokeragePerItem, unfreezeTime, bizType.getTitle())); totalBrokerage += brokeragePerItem; } @@ -165,20 +165,20 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ return; } // 1.3 保存佣金记录 - tradeBrokerageRecordMapper.insertBatch(records); + brokerageRecordMapper.insertBatch(records); // 2. 更新用户佣金 if (brokerageFrozenDays != null && brokerageFrozenDays > 0) { // 更新用户冻结佣金 - tradeBrokerageUserService.updateUserFrozenBrokeragePrice(user.getId(), totalBrokerage); + brokerageUserService.updateUserFrozenBrokeragePrice(user.getId(), totalBrokerage); } else { // 更新用户可用佣金 - tradeBrokerageUserService.updateUserBrokeragePrice(user.getId(), totalBrokerage); + brokerageUserService.updateUserBrokeragePrice(user.getId(), totalBrokerage); } } @Override public int unfreezeRecord() { // 1. 查询待结算的佣金记录 - List records = tradeBrokerageRecordMapper.selectListByStatusAndUnfreezeTimeLt( + List records = brokerageRecordMapper.selectListByStatusAndUnfreezeTimeLt( BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus(), LocalDateTime.now()); if (CollUtil.isEmpty(records)) { return 0; @@ -186,7 +186,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ // 2. 遍历执行 int count = 0; - for (TradeBrokerageRecordDO record : records) { + for (BrokerageRecordDO record : records) { try { boolean success = getSelf().unfreezeRecord(record); if (success) { @@ -201,24 +201,24 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ @Override public UserBrokerageSummaryBO summaryByUserIdAndBizTypeAndStatus(Long userId, Integer bizType, Integer status) { - UserBrokerageSummaryBO summaryBO = tradeBrokerageRecordMapper.selectCountAndSumPriceByUserIdAndBizTypeAndStatus(userId, bizType, status); + UserBrokerageSummaryBO summaryBO = brokerageRecordMapper.selectCountAndSumPriceByUserIdAndBizTypeAndStatus(userId, bizType, status); return summaryBO == null ? new UserBrokerageSummaryBO(0, 0) : summaryBO; } @Transactional(rollbackFor = Exception.class) - public boolean unfreezeRecord(TradeBrokerageRecordDO record) { + public boolean unfreezeRecord(BrokerageRecordDO record) { // 更新记录状态 - TradeBrokerageRecordDO updateObj = new TradeBrokerageRecordDO() + BrokerageRecordDO updateObj = new BrokerageRecordDO() .setStatus(BrokerageRecordStatusEnum.SETTLEMENT.getStatus()) .setUnfreezeTime(LocalDateTime.now()); - int updateRows = tradeBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); + int updateRows = brokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); if (updateRows == 0) { log.error("[unfreezeRecord][record({}) 更新为已结算失败]", record.getId()); return false; } // 更新用户冻结佣金 - tradeBrokerageUserService.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(record.getUserId(), -record.getPrice()); + brokerageUserService.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(record.getUserId(), -record.getPrice()); log.info("[unfreezeRecord][record({}) 更新为已结算成功]", record.getId()); return true; } @@ -228,7 +228,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ * * @return 自己 */ - private TradeBrokerageRecordServiceImpl getSelf() { + private BrokerageRecordServiceImpl getSelf() { return SpringUtil.getBean(getClass()); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java similarity index 78% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java index c62fc1947e..d1ed8865c3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java @@ -1,19 +1,18 @@ package cn.iocoder.yudao.module.trade.service.brokerage.user; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; import java.util.Collection; import java.util.List; -// TODO @疯狂:要不去掉 Trade 前缀哈;交易这块,我准备除了 tradeorder 保持下,类似 aftersale,都要取消前缀了;tradeorder 保持的原因,是避免 payorder 和它重复 /** * 分销用户 Service 接口 * * @author owen */ -public interface TradeBrokerageUserService { +public interface BrokerageUserService { /** * 获得分销用户 @@ -21,7 +20,7 @@ public interface TradeBrokerageUserService { * @param id 编号 * @return 分销用户 */ - TradeBrokerageUserDO getBrokerageUser(Long id); + BrokerageUserDO getBrokerageUser(Long id); /** * 获得分销用户列表 @@ -29,7 +28,7 @@ public interface TradeBrokerageUserService { * @param ids 编号 * @return 分销用户列表 */ - List getBrokerageUserList(Collection ids); + List getBrokerageUserList(Collection ids); /** * 获得分销用户分页 @@ -37,7 +36,7 @@ public interface TradeBrokerageUserService { * @param pageReqVO 分页查询 * @return 分销用户分页 */ - PageResult getBrokerageUserPage(TradeBrokerageUserPageReqVO pageReqVO); + PageResult getBrokerageUserPage(BrokerageUserPageReqVO pageReqVO); /** * 修改推广员编号 @@ -61,7 +60,7 @@ public interface TradeBrokerageUserService { * @param id 用户编号 * @return 用户的推广人 */ - TradeBrokerageUserDO getBindBrokerageUser(Long id); + BrokerageUserDO getBindBrokerageUser(Long id); /** * 更新用户佣金 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java similarity index 80% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java index 6851e522c3..8f840bb7da 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java @@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.trade.service.brokerage.user; import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.TradeBrokerageUserMapper; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.BrokerageUserMapper; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -24,23 +24,23 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.USER_FROZEN */ @Service @Validated -public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService { +public class BrokerageUserServiceImpl implements BrokerageUserService { @Resource - private TradeBrokerageUserMapper brokerageUserMapper; + private BrokerageUserMapper brokerageUserMapper; @Override - public TradeBrokerageUserDO getBrokerageUser(Long id) { + public BrokerageUserDO getBrokerageUser(Long id) { return brokerageUserMapper.selectById(id); } @Override - public List getBrokerageUserList(Collection ids) { + public List getBrokerageUserList(Collection ids) { return brokerageUserMapper.selectBatchIds(ids); } @Override - public PageResult getBrokerageUserPage(TradeBrokerageUserPageReqVO pageReqVO) { + public PageResult getBrokerageUserPage(BrokerageUserPageReqVO pageReqVO) { return brokerageUserMapper.selectPage(pageReqVO); } @@ -65,10 +65,10 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService } @Override - public TradeBrokerageUserDO getBindBrokerageUser(Long id) { + public BrokerageUserDO getBindBrokerageUser(Long id) { return Optional.ofNullable(id) .map(this::getBrokerageUser) - .map(TradeBrokerageUserDO::getBrokerageUserId) + .map(BrokerageUserDO::getBrokerageUserId) .map(this::getBrokerageUser) .orElse(null); } @@ -102,7 +102,7 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService @Override public Long getCountByBrokerageUserId(Long brokerageUserId) { - return brokerageUserMapper.selectCount(TradeBrokerageUserDO::getBrokerageUserId, brokerageUserId); + return brokerageUserMapper.selectCount(BrokerageUserDO::getBrokerageUserId, brokerageUserId); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 199cfcbfdd..1cda4b3a5e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -51,7 +51,7 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.*; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; -import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService; import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.trade.service.cart.CartService; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; @@ -121,7 +121,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Resource private MemberPointApi memberPointApi; @Resource - private TradeBrokerageRecordService tradeBrokerageRecordService; + private BrokerageRecordService brokerageRecordService; @Resource private ProductCommentApi productCommentApi; @@ -755,12 +755,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { List orderItems = tradeOrderItemMapper.selectListByOrderId(orderId); List list = convertList(orderItems, item -> TradeOrderConvert.INSTANCE.convert(item, productSkuApi.getSku(item.getSkuId()))); - tradeBrokerageRecordService.addBrokerage(userId, bizType, list); + brokerageRecordService.addBrokerage(userId, bizType, list); } @Async protected void cancelBrokerageAsync(Long userId, BrokerageRecordBizTypeEnum bizType, Long orderItemId) { - tradeBrokerageRecordService.cancelBrokerage(userId, bizType, String.valueOf(orderItemId)); + brokerageRecordService.cancelBrokerage(userId, bizType, String.valueOf(orderItemId)); } /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImplTest.java similarity index 67% rename from yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java rename to yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImplTest.java index eb51279d5a..00ff04d6da 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImplTest.java @@ -3,10 +3,10 @@ package cn.iocoder.yudao.module.trade.service.brokerage.record; import cn.hutool.core.util.NumberUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.TradeBrokerageRecordMapper; -import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.BrokerageRecordMapper; +import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -27,51 +27,51 @@ import static org.junit.jupiter.api.Assertions.assertEquals; // TODO @芋艿:单测后续看看 /** - * {@link TradeBrokerageRecordServiceImpl} 的单元测试类 + * {@link BrokerageRecordServiceImpl} 的单元测试类 * * @author owen */ -@Import(TradeBrokerageRecordServiceImpl.class) -public class TradeBrokerageRecordServiceImplTest extends BaseDbUnitTest { +@Import(BrokerageRecordServiceImpl.class) +public class BrokerageRecordServiceImplTest extends BaseDbUnitTest { @Resource - private TradeBrokerageRecordServiceImpl tradeBrokerageRecordService; + private BrokerageRecordServiceImpl brokerageRecordService; @Resource - private TradeBrokerageRecordMapper tradeBrokerageRecordMapper; + private BrokerageRecordMapper brokerageRecordMapper; @MockBean private TradeConfigService tradeConfigService; @MockBean - private TradeBrokerageUserService tradeBrokerageUserService; + private BrokerageUserService brokerageUserService; @Test @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 public void testGetBrokerageRecordPage() { // mock 数据 - TradeBrokerageRecordDO dbBrokerageRecord = randomPojo(TradeBrokerageRecordDO.class, o -> { // 等会查询到 + BrokerageRecordDO dbBrokerageRecord = randomPojo(BrokerageRecordDO.class, o -> { // 等会查询到 o.setUserId(null); o.setBizType(null); o.setStatus(null); o.setCreateTime(null); }); - tradeBrokerageRecordMapper.insert(dbBrokerageRecord); + brokerageRecordMapper.insert(dbBrokerageRecord); // 测试 userId 不匹配 - tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setUserId(null))); + brokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setUserId(null))); // 测试 bizType 不匹配 - tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setBizType(null))); + brokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setBizType(null))); // 测试 status 不匹配 - tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setStatus(null))); + brokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setStatus(null))); // 测试 createTime 不匹配 - tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setCreateTime(null))); + brokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setCreateTime(null))); // 准备参数 - TradeBrokerageRecordPageReqVO reqVO = new TradeBrokerageRecordPageReqVO(); + BrokerageRecordPageReqVO reqVO = new BrokerageRecordPageReqVO(); reqVO.setUserId(null); reqVO.setBizType(null); reqVO.setStatus(null); reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); // 调用 - PageResult pageResult = tradeBrokerageRecordService.getBrokerageRecordPage(reqVO); + PageResult pageResult = brokerageRecordService.getBrokerageRecordPage(reqVO); // 断言 assertEquals(1, pageResult.getTotal()); assertEquals(1, pageResult.getList().size()); @@ -85,7 +85,7 @@ public class TradeBrokerageRecordServiceImplTest extends BaseDbUnitTest { Integer percent = randomInt(1, 101); Integer fixedBrokeragePrice = randomInt(); // 调用 - int brokerage = tradeBrokerageRecordService.calculateBrokeragePrice(payPrice, percent, fixedBrokeragePrice); + int brokerage = brokerageRecordService.calculateBrokeragePrice(payPrice, percent, fixedBrokeragePrice); // 断言 assertEquals(brokerage, fixedBrokeragePrice); } @@ -98,7 +98,7 @@ public class TradeBrokerageRecordServiceImplTest extends BaseDbUnitTest { Integer skuBrokeragePrice = randomEle(new Integer[]{0, null}); System.out.println("skuBrokeragePrice=" + skuBrokeragePrice); // 调用 - int brokerage = tradeBrokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); + int brokerage = brokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); // 断言 assertEquals(brokerage, NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue()); } @@ -110,7 +110,7 @@ public class TradeBrokerageRecordServiceImplTest extends BaseDbUnitTest { Integer percent = null; Integer skuBrokeragePrice = null; // 调用 - int brokerage = tradeBrokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); + int brokerage = brokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); // 断言 assertEquals(brokerage, 0); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java similarity index 74% rename from yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java rename to yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java index 153bbb4267..6950f84e46 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java @@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.trade.service.brokerage.user; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.TradeBrokerageUserPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.TradeBrokerageUserMapper; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.BrokerageUserMapper; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Import; @@ -19,24 +19,24 @@ import static org.junit.jupiter.api.Assertions.assertEquals; // TODO @芋艿:单测后续看看 /** - * {@link TradeBrokerageUserServiceImpl} 的单元测试类 + * {@link BrokerageUserServiceImpl} 的单元测试类 * * @author owen */ -@Import(TradeBrokerageUserServiceImpl.class) -public class TradeBrokerageUserServiceImplTest extends BaseDbUnitTest { +@Import(BrokerageUserServiceImpl.class) +public class BrokerageUserServiceImplTest extends BaseDbUnitTest { @Resource - private TradeBrokerageUserServiceImpl brokerageUserService; + private BrokerageUserServiceImpl brokerageUserService; @Resource - private TradeBrokerageUserMapper brokerageUserMapper; + private BrokerageUserMapper brokerageUserMapper; @Test @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 public void testGetBrokerageUserPage() { // mock 数据 - TradeBrokerageUserDO dbBrokerageUser = randomPojo(TradeBrokerageUserDO.class, o -> { // 等会查询到 + BrokerageUserDO dbBrokerageUser = randomPojo(BrokerageUserDO.class, o -> { // 等会查询到 o.setBrokerageUserId(null); o.setBrokerageEnabled(null); o.setCreateTime(null); @@ -49,13 +49,13 @@ public class TradeBrokerageUserServiceImplTest extends BaseDbUnitTest { // 测试 createTime 不匹配 brokerageUserMapper.insert(cloneIgnoreId(dbBrokerageUser, o -> o.setCreateTime(null))); // 准备参数 - TradeBrokerageUserPageReqVO reqVO = new TradeBrokerageUserPageReqVO(); + BrokerageUserPageReqVO reqVO = new BrokerageUserPageReqVO(); reqVO.setBrokerageUserId(null); reqVO.setBrokerageEnabled(null); reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); // 调用 - PageResult pageResult = brokerageUserService.getBrokerageUserPage(reqVO); + PageResult pageResult = brokerageUserService.getBrokerageUserPage(reqVO); // 断言 assertEquals(1, pageResult.getTotal()); assertEquals(1, pageResult.getList().size()); From b85d660a5cc375bccb9c200fd0ac4a813c62c00d Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 22:33:44 +0800 Subject: [PATCH 31/48] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E5=AE=8C=E5=96=84=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../record/AppBrokerageRecordPageReqVO.java | 7 ++- .../AppBrokerageWithdrawCreateReqVO.java | 59 +++++++++++++++++-- .../brokerage/bo/BrokerageAddReqBO.java | 7 ++- .../record/BrokerageRecordService.java | 3 +- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java index b7675e6ec1..e2df6dae6b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageRecordPageReqVO.java @@ -1,6 +1,9 @@ package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record; import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -8,12 +11,12 @@ import lombok.Data; @Data public class AppBrokerageRecordPageReqVO extends PageParam { - // TODO @疯狂:要加下枚举校验 - @Schema(description = "业务类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @InEnum(value = BrokerageRecordBizTypeEnum.class, message = "业务类型必须是 {value}") private Integer bizType; @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @InEnum(value = BrokerageRecordStatusEnum.class, message = "状态必须是 {value}") private Integer status; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java index 75aec997be..7528181303 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java @@ -1,29 +1,76 @@ package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw; +import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawTypeEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import org.hibernate.validator.constraints.URL; +import javax.validation.Validator; import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; @Schema(description = "用户 App - 分销提现创建 Request VO") @Data public class AppBrokerageWithdrawCreateReqVO { - // TODO @疯狂:参数校验逻辑,需要根据 type 进行不同的校验;感觉可以通过分组? - @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @InEnum(value = BrokerageWithdrawTypeEnum.class, message = "提现方式必须是 {value}") private Integer type; - @Schema(description = "提现账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456789") // 银行卡号/微信账号/支付宝账号 + @Schema(description = "提现金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") + @Min(value = 1, message = "提现金额不能小于 1") + private Integer price; + + + // ========== 银行卡、微信、支付宝 提现相关字段 ========== + + @Schema(description = "提现账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456789") + @NotBlank(message = "提现账号不能为空", groups = {Bank.class, Wechat.class, Alipay.class}) private String accountNo; + + // ========== 微信、支付宝 提现相关字段 ========== + @Schema(description = "收款码的图片", example = "https://www.iocoder.cn/1.png") @URL(message = "收款码的图片,必须是一个 URL") private String accountQrCodeUrl; - @Schema(description = "提现金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") - @Min(value = 1, message = "提现金额必须大于 1") - private Integer price; + + // ========== 银行卡 提现相关字段 ========== + + @Schema(description = "持卡人姓名", example = "张三") + @NotBlank(message = "持卡人姓名不能为空", groups = {Bank.class}) + private String name; + @Schema(description = "提现银行", example = "1") + @NotBlank(message = "提现银行不能为空", groups = {Bank.class}) + private Integer bankName; + @Schema(description = "开户地址", example = "海淀支行") + private String bankAddress; + + public interface Wallet { + } + + public interface Bank { + } + + public interface Wechat { + } + + public interface Alipay { + } + + public void validate(Validator validator) { + if (BrokerageWithdrawTypeEnum.WALLET.getType().equals(type)) { + ValidationUtils.validate(validator, this, Wallet.class); + } else if (BrokerageWithdrawTypeEnum.BANK.getType().equals(type)) { + ValidationUtils.validate(validator, this, Bank.class); + } else if (BrokerageWithdrawTypeEnum.WECHAT.getType().equals(type)) { + ValidationUtils.validate(validator, this, Wechat.class); + } else if (BrokerageWithdrawTypeEnum.ALIPAY.getType().equals(type)) { + ValidationUtils.validate(validator, this, Alipay.class); + } + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java index 7e17d9bda2..510960beb5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java @@ -4,6 +4,8 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import javax.validation.constraints.NotBlank; + /** * 佣金 增加 Request BO * @@ -14,11 +16,10 @@ import lombok.NoArgsConstructor; @AllArgsConstructor public class BrokerageAddReqBO { - // TODO @疯狂:bo 的话,也可以考虑加下 @Validated 注解,校验下参数;防御性下哈,虽然不一定用的到 - /** - * 业务ID + * 业务编号 */ + @NotBlank(message = "业务编号不能为空") private String bizId; /** * 佣金基数 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java index f0cadd7615..64e5fe52fa 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; +import javax.validation.Valid; import java.util.List; /** @@ -39,7 +40,7 @@ public interface BrokerageRecordService { * @param bizType 业务类型 * @param list 请求参数列表 */ - void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, List list); + void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, @Valid List list); /** * 取消佣金:将佣金记录,状态修改为已失效 From f36a6c5d6ca554962315d625df29fb0a6619aad5 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 22:40:49 +0800 Subject: [PATCH 32/48] =?UTF-8?q?trade:=20=E4=BC=98=E5=8C=96=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=8E=A8=E5=B9=BF=E5=91=98=E6=8E=A5=E5=8F=A3=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/brokerage/user/BrokerageUserController.java | 2 +- .../user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java | 4 +--- .../trade/service/brokerage/user/BrokerageUserService.java | 6 +++--- .../service/brokerage/user/BrokerageUserServiceImpl.java | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java index b6c9a1c844..1e1ad3acd4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java @@ -62,7 +62,7 @@ public class BrokerageUserController { @Operation(summary = "修改推广资格") @PreAuthorize("@ss.hasPermission('trade:brokerage-user:update-brokerage-enable')") public CommonResult updateBrokerageEnabled(@Valid @RequestBody BrokerageUserUpdateBrokerageEnabledReqVO updateReqVO) { - brokerageUserService.updateBrokerageEnabled(updateReqVO.getId(), updateReqVO.getBrokerageEnabled()); + brokerageUserService.updateBrokerageEnabled(updateReqVO.getId(), updateReqVO.getEnabled()); return success(true); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java index 5e6d920be0..92001e698a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java @@ -15,10 +15,8 @@ public class BrokerageUserUpdateBrokerageEnabledReqVO { @NotNull(message = "用户编号不能为空") private Long id; - // TODO @疯狂:是不是这个字段,可以改成 enabled - @Schema(description = "推广资格", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "推广资格不能为空") - private Boolean brokerageEnabled; + private Boolean enabled; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java index d1ed8865c3..362743b653 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java @@ -49,10 +49,10 @@ public interface BrokerageUserService { /** * 修改推广资格 * - * @param id 用户编号 - * @param brokerageEnabled 推广资格 + * @param id 用户编号 + * @param enabled 推广资格 */ - void updateBrokerageEnabled(Long id, Boolean brokerageEnabled); + void updateBrokerageEnabled(Long id, Boolean enabled); /** * 获得用户的推广人 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java index 8f840bb7da..3a4fb475f6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java @@ -52,7 +52,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } @Override - public void updateBrokerageEnabled(Long id, Boolean brokerageEnabled) { + public void updateBrokerageEnabled(Long id, Boolean enabled) { // 校验存在 validateBrokerageUserExists(id); // TODO @疯狂:貌似没实现完 From 3e09da012849bd45438344fe6a65eee78415dd92 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 8 Sep 2023 22:47:00 +0800 Subject: [PATCH 33/48] =?UTF-8?q?code=20review=EF=BC=9A=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E9=92=B1=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/order/PayOrderController.java | 21 ++- .../app/wallet/AppPayWalletController.java | 2 +- .../dal/dataobject/wallet/PayWalletDO.java | 2 + .../pay/dal/mysql/wallet/PayWalletMapper.java | 3 + .../framework/pay/wallet/WalletPayClient.java | 27 ++-- .../pay/service/wallet/PayWalletService.java | 24 +-- .../service/wallet/PayWalletServiceImpl.java | 145 +++++++++--------- .../PayWalletTransactionServiceImpl.java | 2 +- 8 files changed, 122 insertions(+), 104 deletions(-) diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java index a47031a2a9..8967426368 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java @@ -6,14 +6,15 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; -import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; import cn.iocoder.yudao.module.pay.controller.admin.order.vo.*; import cn.iocoder.yudao.module.pay.convert.order.PayOrderConvert; import cn.iocoder.yudao.module.pay.dal.dataobject.app.PayAppDO; import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO; import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderExtensionDO; +import cn.iocoder.yudao.module.pay.framework.pay.wallet.WalletPayClient; import cn.iocoder.yudao.module.pay.service.app.PayAppService; import cn.iocoder.yudao.module.pay.service.order.PayOrderService; +import com.google.common.collect.Maps; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -25,12 +26,17 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; +import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId; +import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserType; @Tag(name = "管理后台 - 支付订单") @RestController @@ -70,13 +76,16 @@ public class PayOrderController { @PostMapping("/submit") @Operation(summary = "提交支付订单") public CommonResult submitPayOrder(@RequestBody PayOrderSubmitReqVO reqVO) { - // 钱包支付需要 额外传 user_id 和 user_type + // 1. 钱包支付事,需要额外传 user_id 和 user_type if (Objects.equals(reqVO.getChannelCode(), PayChannelEnum.WALLET.getCode())) { - Map channelExtras = reqVO.getChannelExtras() == null ? new HashMap<>(8) : reqVO.getChannelExtras(); - channelExtras.put("user_id", String.valueOf(WebFrameworkUtils.getLoginUserId())); - channelExtras.put("user_type", String.valueOf(WebFrameworkUtils.getLoginUserType())); + Map channelExtras = reqVO.getChannelExtras() == null ? + Maps.newHashMapWithExpectedSize(2) : reqVO.getChannelExtras(); + channelExtras.put(WalletPayClient.USER_ID_KEY, String.valueOf(getLoginUserId())); + channelExtras.put(WalletPayClient.USER_TYPE_KEY, String.valueOf(getLoginUserType())); reqVO.setChannelExtras(channelExtras); } + + // 2. 提交支付 PayOrderSubmitRespVO respVO = orderService.submitOrder(reqVO, getClientIP()); return success(respVO); } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletController.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletController.java index 2c5f2d5f4a..95c085cbc4 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletController.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletController.java @@ -37,7 +37,7 @@ public class AppPayWalletController { @Operation(summary = "获取钱包") @PreAuthenticated public CommonResult getPayWallet() { - PayWalletDO wallet = payWalletService.getOrCreatePayWallet(getLoginUserId(), UserTypeEnum.MEMBER.getValue()); + PayWalletDO wallet = payWalletService.getOrCreateWallet(getLoginUserId(), UserTypeEnum.MEMBER.getValue()); return success(PayWalletConvert.INSTANCE.convert(wallet)); } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletDO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletDO.java index 92eb620dac..4bf8e61519 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletDO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletDO.java @@ -37,6 +37,8 @@ public class PayWalletDO extends BaseDO { */ private Integer userType; + // TODO @jason:三个都搞 integer?应该要统一哈 + /** * 余额,单位分 */ diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java index ccacdd3768..47717d04a3 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java @@ -15,6 +15,7 @@ public interface PayWalletMapper extends BaseMapperX { PayWalletDO::getUserType, userType); } + // TODO @jason:减少时,需要 update price -= ? where price >= ?,避免并发问题。现在基于 price 来过滤,虽然也能解决并发问题,但是冲突概率会高一点;可以看到 TradeBrokerageUserMapper 的做法; /** * 当余额减少时候更新 * @@ -27,6 +28,7 @@ public interface PayWalletMapper extends BaseMapperX { */ default int updateWhenDecBalance(PayWalletBizTypeEnum bizType, Integer balance, Long totalRecharge, Long totalExpense, Integer price, Long id) { + // TODO @jason:这种偏判断的,最红放在 service 层;mapper 可以写多个方法; PayWalletDO updateDO = new PayWalletDO().setBalance(balance - price); if(bizType == PayWalletBizTypeEnum.PAYMENT){ updateDO.setTotalExpense(totalExpense + price); @@ -40,6 +42,7 @@ public interface PayWalletMapper extends BaseMapperX { .ge(PayWalletDO::getBalance, price)); } + // TODO @jason:类似上面的修改建议哈; /** * 当余额增加时候更新 * diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java index 42da490d28..47e8217d30 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java @@ -37,13 +37,13 @@ import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.REFUND_NOT_FO @Slf4j public class WalletPayClient extends AbstractPayClient { + public static final String USER_ID_KEY = "user_id"; + public static final String USER_TYPE_KEY = "user_type"; + private PayWalletService wallService; - private PayWalletTransactionService walletTransactionService; - - private PayOrderService payOrderService; - - private PayRefundService payRefundService; + private PayOrderService orderService; + private PayRefundService refundService; public WalletPayClient(Long channelId, NonePayClientConfig config) { super(channelId, PayChannelEnum.WALLET.getCode(), config); @@ -62,8 +62,9 @@ public class WalletPayClient extends AbstractPayClient { @Override protected PayOrderRespDTO doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) { try { - String userId = MapUtil.getStr(reqDTO.getChannelExtras(), "user_id"); - String userType = MapUtil.getStr(reqDTO.getChannelExtras(), "user_type"); + // TODO @jason:直接 getLong 和 getInt 会不会更简洁哈 + String userId = MapUtil.getStr(reqDTO.getChannelExtras(), USER_ID_KEY); + String userType = MapUtil.getStr(reqDTO.getChannelExtras(), USER_TYPE_KEY); Assert.notEmpty(userId, "用户 id 不能为空"); Assert.notEmpty(userType, "用户类型不能为空"); PayWalletTransactionDO transaction = wallService.orderPay(Long.valueOf(userId), Integer.valueOf(userType), @@ -92,10 +93,10 @@ public class WalletPayClient extends AbstractPayClient { @Override protected PayOrderRespDTO doGetOrder(String outTradeNo) { - if (payOrderService == null) { - payOrderService = SpringUtil.getBean(PayOrderService.class); + if (orderService == null) { + orderService = SpringUtil.getBean(PayOrderService.class); } - PayOrderExtensionDO orderExtension = payOrderService.getOrderExtensionByNo(outTradeNo); + PayOrderExtensionDO orderExtension = orderService.getOrderExtensionByNo(outTradeNo); // 支付交易拓展单不存在, 返回关闭状态 if (orderExtension == null) { return PayOrderRespDTO.closedOf(String.valueOf(ORDER_EXTENSION_NOT_FOUND.getCode()), @@ -147,10 +148,10 @@ public class WalletPayClient extends AbstractPayClient { @Override protected PayRefundRespDTO doGetRefund(String outTradeNo, String outRefundNo) { - if (payRefundService == null) { - payRefundService = SpringUtil.getBean(PayRefundService.class); + if (refundService == null) { + refundService = SpringUtil.getBean(PayRefundService.class); } - PayRefundDO payRefund = payRefundService.getRefundByNo(outRefundNo); + PayRefundDO payRefund = refundService.getRefundByNo(outRefundNo); // 支付退款单不存在, 返回退款失败状态 if (payRefund == null) { return PayRefundRespDTO.failureOf(String.valueOf(REFUND_NOT_FOUND), REFUND_NOT_FOUND.getMsg(), diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java index 3ea75ad09f..28f9849b5b 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java @@ -12,12 +12,14 @@ import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; public interface PayWalletService { /** - * 获取钱包信息,如果不存在创建钱包。由于用户注册时候不会创建钱包 + * 获取钱包信息 + * + * 如果不存在,则创建钱包。由于用户注册时候不会创建钱包 * * @param userId 用户编号 * @param userType 用户类型 */ - PayWalletDO getOrCreatePayWallet(Long userId, Integer userType); + PayWalletDO getOrCreateWallet(Long userId, Integer userType); /** * 钱包订单支付 @@ -29,6 +31,14 @@ public interface PayWalletService { */ PayWalletTransactionDO orderPay(Long userId, Integer userType, String outTradeNo, Integer price); + /** + * 钱包订单支付退款 + * + * @param outRefundNo 外部退款号 + * @param refundPrice 退款金额 + * @param reason 退款原因 + */ + PayWalletTransactionDO orderRefund(String outRefundNo, Integer refundPrice, String reason); /** * 扣减钱包余额 @@ -43,7 +53,6 @@ public interface PayWalletService { PayWalletTransactionDO reduceWalletBalance(Long userId, Integer userType, Long bizId, PayWalletBizTypeEnum bizType, Integer price); - /** * 增加钱包余额 * @@ -57,13 +66,4 @@ public interface PayWalletService { PayWalletTransactionDO addWalletBalance(Long userId, Integer userType, Long bizId, PayWalletBizTypeEnum bizType, Integer price); - /** - * 钱包订单支付退款 - * - * @param outRefundNo 外部退款号 - * @param refundPrice 退款金额 - * @param reason 退款原因 - */ - PayWalletTransactionDO orderRefund(String outRefundNo, Integer refundPrice, String reason); - } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java index ea607c0e8c..d017e53327 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java @@ -43,81 +43,124 @@ public class PayWalletServiceImpl implements PayWalletService { private static final String WALLET_REFUND_NO_PREFIX = "WR"; @Resource - private PayWalletMapper payWalletMapper; + private PayWalletMapper walletMapper; @Resource private PayNoRedisDAO noRedisDAO; @Resource - private PayWalletTransactionService payWalletTransactionService; + private PayWalletTransactionService walletTransactionService; @Resource @Lazy - private PayOrderService payOrderService; + private PayOrderService orderService; @Resource @Lazy - private PayRefundService payRefundService; + private PayRefundService refundService; @Override - public PayWalletDO getOrCreatePayWallet(Long userId, Integer userType) { - PayWalletDO payWalletDO = payWalletMapper.selectByUserIdAndType(userId, userType); - if (payWalletDO == null) { - payWalletDO = new PayWalletDO(); - payWalletDO.setUserId(userId); - payWalletDO.setUserType(userType); - payWalletDO.setBalance(0); - payWalletDO.setTotalExpense(0L); - payWalletDO.setTotalRecharge(0L); - payWalletDO.setCreateTime(LocalDateTime.now()); - payWalletMapper.insert(payWalletDO); + public PayWalletDO getOrCreateWallet(Long userId, Integer userType) { + PayWalletDO wallet = walletMapper.selectByUserIdAndType(userId, userType); + if (wallet == null) { + wallet = new PayWalletDO().setUserId(userId).setUserType(userType) + .setBalance(0).setTotalExpense(0L).setTotalRecharge(0L); + wallet.setCreateTime(LocalDateTime.now()); + walletMapper.insert(wallet); } - return payWalletDO; + return wallet; } - @Override @Transactional(rollbackFor = Exception.class) public PayWalletTransactionDO orderPay(Long userId, Integer userType, String outTradeNo, Integer price) { - // 判断支付交易拓展单是否存 - PayOrderExtensionDO orderExtension = payOrderService.getOrderExtensionByNo(outTradeNo); + // 1. 判断支付交易拓展单是否存 + PayOrderExtensionDO orderExtension = orderService.getOrderExtensionByNo(outTradeNo); if (orderExtension == null) { throw exception(ORDER_EXTENSION_NOT_FOUND); } + // 2. 扣减余额 return reduceWalletBalance(userId, userType, orderExtension.getOrderId(), PAYMENT, price); } + @Override + @Transactional(rollbackFor = Exception.class) + public PayWalletTransactionDO orderRefund(String outRefundNo, Integer refundPrice, String reason) { + // 1.1 判断退款单是否存在 + PayRefundDO payRefund = refundService.getRefundByNo(outRefundNo); + if (payRefund == null) { + throw exception(REFUND_NOT_FOUND); + } + // 1.2 校验是否可以退款 + Long walletId = validateWalletCanRefund(payRefund.getId(), payRefund.getChannelOrderNo(), refundPrice); + PayWalletDO wallet = walletMapper.selectById(walletId); + Assert.notNull(wallet, "钱包 {} 不存在", walletId); + // 2. 增加余额 + return addWalletBalance(wallet.getUserId(), wallet.getUserType(), payRefund.getId(), PAYMENT_REFUND, refundPrice); + } + + /** + * 校验是否能退款 + * + * @param refundId 支付退款单 id + * @param walletPayNo 钱包支付 no + */ + private Long validateWalletCanRefund(Long refundId, String walletPayNo, Integer refundPrice) { + // 1. 校验钱包支付交易存在 + PayWalletTransactionDO walletTransaction = walletTransactionService.getWalletTransactionByNo(walletPayNo); + if (walletTransaction == null) { + throw exception(WALLET_TRANSACTION_NOT_FOUND); + } + // 原来的支付金额 + // TODO @jason:应该允许多次退款哈; + int amount = - walletTransaction.getPrice(); + if (refundPrice != amount) { + throw exception(WALLET_REFUND_AMOUNT_ERROR); + } + PayWalletTransactionDO refundTransaction = walletTransactionService.getWalletTransaction( + String.valueOf(refundId), PAYMENT_REFUND); + if (refundTransaction != null) { + throw exception(WALLET_REFUND_EXIST); + } + return walletTransaction.getWalletId(); + } + @Override public PayWalletTransactionDO reduceWalletBalance(Long userId, Integer userType, Long bizId, PayWalletBizTypeEnum bizType, Integer price) { // 1.1 获取钱包 - PayWalletDO payWallet = getOrCreatePayWallet(userId, userType); + PayWalletDO payWallet = getOrCreateWallet(userId, userType); // 1.2 判断余额是否足够 int afterBalance = payWallet.getBalance() - price; if (afterBalance < 0) { throw exception(WALLET_BALANCE_NOT_ENOUGH); } + // TODO jason:建议基于 where price >= 来做哈;然后抛出 WALLET_BALANCE_NOT_ENOUGH // 2.1 扣除余额 - int number = payWalletMapper.updateWhenDecBalance(bizType,payWallet.getBalance(), payWallet.getTotalRecharge(), - payWallet.getTotalExpense(), price, payWallet.getId()); + int number = walletMapper.updateWhenDecBalance(bizType, payWallet.getBalance(), + payWallet.getTotalRecharge(), payWallet.getTotalExpense(), price, payWallet.getId()); if (number == 0) { throw exception(TOO_MANY_REQUESTS); } + // 2.2 生成钱包流水 + // TODO @jason:walletNo 交给 payWalletTransactionService 自己生成哈; String walletNo = generateWalletNo(bizType); PayWalletTransactionDO walletTransaction = new PayWalletTransactionDO().setWalletId(payWallet.getId()) .setNo(walletNo).setPrice(-price).setBalance(afterBalance) .setBizId(String.valueOf(bizId)).setBizType(bizType.getType()).setTitle(bizType.getDescription()); - payWalletTransactionService.createWalletTransaction(walletTransaction); + // TODO @jason:是不是可以 createWalletTransaction 搞个 bo 参数,然后 PayWalletTransactionDO 交回给 walletTransactionService 更好;然后把参数简化下 + walletTransactionService.createWalletTransaction(walletTransaction); return walletTransaction; } @Override - public PayWalletTransactionDO addWalletBalance(Long userId, Integer userType, Long bizId, - PayWalletBizTypeEnum bizType, Integer price) { + public PayWalletTransactionDO addWalletBalance(Long userId, Integer userType, + Long bizId, PayWalletBizTypeEnum bizType, Integer price) { // 1.1 获取钱包 - PayWalletDO payWallet = getOrCreatePayWallet(userId, userType); + PayWalletDO payWallet = getOrCreateWallet(userId, userType); // 2.1 增加余额 - int number = payWalletMapper.updateWhenIncBalance(bizType, payWallet.getBalance(), payWallet.getTotalRecharge(), + // TODO @jason:类似上面的思路哈; + int number = walletMapper.updateWhenIncBalance(bizType, payWallet.getBalance(), payWallet.getTotalRecharge(), payWallet.getTotalExpense(), price, payWallet.getId()); if (number == 0) { throw exception(TOO_MANY_REQUESTS); @@ -129,63 +172,23 @@ public class PayWalletServiceImpl implements PayWalletService { .setNo(walletNo).setPrice(price).setBalance(payWallet.getBalance()+price) .setBizId(String.valueOf(bizId)).setBizType(bizType.getType()) .setTitle(bizType.getDescription()); - payWalletTransactionService.createWalletTransaction(newWalletTransaction); + walletTransactionService.createWalletTransaction(newWalletTransaction); return newWalletTransaction; } private String generateWalletNo(PayWalletBizTypeEnum bizType) { + // TODO @jason:对于余额来说,是不是直接 W+序号就行了,它其实不关注业务;;;不然就耦合啦 String no = ""; switch(bizType){ - case PAYMENT : + case PAYMENT: no = noRedisDAO.generate(WALLET_PAY_NO_PREFIX); break; - case PAYMENT_REFUND : + case PAYMENT_REFUND: no = noRedisDAO.generate(WALLET_REFUND_NO_PREFIX); break; default : - // TODO 待增加 } return no; } - @Override - @Transactional(rollbackFor = Exception.class) - public PayWalletTransactionDO orderRefund(String outRefundNo, Integer refundPrice, String reason) { - // 1.1 判断退款单是否存在 - PayRefundDO payRefund = payRefundService.getRefundByNo(outRefundNo); - if (payRefund == null) { - throw exception(REFUND_NOT_FOUND); - } - // 1.2 校验是否可以退款 - Long walletId = validateWalletCanRefund(payRefund.getId(), payRefund.getChannelOrderNo(), refundPrice); - - PayWalletDO payWallet = payWalletMapper.selectById(walletId); - Assert.notNull(payWallet, "钱包 {} 不存在", walletId); - return addWalletBalance(payWallet.getUserId(), payWallet.getUserType(),payRefund.getId(), PAYMENT_REFUND, refundPrice); - } - - /** - * 校验是否能退款 - * - * @param refundId 支付退款单 id - * @param walletPayNo 钱包支付 no - */ - private Long validateWalletCanRefund(Long refundId, String walletPayNo, Integer refundPrice) { - // 查询钱包支付交易 - PayWalletTransactionDO payWalletTransaction = payWalletTransactionService.getWalletTransactionByNo(walletPayNo); - if (payWalletTransaction == null) { - throw exception(WALLET_TRANSACTION_NOT_FOUND); - } - // 原来的支付金额 - int amount = - payWalletTransaction.getPrice(); - if (refundPrice != amount) { - throw exception(WALLET_REFUND_AMOUNT_ERROR); - } - PayWalletTransactionDO refundTransaction = payWalletTransactionService.getWalletTransaction( - String.valueOf(refundId), PAYMENT_REFUND); - if (refundTransaction != null) { - throw exception(WALLET_REFUND_EXIST); - } - return payWalletTransaction.getWalletId(); - } } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java index 971f594167..05a2a48000 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java @@ -28,7 +28,7 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ @Override public PageResult getWalletTransactionPage(Long userId, Integer userType, AppPayWalletTransactionPageReqVO pageVO) { - PayWalletDO wallet = payWalletService.getOrCreatePayWallet(userId, userType); + PayWalletDO wallet = payWalletService.getOrCreateWallet(userId, userType); return payWalletTransactionMapper.selectPage(wallet.getId(), pageVO); } From 4b43304c765190a0cae4fc6285e3ec5b69abb8c3 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 22:51:05 +0800 Subject: [PATCH 34/48] =?UTF-8?q?trade:=20=E4=BC=98=E5=8C=96=E5=88=86?= =?UTF-8?q?=E9=94=80=E7=94=A8=E6=88=B7=E7=BB=91=E5=AE=9A=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=BC=96=E5=8F=B7=E3=80=81=E7=BB=91=E5=AE=9A=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/brokerage.sql | 6 +++--- .../admin/brokerage/user/BrokerageUserController.java | 2 +- .../admin/brokerage/user/vo/BrokerageUserBaseVO.java | 4 ++-- .../admin/brokerage/user/vo/BrokerageUserPageReqVO.java | 2 +- .../dal/dataobject/brokerage/user/BrokerageUserDO.java | 9 +++++---- .../dal/mysql/brokerage/user/BrokerageUserMapper.java | 2 +- .../brokerage/record/BrokerageRecordServiceImpl.java | 4 ++-- .../service/brokerage/user/BrokerageUserService.java | 4 ++-- .../service/brokerage/user/BrokerageUserServiceImpl.java | 6 +++--- .../brokerage/user/BrokerageUserServiceImplTest.java | 6 +++--- .../src/test/resources/sql/create_tables.sql | 4 ++-- 11 files changed, 25 insertions(+), 24 deletions(-) diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index 53b9dc04e8..08b05da146 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -24,8 +24,8 @@ create table trade_config create table trade_brokerage_user ( id bigint auto_increment comment '用户编号' primary key, - brokerage_user_id bigint null comment '推广员编号', - brokerage_bind_time datetime null comment '推广员绑定时间', + bind_user_id bigint null comment '推广员编号', + bind_user_time datetime null comment '推广员绑定时间', brokerage_enabled bit default 1 not null comment '是否成为推广员', brokerage_time datetime null comment '成为分销员时间', brokerage_price int default 0 not null comment '可用佣金', @@ -38,7 +38,7 @@ create table trade_brokerage_user tenant_id bigint default 0 not null comment '租户编号' ) comment '分销用户'; -create index idx_invite_user_id on trade_brokerage_user (brokerage_user_id) comment '推广员编号'; +create index idx_invite_user_id on trade_brokerage_user (bind_user_id) comment '推广员编号'; create index idx_agent on trade_brokerage_user (brokerage_enabled) comment '是否成为推广员'; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java index 1e1ad3acd4..0992f52e02 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java @@ -94,7 +94,7 @@ public class BrokerageUserController { // 合计推广用户数量 Map brokerageUserCountMap = convertMap(userIds, userId -> userId, - userId -> brokerageUserService.getCountByBrokerageUserId(userId)); + userId -> brokerageUserService.getCountByBindUserId(userId)); // todo 合计提现 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java index 41ddd454cf..5da0b5d6b5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java @@ -18,11 +18,11 @@ public class BrokerageUserBaseVO { @Schema(description = "推广员编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4587") @NotNull(message = "推广员编号不能为空") - private Long brokerageUserId; + private Long bindUserId; @Schema(description = "推广员绑定时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime brokerageBindTime; + private LocalDateTime bindUserTime; @Schema(description = "推广资格", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "推广资格不能为空") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java index 2b99d686ed..e6908e8aa0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java @@ -18,7 +18,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ public class BrokerageUserPageReqVO extends PageParam { @Schema(description = "推广员编号", example = "4587") - private Long brokerageUserId; + private Long bindUserId; @Schema(description = "推广资格") private Boolean brokerageEnabled; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java index 4b85dc3d0e..09ad6d72d2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java @@ -26,21 +26,22 @@ public class BrokerageUserDO extends BaseDO { /** * 用户编号 + *

+ * 对应 MemberUserDO 的 id 字段 */ @TableId private Long id; - // TODO @疯狂:貌似改成 bindUserId,更明确? /** * 推广员编号 - * + *

* 关联 MemberUserDO 的 id 字段 */ - private Long brokerageUserId; + private Long bindUserId; /** * 推广员绑定时间 */ - private LocalDateTime brokerageBindTime; + private LocalDateTime bindUserTime; /** * 推广资格 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java index d5cc39523c..2d536bb888 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java @@ -19,7 +19,7 @@ public interface BrokerageUserMapper extends BaseMapperX { default PageResult selectPage(BrokerageUserPageReqVO reqVO) { return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(BrokerageUserDO::getBrokerageUserId, reqVO.getBrokerageUserId()) + .eqIfPresent(BrokerageUserDO::getBindUserId, reqVO.getBindUserId()) .eqIfPresent(BrokerageUserDO::getBrokerageEnabled, reqVO.getBrokerageEnabled()) .betweenIfPresent(BrokerageUserDO::getCreateTime, reqVO.getCreateTime()) .orderByDesc(BrokerageUserDO::getId)); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java index ae9f1ff883..1a0cf4fe7f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java @@ -75,10 +75,10 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqBO::getFirstBrokeragePrice, bizType); // 2.1 获得二级推广员 - if (firstUser.getBrokerageUserId() == null) { + if (firstUser.getBindUserId() == null) { return; } - BrokerageUserDO secondUser = brokerageUserService.getBrokerageUser(firstUser.getBrokerageUserId()); + BrokerageUserDO secondUser = brokerageUserService.getBrokerageUser(firstUser.getBindUserId()); if (secondUser == null || !BooleanUtil.isTrue(secondUser.getBrokerageEnabled())) { return; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java index 362743b653..5ba7eb4c1b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java @@ -89,8 +89,8 @@ public interface BrokerageUserService { /** * 获得推广用户数量(一级) * - * @param brokerageUserId 推广员编号 + * @param bindUserId 绑定的推广员编号 * @return 推广用户数量 */ - Long getCountByBrokerageUserId(Long brokerageUserId); + Long getCountByBindUserId(Long bindUserId); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java index 3a4fb475f6..a09192ed6d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java @@ -68,7 +68,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { public BrokerageUserDO getBindBrokerageUser(Long id) { return Optional.ofNullable(id) .map(this::getBrokerageUser) - .map(BrokerageUserDO::getBrokerageUserId) + .map(BrokerageUserDO::getBindUserId) .map(this::getBrokerageUser) .orElse(null); } @@ -101,8 +101,8 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } @Override - public Long getCountByBrokerageUserId(Long brokerageUserId) { - return brokerageUserMapper.selectCount(BrokerageUserDO::getBrokerageUserId, brokerageUserId); + public Long getCountByBindUserId(Long bindUserId) { + return brokerageUserMapper.selectCount(BrokerageUserDO::getBindUserId, bindUserId); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java index 6950f84e46..1c505e1b49 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java @@ -37,20 +37,20 @@ public class BrokerageUserServiceImplTest extends BaseDbUnitTest { public void testGetBrokerageUserPage() { // mock 数据 BrokerageUserDO dbBrokerageUser = randomPojo(BrokerageUserDO.class, o -> { // 等会查询到 - o.setBrokerageUserId(null); + o.setBindUserId(null); o.setBrokerageEnabled(null); o.setCreateTime(null); }); brokerageUserMapper.insert(dbBrokerageUser); // 测试 brokerageUserId 不匹配 - brokerageUserMapper.insert(cloneIgnoreId(dbBrokerageUser, o -> o.setBrokerageUserId(null))); + brokerageUserMapper.insert(cloneIgnoreId(dbBrokerageUser, o -> o.setBindUserId(null))); // 测试 brokerageEnabled 不匹配 brokerageUserMapper.insert(cloneIgnoreId(dbBrokerageUser, o -> o.setBrokerageEnabled(null))); // 测试 createTime 不匹配 brokerageUserMapper.insert(cloneIgnoreId(dbBrokerageUser, o -> o.setCreateTime(null))); // 准备参数 BrokerageUserPageReqVO reqVO = new BrokerageUserPageReqVO(); - reqVO.setBrokerageUserId(null); + reqVO.setBindUserId(null); reqVO.setBrokerageEnabled(null); reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql index 02045d2c29..eafad666f9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql @@ -129,8 +129,8 @@ CREATE TABLE IF NOT EXISTS "trade_after_sale_log" ( CREATE TABLE IF NOT EXISTS "trade_brokerage_user" ( "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "brokerage_user_id" bigint NOT NULL, - "brokerage_bind_time" varchar, + "bind_user_id" bigint NOT NULL, + "bind_user_time" varchar, "brokerage_enabled" bit NOT NULL, "brokerage_time" varchar, "brokerage_price" int NOT NULL, From 1ead3685958846d86afe620f547932bececdc094 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 23:10:04 +0800 Subject: [PATCH 35/48] =?UTF-8?q?trade:=20=E4=BC=98=E5=8C=96=E5=88=86?= =?UTF-8?q?=E9=94=80=E7=94=A8=E6=88=B7=E4=BD=A3=E9=87=91=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/brokerage.sql | 26 ++++++------ .../trade/enums/ErrorCodeConstants.java | 2 +- .../user/vo/BrokerageUserBaseVO.java | 4 +- .../brokerage/AppBrokerageUserController.java | 24 +++++------ .../AppBrokerageUserChildSummaryRespVO.java | 2 +- .../user/AppBrokerageUserMySummaryRespVO.java | 8 ++-- .../AppBrokerageUserRankByPriceRespVO.java | 2 +- .../vo/user/AppBrokerageUserRespVO.java | 4 +- .../record/BrokerageRecordConvert.java | 2 +- .../convert/order/TradeOrderConvert.java | 4 +- .../brokerage/user/BrokerageUserDO.java | 5 +-- .../brokerage/user/BrokerageUserMapper.java | 24 +++++------ .../brokerage/bo/BrokerageAddReqBO.java | 4 +- .../record/BrokerageRecordServiceImpl.java | 42 +++++++++---------- .../brokerage/user/BrokerageUserService.java | 18 ++++---- .../user/BrokerageUserServiceImpl.java | 30 ++++++------- .../BrokerageRecordServiceImplTest.java | 22 +++++----- .../src/test/resources/sql/create_tables.sql | 26 ++++++------ 18 files changed, 124 insertions(+), 125 deletions(-) diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index 08b05da146..a84d80051f 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -23,19 +23,19 @@ create table trade_config -- 增加分销用户扩展表 create table trade_brokerage_user ( - id bigint auto_increment comment '用户编号' primary key, - bind_user_id bigint null comment '推广员编号', - bind_user_time datetime null comment '推广员绑定时间', - brokerage_enabled bit default 1 not null comment '是否成为推广员', - brokerage_time datetime null comment '成为分销员时间', - brokerage_price int default 0 not null comment '可用佣金', - frozen_brokerage_price int default 0 not null comment '冻结佣金', - creator varchar(64) collate utf8mb4_unicode_ci default '' null comment '创建者', - create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', - updater varchar(64) collate utf8mb4_unicode_ci default '' null comment '更新者', - update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', - deleted bit default b'0' not null comment '是否删除', - tenant_id bigint default 0 not null comment '租户编号' + id bigint auto_increment comment '用户编号' primary key, + bind_user_id bigint null comment '推广员编号', + bind_user_time datetime null comment '推广员绑定时间', + brokerage_enabled bit default 1 not null comment '是否成为推广员', + brokerage_time datetime null comment '成为分销员时间', + price int default 0 not null comment '可用佣金', + frozen_price int default 0 not null comment '冻结佣金', + creator varchar(64) collate utf8mb4_unicode_ci default '' null comment '创建者', + create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', + updater varchar(64) collate utf8mb4_unicode_ci default '' null comment '更新者', + update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', + deleted bit default b'0' not null comment '是否删除', + tenant_id bigint default 0 not null comment '租户编号' ) comment '分销用户'; create index idx_invite_user_id on trade_brokerage_user (bind_user_id) comment '推广员编号'; diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 5ddff9b119..fa5be50b7d 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -77,6 +77,6 @@ public interface ErrorCodeConstants { // ========== 分销用户 模块 1011007000 ========== ErrorCode BROKERAGE_USER_NOT_EXISTS = new ErrorCode(1011007000, "分销用户不存在"); - ErrorCode USER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH = new ErrorCode(1011007001, "用户冻结佣金({})数量不足"); + ErrorCode BROKERAGE_USER_FROZEN_PRICE_NOT_ENOUGH = new ErrorCode(1011007001, "用户冻结佣金({})数量不足"); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java index 5da0b5d6b5..34f792b724 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java @@ -34,10 +34,10 @@ public class BrokerageUserBaseVO { @Schema(description = "可用佣金", requiredMode = Schema.RequiredMode.REQUIRED, example = "11089") @NotNull(message = "可用佣金不能为空") - private Integer brokeragePrice; + private Integer price; @Schema(description = "冻结佣金", requiredMode = Schema.RequiredMode.REQUIRED, example = "30916") @NotNull(message = "冻结佣金不能为空") - private Integer frozenBrokeragePrice; + private Integer frozenPrice; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index 1b760be059..ecbb7de456 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -34,8 +34,8 @@ public class AppBrokerageUserController { @PreAuthenticated public CommonResult getBrokerageUser() { AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO() - .setBrokeragePrice(2000) - .setFrozenBrokeragePrice(3000); + .setPrice(2000) + .setFrozenPrice(3000); return success(respVO); } @@ -45,10 +45,10 @@ public class AppBrokerageUserController { @PreAuthenticated public CommonResult getBrokerageUserSummary() { AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO() - .setYesterdayBrokeragePrice(1) - .setBrokeragePrice(2) - .setFrozenBrokeragePrice(3) - .setWithdrawBrokeragePrice(4) + .setYesterdayPrice(1) + .setPrice(2) + .setFrozenPrice(3) + .setWithdrawPrice(4) .setFirstBrokerageUserCount(166) .setSecondBrokerageUserCount(233); return success(respVO); @@ -81,16 +81,16 @@ public class AppBrokerageUserController { public CommonResult> getBrokerageUserChildSummaryPageByPrice(AppBrokerageUserRankPageReqVO pageReqVO) { AppBrokerageUserRankByPriceRespVO vo1 = new AppBrokerageUserRankByPriceRespVO() .setId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(10); + .setPrice(10); AppBrokerageUserRankByPriceRespVO vo2 = new AppBrokerageUserRankByPriceRespVO() .setId(2L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(6); + .setPrice(6); AppBrokerageUserRankByPriceRespVO vo3 = new AppBrokerageUserRankByPriceRespVO() .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(4); + .setPrice(4); AppBrokerageUserRankByPriceRespVO vo4 = new AppBrokerageUserRankByPriceRespVO() .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(4); + .setPrice(4); return success(new PageResult<>(asList(vo1, vo2, vo3, vo4), 10L)); } @@ -102,11 +102,11 @@ public class AppBrokerageUserController { AppBrokerageUserChildSummaryPageReqVO pageReqVO) { AppBrokerageUserChildSummaryRespVO vo1 = new AppBrokerageUserChildSummaryRespVO() .setId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(10).setBrokeragePrice(20).setBrokerageOrderCount(30) + .setPrice(10).setPrice(20).setBrokerageOrderCount(30) .setBrokerageTime(LocalDateTime.now()); AppBrokerageUserChildSummaryRespVO vo2 = new AppBrokerageUserChildSummaryRespVO() .setId(1L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(20).setBrokeragePrice(30).setBrokerageOrderCount(40) + .setPrice(20).setPrice(30).setBrokerageOrderCount(40) .setBrokerageTime(LocalDateTime.now()); return success(new PageResult<>(asList(vo1, vo2), 10L)); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java index 1beb1b5e2a..55d88d74fb 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java @@ -19,7 +19,7 @@ public class AppBrokerageUserChildSummaryRespVO { private String avatar; @Schema(description = "佣金金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Integer brokeragePrice; + private Integer price; @Schema(description = "分销订单数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "20") private Integer brokerageOrderCount; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java index 64fafe3294..33a089cc61 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java @@ -8,16 +8,16 @@ import lombok.Data; public class AppBrokerageUserMySummaryRespVO { @Schema(description = "昨天的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Integer yesterdayBrokeragePrice; + private Integer yesterdayPrice; @Schema(description = "提现的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Integer withdrawBrokeragePrice; + private Integer withdrawPrice; @Schema(description = "可用的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2408") - private Integer brokeragePrice; + private Integer price; @Schema(description = "冻结的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "234") - private Integer frozenBrokeragePrice; + private Integer frozenPrice; @Schema(description = "分销用户数量(一级)", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") private Integer firstBrokerageUserCount; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java index 91345ea789..d80fb67a2b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java @@ -17,6 +17,6 @@ public class AppBrokerageUserRankByPriceRespVO { private String avatar; @Schema(description = "佣金金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Integer brokeragePrice; + private Integer price; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java index 04f1a72780..9db6e0cc2f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java @@ -8,9 +8,9 @@ import lombok.Data; public class AppBrokerageUserRespVO { @Schema(description = "可用的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2408") - private Integer brokeragePrice; + private Integer price; @Schema(description = "冻结的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "234") - private Integer frozenBrokeragePrice; + private Integer frozenPrice; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java index d619c69264..9307a4f558 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java @@ -43,7 +43,7 @@ public interface BrokerageRecordConvert { .setBizType(bizType.getType()) .setBizId(bizId) .setPrice(brokerage) - .setTotalPrice(user.getBrokeragePrice()) + .setTotalPrice(user.getPrice()) .setTitle(title) .setDescription(StrUtil.format(bizType.getDescription(), String.valueOf(brokerage / 100.0))) .setStatus(status) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index 27854def6e..8588fb9729 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -278,7 +278,7 @@ public interface TradeOrderConvert { default BrokerageAddReqBO convert(TradeOrderItemDO item, ProductSkuRespDTO sku) { return new BrokerageAddReqBO().setBizId(String.valueOf(item.getId())) .setBasePrice(item.getPayPrice() * item.getCount()) - .setFirstBrokeragePrice(sku.getSubCommissionFirstPrice()) - .setSecondBrokeragePrice(sku.getSubCommissionSecondPrice()); + .setFirstFixedPrice(sku.getSubCommissionFirstPrice()) + .setSecondFixedPrice(sku.getSubCommissionSecondPrice()); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java index 09ad6d72d2..1773e41e7b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java @@ -8,7 +8,6 @@ import lombok.*; import java.time.LocalDateTime; -// TODO @疯狂:因为独立了表,是不是可以把字段的 brokerage 去掉了哈? /** * 分销用户 DO * @@ -55,10 +54,10 @@ public class BrokerageUserDO extends BaseDO { /** * 可用佣金 */ - private Integer brokeragePrice; + private Integer price; /** * 冻结佣金 */ - private Integer frozenBrokeragePrice; + private Integer frozenPrice; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java index 2d536bb888..2f7d1d19c6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java @@ -31,10 +31,10 @@ public interface BrokerageUserMapper extends BaseMapperX { * @param id 用户编号 * @param incrCount 增加佣金(正数) */ - default void updateBrokeragePriceIncr(Long id, Integer incrCount) { + default void updatePriceIncr(Long id, Integer incrCount) { Assert.isTrue(incrCount > 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" brokerage_price = brokerage_price + " + incrCount) + .setSql(" price = price + " + incrCount) .eq(BrokerageUserDO::getId, id); update(null, lambdaUpdateWrapper); } @@ -46,10 +46,10 @@ public interface BrokerageUserMapper extends BaseMapperX { * @param id 用户编号 * @param incrCount 增加佣金(负数) */ - default void updateBrokeragePriceDecr(Long id, Integer incrCount) { + default void updatePriceDecr(Long id, Integer incrCount) { Assert.isTrue(incrCount < 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" brokerage_price = brokerage_price + " + incrCount) // 负数,所以使用 + 号 + .setSql(" price = price + " + incrCount) // 负数,所以使用 + 号 .eq(BrokerageUserDO::getId, id); update(null, lambdaUpdateWrapper); } @@ -60,10 +60,10 @@ public interface BrokerageUserMapper extends BaseMapperX { * @param id 用户编号 * @param incrCount 增加冻结佣金(正数) */ - default void updateFrozenBrokeragePriceIncr(Long id, Integer incrCount) { + default void updateFrozenPriceIncr(Long id, Integer incrCount) { Assert.isTrue(incrCount > 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) + .setSql(" frozen_price = frozen_price + " + incrCount) .eq(BrokerageUserDO::getId, id); update(null, lambdaUpdateWrapper); } @@ -75,10 +75,10 @@ public interface BrokerageUserMapper extends BaseMapperX { * @param id 用户编号 * @param incrCount 减少冻结佣金(负数) */ - default void updateFrozenBrokeragePriceDecr(Long id, Integer incrCount) { + default void updateFrozenPriceDecr(Long id, Integer incrCount) { Assert.isTrue(incrCount < 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) // 负数,所以使用 + 号 + .setSql(" frozen_price = frozen_price + " + incrCount) // 负数,所以使用 + 号 .eq(BrokerageUserDO::getId, id); update(null, lambdaUpdateWrapper); } @@ -90,13 +90,13 @@ public interface BrokerageUserMapper extends BaseMapperX { * @param incrCount 减少冻结佣金(负数) * @return 更新条数 */ - default int updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, Integer incrCount) { + default int updateFrozenPriceDecrAndPriceIncr(Long id, Integer incrCount) { Assert.isTrue(incrCount < 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount + // 负数,所以使用 + 号 - ", brokerage_price = brokerage_price + " + -incrCount) // 负数,所以使用 - 号 + .setSql(" frozen_price = frozen_price + " + incrCount + // 负数,所以使用 + 号 + ", price = price + " + -incrCount) // 负数,所以使用 - 号 .eq(BrokerageUserDO::getId, id) - .ge(BrokerageUserDO::getFrozenBrokeragePrice, -incrCount); // cas 逻辑 + .ge(BrokerageUserDO::getFrozenPrice, -incrCount); // cas 逻辑 return update(null, lambdaUpdateWrapper); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java index 510960beb5..07e07817ef 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java @@ -28,10 +28,10 @@ public class BrokerageAddReqBO { /** * 一级佣金(固定) */ - private Integer firstBrokeragePrice; + private Integer firstFixedPrice; /** * 二级佣金(固定) */ - private Integer secondBrokeragePrice; + private Integer secondFixedPrice; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java index 1a0cf4fe7f..960b45ae54 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java @@ -72,7 +72,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { return; } // 1.2 计算一级分佣 - addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqBO::getFirstBrokeragePrice, bizType); + addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqBO::getFirstFixedPrice, bizType); // 2.1 获得二级推广员 if (firstUser.getBindUserId() == null) { @@ -83,7 +83,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { return; } // 2.2 计算二级分佣 - addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqBO::getSecondBrokeragePrice, bizType); + addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqBO::getSecondFixedPrice, bizType); } @Override @@ -105,24 +105,24 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { // 2. 更新用户的佣金 if (BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus().equals(record.getStatus())) { - brokerageUserService.updateUserFrozenBrokeragePrice(userId, -record.getPrice()); + brokerageUserService.updateUserFrozenPrice(userId, -record.getPrice()); } else if (BrokerageRecordStatusEnum.SETTLEMENT.getStatus().equals(record.getStatus())) { - brokerageUserService.updateUserBrokeragePrice(userId, -record.getPrice()); + brokerageUserService.updateUserPrice(userId, -record.getPrice()); } } /** * 计算佣金 * - * @param basePrice 佣金基数 - * @param percent 佣金比例 - * @param fixedBrokeragePrice 固定佣金 + * @param basePrice 佣金基数 + * @param percent 佣金比例 + * @param fixedPrice 固定佣金 * @return 佣金 */ - int calculateBrokeragePrice(Integer basePrice, Integer percent, Integer fixedBrokeragePrice) { + int calculatePrice(Integer basePrice, Integer percent, Integer fixedPrice) { // 1. 优先使用固定佣金 - if (fixedBrokeragePrice != null && fixedBrokeragePrice > 0) { - return ObjectUtil.defaultIfNull(fixedBrokeragePrice, 0); + if (fixedPrice != null && fixedPrice > 0) { + return ObjectUtil.defaultIfNull(fixedPrice, 0); } // 2. 根据比例计算佣金 if (basePrice != null && basePrice > 0 && percent != null && percent > 0) { @@ -134,15 +134,15 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { /** * 增加用户佣金 * - * @param user 用户 - * @param list 佣金增加参数列表 - * @param brokerageFrozenDays 冻结天数 - * @param brokeragePercent 佣金比例 - * @param FixedBrokeragePriceFun 固定佣金 - * @param bizType 业务类型 + * @param user 用户 + * @param list 佣金增加参数列表 + * @param brokerageFrozenDays 冻结天数 + * @param brokeragePercent 佣金比例 + * @param fixedPriceFun 固定佣金 + * @param bizType 业务类型 */ private void addBrokerage(BrokerageUserDO user, List list, Integer brokerageFrozenDays, - Integer brokeragePercent, Function FixedBrokeragePriceFun, + Integer brokeragePercent, Function fixedPriceFun, BrokerageRecordBizTypeEnum bizType) { // 1.1 处理冻结时间 LocalDateTime unfreezeTime = null; @@ -153,7 +153,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { int totalBrokerage = 0; List records = new ArrayList<>(); for (BrokerageAddReqBO item : list) { - int brokeragePerItem = calculateBrokeragePrice(item.getBasePrice(), brokeragePercent, FixedBrokeragePriceFun.apply(item)); + int brokeragePerItem = calculatePrice(item.getBasePrice(), brokeragePercent, fixedPriceFun.apply(item)); if (brokeragePerItem <= 0) { continue; } @@ -169,9 +169,9 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { // 2. 更新用户佣金 if (brokerageFrozenDays != null && brokerageFrozenDays > 0) { // 更新用户冻结佣金 - brokerageUserService.updateUserFrozenBrokeragePrice(user.getId(), totalBrokerage); + brokerageUserService.updateUserFrozenPrice(user.getId(), totalBrokerage); } else { // 更新用户可用佣金 - brokerageUserService.updateUserBrokeragePrice(user.getId(), totalBrokerage); + brokerageUserService.updateUserPrice(user.getId(), totalBrokerage); } } @@ -218,7 +218,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { } // 更新用户冻结佣金 - brokerageUserService.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(record.getUserId(), -record.getPrice()); + brokerageUserService.updateFrozenPriceDecrAndPriceIncr(record.getUserId(), -record.getPrice()); log.info("[unfreezeRecord][record({}) 更新为已结算成功]", record.getId()); return true; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java index 5ba7eb4c1b..c26cfb6e3d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java @@ -65,26 +65,26 @@ public interface BrokerageUserService { /** * 更新用户佣金 * - * @param id 用户编号 - * @param brokeragePrice 用户可用佣金 + * @param id 用户编号 + * @param price 用户可用佣金 */ - void updateUserBrokeragePrice(Long id, Integer brokeragePrice); + void updateUserPrice(Long id, Integer price); /** * 更新用户冻结佣金 * - * @param id 用户编号 - * @param frozenBrokeragePrice 用户冻结佣金 + * @param id 用户编号 + * @param frozenPrice 用户冻结佣金 */ - void updateUserFrozenBrokeragePrice(Long id, Integer frozenBrokeragePrice); + void updateUserFrozenPrice(Long id, Integer frozenPrice); /** * 更新用户冻结佣金(减少), 更新用户佣金(增加) * - * @param id 用户编号 - * @param frozenBrokeragePrice 减少冻结佣金(负数) + * @param id 用户编号 + * @param frozenPrice 减少冻结佣金(负数) */ - void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, Integer frozenBrokeragePrice); + void updateFrozenPriceDecrAndPriceIncr(Long id, Integer frozenPrice); /** * 获得推广用户数量(一级) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java index a09192ed6d..33f81602da 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java @@ -14,8 +14,8 @@ import java.util.List; import java.util.Optional; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_USER_FROZEN_PRICE_NOT_ENOUGH; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_USER_NOT_EXISTS; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.USER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH; /** * 分销用户 Service 实现类 @@ -74,29 +74,29 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } @Override - public void updateUserBrokeragePrice(Long id, Integer brokeragePrice) { - if (brokeragePrice > 0) { - brokerageUserMapper.updateBrokeragePriceIncr(id, brokeragePrice); - } else if (brokeragePrice < 0) { - brokerageUserMapper.updateBrokeragePriceDecr(id, brokeragePrice); + public void updateUserPrice(Long id, Integer price) { + if (price > 0) { + brokerageUserMapper.updatePriceIncr(id, price); + } else if (price < 0) { + brokerageUserMapper.updatePriceDecr(id, price); } } @Override - public void updateUserFrozenBrokeragePrice(Long id, Integer frozenBrokeragePrice) { - if (frozenBrokeragePrice > 0) { - brokerageUserMapper.updateFrozenBrokeragePriceIncr(id, frozenBrokeragePrice); - } else if (frozenBrokeragePrice < 0) { - brokerageUserMapper.updateFrozenBrokeragePriceDecr(id, frozenBrokeragePrice); + public void updateUserFrozenPrice(Long id, Integer frozenPrice) { + if (frozenPrice > 0) { + brokerageUserMapper.updateFrozenPriceIncr(id, frozenPrice); + } else if (frozenPrice < 0) { + brokerageUserMapper.updateFrozenPriceDecr(id, frozenPrice); } } @Override - public void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, Integer frozenBrokeragePrice) { - Assert.isTrue(frozenBrokeragePrice < 0); - int updateRows = brokerageUserMapper.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(id, frozenBrokeragePrice); + public void updateFrozenPriceDecrAndPriceIncr(Long id, Integer frozenPrice) { + Assert.isTrue(frozenPrice < 0); + int updateRows = brokerageUserMapper.updateFrozenPriceDecrAndPriceIncr(id, frozenPrice); if (updateRows == 0) { - throw exception(USER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH); + throw exception(BROKERAGE_USER_FROZEN_PRICE_NOT_ENOUGH); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImplTest.java index 00ff04d6da..abf2b37c19 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImplTest.java @@ -79,38 +79,38 @@ public class BrokerageRecordServiceImplTest extends BaseDbUnitTest { } @Test - public void testCalculateBrokeragePrice_useFixedBrokeragePrice() { + public void testCalculatePrice_useFixedPrice() { // mock 数据 Integer payPrice = randomInteger(); Integer percent = randomInt(1, 101); - Integer fixedBrokeragePrice = randomInt(); + Integer fixedPrice = randomInt(); // 调用 - int brokerage = brokerageRecordService.calculateBrokeragePrice(payPrice, percent, fixedBrokeragePrice); + int brokerage = brokerageRecordService.calculatePrice(payPrice, percent, fixedPrice); // 断言 - assertEquals(brokerage, fixedBrokeragePrice); + assertEquals(brokerage, fixedPrice); } @Test - public void testCalculateBrokeragePrice_usePercent() { + public void testCalculatePrice_usePercent() { // mock 数据 Integer payPrice = randomInteger(); Integer percent = randomInt(1, 101); - Integer skuBrokeragePrice = randomEle(new Integer[]{0, null}); - System.out.println("skuBrokeragePrice=" + skuBrokeragePrice); + Integer fixedPrice = randomEle(new Integer[]{0, null}); + System.out.println("fixedPrice=" + fixedPrice); // 调用 - int brokerage = brokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); + int brokerage = brokerageRecordService.calculatePrice(payPrice, percent, fixedPrice); // 断言 assertEquals(brokerage, NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue()); } @Test - public void testCalculateBrokeragePrice_equalsZero() { + public void testCalculatePrice_equalsZero() { // mock 数据 Integer payPrice = null; Integer percent = null; - Integer skuBrokeragePrice = null; + Integer fixedPrice = null; // 调用 - int brokerage = brokerageRecordService.calculateBrokeragePrice(payPrice, percent, skuBrokeragePrice); + int brokerage = brokerageRecordService.calculatePrice(payPrice, percent, fixedPrice); // 断言 assertEquals(brokerage, 0); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql index eafad666f9..4c0e0fcea3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql @@ -128,19 +128,19 @@ CREATE TABLE IF NOT EXISTS "trade_after_sale_log" ( CREATE TABLE IF NOT EXISTS "trade_brokerage_user" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "bind_user_id" bigint NOT NULL, - "bind_user_time" varchar, - "brokerage_enabled" bit NOT NULL, - "brokerage_time" varchar, - "brokerage_price" int NOT NULL, - "frozen_brokerage_price" int NOT NULL, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint NOT NULL DEFAULT '0', + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "bind_user_id" bigint NOT NULL, + "bind_user_time" varchar, + "brokerage_enabled" bit NOT NULL, + "brokerage_time" varchar, + "price" int NOT NULL, + "frozen_price" int NOT NULL, + "creator" varchar DEFAULT '', + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar DEFAULT '', + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + "tenant_id" bigint NOT NULL DEFAULT '0', PRIMARY KEY ("id") ) COMMENT '分销用户'; CREATE TABLE IF NOT EXISTS "trade_brokerage_record" From 6ef36d5ca6277d9ad64a824e9af8ec6aefd71a70 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 23:33:02 +0800 Subject: [PATCH 36/48] =?UTF-8?q?trade:=20=E5=A2=9E=E5=8A=A0=E5=88=86?= =?UTF-8?q?=E9=94=80=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/api/brokerage/BrokerageApi.java | 30 +++++++++++ .../api/brokerage/dto/BrokerageUserDTO.java | 51 +++++++++++++++++++ .../trade/api/brokerage/BrokerageApiImpl.java | 33 ++++++++++++ .../brokerage/user/BrokerageUserConvert.java | 3 ++ .../yudao-module-member-biz/pom.xml | 5 ++ .../app/user/AppMemberUserController.java | 9 +++- 6 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java create mode 100644 yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/dto/BrokerageUserDTO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java new file mode 100644 index 0000000000..4952e5cad0 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.trade.api.brokerage; + +import cn.iocoder.yudao.module.trade.api.brokerage.dto.BrokerageUserDTO; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageBindModeEnum; + +/** + * 分销 API 接口 + * + * @author owen + */ +public interface BrokerageApi { + + /** + * 获得分销用户 + * + * @param userId 用户编号 + * @return 分销用户信息 + */ + BrokerageUserDTO getBrokerageUser(Long userId); + + /** + * 绑定推广员 + * + * @param userId 用户编号 + * @param bindUserId 推广员编号 + * @param bindMode 绑定模式 {@link BrokerageBindModeEnum} + * @return 是否绑定 + */ + boolean bindUser(Long userId, Long bindUserId, Integer bindMode); +} diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/dto/BrokerageUserDTO.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/dto/BrokerageUserDTO.java new file mode 100644 index 0000000000..864abe1488 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/dto/BrokerageUserDTO.java @@ -0,0 +1,51 @@ +package cn.iocoder.yudao.module.trade.api.brokerage.dto; + +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 分销用户 DTO + * + * @author owen + */ +@Data +public class BrokerageUserDTO { + + /** + * 用户编号 + *

+ * 对应 MemberUserDO 的 id 字段 + */ + private Long id; + + /** + * 推广员编号 + *

+ * 关联 MemberUserDO 的 id 字段 + */ + private Long bindUserId; + /** + * 推广员绑定时间 + */ + private LocalDateTime bindUserTime; + + /** + * 推广资格 + */ + private Boolean brokerageEnabled; + /** + * 成为分销员时间 + */ + private LocalDateTime brokerageTime; + + /** + * 可用佣金 + */ + private Integer price; + /** + * 冻结佣金 + */ + private Integer frozenPrice; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java new file mode 100644 index 0000000000..1bb5207341 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.trade.api.brokerage; + +import cn.iocoder.yudao.module.trade.api.brokerage.dto.BrokerageUserDTO; +import cn.iocoder.yudao.module.trade.convert.brokerage.user.BrokerageUserConvert; +import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; + +/** + * 分销 API 接口实现类 + * + * @author owen + */ +@Service +@Validated +public class BrokerageApiImpl implements BrokerageApi { + + @Resource + private BrokerageUserService brokerageUserService; + + public BrokerageUserDTO getBrokerageUser(Long userId) { + return BrokerageUserConvert.INSTANCE.convertDTO(brokerageUserService.getBrokerageUser(userId)); + } + + @Override + public boolean bindUser(Long userId, Long bindUserId, Integer bindMode) { + // todo 待实现 + return false; + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java index c4a31cc987..01d0be8c8b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.trade.convert.brokerage.user; import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; +import cn.iocoder.yudao.module.trade.api.brokerage.dto.BrokerageUserDTO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; @@ -58,4 +59,6 @@ public interface BrokerageUserConvert { } return result; } + + BrokerageUserDTO convertDTO(BrokerageUserDO brokerageUser); } diff --git a/yudao-module-member/yudao-module-member-biz/pom.xml b/yudao-module-member/yudao-module-member-biz/pom.xml index a5eda05b0b..1df7e7be8a 100644 --- a/yudao-module-member/yudao-module-member-biz/pom.xml +++ b/yudao-module-member/yudao-module-member-biz/pom.xml @@ -33,6 +33,11 @@ yudao-module-infra-api ${revision} + + cn.iocoder.boot + yudao-module-trade-api + ${revision} + diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppMemberUserController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppMemberUserController.java index 4d15aad1fc..461a1a5c53 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppMemberUserController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppMemberUserController.java @@ -8,6 +8,8 @@ import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.service.level.MemberLevelService; import cn.iocoder.yudao.module.member.service.user.MemberUserService; +import cn.iocoder.yudao.module.trade.api.brokerage.BrokerageApi; +import cn.iocoder.yudao.module.trade.api.brokerage.dto.BrokerageUserDTO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; @@ -16,6 +18,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.Optional; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @@ -33,14 +36,18 @@ public class AppMemberUserController { @Resource private MemberLevelService levelService; + @Resource + private BrokerageApi brokerageApi; + @GetMapping("/get") @Operation(summary = "获得基本信息") @PreAuthenticated public CommonResult getUserInfo() { MemberUserDO user = userService.getUser(getLoginUserId()); MemberLevelDO level = levelService.getLevel(user.getLevelId()); + BrokerageUserDTO brokerageUser = brokerageApi.getBrokerageUser(user.getId()); return success(MemberUserConvert.INSTANCE.convert(user, level) - .setBrokerageEnabled(true) // TODO @疯狂:这里我先写死,后面改成 db 返回; + .setBrokerageEnabled(Optional.ofNullable(brokerageUser).map(BrokerageUserDTO::getBrokerageEnabled).orElse(false)) ); } From 87c55784c4bd119c28a24c758c8d66b3dbb5fdca Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 9 Sep 2023 01:27:55 +0800 Subject: [PATCH 37/48] =?UTF-8?q?code=20review=EF=BC=9A=E8=90=A5=E9=94=80?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8+=E8=AE=A2=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/pojo/CommonResult.java | 8 -- .../api/combination/CombinationRecordApi.java | 4 +- .../api/seckill/SeckillActivityApi.java | 1 - .../dto/SeckillActivityUpdateStockReqDTO.java | 4 + .../api/bargain/BargainActivityApiImpl.java | 2 + .../api/seckill/SeckillActivityApiImpl.java | 11 ++- .../combination/CombinationRecordDO.java | 84 +++++++++++-------- .../seckill/SeckillActivityService.java | 4 +- .../seckill/SeckillActivityServiceImpl.java | 8 +- .../aftersale/TradeAfterSaleController.java | 9 +- .../admin/order/TradeOrderController.java | 9 +- .../app/order/AppTradeOrderController.java | 8 +- .../vo/AppTradeOrderSettlementReqVO.java | 2 + .../dal/redis/no/TradeOrderNoRedisDAO.java | 1 + .../order/TradeOrderUpdateServiceImpl.java | 4 + .../module/pay/api/order/PayOrderApi.java | 2 + .../module/pay/api/order/PayOrderApiImpl.java | 1 - .../service/order/PayOrderServiceImpl.java | 1 + 18 files changed, 96 insertions(+), 67 deletions(-) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/CommonResult.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/CommonResult.java index 3a974456e3..e29292dd83 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/CommonResult.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/CommonResult.java @@ -68,14 +68,6 @@ public class CommonResult implements Serializable { return result; } - public static CommonResult success(T data, String msg) { - CommonResult result = new CommonResult<>(); - result.code = GlobalErrorCodeConstants.SUCCESS.getCode(); - result.data = data; - result.msg = msg; - return result; - } - public static boolean isSuccess(Integer code) { return Objects.equals(code, GlobalErrorCodeConstants.SUCCESS.getCode()); } diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java index c03559785d..859eb5c7ed 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java @@ -52,7 +52,7 @@ public interface CombinationRecordApi { void validateCombinationLimitCount(Long activityId, Integer count, Integer sumCount); /** - * 更新拼团状态为 成功 + * 更新拼团状态为成功 * * @param userId 用户编号 * @param orderId 订单编号 @@ -60,7 +60,7 @@ public interface CombinationRecordApi { void updateRecordStatusToSuccess(Long userId, Long orderId); /** - * 更新拼团状态为 失败 + * 更新拼团状态为失败 * * @param userId 用户编号 * @param orderId 订单编号 diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java index 09ec051a33..9c5cf1d357 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.promotion.api.seckill.dto.SeckillActivityUpdateSt */ public interface SeckillActivityApi { - /** * 更新秒杀库存 * diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/dto/SeckillActivityUpdateStockReqDTO.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/dto/SeckillActivityUpdateStockReqDTO.java index 476ba8e159..df7c5649c7 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/dto/SeckillActivityUpdateStockReqDTO.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/dto/SeckillActivityUpdateStockReqDTO.java @@ -12,6 +12,10 @@ import java.util.List; @Data public class SeckillActivityUpdateStockReqDTO { + // TODO @puhui999:参数校验 + + // TODO @puhui999:秒杀的话,一次只能购买一种商品哈;不能多个哈; + /** * 活动编号 */ diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApiImpl.java index 826b4b2aa4..02620c5ecc 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApiImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApiImpl.java @@ -23,6 +23,7 @@ public class BargainActivityApiImpl implements BargainActivityApi { @Override public void updateBargainActivityStock(Long activityId, Integer count) { + // TODO @puhui999:可以整个实现到 bargainActivityService 中 // 查询砍价活动 BargainActivityDO activity = bargainActivityService.getBargainActivity(activityId); if (activity == null) { @@ -30,6 +31,7 @@ public class BargainActivityApiImpl implements BargainActivityApi { } // 更新砍价库存 + // TODO @puhui999:考虑下并发更新问题 BargainActivityUpdateReqVO reqVO = new BargainActivityUpdateReqVO(); reqVO.setId(activityId); reqVO.setStock(activity.getStock() - count); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java index 299316aa06..1f5c157557 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java @@ -27,14 +27,19 @@ public class SeckillActivityApiImpl implements SeckillActivityApi { @Resource private SeckillActivityService activityService; + // TODO @puhui:建议这块弄到 activityService 实现哈; + // TODO @puhui:这个方法,要考虑事务性 @Override public void updateSeckillStock(SeckillActivityUpdateStockReqDTO updateStockReqDTO) { + // TODO @puhui999:长方法,最好有 1.1 1.2 2.1 这种步骤哈; SeckillActivityDO seckillActivity = activityService.getSeckillActivity(updateStockReqDTO.getActivityId()); if (seckillActivity.getStock() < updateStockReqDTO.getCount()) { throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); } // 获取活动商品 + // TODO @puhui999:在一个方法里,dos 和 dolist 最好保持一致,要么用 s,要么用 list 哈; List productDOs = activityService.getSeckillProductListByActivityId(updateStockReqDTO.getActivityId()); + // TODO @puhui999:这个是不是搞成 CollectionUtils.convertMultiMap() List items = updateStockReqDTO.getItems(); Map> map = new HashMap<>(); items.forEach(item -> { @@ -49,9 +54,11 @@ public class SeckillActivityApiImpl implements SeckillActivityApi { } }); // 过滤出购买的商品 + // TODO @puhui999:productDOList 可以简化成 productList;一般来说,do 之类不用带着哈,在变量里; List productDOList = CollectionUtils.filterList(productDOs, item -> map.get(item.getSpuId()).contains(item.getSkuId())); Map productDOMap = CollectionUtils.convertMap(items, SeckillActivityUpdateStockReqDTO.Item::getSkuId, p -> p); // 检查活动商品库存是否充足 + // TODO @puhui999:避免 b 这种无业务含义的变量; boolean b = CollectionUtils.anyMatch(productDOList, item -> { SeckillActivityUpdateStockReqDTO.Item item1 = productDOMap.get(item.getSkuId()); return (item.getStock() < item1.getCount()) || (item.getStock() - item1.getCount()) < 0; @@ -59,17 +66,19 @@ public class SeckillActivityApiImpl implements SeckillActivityApi { if (b) { throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); } + // TODO @puhui999:类似 doList,应该和下面的 update 逻辑粘的更紧密一点;so 在空行的时候,应该挪到 74 之后里去;甚至更合理,应该是 79 之后;说白了,逻辑要分块,每个模块涉及的代码要紧密在一起; List doList = CollectionUtils.convertList(productDOList, item -> { item.setStock(item.getStock() - productDOMap.get(item.getSkuId()).getCount()); return item; }); // 更新活动库存 + // TODO @puhui999:考虑下并发更新 seckillActivity.setStock(seckillActivity.getStock() + updateStockReqDTO.getCount()); seckillActivity.setTotalStock(seckillActivity.getTotalStock() - updateStockReqDTO.getCount()); activityService.updateSeckillActivity(seckillActivity); // 更新活动商品库存 - activityService.updateSeckillActivityProductByList(doList); + activityService.updateSeckillActivityProductList(doList); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java index 898d2a822c..ea851d67e6 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/combination/CombinationRecordDO.java @@ -9,6 +9,7 @@ import lombok.*; import java.time.LocalDateTime; +// TODO 芋艿:把字段的顺序,和 do 顺序对齐下 /** * 拼团记录 DO * @@ -27,34 +28,28 @@ import java.time.LocalDateTime; @AllArgsConstructor public class CombinationRecordDO extends BaseDO { + /** + * 编号,主键自增 + */ @TableId private Long id; + /** * 拼团活动编号 + * + * 关联 {@link CombinationActivityDO#getId()} */ private Long activityId; + /** + * 拼团商品单价 + * + * 冗余 {@link CombinationProductDO#getCombinationPrice()} + */ + private Integer combinationPrice; /** * SPU 编号 */ private Long spuId; - /** - * SKU 编号 - */ - private Long skuId; - /** - * 用户编号 - */ - private Long userId; - /** - * 订单编号 - */ - private Long orderId; - /** - * 团长编号 - * - * 关联 {@link CombinationRecordDO#getId()} - */ - private Long headId; /** * 商品名字 */ @@ -64,9 +59,14 @@ public class CombinationRecordDO extends BaseDO { */ private String picUrl; /** - * 拼团商品单价 + * SKU 编号 */ - private Integer combinationPrice; + private Long skuId; + + /** + * 用户编号 + */ + private Long userId; /** * 用户昵称 */ @@ -75,6 +75,13 @@ public class CombinationRecordDO extends BaseDO { * 用户头像 */ private String avatar; + + /** + * 团长编号 + * + * 关联 {@link CombinationRecordDO#getId()} + */ + private Long headId; /** * 开团状态 * @@ -82,23 +89,9 @@ public class CombinationRecordDO extends BaseDO { */ private Integer status; /** - * 是否虚拟成团 + * 订单编号 */ - private Boolean virtualGroup; - /** - * 过期时间 - * - * {@link CombinationRecordDO#getStartTime()} + {@link CombinationActivityDO#getLimitDuration()} 计算 - */ - private LocalDateTime expireTime; - /** - * 开始时间 (订单付款后开始的时间) - */ - private LocalDateTime startTime; - /** - * 结束时间(成团时间/失败时间) - */ - private LocalDateTime endTime; + private Long orderId; /** * 开团需要人数 * @@ -109,5 +102,24 @@ public class CombinationRecordDO extends BaseDO { * 已加入拼团人数 */ private Integer userCount; + /** + * 是否虚拟成团 + */ + private Boolean virtualGroup; + + /** + * 过期时间 + * + * 基于 {@link CombinationRecordDO#getStartTime()} + {@link CombinationActivityDO#getLimitDuration()} 计算 + */ + private LocalDateTime expireTime; + /** + * 开始时间 (订单付款后开始的时间) + */ + private LocalDateTime startTime; + /** + * 结束时间(成团时间/失败时间) + */ + private LocalDateTime endTime; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java index 052b595619..079470814f 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java @@ -43,9 +43,9 @@ public interface SeckillActivityService { /** * 更新秒杀活动商品 * - * @param productDOList 活动商品列表 + * @param productList 活动商品列表 */ - void updateSeckillActivityProductByList(List productDOList); + void updateSeckillActivityProductList(List productList); /** * 关闭秒杀活动 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java index 17fb9a90fe..28f654049c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java @@ -93,8 +93,8 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { activityList.removeIf(item -> ObjectUtil.equal(item.getId(), activityId)); } // 2.2 过滤出所有 configIds 有交集的活动,判断是否存在重叠 - List activityDOs = filterList(activityList, s -> containsAny(s.getConfigIds(), configIds)); - if (isNotEmpty(activityDOs)) { + List conflictActivityList = filterList(activityList, s -> containsAny(s.getConfigIds(), configIds)); + if (isNotEmpty(conflictActivityList)) { throw exception(SECKILL_ACTIVITY_SPU_CONFLICTS); } } @@ -150,8 +150,8 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { } @Override - public void updateSeckillActivityProductByList(List productDOList) { - seckillProductMapper.updateBatch(productDOList); + public void updateSeckillActivityProductList(List productList) { + seckillProductMapper.updateBatch(productList); } /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java index 60afbc0ab0..fec1fc1aa0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java @@ -36,7 +36,6 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.AFTER_SALE_NOT_FOUND; @Tag(name = "管理后台 - 售后订单") @RestController @@ -77,9 +76,11 @@ public class TradeAfterSaleController { public CommonResult getOrderDetail(@RequestParam("id") Long id) { // 查询订单 TradeAfterSaleDO afterSale = afterSaleService.getAfterSale(id); - if (afterSale == null) { - return success(null, AFTER_SALE_NOT_FOUND.getMsg()); - } + // TODO @puhui999:这里建议改成,如果为 null,直接返回 success null;主要查询操作,尽量不要有非空的提示哈;交给前端处理; +// if (afterSale == null) { +// return success(null, AFTER_SALE_NOT_FOUND.getMsg()); +// } + // 查询订单 TradeOrderDO order = tradeOrderQueryService.getOrder(afterSale.getOrderId()); // 查询订单项 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/TradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/TradeOrderController.java index 728c70c675..546519a1b0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/TradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/TradeOrderController.java @@ -25,7 +25,6 @@ import java.util.Map; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND; @Tag(name = "管理后台 - 交易订单") @RestController @@ -68,9 +67,11 @@ public class TradeOrderController { public CommonResult getOrderDetail(@RequestParam("id") Long id) { // 查询订单 TradeOrderDO order = tradeOrderQueryService.getOrder(id); - if (order == null) { - return success(null, ORDER_NOT_FOUND.getMsg()); - } + // TODO @puhui999:这里建议改成,如果为 null,直接返回 success null;主要查询操作,尽量不要有非空的提示哈;交给前端处理; +// if (order == null) { +// return success(null, ORDER_NOT_FOUND.getMsg()); +// } + // 查询订单项 List orderItems = tradeOrderQueryService.getOrderItemListByOrderId(id); // orderLog diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index a65836c33c..a2ea2f79f3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -33,7 +33,6 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND; @Tag(name = "用户 App - 交易订单") @RestController @@ -82,9 +81,10 @@ public class AppTradeOrderController { public CommonResult getOrder(@RequestParam("id") Long id) { // 查询订单 TradeOrderDO order = tradeOrderQueryService.getOrder(getLoginUserId(), id); - if (order == null) { - return success(null, ORDER_NOT_FOUND.getMsg()); - } + // TODO @puhui999:这里建议改成,如果为 null,直接返回 success null;主要查询操作,尽量不要有非空的提示哈;交给前端处理; +// if (order == null) { +// return success(null, ORDER_NOT_FOUND.getMsg()); +// } // 查询订单项 List orderItems = tradeOrderQueryService.getOrderItemListByOrderId(order.getId()); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java index 6b8c147253..929a2ec197 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java @@ -50,6 +50,7 @@ public class AppTradeOrderSettlementReqVO { private Long seckillActivityId; // ========== 拼团活动相关字段 ========== + // TODO @puhui999:是不是拼团记录的编号哈? @Schema(description = "拼团活动编号", example = "1024") private Long combinationActivityId; @@ -57,6 +58,7 @@ public class AppTradeOrderSettlementReqVO { private Long combinationHeadId; // ========== 砍价活动相关字段 ========== + // TODO @puhui999:是不是砍价记录的编号哈? @Schema(description = "砍价活动编号", example = "123") private Long bargainActivityId; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/redis/no/TradeOrderNoRedisDAO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/redis/no/TradeOrderNoRedisDAO.java index 781975aca9..8ad619269a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/redis/no/TradeOrderNoRedisDAO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/redis/no/TradeOrderNoRedisDAO.java @@ -15,6 +15,7 @@ import java.time.LocalDateTime; */ @Repository public class TradeOrderNoRedisDAO { + public static final String TRADE_ORDER_NO_PREFIX = "O"; @Resource diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 56e887b42f..94fdfe17eb 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -561,6 +561,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { } @Override + // TODO @puhui999:考虑事务性 public void updateOrderPrice(TradeOrderUpdatePriceReqVO reqVO) { // 校验交易订单 TradeOrderDO order = validateOrderExists(reqVO.getId()); @@ -571,6 +572,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { throw exception(ORDER_UPDATE_PRICE_FAIL_EQUAL); } + // TODO @puhui999:应该是按照 payPrice 分配;并且要考虑取余问题;payPrice 也要考虑,item 里的 List itemDOs = tradeOrderItemMapper.selectListByOrderId(order.getId()); // TradeOrderItemDO 需要做 adjustPrice 的分摊 int price = reqVO.getAdjustPrice() / itemDOs.size(); @@ -578,8 +580,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { item.setAdjustPrice(price); }); // 更新 TradeOrderItem + // TODO @puhui999:不要整个对象去更新哈;应该 new 一下; tradeOrderItemMapper.updateBatch(itemDOs); // 更新订单 + // TODO @puhui999:要考虑多次修改价格,不能单单的 payPrice + 价格; TradeOrderDO update = TradeOrderConvert.INSTANCE.convert(reqVO); update.setPayPrice(update.getPayPrice() + update.getAdjustPrice()); // TODO @芋艿:改价时,赠送的积分,要不要做改动??? diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApi.java b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApi.java index 94a79ea3d7..b46f195346 100644 --- a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApi.java +++ b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApi.java @@ -29,6 +29,7 @@ public interface PayOrderApi { */ PayOrderRespDTO getOrder(Long id); + // TODO @puhui999:可以去掉 byId;然后 payOrderId 参数改成 id; /** * 更新支付订单价格 * @@ -36,4 +37,5 @@ public interface PayOrderApi { * @param payPrice 支付单价格 */ void updatePayOrderPriceById(Long payOrderId, Integer payPrice); + } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApiImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApiImpl.java index 18c9ff3ef0..1740e3bba6 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApiImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApiImpl.java @@ -36,5 +36,4 @@ public class PayOrderApiImpl implements PayOrderApi { payOrderService.updatePayOrderPriceById(payOrderId, payPrice); } - } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java index 46d83d32c6..2a6750e5dd 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java @@ -413,6 +413,7 @@ public class PayOrderServiceImpl implements PayOrderService { @Override public void updatePayOrderPriceById(Long payOrderId, Integer payPrice) { + // TODO @puhui999:不能直接这样修改哈;应该只有未支付状态的订单才可以改;另外,如果价格如果没变,可以直接 return 哈; PayOrderDO order = orderMapper.selectById(payOrderId); if (order == null) { throw exception(ORDER_NOT_FOUND); From f97c7a0f6e14decc794b538d2611dd8a6a4f138f Mon Sep 17 00:00:00 2001 From: owen Date: Sat, 9 Sep 2023 01:46:42 +0800 Subject: [PATCH 38/48] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E7=BB=91=E5=AE=9A=E6=8E=A8=E5=B9=BF=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/api/brokerage/BrokerageApi.java | 5 +- .../trade/enums/ErrorCodeConstants.java | 6 ++ .../trade/api/brokerage/BrokerageApiImpl.java | 5 +- .../brokerage/AppBrokerageUserController.java | 17 +++- .../vo/user/AppBrokerageUserBindReqVO.java | 17 ++++ .../brokerage/user/BrokerageUserService.java | 10 ++ .../user/BrokerageUserServiceImpl.java | 92 ++++++++++++++++++- 7 files changed, 140 insertions(+), 12 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserBindReqVO.java diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java index 4952e5cad0..4d7314d4b4 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.trade.api.brokerage; import cn.iocoder.yudao.module.trade.api.brokerage.dto.BrokerageUserDTO; -import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageBindModeEnum; /** * 分销 API 接口 @@ -23,8 +22,8 @@ public interface BrokerageApi { * * @param userId 用户编号 * @param bindUserId 推广员编号 - * @param bindMode 绑定模式 {@link BrokerageBindModeEnum} + * @param isNewUser 是否为新用户 * @return 是否绑定 */ - boolean bindUser(Long userId, Long bindUserId, Integer bindMode); + boolean bindUser(Long userId, Long bindUserId, Boolean isNewUser); } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index fa5be50b7d..236e7af235 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -78,5 +78,11 @@ public interface ErrorCodeConstants { // ========== 分销用户 模块 1011007000 ========== ErrorCode BROKERAGE_USER_NOT_EXISTS = new ErrorCode(1011007000, "分销用户不存在"); ErrorCode BROKERAGE_USER_FROZEN_PRICE_NOT_ENOUGH = new ErrorCode(1011007001, "用户冻结佣金({})数量不足"); + ErrorCode BROKERAGE_BIND_SELF = new ErrorCode(1011007002, "不能绑定自己"); + ErrorCode BROKERAGE_BIND_USER_NOT_ENABLED = new ErrorCode(1011007003, "绑定用户没有推广资格"); + ErrorCode BROKERAGE_BIND_CONDITION_ADMIN = new ErrorCode(1011007004, "仅可在后台绑定推广员"); + ErrorCode BROKERAGE_BIND_MODE_REGISTER = new ErrorCode(1011007005, "只有在注册时可以绑定"); + ErrorCode BROKERAGE_BIND_OVERRIDE = new ErrorCode(1011007006, "已绑定了推广人"); + ErrorCode BROKERAGE_BIND_LOOP = new ErrorCode(1011007007, "下级不能绑定自己的上级"); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java index 1bb5207341..4a534fa223 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java @@ -25,9 +25,8 @@ public class BrokerageApiImpl implements BrokerageApi { } @Override - public boolean bindUser(Long userId, Long bindUserId, Integer bindMode) { - // todo 待实现 - return false; + public boolean bindUser(Long userId, Long bindUserId, Boolean isNewUser) { + return brokerageUserService.bindUser(userId, bindUserId, isNewUser); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index ecbb7de456..ef16340988 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -4,21 +4,22 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.*; +import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import javax.validation.Valid; import java.time.LocalDateTime; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static java.util.Arrays.asList; @Tag(name = "用户 APP - 分销用户") @@ -27,6 +28,8 @@ import static java.util.Arrays.asList; @Validated @Slf4j public class AppBrokerageUserController { + @Resource + private BrokerageUserService brokerageUserService; // TODO 芋艿:临时 mock => @GetMapping("/get") @@ -120,4 +123,10 @@ public class AppBrokerageUserController { return success(1); } + @PutMapping("/bind-user") + @Operation(summary = "绑定推广员") + public CommonResult getBrokerageUserRankByPrice(@Valid AppBrokerageUserBindReqVO reqVO) { + return success(brokerageUserService.bindUser(getLoginUserId(), reqVO.getBindUserId(), false)); + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserBindReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserBindReqVO.java new file mode 100644 index 0000000000..f2a14996a4 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserBindReqVO.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@Schema(description = "应用 App - 绑定推广员 Request VO") +@Data +public class AppBrokerageUserBindReqVO extends PageParam { + + @Schema(description = "推广员编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @NotNull(message = "推广员编号不能为空") + private Long bindUserId; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java index c26cfb6e3d..61aa8bde0d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java @@ -93,4 +93,14 @@ public interface BrokerageUserService { * @return 推广用户数量 */ Long getCountByBindUserId(Long bindUserId); + + /** + * 【会员】绑定推广员 + * + * @param userId 用户编号 + * @param bindUserId 推广员编号 + * @param isNewUser 是否为新用户 + * @return 是否绑定 + */ + boolean bindUser(Long userId, Long bindUserId, Boolean isNewUser); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java index 33f81602da..7666da49bf 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java @@ -1,21 +1,27 @@ package cn.iocoder.yudao.module.trade.service.brokerage.user; import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.BooleanUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.BrokerageUserMapper; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageBindModeEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageEnabledConditionEnum; +import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.time.LocalDateTime; import java.util.Collection; import java.util.List; +import java.util.Objects; import java.util.Optional; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_USER_FROZEN_PRICE_NOT_ENOUGH; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_USER_NOT_EXISTS; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; /** * 分销用户 Service 实现类 @@ -29,6 +35,9 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { @Resource private BrokerageUserMapper brokerageUserMapper; + @Resource + private TradeConfigService tradeConfigService; + @Override public BrokerageUserDO getBrokerageUser(Long id) { return brokerageUserMapper.selectById(id); @@ -105,4 +114,83 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { return brokerageUserMapper.selectCount(BrokerageUserDO::getBindUserId, bindUserId); } + @Override + public boolean bindUser(Long userId, Long bindUserId, Boolean isNewUser) { + if (userId == null) { + throw exception(0); + } + + boolean isInsert = false; + BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(userId); + // 分销用户不存在的情况:1.新注册 2.旧数据 3.分销功能关闭后又打开 + if (brokerageUser == null) { + isInsert = true; + brokerageUser = new BrokerageUserDO().setId(userId).setBrokerageEnabled(false).setPrice(0).setFrozenPrice(0); + } + + // 校验能否绑定 + boolean validated = validateCanBindUser(brokerageUser, bindUserId, isNewUser); + if (!validated) { + return false; + } + + if (isInsert) { + Integer enabledCondition = tradeConfigService.getTradeConfig().getBrokerageEnabledCondition(); + if (BrokerageEnabledConditionEnum.ALL.getCondition().equals(enabledCondition)) { + // 人人分销:用户默认就有分销资格 + brokerageUser.setBrokerageEnabled(true).setBindUserTime(LocalDateTime.now()); + } + brokerageUserMapper.insert(brokerageUser); + } else { + brokerageUserMapper.updateById(new BrokerageUserDO().setId(userId) + .setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now())); + } + return true; + } + + private boolean validateCanBindUser(BrokerageUserDO user, Long bindUserId, Boolean isNewUser) { + if (bindUserId == null) { + return false; + } + + // 校验分销功能是否启用 + TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig(); + if (tradeConfig == null || !BooleanUtil.isTrue(tradeConfig.getBrokerageEnabled())) { + return false; + } + + // 校验绑定自己 + if (Objects.equals(user.getId(), bindUserId)) { + throw exception(BROKERAGE_BIND_SELF); + } + + // 校验要绑定的用户有无推广资格 + BrokerageUserDO bindUser = brokerageUserMapper.selectById(bindUserId); + if (bindUser == null || !BooleanUtil.isTrue(bindUser.getBrokerageEnabled())) { + throw exception(BROKERAGE_BIND_USER_NOT_ENABLED); + } + + // 校验分佣模式:仅可后台手动设置推广员 + if (BrokerageEnabledConditionEnum.ADMIN.getCondition().equals(tradeConfig.getBrokerageEnabledCondition())) { + throw exception(BROKERAGE_BIND_CONDITION_ADMIN); + } + + // 校验分销关系绑定模式 + if (BrokerageBindModeEnum.REGISTER.getMode().equals(tradeConfig.getBrokerageBindMode())) { + if (!BooleanUtil.isTrue(isNewUser)) { + throw exception(BROKERAGE_BIND_MODE_REGISTER); // 只有在注册时可以绑定 + } + } else if (BrokerageBindModeEnum.ANYTIME.getMode().equals(tradeConfig.getBrokerageBindMode())) { + if (user.getBindUserId() != null) { + throw exception(BROKERAGE_BIND_OVERRIDE); // 已绑定了推广人 + } + } + + // A->B->A:下级不能绑定自己的上级, A->B->C->A可以!! + if (Objects.equals(user.getId(), bindUser.getBindUserId())) { + throw exception(BROKERAGE_BIND_LOOP); + } + return true; + } + } From 259734964de364fd6d58c1db4cecd0fc3b126246 Mon Sep 17 00:00:00 2001 From: owen Date: Sat, 9 Sep 2023 01:54:48 +0800 Subject: [PATCH 39/48] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E5=90=8E=E5=8F=B0=E5=8A=9F=E8=83=BD=EF=BC=9A=E6=B8=85?= =?UTF-8?q?=E9=99=A4=E6=8E=A8=E5=B9=BF=E5=91=98=E3=80=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=8E=A8=E5=B9=BF=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/brokerage/user/BrokerageUserController.java | 2 +- .../vo/BrokerageUserUpdateBrokerageUserReqVO.java | 2 +- .../dal/mysql/brokerage/user/BrokerageUserMapper.java | 5 +++++ .../service/brokerage/user/BrokerageUserService.java | 6 +++--- .../brokerage/user/BrokerageUserServiceImpl.java | 11 +++++++++-- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java index 0992f52e02..f29e2c9a8f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java @@ -46,7 +46,7 @@ public class BrokerageUserController { @Operation(summary = "修改推广员") @PreAuthorize("@ss.hasPermission('trade:brokerage-user:update-brokerage-user')") public CommonResult updateBrokerageUser(@Valid @RequestBody BrokerageUserUpdateBrokerageUserReqVO updateReqVO) { - brokerageUserService.updateBrokerageUserId(updateReqVO.getId(), updateReqVO.getBrokerageUserId()); + brokerageUserService.updateBrokerageUserId(updateReqVO.getId(), updateReqVO.getBindUserId()); return success(true); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java index c6c72999d1..d62c7fd1e4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java @@ -17,6 +17,6 @@ public class BrokerageUserUpdateBrokerageUserReqVO { @Schema(description = "推广员编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4587") @NotNull(message = "推广员编号不能为空") - private Long brokerageUserId; + private Long bindUserId; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java index 2f7d1d19c6..b7d045a660 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java @@ -100,4 +100,9 @@ public interface BrokerageUserMapper extends BaseMapperX { return update(null, lambdaUpdateWrapper); } + default void updateBindUserIdAndBindUserTimeToNull(Long id) { + update(null, new LambdaUpdateWrapper() + .eq(BrokerageUserDO::getId, id) + .set(BrokerageUserDO::getBindUserId, null).set(BrokerageUserDO::getBindUserTime, null)); + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java index 61aa8bde0d..f06bb7ffc4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java @@ -41,10 +41,10 @@ public interface BrokerageUserService { /** * 修改推广员编号 * - * @param id 用户编号 - * @param brokerageUserId 推广员编号 + * @param id 用户编号 + * @param bindUserId 推广员编号 */ - void updateBrokerageUserId(Long id, Long brokerageUserId); + void updateBrokerageUserId(Long id, Long bindUserId); /** * 修改推广资格 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java index 7666da49bf..5df10fa58b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java @@ -54,10 +54,17 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } @Override - public void updateBrokerageUserId(Long id, Long brokerageUserId) { + public void updateBrokerageUserId(Long id, Long bindUserId) { // 校验存在 validateBrokerageUserExists(id); - // TODO @疯狂:貌似没实现完 + if (bindUserId == null) { + // 清除推广员 + brokerageUserMapper.updateBindUserIdAndBindUserTimeToNull(id); + } else { + // 修改推广员 + brokerageUserMapper.updateById(new BrokerageUserDO().setId(id) + .setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now())); + } } @Override From 4e9be7a1815f8c96567294d7600870ee88c7c028 Mon Sep 17 00:00:00 2001 From: owen Date: Sat, 9 Sep 2023 01:58:46 +0800 Subject: [PATCH 40/48] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E5=90=8E=E5=8F=B0=E5=8A=9F=E8=83=BD=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=8E=A8=E5=B9=BF=E8=B5=84=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dal/mysql/brokerage/user/BrokerageUserMapper.java | 6 ++++++ .../service/brokerage/user/BrokerageUserServiceImpl.java | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java index b7d045a660..ee90b3e7d9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java @@ -105,4 +105,10 @@ public interface BrokerageUserMapper extends BaseMapperX { .eq(BrokerageUserDO::getId, id) .set(BrokerageUserDO::getBindUserId, null).set(BrokerageUserDO::getBindUserTime, null)); } + + default void updateEnabledFalseAndBrokerageTimeToNull(Long id) { + update(null, new LambdaUpdateWrapper() + .eq(BrokerageUserDO::getId, id) + .set(BrokerageUserDO::getBrokerageEnabled, false).set(BrokerageUserDO::getBrokerageTime, null)); + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java index 5df10fa58b..6d6d7d2ac2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java @@ -71,7 +71,14 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { public void updateBrokerageEnabled(Long id, Boolean enabled) { // 校验存在 validateBrokerageUserExists(id); - // TODO @疯狂:貌似没实现完 + if (BooleanUtil.isTrue(enabled)) { + // 开通推广资格 + brokerageUserMapper.updateById(new BrokerageUserDO().setId(id) + .setBrokerageEnabled(true).setBrokerageTime(LocalDateTime.now())); + } else { + // 取消推广资格 + brokerageUserMapper.updateEnabledFalseAndBrokerageTimeToNull(id); + } } private void validateBrokerageUserExists(Long id) { From 557b09a15773733b7d3c1730059d222b37bfc508 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 9 Sep 2023 09:41:57 +0800 Subject: [PATCH 41/48] =?UTF-8?q?code=20review=EF=BC=9A=E5=88=86=E9=94=80?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/api/brokerage/BrokerageApiImpl.java | 1 + .../user/BrokerageUserController.java | 6 +-- .../AppBrokerageWithdrawCreateReqVO.java | 3 -- .../record/BrokerageRecordConvert.java | 18 +++----- .../brokerage/user/BrokerageUserConvert.java | 20 +++------ .../record/BrokerageRecordMapper.java | 1 + .../brokerage/user/BrokerageUserMapper.java | 1 + .../brokerage/bo/BrokerageAddReqBO.java | 2 + .../brokerage/bo/UserBrokerageSummaryBO.java | 2 + .../record/BrokerageRecordService.java | 2 +- .../record/BrokerageRecordServiceImpl.java | 7 +-- .../brokerage/user/BrokerageUserService.java | 8 ++-- .../user/BrokerageUserServiceImpl.java | 44 ++++++++++++------- .../order/TradeOrderUpdateServiceImpl.java | 12 ++--- .../yudao-module-member-biz/pom.xml | 5 --- .../app/user/AppMemberUserController.java | 12 +---- 16 files changed, 68 insertions(+), 76 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java index 4a534fa223..114ba39ace 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java @@ -20,6 +20,7 @@ public class BrokerageApiImpl implements BrokerageApi { @Resource private BrokerageUserService brokerageUserService; + @Override public BrokerageUserDTO getBrokerageUser(Long userId) { return BrokerageUserConvert.INSTANCE.convertDTO(brokerageUserService.getBrokerageUser(userId)); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java index f29e2c9a8f..b0263f6844 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java @@ -62,7 +62,7 @@ public class BrokerageUserController { @Operation(summary = "修改推广资格") @PreAuthorize("@ss.hasPermission('trade:brokerage-user:update-brokerage-enable')") public CommonResult updateBrokerageEnabled(@Valid @RequestBody BrokerageUserUpdateBrokerageEnabledReqVO updateReqVO) { - brokerageUserService.updateBrokerageEnabled(updateReqVO.getId(), updateReqVO.getEnabled()); + brokerageUserService.updateBrokerageUserEnabled(updateReqVO.getId(), updateReqVO.getEnabled()); return success(true); } @@ -89,12 +89,12 @@ public class BrokerageUserController { // 合计分佣订单 Map userOrderSummaryMap = convertMap(userIds, userId -> userId, - userId -> brokerageRecordService.summaryByUserIdAndBizTypeAndStatus(userId, + userId -> brokerageRecordService.getUserBrokerageSummaryByUserId(userId, BrokerageRecordBizTypeEnum.ORDER.getType(), BrokerageRecordStatusEnum.SETTLEMENT.getStatus())); // 合计推广用户数量 Map brokerageUserCountMap = convertMap(userIds, userId -> userId, - userId -> brokerageUserService.getCountByBindUserId(userId)); + userId -> brokerageUserService.getBrokerageUserCountByBindUserId(userId)); // todo 合计提现 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java index 7528181303..a8b1523b23 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java @@ -23,21 +23,18 @@ public class AppBrokerageWithdrawCreateReqVO { @Min(value = 1, message = "提现金额不能小于 1") private Integer price; - // ========== 银行卡、微信、支付宝 提现相关字段 ========== @Schema(description = "提现账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456789") @NotBlank(message = "提现账号不能为空", groups = {Bank.class, Wechat.class, Alipay.class}) private String accountNo; - // ========== 微信、支付宝 提现相关字段 ========== @Schema(description = "收款码的图片", example = "https://www.iocoder.cn/1.png") @URL(message = "收款码的图片,必须是一个 URL") private String accountQrCodeUrl; - // ========== 银行卡 提现相关字段 ========== @Schema(description = "持卡人姓名", example = "张三") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java index 9307a4f558..f313fa39f8 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java @@ -30,25 +30,21 @@ public interface BrokerageRecordConvert { PageResult convertPage(PageResult page); + // TODO @疯狂:可能 title 不是很固化,会存在类似:沐晴成功购买《XXX JVM 实战》 default BrokerageRecordDO convert(BrokerageUserDO user, BrokerageRecordBizTypeEnum bizType, String bizId, - Integer brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime, + Integer brokerageFrozenDays, int brokeragePrice, LocalDateTime unfreezeTime, String title) { brokerageFrozenDays = ObjectUtil.defaultIfNull(brokerageFrozenDays, 0); // 不冻结时,佣金直接就是结算状态 Integer status = brokerageFrozenDays > 0 ? BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus() : BrokerageRecordStatusEnum.SETTLEMENT.getStatus(); - return new BrokerageRecordDO() - .setUserId(user.getId()) - .setBizType(bizType.getType()) - .setBizId(bizId) - .setPrice(brokerage) - .setTotalPrice(user.getPrice()) + return new BrokerageRecordDO().setUserId(user.getId()) + .setBizType(bizType.getType()).setBizId(bizId) + .setPrice(brokeragePrice).setTotalPrice(user.getPrice()) .setTitle(title) - .setDescription(StrUtil.format(bizType.getDescription(), String.valueOf(brokerage / 100.0))) - .setStatus(status) - .setFrozenDays(brokerageFrozenDays) - .setUnfreezeTime(unfreezeTime); + .setDescription(StrUtil.format(bizType.getDescription(), String.valueOf(brokeragePrice / 100.0))) + .setStatus(status).setFrozenDays(brokerageFrozenDays).setUnfreezeTime(unfreezeTime); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java index 01d0be8c8b..6f0222b5bf 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java @@ -37,24 +37,16 @@ public interface BrokerageUserConvert { PageResult result = convertPage(pageResult); for (BrokerageUserRespVO vo : result.getList()) { // 用户信息 - Optional.ofNullable(userMap.get(vo.getId())) - .ifPresent(user -> { - vo.setNickname(user.getNickname()); - vo.setAvatar(user.getAvatar()); - }); - + Optional.ofNullable(userMap.get(vo.getId())).ifPresent( + user -> vo.setNickname(user.getNickname()).setAvatar(user.getAvatar())); // 推广用户数量(一级) vo.setBrokerageUserCount(MapUtil.getInt(brokerageUserCountMap, vo.getId(), 0)); - + // 推广订单数量、推广订单金额 Optional orderSummaryOptional = Optional.ofNullable(userOrderSummaryMap.get(vo.getId())); - // 推广订单数量 - vo.setBrokerageOrderCount(orderSummaryOptional.map(UserBrokerageSummaryBO::getCount).orElse(0)); - // 推广订单金额 - vo.setBrokerageOrderPrice(orderSummaryOptional.map(UserBrokerageSummaryBO::getPrice).orElse(0)); - - // todo 已提现次数 + vo.setBrokerageOrderCount(orderSummaryOptional.map(UserBrokerageSummaryBO::getCount).orElse(0)) + .setBrokerageOrderPrice(orderSummaryOptional.map(UserBrokerageSummaryBO::getPrice).orElse(0)); + // todo 已提现次数、已提现金额 vo.setWithdrawCount(0); - // todo 已提现金额 vo.setWithdrawPrice(0); } return result; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/BrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/BrokerageRecordMapper.java index 9f9aae824d..b72b50ca76 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/BrokerageRecordMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/BrokerageRecordMapper.java @@ -48,6 +48,7 @@ public interface BrokerageRecordMapper extends BaseMapperX { BrokerageRecordDO::getBizId, bizId); } + // TODO @疯狂:mysql 关键字,大写哈;这样看起来清晰点;例如说 SELECT COUNT(1) @Select("select count(1), sum(price) from trade_brokerage_record where user_id = #{userId} and biz_type = #{bizType} and status = #{status}") UserBrokerageSummaryBO selectCountAndSumPriceByUserIdAndBizTypeAndStatus(@Param("userId") Long userId, @Param("bizType") Integer bizType, diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java index ee90b3e7d9..7fa3e415a0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java @@ -111,4 +111,5 @@ public interface BrokerageUserMapper extends BaseMapperX { .eq(BrokerageUserDO::getId, id) .set(BrokerageUserDO::getBrokerageEnabled, false).set(BrokerageUserDO::getBrokerageTime, null)); } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java index 07e07817ef..ff16ba16a2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java @@ -5,6 +5,7 @@ import lombok.Data; import lombok.NoArgsConstructor; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; /** * 佣金 增加 Request BO @@ -24,6 +25,7 @@ public class BrokerageAddReqBO { /** * 佣金基数 */ + @NotNull(message = "佣金基数不能为空") private Integer basePrice; /** * 一级佣金(固定) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryBO.java index ffbb3ed9a0..4504290bea 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryBO.java @@ -13,6 +13,7 @@ import lombok.NoArgsConstructor; @NoArgsConstructor @AllArgsConstructor public class UserBrokerageSummaryBO { + /** * 佣金数量 */ @@ -21,4 +22,5 @@ public class UserBrokerageSummaryBO { * 佣金总额 */ private Integer price; + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java index 64e5fe52fa..a6ef0b6592 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java @@ -66,5 +66,5 @@ public interface BrokerageRecordService { * @param status 佣金状态 * @return 用户佣金汇总 */ - UserBrokerageSummaryBO summaryByUserIdAndBizTypeAndStatus(Long userId, Integer bizType, Integer status); + UserBrokerageSummaryBO getUserBrokerageSummaryByUserId(Long userId, Integer bizType, Integer status); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java index 960b45ae54..7740d7d06d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java @@ -89,6 +89,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { @Override @Transactional(rollbackFor = Exception.class) public void cancelBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId) { + // TODO @疯狂:userId 加进去查询,会不会更好一点?万一穿错参数; BrokerageRecordDO record = brokerageRecordMapper.selectByBizTypeAndBizId(bizType.getType(), bizId); if (record == null || ObjectUtil.notEqual(record.getUserId(), userId)) { log.error("[cancelBrokerage][userId({})][bizId({}) 更新为已失效失败:记录不存在]", userId, bizId); @@ -138,7 +139,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { * @param list 佣金增加参数列表 * @param brokerageFrozenDays 冻结天数 * @param brokeragePercent 佣金比例 - * @param fixedPriceFun 固定佣金 + * @param fixedPriceFun 固定佣金 // TODO 疯狂:这里是不是可以直接传递 fixedPrice 呀? * @param bizType 业务类型 */ private void addBrokerage(BrokerageUserDO user, List list, Integer brokerageFrozenDays, @@ -200,9 +201,9 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { } @Override - public UserBrokerageSummaryBO summaryByUserIdAndBizTypeAndStatus(Long userId, Integer bizType, Integer status) { + public UserBrokerageSummaryBO getUserBrokerageSummaryByUserId(Long userId, Integer bizType, Integer status) { UserBrokerageSummaryBO summaryBO = brokerageRecordMapper.selectCountAndSumPriceByUserIdAndBizTypeAndStatus(userId, bizType, status); - return summaryBO == null ? new UserBrokerageSummaryBO(0, 0) : summaryBO; + return summaryBO != null ? summaryBO : new UserBrokerageSummaryBO(0, 0); } @Transactional(rollbackFor = Exception.class) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java index f06bb7ffc4..b3d265b291 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java @@ -52,7 +52,7 @@ public interface BrokerageUserService { * @param id 用户编号 * @param enabled 推广资格 */ - void updateBrokerageEnabled(Long id, Boolean enabled); + void updateBrokerageUserEnabled(Long id, Boolean enabled); /** * 获得用户的推广人 @@ -79,20 +79,21 @@ public interface BrokerageUserService { void updateUserFrozenPrice(Long id, Integer frozenPrice); /** - * 更新用户冻结佣金(减少), 更新用户佣金(增加) + * 更新用户冻结佣金(减少),更新用户佣金(增加) * * @param id 用户编号 * @param frozenPrice 减少冻结佣金(负数) */ void updateFrozenPriceDecrAndPriceIncr(Long id, Integer frozenPrice); + // TODO @疯狂:这个后面可能要支持下,二级 /** * 获得推广用户数量(一级) * * @param bindUserId 绑定的推广员编号 * @return 推广用户数量 */ - Long getCountByBindUserId(Long bindUserId); + Long getBrokerageUserCountByBindUserId(Long bindUserId); /** * 【会员】绑定推广员 @@ -103,4 +104,5 @@ public interface BrokerageUserService { * @return 是否绑定 */ boolean bindUser(Long userId, Long bindUserId, Boolean isNewUser); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java index 6d6d7d2ac2..2dd7fb03b0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java @@ -57,18 +57,22 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { public void updateBrokerageUserId(Long id, Long bindUserId) { // 校验存在 validateBrokerageUserExists(id); + + // 情况一:清除推广员 if (bindUserId == null) { // 清除推广员 brokerageUserMapper.updateBindUserIdAndBindUserTimeToNull(id); - } else { - // 修改推广员 - brokerageUserMapper.updateById(new BrokerageUserDO().setId(id) - .setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now())); + return; } + + // 情况二:修改推广员 + // TODO @疯狂:要复用一些 validateCanBindUser 的校验哈; + brokerageUserMapper.updateById(new BrokerageUserDO().setId(id) + .setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now())); } @Override - public void updateBrokerageEnabled(Long id, Boolean enabled) { + public void updateBrokerageUserEnabled(Long id, Boolean enabled) { // 校验存在 validateBrokerageUserExists(id); if (BooleanUtil.isTrue(enabled)) { @@ -124,36 +128,41 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } @Override - public Long getCountByBindUserId(Long bindUserId) { + public Long getBrokerageUserCountByBindUserId(Long bindUserId) { + // TODO @疯狂:mapper 封装下哈;不直接在 service 调用这种基础 mapper 的基础方法 return brokerageUserMapper.selectCount(BrokerageUserDO::getBindUserId, bindUserId); } + // TODO @疯狂:因为现在 user 会存在使用验证码直接注册,所以 isNewUser 不太好传递;我们是不是可以约定绑定的时间,createTime 在 30 秒内,就认为新用户; @Override public boolean bindUser(Long userId, Long bindUserId, Boolean isNewUser) { + // TODO @疯狂:userId 为空,搞到参数校验里哇; if (userId == null) { throw exception(0); } - boolean isInsert = false; + // 1. 获得分销用户 + boolean isNewBrokerageUser = false; BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(userId); - // 分销用户不存在的情况:1.新注册 2.旧数据 3.分销功能关闭后又打开 - if (brokerageUser == null) { - isInsert = true; + if (brokerageUser == null) { // 分销用户不存在的情况:1. 新注册;2. 旧数据;3. 分销功能关闭后又打开 + isNewBrokerageUser = true; brokerageUser = new BrokerageUserDO().setId(userId).setBrokerageEnabled(false).setPrice(0).setFrozenPrice(0); } - // 校验能否绑定 + // 2.1 校验能否绑定 boolean validated = validateCanBindUser(brokerageUser, bindUserId, isNewUser); if (!validated) { return false; } - if (isInsert) { + // 2.2 绑定用户 + if (isNewBrokerageUser) { Integer enabledCondition = tradeConfigService.getTradeConfig().getBrokerageEnabledCondition(); - if (BrokerageEnabledConditionEnum.ALL.getCondition().equals(enabledCondition)) { - // 人人分销:用户默认就有分销资格 + if (BrokerageEnabledConditionEnum.ALL.getCondition().equals(enabledCondition)) { // 人人分销:用户默认就有分销资格 + // TODO @疯狂:应该设置下 brokerageTime,而不是 bindUserTime brokerageUser.setBrokerageEnabled(true).setBindUserTime(LocalDateTime.now()); } + // TODO @疯狂:这里是不是要设置 bindUserId、bindUserTime 字段哈; brokerageUserMapper.insert(brokerageUser); } else { brokerageUserMapper.updateById(new BrokerageUserDO().setId(userId) @@ -162,14 +171,16 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { return true; } + // TODO @疯狂:validate 方法,一般不返回 true false,而是抛出异常;如果要返回 true false 这种,方法名字可以改成 isUserCanBind private boolean validateCanBindUser(BrokerageUserDO user, Long bindUserId, Boolean isNewUser) { + // TODO @疯狂:bindUserId 为空,搞到参数校验里哇; if (bindUserId == null) { return false; } // 校验分销功能是否启用 TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig(); - if (tradeConfig == null || !BooleanUtil.isTrue(tradeConfig.getBrokerageEnabled())) { + if (tradeConfig == null || BooleanUtil.isFalse(tradeConfig.getBrokerageEnabled())) { return false; } @@ -180,7 +191,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { // 校验要绑定的用户有无推广资格 BrokerageUserDO bindUser = brokerageUserMapper.selectById(bindUserId); - if (bindUser == null || !BooleanUtil.isTrue(bindUser.getBrokerageEnabled())) { + if (bindUser == null || BooleanUtil.isFalse(bindUser.getBrokerageEnabled())) { throw exception(BROKERAGE_BIND_USER_NOT_ENABLED); } @@ -200,6 +211,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } } + // TODO @疯狂:这块是不是一直查询到根节点,中间不允许出现自己;就是不能形成环。虽然目前是 2 级,但是未来可能会改多级; = = 环的话,就会存在问题哈 // A->B->A:下级不能绑定自己的上级, A->B->C->A可以!! if (Objects.equals(user.getId(), bindUser.getBindUserId())) { throw exception(BROKERAGE_BIND_LOOP); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 85d4caae02..7893d62a95 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -395,7 +395,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 增加用户经验 getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); // 增加用户佣金 - getSelf().addBrokerageAsync(order.getUserId(), BrokerageRecordBizTypeEnum.ORDER, order.getId()); + getSelf().addBrokerageAsync(order.getUserId(), order.getId()); } /** @@ -675,7 +675,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 扣减用户经验 getSelf().reduceUserExperienceAsync(order.getUserId(), orderRefundPrice, afterSaleId); // 更新分佣记录为已失效 - getSelf().cancelBrokerageAsync(order.getUserId(), BrokerageRecordBizTypeEnum.ORDER, id); + getSelf().cancelBrokerageAsync(order.getUserId(), id); } @Override @@ -785,16 +785,16 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Async - protected void addBrokerageAsync(Long userId, BrokerageRecordBizTypeEnum bizType, Long orderId) { + protected void addBrokerageAsync(Long userId, Long orderId) { List orderItems = tradeOrderItemMapper.selectListByOrderId(orderId); List list = convertList(orderItems, item -> TradeOrderConvert.INSTANCE.convert(item, productSkuApi.getSku(item.getSkuId()))); - brokerageRecordService.addBrokerage(userId, bizType, list); + brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, list); } @Async - protected void cancelBrokerageAsync(Long userId, BrokerageRecordBizTypeEnum bizType, Long orderItemId) { - brokerageRecordService.cancelBrokerage(userId, bizType, String.valueOf(orderItemId)); + protected void cancelBrokerageAsync(Long userId, Long orderItemId) { + brokerageRecordService.cancelBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, String.valueOf(orderItemId)); } /** diff --git a/yudao-module-member/yudao-module-member-biz/pom.xml b/yudao-module-member/yudao-module-member-biz/pom.xml index 1df7e7be8a..a5eda05b0b 100644 --- a/yudao-module-member/yudao-module-member-biz/pom.xml +++ b/yudao-module-member/yudao-module-member-biz/pom.xml @@ -33,11 +33,6 @@ yudao-module-infra-api ${revision} - - cn.iocoder.boot - yudao-module-trade-api - ${revision} - diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppMemberUserController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppMemberUserController.java index 461a1a5c53..9322f91467 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppMemberUserController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppMemberUserController.java @@ -8,8 +8,6 @@ import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.service.level.MemberLevelService; import cn.iocoder.yudao.module.member.service.user.MemberUserService; -import cn.iocoder.yudao.module.trade.api.brokerage.BrokerageApi; -import cn.iocoder.yudao.module.trade.api.brokerage.dto.BrokerageUserDTO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; @@ -18,7 +16,6 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.Optional; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @@ -32,23 +29,16 @@ public class AppMemberUserController { @Resource private MemberUserService userService; - @Resource private MemberLevelService levelService; - @Resource - private BrokerageApi brokerageApi; - @GetMapping("/get") @Operation(summary = "获得基本信息") @PreAuthenticated public CommonResult getUserInfo() { MemberUserDO user = userService.getUser(getLoginUserId()); MemberLevelDO level = levelService.getLevel(user.getLevelId()); - BrokerageUserDTO brokerageUser = brokerageApi.getBrokerageUser(user.getId()); - return success(MemberUserConvert.INSTANCE.convert(user, level) - .setBrokerageEnabled(Optional.ofNullable(brokerageUser).map(BrokerageUserDTO::getBrokerageEnabled).orElse(false)) - ); + return success(MemberUserConvert.INSTANCE.convert(user, level)); } @PutMapping("/update") From 5858f57fe91ed97693ed10a4bec399aa263bf757 Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Sat, 9 Sep 2023 18:32:53 +0800 Subject: [PATCH 42/48] =?UTF-8?q?=E9=92=B1=E5=8C=85=20review=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/pay_wallet.sql | 4 +- .../wallet/vo/wallet/AppPayWalletRespVO.java | 4 +- .../wallet/PayWalletTransactionConvert.java | 3 + .../dal/dataobject/wallet/PayWalletDO.java | 6 +- .../pay/dal/mysql/wallet/PayWalletMapper.java | 58 +++------- .../framework/pay/wallet/WalletPayClient.java | 13 ++- .../service/wallet/PayWalletServiceImpl.java | 101 ++++++------------ .../wallet/PayWalletTransactionService.java | 7 +- .../PayWalletTransactionServiceImpl.java | 18 +++- .../wallet/bo/CreateWalletTransactionBO.java | 48 +++++++++ 10 files changed, 132 insertions(+), 130 deletions(-) create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/CreateWalletTransactionBO.java diff --git a/sql/mysql/pay_wallet.sql b/sql/mysql/pay_wallet.sql index bc2ad183e0..7d092ef453 100644 --- a/sql/mysql/pay_wallet.sql +++ b/sql/mysql/pay_wallet.sql @@ -8,8 +8,8 @@ CREATE TABLE `pay_wallet` `user_id` bigint NOT NULL COMMENT '用户编号', `user_type` tinyint NOT NULL DEFAULT 0 COMMENT '用户类型', `balance` int NOT NULL DEFAULT 0 COMMENT '余额,单位分', - `total_expense` bigint NOT NULL DEFAULT 0 COMMENT '累计支出,单位分', - `total_recharge` bigint NOT NULL DEFAULT 0 COMMENT '累计充值,单位分', + `total_expense` int NOT NULL DEFAULT 0 COMMENT '累计支出,单位分', + `total_recharge` int NOT NULL DEFAULT 0 COMMENT '累计充值,单位分', `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/wallet/AppPayWalletRespVO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/wallet/AppPayWalletRespVO.java index c66cda8716..bd0e0b9d7d 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/wallet/AppPayWalletRespVO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/wallet/AppPayWalletRespVO.java @@ -11,9 +11,9 @@ public class AppPayWalletRespVO { private Integer balance; @Schema(description = "累计支出, 单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") - private Long totalExpense; + private Integer totalExpense; @Schema(description = "累计充值, 单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000") - private Long totalRecharge; + private Integer totalRecharge; } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletTransactionConvert.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletTransactionConvert.java index 9d1edaf6ad..088bdecf3b 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletTransactionConvert.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletTransactionConvert.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.pay.convert.wallet; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionRespVO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; +import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -12,4 +13,6 @@ public interface PayWalletTransactionConvert { PayWalletTransactionConvert INSTANCE = Mappers.getMapper(PayWalletTransactionConvert.class); PageResult convertPage(PageResult page); + + PayWalletTransactionDO convert(CreateWalletTransactionBO bo); } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletDO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletDO.java index 4bf8e61519..4536ae6355 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletDO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletDO.java @@ -37,8 +37,6 @@ public class PayWalletDO extends BaseDO { */ private Integer userType; - // TODO @jason:三个都搞 integer?应该要统一哈 - /** * 余额,单位分 */ @@ -47,10 +45,10 @@ public class PayWalletDO extends BaseDO { /** * 累计支出,单位分 */ - private Long totalExpense; + private Integer totalExpense; /** * 累计充值,单位分 */ - private Long totalRecharge; + private Integer totalRecharge; } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java index 47717d04a3..9184621bdb 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java @@ -3,8 +3,7 @@ package cn.iocoder.yudao.module.pay.dal.mysql.wallet; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; -import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; @Mapper @@ -15,56 +14,31 @@ public interface PayWalletMapper extends BaseMapperX { PayWalletDO::getUserType, userType); } - // TODO @jason:减少时,需要 update price -= ? where price >= ?,避免并发问题。现在基于 price 来过滤,虽然也能解决并发问题,但是冲突概率会高一点;可以看到 TradeBrokerageUserMapper 的做法; /** - * 当余额减少时候更新 + * 当消费退款时候, 更新钱包 * - * @param bizType 业务类型 - * @param balance 当前余额 - * @param totalRecharge 当前累计充值 - * @param totalExpense 当前累计支出 - * @param price 支出的金额 + * @param price 消费金额 * @param id 钱包 id */ - default int updateWhenDecBalance(PayWalletBizTypeEnum bizType, Integer balance, Long totalRecharge, - Long totalExpense, Integer price, Long id) { - // TODO @jason:这种偏判断的,最红放在 service 层;mapper 可以写多个方法; - PayWalletDO updateDO = new PayWalletDO().setBalance(balance - price); - if(bizType == PayWalletBizTypeEnum.PAYMENT){ - updateDO.setTotalExpense(totalExpense + price); - } - if (bizType == PayWalletBizTypeEnum.RECHARGE_REFUND) { - updateDO.setTotalRecharge(totalRecharge - price); - } - return update(updateDO, - new LambdaQueryWrapper().eq(PayWalletDO::getId, id) - .eq(PayWalletDO::getBalance, balance) - .ge(PayWalletDO::getBalance, price)); + default int updateWhenConsumptionRefund(Integer price, Long id){ + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" balance = balance + " + price + ", total_expense = total_expense - " + price) + .eq(PayWalletDO::getId, id); + return update(null, lambdaUpdateWrapper); } - // TODO @jason:类似上面的修改建议哈; /** - * 当余额增加时候更新 + * 当消费时候, 更新钱包 * - * @param bizType 业务类型 - * @param balance 当前余额 - * @param totalRecharge 当前累计充值 - * @param totalExpense 当前累计支出 - * @param price 金额 + * @param price 消费金额 * @param id 钱包 id */ - default int updateWhenIncBalance(PayWalletBizTypeEnum bizType, Integer balance, Long totalRecharge, - Long totalExpense, Integer price, Long id) { - PayWalletDO updateDO = new PayWalletDO().setBalance(balance + price); - if (bizType == PayWalletBizTypeEnum.PAYMENT_REFUND) { - updateDO.setTotalExpense(totalExpense - price); - } - if (bizType == PayWalletBizTypeEnum.RECHARGE) { - updateDO.setTotalExpense(totalRecharge + price); - } - return update(updateDO, - new LambdaQueryWrapper().eq(PayWalletDO::getId, id) - .eq(PayWalletDO::getBalance, balance)); + default int updateWhenConsumption(Integer price, Long id){ + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" balance = balance - " + price + ", total_expense = total_expense + " + price) + .eq(PayWalletDO::getId, id) + .ge(PayWalletDO::getBalance, price); // cas 逻辑 + return update(null, lambdaUpdateWrapper); } } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java index 47e8217d30..54681f8158 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java @@ -62,13 +62,12 @@ public class WalletPayClient extends AbstractPayClient { @Override protected PayOrderRespDTO doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) { try { - // TODO @jason:直接 getLong 和 getInt 会不会更简洁哈 - String userId = MapUtil.getStr(reqDTO.getChannelExtras(), USER_ID_KEY); - String userType = MapUtil.getStr(reqDTO.getChannelExtras(), USER_TYPE_KEY); - Assert.notEmpty(userId, "用户 id 不能为空"); - Assert.notEmpty(userType, "用户类型不能为空"); - PayWalletTransactionDO transaction = wallService.orderPay(Long.valueOf(userId), Integer.valueOf(userType), - reqDTO.getOutTradeNo(), reqDTO.getPrice()); + Long userId = MapUtil.getLong(reqDTO.getChannelExtras(), USER_ID_KEY); + Integer userType = MapUtil.getInt(reqDTO.getChannelExtras(), USER_TYPE_KEY); + Assert.notNull(userId, "用户 id 不能为空"); + Assert.notNull(userType, "用户类型不能为空"); + PayWalletTransactionDO transaction = wallService.orderPay(userId, userType, reqDTO.getOutTradeNo(), + reqDTO.getPrice()); return PayOrderRespDTO.successOf(transaction.getNo(), transaction.getCreator(), transaction.getCreateTime(), reqDTO.getOutTradeNo(), transaction); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java index d017e53327..2d186b98ee 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java @@ -6,10 +6,10 @@ import cn.iocoder.yudao.module.pay.dal.dataobject.refund.PayRefundDO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletMapper; -import cn.iocoder.yudao.module.pay.dal.redis.no.PayNoRedisDAO; import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; import cn.iocoder.yudao.module.pay.service.order.PayOrderService; import cn.iocoder.yudao.module.pay.service.refund.PayRefundService; +import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; @@ -18,7 +18,6 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.time.LocalDateTime; -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.TOO_MANY_REQUESTS; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum.PAYMENT; @@ -33,20 +32,8 @@ import static cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum.PAYM @Slf4j public class PayWalletServiceImpl implements PayWalletService { - /** - * 余额支付的 no 前缀 - */ - private static final String WALLET_PAY_NO_PREFIX = "WP"; - /** - * 余额退款的 no 前缀 - */ - private static final String WALLET_REFUND_NO_PREFIX = "WR"; - @Resource private PayWalletMapper walletMapper; - @Resource - private PayNoRedisDAO noRedisDAO; - @Resource private PayWalletTransactionService walletTransactionService; @Resource @@ -61,7 +48,7 @@ public class PayWalletServiceImpl implements PayWalletService { PayWalletDO wallet = walletMapper.selectByUserIdAndType(userId, userType); if (wallet == null) { wallet = new PayWalletDO().setUserId(userId).setUserType(userType) - .setBalance(0).setTotalExpense(0L).setTotalRecharge(0L); + .setBalance(0).setTotalExpense(0).setTotalRecharge(0); wallet.setCreateTime(LocalDateTime.now()); walletMapper.insert(wallet); } @@ -127,68 +114,50 @@ public class PayWalletServiceImpl implements PayWalletService { Long bizId, PayWalletBizTypeEnum bizType, Integer price) { // 1.1 获取钱包 PayWalletDO payWallet = getOrCreateWallet(userId, userType); - // 1.2 判断余额是否足够 - int afterBalance = payWallet.getBalance() - price; - if (afterBalance < 0) { + // 2.1 扣除余额 + int number = 0 ; + switch (bizType) { + case PAYMENT: { + number = walletMapper.updateWhenConsumption(price, payWallet.getId()); + break; + } + case RECHARGE_REFUND: { + // TODO + break; + } + } + if (number == 0) { throw exception(WALLET_BALANCE_NOT_ENOUGH); } - - // TODO jason:建议基于 where price >= 来做哈;然后抛出 WALLET_BALANCE_NOT_ENOUGH - // 2.1 扣除余额 - int number = walletMapper.updateWhenDecBalance(bizType, payWallet.getBalance(), - payWallet.getTotalRecharge(), payWallet.getTotalExpense(), price, payWallet.getId()); - if (number == 0) { - throw exception(TOO_MANY_REQUESTS); - } - + int afterBalance = payWallet.getBalance() - price; // 2.2 生成钱包流水 - // TODO @jason:walletNo 交给 payWalletTransactionService 自己生成哈; - String walletNo = generateWalletNo(bizType); - PayWalletTransactionDO walletTransaction = new PayWalletTransactionDO().setWalletId(payWallet.getId()) - .setNo(walletNo).setPrice(-price).setBalance(afterBalance) - .setBizId(String.valueOf(bizId)).setBizType(bizType.getType()).setTitle(bizType.getDescription()); - // TODO @jason:是不是可以 createWalletTransaction 搞个 bo 参数,然后 PayWalletTransactionDO 交回给 walletTransactionService 更好;然后把参数简化下 - walletTransactionService.createWalletTransaction(walletTransaction); - return walletTransaction; + CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId()) + .setPrice(-price).setBalance(afterBalance).setBizId(String.valueOf(bizId)) + .setBizType(bizType.getType()).setTitle(bizType.getDescription()); + return walletTransactionService.createWalletTransaction(bo); } @Override public PayWalletTransactionDO addWalletBalance(Long userId, Integer userType, Long bizId, PayWalletBizTypeEnum bizType, Integer price) { - // 1.1 获取钱包 + // 获取钱包 PayWalletDO payWallet = getOrCreateWallet(userId, userType); - - // 2.1 增加余额 - // TODO @jason:类似上面的思路哈; - int number = walletMapper.updateWhenIncBalance(bizType, payWallet.getBalance(), payWallet.getTotalRecharge(), - payWallet.getTotalExpense(), price, payWallet.getId()); - if (number == 0) { - throw exception(TOO_MANY_REQUESTS); + switch (bizType) { + case PAYMENT_REFUND: { + // 更新退款 + walletMapper.updateWhenConsumptionRefund(price, payWallet.getId()); + break; + } + case RECHARGE: { + //TODO + break; + } } - // 2.2 生成钱包流水 - String walletNo = generateWalletNo(bizType); - PayWalletTransactionDO newWalletTransaction = new PayWalletTransactionDO().setWalletId(payWallet.getId()) - .setNo(walletNo).setPrice(price).setBalance(payWallet.getBalance()+price) - .setBizId(String.valueOf(bizId)).setBizType(bizType.getType()) - .setTitle(bizType.getDescription()); - walletTransactionService.createWalletTransaction(newWalletTransaction); - return newWalletTransaction; - } - - private String generateWalletNo(PayWalletBizTypeEnum bizType) { - // TODO @jason:对于余额来说,是不是直接 W+序号就行了,它其实不关注业务;;;不然就耦合啦 - String no = ""; - switch(bizType){ - case PAYMENT: - no = noRedisDAO.generate(WALLET_PAY_NO_PREFIX); - break; - case PAYMENT_REFUND: - no = noRedisDAO.generate(WALLET_REFUND_NO_PREFIX); - break; - default : - } - return no; + CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId()) + .setPrice(price).setBalance(payWallet.getBalance()+price).setBizId(String.valueOf(bizId)) + .setBizType(bizType.getType()).setTitle(bizType.getDescription()); + return walletTransactionService.createWalletTransaction(bo); } } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java index 432e2f2e00..db6f778f3a 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; +import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO; /** * 钱包余额流水 Service 接口 @@ -25,10 +26,10 @@ public interface PayWalletTransactionService { /** * 新增钱包余额流水 * - * @param payWalletTransaction 余额流水 - * @return id + * @param bo 创建钱包流水 bo + * @return 新建的钱包 do */ - Long createWalletTransaction(PayWalletTransactionDO payWalletTransaction); + PayWalletTransactionDO createWalletTransaction(CreateWalletTransactionBO bo); /** * 根据 no,获取钱包余流水 diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java index 05a2a48000..ba27392f0f 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java @@ -2,10 +2,13 @@ package cn.iocoder.yudao.module.pay.service.wallet; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO; +import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletTransactionConvert; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletTransactionMapper; +import cn.iocoder.yudao.module.pay.dal.redis.no.PayNoRedisDAO; import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; +import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -19,11 +22,16 @@ import javax.annotation.Resource; @Service @Slf4j public class PayWalletTransactionServiceImpl implements PayWalletTransactionService { - + /** + * 钱包流水的 no 前缀 + */ + private static final String WALLET_NO_PREFIX = "W"; @Resource private PayWalletService payWalletService; @Resource private PayWalletTransactionMapper payWalletTransactionMapper; + @Resource + private PayNoRedisDAO noRedisDAO; @Override public PageResult getWalletTransactionPage(Long userId, Integer userType, @@ -33,9 +41,11 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ } @Override - public Long createWalletTransaction(PayWalletTransactionDO payWalletTransaction) { - payWalletTransactionMapper.insert(payWalletTransaction); - return payWalletTransaction.getId(); + public PayWalletTransactionDO createWalletTransaction(CreateWalletTransactionBO bo) { + PayWalletTransactionDO transactionDO = PayWalletTransactionConvert.INSTANCE.convert(bo); + transactionDO.setNo(noRedisDAO.generate(WALLET_NO_PREFIX)); + payWalletTransactionMapper.insert(transactionDO); + return transactionDO; } @Override diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/CreateWalletTransactionBO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/CreateWalletTransactionBO.java new file mode 100644 index 0000000000..2b71886063 --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/CreateWalletTransactionBO.java @@ -0,0 +1,48 @@ +package cn.iocoder.yudao.module.pay.service.wallet.bo; + +import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; +import lombok.Data; + +/** + * 创建钱包流水 BO + * + * @author jason + */ +@Data +public class CreateWalletTransactionBO { + + /** + * 钱包编号 + * + */ + private Long walletId; + + /** + * 交易金额,单位分 + * + * 正值表示余额增加,负值表示余额减少 + */ + private Integer price; + + /** + * 交易后余额,单位分 + */ + private Integer balance; + + /** + * 关联业务分类 + * + * 枚举 {@link PayWalletBizTypeEnum#getType()} + */ + private Integer bizType; + + /** + * 关联业务编号 + */ + private String bizId; + + /** + * 流水说明 + */ + private String title; +} From 426594ae001a2465a3476ad18202386a0979550f Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 9 Sep 2023 19:34:50 +0800 Subject: [PATCH 43/48] =?UTF-8?q?=E5=88=86=E9=94=80=EF=BC=9A=E8=B0=83?= =?UTF-8?q?=E6=95=B4=20app=20=E7=9A=84=20price=20=E5=88=B0=20brokeragePric?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../brokerage/user/vo/BrokerageUserRespVO.java | 3 --- .../app/brokerage/AppBrokerageUserController.java | 15 ++++++++------- .../user/AppBrokerageUserChildSummaryRespVO.java | 2 +- .../vo/user/AppBrokerageUserMySummaryRespVO.java | 2 +- .../user/AppBrokerageUserRankByPriceRespVO.java | 2 +- .../brokerage/vo/user/AppBrokerageUserRespVO.java | 3 +++ .../brokerage/record/BrokerageRecordConvert.java | 2 +- .../brokerage/user/BrokerageUserDO.java | 4 ++-- .../brokerage/user/BrokerageUserServiceImpl.java | 2 +- 9 files changed, 18 insertions(+), 17 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserRespVO.java index c353b46145..ae7caf5ff2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserRespVO.java @@ -19,7 +19,6 @@ public class BrokerageUserRespVO extends BrokerageUserBaseVO { @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; - // ========== 用户信息 ========== @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png") @@ -27,7 +26,6 @@ public class BrokerageUserRespVO extends BrokerageUserBaseVO { @Schema(description = "用户昵称", example = "李四") private String nickname; - // ========== 推广信息 ========== @Schema(description = "推广用户数量(一级)", example = "20019") @@ -37,7 +35,6 @@ public class BrokerageUserRespVO extends BrokerageUserBaseVO { @Schema(description = "推广订单金额", example = "20019") private Integer brokerageOrderPrice; - // ========== 提现信息 ========== @Schema(description = "已提现金额", example = "20019") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index ef16340988..83a1b25e00 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -37,6 +37,7 @@ public class AppBrokerageUserController { @PreAuthenticated public CommonResult getBrokerageUser() { AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO() + .setBrokerageEnabled(true) .setPrice(2000) .setFrozenPrice(3000); return success(respVO); @@ -49,7 +50,7 @@ public class AppBrokerageUserController { public CommonResult getBrokerageUserSummary() { AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO() .setYesterdayPrice(1) - .setPrice(2) + .setBrokeragePrice(2) .setFrozenPrice(3) .setWithdrawPrice(4) .setFirstBrokerageUserCount(166) @@ -84,16 +85,16 @@ public class AppBrokerageUserController { public CommonResult> getBrokerageUserChildSummaryPageByPrice(AppBrokerageUserRankPageReqVO pageReqVO) { AppBrokerageUserRankByPriceRespVO vo1 = new AppBrokerageUserRankByPriceRespVO() .setId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setPrice(10); + .setBrokeragePrice(10); AppBrokerageUserRankByPriceRespVO vo2 = new AppBrokerageUserRankByPriceRespVO() .setId(2L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setPrice(6); + .setBrokeragePrice(6); AppBrokerageUserRankByPriceRespVO vo3 = new AppBrokerageUserRankByPriceRespVO() .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setPrice(4); + .setBrokeragePrice(4); AppBrokerageUserRankByPriceRespVO vo4 = new AppBrokerageUserRankByPriceRespVO() .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setPrice(4); + .setBrokeragePrice(4); return success(new PageResult<>(asList(vo1, vo2, vo3, vo4), 10L)); } @@ -105,11 +106,11 @@ public class AppBrokerageUserController { AppBrokerageUserChildSummaryPageReqVO pageReqVO) { AppBrokerageUserChildSummaryRespVO vo1 = new AppBrokerageUserChildSummaryRespVO() .setId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setPrice(10).setPrice(20).setBrokerageOrderCount(30) + .setBrokeragePrice(10).setBrokeragePrice(20).setBrokerageOrderCount(30) .setBrokerageTime(LocalDateTime.now()); AppBrokerageUserChildSummaryRespVO vo2 = new AppBrokerageUserChildSummaryRespVO() .setId(1L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setPrice(20).setPrice(30).setBrokerageOrderCount(40) + .setBrokeragePrice(20).setBrokeragePrice(30).setBrokerageOrderCount(40) .setBrokerageTime(LocalDateTime.now()); return success(new PageResult<>(asList(vo1, vo2), 10L)); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java index 55d88d74fb..1beb1b5e2a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java @@ -19,7 +19,7 @@ public class AppBrokerageUserChildSummaryRespVO { private String avatar; @Schema(description = "佣金金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Integer price; + private Integer brokeragePrice; @Schema(description = "分销订单数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "20") private Integer brokerageOrderCount; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java index 33a089cc61..cc9a03ebc8 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java @@ -14,7 +14,7 @@ public class AppBrokerageUserMySummaryRespVO { private Integer withdrawPrice; @Schema(description = "可用的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2408") - private Integer price; + private Integer brokeragePrice; @Schema(description = "冻结的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "234") private Integer frozenPrice; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java index d80fb67a2b..91345ea789 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRankByPriceRespVO.java @@ -17,6 +17,6 @@ public class AppBrokerageUserRankByPriceRespVO { private String avatar; @Schema(description = "佣金金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Integer price; + private Integer brokeragePrice; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java index 9db6e0cc2f..40b70bed2d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java @@ -7,6 +7,9 @@ import lombok.Data; @Data public class AppBrokerageUserRespVO { + @Schema(description = "是否有分销资格", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") + private Boolean brokerageEnabled; + @Schema(description = "可用的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2408") private Integer price; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java index f313fa39f8..b55a76c889 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java @@ -41,7 +41,7 @@ public interface BrokerageRecordConvert { : BrokerageRecordStatusEnum.SETTLEMENT.getStatus(); return new BrokerageRecordDO().setUserId(user.getId()) .setBizType(bizType.getType()).setBizId(bizId) - .setPrice(brokeragePrice).setTotalPrice(user.getPrice()) + .setPrice(brokeragePrice).setTotalPrice(user.getBrokeragePrice()) .setTitle(title) .setDescription(StrUtil.format(bizType.getDescription(), String.valueOf(brokeragePrice / 100.0))) .setStatus(status).setFrozenDays(brokerageFrozenDays).setUnfreezeTime(unfreezeTime); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java index 1773e41e7b..4348fa1953 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java @@ -43,7 +43,7 @@ public class BrokerageUserDO extends BaseDO { private LocalDateTime bindUserTime; /** - * 推广资格 + * 是否有分销资格 */ private Boolean brokerageEnabled; /** @@ -54,7 +54,7 @@ public class BrokerageUserDO extends BaseDO { /** * 可用佣金 */ - private Integer price; + private Integer brokeragePrice; /** * 冻结佣金 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java index 2dd7fb03b0..47ad454ef9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java @@ -146,7 +146,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(userId); if (brokerageUser == null) { // 分销用户不存在的情况:1. 新注册;2. 旧数据;3. 分销功能关闭后又打开 isNewBrokerageUser = true; - brokerageUser = new BrokerageUserDO().setId(userId).setBrokerageEnabled(false).setPrice(0).setFrozenPrice(0); + brokerageUser = new BrokerageUserDO().setId(userId).setBrokerageEnabled(false).setBrokeragePrice(0).setFrozenPrice(0); } // 2.1 校验能否绑定 From cd51d57f122ad8d74c5ade811098472b17860ecb Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 9 Sep 2023 19:42:53 +0800 Subject: [PATCH 44/48] =?UTF-8?q?=E5=88=86=E9=94=80=EF=BC=9A=E8=B0=83?= =?UTF-8?q?=E6=95=B4=20app=20=E7=9A=84=20price=20=E5=88=B0=20brokeragePric?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wallet/PayWalletTransactionConvert.java | 3 ++- .../pay/dal/mysql/wallet/PayWalletMapper.java | 6 ++++-- .../pay/service/wallet/PayWalletServiceImpl.java | 16 +++++++++------- .../wallet/PayWalletTransactionService.java | 5 ++++- .../wallet/PayWalletTransactionServiceImpl.java | 11 +++++++---- .../wallet/bo/CreateWalletTransactionBO.java | 2 ++ 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletTransactionConvert.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletTransactionConvert.java index 088bdecf3b..f806168c8f 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletTransactionConvert.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletTransactionConvert.java @@ -14,5 +14,6 @@ public interface PayWalletTransactionConvert { PageResult convertPage(PageResult page); - PayWalletTransactionDO convert(CreateWalletTransactionBO bo); + PayWalletTransactionDO convert(CreateWalletTransactionBO bean); + } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java index 9184621bdb..ef695c9fee 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java @@ -22,7 +22,8 @@ public interface PayWalletMapper extends BaseMapperX { */ default int updateWhenConsumptionRefund(Integer price, Long id){ LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" balance = balance + " + price + ", total_expense = total_expense - " + price) + .setSql(" balance = balance + " + price + + ", total_expense = total_expense - " + price) .eq(PayWalletDO::getId, id); return update(null, lambdaUpdateWrapper); } @@ -35,7 +36,8 @@ public interface PayWalletMapper extends BaseMapperX { */ default int updateWhenConsumption(Integer price, Long id){ LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" balance = balance - " + price + ", total_expense = total_expense + " + price) + .setSql(" balance = balance - " + price + + ", total_expense = total_expense + " + price) .eq(PayWalletDO::getId, id) .ge(PayWalletDO::getBalance, price); // cas 逻辑 return update(null, lambdaUpdateWrapper); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java index 2d186b98ee..f09dfc6187 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java @@ -112,13 +112,14 @@ public class PayWalletServiceImpl implements PayWalletService { @Override public PayWalletTransactionDO reduceWalletBalance(Long userId, Integer userType, Long bizId, PayWalletBizTypeEnum bizType, Integer price) { - // 1.1 获取钱包 + // 1. 获取钱包 PayWalletDO payWallet = getOrCreateWallet(userId, userType); + // 2.1 扣除余额 - int number = 0 ; + int updateCounts = 0 ; switch (bizType) { case PAYMENT: { - number = walletMapper.updateWhenConsumption(price, payWallet.getId()); + updateCounts = walletMapper.updateWhenConsumption(price, payWallet.getId()); break; } case RECHARGE_REFUND: { @@ -126,11 +127,11 @@ public class PayWalletServiceImpl implements PayWalletService { break; } } - if (number == 0) { + if (updateCounts == 0) { throw exception(WALLET_BALANCE_NOT_ENOUGH); } - int afterBalance = payWallet.getBalance() - price; // 2.2 生成钱包流水 + Integer afterBalance = payWallet.getBalance() - price; CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId()) .setPrice(-price).setBalance(afterBalance).setBizId(String.valueOf(bizId)) .setBizType(bizType.getType()).setTitle(bizType.getDescription()); @@ -140,7 +141,7 @@ public class PayWalletServiceImpl implements PayWalletService { @Override public PayWalletTransactionDO addWalletBalance(Long userId, Integer userType, Long bizId, PayWalletBizTypeEnum bizType, Integer price) { - // 获取钱包 + // 1. 获取钱包 PayWalletDO payWallet = getOrCreateWallet(userId, userType); switch (bizType) { case PAYMENT_REFUND: { @@ -153,7 +154,8 @@ public class PayWalletServiceImpl implements PayWalletService { break; } } - // 2.2 生成钱包流水 + + // 2. 生成钱包流水 CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId()) .setPrice(price).setBalance(payWallet.getBalance()+price).setBizId(String.valueOf(bizId)) .setBizType(bizType.getType()).setTitle(bizType.getDescription()); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java index db6f778f3a..52c84e159c 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java @@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO; +import javax.validation.Valid; + /** * 钱包余额流水 Service 接口 * @@ -29,7 +31,7 @@ public interface PayWalletTransactionService { * @param bo 创建钱包流水 bo * @return 新建的钱包 do */ - PayWalletTransactionDO createWalletTransaction(CreateWalletTransactionBO bo); + PayWalletTransactionDO createWalletTransaction(@Valid CreateWalletTransactionBO bo); /** * 根据 no,获取钱包余流水 @@ -46,4 +48,5 @@ public interface PayWalletTransactionService { * @return 钱包流水 */ PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type); + } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java index ba27392f0f..6ef32a5570 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java @@ -22,10 +22,12 @@ import javax.annotation.Resource; @Service @Slf4j public class PayWalletTransactionServiceImpl implements PayWalletTransactionService { + /** * 钱包流水的 no 前缀 */ private static final String WALLET_NO_PREFIX = "W"; + @Resource private PayWalletService payWalletService; @Resource @@ -42,10 +44,10 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ @Override public PayWalletTransactionDO createWalletTransaction(CreateWalletTransactionBO bo) { - PayWalletTransactionDO transactionDO = PayWalletTransactionConvert.INSTANCE.convert(bo); - transactionDO.setNo(noRedisDAO.generate(WALLET_NO_PREFIX)); - payWalletTransactionMapper.insert(transactionDO); - return transactionDO; + PayWalletTransactionDO transaction = PayWalletTransactionConvert.INSTANCE.convert(bo) + .setNo(noRedisDAO.generate(WALLET_NO_PREFIX)); + payWalletTransactionMapper.insert(transaction); + return transaction; } @Override @@ -57,4 +59,5 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ public PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type) { return payWalletTransactionMapper.selectByBiz(bizId, type.getType()); } + } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/CreateWalletTransactionBO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/CreateWalletTransactionBO.java index 2b71886063..a1b7af8be0 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/CreateWalletTransactionBO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/CreateWalletTransactionBO.java @@ -11,6 +11,8 @@ import lombok.Data; @Data public class CreateWalletTransactionBO { + // TODO @jason:bo 的话,最好加个参数校验哈; + /** * 钱包编号 * From a47d744f648cdd60165f757254d176dd5116d919 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 9 Sep 2023 21:05:44 +0800 Subject: [PATCH 45/48] =?UTF-8?q?=E5=88=86=E9=94=80=EF=BC=9A=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E5=88=86=E9=94=80=E7=9A=84=20url=20=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/api/brokerage/BrokerageApiImpl.java | 2 +- .../app/brokerage/AppBrokerageUserController.java | 15 ++++++++------- .../brokerage/user/BrokerageUserService.java | 2 +- .../brokerage/user/BrokerageUserServiceImpl.java | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java index 114ba39ace..4910f07a58 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApiImpl.java @@ -27,7 +27,7 @@ public class BrokerageApiImpl implements BrokerageApi { @Override public boolean bindUser(Long userId, Long bindUserId, Boolean isNewUser) { - return brokerageUserService.bindUser(userId, bindUserId, isNewUser); + return brokerageUserService.bindBrokerageUser(userId, bindUserId, isNewUser); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index 83a1b25e00..208ecee2e2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -43,6 +43,13 @@ public class AppBrokerageUserController { return success(respVO); } + @PutMapping("/bind") + @Operation(summary = "绑定推广员") + @PreAuthenticated + public CommonResult bindBrokerageUser(@Valid @RequestBody AppBrokerageUserBindReqVO reqVO) { + return success(brokerageUserService.bindBrokerageUser(getLoginUserId(), reqVO.getBindUserId(), false)); + } + // TODO 芋艿:临时 mock => @GetMapping("/get-summary") @Operation(summary = "获得个人分销统计") @@ -119,15 +126,9 @@ public class AppBrokerageUserController { @GetMapping("/get-rank-by-price") @Operation(summary = "获得分销用户排行(基于佣金)") @Parameter(name = "times", description = "时间段", required = true) - public CommonResult getBrokerageUserRankByPrice( + public CommonResult bindBrokerageUser( @RequestParam("times") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) LocalDateTime[] times) { return success(1); } - @PutMapping("/bind-user") - @Operation(summary = "绑定推广员") - public CommonResult getBrokerageUserRankByPrice(@Valid AppBrokerageUserBindReqVO reqVO) { - return success(brokerageUserService.bindUser(getLoginUserId(), reqVO.getBindUserId(), false)); - } - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java index b3d265b291..de9d0a2b71 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java @@ -103,6 +103,6 @@ public interface BrokerageUserService { * @param isNewUser 是否为新用户 * @return 是否绑定 */ - boolean bindUser(Long userId, Long bindUserId, Boolean isNewUser); + boolean bindBrokerageUser(Long userId, Long bindUserId, Boolean isNewUser); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java index 47ad454ef9..1a168d9668 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java @@ -135,7 +135,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { // TODO @疯狂:因为现在 user 会存在使用验证码直接注册,所以 isNewUser 不太好传递;我们是不是可以约定绑定的时间,createTime 在 30 秒内,就认为新用户; @Override - public boolean bindUser(Long userId, Long bindUserId, Boolean isNewUser) { + public boolean bindBrokerageUser(Long userId, Long bindUserId, Boolean isNewUser) { // TODO @疯狂:userId 为空,搞到参数校验里哇; if (userId == null) { throw exception(0); From 4265441e1daec669527b89a02e4e1a4850b4560c Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 9 Sep 2023 22:28:01 +0800 Subject: [PATCH 46/48] =?UTF-8?q?=E5=88=86=E9=94=80=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=95=86=E5=93=81=E7=9A=84=E5=88=86=E4=BD=A3=E9=87=91?= =?UTF-8?q?=E9=A2=9D=E8=AE=A1=E7=AE=97=20api=20mock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppBrokerageRecordController.java | 12 ++++++++++++ .../AppBrokerageProductPriceRespVO.java | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageProductPriceRespVO.java diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java index d4c72028fd..9569162cbf 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.trade.controller.app.brokerage; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageProductPriceRespVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordRespVO; import io.swagger.v3.oas.annotations.Operation; @@ -11,6 +12,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; @@ -40,4 +42,14 @@ public class AppBrokerageRecordController { return success(new PageResult<>(asList(vo1, vo2), 10L)); } + @GetMapping("/get-product-brokerage-price") + @Operation(summary = "获得商品的分销金额") + public CommonResult getProductBrokeragePrice(@RequestParam("spuId") Long spuId) { + AppBrokerageProductPriceRespVO respVO = new AppBrokerageProductPriceRespVO(); + respVO.setEnabled(true); // TODO @疯狂:需要开启分销 + 人允许分销 + respVO.setBrokerageMinPrice(1); + respVO.setBrokerageMaxPrice(2); + return success(respVO); + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageProductPriceRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageProductPriceRespVO.java new file mode 100644 index 0000000000..6b2191d5ff --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/record/AppBrokerageProductPriceRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "用户 App - 商品的分销金额 Response VO") +@Data +public class AppBrokerageProductPriceRespVO { + + @Schema(description = "是否开启", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Boolean enabled; + + @Schema(description = "分销最小金额,单位:分", example = "100") + private Integer brokerageMinPrice; + + @Schema(description = "分销最大金额,单位:分", example = "100") + private Integer brokerageMaxPrice; + +} From 40e1a879e3b38d830b25f81716986d485f115d61 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 10 Sep 2023 18:01:53 +0800 Subject: [PATCH 47/48] =?UTF-8?q?=E7=99=BB=E5=BD=95=EF=BC=9A=E7=A4=BE?= =?UTF-8?q?=E4=BA=A4=E7=99=BB=E5=BD=95=E6=97=B6=EF=BC=8C=E9=A2=9D=E5=A4=96?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=20openid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/auth/AppAuthController.http | 12 +++++++- .../app/auth/vo/AppAuthLoginRespVO.java | 8 +++++ .../member/convert/auth/AuthConvert.java | 2 +- .../service/auth/MemberAuthServiceImpl.java | 30 +++++++++++-------- .../system/api/social/SocialUserApi.java | 13 ++++---- .../api/social/dto/SocialUserRespDTO.java | 27 +++++++++++++++++ .../system/api/social/SocialUserApiImpl.java | 9 +++--- .../service/auth/AdminAuthServiceImpl.java | 7 +++-- .../service/social/SocialUserService.java | 13 ++++---- .../service/social/SocialUserServiceImpl.java | 8 +++-- .../auth/AdminAuthServiceImplTest.java | 5 ++-- .../social/SocialUserServiceImplTest.java | 17 ++++++----- .../src/main/resources/application-local.yaml | 6 ++-- 13 files changed, 111 insertions(+), 46 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialUserRespDTO.java diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.http b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.http index 51252530b5..648802b809 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.http +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.http @@ -28,6 +28,17 @@ tenant-id: {{appTenentId}} "code": 9999 } +### 请求 /social-login 接口 => 成功 +POST {{appApi}}/member/auth/social-login +Content-Type: application/json +tenant-id: {{appTenentId}} + +{ + "type": 34, + "code": "0e1oc9000CTjFQ1oim200bhtb61oc90g", + "state": "default" +} + ### 请求 /weixin-mini-app-login 接口 => 成功 POST {{appApi}}/member/auth/weixin-mini-app-login Content-Type: application/json @@ -38,7 +49,6 @@ tenant-id: {{appTenentId}} "loginCode": "001frTkl21JUf94VGxol2hSlff1frTkR" } - ### 请求 /logout 接口 => 成功 POST {{appApi}}/member/auth/logout Content-Type: application/json diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/vo/AppAuthLoginRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/vo/AppAuthLoginRespVO.java index 41318fe595..072ec9e4b8 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/vo/AppAuthLoginRespVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/vo/AppAuthLoginRespVO.java @@ -27,4 +27,12 @@ public class AppAuthLoginRespVO { @Schema(description = "过期时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime expiresTime; + /** + * 仅社交登录、社交绑定时会返回 + * + * 为什么需要返回?微信公众号、微信小程序支付需要传递 openid 给支付接口 + */ + @Schema(description = "社交用户 openid", example = "qq768") + private String openid; + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/auth/AuthConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/auth/AuthConvert.java index 16a8e6d4c2..08c9b59ea6 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/auth/AuthConvert.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/auth/AuthConvert.java @@ -25,7 +25,7 @@ public interface AuthConvert { SmsCodeUseReqDTO convert(AppMemberUserResetPasswordReqVO reqVO, SmsSceneEnum scene, String usedIp); SmsCodeUseReqDTO convert(AppAuthSmsLoginReqVO reqVO, Integer scene, String usedIp); - AppAuthLoginRespVO convert(OAuth2AccessTokenRespDTO bean); + AppAuthLoginRespVO convert(OAuth2AccessTokenRespDTO bean, String openid); SmsCodeValidateReqDTO convert(AppAuthSmsValidateReqVO bean); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java index ed89d0a507..e8f816ea67 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java @@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenRespDTO; import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi; import cn.iocoder.yudao.module.system.api.social.SocialUserApi; import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; +import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum; import cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum; import cn.iocoder.yudao.module.system.enums.oauth2.OAuth2ClientConstants; @@ -65,13 +66,14 @@ public class MemberAuthServiceImpl implements MemberAuthService { MemberUserDO user = login0(reqVO.getMobile(), reqVO.getPassword()); // 如果 socialType 非空,说明需要绑定社交用户 + String openid = null; if (reqVO.getSocialType() != null) { - socialUserApi.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(), + openid = socialUserApi.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(), reqVO.getSocialType(), reqVO.getSocialCode(), reqVO.getSocialState())); } // 创建 Token 令牌,记录登录日志 - return createTokenAfterLoginSuccess(user, reqVO.getMobile(), LoginLogTypeEnum.LOGIN_MOBILE); + return createTokenAfterLoginSuccess(user, reqVO.getMobile(), LoginLogTypeEnum.LOGIN_MOBILE, openid); } @Override @@ -86,32 +88,33 @@ public class MemberAuthServiceImpl implements MemberAuthService { Assert.notNull(user, "获取用户失败,结果为空"); // 如果 socialType 非空,说明需要绑定社交用户 + String openid = null; if (reqVO.getSocialType() != null) { - socialUserApi.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(), + openid = socialUserApi.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(), reqVO.getSocialType(), reqVO.getSocialCode(), reqVO.getSocialState())); } // 创建 Token 令牌,记录登录日志 - return createTokenAfterLoginSuccess(user, reqVO.getMobile(), LoginLogTypeEnum.LOGIN_SMS); + return createTokenAfterLoginSuccess(user, reqVO.getMobile(), LoginLogTypeEnum.LOGIN_SMS, openid); } @Override public AppAuthLoginRespVO socialLogin(AppAuthSocialLoginReqVO reqVO) { // 使用 code 授权码,进行登录。然后,获得到绑定的用户编号 - Long userId = socialUserApi.getBindUserId(UserTypeEnum.MEMBER.getValue(), reqVO.getType(), + SocialUserRespDTO socialUser = socialUserApi.getSocialUser(UserTypeEnum.MEMBER.getValue(), reqVO.getType(), reqVO.getCode(), reqVO.getState()); - if (userId == null) { + if (socialUser == null) { throw exception(AUTH_THIRD_LOGIN_NOT_BIND); } // 自动登录 - MemberUserDO user = userService.getUser(userId); + MemberUserDO user = userService.getUser(socialUser.getUserId()); if (user == null) { throw exception(USER_NOT_EXISTS); } // 创建 Token 令牌,记录登录日志 - return createTokenAfterLoginSuccess(user, user.getMobile(), LoginLogTypeEnum.LOGIN_SOCIAL); + return createTokenAfterLoginSuccess(user, user.getMobile(), LoginLogTypeEnum.LOGIN_SOCIAL, socialUser.getOpenid()); } @Override @@ -129,14 +132,15 @@ public class MemberAuthServiceImpl implements MemberAuthService { Assert.notNull(user, "获取用户失败,结果为空"); // 绑定社交用户 - socialUserApi.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(), + String openid = socialUserApi.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(), SocialTypeEnum.WECHAT_MINI_APP.getType(), reqVO.getLoginCode(), "")); // 创建 Token 令牌,记录登录日志 - return createTokenAfterLoginSuccess(user, user.getMobile(), LoginLogTypeEnum.LOGIN_SOCIAL); + return createTokenAfterLoginSuccess(user, user.getMobile(), LoginLogTypeEnum.LOGIN_SOCIAL, openid); } - private AppAuthLoginRespVO createTokenAfterLoginSuccess(MemberUserDO user, String mobile, LoginLogTypeEnum logType) { + private AppAuthLoginRespVO createTokenAfterLoginSuccess(MemberUserDO user, String mobile, + LoginLogTypeEnum logType, String openid) { // 插入登陆日志 createLoginLog(user.getId(), mobile, logType, LoginResultEnum.SUCCESS); // 创建 Token 令牌 @@ -144,7 +148,7 @@ public class MemberAuthServiceImpl implements MemberAuthService { .setUserId(user.getId()).setUserType(getUserType().getValue()) .setClientId(OAuth2ClientConstants.CLIENT_ID_DEFAULT)); // 构建返回结果 - return AuthConvert.INSTANCE.convert(accessTokenRespDTO); + return AuthConvert.INSTANCE.convert(accessTokenRespDTO, openid); } @Override @@ -231,7 +235,7 @@ public class MemberAuthServiceImpl implements MemberAuthService { public AppAuthLoginRespVO refreshToken(String refreshToken) { OAuth2AccessTokenRespDTO accessTokenDO = oauth2TokenApi.refreshAccessToken(refreshToken, OAuth2ClientConstants.CLIENT_ID_DEFAULT); - return AuthConvert.INSTANCE.convert(accessTokenDO); + return AuthConvert.INSTANCE.convert(accessTokenDO, null); } private void createLogoutLog(Long userId) { diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApi.java index 5d42731c29..c7c2fe459f 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApi.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApi.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.system.api.social; import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; +import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO; import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; @@ -27,8 +28,9 @@ public interface SocialUserApi { * 绑定社交用户 * * @param reqDTO 绑定信息 + * @return 社交用户 openid */ - void bindSocialUser(@Valid SocialUserBindReqDTO reqDTO); + String bindSocialUser(@Valid SocialUserBindReqDTO reqDTO); /** * 取消绑定社交用户 @@ -38,16 +40,17 @@ public interface SocialUserApi { void unbindSocialUser(@Valid SocialUserUnbindReqDTO reqDTO); /** - * 获得社交用户的绑定用户编号 - * 注意,返回的是 MemberUser 或者 AdminUser 的 id 编号! + * 获得社交用户 + * * 在认证信息不正确的情况下,也会抛出 {@link ServiceException} 业务异常 * * @param userType 用户类型 * @param type 社交平台的类型 * @param code 授权码 * @param state state - * @return 绑定用户编号 + * @return 社交用户 */ - Long getBindUserId(Integer userType, Integer type, String code, String state); + SocialUserRespDTO getSocialUser(Integer userType, Integer type, + String code, String state); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialUserRespDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialUserRespDTO.java new file mode 100644 index 0000000000..ac25b148eb --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialUserRespDTO.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.system.api.social.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 社交用户 Response DTO + * + * @author 芋道源码 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class SocialUserRespDTO { + + /** + * 社交用户 openid + */ + private String openid; + + /** + * 关联的用户编号 + */ + private Long userId; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApiImpl.java index ae8903135a..d322952af7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApiImpl.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.system.api.social; import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; +import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO; import cn.iocoder.yudao.module.system.service.social.SocialUserService; import org.springframework.stereotype.Service; @@ -26,8 +27,8 @@ public class SocialUserApiImpl implements SocialUserApi { } @Override - public void bindSocialUser(SocialUserBindReqDTO reqDTO) { - socialUserService.bindSocialUser(reqDTO); + public String bindSocialUser(SocialUserBindReqDTO reqDTO) { + return socialUserService.bindSocialUser(reqDTO); } @Override @@ -37,8 +38,8 @@ public class SocialUserApiImpl implements SocialUserApi { } @Override - public Long getBindUserId(Integer userType, Integer type, String code, String state) { - return socialUserService.getBindUserId(userType, type, code, state); + public SocialUserRespDTO getSocialUser(Integer userType, Integer type, String code, String state) { + return socialUserService.getSocialUser(userType, type, code, state); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java index ca34156eb9..37fac09974 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java @@ -9,6 +9,7 @@ import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi; import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; +import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; import cn.iocoder.yudao.module.system.controller.admin.auth.vo.*; import cn.iocoder.yudao.module.system.convert.auth.AuthConvert; import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; @@ -155,14 +156,14 @@ public class AdminAuthServiceImpl implements AdminAuthService { @Override public AuthLoginRespVO socialLogin(AuthSocialLoginReqVO reqVO) { // 使用 code 授权码,进行登录。然后,获得到绑定的用户编号 - Long userId = socialUserService.getBindUserId(UserTypeEnum.ADMIN.getValue(), reqVO.getType(), + SocialUserRespDTO socialUser = socialUserService.getSocialUser(UserTypeEnum.ADMIN.getValue(), reqVO.getType(), reqVO.getCode(), reqVO.getState()); - if (userId == null) { + if (socialUser == null) { throw exception(AUTH_THIRD_LOGIN_NOT_BIND); } // 获得用户 - AdminUserDO user = userService.getUser(userId); + AdminUserDO user = userService.getUser(socialUser.getUserId()); if (user == null) { throw exception(USER_NOT_EXISTS); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java index 6d89897bb7..bc776ec604 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.system.service.social; import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; +import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; @@ -50,8 +51,9 @@ public interface SocialUserService { * 绑定社交用户 * * @param reqDTO 绑定信息 + * @return 社交用户 openid */ - void bindSocialUser(@Valid SocialUserBindReqDTO reqDTO); + String bindSocialUser(@Valid SocialUserBindReqDTO reqDTO); /** * 取消绑定社交用户 @@ -64,15 +66,16 @@ public interface SocialUserService { void unbindSocialUser(Long userId, Integer userType, Integer type, String openid); /** - * 获得社交用户的绑定用户编号 - * 注意,返回的是 MemberUser 或者 AdminUser 的 id 编号! + * 获得社交用户 + * * 在认证信息不正确的情况下,也会抛出 {@link ServiceException} 业务异常 * * @param userType 用户类型 * @param type 社交平台的类型 * @param code 授权码 * @param state state - * @return 绑定用户编号 + * @return 社交用户 */ - Long getBindUserId(Integer userType, Integer type, String code, String state); + SocialUserRespDTO getSocialUser(Integer userType, Integer type, String code, String state); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java index b6999bd01a..bd5548af75 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.util.http.HttpUtils; import cn.iocoder.yudao.framework.social.core.YudaoAuthRequestFactory; import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; +import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserBindDO; import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserBindMapper; @@ -98,7 +99,7 @@ public class SocialUserServiceImpl implements SocialUserService { @Override @Transactional - public void bindSocialUser(SocialUserBindReqDTO reqDTO) { + public String bindSocialUser(SocialUserBindReqDTO reqDTO) { // 获得社交用户 SocialUserDO socialUser = authSocialUser(reqDTO.getType(), reqDTO.getCode(), reqDTO.getState()); Assert.notNull(socialUser, "社交用户不能为空"); @@ -115,6 +116,7 @@ public class SocialUserServiceImpl implements SocialUserService { .userId(reqDTO.getUserId()).userType(reqDTO.getUserType()) .socialUserId(socialUser.getId()).socialType(socialUser.getType()).build(); socialUserBindMapper.insert(socialUserBind); + return socialUser.getOpenid(); } @Override @@ -130,7 +132,7 @@ public class SocialUserServiceImpl implements SocialUserService { } @Override - public Long getBindUserId(Integer userType, Integer type, String code, String state) { + public SocialUserRespDTO getSocialUser(Integer userType, Integer type, String code, String state) { // 获得社交用户 SocialUserDO socialUser = authSocialUser(type, code, state); Assert.notNull(socialUser, "社交用户不能为空"); @@ -141,7 +143,7 @@ public class SocialUserServiceImpl implements SocialUserService { if (socialUserBind == null) { throw exception(AUTH_THIRD_LOGIN_NOT_BIND); } - return socialUserBind.getUserId(); + return new SocialUserRespDTO(socialUser.getOpenid(), socialUserBind.getUserId()); } /** diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImplTest.java index b0331cff2a..1009e92206 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImplTest.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi; import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; +import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; import cn.iocoder.yudao.module.system.controller.admin.auth.vo.*; import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; @@ -235,8 +236,8 @@ public class AdminAuthServiceImplTest extends BaseDbUnitTest { AuthSocialLoginReqVO reqVO = randomPojo(AuthSocialLoginReqVO.class); // mock 方法(绑定的用户编号) Long userId = 1L; - when(socialUserService.getBindUserId(eq(UserTypeEnum.ADMIN.getValue()), eq(reqVO.getType()), - eq(reqVO.getCode()), eq(reqVO.getState()))).thenReturn(userId); + when(socialUserService.getSocialUser(eq(UserTypeEnum.ADMIN.getValue()), eq(reqVO.getType()), + eq(reqVO.getCode()), eq(reqVO.getState()))).thenReturn(new SocialUserRespDTO(randomString(), userId)); // mock(用户) AdminUserDO user = randomPojo(AdminUserDO.class, o -> o.setId(userId)); when(userService.getUser(eq(userId))).thenReturn(user); diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImplTest.java index fcea1a864a..bfbbd40aac 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImplTest.java @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.social.core.YudaoAuthRequestFactory; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; +import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserBindDO; import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserBindMapper; @@ -195,10 +196,11 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest { .setSocialType(SocialTypeEnum.GITEE.getType()).setSocialUserId(socialUser.getId())); // 调用 - socialUserService.bindSocialUser(reqDTO); + String openid = socialUserService.bindSocialUser(reqDTO); // 断言 List socialUserBinds = socialUserBindMapper.selectList(); assertEquals(1, socialUserBinds.size()); + assertEquals(socialUser.getOpenid(), openid); } @Test @@ -232,25 +234,26 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest { } @Test - public void testGetBindUserId() { + public void testGetSocialUser() { // 准备参数 Integer userType = UserTypeEnum.ADMIN.getValue(); Integer type = SocialTypeEnum.GITEE.getType(); String code = "tudou"; String state = "yuanma"; // mock 社交用户 - SocialUserDO socialUser = randomPojo(SocialUserDO.class).setType(type).setCode(code).setState(state); - socialUserMapper.insert(socialUser); + SocialUserDO socialUserDO = randomPojo(SocialUserDO.class).setType(type).setCode(code).setState(state); + socialUserMapper.insert(socialUserDO); // mock 社交用户的绑定 Long userId = randomLong(); SocialUserBindDO socialUserBind = randomPojo(SocialUserBindDO.class).setUserType(userType).setUserId(userId) - .setSocialType(type).setSocialUserId(socialUser.getId()); + .setSocialType(type).setSocialUserId(socialUserDO.getId()); socialUserBindMapper.insert(socialUserBind); // 调用 - Long result = socialUserService.getBindUserId(userType, type, code, state); + SocialUserRespDTO socialUser = socialUserService.getSocialUser(userType, type, code, state); // 断言 - assertEquals(userId, result); + assertEquals(userId, socialUser.getUserId()); + assertEquals(socialUserDO.getOpenid(), socialUser.getOpenid()); } } diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index 5964261ce2..4adfb0a9f3 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -173,8 +173,10 @@ wx: key-prefix: wx # Redis Key 的前缀 http-client-type: HttpClient # 采用 HttpClient 请求微信公众号平台 miniapp: # 小程序配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-miniapp-spring-boot-starter/README.md 文档 - appid: wx62056c0d5e8db250 - secret: 333ae72f41552af1e998fe1f54e1584a +# appid: wx62056c0d5e8db250 +# secret: 333ae72f41552af1e998fe1f54e1584a + appid: wx63c280fe3248a3e7 # wenhualian的接口测试号 + secret: 6f270509224a7ae1296bbf1c8cb97aed config-storage: type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取 key-prefix: wa # Redis Key 的前缀 From 314dee430ed0f90e0e0ef9be3ff6e2b8d9c5529f Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 11 Sep 2023 11:06:42 +0800 Subject: [PATCH 48/48] =?UTF-8?q?bugfix=EF=BC=9A=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E5=85=AC=E4=BC=97=E5=8F=B7=E7=99=BB=E5=BD=95=E6=8A=A5=20access?= =?UTF-8?q?=20token=20=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../social/core/YudaoAuthRequestFactory.java | 9 + .../core/request/AuthWeChatMpRequest.java | 178 ++++++++++++++++++ .../src/main/resources/application-local.yaml | 11 +- 3 files changed, 196 insertions(+), 2 deletions(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/request/AuthWeChatMpRequest.java diff --git a/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/YudaoAuthRequestFactory.java b/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/YudaoAuthRequestFactory.java index 5d5475e843..6cabb0ccdd 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/YudaoAuthRequestFactory.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/YudaoAuthRequestFactory.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.EnumUtil; import cn.hutool.core.util.ReflectUtil; import cn.iocoder.yudao.framework.social.core.enums.AuthExtendSource; import cn.iocoder.yudao.framework.social.core.request.AuthWeChatMiniAppRequest; +import cn.iocoder.yudao.framework.social.core.request.AuthWeChatMpRequest; import com.xingyuv.jushauth.cache.AuthStateCache; import com.xingyuv.jushauth.config.AuthConfig; import com.xingyuv.jushauth.config.AuthSource; @@ -13,6 +14,8 @@ import com.xingyuv.justauth.autoconfigure.JustAuthProperties; import java.lang.reflect.Method; +import static com.xingyuv.jushauth.config.AuthDefaultSource.WECHAT_MP; + /** * 第三方授权拓展 request 工厂类 * 为使得拓展配置 {@link AuthConfig} 和默认配置齐平,所以自定义本工厂类 @@ -55,6 +58,12 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory { } protected AuthRequest getExtendRequest(String source) { + // TODO 芋艿:临时兼容 justauth 迁移的类型不对问题; + if (WECHAT_MP.name().equalsIgnoreCase(source)) { + AuthConfig config = properties.getType().get(WECHAT_MP.name()); + return new AuthWeChatMpRequest(config, authStateCache); + } + AuthExtendSource authExtendSource; try { authExtendSource = EnumUtil.fromString(AuthExtendSource.class, source.toUpperCase()); diff --git a/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/request/AuthWeChatMpRequest.java b/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/request/AuthWeChatMpRequest.java new file mode 100644 index 0000000000..13b77cd357 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/request/AuthWeChatMpRequest.java @@ -0,0 +1,178 @@ +package cn.iocoder.yudao.framework.social.core.request; + +import com.alibaba.fastjson.JSONObject; +import com.xingyuv.jushauth.cache.AuthStateCache; +import com.xingyuv.jushauth.config.AuthConfig; +import com.xingyuv.jushauth.config.AuthDefaultSource; +import com.xingyuv.jushauth.enums.AuthResponseStatus; +import com.xingyuv.jushauth.enums.AuthUserGender; +import com.xingyuv.jushauth.enums.scope.AuthWechatMpScope; +import com.xingyuv.jushauth.exception.AuthException; +import com.xingyuv.jushauth.model.AuthCallback; +import com.xingyuv.jushauth.model.AuthResponse; +import com.xingyuv.jushauth.model.AuthToken; +import com.xingyuv.jushauth.model.AuthUser; +import com.xingyuv.jushauth.request.AuthDefaultRequest; +import com.xingyuv.jushauth.utils.AuthScopeUtils; +import com.xingyuv.jushauth.utils.GlobalAuthUtils; +import com.xingyuv.jushauth.utils.HttpUtils; +import com.xingyuv.jushauth.utils.UrlBuilder; + +/** + * 微信公众平台登录 + * + * @author yangkai.shen (https://xkcoding.com) + * @since 1.1.0 + */ +public class AuthWeChatMpRequest extends AuthDefaultRequest { + public AuthWeChatMpRequest(AuthConfig config) { + super(config, AuthDefaultSource.WECHAT_MP); + } + + public AuthWeChatMpRequest(AuthConfig config, AuthStateCache authStateCache) { + super(config, AuthDefaultSource.WECHAT_MP, authStateCache); + } + + /** + * 微信的特殊性,此时返回的信息同时包含 openid 和 access_token + * + * @param authCallback 回调返回的参数 + * @return 所有信息 + */ + @Override + protected AuthToken getAccessToken(AuthCallback authCallback) { + return this.getToken(accessTokenUrl(authCallback.getCode())); + } + + @Override + protected AuthUser getUserInfo(AuthToken authToken) { + String openId = authToken.getOpenId(); + + String response = doGetUserInfo(authToken); + JSONObject object = JSONObject.parseObject(response); + + this.checkResponse(object); + + String location = String.format("%s-%s-%s", object.getString("country"), object.getString("province"), object.getString("city")); + + if (object.containsKey("unionid")) { + authToken.setUnionId(object.getString("unionid")); + } + + return AuthUser.builder() + .rawUserInfo(object) + .username(object.getString("nickname")) + .nickname(object.getString("nickname")) + .avatar(object.getString("headimgurl")) + .location(location) + .uuid(openId) + .gender(AuthUserGender.getWechatRealGender(object.getString("sex"))) + .token(authToken) + .source(source.toString()) + .build(); + } + + @Override + public AuthResponse refresh(AuthToken oldToken) { + return AuthResponse.builder() + .code(AuthResponseStatus.SUCCESS.getCode()) + .data(this.getToken(refreshTokenUrl(oldToken.getRefreshToken()))) + .build(); + } + + /** + * 检查响应内容是否正确 + * + * @param object 请求响应内容 + */ + private void checkResponse(JSONObject object) { + if (object.containsKey("errcode")) { + throw new AuthException(object.getIntValue("errcode"), object.getString("errmsg")); + } + } + + /** + * 获取token,适用于获取access_token和刷新token + * + * @param accessTokenUrl 实际请求token的地址 + * @return token对象 + */ + private AuthToken getToken(String accessTokenUrl) { + String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl).getBody(); + JSONObject accessTokenObject = JSONObject.parseObject(response); + + this.checkResponse(accessTokenObject); + + return AuthToken.builder() + .accessToken(accessTokenObject.getString("access_token")) + .refreshToken(accessTokenObject.getString("refresh_token")) + .expireIn(accessTokenObject.getIntValue("expires_in")) + .openId(accessTokenObject.getString("openid")) + .scope(accessTokenObject.getString("scope")) + .build(); + } + + /** + * 返回带{@code state}参数的授权url,授权回调时会带上这个{@code state} + * + * @param state state 验证授权流程的参数,可以防止csrf + * @return 返回授权地址 + * @since 1.9.3 + */ + @Override + public String authorize(String state) { + return UrlBuilder.fromBaseUrl(source.authorize()) + .queryParam("appid", config.getClientId()) + .queryParam("redirect_uri", GlobalAuthUtils.urlEncode(config.getRedirectUri())) + .queryParam("response_type", "code") + .queryParam("scope", this.getScopes(",", false, AuthScopeUtils.getDefaultScopes(AuthWechatMpScope.values()))) + .queryParam("state", getRealState(state).concat("#wechat_redirect")) + .build(); + } + + /** + * 返回获取accessToken的url + * + * @param code 授权码 + * @return 返回获取accessToken的url + */ + @Override + protected String accessTokenUrl(String code) { + return UrlBuilder.fromBaseUrl(source.accessToken()) + .queryParam("appid", config.getClientId()) + .queryParam("secret", config.getClientSecret()) + .queryParam("code", code) + .queryParam("grant_type", "authorization_code") + .build(); + } + + /** + * 返回获取userInfo的url + * + * @param authToken 用户授权后的token + * @return 返回获取userInfo的url + */ + @Override + protected String userInfoUrl(AuthToken authToken) { + return UrlBuilder.fromBaseUrl(source.userInfo()) + .queryParam("access_token", authToken.getAccessToken()) + .queryParam("openid", authToken.getOpenId()) + .queryParam("lang", "zh_CN") + .build(); + } + + /** + * 返回获取userInfo的url + * + * @param refreshToken getAccessToken方法返回的refreshToken + * @return 返回获取userInfo的url + */ + @Override + protected String refreshTokenUrl(String refreshToken) { + return UrlBuilder.fromBaseUrl(source.refresh()) + .queryParam("appid", config.getClientId()) + .queryParam("grant_type", "refresh_token") + .queryParam("refresh_token", refreshToken) + .build(); + } +} diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index 4adfb0a9f3..5dc82c68c1 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -165,8 +165,10 @@ debug: false --- #################### 微信公众号、小程序相关配置 #################### wx: mp: # 公众号配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档 - app-id: wx041349c6f39b268b - secret: 5abee519483bc9f8cb37ce280e814bd0 +# app-id: wx041349c6f39b268b +# secret: 5abee519483bc9f8cb37ce280e814bd0 + app-id: wx5b23ba7a5589ecbb # 测试号 + secret: 2a7b3b20c537e52e74afd395eb85f61f # 存储配置,解决 AccessToken 的跨节点的共享 config-storage: type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取 @@ -221,6 +223,11 @@ justauth: client-secret: ${wx.miniapp.secret} ignore-check-redirect-uri: true ignore-check-state: true # 微信小程序,不会使用到 state,所以不进行校验 + WECHAT_MP: # 微信公众号 + client-id: ${wx.mp.app-id} + client-secret: ${wx.mp.secret} + ignore-check-redirect-uri: true + ignore-check-state: true # 微信公众号,未调用后端的 getSocialAuthorizeUrl 方法,所以无法进行 state 校验 TODO 芋艿:后续考虑支持 cache: type: REDIS