分销修改

This commit is contained in:
张松
2025-11-06 10:46:15 +08:00
parent 94f46b8894
commit d96d692b61
7 changed files with 23 additions and 21 deletions

View File

@@ -79,9 +79,9 @@ public class DistributionTask {
} else {
item.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode());
ShopUser shopUser = shopUserService.getById(item.getDistributionUserId());
distributionUserService.updateIncome(item.getRewardAmount().negate(), item.getRewardAmount(), BigDecimal.ZERO,
item.getDistributionUserId(), shopUser.getUserId(), item.getShopId(), item.getLevel());
distributionUserService.updateShopInfoAmount(orderInfo.getShopId(), item.getRewardAmount().negate(), orderInfo.getId(), TableValueConstant.DistributionAmountFlow.Type.SUB, "分销扣减");
distributionUserService.updateIncome(item.getRewardAmount().negate(), item.getRewardAmount(), BigDecimal.ZERO,
item.getDistributionUserId(), shopUser.getUserId(), item.getShopUserId(), item.getShopId(), item.getLevel());
}
distributionFlowService.updateById(item);
});

View File

@@ -36,5 +36,5 @@ public interface ShopUserService extends IService<ShopUser> {
List<ShopUser> selectBirthdayUser(LocalDate current, Long mainShopId, String userType);
void updateOneOrTwoAmount(Long userId, Long mainShopId, BigDecimal bigDecimal, Integer isOne);
void updateOneOrTwoAmount(Long shopUserId, Long shopId, BigDecimal bigDecimal, Integer isOne);
}

View File

@@ -132,7 +132,7 @@ public interface MkDistributionUserService extends IService<MkDistributionUser>
*/
void distribute(Long sourceId, String orderNo, BigDecimal amount, Long userId, Long shopId, String type);
void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Long shopId, Integer isOne);
void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Long shopUserId, Long shopId, Integer isOne);
Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO);

View File

@@ -72,6 +72,6 @@ public interface ShopUserMapper extends BaseMapper<ShopUser> {
*/
List<InviteUserVO> getInviteUser(Long distributionUserId, Long shopUserId, Long distributionLevelId);
void updateOneOrTwoAmount(Long userId, Long mainShopId, BigDecimal amount, Integer isOne);
void updateOneOrTwoAmount(Long shopUserId, Long shopId, BigDecimal amount, Integer isOne);
}

View File

@@ -171,7 +171,7 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
}
@Override
public void updateOneOrTwoAmount(Long userId, Long mainShopId, BigDecimal bigDecimal, Integer isOne) {
mapper.updateOneOrTwoAmount(userId, mainShopId, bigDecimal, isOne);
public void updateOneOrTwoAmount(Long shopUserId, Long shopId, BigDecimal bigDecimal, Integer isOne) {
mapper.updateOneOrTwoAmount(shopUserId, shopId, bigDecimal, isOne);
}
}

View File

@@ -18,7 +18,7 @@
and amount - #{money} >= 0
</update>
<update id="updateOneOrTwoAmount">
update tb_shop_user
update tb_shop_user_invite
<set>
<if test="isOne != null and isOne == 1">
one_income = one_income + #{amount}
@@ -27,8 +27,8 @@
two_income = two_income + #{amount}
</if>
</set>
where user_id = #{userId}
and main_shop_id = #{mainShopId}
where shop_user_id = #{shopUserId}
and shop_id = #{shopId}
</update>

View File

@@ -578,7 +578,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
AssertUtil.isNull(currentDistributionUser, "分销员不存在");
AssertUtil.isTrue(currentDistributionUser.getStatus() != 1, "分销员未开启");
ShopUser currentShopUser = shopUserService.getById(currentDistributionUser.getId());
// ShopUser currentShopUser = shopUserService.getById(currentDistributionUser.getId());
ShopUserInvite currentShopUser = shopUserInviteService.getOneByShopIdAndShopUserId(config.getShopId(), currentDistributionUser.getId());
MkDistributionLevelConfig level = levelConfigService.getById(currentDistributionUser.getDistributionLevelId());
// 校验剩余分成比例
@@ -639,10 +640,10 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
log.info("即时分销开始");
try {
updateShopInfoAmount(currentDistributionUser.getShopId(), rewardAmount.negate(), sourceId, TableValueConstant.DistributionAmountFlow.Type.SUB, "分销扣除");
updateIncome(BigDecimal.ZERO, rewardAmount, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
updateIncome(BigDecimal.ZERO, rewardAmount, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getId(), config.getShopId(), currentLevel == 1 ? 1 : 2);
} catch (Exception e) {
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.PENDING.getCode());
updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getId(), config.getShopId(), currentLevel == 1 ? 1 : 2);
distributionFlowService.updateById(mkDistributionFlow);
}
} else {
@@ -650,7 +651,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.PENDING.getCode());
distributionFlowService.save(mkDistributionFlow);
log.info("延时分销开始");
updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getId(), config.getShopId(), currentLevel == 1 ? 1 : 2);
}
}
@@ -681,11 +682,11 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
refundFlow.setUpdateTime(DateUtil.date().toLocalDateTime());
if (TableValueConstant.DistributionFlow.Status.PENDING.getCode().equals(item.getStatus())) {
item.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode());
updateIncome(item.getRewardAmount().negate(), BigDecimal.ZERO, BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopId(), item.getLevel());
updateIncome(item.getRewardAmount().negate(), BigDecimal.ZERO, BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopUserId(), item.getShopId(), item.getLevel());
distributionFlowService.updateById(item);
} else {
// 执行扣款
updateIncome(BigDecimal.ZERO, item.getRewardAmount().negate(), BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), 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);
@@ -701,12 +702,13 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
AssertUtil.isTrue(config.getIsEnable() != 1, "分销未开启");
// 当前用户上级分销员
ShopUser sourceShopUserInfo = shopUserService.getShopUserInfo(shopId, sourceUserId);
if (sourceShopUserInfo.getDistributionUserId() == null) {
ShopUserInvite sourceInviteUser = shopUserInviteService.getOneByShopIdAndShopUserId(shopId, sourceShopUserInfo.getId());
if (sourceInviteUser.getDistributionUserId() == null) {
return;
}
log.info("开始分销, 当前来源用户: {}, shopId: {}, 邀请人id: {}", sourceUserId, shopId, sourceShopUserInfo.getDistributionUserId());
log.info("开始分销, 当前来源用户: {}, shopId: {}, 邀请人id: {}", sourceUserId, shopId, sourceInviteUser.getDistributionUserId());
MkDistributionUser distributionUser = getById(sourceShopUserInfo.getDistributionUserId());
MkDistributionUser distributionUser = getById(sourceInviteUser.getDistributionUserId());
deepReward(sourceShopUserInfo, null, config, distributionUser, amount, sourceId, type, orderNo, 1);
});
distributionDeliverService.save(deliver);
@@ -714,9 +716,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
@Override
@Transactional(rollbackFor = Exception.class)
public void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Long mainShopId, Integer isOne) {
public void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Long shopUserId, Long shopId, Integer isOne) {
// 用户收益信息
shopUserService.updateOneOrTwoAmount(userId, mainShopId, receivedIncome, isOne);
shopUserService.updateOneOrTwoAmount(shopUserId, shopId, receivedIncome, isOne);
// 用户可提现余额
userInfoService.updateDistributionAmount(userId, receivedIncome);
//分销员余额