运营端充值 分账修改

This commit is contained in:
张松
2025-10-30 10:23:19 +08:00
parent cb5f006c22
commit 96ecb86d42
6 changed files with 66 additions and 46 deletions

View File

@@ -554,7 +554,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
distributionAmountFlowService.save(new MkDistributionAmountFlow()
.setType(TableValueConstant.DistributionAmountFlow.Type.SELF_RECHARGE.getCode())
.setMainShopId(mainShopId).setShopId(shopId).setAmount(finalAmount).setChangeAmount(amount).setSourceId(paymentId)
.setRemark("自助充值").setOpAccount(StpKit.USER.getAccount()));
.setRemark("自助充值"));
}
@@ -610,56 +610,52 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
// }
rewardAmount = amount.multiply(finalCommission.divide(BigDecimal.valueOf(100), RoundingMode.DOWN));
boolean flag = true;
BigDecimal finalAmount = BigDecimal.ZERO;
try {
finalAmount = shopInfoService.updateAmount(currentDistributionUser.getShopId(), rewardAmount.negate());
} catch (Exception e) {
flag = false;
}
ShopUser shopUser = shopUserService.getById(currentDistributionUser.getId());
// 延时发放时间
LocalDateTime delayTime = config.getSettlementDay() == null || config.getSettlementDay() == 0 ? null : DateUtil.offsetDay(DateUtil.date(), config.getSettlementDay()).toLocalDateTime();
// 用户分账明细
ShopUser shopUser = shopUserService.getById(currentDistributionUser.getId());
MkDistributionFlow mkDistributionFlow = new MkDistributionFlow().setShopUserId(currentDistributionUser.getId())
.setShopId(currentDistributionUser.getShopId()).setDistributionUserId(currentDistributionUser.getId())
.setNickName(shopUser.getNickName()).setSourceShopUserId(orderSourceShopUser.getId()).setSourceNickName(orderSourceShopUser.getNickName())
.setCommission(finalCommission).setParentCommission(parentLevel.getLevelOneCommission())
.setCommission(finalCommission).setParentCommission(parentLevel != null ? parentLevel.getLevelOneCommission() : null)
.setLevelId(currentDistributionUser.getDistributionLevelId()).setLevel(currentLevel == 1 ? 1 : 2).setOrderNo(orderNo)
.setSourceId(sourceId).setAmount(amount).setType(type).setStatus(flag ? TableValueConstant.DistributionFlow.Status.SUCCESS.getCode() :
TableValueConstant.DistributionFlow.Status.PENDING.getCode())
.setSourceId(sourceId).setAmount(amount).setType(type)
.setRewardAmount(rewardAmount).setBillNo(IdUtil.simpleUUID());
distributionFlowService.save(mkDistributionFlow);
updateIncome(!flag ? rewardAmount : BigDecimal.ZERO,
flag ? rewardAmount : BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
if (delayTime == null) {
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode());
try {
updateShopInfoAmount(currentDistributionUser.getShopId(), rewardAmount, mkDistributionFlow.getId());
updateIncome(BigDecimal.ZERO, rewardAmount, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
} catch (Exception e) {
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.PENDING.getCode());
distributionFlowService.updateById(mkDistributionFlow);
}
}else {
updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
if (flag) {
distributionAmountFlowService.save(new MkDistributionAmountFlow()
.setType(TableValueConstant.DistributionAmountFlow.Type.SUB.getCode())
.setShopId(config.getShopId()).setAmount(finalAmount).setChangeAmount(rewardAmount).setSourceId(mkDistributionFlow.getId())
.setRemark("分账扣除"));
}
}
@Override
public void distribute(Long sourceId, String orderNo, BigDecimal amount, Long sourceUserId, Long shopId, String type, boolean isTask) {
MkDistributionDeliver deliver = new MkDistributionDeliver().setSourceId(sourceId).setOrderNo(orderNo).setShopId(shopId).setType(type).setStatus("pending");
public BigDecimal updateShopInfoAmount(Long shopId, BigDecimal changeAmount, Long sourceId) {
BigDecimal finalAmount = shopInfoService.updateAmount(shopId, changeAmount.negate());
distributionAmountFlowService.save(new MkDistributionAmountFlow()
.setType(TableValueConstant.DistributionAmountFlow.Type.SUB.getCode())
.setShopId(shopId).setAmount(finalAmount).setChangeAmount(changeAmount).setSourceId(sourceId)
.setRemark("分账扣除"));
return finalAmount;
}
@Override
public void distribute(Long sourceId, String orderNo, BigDecimal amount, Long sourceUserId, Long shopId, String type) {
MkDistributionDeliver deliver = new MkDistributionDeliver().setSourceId(sourceId).setOrderNo(orderNo).setShopId(shopId).setType(type).setStatus("success");
FunUtils.safeRunVoid(() -> {
AssertUtil.isTrue(amount.compareTo(BigDecimal.ZERO) == 0, "分销金额不能为0");
MkDistributionConfigVO config = mkDistributionConfigService.detail(shopId);
AssertUtil.isTrue(config.getIsEnable() != 1, "分销未开启");
if (!isTask) {
if (config.getSettlementDay() != null && config.getSettlementDay() != 0) {
deliver.setShouldDeliverTime(DateUtil.offsetDay(DateUtil.date(), config.getSettlementDay()).toLocalDateTime());
log.info("延时发放, {}", config.getSettlementDay());
return;
}else {
deliver.setStatus("success");
}
}
// 当前用户上级分销员
ShopUser sourceShopUserInfo = shopUserService.getShopUserInfo(shopId, sourceUserId);
if (sourceShopUserInfo.getDistributionUserId() == null) {
@@ -670,15 +666,16 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
MkDistributionUser distributionUser = getById(sourceShopUserInfo.getDistributionUserId());
deepReward(sourceShopUserInfo, null, config, distributionUser, amount, sourceId, type, orderNo, 1);
});
if (!isTask) {
distributionDeliverService.save(deliver);
}
distributionDeliverService.save(deliver);
}
@Override
public void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Long mainShopId, Integer isOne) {
shopUserService.updateOneOrTwoAmount(userId, mainShopId, receivedIncome == null ? pendingIncome : receivedIncome, isOne);
// 用户收益信息
shopUserService.updateOneOrTwoAmount(userId, mainShopId, receivedIncome, isOne);
// 用户可提现余额
userInfoService.updateDistributionAmount(userId, receivedIncome);
//分销员余额
boolean flag = mapper.updateIncome(pendingIncome, receivedIncome, withdrawIncome, id);
if (!flag) {
throw new CzgException("操作失败");

View File

@@ -1066,7 +1066,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
// 分销员升级等级
distributionUserService.costUpgradeLevelBefore(orderInfo.getUserId(), orderInfo.getShopId());
// 分销奖励
distributionUserService.distribute(orderInfo.getId(), payment.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), orderInfo.getShopId(), "order",false);
distributionUserService.distribute(orderInfo.getId(), payment.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), orderInfo.getShopId(), "order");
} else if ("memberIn".equals(payment.getPayType()) || "free".equals(payment.getPayType())) {
boolean isFree = "free".equals(payment.getPayType());
ShopUser shopUser = shopUserService.getById(payment.getSourceId());