SystemAttachmentController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | saiadmin [ saiadmin快速开发框架 ]
  4. // +----------------------------------------------------------------------
  5. // | Author: sai <1430792918@qq.com>
  6. // +----------------------------------------------------------------------
  7. namespace plugin\saiadmin\app\controller\system;
  8. use plugin\saiadmin\basic\BaseController;
  9. use plugin\saiadmin\app\logic\system\SystemAttachmentLogic;
  10. use plugin\saiadmin\service\Permission;
  11. use support\Request;
  12. use support\Response;
  13. /**
  14. * 附件管理控制器
  15. */
  16. class SystemAttachmentController extends BaseController
  17. {
  18. /**
  19. * 构造
  20. */
  21. public function __construct()
  22. {
  23. $this->logic = new SystemAttachmentLogic();
  24. parent::__construct();
  25. }
  26. /**
  27. * 数据列表
  28. * @param Request $request
  29. * @return Response
  30. */
  31. #[Permission('附件数据列表', 'core:attachment:index')]
  32. public function index(Request $request) : Response
  33. {
  34. $where = $request->more([
  35. ['origin_name', ''],
  36. ['category_id', ''],
  37. ['storage_mode', ''],
  38. ['mime_type', ''],
  39. ['create_time', ''],
  40. ]);
  41. $query = $this->logic->search($where);
  42. $data = $this->logic->getList($query);
  43. return $this->success($data);
  44. }
  45. /**
  46. * 更新数据
  47. * @param Request $request
  48. * @return Response
  49. */
  50. #[Permission('附件数据修改', 'core:attachment:edit')]
  51. public function update(Request $request): Response
  52. {
  53. $data = $request->post();
  54. $result = $this->logic->edit($data['id'], ['origin_name' => $data['origin_name']]);
  55. if ($result) {
  56. return $this->success('修改成功');
  57. } else {
  58. return $this->fail('修改失败');
  59. }
  60. }
  61. /**
  62. * 删除数据
  63. * @param Request $request
  64. * @return Response
  65. */
  66. #[Permission('附件数据删除', 'core:attachment:edit')]
  67. public function destroy(Request $request) : Response
  68. {
  69. $ids = $request->post('ids', '');
  70. if (empty($ids)) {
  71. return $this->fail('请选择要删除的数据');
  72. }
  73. $result = $this->logic->destroy($ids);
  74. if ($result) {
  75. return $this->success('删除成功');
  76. } else {
  77. return $this->fail('删除失败');
  78. }
  79. }
  80. /**
  81. * 移动分类
  82. * @param Request $request
  83. * @return Response
  84. */
  85. #[Permission('附件移动分类', 'core:attachment:edit')]
  86. public function move(Request $request) : Response
  87. {
  88. $category_id = $request->post('category_id', '');
  89. $ids = $request->post('ids', '');
  90. if (empty($ids) || empty($category_id)) {
  91. return $this->fail('参数错误,请检查参数');
  92. }
  93. $result = $this->logic->move($category_id, $ids);
  94. if ($result) {
  95. return $this->success('删除成功');
  96. } else {
  97. return $this->fail('删除失败');
  98. }
  99. }
  100. }