分销日志

This commit is contained in:
张松 2025-10-29 18:50:26 +08:00
parent 759a393b7d
commit 2c17e5dcdf
6 changed files with 18 additions and 10 deletions

View File

@ -25,6 +25,6 @@ public interface UserInfoService extends IService<UserInfo> {
Boolean getCode(Long userId, String type); Boolean getCode(Long userId, String type);
void updateDistributionAmount(long userId, BigDecimal amount); void updateDistributionAmount(long userId, BigDecimal amount, Integer isOne);
} }

View File

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

View File

@ -14,5 +14,5 @@ import java.math.BigDecimal;
*/ */
public interface UserInfoMapper extends BaseMapper<UserInfo> { public interface UserInfoMapper extends BaseMapper<UserInfo> {
int updateAmount(long userId, BigDecimal amount); int updateAmount(long userId, BigDecimal amount, Integer isOne);
} }

View File

@ -101,8 +101,8 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> i
} }
@Override @Override
public void updateDistributionAmount(long userId, BigDecimal amount) { public void updateDistributionAmount(long userId, BigDecimal amount, Integer isOne) {
int b = mapper.updateAmount(userId, amount); int b = mapper.updateAmount(userId, amount, isOne);
if (b <= 0) { if (b <= 0) {
throw new CzgException("更新分销金额失败"); throw new CzgException("更新分销金额失败");
} }

View File

@ -6,6 +6,12 @@
<update id="updateAmount"> <update id="updateAmount">
update tb_user_info set distribution_amount = distribution_amount + #{amount} where id = #{userId} update tb_user_info set distribution_amount = distribution_amount + #{amount} where id = #{userId}
<if test="isOne != null and isOne == 1">
,one_income = one_income + #{amount}
</if>
<if test="isOne != null and isOne == 2">
,two_income = two_income + #{amount}
</if>
and distribution_amount + #{amount} >= 0 and distribution_amount + #{amount} >= 0
</update> </update>
</mapper> </mapper>

View File

@ -579,6 +579,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
MkDistributionLevelConfig level = levelConfigService.getById(distributionUser.getDistributionLevelId()); MkDistributionLevelConfig level = levelConfigService.getById(distributionUser.getDistributionLevelId());
AssertUtil.isNull(level, "分销等级不存在"); AssertUtil.isNull(level, "分销等级不存在");
log.info("当前分销员: {}, 上级分销员: {}, 分销等级: {}", distributionUser.getId(), sourceShopUser.getDistributionUserParentId(), level.getId());
if (config.getRewardCount() != null && config.getRewardCount() > 0) { if (config.getRewardCount() != null && config.getRewardCount() > 0) {
long count = distributionFlowService.count(new QueryWrapper().eq(MkDistributionFlow::getSourceShopUserId, sourceShopUser.getId()) long count = distributionFlowService.count(new QueryWrapper().eq(MkDistributionFlow::getSourceShopUserId, sourceShopUser.getId())
@ -617,7 +618,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
distributionFlowService.save(mkDistributionFlow); distributionFlowService.save(mkDistributionFlow);
updateIncome(!flag ? rewardAmount : BigDecimal.ZERO, updateIncome(!flag ? rewardAmount : BigDecimal.ZERO,
flag ? rewardAmount : BigDecimal.ZERO, BigDecimal.ZERO, distributionUser.getId(), shopUser.getUserId()); flag ? rewardAmount : BigDecimal.ZERO, BigDecimal.ZERO, distributionUser.getId(), shopUser.getUserId(), currentLevel == 1 ? 1 : 2);
if (flag) { if (flag) {
distributionAmountFlowService.save(new MkDistributionAmountFlow() distributionAmountFlowService.save(new MkDistributionAmountFlow()
@ -640,6 +641,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
if (sourceShopUserInfo.getDistributionUserId() == null) { if (sourceShopUserInfo.getDistributionUserId() == null) {
return; return;
} }
log.info("开始分销, 当前来源用户: {}, shopId: {}, 邀请人id: {}", sourceUserId, shopId, sourceShopUserInfo.getDistributionUserId());
ShopUser parentUserInfo = shopUserService.getById(sourceShopUserInfo.getDistributionUserId()); ShopUser parentUserInfo = shopUserService.getById(sourceShopUserInfo.getDistributionUserId());
deepReward(config, parentUserInfo, amount, sourceId, type, orderNo, 1); deepReward(config, parentUserInfo, amount, sourceId, type, orderNo, 1);
@ -647,8 +649,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
} }
@Override @Override
public void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId) { public void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Integer isOne) {
userInfoService.updateDistributionAmount(userId, receivedIncome); userInfoService.updateDistributionAmount(userId, receivedIncome, isOne);
boolean flag = mapper.updateIncome(pendingIncome, receivedIncome, withdrawIncome, id); boolean flag = mapper.updateIncome(pendingIncome, receivedIncome, withdrawIncome, id);
if (!flag) { if (!flag) {
throw new CzgException("操作失败"); throw new CzgException("操作失败");
@ -674,7 +676,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
JSONObject jsonObject = appWxService.transferBalance(userInfo.getWechatOpenId(), userInfo.getRealName(), finalAmount, "提现", withdrawFlow.getBillNo()); JSONObject jsonObject = appWxService.transferBalance(userInfo.getWechatOpenId(), userInfo.getRealName(), finalAmount, "提现", withdrawFlow.getBillNo());
withdrawFlow.setPackageInfo(jsonObject.getString("package_info")); withdrawFlow.setPackageInfo(jsonObject.getString("package_info"));
// 扣减余额 // 扣减余额
userInfoService.updateDistributionAmount(userId, withdrawFlowDTO.getAmount().negate()); userInfoService.updateDistributionAmount(userId, withdrawFlowDTO.getAmount().negate(), null);
return withdrawFlowService.save(withdrawFlow); return withdrawFlowService.save(withdrawFlow);
} }
@ -705,7 +707,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
case "CANCELLED": case "CANCELLED":
flow.setStatus(TableValueConstant.DistributionWithdrawFlow.Status.FAIL.getCode()); flow.setStatus(TableValueConstant.DistributionWithdrawFlow.Status.FAIL.getCode());
// 扣减余额 // 扣减余额
userInfoService.updateDistributionAmount(flow.getUserId(), flow.getAmount().add(flow.getServiceFee())); userInfoService.updateDistributionAmount(flow.getUserId(), flow.getAmount().add(flow.getServiceFee()), null);
break; break;
} }