mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-31 17:40:05 +08:00
trade: 分销业务后台功能:修改上级推广人
This commit is contained in:
parent
ca55e61dd2
commit
643602d038
@ -9,8 +9,8 @@ import cn.iocoder.yudao.module.trade.convert.brokerage.user.BrokerageUserConvert
|
||||
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO;
|
||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum;
|
||||
import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService;
|
||||
import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO;
|
||||
import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService;
|
||||
import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@ -72,7 +72,8 @@ public class BrokerageUserController {
|
||||
@PreAuthorize("@ss.hasPermission('trade:brokerage-user:query')")
|
||||
public CommonResult<BrokerageUserRespVO> getBrokerageUser(@RequestParam("id") Long id) {
|
||||
BrokerageUserDO brokerageUser = brokerageUserService.getBrokerageUser(id);
|
||||
return success(BrokerageUserConvert.INSTANCE.convert(brokerageUser));
|
||||
BrokerageUserRespVO respVO = BrokerageUserConvert.INSTANCE.convert(brokerageUser);
|
||||
return success(BrokerageUserConvert.INSTANCE.copyTo(memberUserApi.getUser(id), respVO));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
|
@ -37,11 +37,7 @@ public interface BrokerageUserConvert {
|
||||
PageResult<BrokerageUserRespVO> result = convertPage(pageResult);
|
||||
for (BrokerageUserRespVO vo : result.getList()) {
|
||||
// 用户信息
|
||||
Optional.ofNullable(userMap.get(vo.getId()))
|
||||
.ifPresent(user -> {
|
||||
vo.setNickname(user.getNickname());
|
||||
vo.setAvatar(user.getAvatar());
|
||||
});
|
||||
copyTo(userMap.get(vo.getId()), vo);
|
||||
|
||||
// 推广用户数量(一级)
|
||||
vo.setBrokerageUserCount(MapUtil.getInt(brokerageUserCountMap, vo.getId(), 0));
|
||||
@ -60,5 +56,12 @@ public interface BrokerageUserConvert {
|
||||
return result;
|
||||
}
|
||||
|
||||
default BrokerageUserRespVO copyTo(MemberUserRespDTO source, BrokerageUserRespVO target) {
|
||||
Optional.ofNullable(source)
|
||||
.ifPresent(user -> target.setNickname(user.getNickname())
|
||||
.setAvatar(user.getAvatar()));
|
||||
return target;
|
||||
}
|
||||
|
||||
BrokerageUserDTO convertDTO(BrokerageUserDO brokerageUser);
|
||||
}
|
||||
|
@ -55,16 +55,19 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
||||
|
||||
@Override
|
||||
public void updateBrokerageUserId(Long id, Long bindUserId) {
|
||||
// 校验存在
|
||||
validateBrokerageUserExists(id);
|
||||
// 0. 校验存在
|
||||
BrokerageUserDO brokerageUser = validateBrokerageUserExists(id);
|
||||
if (bindUserId == null) {
|
||||
// 清除推广员
|
||||
// 1. 清除推广员
|
||||
brokerageUserMapper.updateBindUserIdAndBindUserTimeToNull(id);
|
||||
} else {
|
||||
// 修改推广员
|
||||
brokerageUserMapper.updateById(new BrokerageUserDO().setId(id)
|
||||
.setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now()));
|
||||
return;
|
||||
}
|
||||
|
||||
// 2.1 校验能否绑定
|
||||
validateCanBindUser(brokerageUser, bindUserId);
|
||||
// 2.2 修改推广员
|
||||
brokerageUserMapper.updateById(new BrokerageUserDO().setId(id)
|
||||
.setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -81,10 +84,13 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
||||
}
|
||||
}
|
||||
|
||||
private void validateBrokerageUserExists(Long id) {
|
||||
if (brokerageUserMapper.selectById(id) == null) {
|
||||
private BrokerageUserDO validateBrokerageUserExists(Long id) {
|
||||
BrokerageUserDO brokerageUserDO = brokerageUserMapper.selectById(id);
|
||||
if (brokerageUserDO == null) {
|
||||
throw exception(BROKERAGE_USER_NOT_EXISTS);
|
||||
}
|
||||
|
||||
return brokerageUserDO;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -142,12 +148,15 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
||||
brokerageUser = new BrokerageUserDO().setId(userId).setBrokerageEnabled(false).setPrice(0).setFrozenPrice(0);
|
||||
}
|
||||
|
||||
// 校验能否绑定
|
||||
boolean validated = validateCanBindUser(brokerageUser, bindUserId, isNewUser);
|
||||
// 校验分配配置
|
||||
boolean validated = validateTradeConfig(brokerageUser, bindUserId, isNewUser);
|
||||
if (!validated) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 校验能否绑定
|
||||
validateCanBindUser(brokerageUser, bindUserId);
|
||||
|
||||
if (isInsert) {
|
||||
Integer enabledCondition = tradeConfigService.getTradeConfig().getBrokerageEnabledCondition();
|
||||
if (BrokerageEnabledConditionEnum.ALL.getCondition().equals(enabledCondition)) {
|
||||
@ -162,28 +171,13 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean validateCanBindUser(BrokerageUserDO user, Long bindUserId, Boolean isNewUser) {
|
||||
if (bindUserId == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean validateTradeConfig(BrokerageUserDO user, Long bindUserId, Boolean isNewUser) {
|
||||
// 校验分销功能是否启用
|
||||
TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig();
|
||||
if (tradeConfig == null || !BooleanUtil.isTrue(tradeConfig.getBrokerageEnabled())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 校验绑定自己
|
||||
if (Objects.equals(user.getId(), bindUserId)) {
|
||||
throw exception(BROKERAGE_BIND_SELF);
|
||||
}
|
||||
|
||||
// 校验要绑定的用户有无推广资格
|
||||
BrokerageUserDO bindUser = brokerageUserMapper.selectById(bindUserId);
|
||||
if (bindUser == null || !BooleanUtil.isTrue(bindUser.getBrokerageEnabled())) {
|
||||
throw exception(BROKERAGE_BIND_USER_NOT_ENABLED);
|
||||
}
|
||||
|
||||
// 校验分佣模式:仅可后台手动设置推广员
|
||||
if (BrokerageEnabledConditionEnum.ADMIN.getCondition().equals(tradeConfig.getBrokerageEnabledCondition())) {
|
||||
throw exception(BROKERAGE_BIND_CONDITION_ADMIN);
|
||||
@ -200,11 +194,26 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
||||
}
|
||||
}
|
||||
|
||||
validateCanBindUser(user, bindUserId);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void validateCanBindUser(BrokerageUserDO user, Long bindUserId) {
|
||||
// 校验要绑定的用户有无推广资格
|
||||
BrokerageUserDO bindUser = brokerageUserMapper.selectById(bindUserId);
|
||||
if (bindUser == null || !BooleanUtil.isTrue(bindUser.getBrokerageEnabled())) {
|
||||
throw exception(BROKERAGE_BIND_USER_NOT_ENABLED);
|
||||
}
|
||||
|
||||
// 校验绑定自己
|
||||
if (Objects.equals(user.getId(), bindUserId)) {
|
||||
throw exception(BROKERAGE_BIND_SELF);
|
||||
}
|
||||
|
||||
// A->B->A:下级不能绑定自己的上级, A->B->C->A可以!!
|
||||
if (Objects.equals(user.getId(), bindUser.getBindUserId())) {
|
||||
throw exception(BROKERAGE_BIND_LOOP);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user