Product.php 1.4 KB

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