From 01f75aa77efcbd156f9de091ede365080fcfb75c Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 10 Oct 2023 15:34:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=90=86=E8=A2=AB=E5=88=A0=E9=99=A4?= =?UTF-8?q?=EF=BC=8C=E6=97=97=E4=B8=8B=E7=94=A8=E6=88=B7=E5=BD=92=E5=B1=9E?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E7=9A=84=E4=BB=A3=E7=90=86=EF=BC=8C=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E4=BF=AE=E6=94=B9=E5=8D=A0=E6=AF=94=E6=97=97=E4=B8=8B?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E6=B8=85=E9=9B=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/AdminAgentTeam.php | 2 ++ app/model/AgentInfo.php | 37 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/app/controller/AdminAgentTeam.php b/app/controller/AdminAgentTeam.php index 839399b..911a7dc 100644 --- a/app/controller/AdminAgentTeam.php +++ b/app/controller/AdminAgentTeam.php @@ -240,6 +240,8 @@ class AdminAgentTeam extends BaseController $resInfo = AgentInfo::destroy($agent_info_id); if (!$resInfo) throw new ValidateException('删除失败'); + AgentInfo::syncUpdateAid($param['aid']); + $connection->commit(); return $this->renderSuccess('已删除'); } catch (ValidateException $validateException) { diff --git a/app/model/AgentInfo.php b/app/model/AgentInfo.php index 9797778..4913be8 100644 --- a/app/model/AgentInfo.php +++ b/app/model/AgentInfo.php @@ -71,5 +71,42 @@ class AgentInfo extends Model $AgentInfoRes->rebate_ratio = $rebate_ratio / 100; $AgentInfoRes->update_time = date("Y-m-d H:i:s",time()); $AgentInfoRes->save(); + self::syncUpdateRebateRatio($aid); + } + + /** + * 代理修改占比,旗下代理全部清零 + * @param $aid + * @return false|void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + protected static function syncUpdateRebateRatio($aid) + { + $UserRes = User::where(['aid' => $aid,'identity' => 2])->field('id')->select()->toArray(); + if (empty($UserRes)) return false; + foreach ($UserRes as $UserRow) { + # 修改为0 + self::updateRebateRatio($UserRow['id'],0); + } + } + + /** + * 代理被删除,旗下用户变为代理上级代理 + * @param $oldAid // 被删除的aid + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function syncUpdateAid($oldAid) + { + // 被删除aid的上级id + $newAid = User::withTrashed()->where('id',$oldAid)->value('aid'); + $newAid = $newAid ?: 0; + $UserRes = User::where(['aid' => $oldAid, 'identity' => 2])->field('id')->select()->toArray(); + $userIdArr = []; + foreach ($UserRes as $UserRow) $userIdArr[] = $UserRow['id']; + User::update(['aid' => $newAid],['id' => $userIdArr],['aid']); } }