CutterTask.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace app\controller\adminapi\cutter;
  3. use app\extra\basic\Base;
  4. use app\extra\service\cutter\CutterTaskService;
  5. use app\middleware\AuthMiddleware;
  6. use app\validate\adminapi\cutter\CutterTaskValidate;
  7. use DI\Attribute\Inject;
  8. use LinFly\Annotation\Route\Controller;
  9. use LinFly\Annotation\Route\Middleware;
  10. use LinFly\Annotation\Route\Route;
  11. use support\Request;
  12. use support\Response;
  13. #[Controller(prefix: "/adminapi/cutter/task"),Middleware(AuthMiddleware::class)]
  14. class CutterTask extends Base
  15. {
  16. #[Inject]
  17. protected CutterTaskService $service;
  18. #[Inject]
  19. protected CutterTaskValidate $validate;
  20. #[Route(path: "list",methods: "get")]
  21. public function getList(Request $request): Response
  22. {
  23. try {
  24. $param = $request->get();
  25. $param['is_del'] = 0;
  26. $list = $this->service->getList($param,'*',$param['page']??0,$param['limit']??0);
  27. return successTrans("success.data",$list);
  28. } catch (\Throwable $throwable) {
  29. return error($throwable->getMessage());
  30. }
  31. }
  32. #[Route(path: "info/{id}",methods: "get")]
  33. public function info($id): Response
  34. {
  35. try {
  36. $info = $this->service->getOne(['id'=>$id]);
  37. if ($info->isEmpty()) return errorTrans("empty.error");
  38. return successTrans("success.data",$info->toArray());
  39. } catch (\Throwable $throwable) {
  40. return error($throwable->getMessage());
  41. }
  42. }
  43. #[Route(path: "save",methods: "post")]
  44. public function save(Request $request): Response
  45. {
  46. try {
  47. $param = $request->post();
  48. if (!$this->validate->check($param)) return error($this->validate->getError());
  49. $param = $this->validate->checked($param);
  50. if(!empty($param['id'])){
  51. $id = $param['id'];
  52. unset($param['id']);
  53. $state = $this->service->update($id,$param);
  54. }else{
  55. $state = $this->service->save($param);
  56. }
  57. if (!$state) return errorTrans("empty.error");
  58. return successTrans("success.data");
  59. } catch (\Throwable $throwable) {
  60. return error($throwable->getMessage());
  61. }
  62. }
  63. #[Route(path: "set_status/{id}/{status}",methods: "get")]
  64. public function set_status($id,$status): Response
  65. {
  66. try {
  67. $state = $this->service->update($id,['status'=>$status]);
  68. if (!$state) return errorTrans("empty.error");
  69. return successTrans($status?'显示成功':'关闭成功');
  70. } catch (\Throwable $throwable) {
  71. return error($throwable->getMessage());
  72. }
  73. }
  74. #[Route(path: "del/{id}",methods: "delete")]
  75. public function delete($id): Response
  76. {
  77. try {
  78. $state = $this->service->update($id,['is_del'=>1]);
  79. if (!$state) return errorTrans("empty.error");
  80. return successTrans('删除成功');
  81. } catch (\Throwable $throwable) {
  82. return error($throwable->getMessage());
  83. }
  84. }
  85. }