getUser(true); if ($user) { $link = $this->request->post("link", []); if ($link) { $is = LinkModel::where("user_id", $user['user_id'])->find(); if ($is) { $is->link = $link; $is->save(); } else { LinkModel::create(["user_id" => $user['user_id'], "link" => $link]); } Cache::delete("Link.{$user['user_id']}"); HistoryModel::create(["user_id" => $user['user_id'], "link" => $link]); //历史记录备份,用于用户误操作恢复用途 return $this->success('ok'); } } return $this->error('保存失败'); } public function get(): \think\response\Json { $user = $this->getUser(); if ($user) { $c = Cache::get("Link.{$user['user_id']}"); if ($c) { return $this->success('ok', $c); } $data = LinkModel::where('user_id', $user['user_id'])->find(); if ($data) { $c = $data['link']; Cache::tag("linkCache")->set("Link.{$user['user_id']}", $c, 60 * 60); return $this->success('ok', $c); } } $config = $this->Setting("defaultTab", 'static/defaultTab.json', true); if ($config) { $fp = public_path() . $config; if (file_exists($fp)) { $file = file_get_contents($fp); $json = json_decode($file, true); return $this->success('ok', $json['link'] ?? []); } } return $this->success('ok', []); } function refreshWebAppCache(): \think\response\Json { $this->getAdmin(); Cache::tag('linkCache')->clear(); return $this->success('刷新完毕'); } public function reset(): \think\response\Json { $user = $this->getUser(); if ($user) { $data = LinkModel::find($user['user_id']); if ($data) { Cache::delete("Link.{$user['user_id']}"); $data->delete(); } $data = TabbarModel::find($user['user_id']); if ($data) { $data->delete(); } $data = ConfigModel::find($user['user_id']); if ($data) { $data->delete(); } $data = UserSearchEngineModel::find($user['user_id']); if ($data) { $data->delete(); } } return $this->success('ok'); } }