Pages.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\controller\admin;
  3. use app\extra\basic\Base;
  4. use app\middleware\AuthMiddleware;
  5. use app\model\cpa\CpaPage;
  6. use app\service\cpa\PageService;
  7. use DI\Attribute\Inject;
  8. use LinFly\Annotation\Attributes\Route\Controller;
  9. use LinFly\Annotation\Attributes\Route\GetMapping;
  10. use LinFly\Annotation\Attributes\Route\Middleware;
  11. use LinFly\Annotation\Attributes\Route\PostMapping;
  12. use support\Request;
  13. use support\Response;
  14. #[Controller("/api/pages"),Middleware(AuthMiddleware::class)]
  15. class Pages extends Base
  16. {
  17. #[Inject]
  18. protected PageService $service;
  19. #[Inject]
  20. protected CpaPage $model;
  21. #[GetMapping('list')]
  22. public function getDataList(Request $request): Response
  23. {
  24. try {
  25. $param = $request->all();
  26. $data = $this->service->setModel()->getList($param);
  27. return successTrans("success.data",pageFormat($data),200);
  28. } catch (\Throwable $th) {
  29. return error($th->getMessage());
  30. }
  31. }
  32. #[PostMapping("save")]
  33. public function setDepositData(Request $request): Response
  34. {
  35. try {
  36. $param = $request->post();
  37. $state = $this->model->setAutoData($param);
  38. if (!$state) return errorTrans("error.data");
  39. return successTrans("success.data");
  40. } catch (\Throwable $throwable) {
  41. return error($throwable->getMessage());
  42. }
  43. }
  44. }