AttachmentCategory.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\adminapi\attachment;
  12. use app\extra\basic\Base;
  13. use app\extra\service\system\SystemAttachmentCategoryService;
  14. use app\extra\service\system\SystemAttachmentService;
  15. use app\middleware\AuthMiddleware;
  16. use DI\Attribute\Inject;
  17. use LinFly\Annotation\Route\Controller;
  18. use LinFly\Annotation\Route\Middleware;
  19. use LinFly\Annotation\Route\Route;
  20. use support\Request;
  21. use support\Response;
  22. /**
  23. * 图片管理类
  24. * Class SystemAttachment
  25. */
  26. #[Controller(prefix: "/adminapi/file/category/"),Middleware(AuthMiddleware::class)]
  27. class AttachmentCategory extends Base
  28. {
  29. /**
  30. * @var SystemAttachmentCategoryService
  31. */
  32. #[Inject]
  33. protected SystemAttachmentCategoryService $service;
  34. /**
  35. * 显示列表
  36. * @return mixed
  37. */
  38. #[Route(path: "",methods: "get")]
  39. public function index(Request $request)
  40. {
  41. $param = $request->get();
  42. return $this->success($this->service->getAll($param));
  43. }
  44. /**
  45. * 获取分类列表
  46. * @return mixed
  47. * @throws \FormBuilder\Exception\FormBuilderException
  48. */
  49. #[Route(path: "cate_list",methods: "get")]
  50. public function cate_list(Request $request)
  51. {
  52. $param = $request->get();
  53. return $this->success($this->service->getCateList($param));
  54. }
  55. #[Route(path: "save[/{id}]",methods: "post")]
  56. public function save(Request $request,$id): Response
  57. {
  58. try {
  59. $param = $this->_valid([
  60. "pid.number" => '上级分类错误',
  61. "name.require" => '请输入分类名称',
  62. "file_type.require" => '文件类型参数错误',
  63. ],"post");
  64. if (!is_array($param)) return error($param);
  65. if($id){
  66. $info = $this->service->getOne(['id'=>$id]);
  67. $count = $this->service->count(['pid' => $id]);
  68. if ($count && $info['pid'] != $param['pid']) return errorTrans('该分类有下级分类,无法修改上级');
  69. $state = $this->service->update($id, $param);
  70. }else{
  71. $state = $this->service->save($param);
  72. }
  73. if (!$state) return errorTrans("empty.error");
  74. return successTrans("success.data");
  75. } catch (\Throwable $throwable) {
  76. return error($throwable->getMessage());
  77. }
  78. }
  79. /**
  80. * 删除指定资源
  81. *
  82. * @param int $id
  83. * @return \think\Response
  84. */
  85. #[Route(path: "delete/{id}",methods: "delete")]
  86. public function delete($id)
  87. {
  88. $this->service->del($id);
  89. return $this->success('删除成功!');
  90. }
  91. }