|
|
|
|
@@ -76,6 +76,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
@Resource
|
|
|
|
|
private MkDistributionDeliverService distributionDeliverService;
|
|
|
|
|
@Resource
|
|
|
|
|
private MkDistributionInviteService distributionInviteService;
|
|
|
|
|
@Resource
|
|
|
|
|
private AppWxServiceImpl appWxService;
|
|
|
|
|
@DubboReference
|
|
|
|
|
private ShopUserService shopUserService;
|
|
|
|
|
@@ -148,9 +150,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
AssertUtil.isNull(shopUser, "店铺用户不存在");
|
|
|
|
|
UserInfo userInfo = userInfoService.getById(shopUser.getUserId());
|
|
|
|
|
result.put("cashOutAmount", userInfo.getDistributionAmount() == null ? 0.0 : userInfo.getDistributionAmount());
|
|
|
|
|
|
|
|
|
|
if (shopUser.getParentUserId() != null) {
|
|
|
|
|
MkDistributionUser mkDistributionUser = getMkDistributionUserByIdAndShopId(shopUser.getParentUserId(), shopId);
|
|
|
|
|
MkDistributionInvite invite = distributionInviteService.getByShopIdAndShopUserId(shopId, shopUser.getUserId());
|
|
|
|
|
if (invite != null && invite.getParentUserId() != null) {
|
|
|
|
|
MkDistributionUser mkDistributionUser = getMkDistributionUserByIdAndShopId(invite.getParentUserId(), shopId);
|
|
|
|
|
AssertUtil.isNull(mkDistributionUser, "上级分销员不存在");
|
|
|
|
|
ShopUser shopUserParent = shopUserService.getById(mkDistributionUser.getId());
|
|
|
|
|
result.put("parentName", shopUserParent.getNickName());
|
|
|
|
|
@@ -234,8 +236,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
public void bindInviteUser(MkDistributionUserDTO param) throws CzgException, ValidateException {
|
|
|
|
|
ShopUser shopUser = shopUserService.getById(param.getId());
|
|
|
|
|
AssertUtil.isNull(shopUser, "店铺用户不存在");
|
|
|
|
|
if (shopUser.getParentUserId() != null) {
|
|
|
|
|
throw new CzgException("店铺用户已绑定分销员");
|
|
|
|
|
MkDistributionInvite shopUserInvite = distributionInviteService.getByShopIdAndShopUserId(param.getShopId(), shopUser.getId());
|
|
|
|
|
if (shopUserInvite != null && shopUserInvite.getParentUserId() != null) {
|
|
|
|
|
throw new CzgException("店铺用户已存在上级");
|
|
|
|
|
}
|
|
|
|
|
MkDistributionUser parent = getOne(QueryWrapper.create().eq(MkDistributionUser::getInviteCode, param.getInviteCode()));
|
|
|
|
|
AssertUtil.isNull(parent, "邀请人不存在");
|
|
|
|
|
@@ -250,28 +253,28 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
}
|
|
|
|
|
ShopUser parentShopUser = shopUserService.getById(parent.getId());
|
|
|
|
|
AssertUtil.isNull(parentShopUser, "邀请人不存在");
|
|
|
|
|
MkDistributionInvite parentShopUserInvite = distributionInviteService.getByShopIdAndShopUserId(param.getShopId(), parentShopUser.getId());
|
|
|
|
|
if (parentShopUserInvite != null && parentShopUserInvite.getParentUserId() != null && parentShopUserInvite.getParentUserId().equals(shopUser.getId())) {
|
|
|
|
|
throw new CzgException("存在绑定关系,不可绑定");
|
|
|
|
|
}
|
|
|
|
|
if (parentShopUserInvite != null && parentShopUserInvite.getGradeUserId() != null && parentShopUserInvite.getGradeUserId().equals(shopUser.getId())) {
|
|
|
|
|
throw new CzgException("存在绑定关系,不可绑定");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parentShopUser.getParentUserId() != null && parentShopUser.getParentUserId().equals(shopUser.getId())) {
|
|
|
|
|
throw new CzgException("存在绑定关系,不可绑定");
|
|
|
|
|
}
|
|
|
|
|
if (parentShopUser.getGradeUserId() != null && parentShopUser.getGradeUserId().equals(shopUser.getId())) {
|
|
|
|
|
throw new CzgException("存在绑定关系,不可绑定");
|
|
|
|
|
}
|
|
|
|
|
//更新自己的上级
|
|
|
|
|
shopUser.setParentUserId(parentShopUser.getId());
|
|
|
|
|
shopUser.setGradeUserId(parentShopUser.getParentUserId());
|
|
|
|
|
|
|
|
|
|
//更新自己的下级 的上级的上级 为自己的上级
|
|
|
|
|
ShopUser upShopUser1 = new ShopUser();
|
|
|
|
|
upShopUser1.setParentUserId(parentShopUser.getId());
|
|
|
|
|
upShopUser1.setGradeUserId(parentShopUser.getParentUserId());
|
|
|
|
|
shopUserService.update(upShopUser1, QueryWrapper.create().eq(ShopUser::getId, shopUser.getId()));
|
|
|
|
|
|
|
|
|
|
if (shopUser.getParentUserId() != null) {
|
|
|
|
|
MkDistributionInvite newShopUserInvite = new MkDistributionInvite();
|
|
|
|
|
newShopUserInvite.setShopId(param.getShopId());
|
|
|
|
|
newShopUserInvite.setUserId(shopUser.getUserId());
|
|
|
|
|
newShopUserInvite.setShopUserId(shopUser.getId());
|
|
|
|
|
newShopUserInvite.setParentUserId(parentShopUser.getId());
|
|
|
|
|
newShopUserInvite.setGradeUserId(parentShopUserInvite == null ? null : parentShopUserInvite.getParentUserId());
|
|
|
|
|
newShopUserInvite.setInviteTime(LocalDateTime.now());
|
|
|
|
|
distributionInviteService.save(newShopUserInvite);
|
|
|
|
|
if (parentShopUserInvite != null && parentShopUserInvite.getParentUserId() != null) {
|
|
|
|
|
//更新自己的下级 的上级的上级 为自己的上级
|
|
|
|
|
ShopUser upShopUser = new ShopUser();
|
|
|
|
|
upShopUser.setGradeUserId(shopUser.getParentUserId());
|
|
|
|
|
shopUserService.update(upShopUser, QueryWrapper.create().eq(ShopUser::getParentUserId, shopUser.getId()));
|
|
|
|
|
MkDistributionInvite childShopUserInvite = new MkDistributionInvite();
|
|
|
|
|
childShopUserInvite.setGradeUserId(parentShopUser.getId());
|
|
|
|
|
distributionInviteService.update(childShopUserInvite, QueryWrapper.create().eq(MkDistributionInvite::getParentUserId, shopUser.getId()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MkDistributionUser newDistributionUser = new MkDistributionUser();
|
|
|
|
|
@@ -320,8 +323,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
public void bindInviteUser(Long fromUserId, Long toUserId, Long shopId) throws CzgException, ValidateException {
|
|
|
|
|
ShopUser shopUser = shopUserService.getById(fromUserId);
|
|
|
|
|
AssertUtil.isNull(shopUser, "店铺用户不存在");
|
|
|
|
|
if (shopUser.getParentUserId() != null) {
|
|
|
|
|
throw new CzgException("店铺用户已绑定上级");
|
|
|
|
|
MkDistributionInvite shopUserInvite = distributionInviteService.getByShopIdAndShopUserId(shopId, shopUser.getId());
|
|
|
|
|
if (shopUserInvite != null && shopUserInvite.getParentUserId() != null) {
|
|
|
|
|
throw new CzgException("店铺用户已存在上级");
|
|
|
|
|
}
|
|
|
|
|
MkDistributionUser parent = getOne(QueryWrapper.create().eq(MkDistributionUser::getId, toUserId));
|
|
|
|
|
AssertUtil.isNull(parent, "邀请人不存在");
|
|
|
|
|
@@ -337,27 +341,28 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
ShopUser parentShopUser = shopUserService.getById(parent.getId());
|
|
|
|
|
AssertUtil.isNull(parentShopUser, "邀请人不存在");
|
|
|
|
|
|
|
|
|
|
if (parentShopUser.getParentUserId() != null && parentShopUser.getParentUserId().equals(shopUser.getId())) {
|
|
|
|
|
MkDistributionInvite parentShopUserInvite = distributionInviteService.getByShopIdAndShopUserId(shopId, parentShopUser.getId());
|
|
|
|
|
if (parentShopUserInvite != null && parentShopUserInvite.getParentUserId() != null && parentShopUserInvite.getParentUserId().equals(shopUser.getId())) {
|
|
|
|
|
throw new CzgException("存在绑定关系,不可绑定");
|
|
|
|
|
}
|
|
|
|
|
if (parentShopUser.getGradeUserId() != null && parentShopUser.getGradeUserId().equals(shopUser.getId())) {
|
|
|
|
|
if (parentShopUserInvite != null && parentShopUserInvite.getGradeUserId() != null && parentShopUserInvite.getGradeUserId().equals(shopUser.getId())) {
|
|
|
|
|
throw new CzgException("存在绑定关系,不可绑定");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新自己的上级
|
|
|
|
|
shopUser.setParentUserId(parentShopUser.getId());
|
|
|
|
|
shopUser.setGradeUserId(parentShopUser.getParentUserId());
|
|
|
|
|
|
|
|
|
|
//更新自己的下级 的上级的上级 为自己的上级
|
|
|
|
|
ShopUser upShopUser1 = new ShopUser();
|
|
|
|
|
upShopUser1.setParentUserId(parentShopUser.getId());
|
|
|
|
|
upShopUser1.setGradeUserId(parentShopUser.getParentUserId());
|
|
|
|
|
shopUserService.update(upShopUser1, QueryWrapper.create().eq(ShopUser::getId, shopUser.getId()));
|
|
|
|
|
|
|
|
|
|
if (shopUser.getParentUserId() != null) {
|
|
|
|
|
MkDistributionInvite newShopUserInvite = new MkDistributionInvite();
|
|
|
|
|
newShopUserInvite.setShopId(shopId);
|
|
|
|
|
newShopUserInvite.setUserId(shopUser.getUserId());
|
|
|
|
|
newShopUserInvite.setShopUserId(shopUser.getId());
|
|
|
|
|
newShopUserInvite.setParentUserId(parentShopUser.getId());
|
|
|
|
|
newShopUserInvite.setGradeUserId(parentShopUserInvite == null ? null : parentShopUserInvite.getParentUserId());
|
|
|
|
|
newShopUserInvite.setInviteTime(LocalDateTime.now());
|
|
|
|
|
distributionInviteService.save(newShopUserInvite);
|
|
|
|
|
if (parentShopUserInvite != null && parentShopUserInvite.getParentUserId() != null) {
|
|
|
|
|
//更新自己的下级 的上级的上级 为自己的上级
|
|
|
|
|
ShopUser upShopUser = new ShopUser();
|
|
|
|
|
upShopUser.setGradeUserId(shopUser.getParentUserId());
|
|
|
|
|
shopUserService.update(upShopUser, QueryWrapper.create().eq(ShopUser::getParentUserId, shopUser.getId()));
|
|
|
|
|
MkDistributionInvite childShopUserInvite = new MkDistributionInvite();
|
|
|
|
|
childShopUserInvite.setGradeUserId(parentShopUser.getId());
|
|
|
|
|
distributionInviteService.update(childShopUserInvite, QueryWrapper.create().eq(MkDistributionInvite::getParentUserId, shopUser.getId()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MkDistributionUser newDistributionUser = new MkDistributionUser();
|
|
|
|
|
@@ -405,8 +410,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
public void costUpgradeLevelBefore(Long userId, Long shopId) {
|
|
|
|
|
ShopUser shopUser = shopUserService.getShopUserInfo(shopId, userId);
|
|
|
|
|
costUpgradeLevel(shopUser.getId(), shopId);
|
|
|
|
|
if (shopUser.getParentUserId() != null) {
|
|
|
|
|
costUpgradeLevel(shopUser.getParentUserId(), shopId);
|
|
|
|
|
MkDistributionInvite shopUserInvite = distributionInviteService.getByShopIdAndShopUserId(shopId, shopUser.getId());
|
|
|
|
|
if (shopUserInvite != null && shopUserInvite.getParentUserId() != null) {
|
|
|
|
|
costUpgradeLevel(shopUserInvite.getParentUserId(), shopId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -773,18 +779,19 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
AssertUtil.isTrue(config.getIsEnable() != 1, "分销未开启");
|
|
|
|
|
// 产生消费的用户
|
|
|
|
|
ShopUser curUser = shopUserService.getShopUserInfo(shopId, sourceUserId);
|
|
|
|
|
if (curUser == null || curUser.getParentUserId() == null) {
|
|
|
|
|
MkDistributionInvite sourceInviteUser = distributionInviteService.getByShopIdAndShopUserId(shopId, curUser.getId());
|
|
|
|
|
if (sourceInviteUser.getParentUserId() == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.info("开始分销, 当前来源用户: {}, shopId: {}, 邀请人id: {}", sourceUserId, shopId, curUser.getParentUserId());
|
|
|
|
|
log.info("开始分销, 当前来源用户: {}, shopId: {}, 邀请人id: {}", sourceUserId, shopId, sourceInviteUser.getParentUserId());
|
|
|
|
|
|
|
|
|
|
MkDistributionUser distributionUser = getMkDistributionUserByIdAndShopId(curUser.getParentUserId(), shopId);
|
|
|
|
|
MkDistributionUser distributionUser = getMkDistributionUserByIdAndShopId(sourceInviteUser.getParentUserId(), shopId);
|
|
|
|
|
MkDistributionLevelConfig level = levelConfigService.getById(distributionUser.getDistributionLevelId());
|
|
|
|
|
deepReward(curUser, level.getCommission(), config, distributionUser,
|
|
|
|
|
amount, sourceId, type, orderNo, 1);
|
|
|
|
|
if (curUser.getGradeUserId() != null) {
|
|
|
|
|
MkDistributionUser parentDis = getMkDistributionUserByIdAndShopId(curUser.getGradeUserId(), shopId);
|
|
|
|
|
if (sourceInviteUser.getGradeUserId() != null) {
|
|
|
|
|
MkDistributionUser parentDis = getMkDistributionUserByIdAndShopId(sourceInviteUser.getGradeUserId(), shopId);
|
|
|
|
|
MkDistributionLevelConfig parentDisLevel = levelConfigService.getById(parentDis.getDistributionLevelId());
|
|
|
|
|
deepReward(curUser, parentDisLevel.getCommission().subtract(level.getCommission()), config, parentDis,
|
|
|
|
|
amount, sourceId, type, orderNo, 2);
|
|
|
|
|
|