|
|
|
|
@@ -155,14 +155,13 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
result.put("cashOutAmount", userInfo.getDistributionAmount() == null ? 0.0 : userInfo.getDistributionAmount());
|
|
|
|
|
ShopUserInvite shopUserInvite = shopUserInviteService.getOneByShopIdAndShopUserId(shopId, shopUser.getId());
|
|
|
|
|
if (shopUserInvite != null && shopUserInvite.getDistributionUserId() != null) {
|
|
|
|
|
MkDistributionUser mkDistributionUser = this.getById(shopUserInvite.getDistributionUserId());
|
|
|
|
|
MkDistributionUser mkDistributionUser = getMkDistributionUserByIdAndShopId(shopUserInvite.getDistributionUserId(), shopId);
|
|
|
|
|
AssertUtil.isNull(mkDistributionUser, "上级分销员不存在");
|
|
|
|
|
ShopUser shopUserParent = shopUserService.getById(mkDistributionUser.getId());
|
|
|
|
|
result.put("parentName", shopUserParent.getNickName());
|
|
|
|
|
result.put("parentPhone", shopUserParent.getPhone());
|
|
|
|
|
}
|
|
|
|
|
MkDistributionUser mkDistributionUser = this.getOne(QueryWrapper.create()
|
|
|
|
|
.eq(MkDistributionUser::getId, shopUser.getId()).eq(MkDistributionUser::getShopId, shopId));
|
|
|
|
|
MkDistributionUser mkDistributionUser = getMkDistributionUserByIdAndShopId(shopUser.getId(), shopId);
|
|
|
|
|
MkDistributionConfigVO mkDistributionConfigVO = mkDistributionConfigService.detail(shopId);
|
|
|
|
|
if (mkDistributionUser != null) {
|
|
|
|
|
Map<String, Object> distributionUser = new HashMap<>();
|
|
|
|
|
@@ -212,8 +211,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
if (!"auto".equals(mkDistributionConfigVO.getOpenType())) {
|
|
|
|
|
throw new CzgException("该店铺不可自行成为分销员");
|
|
|
|
|
}
|
|
|
|
|
MkDistributionUser mkDistributionUser = this.getOne(QueryWrapper.create()
|
|
|
|
|
.eq(MkDistributionUser::getId, shopUser.getId()).eq(MkDistributionUser::getShopId, shopId));
|
|
|
|
|
MkDistributionUser mkDistributionUser = getMkDistributionUserByIdAndShopId(shopUser.getId(), shopId);
|
|
|
|
|
if (mkDistributionUser == null) {
|
|
|
|
|
mkDistributionUser = new MkDistributionUser();
|
|
|
|
|
mkDistributionUser.setId(shopUser.getId());
|
|
|
|
|
@@ -333,7 +331,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
* 分销员:按消费金额升级等级
|
|
|
|
|
*/
|
|
|
|
|
public void costUpgradeLevel(Long shopUserId, Long shopId) {
|
|
|
|
|
MkDistributionUser distributionUser = getById(shopUserId);
|
|
|
|
|
MkDistributionUser distributionUser = getMkDistributionUserByIdAndShopId(shopUserId, shopId);
|
|
|
|
|
if (distributionUser == null || distributionUser.getIsAssignLevel() == 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
@@ -413,9 +411,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
AssertUtil.isNull(param.getId(), "店铺用户ID不能为空");
|
|
|
|
|
ShopUser shopUser = shopUserService.getById(param.getId());
|
|
|
|
|
AssertUtil.isNull(shopUser, "店铺用户ID不能为空");
|
|
|
|
|
MkDistributionUser distributionUser = getOne(QueryWrapper.create()
|
|
|
|
|
.eq(MkDistributionUser::getId, param.getId())
|
|
|
|
|
.eq(MkDistributionUser::getShopId, param.getShopId()));
|
|
|
|
|
MkDistributionUser distributionUser = getMkDistributionUserByIdAndShopId(param.getId(), param.getShopId());
|
|
|
|
|
if (distributionUser != null && distributionUser.getStatus() != 0) {
|
|
|
|
|
throw new CzgException("该用户已是分销员,不可重复添加");
|
|
|
|
|
}
|
|
|
|
|
@@ -457,13 +453,14 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
public void updateDistributionUserById(MkDistributionUserDTO param) {
|
|
|
|
|
AssertUtil.isNull(param.getId(), "分销员ID不能为空");
|
|
|
|
|
MkDistributionUser distributionUser = BeanUtil.toBean(param, MkDistributionUser.class);
|
|
|
|
|
updateById(distributionUser);
|
|
|
|
|
update(distributionUser, QueryWrapper.create().eq(MkDistributionUser::getId, param.getId())
|
|
|
|
|
.eq(MkDistributionUser::getShopId, param.getShopId()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void resetDistributionUserLevel(MkDistributionUserDTO param) {
|
|
|
|
|
AssertUtil.isNull(param.getId(), "分销员ID不能为空");
|
|
|
|
|
MkDistributionUser distributionUser = getById(param.getId());
|
|
|
|
|
MkDistributionUser distributionUser = getMkDistributionUserByIdAndShopId(param.getId(), param.getShopId());
|
|
|
|
|
AssertUtil.isNull(distributionUser, "分销员不存在");
|
|
|
|
|
AssertUtil.isTrue(distributionUser.getIsAssignLevel() == 0, "分销员并未指定等级,不可重置");
|
|
|
|
|
MkDistributionConfig config = mkDistributionConfigService.getOne(
|
|
|
|
|
@@ -477,7 +474,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
newDistributionUser.setDistributionLevelId(distributionUser.getDistributionLevelId());
|
|
|
|
|
newDistributionUser.setDistributionLevelName(distributionUser.getDistributionLevelName());
|
|
|
|
|
newDistributionUser.setConsumeAmount(distributionUser.getConsumeAmount());
|
|
|
|
|
updateById(newDistributionUser);
|
|
|
|
|
update(newDistributionUser, QueryWrapper.create().eq(MkDistributionUser::getId, distributionUser.getId())
|
|
|
|
|
.eq(MkDistributionUser::getShopId, distributionUser.getShopId()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -515,12 +513,12 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void deleteDistributionUser(Long id) {
|
|
|
|
|
public void deleteDistributionUser(Long id, Long shopId) {
|
|
|
|
|
AssertUtil.isNull(id, "分销员ID不能为空");
|
|
|
|
|
MkDistributionUser distributionUser = new MkDistributionUser();
|
|
|
|
|
distributionUser.setId(id);
|
|
|
|
|
distributionUser.setIsDel(1);
|
|
|
|
|
updateById(distributionUser);
|
|
|
|
|
update(distributionUser, QueryWrapper.create().eq(MkDistributionUser::getId, id)
|
|
|
|
|
.eq(MkDistributionUser::getShopId, shopId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -591,7 +589,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
|
|
|
|
|
// 上上级分销员
|
|
|
|
|
if (currentShopUser != null && currentShopUser.getDistributionUserId() != null) {
|
|
|
|
|
MkDistributionUser parent = getOne(new QueryWrapper().eq(MkDistributionUser::getId, currentShopUser.getDistributionUserId()));
|
|
|
|
|
MkDistributionUser parent = getMkDistributionUserByIdAndShopId(currentShopUser.getDistributionUserId(), config.getShopId());
|
|
|
|
|
try {
|
|
|
|
|
deepReward(orderSourceShopUser, level, config, parent, amount, sourceId, type, orderNo, currentLevel + 1);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
@@ -686,7 +684,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
distributionFlowService.updateById(item);
|
|
|
|
|
} else {
|
|
|
|
|
// 执行扣款
|
|
|
|
|
updateIncome(BigDecimal.ZERO, item.getRewardAmount().negate(), BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(),item.getShopUserId(), item.getShopId(), item.getLevel());
|
|
|
|
|
updateIncome(BigDecimal.ZERO, item.getRewardAmount().negate(), BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopUserId(), item.getShopId(), item.getLevel());
|
|
|
|
|
updateShopInfoAmount(item.getShopId(), item.getRewardAmount(), orderId, TableValueConstant.DistributionAmountFlow.Type.REFUND, "分销回退");
|
|
|
|
|
}
|
|
|
|
|
distributionFlowService.save(refundFlow);
|
|
|
|
|
@@ -708,7 +706,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
}
|
|
|
|
|
log.info("开始分销, 当前来源用户: {}, shopId: {}, 邀请人id: {}", sourceUserId, shopId, sourceInviteUser.getDistributionUserId());
|
|
|
|
|
|
|
|
|
|
MkDistributionUser distributionUser = getById(sourceInviteUser.getDistributionUserId());
|
|
|
|
|
MkDistributionUser distributionUser = getMkDistributionUserByIdAndShopId(sourceInviteUser.getDistributionUserId(), shopId);
|
|
|
|
|
deepReward(sourceShopUserInfo, null, config, distributionUser, amount, sourceId, type, orderNo, 1);
|
|
|
|
|
});
|
|
|
|
|
distributionDeliverService.save(deliver);
|
|
|
|
|
@@ -722,7 +720,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
// 用户可提现余额
|
|
|
|
|
userInfoService.updateDistributionAmount(userId, receivedIncome);
|
|
|
|
|
//分销员余额
|
|
|
|
|
boolean flag = mapper.updateIncome(pendingIncome, receivedIncome, withdrawIncome, id);
|
|
|
|
|
boolean flag = mapper.updateIncome(pendingIncome, receivedIncome, withdrawIncome, id, shopId);
|
|
|
|
|
if (!flag) {
|
|
|
|
|
throw new CzgException("操作失败");
|
|
|
|
|
}
|
|
|
|
|
@@ -785,4 +783,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|
|
|
|
flow.setFailReason(failReason);
|
|
|
|
|
withdrawFlowService.updateById(flow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public MkDistributionUser getMkDistributionUserByIdAndShopId(Long shopUserId, Long shopId) {
|
|
|
|
|
return getOne(new QueryWrapper().eq(MkDistributionUser::getId, shopUserId).eq(MkDistributionUser::getShopId, shopId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|