| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\controller\adminapi\attachment;
- use app\extra\basic\Base;
- use app\extra\service\system\SystemAttachmentCategoryService;
- use app\extra\service\system\SystemAttachmentService;
- use app\middleware\AuthMiddleware;
- use DI\Attribute\Inject;
- use LinFly\Annotation\Route\Controller;
- use LinFly\Annotation\Route\Middleware;
- use LinFly\Annotation\Route\Route;
- use support\Request;
- use support\Response;
- /**
- * 图片管理类
- * Class SystemAttachment
- */
- #[Controller(prefix: "/adminapi/file/category/"),Middleware(AuthMiddleware::class)]
- class AttachmentCategory extends Base
- {
- /**
- * @var SystemAttachmentCategoryService
- */
- #[Inject]
- protected SystemAttachmentCategoryService $service;
- /**
- * 显示列表
- * @return mixed
- */
- #[Route(path: "",methods: "get")]
- public function index(Request $request)
- {
- $param = $request->get();
- return $this->success($this->service->getAll($param));
- }
- /**
- * 获取分类列表
- * @return mixed
- * @throws \FormBuilder\Exception\FormBuilderException
- */
- #[Route(path: "cate_list",methods: "get")]
- public function cate_list(Request $request)
- {
- $param = $request->get();
- return $this->success($this->service->getCateList($param));
- }
- #[Route(path: "save[/{id}]",methods: "post")]
- public function save(Request $request,$id): Response
- {
- try {
- $param = $this->_valid([
- "pid.number" => '上级分类错误',
- "name.require" => '请输入分类名称',
- "file_type.require" => '文件类型参数错误',
- ],"post");
- if (!is_array($param)) return error($param);
- if($id){
- $info = $this->service->getOne(['id'=>$id]);
- $count = $this->service->count(['pid' => $id]);
- if ($count && $info['pid'] != $param['pid']) return errorTrans('该分类有下级分类,无法修改上级');
- $state = $this->service->update($id, $param);
- }else{
- $state = $this->service->save($param);
- }
- if (!$state) return errorTrans("empty.error");
- return successTrans("success.data");
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- /**
- * 删除指定资源
- *
- * @param int $id
- * @return \think\Response
- */
- #[Route(path: "delete/{id}",methods: "delete")]
- public function delete($id)
- {
- $this->service->del($id);
- return $this->success('删除成功!');
- }
- }
|