From 6ef36d5ca6277d9ad64a824e9af8ec6aefd71a70 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 8 Sep 2023 23:33:02 +0800 Subject: [PATCH] =?UTF-8?q?trade:=20=E5=A2=9E=E5=8A=A0=E5=88=86=E9=94=80?= =?UTF-8?q?=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 000000000..4952e5cad --- /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 000000000..864abe148 --- /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 000000000..1bb520734 --- /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 c4a31cc98..01d0be8c8 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 a5eda05b0..1df7e7be8 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 4d15aad1f..461a1a5c5 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)) ); }