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 ccd5dded..b7bb61e0 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