mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	code review:分销逻辑
This commit is contained in:
		| @@ -147,4 +147,5 @@ public class ProductSpuRespDTO { | ||||
|      * true - 自行设置 | ||||
|      */ | ||||
|     private Boolean subCommissionType; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -179,6 +179,7 @@ public class ProductSpuDO extends BaseDO { | ||||
|     @TableField(typeHandler = JacksonTypeHandler.class) | ||||
|     private List<Long> giveCouponTemplateIds; | ||||
|  | ||||
|     // TODO @puhui999:字段估计要改成 brokerageType | ||||
|     /** | ||||
|      * 分销类型 | ||||
|      * | ||||
|   | ||||
| @@ -8,4 +8,5 @@ package cn.iocoder.yudao.module.trade.enums; | ||||
| public interface DictTypeConstants { | ||||
|  | ||||
|     String BROKERAGE_WITHDRAW_STATUS = "brokerage_withdraw_status"; // 佣金提现状态 | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -92,6 +92,7 @@ public class BrokerageUserController { | ||||
|         Set<Long> userIds = convertSet(pageResult.getList(), BrokerageUserDO::getId); | ||||
|         // 查询用户信息 | ||||
|         Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(userIds); | ||||
|         // TODO @疯狂:看看下面两个 getBrokerageUserCountByBindUserId、getWithdrawSummaryByUserId 有没可能一次性出结果,不然 n 次有点太花性能了; | ||||
|         // 合计分佣订单 | ||||
|         Map<Long, UserBrokerageSummaryBO> userOrderSummaryMap = convertMap(userIds, | ||||
|                 userId -> userId, | ||||
| @@ -101,13 +102,13 @@ public class BrokerageUserController { | ||||
|         Map<Long, Long> brokerageUserCountMap = convertMap(userIds, | ||||
|                 userId -> userId, | ||||
|                 userId -> brokerageUserService.getBrokerageUserCountByBindUserId(userId, null)); | ||||
|  | ||||
|         // 合计提现 | ||||
|         Map<Long, UserWithdrawSummaryBO> withdrawMap = convertMap(userIds, | ||||
|                 userId -> userId, | ||||
|                 userId -> brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS)); | ||||
|  | ||||
|         return success(BrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap, withdrawMap)); | ||||
|         // 拼接返回 | ||||
|         return success(BrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, | ||||
|                 userOrderSummaryMap, withdrawMap)); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -77,13 +77,15 @@ public class AppBrokerageUserController { | ||||
|     @PreAuthenticated | ||||
|     public CommonResult<AppBrokerageUserMySummaryRespVO> getBrokerageUserSummary() { | ||||
|         Long userId = getLoginUserId(); | ||||
|         // TODO @疯狂:后面这种,要不也改成 convert;感觉 controller 这样更容易看到整体;核心其实是 86、8/87、9/90、9/91 这阶段 | ||||
|         // 统计 yesterdayPrice、withdrawPrice、firstBrokerageUserCount、secondBrokerageUserCount 字段 | ||||
|         LocalDateTime yesterday = LocalDateTime.now().minusDays(1); | ||||
|         LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday); | ||||
|         LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday); | ||||
|         AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO() | ||||
|                 .setYesterdayPrice(brokerageRecordService.getSummaryPriceByUserId(userId, BrokerageRecordBizTypeEnum.ORDER.getType(), beginTime, endTime)) | ||||
|                 .setWithdrawPrice(Optional.ofNullable(brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS)).map(UserWithdrawSummaryBO::getPrice).orElse(0)) | ||||
|                 .setWithdrawPrice(Optional.ofNullable(brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS)) | ||||
|                         .map(UserWithdrawSummaryBO::getPrice).orElse(0)) | ||||
|                 .setBrokeragePrice(0).setFrozenPrice(0) | ||||
|                 .setFirstBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1)) | ||||
|                 .setSecondBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2)); | ||||
|   | ||||
| @@ -41,4 +41,5 @@ public interface BrokerageWithdrawMapper extends BaseMapperX<BrokerageWithdrawDO | ||||
|             "WHERE user_id = #{userId} AND status = #{status} AND deleted = FALSE") | ||||
|     UserWithdrawSummaryBO selectCountAndSumPriceByUserIdAndStatus(@Param("userId") Long userId, | ||||
|                                                                   @Param("status") Integer status); | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -315,37 +315,34 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { | ||||
|  | ||||
|         // 2.1 校验分销功能是否开启 | ||||
|         TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig(); | ||||
|         if (tradeConfig == null || !BooleanUtil.isTrue(tradeConfig.getBrokerageEnabled())) { | ||||
|         if (tradeConfig == null || BooleanUtil.isFalse(tradeConfig.getBrokerageEnabled())) { | ||||
|             return respVO; | ||||
|         } | ||||
|  | ||||
|         // 2.2 校验用户是否有分销资格 | ||||
|         respVO.setEnabled(brokerageUserService.getUserBrokerageEnabled(getLoginUserId())); | ||||
|         if (!BooleanUtil.isTrue(respVO.getEnabled())) { | ||||
|         if (BooleanUtil.isFalse(respVO.getEnabled())) { | ||||
|             return respVO; | ||||
|         } | ||||
|  | ||||
|         Integer fixedMinPrice = 0; | ||||
|         Integer fixedMaxPrice = 0; | ||||
|         Integer spuMinPrice = 0; | ||||
|         Integer spuMaxPrice = 0; | ||||
|         // 2.3 校验商品是否存在 | ||||
|         ProductSpuRespDTO spu = productSpuApi.getSpu(spuId); | ||||
|         if (spu == null) { | ||||
|             return respVO; | ||||
|         } | ||||
|  | ||||
|         // 3.1 商品单独分佣模式 | ||||
|         Integer fixedMinPrice = 0; | ||||
|         Integer fixedMaxPrice = 0; | ||||
|         Integer spuMinPrice = 0; | ||||
|         Integer spuMaxPrice = 0; | ||||
|         List<ProductSkuRespDTO> skuList = productSkuApi.getSkuListBySpuId(ListUtil.of(spuId)); | ||||
|         if (BooleanUtil.isTrue(spu.getSubCommissionType())) { | ||||
|             // 3.1 商品单独分佣模式 | ||||
|             fixedMinPrice = getMinValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice); | ||||
|             fixedMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice); | ||||
|         // 3.2 全局分佣模式(根据商品价格比例计算) | ||||
|         } else { | ||||
|             // 3.2 全局分佣模式(根据商品价格比例计算) | ||||
|             spuMinPrice = getMinValue(skuList, ProductSkuRespDTO::getPrice); | ||||
|             spuMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getPrice); | ||||
|         } | ||||
|  | ||||
|         respVO.setBrokerageMinPrice(calculatePrice(spuMinPrice, tradeConfig.getBrokerageFirstPercent(), fixedMinPrice)); | ||||
|         respVO.setBrokerageMaxPrice(calculatePrice(spuMaxPrice, tradeConfig.getBrokerageFirstPercent(), fixedMaxPrice)); | ||||
|         return respVO; | ||||
|   | ||||
| @@ -236,6 +236,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { | ||||
|  | ||||
|         // 校验分销关系绑定模式 | ||||
|         if (BrokerageBindModeEnum.REGISTER.getMode().equals(tradeConfig.getBrokerageBindMode())) { | ||||
|             // TODO @疯狂:是不是把 isNewUser 挪到这里好点呀? | ||||
|             if (!BooleanUtil.isTrue(isNewUser)) { | ||||
|                 throw exception(BROKERAGE_BIND_MODE_REGISTER); // 只有在注册时可以绑定 | ||||
|             } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV