From de02f98141ca45b78f549e40f5a36ba9c90bdaca Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Tue, 28 Oct 2025 13:41:45 +0800 Subject: [PATCH] =?UTF-8?q?shopUser=20=E5=A2=9E=E5=8A=A0=20=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E6=98=AF=E5=88=86=E9=94=80=E5=91=98=E7=9A=84=E6=A0=87?= =?UTF-8?q?=E8=AF=86=20=E4=BC=9A=E5=91=98=E7=AD=89=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/czg/account/entity/ShopUser.java | 47 +++++++++++++++++-- .../impl/MkDistributionUserServiceImpl.java | 18 ++++--- 2 files changed, 55 insertions(+), 10 deletions(-) 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 61fb3d30..3a9ad8f5 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 @@ -1,5 +1,6 @@ package com.czg.account.entity; +import cn.hutool.core.util.StrUtil; import com.mybatisflex.annotation.Column; import com.mybatisflex.annotation.Id; import com.mybatisflex.annotation.KeyType; @@ -12,8 +13,9 @@ import lombok.experimental.Accessors; import java.io.Serial; import java.io.Serializable; import java.math.BigDecimal; -import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.HashSet; +import java.util.Set; /** * 商户储值会员 实体类。 @@ -22,7 +24,6 @@ import java.time.LocalDateTime; * @since 2025-02-08 */ @Data - @NoArgsConstructor @AllArgsConstructor @Table("tb_shop_user") @@ -157,7 +158,7 @@ public class ShopUser implements Serializable { //邀请人上级累计收益/二级分润 private BigDecimal twoIncome; // 是否分销员 - private Integer isDistribution; + private String distributionShops; @Column(ignore = true) private String memberName; @@ -167,4 +168,44 @@ public class ShopUser implements Serializable { @Column(ignore = true) private Integer isMemberPrice; + + /** + * 检查分销店铺是否包含当前店铺 + */ + public boolean checkDistributionShops(String shopId) { + if (distributionShops == null || StrUtil.isEmpty(shopId)) { + return false; + } + // 按逗号分割并检查每个元素是否完全匹配 + String[] shopIds = distributionShops.split(","); + for (String id : shopIds) { + if (shopId.equals(id.trim())) { + return true; + } + } + return false; + } + + public void addDistributionShop(Long shopId) { + if (shopId == null) { + return; + } + String targetId = shopId.toString().trim(); + if (targetId.isEmpty()) { + return; + } + + // 解析原有字符串为Set(去重+方便判断) + Set shopSet = new HashSet<>(); + if (distributionShops != null && !distributionShops.trim().isEmpty()) { + for (String id : distributionShops.split(",")) { + String trimmedId = id.trim(); + if (!trimmedId.isEmpty()) { + shopSet.add(trimmedId); + } + } + } + shopSet.add(targetId); + distributionShops = String.join(",", shopSet); + } } 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 a2fc9678..940eb1bb 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 @@ -270,7 +270,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl 0) { - throw new CzgException("该用户已被添加为分销员"); + ShopUser shopUser = shopUserService.getById(param.getId()); + AssertUtil.isNull(shopUser, "店铺用户ID不能为空"); + boolean isExits = shopUser.checkDistributionShops(param.getShopId().toString()); + if(isExits){ + throw new CzgException("该用户已被添加为分销员,不可重复添加"); } MkDistributionConfig config = mkDistributionConfigService.getOne( QueryWrapper.create().eq(MkDistributionConfig::getShopId, param.getShopId()) @@ -347,6 +347,10 @@ public class MkDistributionUserServiceImpl extends ServiceImpl