【代码优化】商城:分销用户绑定移除 try catch,错误消息由前端进行特殊处理
This commit is contained in:
parent
b1c115d221
commit
2451942cf2
|
@ -29,7 +29,6 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum;
|
||||||
import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
|
import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
@ -46,7 +45,6 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*;
|
||||||
*
|
*
|
||||||
* @author owen
|
* @author owen
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
|
||||||
@Service
|
@Service
|
||||||
@Validated
|
@Validated
|
||||||
public class BrokerageUserServiceImpl implements BrokerageUserService {
|
public class BrokerageUserServiceImpl implements BrokerageUserService {
|
||||||
|
@ -176,39 +174,34 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean bindBrokerageUser(Long userId, Long bindUserId) {
|
public boolean bindBrokerageUser(Long userId, Long bindUserId) {
|
||||||
try {
|
// 1. 获得分销用户
|
||||||
// 1. 获得分销用户
|
boolean isNewBrokerageUser = false;
|
||||||
boolean isNewBrokerageUser = false;
|
BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(userId);
|
||||||
BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(userId);
|
if (brokerageUser == null) { // 分销用户不存在的情况:1. 新注册;2. 旧数据;3. 分销功能关闭后又打开
|
||||||
if (brokerageUser == null) { // 分销用户不存在的情况:1. 新注册;2. 旧数据;3. 分销功能关闭后又打开
|
isNewBrokerageUser = true;
|
||||||
isNewBrokerageUser = true;
|
brokerageUser = new BrokerageUserDO().setId(userId).setBrokerageEnabled(false).setBrokeragePrice(0).setFrozenPrice(0);
|
||||||
brokerageUser = new BrokerageUserDO().setId(userId).setBrokerageEnabled(false).setBrokeragePrice(0).setFrozenPrice(0);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 2.1 校验是否能绑定用户
|
// 2.1 校验是否能绑定用户
|
||||||
boolean validated = isUserCanBind(brokerageUser);
|
boolean validated = isUserCanBind(brokerageUser);
|
||||||
if (!validated) {
|
if (!validated) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// 2.3 校验能否绑定
|
|
||||||
validateCanBindUser(brokerageUser, bindUserId);
|
|
||||||
// 2.3 绑定用户
|
|
||||||
if (isNewBrokerageUser) {
|
|
||||||
Integer enabledCondition = tradeConfigService.getTradeConfig().getBrokerageEnabledCondition();
|
|
||||||
if (BrokerageEnabledConditionEnum.ALL.getCondition().equals(enabledCondition)) { // 人人分销:用户默认就有分销资格
|
|
||||||
brokerageUser.setBrokerageEnabled(true).setBrokerageTime(LocalDateTime.now());
|
|
||||||
} else {
|
|
||||||
brokerageUser.setBrokerageEnabled(false).setBrokerageTime(LocalDateTime.now());
|
|
||||||
}
|
|
||||||
brokerageUserMapper.insert(fillBindUserData(bindUserId, brokerageUser));
|
|
||||||
} else {
|
|
||||||
brokerageUserMapper.updateById(fillBindUserData(bindUserId, new BrokerageUserDO().setId(userId)));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("[bindBrokerageUser][userId({}) 绑定推广员失败 bindUserId({})]", userId, bindUserId, e);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// 2.3 校验能否绑定
|
||||||
|
validateCanBindUser(brokerageUser, bindUserId);
|
||||||
|
// 2.3 绑定用户
|
||||||
|
if (isNewBrokerageUser) {
|
||||||
|
Integer enabledCondition = tradeConfigService.getTradeConfig().getBrokerageEnabledCondition();
|
||||||
|
if (BrokerageEnabledConditionEnum.ALL.getCondition().equals(enabledCondition)) { // 人人分销:用户默认就有分销资格
|
||||||
|
brokerageUser.setBrokerageEnabled(true).setBrokerageTime(LocalDateTime.now());
|
||||||
|
} else {
|
||||||
|
brokerageUser.setBrokerageEnabled(false).setBrokerageTime(LocalDateTime.now());
|
||||||
|
}
|
||||||
|
brokerageUserMapper.insert(fillBindUserData(bindUserId, brokerageUser));
|
||||||
|
} else {
|
||||||
|
brokerageUserMapper.updateById(fillBindUserData(bindUserId, new BrokerageUserDO().setId(userId)));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue