绑定上级
This commit is contained in:
@@ -30,9 +30,12 @@ import com.czg.market.service.*;
|
|||||||
import com.czg.market.vo.InviteUserVO;
|
import com.czg.market.vo.InviteUserVO;
|
||||||
import com.czg.market.vo.MkDistributionConfigVO;
|
import com.czg.market.vo.MkDistributionConfigVO;
|
||||||
import com.czg.order.dto.MkDistributionPayDTO;
|
import com.czg.order.dto.MkDistributionPayDTO;
|
||||||
|
import com.czg.order.entity.OrderInfo;
|
||||||
import com.czg.order.entity.OrderPayment;
|
import com.czg.order.entity.OrderPayment;
|
||||||
|
import com.czg.order.service.OrderInfoService;
|
||||||
import com.czg.order.service.OrderPaymentService;
|
import com.czg.order.service.OrderPaymentService;
|
||||||
import com.czg.sa.StpKit;
|
import com.czg.sa.StpKit;
|
||||||
|
import com.czg.service.market.enums.OrderStatusEnums;
|
||||||
import com.czg.service.market.mapper.MkDistributionUserMapper;
|
import com.czg.service.market.mapper.MkDistributionUserMapper;
|
||||||
import com.czg.utils.AssertUtil;
|
import com.czg.utils.AssertUtil;
|
||||||
import com.czg.utils.CzgRandomUtils;
|
import com.czg.utils.CzgRandomUtils;
|
||||||
@@ -47,6 +50,7 @@ import jakarta.annotation.Resource;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -88,6 +92,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|||||||
@DubboReference
|
@DubboReference
|
||||||
private OrderPaymentService orderPaymentService;
|
private OrderPaymentService orderPaymentService;
|
||||||
@DubboReference
|
@DubboReference
|
||||||
|
private OrderInfoService orderInfoService;
|
||||||
|
@DubboReference
|
||||||
private ShopInfoService shopInfoService;
|
private ShopInfoService shopInfoService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -210,14 +216,18 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void bindInviteUser(MkDistributionUserDTO param) {
|
public void bindInviteUser(MkDistributionUserDTO param) {
|
||||||
ShopUser shopUser = shopUserService.getById(param.getId());
|
ShopUser shopUser = shopUserService.getById(param.getId());
|
||||||
AssertUtil.isNull(shopUser, "店铺用户不存在");
|
AssertUtil.isNull(shopUser, "店铺用户不存在");
|
||||||
if(shopUser.getDistributionUserId() != null){
|
if (shopUser.getDistributionUserId() != null) {
|
||||||
throw new CzgException("店铺用户已绑定分销员");
|
throw new CzgException("店铺用户已绑定分销员");
|
||||||
}
|
}
|
||||||
MkDistributionUser parent = getOne(QueryWrapper.create().eq(MkDistributionUser::getInviteCode, param.getInviteCode()));
|
MkDistributionUser parent = getOne(QueryWrapper.create().eq(MkDistributionUser::getInviteCode, param.getInviteCode()));
|
||||||
AssertUtil.isNull(parent, "邀请人不存在");
|
AssertUtil.isNull(parent, "邀请人不存在");
|
||||||
|
if (parent.getStatus() == 9) {
|
||||||
|
throw new CzgException("绑定失败该邀请人分销身份已被取消");
|
||||||
|
}
|
||||||
ShopUser newShopUser = new ShopUser();
|
ShopUser newShopUser = new ShopUser();
|
||||||
newShopUser.setId(shopUser.getId());
|
newShopUser.setId(shopUser.getId());
|
||||||
newShopUser.setDistributionUserId(parent.getId());
|
newShopUser.setDistributionUserId(parent.getId());
|
||||||
@@ -226,21 +236,28 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|||||||
MkDistributionUser newDistributionUser = new MkDistributionUser();
|
MkDistributionUser newDistributionUser = new MkDistributionUser();
|
||||||
newDistributionUser.setId(parent.getId());
|
newDistributionUser.setId(parent.getId());
|
||||||
newDistributionUser.setInviteCount(parent.getInviteCount() + 1);
|
newDistributionUser.setInviteCount(parent.getInviteCount() + 1);
|
||||||
if (parent.getStatus() != 9) {
|
MkDistributionConfig mkDistributionConfig = mkDistributionConfigService.getOne(QueryWrapper.create()
|
||||||
MkDistributionConfig mkDistributionConfig = mkDistributionConfigService.getOne(QueryWrapper.create()
|
.eq(MkDistributionConfig::getShopId, parent.getShopId()));
|
||||||
.eq(MkDistributionConfig::getShopId, parent.getShopId()));
|
if (mkDistributionConfig != null) {
|
||||||
if (mkDistributionConfig != null) {
|
if ("invite".equals(mkDistributionConfig.getUpgradeType())) {
|
||||||
if ("invite".equals(mkDistributionConfig.getUpgradeType())) {
|
if (mkDistributionConfig.getInviteConsume() == 1) {
|
||||||
MkDistributionLevelConfig levelConfig = levelConfigService.getOne(QueryWrapper.create()
|
long count = orderInfoService.count(QueryWrapper.create()
|
||||||
.eq(MkDistributionLevelConfig::getShopId, parent.getShopId())
|
.eq(OrderInfo::getUserId, shopUser.getId())
|
||||||
.le(MkDistributionLevelConfig::getInviteCount, parent.getInviteCount())
|
.eq(OrderInfo::getShopId, parent.getShopId())
|
||||||
.gt(MkDistributionLevelConfig::getId, parent.getDistributionLevelId())
|
.eq(OrderInfo::getStatus, OrderStatusEnums.DONE.getCode()));
|
||||||
.orderBy(MkDistributionLevelConfig::getLevel).desc().limit(1));
|
if (count < 1) {
|
||||||
if (levelConfig != null) {
|
throw new CzgException("绑定失败,被邀请人需要成功支付一笔订单");
|
||||||
newDistributionUser.setDistributionLevelId(levelConfig.getId());
|
|
||||||
newDistributionUser.setDistributionLevelName(levelConfig.getName());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MkDistributionLevelConfig levelConfig = levelConfigService.getOne(QueryWrapper.create()
|
||||||
|
.eq(MkDistributionLevelConfig::getShopId, parent.getShopId())
|
||||||
|
.le(MkDistributionLevelConfig::getInviteCount, parent.getInviteCount())
|
||||||
|
.gt(MkDistributionLevelConfig::getId, parent.getDistributionLevelId())
|
||||||
|
.orderBy(MkDistributionLevelConfig::getId).asc().limit(1));
|
||||||
|
if (levelConfig != null) {
|
||||||
|
newDistributionUser.setDistributionLevelId(levelConfig.getId());
|
||||||
|
newDistributionUser.setDistributionLevelName(levelConfig.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.updateById(newDistributionUser);
|
this.updateById(newDistributionUser);
|
||||||
@@ -329,7 +346,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|||||||
ShopUser shopUser = shopUserService.getById(param.getId());
|
ShopUser shopUser = shopUserService.getById(param.getId());
|
||||||
AssertUtil.isNull(shopUser, "店铺用户ID不能为空");
|
AssertUtil.isNull(shopUser, "店铺用户ID不能为空");
|
||||||
boolean isExits = shopUser.checkDistributionShops(param.getShopId().toString());
|
boolean isExits = shopUser.checkDistributionShops(param.getShopId().toString());
|
||||||
if(isExits){
|
if (isExits) {
|
||||||
throw new CzgException("该用户已被添加为分销员,不可重复添加");
|
throw new CzgException("该用户已被添加为分销员,不可重复添加");
|
||||||
}
|
}
|
||||||
MkDistributionConfig config = mkDistributionConfigService.getOne(
|
MkDistributionConfig config = mkDistributionConfigService.getOne(
|
||||||
|
|||||||
Reference in New Issue
Block a user