[ 'title' => sysconfig('site', 'logo_title'), 'image' => sysconfig('site', 'logo_image'), 'href' => __url('index/index'), ], 'homeInfo' => $menuService->getHomeInfo(), 'menuInfo' => $menuService->getMenuTree(), ]; Cache::tag('initAdmin')->set('initAdmin_' . session('admin.id'), $data); return json($data); } /** * 清理缓存接口 */ public function clearCache() { Cache::clear(); $this->success('清理缓存成功'); } /** * 上传文件 */ public function upload() { $this->isDemo && $this->error('演示环境下不允许修改'); $this->checkPostRequest(); $type = $this->request->param('type', ''); $data = [ 'upload_type' => $this->request->post('upload_type'), 'file' => $this->request->file($type == 'editor' ? 'upload' : 'file'), ]; $uploadConfig = sysconfig('upload'); empty($data['upload_type']) && $data['upload_type'] = $uploadConfig['upload_type']; $rule = [ 'upload_type|指定上传类型有误' => "in:{$uploadConfig['upload_allow_type']}", 'file|文件' => "require|file|fileExt:{$uploadConfig['upload_allow_ext']}|fileSize:{$uploadConfig['upload_allow_size']}", ]; $this->validate($data, $rule); $upload_type = $uploadConfig['upload_type']; try { $upload = UploadService::instance()->setConfig($uploadConfig)->$upload_type($data['file'], $type); } catch (\Exception $e) { return $this->error($e->getMessage()); } $code = $upload['code'] ?? 0; if ($code == 0) { return $this->error($upload['data'] ?? ''); } else { return $type == 'editor' ? json( [ 'error' => ['message' => '上传成功', 'number' => 201,], 'fileName' => '', 'uploaded' => 1, 'url' => $upload['data']['url'] ?? '', ] ) : $this->success('上传成功', $upload['data'] ?? ''); } } /** * 获取上传文件列表 * @return Json * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function getUploadFiles(): Json { $get = $this->request->get(); $page = isset($get['page']) && !empty($get['page']) ? $get['page'] : 1; $limit = isset($get['limit']) && !empty($get['limit']) ? $get['limit'] : 10; $title = isset($get['title']) && !empty($get['title']) ? $get['title'] : null; $this->model = new SystemUploadfile(); $count = $this->model ->where(function (Query $query) use ($title) { !empty($title) && $query->where('original_name', 'like', "%{$title}%"); }) ->count(); $list = $this->model ->where(function (Query $query) use ($title) { !empty($title) && $query->where('original_name', 'like', "%{$title}%"); }) ->page($page, $limit) ->order($this->sort) ->select(); $data = [ 'code' => 0, 'msg' => '', 'count' => $count, 'data' => $list, ]; return json($data); } }