From 1a18449d65cb0a4635332cb6341eecbd7154b570 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 23 Jan 2026 16:35:56 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=80=E8=AF=B7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/UDistributionController.java | 20 +-- .../java/com/czg/account/entity/ShopUser.java | 17 +++ .../czg/market/entity/MkDistributionFlow.java | 4 +- .../entity/MkDistributionLevelConfig.java | 6 +- .../com/czg/market/entity/ShopUserInvite.java | 74 ----------- .../market/service/ShopUserInviteService.java | 22 ---- .../main/resources/mapper/ShopUserMapper.xml | 22 ++-- .../market/mapper/ShopUserInviteMapper.java | 14 -- .../impl/MkDistributionUserServiceImpl.java | 120 ++++++------------ .../impl/ShopUserInviteServiceImpl.java | 25 ---- .../mapper/MkDistributionUserMapper.xml | 8 +- .../resources/mapper/ShopUserInviteMapper.xml | 7 - 12 files changed, 79 insertions(+), 260 deletions(-) delete mode 100644 cash-common/cash-common-service/src/main/java/com/czg/market/entity/ShopUserInvite.java delete mode 100644 cash-common/cash-common-service/src/main/java/com/czg/market/service/ShopUserInviteService.java delete mode 100644 cash-service/market-service/src/main/java/com/czg/service/market/mapper/ShopUserInviteMapper.java delete mode 100644 cash-service/market-service/src/main/java/com/czg/service/market/service/impl/ShopUserInviteServiceImpl.java delete mode 100644 cash-service/market-service/src/main/resources/mapper/ShopUserInviteMapper.xml diff --git a/cash-api/market-server/src/main/java/com/czg/controller/user/UDistributionController.java b/cash-api/market-server/src/main/java/com/czg/controller/user/UDistributionController.java index 941ee352e..7d5b1c4c7 100644 --- a/cash-api/market-server/src/main/java/com/czg/controller/user/UDistributionController.java +++ b/cash-api/market-server/src/main/java/com/czg/controller/user/UDistributionController.java @@ -4,8 +4,10 @@ import com.czg.account.entity.UserInfo; import com.czg.market.dto.MkDistributionUserDTO; import com.czg.market.dto.MkDistributionWithdrawFlowDTO; import com.czg.market.entity.MkDistributionWithdrawFlow; -import com.czg.market.entity.ShopUserInvite; -import com.czg.market.service.*; +import com.czg.market.service.MkDistributionConfigService; +import com.czg.market.service.MkDistributionFlowService; +import com.czg.market.service.MkDistributionUserService; +import com.czg.market.service.MkDistributionWithdrawFlowService; import com.czg.market.vo.DistributionCenterShopVO; import com.czg.market.vo.InviteUserVO; import com.czg.market.vo.MkDistributionConfigVO; @@ -14,7 +16,6 @@ import com.czg.sa.StpKit; import com.czg.task.DistributionTask; import com.czg.utils.AssertUtil; import com.mybatisflex.core.paginate.Page; -import com.mybatisflex.core.query.QueryWrapper; import io.seata.core.exception.TransactionException; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; @@ -43,19 +44,6 @@ public class UDistributionController { private MkDistributionFlowService distributionFlowService; @Resource private DistributionTask distributionTask; - @Resource - private ShopUserInviteService shopUserInviteService; - - - /** - * 测试方法-清空绑定 - */ - @GetMapping("/clean") - public CzgResult task() { - shopUserInviteService.remove(QueryWrapper.create().gt(ShopUserInvite::getId, 1)); - return CzgResult.success(true); - } - /** * 测试方法-分销流水入账 diff --git a/cash-common/cash-common-service/src/main/java/com/czg/account/entity/ShopUser.java b/cash-common/cash-common-service/src/main/java/com/czg/account/entity/ShopUser.java index 961c7c69e..1fb6dff35 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/account/entity/ShopUser.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/account/entity/ShopUser.java @@ -152,6 +152,23 @@ public class ShopUser implements Serializable { private LocalDateTime nextDeliverTime; // 是否分销员 private String distributionShops; + /** + * 上级分销员id + */ + private Long parentUserId; + /** + * 上上级分销员id + */ + private Long gradeUserId; + /** + * 一级分销收入 + */ + private BigDecimal oneIncome; + /** + * 二级分销收入 + */ + private BigDecimal twoIncome; + private String memberCircleName; private Integer memberCircleReward; diff --git a/cash-common/cash-common-service/src/main/java/com/czg/market/entity/MkDistributionFlow.java b/cash-common/cash-common-service/src/main/java/com/czg/market/entity/MkDistributionFlow.java index 9f5262993..4f0273ec8 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/market/entity/MkDistributionFlow.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/market/entity/MkDistributionFlow.java @@ -110,8 +110,10 @@ public class MkDistributionFlow implements Serializable { private String nickName; + /** + * 分成比例 + */ private BigDecimal commission; - private BigDecimal parentCommission; private LocalDateTime deliverTime; private Long userId; } diff --git a/cash-common/cash-common-service/src/main/java/com/czg/market/entity/MkDistributionLevelConfig.java b/cash-common/cash-common-service/src/main/java/com/czg/market/entity/MkDistributionLevelConfig.java index 12b049c02..e82b25919 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/market/entity/MkDistributionLevelConfig.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/market/entity/MkDistributionLevelConfig.java @@ -62,12 +62,8 @@ public class MkDistributionLevelConfig implements Serializable { /** * 一级分销比例 */ - private BigDecimal levelOneCommission; + private BigDecimal commission; - /** - * 二级分销比例 - */ - private BigDecimal levelTwoCommission; /** * 创建时间 diff --git a/cash-common/cash-common-service/src/main/java/com/czg/market/entity/ShopUserInvite.java b/cash-common/cash-common-service/src/main/java/com/czg/market/entity/ShopUserInvite.java deleted file mode 100644 index fa0afa8df..000000000 --- a/cash-common/cash-common-service/src/main/java/com/czg/market/entity/ShopUserInvite.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.czg.market.entity; - -import com.mybatisflex.annotation.Id; -import com.mybatisflex.annotation.KeyType; -import com.mybatisflex.annotation.Table; -import java.io.Serializable; -import java.math.BigDecimal; -import java.time.LocalDateTime; - -import java.io.Serial; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * 邀请与上级关联表 实体类。 - * - * @author ww - * @since 2025-11-06 - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@Table("tb_shop_user_invite") -public class ShopUserInvite implements Serializable { - - @Serial - private static final long serialVersionUID = 1L; - - /** - * (随机) - */ - @Id(keyType = KeyType.Auto) - private Long id; - - /** - * 店铺ID - */ - private Long shopId; - - /** - * 店铺用户ID - */ - private Long shopUserId; - - /** - * 邀请人ID mk_distribution_user.id - */ - private Long distributionUserId; - - /** - * 邀请人上级ID mk_distribution_user.id - */ - private Long distributionUserParentId; - - /** - * 邀请人收益/一级分润 - */ - private BigDecimal oneIncome; - - /** - * 邀请人上级收益/二级分润 - */ - private BigDecimal twoIncome; - - /** - * 邀请时间 - */ - private LocalDateTime inviteTime; - -} diff --git a/cash-common/cash-common-service/src/main/java/com/czg/market/service/ShopUserInviteService.java b/cash-common/cash-common-service/src/main/java/com/czg/market/service/ShopUserInviteService.java deleted file mode 100644 index e9d10908e..000000000 --- a/cash-common/cash-common-service/src/main/java/com/czg/market/service/ShopUserInviteService.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.czg.market.service; - -import com.mybatisflex.core.service.IService; -import com.czg.market.entity.ShopUserInvite; - -/** - * 邀请与上级关联表 服务层。 - * - * @author ww - * @since 2025-11-06 - */ -public interface ShopUserInviteService extends IService { - - /** - * 根据店铺ID和店铺用户ID查询邀请记录 - * - * @param shopId 店铺ID - * @param shopUserId 店铺用户ID - * @return 邀请记录 - */ - ShopUserInvite getOneByShopIdAndShopUserId(Long shopId, Long shopUserId); -} diff --git a/cash-service/account-service/src/main/resources/mapper/ShopUserMapper.xml b/cash-service/account-service/src/main/resources/mapper/ShopUserMapper.xml index 448d425ae..c380c7a10 100644 --- a/cash-service/account-service/src/main/resources/mapper/ShopUserMapper.xml +++ b/cash-service/account-service/src/main/resources/mapper/ShopUserMapper.xml @@ -18,7 +18,7 @@ and amount - #{money} >= 0 - update tb_shop_user_invite + update tb_shop_user one_income = one_income + #{amount} @@ -27,8 +27,7 @@ two_income = two_income + #{amount} - where shop_user_id = #{shopUserId} - and shop_id = #{shopId} + where id = #{shopUserId} @@ -257,10 +256,10 @@ diff --git a/cash-service/market-service/src/main/java/com/czg/service/market/mapper/ShopUserInviteMapper.java b/cash-service/market-service/src/main/java/com/czg/service/market/mapper/ShopUserInviteMapper.java deleted file mode 100644 index 5e2c6bccf..000000000 --- a/cash-service/market-service/src/main/java/com/czg/service/market/mapper/ShopUserInviteMapper.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.czg.service.market.mapper; - -import com.mybatisflex.core.BaseMapper; -import com.czg.market.entity.ShopUserInvite; - -/** - * 邀请与上级关联表 映射层。 - * - * @author ww - * @since 2025-11-06 - */ -public interface ShopUserInviteMapper extends BaseMapper { - -} 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 eee6c5fad..d0bbab46c 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 @@ -73,12 +73,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl 2) { - return; - } + protected boolean deepReward(ShopUser orderSourceShopUser, BigDecimal commission, MkDistributionConfigVO config, + MkDistributionUser currentDistributionUser, BigDecimal amount, Long sourceId, + String type, String orderNo, Integer currentLevel) { // 当前分销员 AssertUtil.isNull(currentDistributionUser, "分销员不存在"); AssertUtil.isTrue(currentDistributionUser.getStatus() != 1, "分销员未开启"); - -// ShopUser currentShopUser = shopUserService.getById(currentDistributionUser.getId()); - ShopUserInvite currentShopUser = shopUserInviteService.getOneByShopIdAndShopUserId(config.getShopId(), currentDistributionUser.getId()); - MkDistributionLevelConfig level = levelConfigService.getById(currentDistributionUser.getDistributionLevelId()); - - // 校验剩余分成比例 - BigDecimal finalCommission = parentLevel == null ? level.getLevelOneCommission() : level.getLevelOneCommission().subtract(parentLevel.getLevelOneCommission()); - if (finalCommission.compareTo(BigDecimal.ZERO) <= 0) { - log.info("当前分销员: {}, 分销等级: {}, 剩余比例: {}, 不参与分销", currentDistributionUser.getId(), level.getId(), finalCommission); - return; + if (commission.compareTo(BigDecimal.ZERO) <= 0) { + return false; } - // 上上级分销员 - if (currentShopUser != null && currentShopUser.getDistributionUserId() != null) { - MkDistributionUser parent = getMkDistributionUserByIdAndShopId(currentShopUser.getDistributionUserId(), config.getShopId()); - try { - deepReward(orderSourceShopUser, level, config, parent, amount, sourceId, type, orderNo, currentLevel + 1); - } catch (Exception e) { - log.warn("分销奖励失败: {}", e.getMessage()); - } - } - - AssertUtil.isNull(level, "分销等级不存在"); - log.info("当前分销员: {}, 上级分销员: {}, 分销等级: {}", currentDistributionUser.getId(), currentShopUser == null ? null : currentShopUser.getDistributionUserId(), level.getId()); - if (config.getRewardCount() != null && config.getRewardCount() > 0) { long count = distributionFlowService.count(new QueryWrapper() .eq(MkDistributionFlow::getShopId, config.getShopId()).eq(MkDistributionFlow::getShopUserId, currentDistributionUser.getId())); if (count >= config.getRewardCount()) { log.info("分销员{}已达到奖励次数上限, 次数: {}", currentDistributionUser.getId(), config.getRewardCount()); - return; - } else { - log.info("分销员奖励次数: {}", count); + return false; } } // 店铺信息 - 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)); -// } - rewardAmount = amount.multiply(finalCommission.divide(BigDecimal.valueOf(100), RoundingMode.DOWN)); - + BigDecimal rewardAmount = amount.multiply(commission.divide(BigDecimal.valueOf(100), RoundingMode.DOWN)); // 延时发放时间 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()) .setUserId(shopUser.getUserId()) .setNickName(shopUser.getNickName()).setSourceShopUserId(orderSourceShopUser.getId()).setSourceNickName(orderSourceShopUser.getNickName()) - .setCommission(finalCommission).setParentCommission(parentLevel != null ? parentLevel.getLevelOneCommission() : null) - .setLevelId(currentDistributionUser.getDistributionLevelId()).setLevel(currentLevel == 1 ? 1 : 2).setOrderNo(orderNo) + .setCommission(commission) + .setLevelId(currentDistributionUser.getDistributionLevelId()).setLevel(currentLevel).setOrderNo(orderNo) .setSourceId(sourceId).setAmount(amount).setType(type) .setRewardAmount(rewardAmount).setBillNo(IdUtil.simpleUUID()); @@ -655,6 +611,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl implements ShopUserInviteService { - - @Override - public ShopUserInvite getOneByShopIdAndShopUserId(Long shopId, Long shopUserId) { - return getOne(QueryWrapper.create() - .eq(ShopUserInvite::getShopId, shopId) - .eq(ShopUserInvite::getShopUserId, shopUserId)); - } -} diff --git a/cash-service/market-service/src/main/resources/mapper/MkDistributionUserMapper.xml b/cash-service/market-service/src/main/resources/mapper/MkDistributionUserMapper.xml index 7d2d9ed66..70de08651 100644 --- a/cash-service/market-service/src/main/resources/mapper/MkDistributionUserMapper.xml +++ b/cash-service/market-service/src/main/resources/mapper/MkDistributionUserMapper.xml @@ -65,15 +65,13 @@