feat: 新增分销推荐人手动绑定功能,调整自动绑定规则

本次修改:
1. 新增分销绑定 API 接口与路由
2. 老用户不再自动绑定推荐人,需手动输入邀请码绑定
3. 新增绑定推荐人 UI 弹层与展示组件
4. 新增防环校验与关系补全逻辑
5. 调整邀请码存储逻辑,仅未登录用户自动存储
这个提交包含在:
2026-10-26 13:51:52 +08:00
父节点 7b58952cd4
当前提交 b9fdb7cd77
共有 11 个文件被更改,包括 273 次插入 和 29 次删除

查看文件

@@ -37,8 +37,8 @@ class DistributionService
}
$parent1Id = 0;
// 优先通过邀请码查询推荐人
$inviteCode = trim((string)$inviteCode);
// 优先通过邀请码查询推荐人(忽略大小写)
$inviteCode = strtoupper(trim((string)$inviteCode));
if ($inviteCode !== '') {
$parentExt = Db::name('fc_user_ext')->where('invite_code', $inviteCode)->find();
if ($parentExt && (int)$parentExt['user_id'] > 0) {
@@ -59,6 +59,15 @@ class DistributionService
return false;
}
// 防环校验:不能将自己的直接或间接下线绑定为自己的推荐人
$isDownline = Db::name('fc_dist_relation')
->where('user_id', $parent1Id)
->where('parent_id', $userId)
->count();
if ($isDownline > 0) {
return false;
}
$now = time();
// 更新用户扩展表的直接推荐人ID
@@ -94,6 +103,32 @@ class DistributionService
}
}
// 3. 若当前用户在补绑推荐人之前已经发展了 1 级下线,则为这些 1 级下线补齐以 $parent1Id 为 2 级推荐人的关系
$myL1Children = Db::name('fc_dist_relation')
->where('parent_id', $userId)
->where('level', 1)
->select();
if (!empty($myL1Children)) {
foreach ($myL1Children as $childRow) {
$childId = (int)$childRow['user_id'];
if ($childId <= 0 || $childId === $parent1Id) {
continue;
}
$hasL2 = Db::name('fc_dist_relation')
->where('user_id', $childId)
->where('level', 2)
->count();
if ($hasL2 <= 0) {
Db::name('fc_dist_relation')->insert([
'user_id' => $childId,
'parent_id' => $parent1Id,
'level' => 2,
'createtime' => $now,
]);
}
}
}
return true;
}