CutterController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace app\controller\api\cutter;
  3. use app\extra\basic\Base;
  4. use app\extra\service\cutter\CutterApplyService;
  5. use app\middleware\AuthMiddleware;
  6. use app\validate\api\user\CutterApplyValidate;
  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 Shopwwi\WebmanAuth\Auth;
  12. use support\Request;
  13. use support\Response;
  14. #[Controller(prefix: "/api/user/"),Middleware(AuthMiddleware::class)]
  15. class CutterController extends Base
  16. {
  17. #[Inject]
  18. protected CutterApplyService $cutterApplyService;
  19. #[Inject]
  20. protected CutterApplyValidate $validate;
  21. /**
  22. * 申请剪辑师
  23. * @param Request $request
  24. * @return Response
  25. */
  26. #[Route(path: "cutter/apply",methods: "post")]
  27. public function cutter_apply(Request $request): Response
  28. {
  29. try {
  30. $user = (new Auth)->guard("user")->user()->toArray();
  31. $param = $request->post();
  32. if (!$this->validate->check($param)) return error($this->validate->getError());
  33. $param['uid'] = $user['uid'];
  34. if($user['is_cutter'])
  35. return errorTrans("您已成为剪辑师,请勿重复操作");
  36. $apply = $this->cutterApplyService->getOne(['uid'=>$param['uid']]);
  37. if(!$apply->isEmpty()){
  38. $param['status'] = 0;
  39. $state = $this->cutterApplyService->update($apply['id'],$param);
  40. }else{
  41. $state = $this->cutterApplyService->save($param);
  42. }
  43. if (!$state) return errorTrans("error.data");
  44. return successTrans("success.data");
  45. } catch (\Throwable $throwable) {
  46. return error($throwable->getMessage());
  47. }
  48. }
  49. /**
  50. * 申请剪辑师详情
  51. * @param Request $request
  52. * @return Response
  53. */
  54. #[Route(path: "cutter/apply/info",methods: "get")]
  55. public function cutter_apply_info(Request $request): Response
  56. {
  57. try {
  58. $user = (new Auth)->guard("user")->user()->toArray();
  59. $apply = $this->cutterApplyService->getOne(['uid'=>$user['uid']]);
  60. return successTrans("success.data",$apply?$apply->toArray():[]);
  61. } catch (\Throwable $throwable) {
  62. return error($throwable->getMessage());
  63. }
  64. }
  65. }