mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 01:01:52 +08:00
code review:分销逻辑
This commit is contained in:
parent
c92365128a
commit
e384b810bf
@ -61,10 +61,13 @@ public class MoneyUtils {
|
|||||||
/**
|
/**
|
||||||
* 分转元(字符串)
|
* 分转元(字符串)
|
||||||
*
|
*
|
||||||
|
* 例如说 fen 为 1 时,则结果为 0.01
|
||||||
|
*
|
||||||
* @param fen 分
|
* @param fen 分
|
||||||
* @return 元
|
* @return 元
|
||||||
*/
|
*/
|
||||||
public static String fenToYuanStr(int fen) {
|
public static String fenToYuanStr(int fen) {
|
||||||
return new Money(0, fen).toString();
|
return new Money(0, fen).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -147,4 +147,5 @@ public class ProductSpuRespDTO {
|
|||||||
* true - 自行设置
|
* true - 自行设置
|
||||||
*/
|
*/
|
||||||
private Boolean subCommissionType;
|
private Boolean subCommissionType;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -179,6 +179,7 @@ public class ProductSpuDO extends BaseDO {
|
|||||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||||
private List<Long> giveCouponTemplateIds;
|
private List<Long> giveCouponTemplateIds;
|
||||||
|
|
||||||
|
// TODO @puhui999:字段估计要改成 brokerageType
|
||||||
/**
|
/**
|
||||||
* 分销类型
|
* 分销类型
|
||||||
*
|
*
|
||||||
|
@ -8,4 +8,5 @@ package cn.iocoder.yudao.module.trade.enums;
|
|||||||
public interface DictTypeConstants {
|
public interface DictTypeConstants {
|
||||||
|
|
||||||
String BROKERAGE_WITHDRAW_STATUS = "brokerage_withdraw_status"; // 佣金提现状态
|
String BROKERAGE_WITHDRAW_STATUS = "brokerage_withdraw_status"; // 佣金提现状态
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,7 @@ public class BrokerageUserController {
|
|||||||
Set<Long> userIds = convertSet(pageResult.getList(), BrokerageUserDO::getId);
|
Set<Long> userIds = convertSet(pageResult.getList(), BrokerageUserDO::getId);
|
||||||
// 查询用户信息
|
// 查询用户信息
|
||||||
Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(userIds);
|
Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(userIds);
|
||||||
|
// TODO @疯狂:看看下面两个 getBrokerageUserCountByBindUserId、getWithdrawSummaryByUserId 有没可能一次性出结果,不然 n 次有点太花性能了;
|
||||||
// 合计分佣订单
|
// 合计分佣订单
|
||||||
Map<Long, UserBrokerageSummaryBO> userOrderSummaryMap = convertMap(userIds,
|
Map<Long, UserBrokerageSummaryBO> userOrderSummaryMap = convertMap(userIds,
|
||||||
userId -> userId,
|
userId -> userId,
|
||||||
@ -101,13 +102,13 @@ public class BrokerageUserController {
|
|||||||
Map<Long, Long> brokerageUserCountMap = convertMap(userIds,
|
Map<Long, Long> brokerageUserCountMap = convertMap(userIds,
|
||||||
userId -> userId,
|
userId -> userId,
|
||||||
userId -> brokerageUserService.getBrokerageUserCountByBindUserId(userId, null));
|
userId -> brokerageUserService.getBrokerageUserCountByBindUserId(userId, null));
|
||||||
|
|
||||||
// 合计提现
|
// 合计提现
|
||||||
Map<Long, UserWithdrawSummaryBO> withdrawMap = convertMap(userIds,
|
Map<Long, UserWithdrawSummaryBO> withdrawMap = convertMap(userIds,
|
||||||
userId -> userId,
|
userId -> userId,
|
||||||
userId -> brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS));
|
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
|
@PreAuthenticated
|
||||||
public CommonResult<AppBrokerageUserMySummaryRespVO> getBrokerageUserSummary() {
|
public CommonResult<AppBrokerageUserMySummaryRespVO> getBrokerageUserSummary() {
|
||||||
Long userId = getLoginUserId();
|
Long userId = getLoginUserId();
|
||||||
|
// TODO @疯狂:后面这种,要不也改成 convert;感觉 controller 这样更容易看到整体;核心其实是 86、8/87、9/90、9/91 这阶段
|
||||||
// 统计 yesterdayPrice、withdrawPrice、firstBrokerageUserCount、secondBrokerageUserCount 字段
|
// 统计 yesterdayPrice、withdrawPrice、firstBrokerageUserCount、secondBrokerageUserCount 字段
|
||||||
LocalDateTime yesterday = LocalDateTime.now().minusDays(1);
|
LocalDateTime yesterday = LocalDateTime.now().minusDays(1);
|
||||||
LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday);
|
LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday);
|
||||||
LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday);
|
LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday);
|
||||||
AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO()
|
AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO()
|
||||||
.setYesterdayPrice(brokerageRecordService.getSummaryPriceByUserId(userId, BrokerageRecordBizTypeEnum.ORDER.getType(), beginTime, endTime))
|
.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)
|
.setBrokeragePrice(0).setFrozenPrice(0)
|
||||||
.setFirstBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1))
|
.setFirstBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1))
|
||||||
.setSecondBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2));
|
.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")
|
"WHERE user_id = #{userId} AND status = #{status} AND deleted = FALSE")
|
||||||
UserWithdrawSummaryBO selectCountAndSumPriceByUserIdAndStatus(@Param("userId") Long userId,
|
UserWithdrawSummaryBO selectCountAndSumPriceByUserIdAndStatus(@Param("userId") Long userId,
|
||||||
@Param("status") Integer status);
|
@Param("status") Integer status);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -315,37 +315,34 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
|
|||||||
|
|
||||||
// 2.1 校验分销功能是否开启
|
// 2.1 校验分销功能是否开启
|
||||||
TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig();
|
TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig();
|
||||||
if (tradeConfig == null || !BooleanUtil.isTrue(tradeConfig.getBrokerageEnabled())) {
|
if (tradeConfig == null || BooleanUtil.isFalse(tradeConfig.getBrokerageEnabled())) {
|
||||||
return respVO;
|
return respVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2.2 校验用户是否有分销资格
|
// 2.2 校验用户是否有分销资格
|
||||||
respVO.setEnabled(brokerageUserService.getUserBrokerageEnabled(getLoginUserId()));
|
respVO.setEnabled(brokerageUserService.getUserBrokerageEnabled(getLoginUserId()));
|
||||||
if (!BooleanUtil.isTrue(respVO.getEnabled())) {
|
if (BooleanUtil.isFalse(respVO.getEnabled())) {
|
||||||
return respVO;
|
return respVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer fixedMinPrice = 0;
|
|
||||||
Integer fixedMaxPrice = 0;
|
|
||||||
Integer spuMinPrice = 0;
|
|
||||||
Integer spuMaxPrice = 0;
|
|
||||||
// 2.3 校验商品是否存在
|
// 2.3 校验商品是否存在
|
||||||
ProductSpuRespDTO spu = productSpuApi.getSpu(spuId);
|
ProductSpuRespDTO spu = productSpuApi.getSpu(spuId);
|
||||||
if (spu == null) {
|
if (spu == null) {
|
||||||
return respVO;
|
return respVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3.1 商品单独分佣模式
|
||||||
|
Integer fixedMinPrice = 0;
|
||||||
|
Integer fixedMaxPrice = 0;
|
||||||
|
Integer spuMinPrice = 0;
|
||||||
|
Integer spuMaxPrice = 0;
|
||||||
List<ProductSkuRespDTO> skuList = productSkuApi.getSkuListBySpuId(ListUtil.of(spuId));
|
List<ProductSkuRespDTO> skuList = productSkuApi.getSkuListBySpuId(ListUtil.of(spuId));
|
||||||
if (BooleanUtil.isTrue(spu.getSubCommissionType())) {
|
if (BooleanUtil.isTrue(spu.getSubCommissionType())) {
|
||||||
// 3.1 商品单独分佣模式
|
|
||||||
fixedMinPrice = getMinValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice);
|
fixedMinPrice = getMinValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice);
|
||||||
fixedMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice);
|
fixedMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice);
|
||||||
} else {
|
|
||||||
// 3.2 全局分佣模式(根据商品价格比例计算)
|
// 3.2 全局分佣模式(根据商品价格比例计算)
|
||||||
|
} else {
|
||||||
spuMinPrice = getMinValue(skuList, ProductSkuRespDTO::getPrice);
|
spuMinPrice = getMinValue(skuList, ProductSkuRespDTO::getPrice);
|
||||||
spuMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getPrice);
|
spuMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getPrice);
|
||||||
}
|
}
|
||||||
|
|
||||||
respVO.setBrokerageMinPrice(calculatePrice(spuMinPrice, tradeConfig.getBrokerageFirstPercent(), fixedMinPrice));
|
respVO.setBrokerageMinPrice(calculatePrice(spuMinPrice, tradeConfig.getBrokerageFirstPercent(), fixedMinPrice));
|
||||||
respVO.setBrokerageMaxPrice(calculatePrice(spuMaxPrice, tradeConfig.getBrokerageFirstPercent(), fixedMaxPrice));
|
respVO.setBrokerageMaxPrice(calculatePrice(spuMaxPrice, tradeConfig.getBrokerageFirstPercent(), fixedMaxPrice));
|
||||||
return respVO;
|
return respVO;
|
||||||
|
@ -236,6 +236,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
|||||||
|
|
||||||
// 校验分销关系绑定模式
|
// 校验分销关系绑定模式
|
||||||
if (BrokerageBindModeEnum.REGISTER.getMode().equals(tradeConfig.getBrokerageBindMode())) {
|
if (BrokerageBindModeEnum.REGISTER.getMode().equals(tradeConfig.getBrokerageBindMode())) {
|
||||||
|
// TODO @疯狂:是不是把 isNewUser 挪到这里好点呀?
|
||||||
if (!BooleanUtil.isTrue(isNewUser)) {
|
if (!BooleanUtil.isTrue(isNewUser)) {
|
||||||
throw exception(BROKERAGE_BIND_MODE_REGISTER); // 只有在注册时可以绑定
|
throw exception(BROKERAGE_BIND_MODE_REGISTER); // 只有在注册时可以绑定
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class MemberUserRespDTO {
|
|||||||
*/
|
*/
|
||||||
private String mobile;
|
private String mobile;
|
||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间(注册时间)
|
||||||
*/
|
*/
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ public class AppDictDataController {
|
|||||||
@GetMapping("/type")
|
@GetMapping("/type")
|
||||||
@Operation(summary = "根据字典类型查询字典数据信息")
|
@Operation(summary = "根据字典类型查询字典数据信息")
|
||||||
@Parameter(name = "type", description = "字典类型", required = true, example = "common_status")
|
@Parameter(name = "type", description = "字典类型", required = true, example = "common_status")
|
||||||
public CommonResult<List<AppDictDataRespVO>> getDictDataListByType(@RequestParam String type) {
|
public CommonResult<List<AppDictDataRespVO>> getDictDataListByType(@RequestParam("type") String type) {
|
||||||
List<DictDataDO> list = dictDataService.getEnabledDictDataListByType(type);
|
List<DictDataDO> list = dictDataService.getEnabledDictDataListByType(type);
|
||||||
return success(DictDataConvert.INSTANCE.convertList03(list));
|
return success(DictDataConvert.INSTANCE.convertList03(list));
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import lombok.Data;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
@Schema(description = "用户 App - 字典数据信息 Response VO")
|
@Schema(description = "用户 App - 字典数据信息 Response VO")
|
||||||
@ -19,23 +18,12 @@ public class AppDictDataRespVO {
|
|||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "字典标签", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
|
@Schema(description = "字典标签", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
|
||||||
@NotBlank(message = "字典标签不能为空")
|
|
||||||
@Size(max = 100, message = "字典标签长度不能超过100个字符")
|
|
||||||
private String label;
|
private String label;
|
||||||
|
|
||||||
@Schema(description = "字典值", requiredMode = Schema.RequiredMode.REQUIRED, example = "iocoder")
|
@Schema(description = "字典值", requiredMode = Schema.RequiredMode.REQUIRED, example = "iocoder")
|
||||||
@NotBlank(message = "字典键值不能为空")
|
|
||||||
@Size(max = 100, message = "字典键值长度不能超过100个字符")
|
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
@Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex")
|
@Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex")
|
||||||
@NotBlank(message = "字典类型不能为空")
|
|
||||||
@Size(max = 100, message = "字典类型长度不能超过100个字符")
|
|
||||||
private String dictType;
|
private String dictType;
|
||||||
|
|
||||||
@Schema(description = "颜色类型,default、primary、success、info、warning、danger", example = "default")
|
|
||||||
private String colorType;
|
|
||||||
@Schema(description = "css 样式", example = "btn-visible")
|
|
||||||
private String cssClass;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,8 @@ public interface DictDataMapper extends BaseMapperX<DictDataDO> {
|
|||||||
|
|
||||||
default List<DictDataDO> selectListByTypeAndStatus(String dictType, Integer status) {
|
default List<DictDataDO> selectListByTypeAndStatus(String dictType, Integer status) {
|
||||||
return selectList(new LambdaQueryWrapper<DictDataDO>()
|
return selectList(new LambdaQueryWrapper<DictDataDO>()
|
||||||
.eq(DictDataDO::getDictType, dictType).eq(DictDataDO::getStatus, status));
|
.eq(DictDataDO::getDictType, dictType)
|
||||||
|
.eq(DictDataDO::getStatus, status));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user