PageController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace App\Modules\Mini\Controllers;
  3. use App\Base\BaseController;
  4. use App\Modules\Mini\Services\PageService;
  5. use Faker\Provider\Image;
  6. class PageController extends BaseController
  7. {
  8. protected PageService $service;
  9. /**
  10. * @param PageService $service
  11. */
  12. public function __construct(PageService $service)
  13. {
  14. $this->service = $service;
  15. }
  16. public function filterConfig()
  17. {
  18. return $this->ok([
  19. [
  20. "id" => 1,
  21. "name" => "类目示例",
  22. "type" => "category",
  23. "child" => [
  24. [
  25. "id" => 1,
  26. "name" => "名称",
  27. ],
  28. ],
  29. ],
  30. [
  31. "id" => 1,
  32. "name" => "属性示例",
  33. "type" => "attr",
  34. "child" => [
  35. [
  36. "id" => 1,
  37. "name" => "名称",
  38. ],
  39. ],
  40. ],
  41. ]);
  42. }
  43. public function home()
  44. {
  45. return $this->ok([
  46. "banner" => $this->service->banner(),
  47. "categoryTree" => $this->service->categoryTree(),
  48. "hot_goods" => $this->service->hotGoods(10),
  49. "recommend_goods" => $this->service->recommendedGoods(10),
  50. ]);
  51. }
  52. public function categoryGoods()
  53. {
  54. $params = $this->valid([
  55. "id" => "required",
  56. "page_size" => "int",
  57. "keyword" => "",
  58. "attrs" => "",
  59. ]);
  60. return $this->ok($this->service->categoryGoods($params));
  61. }
  62. public function categoryTree()
  63. {
  64. return $this->ok([
  65. "categoryTree" => $this->service->categoryTree(),
  66. ]);
  67. }
  68. public function search()
  69. {
  70. $params = $this->valid([
  71. "keyword" => "",
  72. "attrs" => "",
  73. ]);
  74. return $this->ok($this->service->search($params));
  75. return $this->ok([
  76. "total" => 1,
  77. "page_total" => 1,
  78. "list" => [
  79. [
  80. "id" => 1,
  81. "name" => "商品名称",
  82. "thumb" => Image::imageUrl(),
  83. ],
  84. ],
  85. "category" => [
  86. [
  87. "id" => 1,
  88. "thumb" => Image::imageUrl(),
  89. "name" => "分类名称",
  90. ],
  91. ],
  92. ]);
  93. }
  94. }