Commit 77daa0085ed7c42b8d0f2c7689fed678ec3f0b02
1 parent
cddeb372
trade: 分销业务review代码修改
Showing
15 changed files
with
103 additions
and
34 deletions
yudao-module-mall/yudao-module-trade-api/pom.xml
| @@ -21,6 +21,13 @@ | @@ -21,6 +21,13 @@ | ||
| 21 | <groupId>cn.iocoder.boot</groupId> | 21 | <groupId>cn.iocoder.boot</groupId> |
| 22 | <artifactId>yudao-common</artifactId> | 22 | <artifactId>yudao-common</artifactId> |
| 23 | </dependency> | 23 | </dependency> |
| 24 | + | ||
| 25 | + <!-- 参数校验 --> | ||
| 26 | + <dependency> | ||
| 27 | + <groupId>org.springframework.boot</groupId> | ||
| 28 | + <artifactId>spring-boot-starter-validation</artifactId> | ||
| 29 | + <optional>true</optional> | ||
| 30 | + </dependency> | ||
| 24 | </dependencies> | 31 | </dependencies> |
| 25 | 32 | ||
| 26 | </project> | 33 | </project> |
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/BrokerageApi.java
| 1 | package cn.iocoder.yudao.module.trade.api.brokerage; | 1 | package cn.iocoder.yudao.module.trade.api.brokerage; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; | ||
| 3 | import cn.iocoder.yudao.module.trade.api.brokerage.dto.BrokerageUserDTO; | 4 | import cn.iocoder.yudao.module.trade.api.brokerage.dto.BrokerageUserDTO; |
| 4 | 5 | ||
| 6 | +import javax.validation.constraints.NotNull; | ||
| 7 | +import java.time.LocalDateTime; | ||
| 8 | + | ||
| 5 | /** | 9 | /** |
| 6 | * 分销 API 接口 | 10 | * 分销 API 接口 |
| 7 | * | 11 | * |
| @@ -18,6 +22,20 @@ public interface BrokerageApi { | @@ -18,6 +22,20 @@ public interface BrokerageApi { | ||
| 18 | BrokerageUserDTO getBrokerageUser(Long userId); | 22 | BrokerageUserDTO getBrokerageUser(Long userId); |
| 19 | 23 | ||
| 20 | /** | 24 | /** |
| 25 | + * 【会员】绑定推广员 | ||
| 26 | + * | ||
| 27 | + * @param userId 用户编号 | ||
| 28 | + * @param bindUserId 推广员编号 | ||
| 29 | + * @param registerTime 用户注册时间 | ||
| 30 | + * @return 是否绑定 | ||
| 31 | + */ | ||
| 32 | + default boolean bindUser(@NotNull Long userId, @NotNull Long bindUserId, @NotNull LocalDateTime registerTime) { | ||
| 33 | + // 注册时间在30秒内的,都算新用户 | ||
| 34 | + boolean isNewUser = LocalDateTimeUtils.afterNow(registerTime.minusSeconds(30)); | ||
| 35 | + return bindUser(userId, bindUserId, isNewUser); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + /** | ||
| 21 | * 绑定推广员 | 39 | * 绑定推广员 |
| 22 | * | 40 | * |
| 23 | * @param userId 用户编号 | 41 | * @param userId 用户编号 |
| @@ -25,5 +43,5 @@ public interface BrokerageApi { | @@ -25,5 +43,5 @@ public interface BrokerageApi { | ||
| 25 | * @param isNewUser 是否为新用户 | 43 | * @param isNewUser 是否为新用户 |
| 26 | * @return 是否绑定 | 44 | * @return 是否绑定 |
| 27 | */ | 45 | */ |
| 28 | - boolean bindUser(Long userId, Long bindUserId, Boolean isNewUser); | 46 | + boolean bindUser(@NotNull Long userId, @NotNull Long bindUserId, @NotNull Boolean isNewUser); |
| 29 | } | 47 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java
| @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.trade.convert.brokerage.user.BrokerageUserConvert | @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.trade.convert.brokerage.user.BrokerageUserConvert | ||
| 9 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; | 9 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; |
| 10 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; | 10 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; |
| 11 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; | 11 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; |
| 12 | +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageUserTypeEnum; | ||
| 12 | import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; | 13 | import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; |
| 13 | import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService; | 14 | import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService; |
| 14 | import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService; | 15 | import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService; |
| @@ -95,7 +96,7 @@ public class BrokerageUserController { | @@ -95,7 +96,7 @@ public class BrokerageUserController { | ||
| 95 | // 合计推广用户数量 | 96 | // 合计推广用户数量 |
| 96 | Map<Long, Long> brokerageUserCountMap = convertMap(userIds, | 97 | Map<Long, Long> brokerageUserCountMap = convertMap(userIds, |
| 97 | userId -> userId, | 98 | userId -> userId, |
| 98 | - userId -> brokerageUserService.getBrokerageUserCountByBindUserId(userId)); | 99 | + userId -> brokerageUserService.getBrokerageUserCountByBindUserId(userId, BrokerageUserTypeEnum.ALL)); |
| 99 | 100 | ||
| 100 | // todo 合计提现 | 101 | // todo 合计提现 |
| 101 | 102 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserRespVO.java
| @@ -28,7 +28,7 @@ public class BrokerageUserRespVO extends BrokerageUserBaseVO { | @@ -28,7 +28,7 @@ public class BrokerageUserRespVO extends BrokerageUserBaseVO { | ||
| 28 | 28 | ||
| 29 | // ========== 推广信息 ========== | 29 | // ========== 推广信息 ========== |
| 30 | 30 | ||
| 31 | - @Schema(description = "推广用户数量(一级)", example = "20019") | 31 | + @Schema(description = "推广用户数量", example = "20019") |
| 32 | private Integer brokerageUserCount; | 32 | private Integer brokerageUserCount; |
| 33 | @Schema(description = "推广订单数量", example = "20019") | 33 | @Schema(description = "推广订单数量", example = "20019") |
| 34 | private Integer brokerageOrderCount; | 34 | private Integer brokerageOrderCount; |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java
| @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; | @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; | ||
| 6 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageProductPriceRespVO; | 6 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageProductPriceRespVO; |
| 7 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordPageReqVO; | 7 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordPageReqVO; |
| 8 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordRespVO; | 8 | import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordRespVO; |
| 9 | +import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService; | ||
| 9 | import io.swagger.v3.oas.annotations.Operation; | 10 | import io.swagger.v3.oas.annotations.Operation; |
| 10 | import io.swagger.v3.oas.annotations.tags.Tag; | 11 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 11 | import lombok.extern.slf4j.Slf4j; | 12 | import lombok.extern.slf4j.Slf4j; |
| @@ -15,10 +16,12 @@ import org.springframework.web.bind.annotation.RequestMapping; | @@ -15,10 +16,12 @@ import org.springframework.web.bind.annotation.RequestMapping; | ||
| 15 | import org.springframework.web.bind.annotation.RequestParam; | 16 | import org.springframework.web.bind.annotation.RequestParam; |
| 16 | import org.springframework.web.bind.annotation.RestController; | 17 | import org.springframework.web.bind.annotation.RestController; |
| 17 | 18 | ||
| 19 | +import javax.annotation.Resource; | ||
| 18 | import javax.validation.Valid; | 20 | import javax.validation.Valid; |
| 19 | import java.time.LocalDateTime; | 21 | import java.time.LocalDateTime; |
| 20 | 22 | ||
| 21 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 23 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 24 | +import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId; | ||
| 22 | import static java.util.Arrays.asList; | 25 | import static java.util.Arrays.asList; |
| 23 | 26 | ||
| 24 | @Tag(name = "用户 APP - 分销用户") | 27 | @Tag(name = "用户 APP - 分销用户") |
| @@ -27,6 +30,8 @@ import static java.util.Arrays.asList; | @@ -27,6 +30,8 @@ import static java.util.Arrays.asList; | ||
| 27 | @Validated | 30 | @Validated |
| 28 | @Slf4j | 31 | @Slf4j |
| 29 | public class AppBrokerageRecordController { | 32 | public class AppBrokerageRecordController { |
| 33 | + @Resource | ||
| 34 | + private BrokerageUserService brokerageUserService; | ||
| 30 | 35 | ||
| 31 | // TODO 芋艿:临时 mock => | 36 | // TODO 芋艿:临时 mock => |
| 32 | @GetMapping("/page") | 37 | @GetMapping("/page") |
| @@ -46,7 +51,7 @@ public class AppBrokerageRecordController { | @@ -46,7 +51,7 @@ public class AppBrokerageRecordController { | ||
| 46 | @Operation(summary = "获得商品的分销金额") | 51 | @Operation(summary = "获得商品的分销金额") |
| 47 | public CommonResult<AppBrokerageProductPriceRespVO> getProductBrokeragePrice(@RequestParam("spuId") Long spuId) { | 52 | public CommonResult<AppBrokerageProductPriceRespVO> getProductBrokeragePrice(@RequestParam("spuId") Long spuId) { |
| 48 | AppBrokerageProductPriceRespVO respVO = new AppBrokerageProductPriceRespVO(); | 53 | AppBrokerageProductPriceRespVO respVO = new AppBrokerageProductPriceRespVO(); |
| 49 | - respVO.setEnabled(true); // TODO @疯狂:需要开启分销 + 人允许分销 | 54 | + respVO.setEnabled(brokerageUserService.getUserBrokerageEnabled(getLoginUserId())); |
| 50 | respVO.setBrokerageMinPrice(1); | 55 | respVO.setBrokerageMinPrice(1); |
| 51 | respVO.setBrokerageMaxPrice(2); | 56 | respVO.setBrokerageMaxPrice(2); |
| 52 | return success(respVO); | 57 | return success(respVO); |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java
| @@ -19,7 +19,7 @@ public class AppBrokerageUserMySummaryRespVO { | @@ -19,7 +19,7 @@ public class AppBrokerageUserMySummaryRespVO { | ||
| 19 | @Schema(description = "冻结的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "234") | 19 | @Schema(description = "冻结的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "234") |
| 20 | private Integer frozenPrice; | 20 | private Integer frozenPrice; |
| 21 | 21 | ||
| 22 | - @Schema(description = "分销用户数量(一级)", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") | 22 | + @Schema(description = "分销用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") |
| 23 | private Integer firstBrokerageUserCount; | 23 | private Integer firstBrokerageUserCount; |
| 24 | 24 | ||
| 25 | @Schema(description = "分销用户数量(二级)", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") | 25 | @Schema(description = "分销用户数量(二级)", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java
| @@ -33,7 +33,6 @@ public interface BrokerageRecordConvert { | @@ -33,7 +33,6 @@ public interface BrokerageRecordConvert { | ||
| 33 | 33 | ||
| 34 | PageResult<BrokerageRecordRespVO> convertPage(PageResult<BrokerageRecordDO> page); | 34 | PageResult<BrokerageRecordRespVO> convertPage(PageResult<BrokerageRecordDO> page); |
| 35 | 35 | ||
| 36 | - // TODO @疯狂:可能 title 不是很固化,会存在类似:沐晴成功购买《XXX JVM 实战》 | ||
| 37 | default BrokerageRecordDO convert(BrokerageUserDO user, BrokerageRecordBizTypeEnum bizType, String bizId, | 36 | default BrokerageRecordDO convert(BrokerageUserDO user, BrokerageRecordBizTypeEnum bizType, String bizId, |
| 38 | Integer brokerageFrozenDays, int brokeragePrice, LocalDateTime unfreezeTime, | 37 | Integer brokerageFrozenDays, int brokeragePrice, LocalDateTime unfreezeTime, |
| 39 | String title, Long sourceUserId, Integer sourceUserType) { | 38 | String title, Long sourceUserId, Integer sourceUserType) { |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java
| @@ -39,7 +39,7 @@ public interface BrokerageUserConvert { | @@ -39,7 +39,7 @@ public interface BrokerageUserConvert { | ||
| 39 | // 用户信息 | 39 | // 用户信息 |
| 40 | copyTo(userMap.get(vo.getId()), vo); | 40 | copyTo(userMap.get(vo.getId()), vo); |
| 41 | 41 | ||
| 42 | - // 推广用户数量(一级) | 42 | + // 推广用户数量 |
| 43 | vo.setBrokerageUserCount(MapUtil.getInt(brokerageUserCountMap, vo.getId(), 0)); | 43 | vo.setBrokerageUserCount(MapUtil.getInt(brokerageUserCountMap, vo.getId(), 0)); |
| 44 | // 推广订单数量、推广订单金额 | 44 | // 推广订单数量、推广订单金额 |
| 45 | Optional<UserBrokerageSummaryBO> orderSummaryOptional = Optional.ofNullable(userOrderSummaryMap.get(vo.getId())); | 45 | Optional<UserBrokerageSummaryBO> orderSummaryOptional = Optional.ofNullable(userOrderSummaryMap.get(vo.getId())); |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java
| @@ -7,7 +7,6 @@ import cn.iocoder.yudao.framework.common.util.string.StrUtils; | @@ -7,7 +7,6 @@ import cn.iocoder.yudao.framework.common.util.string.StrUtils; | ||
| 7 | import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; | 7 | import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; |
| 8 | import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; | 8 | import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; |
| 9 | import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; | 9 | import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; |
| 10 | -import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; | ||
| 11 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; | 10 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| 12 | import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; | 11 | import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; |
| 13 | import cn.iocoder.yudao.module.pay.enums.DictTypeConstants; | 12 | import cn.iocoder.yudao.module.pay.enums.DictTypeConstants; |
| @@ -28,9 +27,11 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; | @@ -28,9 +27,11 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; | ||
| 28 | import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; | 27 | import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; |
| 29 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; | 28 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; |
| 30 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; | 29 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; |
| 30 | +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; | ||
| 31 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum; | 31 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum; |
| 32 | import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; | 32 | import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; |
| 33 | import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; | 33 | import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; |
| 34 | +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; | ||
| 34 | import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; | 35 | import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; |
| 35 | import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; | 36 | import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; |
| 36 | import org.mapstruct.Mapper; | 37 | import org.mapstruct.Mapper; |
| @@ -282,6 +283,7 @@ public interface TradeOrderConvert { | @@ -282,6 +283,7 @@ public interface TradeOrderConvert { | ||
| 282 | .setSourceUserId(item.getUserId()) | 283 | .setSourceUserId(item.getUserId()) |
| 283 | .setBasePrice(item.getPayPrice() * item.getCount()) | 284 | .setBasePrice(item.getPayPrice() * item.getCount()) |
| 284 | .setFirstFixedPrice(sku.getSubCommissionFirstPrice()) | 285 | .setFirstFixedPrice(sku.getSubCommissionFirstPrice()) |
| 285 | - .setSecondFixedPrice(sku.getSubCommissionSecondPrice()); | 286 | + .setSecondFixedPrice(sku.getSubCommissionSecondPrice()) |
| 287 | + .setTitle(BrokerageRecordBizTypeEnum.ORDER.getTitle()); | ||
| 286 | } | 288 | } |
| 287 | } | 289 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/BrokerageRecordMapper.java
| @@ -48,13 +48,13 @@ public interface BrokerageRecordMapper extends BaseMapperX<BrokerageRecordDO> { | @@ -48,13 +48,13 @@ public interface BrokerageRecordMapper extends BaseMapperX<BrokerageRecordDO> { | ||
| 48 | .eq(BrokerageRecordDO::getStatus, status)); | 48 | .eq(BrokerageRecordDO::getStatus, status)); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | - default BrokerageRecordDO selectByBizTypeAndBizId(Integer bizType, String bizId) { | 51 | + default BrokerageRecordDO selectByBizTypeAndBizIdAndUserId(Integer bizType, String bizId, Long userId) { |
| 52 | return selectOne(BrokerageRecordDO::getBizType, bizType, | 52 | return selectOne(BrokerageRecordDO::getBizType, bizType, |
| 53 | - BrokerageRecordDO::getBizId, bizId); | 53 | + BrokerageRecordDO::getBizId, bizId, |
| 54 | + BrokerageRecordDO::getUserId, userId); | ||
| 54 | } | 55 | } |
| 55 | 56 | ||
| 56 | - // TODO @疯狂:mysql 关键字,大写哈;这样看起来清晰点;例如说 SELECT COUNT(1) | ||
| 57 | - @Select("select count(1), sum(price) from trade_brokerage_record where user_id = #{userId} and biz_type = #{bizType} and status = #{status}") | 57 | + @Select("SELECT COUNT(1), SUM(price) FROM trade_brokerage_record WHERE user_id = #{userId} AND biz_type = #{bizType} AND status = #{status}") |
| 58 | UserBrokerageSummaryBO selectCountAndSumPriceByUserIdAndBizTypeAndStatus(@Param("userId") Long userId, | 58 | UserBrokerageSummaryBO selectCountAndSumPriceByUserIdAndBizTypeAndStatus(@Param("userId") Long userId, |
| 59 | @Param("bizType") Integer bizType, | 59 | @Param("bizType") Integer bizType, |
| 60 | @Param("status") Integer status); | 60 | @Param("status") Integer status); |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java
| @@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageUserTypeEnum; | @@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageUserTypeEnum; | ||
| 11 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 11 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| 12 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | 12 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| 13 | import org.apache.ibatis.annotations.Mapper; | 13 | import org.apache.ibatis.annotations.Mapper; |
| 14 | +import org.apache.ibatis.annotations.Select; | ||
| 14 | 15 | ||
| 15 | /** | 16 | /** |
| 16 | * 分销用户 Mapper | 17 | * 分销用户 Mapper |
| @@ -135,4 +136,10 @@ public interface BrokerageUserMapper extends BaseMapperX<BrokerageUserDO> { | @@ -135,4 +136,10 @@ public interface BrokerageUserMapper extends BaseMapperX<BrokerageUserDO> { | ||
| 135 | .set(BrokerageUserDO::getBrokerageEnabled, false).set(BrokerageUserDO::getBrokerageTime, null)); | 136 | .set(BrokerageUserDO::getBrokerageEnabled, false).set(BrokerageUserDO::getBrokerageTime, null)); |
| 136 | } | 137 | } |
| 137 | 138 | ||
| 139 | + default Long selectCountByBindUserId(Long bindUserId) { | ||
| 140 | + return selectCount(BrokerageUserDO::getBindUserId, bindUserId); | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + @Select("SELECT COUNT(1) from trade_brokerage_user WHERE bind_user_id IN (SELECT id FROM trade_brokerage_user WHERE bind_user_id = #{bindUserId})") | ||
| 144 | + Long selectCountByBindUserIdInBindUserId(Long bindUserId); | ||
| 138 | } | 145 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageAddReqBO.java
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java
| @@ -91,9 +91,8 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { | @@ -91,9 +91,8 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { | ||
| 91 | @Override | 91 | @Override |
| 92 | @Transactional(rollbackFor = Exception.class) | 92 | @Transactional(rollbackFor = Exception.class) |
| 93 | public void cancelBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId) { | 93 | public void cancelBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId) { |
| 94 | - // TODO @疯狂:userId 加进去查询,会不会更好一点?万一穿错参数; | ||
| 95 | - BrokerageRecordDO record = brokerageRecordMapper.selectByBizTypeAndBizId(bizType.getType(), bizId); | ||
| 96 | - if (record == null || ObjectUtil.notEqual(record.getUserId(), userId)) { | 94 | + BrokerageRecordDO record = brokerageRecordMapper.selectByBizTypeAndBizIdAndUserId(bizType.getType(), bizId, userId); |
| 95 | + if (record == null) { | ||
| 97 | log.error("[cancelBrokerage][userId({})][bizId({}) 更新为已失效失败:记录不存在]", userId, bizId); | 96 | log.error("[cancelBrokerage][userId({})][bizId({}) 更新为已失效失败:记录不存在]", userId, bizId); |
| 98 | return; | 97 | return; |
| 99 | } | 98 | } |
| @@ -167,7 +166,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { | @@ -167,7 +166,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { | ||
| 167 | continue; | 166 | continue; |
| 168 | } | 167 | } |
| 169 | records.add(BrokerageRecordConvert.INSTANCE.convert(user, bizType, item.getBizId(), | 168 | records.add(BrokerageRecordConvert.INSTANCE.convert(user, bizType, item.getBizId(), |
| 170 | - brokerageFrozenDays, brokeragePerItem, unfreezeTime, bizType.getTitle(), | 169 | + brokerageFrozenDays, brokeragePerItem, unfreezeTime, item.getTitle(), |
| 171 | item.getSourceUserId(), sourceUserType.getType())); | 170 | item.getSourceUserId(), sourceUserType.getType())); |
| 172 | totalBrokerage += brokeragePerItem; | 171 | totalBrokerage += brokeragePerItem; |
| 173 | } | 172 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java
| @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.trade.service.brokerage.user; | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.trade.service.brokerage.user; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO; | 4 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO; |
| 5 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; | 5 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; |
| 6 | +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageUserTypeEnum; | ||
| 6 | 7 | ||
| 7 | import java.util.Collection; | 8 | import java.util.Collection; |
| 8 | import java.util.List; | 9 | import java.util.List; |
| @@ -86,14 +87,14 @@ public interface BrokerageUserService { | @@ -86,14 +87,14 @@ public interface BrokerageUserService { | ||
| 86 | */ | 87 | */ |
| 87 | void updateFrozenPriceDecrAndPriceIncr(Long id, Integer frozenPrice); | 88 | void updateFrozenPriceDecrAndPriceIncr(Long id, Integer frozenPrice); |
| 88 | 89 | ||
| 89 | - // TODO @疯狂:这个后面可能要支持下,二级 | ||
| 90 | /** | 90 | /** |
| 91 | - * 获得推广用户数量(一级) | 91 | + * 获得推广用户数量 |
| 92 | * | 92 | * |
| 93 | * @param bindUserId 绑定的推广员编号 | 93 | * @param bindUserId 绑定的推广员编号 |
| 94 | + * @param userType 用户类型 | ||
| 94 | * @return 推广用户数量 | 95 | * @return 推广用户数量 |
| 95 | */ | 96 | */ |
| 96 | - Long getBrokerageUserCountByBindUserId(Long bindUserId); | 97 | + Long getBrokerageUserCountByBindUserId(Long bindUserId, BrokerageUserTypeEnum userType); |
| 97 | 98 | ||
| 98 | /** | 99 | /** |
| 99 | * 【会员】绑定推广员 | 100 | * 【会员】绑定推广员 |
| @@ -105,4 +106,11 @@ public interface BrokerageUserService { | @@ -105,4 +106,11 @@ public interface BrokerageUserService { | ||
| 105 | */ | 106 | */ |
| 106 | boolean bindBrokerageUser(Long userId, Long bindUserId, Boolean isNewUser); | 107 | boolean bindBrokerageUser(Long userId, Long bindUserId, Boolean isNewUser); |
| 107 | 108 | ||
| 109 | + /** | ||
| 110 | + * 获取用户是否有分销资格 | ||
| 111 | + * | ||
| 112 | + * @param userId 用户编号 | ||
| 113 | + * @return 是否有分销资格 | ||
| 114 | + */ | ||
| 115 | + Boolean getUserBrokerageEnabled(Long userId); | ||
| 108 | } | 116 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java
| @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; | @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; | ||
| 9 | import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.BrokerageUserMapper; | 9 | import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.BrokerageUserMapper; |
| 10 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageBindModeEnum; | 10 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageBindModeEnum; |
| 11 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageEnabledConditionEnum; | 11 | import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageEnabledConditionEnum; |
| 12 | +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageUserTypeEnum; | ||
| 12 | import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; | 13 | import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; |
| 13 | import org.springframework.stereotype.Service; | 14 | import org.springframework.stereotype.Service; |
| 14 | import org.springframework.validation.annotation.Validated; | 15 | import org.springframework.validation.annotation.Validated; |
| @@ -131,19 +132,23 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { | @@ -131,19 +132,23 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { | ||
| 131 | } | 132 | } |
| 132 | 133 | ||
| 133 | @Override | 134 | @Override |
| 134 | - public Long getBrokerageUserCountByBindUserId(Long bindUserId) { | ||
| 135 | - // TODO @疯狂:mapper 封装下哈;不直接在 service 调用这种基础 mapper 的基础方法 | ||
| 136 | - return brokerageUserMapper.selectCount(BrokerageUserDO::getBindUserId, bindUserId); | 135 | + public Long getBrokerageUserCountByBindUserId(Long bindUserId, BrokerageUserTypeEnum userType) { |
| 136 | + switch (userType) { | ||
| 137 | + case ALL: | ||
| 138 | + Long firstCount = brokerageUserMapper.selectCountByBindUserId(bindUserId); | ||
| 139 | + Long secondCount = brokerageUserMapper.selectCountByBindUserIdInBindUserId(bindUserId); | ||
| 140 | + return firstCount + secondCount; | ||
| 141 | + case FIRST: | ||
| 142 | + return brokerageUserMapper.selectCountByBindUserId(bindUserId); | ||
| 143 | + case SECOND: | ||
| 144 | + return brokerageUserMapper.selectCountByBindUserIdInBindUserId(bindUserId); | ||
| 145 | + default: | ||
| 146 | + return 0L; | ||
| 147 | + } | ||
| 137 | } | 148 | } |
| 138 | 149 | ||
| 139 | - // TODO @疯狂:因为现在 user 会存在使用验证码直接注册,所以 isNewUser 不太好传递;我们是不是可以约定绑定的时间,createTime 在 30 秒内,就认为新用户; | ||
| 140 | @Override | 150 | @Override |
| 141 | public boolean bindBrokerageUser(Long userId, Long bindUserId, Boolean isNewUser) { | 151 | public boolean bindBrokerageUser(Long userId, Long bindUserId, Boolean isNewUser) { |
| 142 | - // TODO @疯狂:userId 为空,搞到参数校验里哇; | ||
| 143 | - if (userId == null) { | ||
| 144 | - throw exception(0); | ||
| 145 | - } | ||
| 146 | - | ||
| 147 | // 1. 获得分销用户 | 152 | // 1. 获得分销用户 |
| 148 | boolean isNewBrokerageUser = false; | 153 | boolean isNewBrokerageUser = false; |
| 149 | BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(userId); | 154 | BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(userId); |
| @@ -153,7 +158,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { | @@ -153,7 +158,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { | ||
| 153 | } | 158 | } |
| 154 | 159 | ||
| 155 | // 2.1 校验是否能绑定用户 | 160 | // 2.1 校验是否能绑定用户 |
| 156 | - boolean validated = isUserCanBind(brokerageUser, bindUserId, isNewUser); | 161 | + boolean validated = isUserCanBind(brokerageUser, isNewUser); |
| 157 | if (!validated) { | 162 | if (!validated) { |
| 158 | return false; | 163 | return false; |
| 159 | } | 164 | } |
| @@ -163,10 +168,9 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { | @@ -163,10 +168,9 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { | ||
| 163 | if (isNewBrokerageUser) { | 168 | if (isNewBrokerageUser) { |
| 164 | Integer enabledCondition = tradeConfigService.getTradeConfig().getBrokerageEnabledCondition(); | 169 | Integer enabledCondition = tradeConfigService.getTradeConfig().getBrokerageEnabledCondition(); |
| 165 | if (BrokerageEnabledConditionEnum.ALL.getCondition().equals(enabledCondition)) { // 人人分销:用户默认就有分销资格 | 170 | if (BrokerageEnabledConditionEnum.ALL.getCondition().equals(enabledCondition)) { // 人人分销:用户默认就有分销资格 |
| 166 | - // TODO @疯狂:应该设置下 brokerageTime,而不是 bindUserTime | ||
| 167 | - brokerageUser.setBrokerageEnabled(true).setBindUserTime(LocalDateTime.now()); | 171 | + brokerageUser.setBrokerageEnabled(true).setBrokerageTime(LocalDateTime.now()); |
| 168 | } | 172 | } |
| 169 | - // TODO @疯狂:这里是不是要设置 bindUserId、bindUserTime 字段哈; | 173 | + brokerageUser.setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now()); |
| 170 | brokerageUserMapper.insert(brokerageUser); | 174 | brokerageUserMapper.insert(brokerageUser); |
| 171 | } else { | 175 | } else { |
| 172 | brokerageUserMapper.updateById(new BrokerageUserDO().setId(userId) | 176 | brokerageUserMapper.updateById(new BrokerageUserDO().setId(userId) |
| @@ -175,7 +179,21 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { | @@ -175,7 +179,21 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { | ||
| 175 | return true; | 179 | return true; |
| 176 | } | 180 | } |
| 177 | 181 | ||
| 178 | - private boolean isUserCanBind(BrokerageUserDO user, Long bindUserId, Boolean isNewUser) { | 182 | + @Override |
| 183 | + public Boolean getUserBrokerageEnabled(Long userId) { | ||
| 184 | + // 全局分销功能是否开启 | ||
| 185 | + TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig(); | ||
| 186 | + if (tradeConfig == null || !BooleanUtil.isTrue(tradeConfig.getBrokerageEnabled())) { | ||
| 187 | + return false; | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + // 用户是否有分销资格 | ||
| 191 | + return Optional.ofNullable(getBrokerageUser(userId)) | ||
| 192 | + .map(BrokerageUserDO::getBrokerageEnabled) | ||
| 193 | + .orElse(false); | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + private boolean isUserCanBind(BrokerageUserDO user, Boolean isNewUser) { | ||
| 179 | // 校验分销功能是否启用 | 197 | // 校验分销功能是否启用 |
| 180 | TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig(); | 198 | TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig(); |
| 181 | if (tradeConfig == null || !BooleanUtil.isTrue(tradeConfig.getBrokerageEnabled())) { | 199 | if (tradeConfig == null || !BooleanUtil.isTrue(tradeConfig.getBrokerageEnabled())) { |