CutterApply.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\controller\adminapi\cutter;
  3. use app\extra\basic\Base;
  4. use app\extra\service\cutter\CutterApplyService;
  5. use app\extra\service\user\UserService;
  6. use app\middleware\AuthMiddleware;
  7. use app\validate\system\UserValidate;
  8. use DI\Attribute\Inject;
  9. use LinFly\Annotation\Route\Controller;
  10. use LinFly\Annotation\Route\Middleware;
  11. use LinFly\Annotation\Route\Route;
  12. use support\Request;
  13. use support\Response;
  14. #[Controller(prefix: "/adminapi/cutter/apply"),Middleware(AuthMiddleware::class)]
  15. class CutterApply extends Base
  16. {
  17. #[Inject]
  18. protected CutterApplyService $service;
  19. #[Inject]
  20. protected UserService $userService;
  21. #[Route(path: "list",methods: "get")]
  22. public function getList(Request $request): Response
  23. {
  24. try {
  25. $param = $request->get();
  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. $take = $this->service->getOne(["id"=>$id,'status'=>1,'is_del'=>0]);
  37. if ($take->isEmpty()) return errorTrans("empty.error");
  38. return successTrans("success.data",$take->toArray());
  39. } catch (\Throwable $throwable) {
  40. return error($throwable->getMessage());
  41. }
  42. }
  43. #[Route(path: "agreed/{id}",methods: "post")]
  44. public function agreed($id): Response
  45. {
  46. try {
  47. $apply = $this->service->getOne(["id"=>$id]);
  48. if ($apply->isEmpty()) return errorTrans("empty.error");
  49. $state = $this->service->update($id,['status'=>1]) && $this->userService->update($apply['uid'],['is_cutter'=>1]);
  50. if (!$state) return errorTrans("error.data");
  51. return successTrans("success.data");
  52. } catch (\Throwable $throwable) {
  53. return error($throwable->getMessage());
  54. }
  55. }
  56. #[Route(path: "refuse/{id}",methods: "post")]
  57. public function refuse (Request $request,$id): Response
  58. {
  59. try {
  60. $remark = $request->post('remark','');
  61. $apply = $this->service->getOne(["id"=>$id]);
  62. if ($apply->isEmpty()) return errorTrans("empty.error");
  63. $state = $this->service->update($id,['status'=>2,'remark'=>$remark]);
  64. if (!$state) return errorTrans("error.data");
  65. return successTrans("success.data");
  66. } catch (\Throwable $throwable) {
  67. return error($throwable->getMessage());
  68. }
  69. }
  70. }