error = '参数错误'; return false; } $this->startTrans(); try { if ($action == 'update') { $this->where('user_id', $user_id)->delete(); } foreach ($groups as $k => $v) { if (!db('admin_access')->where(['user_id' => $user_id,'group_id' => $v])->find()) { $userGroup['user_id'] = $user_id; $userGroup['group_id'] = $v; $userGroups[] = $userGroup; } } $this->saveAll($userGroups); $this->commit(); return true; } catch(\Exception $e) { $this->rollback(); $this->error = '编辑失败'; return false; } } }