123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- namespace app\controller\admin;
- use laytp\controller\Backend;
- use app\service\admin\UserServiceFacade;
- use laytp\library\CommonFun;
- use laytp\library\UploadDomain;
- use think\facade\Config;
- /**
- * 附件管理
- */
- class Files extends Backend
- {
- /**
- * files模型对象
- * @var \app\model\Files
- */
- protected $model;
- public $hasSoftDel = 1;//是否拥有软删除功能
- public function initialize()
- {
- parent::initialize();
- $this->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);
- }
- }
|