123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\controller\store\file;
- use app\controller\store\AuthController;
- use app\services\system\attachment\SystemAttachmentCategoryServices;
- use think\facade\App;
- /**
- * 图片分类管理类
- * Class SystemAttachmentCategory
- * @package app\controller\store\file
- */
- class SystemAttachmentCategory extends AuthController
- {
- protected $service;
- public function __construct(App $app, SystemAttachmentCategoryServices $service)
- {
- parent::__construct($app);
- $this->service = $service;
- }
- /**
- * 显示资源列表
- *
- * @return \think\Response
- */
- public function index()
- {
- $where = $this->request->getMore([
- ['name', ''],
- ['pid', 0],
- ['file_type', 1]
- ]);
- $where['type'] = 2;
- $where['relation_id'] = $this->storeId;
- if ($where['name'] != '') $where['pid'] = '';
- return app('json')->success($this->service->getAll($where));
- }
- /**
- * 新增表单
- * @return mixed
- * @throws \FormBuilder\Exception\FormBuilderException
- */
- public function create($id)
- {
- [$file_type] = $this->request->postMore([
- ['file_type', 1]
- ], true);
- return app('json')->success($this->service->createForm($id, 2, $this->storeId, (int)$file_type));
- }
- /**
- * 保存新增
- * @return mixed
- */
- public function save()
- {
- $data = $this->request->postMore([
- ['pid', 0],
- ['name', ''],
- ['file_type', 1]
- ]);
- if (!$data['name']) {
- return app('json')->fail('请输入分类名称');
- }
- $data['type'] = 2;
- $data['relation_id'] = $this->storeId;
- $this->service->save($data);
- return app('json')->success('添加成功');
- }
- /**
- * 编辑表单
- * @param $id
- * @return mixed
- * @throws \FormBuilder\Exception\FormBuilderException
- */
- public function edit($id)
- {
- [$file_type] = $this->request->postMore([
- ['file_type', 1]
- ], true);
- return app('json')->success($this->service->editForm($id, 2, $this->storeId, (int)$file_type));
- }
- /**
- * 保存更新的资源
- *
- * @param \think\Request $request
- * @param int $id
- * @return \think\Response
- */
- public function update($id)
- {
- $data = $this->request->postMore([
- ['pid', 0],
- ['name', ''],
- ['file_type', 1]
- ]);
- if (!$data['name']) {
- return app('json')->fail('请输入分类名称');
- }
- $info = $this->service->get($id);
- $data['relation_id'] = $this->storeId;
- $count = $this->service->count(['pid' => $id]);
- if ($count && $info['pid'] != $data['pid']) return app('json')->fail('该分类有下级分类,无法修改上级');
- $this->service->update($id, $data);
- return app('json')->success('分类编辑成功!');
- }
- /**
- * 删除指定资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function delete($id)
- {
- $this->service->del($id);
- return app('json')->success('删除成功!');
- }
- }
|