mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 07:11:52 +08:00
trade: 优化分销用户佣金字段名称
This commit is contained in:
parent
4b43304c76
commit
1ead368595
@ -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 '推广员编号';
|
||||
|
@ -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, "用户冻结佣金({})数量不足");
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ public class AppBrokerageUserController {
|
||||
@PreAuthenticated
|
||||
public CommonResult<AppBrokerageUserRespVO> 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<AppBrokerageUserMySummaryRespVO> 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<PageResult<AppBrokerageUserRankByPriceRespVO>> 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));
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -17,6 +17,6 @@ public class AppBrokerageUserRankByPriceRespVO {
|
||||
private String avatar;
|
||||
|
||||
@Schema(description = "佣金金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
private Integer brokeragePrice;
|
||||
private Integer price;
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
@ -31,10 +31,10 @@ public interface BrokerageUserMapper extends BaseMapperX<BrokerageUserDO> {
|
||||
* @param id 用户编号
|
||||
* @param incrCount 增加佣金(正数)
|
||||
*/
|
||||
default void updateBrokeragePriceIncr(Long id, Integer incrCount) {
|
||||
default void updatePriceIncr(Long id, Integer incrCount) {
|
||||
Assert.isTrue(incrCount > 0);
|
||||
LambdaUpdateWrapper<BrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<BrokerageUserDO>()
|
||||
.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<BrokerageUserDO> {
|
||||
* @param id 用户编号
|
||||
* @param incrCount 增加佣金(负数)
|
||||
*/
|
||||
default void updateBrokeragePriceDecr(Long id, Integer incrCount) {
|
||||
default void updatePriceDecr(Long id, Integer incrCount) {
|
||||
Assert.isTrue(incrCount < 0);
|
||||
LambdaUpdateWrapper<BrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<BrokerageUserDO>()
|
||||
.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<BrokerageUserDO> {
|
||||
* @param id 用户编号
|
||||
* @param incrCount 增加冻结佣金(正数)
|
||||
*/
|
||||
default void updateFrozenBrokeragePriceIncr(Long id, Integer incrCount) {
|
||||
default void updateFrozenPriceIncr(Long id, Integer incrCount) {
|
||||
Assert.isTrue(incrCount > 0);
|
||||
LambdaUpdateWrapper<BrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<BrokerageUserDO>()
|
||||
.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<BrokerageUserDO> {
|
||||
* @param id 用户编号
|
||||
* @param incrCount 减少冻结佣金(负数)
|
||||
*/
|
||||
default void updateFrozenBrokeragePriceDecr(Long id, Integer incrCount) {
|
||||
default void updateFrozenPriceDecr(Long id, Integer incrCount) {
|
||||
Assert.isTrue(incrCount < 0);
|
||||
LambdaUpdateWrapper<BrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<BrokerageUserDO>()
|
||||
.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<BrokerageUserDO> {
|
||||
* @param incrCount 减少冻结佣金(负数)
|
||||
* @return 更新条数
|
||||
*/
|
||||
default int updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, Integer incrCount) {
|
||||
default int updateFrozenPriceDecrAndPriceIncr(Long id, Integer incrCount) {
|
||||
Assert.isTrue(incrCount < 0);
|
||||
LambdaUpdateWrapper<BrokerageUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<BrokerageUserDO>()
|
||||
.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);
|
||||
}
|
||||
|
||||
|
@ -28,10 +28,10 @@ public class BrokerageAddReqBO {
|
||||
/**
|
||||
* 一级佣金(固定)
|
||||
*/
|
||||
private Integer firstBrokeragePrice;
|
||||
private Integer firstFixedPrice;
|
||||
/**
|
||||
* 二级佣金(固定)
|
||||
*/
|
||||
private Integer secondBrokeragePrice;
|
||||
private Integer secondFixedPrice;
|
||||
|
||||
}
|
||||
|
@ -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<BrokerageAddReqBO> list, Integer brokerageFrozenDays,
|
||||
Integer brokeragePercent, Function<BrokerageAddReqBO, Integer> FixedBrokeragePriceFun,
|
||||
Integer brokeragePercent, Function<BrokerageAddReqBO, Integer> fixedPriceFun,
|
||||
BrokerageRecordBizTypeEnum bizType) {
|
||||
// 1.1 处理冻结时间
|
||||
LocalDateTime unfreezeTime = null;
|
||||
@ -153,7 +153,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
|
||||
int totalBrokerage = 0;
|
||||
List<BrokerageRecordDO> 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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
/**
|
||||
* 获得推广用户数量(一级)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user