|
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
import cn.hutool.core.util.BooleanUtil;
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
|
|
@@ -25,10 +26,10 @@ 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.config.TradeConfigService;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
-import jakarta.annotation.Resource;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -127,6 +128,18 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
|
|
.orElse(null);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public BrokerageUserDO getOrCreateBrokerageUser(Long id) {
|
|
|
+ BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(id);
|
|
|
+ if (brokerageUser == null && ObjUtil.equal(BrokerageEnabledConditionEnum.ALL.getCondition(),
|
|
|
+ tradeConfigService.getTradeConfig().getBrokerageEnabledCondition())) { // 人人分销的情况下,如果分销人为空则创建分销人
|
|
|
+ brokerageUser = new BrokerageUserDO().setId(id).setBrokerageEnabled(true).setBrokeragePrice(0)
|
|
|
+ .setBrokerageTime(LocalDateTime.now()).setFrozenPrice(0);
|
|
|
+ brokerageUserMapper.insert(brokerageUser);
|
|
|
+ }
|
|
|
+ return brokerageUser;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public boolean updateUserPrice(Long id, Integer price) {
|
|
|
if (price > 0) {
|
|
@@ -184,7 +197,6 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
|
|
if (BrokerageEnabledConditionEnum.ALL.getCondition().equals(enabledCondition)) { // 人人分销:用户默认就有分销资格
|
|
|
brokerageUser.setBrokerageEnabled(true).setBrokerageTime(LocalDateTime.now());
|
|
|
}
|
|
|
- brokerageUser.setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now());
|
|
|
brokerageUserMapper.insert(fillBindUserData(bindUserId, brokerageUser));
|
|
|
} else {
|
|
|
brokerageUserMapper.updateById(fillBindUserData(bindUserId, new BrokerageUserDO().setId(userId)));
|
|
@@ -294,18 +306,23 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
|
|
}
|
|
|
|
|
|
private void validateCanBindUser(BrokerageUserDO user, Long bindUserId) {
|
|
|
- // 校验要绑定的用户有无推广资格
|
|
|
- BrokerageUserDO bindUser = brokerageUserMapper.selectById(bindUserId);
|
|
|
+ // 1.1 校验推广人是否存在
|
|
|
+ MemberUserRespDTO bindUserInfo = memberUserApi.getUser(bindUserId);
|
|
|
+ if (bindUserInfo == null) {
|
|
|
+ throw exception(BROKERAGE_USER_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ // 1.2 校验要绑定的用户有无推广资格
|
|
|
+ BrokerageUserDO bindUser = getOrCreateBrokerageUser(bindUserId);
|
|
|
if (bindUser == null || BooleanUtil.isFalse(bindUser.getBrokerageEnabled())) {
|
|
|
throw exception(BROKERAGE_BIND_USER_NOT_ENABLED);
|
|
|
}
|
|
|
|
|
|
- // 校验绑定自己
|
|
|
+ // 2. 校验绑定自己
|
|
|
if (Objects.equals(user.getId(), bindUserId)) {
|
|
|
throw exception(BROKERAGE_BIND_SELF);
|
|
|
}
|
|
|
|
|
|
- // 下级不能绑定自己的上级
|
|
|
+ // 3. 下级不能绑定自己的上级
|
|
|
for (int i = 0; i <= Short.MAX_VALUE; i++) {
|
|
|
if (Objects.equals(bindUser.getBindUserId(), user.getId())) {
|
|
|
throw exception(BROKERAGE_BIND_LOOP);
|