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']); } }