member: 佣金失效
This commit is contained in:
parent
a708521b9d
commit
9eb7837b67
|
@ -635,12 +635,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||
.setRefundStatus(TradeOrderRefundStatusEnum.PART.getStatus()).setRefundPrice(orderRefundPrice));
|
||||
}
|
||||
|
||||
// TODO 芋艿:未来如果有分佣,需要更新相关分佣订单为已失效
|
||||
|
||||
// 扣减用户积分
|
||||
getSelf().reduceUserPointAsync(order.getUserId(), orderRefundPrice, afterSaleId);
|
||||
// 扣减用户经验
|
||||
getSelf().reduceUserExperienceAsync(order.getUserId(), orderRefundPrice, afterSaleId);
|
||||
// 更新分佣记录为已失效
|
||||
getSelf().cancelBrokerageAsync(order.getUserId(), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -757,6 +757,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||
brokerageApi.addBrokerage(userId, list);
|
||||
}
|
||||
|
||||
@Async
|
||||
protected void cancelBrokerageAsync(Long userId, Long orderItemId) {
|
||||
brokerageApi.cancelBrokerage(userId, String.valueOf(orderItemId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得自身的代理对象,解决 AOP 生效问题
|
||||
*
|
||||
|
|
|
@ -27,6 +27,6 @@ public class BrokerageApiImpl implements BrokerageApi {
|
|||
|
||||
@Override
|
||||
public void cancelBrokerage(Long userId, String bizId) {
|
||||
|
||||
memberBrokerageRecordService.cancelBrokerage(userId, bizId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,4 +39,9 @@ public interface MemberBrokerageRecordMapper extends BaseMapperX<MemberBrokerage
|
|||
.eq(MemberBrokerageRecordDO::getId, id)
|
||||
.eq(MemberBrokerageRecordDO::getStatus, status));
|
||||
}
|
||||
|
||||
default MemberBrokerageRecordDO selectByUserIdAndBizTypeAndBizId(Integer bizType, String bizId) {
|
||||
return selectOne(MemberBrokerageRecordDO::getBizType, bizType,
|
||||
MemberBrokerageRecordDO::getBizId, bizId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,6 +78,21 @@ public interface MemberUserMapper extends BaseMapperX<MemberUserDO> {
|
|||
update(null, lambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户可用佣金(减少)
|
||||
* 注意:理论上佣金可能已经提现,这时会扣出负数,确保平台不会造成损失
|
||||
*
|
||||
* @param id 用户编号
|
||||
* @param incrCount 增加佣金(负数)
|
||||
*/
|
||||
default void updateBrokeragePriceDecr(Long id, int incrCount) {
|
||||
Assert.isTrue(incrCount < 0);
|
||||
LambdaUpdateWrapper<MemberUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<MemberUserDO>()
|
||||
.setSql(" brokerage_price = brokerage_price + " + incrCount) // 负数,所以使用 + 号
|
||||
.eq(MemberUserDO::getId, id);
|
||||
update(null, lambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户冻结佣金(增加)
|
||||
*
|
||||
|
@ -94,12 +109,27 @@ public interface MemberUserMapper extends BaseMapperX<MemberUserDO> {
|
|||
|
||||
/**
|
||||
* 更新用户冻结佣金(减少)
|
||||
* 注意:理论上冻结佣金可能已经解冻,这时会扣出负数,确保平台不会造成损失
|
||||
*
|
||||
* @param id 用户编号
|
||||
* @param incrCount 减少冻结佣金(负数)
|
||||
*/
|
||||
default void updateFrozenBrokeragePriceDecr(Long id, int incrCount) {
|
||||
Assert.isTrue(incrCount < 0);
|
||||
LambdaUpdateWrapper<MemberUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<MemberUserDO>()
|
||||
.setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount) // 负数,所以使用 + 号
|
||||
.eq(MemberUserDO::getId, id);
|
||||
update(null, lambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户冻结佣金(减少), 更新用户佣金(增加)
|
||||
*
|
||||
* @param id 用户编号
|
||||
* @param incrCount 减少冻结佣金(负数)
|
||||
* @return 更新条数
|
||||
*/
|
||||
default int updateFrozenBrokeragePriceDecr(Long id, int incrCount) {
|
||||
default int updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int incrCount) {
|
||||
Assert.isTrue(incrCount < 0);
|
||||
LambdaUpdateWrapper<MemberUserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<MemberUserDO>()
|
||||
.setSql(" frozen_brokerage_price = frozen_brokerage_price + " + incrCount + // 负数,所以使用 + 号
|
||||
|
|
|
@ -33,16 +33,22 @@ public interface MemberBrokerageRecordService {
|
|||
/**
|
||||
* 增加佣金
|
||||
*
|
||||
* @param userId 会员ID
|
||||
* @param userId 会员编号
|
||||
* @param list 请求参数列表
|
||||
*/
|
||||
void addBrokerage(Long userId, List<BrokerageAddReqDTO> list);
|
||||
|
||||
/**
|
||||
* 取消佣金:将佣金记录,状态修改为已失效
|
||||
* @param userId 会员编号
|
||||
* @param bizId 业务编号
|
||||
*/
|
||||
void cancelBrokerage(Long userId, String bizId);
|
||||
|
||||
/**
|
||||
* 解冻佣金:将待结算的佣金记录,状态修改为已结算
|
||||
*
|
||||
* @return 解冻佣金的数量
|
||||
*/
|
||||
int unfreezeRecord();
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.member.dal.dataobject.brokerage.record.MemberBrok
|
|||
import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointConfigDO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.brokerage.record.MemberBrokerageRecordMapper;
|
||||
import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageRecordBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.member.enums.brokerage.BrokerageRecordStatusEnum;
|
||||
import cn.iocoder.yudao.module.member.service.point.MemberPointConfigService;
|
||||
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
|
||||
|
@ -85,6 +86,29 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe
|
|||
addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqDTO::getSkuSecondBrokeragePrice);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void cancelBrokerage(Long userId, String bizId) {
|
||||
MemberBrokerageRecordDO record = memberBrokerageRecordMapper.selectByUserIdAndBizTypeAndBizId(BrokerageRecordBizTypeEnum.ORDER.getType(), bizId);
|
||||
if (record == null || ObjectUtil.notEqual(record.getUserId(), userId)) {
|
||||
log.error("[cancelBrokerage][userId({})][bizId({}) 更新为已失效失败:记录不存在]", userId, bizId);
|
||||
return;
|
||||
}
|
||||
|
||||
MemberBrokerageRecordDO updateObj = new MemberBrokerageRecordDO().setStatus(BrokerageRecordStatusEnum.CANCEL.getStatus());
|
||||
int updateRows = memberBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj);
|
||||
if (updateRows == 0) {
|
||||
log.error("[cancelBrokerage][record({}) 更新为已失效失败]", record.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
if (BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus().equals(record.getStatus())) {
|
||||
memberUserService.updateUserFrozenBrokeragePrice(userId, -record.getPrice());
|
||||
} else if (BrokerageRecordStatusEnum.SETTLEMENT.getStatus().equals(record.getStatus())) {
|
||||
memberUserService.updateUserBrokeragePrice(userId, -record.getPrice());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算佣金
|
||||
*
|
||||
|
@ -190,7 +214,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe
|
|||
}
|
||||
|
||||
// 更新用户冻结佣金
|
||||
memberUserService.updateUserFrozenBrokeragePrice(record.getUserId(), -record.getPrice());
|
||||
memberUserService.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(record.getUserId(), -record.getPrice());
|
||||
|
||||
log.info("[unfreezeRecord][record({}) 更新为已结算成功]", record.getId());
|
||||
return true;
|
||||
|
|
|
@ -190,4 +190,12 @@ public interface MemberUserService {
|
|||
* @param frozenBrokeragePrice 用户冻结佣金
|
||||
*/
|
||||
void updateUserFrozenBrokeragePrice(Long id, int frozenBrokeragePrice);
|
||||
|
||||
/**
|
||||
* 更新用户冻结佣金(减少), 更新用户佣金(增加)
|
||||
*
|
||||
* @param id 用户编号
|
||||
* @param frozenBrokeragePrice 减少冻结佣金(负数)
|
||||
*/
|
||||
void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cn.iocoder.yudao.module.member.service.user;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
@ -272,7 +273,11 @@ public class MemberUserServiceImpl implements MemberUserService {
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateUserBrokeragePrice(Long id, int brokeragePrice) {
|
||||
memberUserMapper.updateBrokeragePriceIncr(id, brokeragePrice);
|
||||
if (brokeragePrice > 0) {
|
||||
memberUserMapper.updateBrokeragePriceIncr(id, brokeragePrice);
|
||||
} else if (brokeragePrice < 0) {
|
||||
memberUserMapper.updateBrokeragePriceDecr(id, brokeragePrice);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -281,10 +286,17 @@ public class MemberUserServiceImpl implements MemberUserService {
|
|||
if (frozenBrokeragePrice > 0) {
|
||||
memberUserMapper.updateFrozenBrokeragePriceIncr(id, frozenBrokeragePrice);
|
||||
} else if (frozenBrokeragePrice < 0) {
|
||||
int updateRows = memberUserMapper.updateFrozenBrokeragePriceDecr(id, frozenBrokeragePrice);
|
||||
if (updateRows == 0) {
|
||||
throw exception(MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH);
|
||||
}
|
||||
memberUserMapper.updateFrozenBrokeragePriceDecr(id, frozenBrokeragePrice);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice) {
|
||||
Assert.isTrue(frozenBrokeragePrice < 0);
|
||||
int updateRows = memberUserMapper.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(id, frozenBrokeragePrice);
|
||||
if (updateRows == 0) {
|
||||
throw exception(MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue