邀请人列表 条件 添加邀请人 邀请身份 是否有效

This commit is contained in:
2025-10-30 17:59:55 +08:00
parent 84d2420c59
commit 86e6714f97
10 changed files with 136 additions and 120 deletions

View File

@@ -44,10 +44,11 @@ public class DistributionUserController {
public CzgResult<Page<InviteUserVO>> getInviteUser( public CzgResult<Page<InviteUserVO>> getInviteUser(
@RequestParam Long id, @RequestParam Long id,
@RequestParam(required = false) Long shopUserId, @RequestParam(required = false) Long shopUserId,
@RequestParam(required = false) Long distributionLevelId,
@RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "1") Integer page,
@RequestParam(required = false, defaultValue = "10") Integer size) { @RequestParam(required = false, defaultValue = "10") Integer size) {
AssertUtil.isNull(id, "邀请人ID"); AssertUtil.isNull(id, "邀请人ID");
return CzgResult.success(distributionUserService.getInviteUser(id, shopUserId, page, size)); return CzgResult.success(distributionUserService.getInviteUser(id, shopUserId, distributionLevelId, page, size));
} }
/** /**

View File

@@ -122,7 +122,7 @@ public class UDistributionController {
@RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "1") Integer page,
@RequestParam(required = false, defaultValue = "10") Integer size) { @RequestParam(required = false, defaultValue = "10") Integer size) {
AssertUtil.isNull(id, "邀请人ID"); AssertUtil.isNull(id, "邀请人ID");
return CzgResult.success(distributionUserService.getInviteUser(id, null, page, size)); return CzgResult.success(distributionUserService.getInviteUser(id, null, null, page, size));
} }
/** /**

View File

@@ -171,44 +171,38 @@ public class ShopUser implements Serializable {
@JSONField(format = "yyyy-MM-dd HH:mm:ss") @JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime inviteTime; private LocalDateTime inviteTime;
/** /**
* 检查分销店铺是否包含当前店铺 * 添加或更新分销店铺若shopId已存在无论后缀则替换为新的id_后缀否则插入
*
* @param shopId 店铺ID
* @param suffix 新后缀
*/ */
public boolean checkDistributionShops(String shopId) { public void upDistributionShop(Long shopId, int suffix) {
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) { if (shopId == null) {
return; return;
} }
String targetId = shopId.toString().trim(); String shopIdStr = shopId.toString().trim();
if (targetId.isEmpty()) { if (shopIdStr.isEmpty()) {
return; return;
} }
// 解析原有字符串为Set(去重+方便判断) // 解析原有字符串为Set
Set<String> shopSet = new HashSet<>(); Set<String> shopSet = new HashSet<>();
if (distributionShops != null && !distributionShops.trim().isEmpty()) { if (distributionShops != null && !distributionShops.trim().isEmpty()) {
for (String id : distributionShops.split(",")) { for (String idWithSuffix : distributionShops.split(",")) {
String trimmedId = id.trim(); String trimmed = idWithSuffix.trim();
if (!trimmedId.isEmpty()) { if (trimmed.isEmpty()) {
shopSet.add(trimmedId); continue;
}
// 判断:如果不是以 "shopId_" 开头的记录,则保留
if (!trimmed.startsWith(shopIdStr + "_")) {
shopSet.add(trimmed);
} }
} }
} }
shopSet.add(targetId); // 添加新的id_后缀
shopSet.add(shopIdStr + "_" + suffix);
// 重新拼接字符串
distributionShops = String.join(",", shopSet); distributionShops = String.join(",", shopSet);
} }
} }

View File

@@ -29,7 +29,7 @@ public interface ShopUserService extends IService<ShopUser> {
/** /**
* 获取邀请用户列表 * 获取邀请用户列表
*/ */
Page<InviteUserVO> getInviteUser(Long getDistributionUserId, Long shopUserId, Integer page, Integer size); Page<InviteUserVO> getInviteUser(Long getDistributionUserId, Long shopUserId, Long distributionLevelId, Integer page, Integer size);
boolean updateInfo(ShopUser shopUser); boolean updateInfo(ShopUser shopUser);

View File

@@ -66,7 +66,7 @@ public interface MkDistributionUserService extends IService<MkDistributionUser>
/** /**
* 获取分销员邀请人分页列表 * 获取分销员邀请人分页列表
*/ */
Page<InviteUserVO> getInviteUser(Long id, Long shopUserId, Integer page, Integer size); Page<InviteUserVO> getInviteUser(Long id, Long shopUserId, Long distributionLevelId, Integer page, Integer size);
/** /**
* 分销员:按消费金额升级等级 * 分销员:按消费金额升级等级

View File

@@ -54,5 +54,5 @@ public class InviteUserVO implements Serializable {
/** /**
* 是否分销员 * 是否分销员
*/ */
private Integer isDistribution; private String distributionShops;
} }

View File

@@ -70,7 +70,7 @@ public interface ShopUserMapper extends BaseMapper<ShopUser> {
* @param distributionUserId 分销员ID * @param distributionUserId 分销员ID
* @return 分页结果 * @return 分页结果
*/ */
List<InviteUserVO> getInviteUser(Long distributionUserId, Long shopUserId); List<InviteUserVO> getInviteUser(Long distributionUserId, Long shopUserId, Long distributionLevelId);
void updateOneOrTwoAmount(Long userId, Long mainShopId, BigDecimal amount, Integer isOne); void updateOneOrTwoAmount(Long userId, Long mainShopId, BigDecimal amount, Integer isOne);

View File

@@ -99,9 +99,9 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
} }
@Override @Override
public Page<InviteUserVO> getInviteUser(Long distributionUserId, Long shopUserId, Integer page, Integer size) { public Page<InviteUserVO> getInviteUser(Long distributionUserId, Long shopUserId, Long distributionLevelId, Integer page, Integer size) {
PageHelper.startPage(page, size); PageHelper.startPage(page, size);
List<InviteUserVO> inviteUser = mapper.getInviteUser(distributionUserId, shopUserId); List<InviteUserVO> inviteUser = mapper.getInviteUser(distributionUserId, shopUserId, distributionLevelId);
return PageUtil.convert(new PageInfo<>(inviteUser)); return PageUtil.convert(new PageInfo<>(inviteUser));
} }

View File

@@ -32,7 +32,6 @@
</update> </update>
<select id="selectUserSummary" resultType="com.czg.account.dto.shopuser.ShopUserSummaryDTO"> <select id="selectUserSummary" resultType="com.czg.account.dto.shopuser.ShopUserSummaryDTO">
select count(a.id) userTotal, sum(IFNULL(a.amount, 0)) balanceTotal,sum(IFNULL(b.amount,0)) chargeTotal from select count(a.id) userTotal, sum(IFNULL(a.amount, 0)) balanceTotal,sum(IFNULL(b.amount,0)) chargeTotal from
tb_shop_user as a tb_shop_user as a
@@ -291,11 +290,12 @@
dist.status AS status, dist.status AS status,
dist.distribution_level_id AS levelId, dist.distribution_level_id AS levelId,
dist.distribution_level_name AS levelName, dist.distribution_level_name AS levelName,
CASE WHEN dist.id IS NOT NULL THEN 1 ELSE 0 END AS isDistribution dist.distribution_shops AS distributionShops
FROM `tb_shop_user` as u FROM `tb_shop_user` as u
left join mk_distribution_user dist on u.id = dist.id left join mk_distribution_user dist on u.id = dist.id
WHERE u.`distribution_user_id` = #{distributionUserId} WHERE u.`distribution_user_id` = #{distributionUserId}
<if test="distributionLevelId != null">and dist.distribution_level_id = #{distributionLevelId}</if>
<if test="shopUserId != null">and u.id = #{shopUserId}</if> <if test="shopUserId != null">and u.id = #{shopUserId}</if>
ORDER BY u.`id` DESC ORDER BY u.`invite_time` DESC
</select> </select>
</mapper> </mapper>

View File

