field(['chain', 'id', 'level', 'admin_id'])->where(['id' => $promoteId, 'admin_id' => $fromId])->find(); if (!$promote) { throw new \Exception('会长不存在'); } if ($promote['level'] != 1) { throw new \Exception('该账号非会长'); } if ($fromId == $toId) { throw new \Exception('原市场专员与新市场专员相同,不可转换。'); } if ($promote['admin_id'] == $toId) { throw new \Exception('新市场专员与现市场专员相同,不可转换。'); } $promotes = (new PromoteService)->getAllChildren($promote, 0, ['id']); $promoteIds = [$promote['id']]; $promoteIds = array_merge(array_column($promotes, 'id'), $promoteIds); $this->shiftPromote($promoteId, $fromId, $toId); $this->shiftSpend($promoteIds, $fromId, $toId, $time); $this->shiftDeposit($promoteIds, $fromId, $toId, $time); } public function shiftPromote($promoteId, $fromId, $toId, $time = null) { $map = []; $map['id'] = $promoteId; $map['admin_id'] = $fromId; M('promote', 'tab_')->where($map)->save(['admin_id' => $toId]); } public function shiftSpend($promoteIds, $fromId, $toId, $time = null) { $map = []; $map['promote_id'] = ['in', $promoteIds]; $map['market_admin_id'] = $fromId; if ($time) { $map['pay_time'] = ['egt', $time]; } $count = M('spend', 'tab_')->where($map)->count(); $limit = 50; $pageCount = ceil($count/$limit); for ($page = 0; $page <= $pageCount; $page ++) { M('spend', 'tab_')->where($map)->limit($limit)->save(['market_admin_id' => $toId]); } M('spend', 'tab_')->where($map)->save(['market_admin_id' => $toId]); } public function shiftDeposit($promoteIds, $fromId, $toId, $time = null) { $map = []; $map['promote_id'] = ['in', $promoteIds]; $map['market_admin_id'] = $fromId; if ($time) { $map['create_time'] = ['egt', $time]; } $count = M('deposit', 'tab_')->where($map)->count(); $limit = 50; $pageCount = ceil($count/$limit); for ($page = 0; $page <= $pageCount; $page ++) { M('deposit', 'tab_')->where($map)->limit($limit)->save(['market_admin_id' => $toId]); } M('deposit', 'tab_')->where($map)->save(['market_admin_id' => $toId]); } }