Commit 2451942cf2fbd9d009347b393f0f662466ecd453
1 parent
b1c115d2
【代码优化】商城:分销用户绑定移除 try catch,错误消息由前端进行特殊处理
Showing
1 changed file
with
24 additions
and
31 deletions
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java
| @@ -29,7 +29,6 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; | @@ -29,7 +29,6 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; | ||
| 29 | import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; | 29 | import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; |
| 30 | import com.baomidou.mybatisplus.core.metadata.IPage; | 30 | import com.baomidou.mybatisplus.core.metadata.IPage; |
| 31 | import jakarta.annotation.Resource; | 31 | import jakarta.annotation.Resource; |
| 32 | -import lombok.extern.slf4j.Slf4j; | ||
| 33 | import org.springframework.stereotype.Service; | 32 | import org.springframework.stereotype.Service; |
| 34 | import org.springframework.transaction.annotation.Transactional; | 33 | import org.springframework.transaction.annotation.Transactional; |
| 35 | import org.springframework.validation.annotation.Validated; | 34 | import org.springframework.validation.annotation.Validated; |
| @@ -46,7 +45,6 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; | @@ -46,7 +45,6 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; | ||
| 46 | * | 45 | * |
| 47 | * @author owen | 46 | * @author owen |
| 48 | */ | 47 | */ |
| 49 | -@Slf4j | ||
| 50 | @Service | 48 | @Service |
| 51 | @Validated | 49 | @Validated |
| 52 | public class BrokerageUserServiceImpl implements BrokerageUserService { | 50 | public class BrokerageUserServiceImpl implements BrokerageUserService { |
| @@ -176,39 +174,34 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { | @@ -176,39 +174,34 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { | ||
| 176 | 174 | ||
| 177 | @Override | 175 | @Override |
| 178 | public boolean bindBrokerageUser(Long userId, Long bindUserId) { | 176 | public boolean bindBrokerageUser(Long userId, Long bindUserId) { |
| 179 | - try { | ||
| 180 | - // 1. 获得分销用户 | ||
| 181 | - boolean isNewBrokerageUser = false; | ||
| 182 | - BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(userId); | ||
| 183 | - if (brokerageUser == null) { // 分销用户不存在的情况:1. 新注册;2. 旧数据;3. 分销功能关闭后又打开 | ||
| 184 | - isNewBrokerageUser = true; | ||
| 185 | - brokerageUser = new BrokerageUserDO().setId(userId).setBrokerageEnabled(false).setBrokeragePrice(0).setFrozenPrice(0); | ||
| 186 | - } | 177 | + // 1. 获得分销用户 |
| 178 | + boolean isNewBrokerageUser = false; | ||
| 179 | + BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(userId); | ||
| 180 | + if (brokerageUser == null) { // 分销用户不存在的情况:1. 新注册;2. 旧数据;3. 分销功能关闭后又打开 | ||
| 181 | + isNewBrokerageUser = true; | ||
| 182 | + brokerageUser = new BrokerageUserDO().setId(userId).setBrokerageEnabled(false).setBrokeragePrice(0).setFrozenPrice(0); | ||
| 183 | + } | ||
| 187 | 184 | ||
| 188 | - // 2.1 校验是否能绑定用户 | ||
| 189 | - boolean validated = isUserCanBind(brokerageUser); | ||
| 190 | - if (!validated) { | ||
| 191 | - return false; | ||
| 192 | - } | ||
| 193 | - // 2.3 校验能否绑定 | ||
| 194 | - validateCanBindUser(brokerageUser, bindUserId); | ||
| 195 | - // 2.3 绑定用户 | ||
| 196 | - if (isNewBrokerageUser) { | ||
| 197 | - Integer enabledCondition = tradeConfigService.getTradeConfig().getBrokerageEnabledCondition(); | ||
| 198 | - if (BrokerageEnabledConditionEnum.ALL.getCondition().equals(enabledCondition)) { // 人人分销:用户默认就有分销资格 | ||
| 199 | - brokerageUser.setBrokerageEnabled(true).setBrokerageTime(LocalDateTime.now()); | ||
| 200 | - } else { | ||
| 201 | - brokerageUser.setBrokerageEnabled(false).setBrokerageTime(LocalDateTime.now()); | ||
| 202 | - } | ||
| 203 | - brokerageUserMapper.insert(fillBindUserData(bindUserId, brokerageUser)); | 185 | + // 2.1 校验是否能绑定用户 |
| 186 | + boolean validated = isUserCanBind(brokerageUser); | ||
| 187 | + if (!validated) { | ||
| 188 | + return false; | ||
| 189 | + } | ||
| 190 | + // 2.3 校验能否绑定 | ||
| 191 | + validateCanBindUser(brokerageUser, bindUserId); | ||
| 192 | + // 2.3 绑定用户 | ||
| 193 | + if (isNewBrokerageUser) { | ||
| 194 | + Integer enabledCondition = tradeConfigService.getTradeConfig().getBrokerageEnabledCondition(); | ||
| 195 | + if (BrokerageEnabledConditionEnum.ALL.getCondition().equals(enabledCondition)) { // 人人分销:用户默认就有分销资格 | ||
| 196 | + brokerageUser.setBrokerageEnabled(true).setBrokerageTime(LocalDateTime.now()); | ||
| 204 | } else { | 197 | } else { |
| 205 | - brokerageUserMapper.updateById(fillBindUserData(bindUserId, new BrokerageUserDO().setId(userId))); | 198 | + brokerageUser.setBrokerageEnabled(false).setBrokerageTime(LocalDateTime.now()); |
| 206 | } | 199 | } |
| 207 | - return true; | ||
| 208 | - } catch (Exception e) { | ||
| 209 | - log.error("[bindBrokerageUser][userId({}) 绑定推广员失败 bindUserId({})]", userId, bindUserId, e); | ||
| 210 | - return false; | 200 | + brokerageUserMapper.insert(fillBindUserData(bindUserId, brokerageUser)); |
| 201 | + } else { | ||
| 202 | + brokerageUserMapper.updateById(fillBindUserData(bindUserId, new BrokerageUserDO().setId(userId))); | ||
| 211 | } | 203 | } |
| 204 | + return true; | ||
| 212 | } | 205 | } |
| 213 | 206 | ||
| 214 | @Override | 207 | @Override |