diff --git a/cash-common/cash-common-service/src/main/java/com/czg/market/service/MkDistributionUserService.java b/cash-common/cash-common-service/src/main/java/com/czg/market/service/MkDistributionUserService.java index d52106bf8..4b930b910 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/market/service/MkDistributionUserService.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/market/service/MkDistributionUserService.java @@ -61,12 +61,12 @@ public interface MkDistributionUserService extends IService /** * 发放分销奖励 - * @param orderId 订单id + * @param sourceId 来源id * @param orderNo 订单编号 * @param amount 金额 * @param userId 用户id * @param shopId 店铺id */ - void distribute(Long orderId, String orderNo, BigDecimal amount, Long userId, Long shopId, String type); + void distribute(Long sourceId, String orderNo, BigDecimal amount, Long userId, Long shopId, String type); } diff --git a/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java index 6b7646685..5786fdcee 100644 --- a/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java +++ b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java @@ -191,6 +191,67 @@ public class MkDistributionUserServiceImpl extends ServiceImpl 0) { + long count = distributionFlowService.count(new QueryWrapper().eq(MkDistributionFlow::getSourceShopUserId, sourceShopUser.getId()) + .eq(MkDistributionFlow::getShopUserId, distributionUser.getShopUserId())); + if (count >= config.getRewardCount()) { + log.info("分销员{}已达到奖励次数上限, 次数: {}", distributionUser.getShopUserId(), config.getRewardCount()); + return; + } + } + + // 店铺信息 + BigDecimal rewardAmount; + if (currentLevel == 1) { + rewardAmount = amount.multiply(level.getLevelOneCommission().divide(BigDecimal.valueOf(100), RoundingMode.DOWN)); + }else { + rewardAmount = amount.multiply(level.getLevelTwoCommission().divide(BigDecimal.valueOf(100), RoundingMode.DOWN)); + } + + boolean flag = true; + BigDecimal finalAmount = BigDecimal.ZERO; + try { + shopInfoService.updateAmount(distributionUser.getShopId(), rewardAmount.negate()); + }catch (Exception e) { + flag = false; + } + + MkDistributionFlow mkDistributionFlow = new MkDistributionFlow().setShopUserId(distributionUser.getShopUserId()) + .setShopId(distributionUser.getShopId()).setDistributionUserId(distributionUser.getId()) + .setLevelId(distributionUser.getDistributionLevelId()).setLevel(level.getLevel()).setSourceNickName(sourceShopUser.getNickName()).setOrderNo(orderNo) + .setSourceId(sourceId).setAmount(amount).setType(type).setStatus(flag ? TableValueConstant.DistributionFlow.Status.SUCCESS.getCode() : + TableValueConstant.DistributionFlow.Status.PENDING.getCode()) + .setRewardAmount(rewardAmount); + distributionFlowService.save(mkDistributionFlow); + + if (flag) { + distributionAmountFlowService.save(new MkDistributionAmountFlow() + .setType(TableValueConstant.DistributionAmountFlow.Type.SELF_RECHARGE.getCode()) + .setShopId(config.getShopId()).setAmount(finalAmount).setChangeAmount(amount).setSourceId(mkDistributionFlow.getId()) + .setRemark("自助充值").setOpAccount(StpKit.USER.getAccount())); + } + } @Override public void distribute(Long sourceId, String orderNo, BigDecimal amount, Long sourceUserId, Long shopId, String type) { @@ -204,54 +265,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl 0) { - long count = distributionFlowService.count(new QueryWrapper().eq(MkDistributionFlow::getSourceShopUserId, sourceUserId) - .eq(MkDistributionFlow::getShopUserId, distributionUser.getShopUserId())); - if (count >= config.getRewardCount()) { - log.info("分销员{}已达到奖励次数上限, 次数: {}", distributionUser.getShopUserId(), config.getRewardCount()); - return; - } - } - - // 店铺信息 - ShopInfo shopInfo = shopInfoService.getById(shopId); - BigDecimal oneAmount = amount.multiply(level.getLevelOneCommission().divide(BigDecimal.valueOf(100), RoundingMode.DOWN)); - - boolean flag = true; - BigDecimal finalAmount = BigDecimal.ZERO; - try { - shopInfoService.updateAmount(shopId, oneAmount.negate()); - }catch (Exception e) { - flag = false; - } - - MkDistributionFlow mkDistributionFlow = new MkDistributionFlow().setShopUserId(distributionUser.getShopUserId()).setShopId(distributionUser.getShopId()).setDistributionUserId(distributionUser.getId()) - .setLevelId(distributionUser.getDistributionLevelId()).setLevel(level.getLevel()).setSourceNickName(sourceShopUserInfo.getNickName()).setOrderNo(orderNo) - .setSourceId(sourceId).setAmount(amount).setType(type).setStatus(flag ? TableValueConstant.DistributionFlow.Status.SUCCESS.getCode() : - TableValueConstant.DistributionFlow.Status.PENDING.getCode()) - .setRewardAmount(oneAmount); - distributionFlowService.save(mkDistributionFlow); - - if (flag) { - distributionAmountFlowService.save(new MkDistributionAmountFlow() - .setType(TableValueConstant.DistributionAmountFlow.Type.SELF_RECHARGE.getCode()) - .setShopId(shopId).setAmount(finalAmount).setChangeAmount(amount).setSourceId(mkDistributionFlow.getId()) - .setRemark("自助充值").setOpAccount(StpKit.USER.getAccount())); - } - + deepReward(config, sourceShopUserInfo, amount, sourceId, type, orderNo, 1); }, "分销方法执行失败"); } } diff --git a/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/OrderInfoServiceImpl.java b/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/OrderInfoServiceImpl.java index 6c02e13a1..12d4a657b 100644 --- a/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/OrderInfoServiceImpl.java +++ b/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/OrderInfoServiceImpl.java @@ -100,6 +100,8 @@ public class OrderInfoServiceImpl extends ServiceImpl