@@ -282,7 +282,15 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
newDistributionUser.setInviteCount(parent.getInviteCount() + 1); newDistributionUser.setInviteCount(parent.getInviteCount() + 1);
MkDistributionConfig mkDistributionConfig = mkDistributionConfigService.getOne(QueryWrapper.create() MkDistributionConfig mkDistributionConfig = mkDistributionConfigService.getOne(QueryWrapper.create()
.eq(MkDistributionConfig::getShopId, parent.getShopId())); .eq(MkDistributionConfig::getShopId, parent.getShopId()));
if (mkDistributionConfig != null && parent.getIsAssignLevel() == 0) { if ("自主申请".equals(parent.getOpeningMethod()) && parent.getStatus() == 0 && mkDistributionConfig != null) {
if (newDistributionUser.getInviteCount() >= mkDistributionConfig.getInviteCount()) {
ShopUser parentShopUser1 = new ShopUser();
parentShopUser1.setId(shopUser.getId());
parentShopUser1.upDistributionShop(param.getShopId(), 1);
shopUserService.updateById(parentShopUser1);
}
}
if (mkDistributionConfig != null && !"not_upgrade".equals(mkDistributionConfig.getUpgradeType()) && parent.getIsAssignLevel() == 0) {
if ("invite".equals(mkDistributionConfig.getUpgradeType())) { if ("invite".equals(mkDistributionConfig.getUpgradeType())) {
if (mkDistributionConfig.getInviteConsume() == 1) { if (mkDistributionConfig.getInviteConsume() == 1) {
long count = orderInfoService.count(QueryWrapper.create() long count = orderInfoService.count(QueryWrapper.create()
@@ -296,8 +304,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
MkDistributionLevelConfig levelConfig = levelConfigService.getOne(QueryWrapper.create() MkDistributionLevelConfig levelConfig = levelConfigService.getOne(QueryWrapper.create()
.eq(MkDistributionLevelConfig::getShopId, parent.getShopId()) .eq(MkDistributionLevelConfig::getShopId, parent.getShopId())
.le(MkDistributionLevelConfig::getInviteCount, newDistributionUser.getInviteCount()) .le(MkDistributionLevelConfig::getInviteCount, newDistributionUser.getInviteCount())
.gt(MkDistributionLevelConfig::getId, parent.getDistributionLevelId()) .orderBy(MkDistributionLevelConfig::getId).desc().limit(1));
.orderBy(MkDistributionLevelConfig::getId).asc().limit(1));
if (levelConfig != null) { if (levelConfig != null) {
newDistributionUser.setDistributionLevelId(levelConfig.getId()); newDistributionUser.setDistributionLevelId(levelConfig.getId());
newDistributionUser.setDistributionLevelName(levelConfig.getName()); newDistributionUser.setDistributionLevelName(levelConfig.getName());
@@ -392,8 +399,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
} }
@Override @Override
public Page<InviteUserVO> getInviteUser(Long id, Long shopUserId, Integer page, Integer size) { public Page<InviteUserVO> getInviteUser(Long id, Long shopUserId, Long distributionLevelId, Integer page, Integer size) {
return shopUserService.getInviteUser(id, shopUserId, page, size); return shopUserService.getInviteUser(id, shopUserId, distributionLevelId, page, size);
} }
@Override @Override
@@ -403,25 +410,39 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
AssertUtil.isNull(param.getId(), "店铺用户ID不能为空"); AssertUtil.isNull(param.getId(), "店铺用户ID不能为空");
ShopUser shopUser = shopUserService.getById(param.getId()); ShopUser shopUser = shopUserService.getById(param.getId());
AssertUtil.isNull(shopUser, "店铺用户ID不能为空"); AssertUtil.isNull(shopUser, "店铺用户ID不能为空");
boolean isExits = shopUser.checkDistributionShops(param.getShopId().toString()); MkDistributionUser distributionUser = getOne(QueryWrapper.create()
if (isExits) { .eq(MkDistributionUser::getId, param.getId())
throw new CzgException("该用户已被添加为分销员,不可重复添加"); .eq(MkDistributionUser::getShopId, param.getShopId()));
if (distributionUser != null && distributionUser.getStatus() != 0) {
throw new CzgException("该用户已是分销员,不可重复添加");
} }
MkDistributionConfig config = mkDistributionConfigService.getOne( MkDistributionConfig config = mkDistributionConfigService.getOne(
QueryWrapper.create().eq(MkDistributionConfig::getShopId, param.getShopId()) QueryWrapper.create().eq(MkDistributionConfig::getShopId, param.getShopId())
.eq(MkDistributionConfig::getIsEnable, 1)); .eq(MkDistributionConfig::getIsEnable, 1));
AssertUtil.isNull(config, "店铺未配置分销"); AssertUtil.isNull(config, "店铺未配置分销");
if (!"自主申请".equals(param.getOpeningMethod()) || config.getInviteCount() == 0) {
initLevel(config, param);
}
if (distributionUser != null) {
distributionUser.setOpeningMethod("手动添加");
distributionUser.setDistributionLevelId(param.getDistributionLevelId());
distributionUser.setDistributionLevelName(param.getDistributionLevelName());
distributionUser.setStatus(1);
saveOrUpdate(distributionUser);
}else {
param.setStatus(0); param.setStatus(0);
param.setId(param.getId()); param.setId(param.getId());
param.setUserId(shopUser.getUserId()); param.setUserId(shopUser.getUserId());
param.setInviteCode(CzgRandomUtils.randomString(10)); param.setInviteCode(CzgRandomUtils.randomString(10));
if (!"自主申请".equals(param.getOpeningMethod()) || config.getInviteCount() == 0) { saveOrUpdate(param);
initLevel(config, param);
} }
save(param);
ShopUser shopUser2 = new ShopUser(); ShopUser shopUser2 = new ShopUser();
shopUser2.setId(shopUser.getId()); shopUser2.setId(shopUser.getId());
shopUser2.addDistributionShop(param.getShopId()); if (param.getStatus() == 0) {
shopUser2.upDistributionShop(param.getShopId(), 0);
} else {
shopUser2.upDistributionShop(param.getShopId(), 1);
}
shopUserService.updateById(shopUser2); shopUserService.updateById(shopUser2);
return param; return param;
} }
@@ -523,7 +544,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
addDistributionUser(new MkDistributionUser().setShopId(shopId) addDistributionUser(new MkDistributionUser().setShopId(shopId)
.setUserId(shopUserInfo.getUserId()) .setUserId(shopUserInfo.getUserId())
.setId(shopUserInfo.getId()).setOpeningMethod("付费开通")); .setId(shopUserInfo.getId()).setOpeningMethod("付费开通"));
}catch (Exception e) { } catch (Exception e) {
log.error("分销员开通失败", e); log.error("分销员开通失败", e);
} }
} }
@@ -616,7 +637,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2); updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
distributionFlowService.updateById(mkDistributionFlow); distributionFlowService.updateById(mkDistributionFlow);
} }
}else { } else {
mkDistributionFlow.setDeliverTime(delayTime); mkDistributionFlow.setDeliverTime(delayTime);
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.PENDING.getCode()); mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.PENDING.getCode());
distributionFlowService.save(mkDistributionFlow); distributionFlowService.save(mkDistributionFlow);
@@ -654,7 +675,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
item.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode()); item.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode());
updateIncome(item.getRewardAmount().negate(), BigDecimal.ZERO, BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopId(), item.getLevel()); updateIncome(item.getRewardAmount().negate(), BigDecimal.ZERO, BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopId(), item.getLevel());
distributionFlowService.updateById(item); distributionFlowService.updateById(item);
}else { } else {
// 执行扣款 // 执行扣款
updateIncome(BigDecimal.ZERO, item.getRewardAmount().negate(), BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopId(), item.getLevel()); updateIncome(BigDecimal.ZERO, item.getRewardAmount().negate(), BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopId(), item.getLevel());
updateShopInfoAmount(item.getShopId(), item.getRewardAmount(), orderId, TableValueConstant.DistributionAmountFlow.Type.REFUND, "分销回退"); updateShopInfoAmount(item.getShopId(), item.getRewardAmount(), orderId, TableValueConstant.DistributionAmountFlow.Type.REFUND, "分销回退");