model = new \app\model\Files(); } /** * 查看 * @throws \think\db\exception\DbException */ public function index() { global $_W; $where = $this->buildSearchParams(); $where[] = ['uniacid','=',$_W['uniacid']]; $order = $this->buildOrder(); $data = $this->model->where($where)->order($order)->with(['category', 'createAdminUser', 'updateAdminUser']); $paging = $this->request->param('paging', false); if ($paging) { $limit = $this->request->param('limit', Config::get('paginate.limit')); $data = $data->paginate($limit)->toArray(); $data['data'] = $this->getSelectedData($data['data']); } else { $data = $data->select()->toArray(); } return $this->success('数据获取成功', $data); } //添加 public function add() { return $this->error('当前版本暂时不支持在附件管理中添加附件'); $post = CommonFun::filterPostData($this->request->post()); $post['create_admin_user_id'] = UserServiceFacade::getUser()->id; $post['update_admin_user_id'] = UserServiceFacade::getUser()->id; $post['path'] = UploadDomain::singleDelUploadDomain($post['path']); if ($this->model->create($post)) { return $this->success('添加成功', $post); } else { return $this->error('操作失败'); } } //不经过服务器方式上传成功后,回调的ajax请求地址,将上传成功的文件信息存入表中 public function unViaSave() { $post = $this->request->post(); $post['create_admin_user_id'] = UserServiceFacade::getUser()->id; $post['update_admin_user_id'] = UserServiceFacade::getUser()->id; $post['create_time'] = date('Y-m-d H:i:s'); $post['update_time'] = date('Y-m-d H:i:s'); $post['id'] = $this->model->insertGetId($post); if ($post['id']) { return $this->success('添加成功', $post); } else { return $this->error('操作失败'); } } //编辑 public function edit() { return $this->error('当前版本暂时不支持在附件管理中编辑附件'); $id = $this->request->param('id'); $info = $this->model->find($id); $post = CommonFun::filterPostData($this->request->post()); $post['update_admin_user_id'] = UserServiceFacade::getUser()->id; $post['path'] = UploadDomain::singleDelUploadDomain($post['path']); foreach ($post as $k => $v) { $info->$k = $v; } try { $updateRes = $info->save(); if ($updateRes) { return $this->success('编辑成功'); } else if ($updateRes === 0) { return $this->success('未做修改'); } else if ($updateRes === null) { return $this->error('操作失败'); } } catch (\Exception $e) { return $this->exceptionError($e); } } //删除 public function del() { $id = $this->request->param('id'); $info = $this->model->find($id); $post = CommonFun::filterPostData($this->request->post()); $post['update_admin_user_id'] = UserServiceFacade::getUser()->id; $post['path'] = UploadDomain::singleDelUploadDomain($post['path']); foreach ($post as $k => $v) { $info->$k = $v; } try { $updateRes = $info->save(); if (!$updateRes) { return $this->error('操作失败'); } else { return $this->success('编辑成功'); } } catch (\Exception $e) { return $this->exceptionError($e); } } //回收站 public function recycle() { global $_W; $where = $this->buildSearchParams(); $where[] = ['uniacid','=',$_W['uniacid']]; $order = $this->buildOrder(); $limit = $this->request->param('limit', Config::get('paginate.limit')); $data = $this->model->onlyTrashed() ->with(['category', 'createAdminUser', 'updateAdminUser']) ->order($order)->where($where)->paginate($limit)->toArray(); return $this->success('回收站数据获取成功', $data); } }