where('is_delete',-1)->order('id', 'desc')->paginate($request->get('limit', 10)); return json(['code' => 200, 'msg' => '获取成功', 'count' => $select->total(), 'data' => $select->items()]); } /** * 更新图片 */ public function edit(Request $request) { Db::name('Projects')->where('id', $request->post('id'))->update(['indexImage' => $request->post('indexImage')]); return json(['code' => 200, 'msg' => '更新成功']); } /** * 创建项目 */ public function create(Request $request) { $data = $request->post(); $id = ProjectModel::insertGetId($data); $res = ProjectModel::where('id', $id)->first(); $res['CreateTime'] = $res['created_at']; $res['CreateUserId'] = 1; return $this->json(200, 'ok', $res->toArray()); } /** * 更新项目 */ public function publish(Request $request) { $data = $request->post(); $find = ProjectModel::find($data['id']); $find['state'] = $data['state']; $find->save(); if ($find) { return $this->json(200, '操作成功'); } else { return $this->json(500, '操作失败'); } } /** * 获取内容 */ public function getData(Request $request) { $data = $request->get(); $find = ProjectModel::find($data['projectId']); $ProjectdataModel = ProjectdataModel::where('project_id', $data['projectId'])->first(); if ($ProjectdataModel) { $find['content'] = $ProjectdataModel['content']; } else { $find['content'] = ''; } return $this->json(200, 'ok', $find->toArray()); } /** * 保存内容 */ public function data(Request $request) { $data = $request->post(); $find = Db::name('projectdatas')->where('project_id', $data['projectId'])->find(); if ($find) { Db::name('projectdatas')->where('project_id', $data['projectId'])->update(['content' => $data['content']]); } else { $id = Db::name('projectdatas')->insertGetId(['project_id' => $data['projectId'], 'content' => $data['content']]); $find = Db::name('projectdatas')->where('id', $id)->find(); } return $this->json(200, 'ok', $find); } public function delete(Request $request) { $ids = $request->get('ids'); $res = Db::name('projects')->where('id', $ids)->update(['is_delete' => 1]); if ($res) { return $this->json(200, '删除成功'); } else { return $this->json(500, '删除失败'); } } /** * 上传图片 */ public function upload(Request $request) { $file = current($request->file()); if (!$file || !$file->isValid()) { return $this->json(1, '未找到文件'); } $relative_dir = '/upload/img/' . date('Ymd'); $relative_dir = ltrim($relative_dir, '/'); $file = current($request->file()); if (!$file || !$file->isValid()) { throw new BusinessException('未找到上传文件', 400); } $base_dir = base_path() . '/plugin/admin/public/'; $full_dir = $base_dir . $relative_dir; if (!is_dir($full_dir)) { mkdir($full_dir, 0777, true); } $ext = strtolower($file->getUploadExtension()); $ext_forbidden_map = ['php', 'php3', 'php5', 'css', 'js', 'html', 'htm', 'asp', 'jsp']; if (in_array($ext, $ext_forbidden_map)) { throw new BusinessException('不支持该格式的文件上传', 400); } $relative_path = $relative_dir . '/' . bin2hex(pack('Nn', time(), random_int(1, 65535))) . ".$ext"; $full_path = $base_dir . $relative_path; var_dump($full_path); $file_size = $file->getSize(); $file_name = $file->getUploadName(); $file->move($full_path); return $this->json(200, '上传成功', [ 'fileName' => "/app/admin/$relative_path", 'name' => $file_name, 'size' => $file_size, ]); } }