GoodsController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace App\Modules\Admin\Controllers\Admin;
  3. use App\Base\BaseController;
  4. use App\Models\Goods\Goods;
  5. use App\Modules\Admin\Services\GoodsService;
  6. use App\Modules\Admin\Services\SpecService;
  7. class GoodsController extends BaseController
  8. {
  9. protected SpecService $specService;
  10. protected GoodsService $service;
  11. public function __construct(GoodsService $service, SpecService $authService)
  12. {
  13. $this->specService = $authService;
  14. $this->service = $service;
  15. }
  16. public function paginate()
  17. {
  18. $params = $this->valid([
  19. "page_size" => "",
  20. "name" => "",
  21. "status" => "",
  22. "category_id" => "",
  23. ]);
  24. return $this->ok($this->service->paginate($params));
  25. }
  26. public function changeStatus()
  27. {
  28. $id = request()->input("id", 0);
  29. $m = Goods::findOrFail($id);
  30. if ($m->status == Goods::STATUS_OK) {
  31. $m->status = Goods::STATUS_OFF;
  32. } else {
  33. $m->status = Goods::STATUS_OK;
  34. }
  35. $m->save();
  36. return $this->ok();
  37. }
  38. public function makeSkuTable()
  39. {
  40. $data = $this->valid([
  41. "spec_list" => "required|array",
  42. ]);
  43. return $this->ok([
  44. "sku_table" => $this->specService->cartesian($data['spec_list']),
  45. ]);
  46. }
  47. public function info()
  48. {
  49. $params = $this->valid([
  50. "id" => "required",
  51. ]);
  52. return $this->ok($this->service->info($params));
  53. }
  54. public function store()
  55. {
  56. $params = $this->valid([
  57. "id" => "",
  58. "name" => "required|max:50",
  59. "en_name" => "max:255",
  60. "image_list" => "required|array",
  61. "category" => "required|array",
  62. "spec" => 'array',
  63. "spec_map" => "array",
  64. 'weight' => "int",
  65. "desc_html" => "",
  66. "spec_attr_html" => "",
  67. "faq_html" => "",
  68. "url_3d" => "",
  69. "sn" => "",
  70. "custom" => "array",
  71. ]);
  72. return $this->ok($this->service->store($params));
  73. }
  74. public function specPaginate()
  75. {
  76. $data = $this->valid([
  77. "name" => "",
  78. "status" => "",
  79. "page_size" => "",
  80. ]);
  81. return $this->ok($this->specService->paginate($data));
  82. }
  83. public function specStore()
  84. {
  85. $params = $this->valid([
  86. "id" => "",
  87. "name" => "required",
  88. "en_name" => "",
  89. "attr" => "array",
  90. "index_weight" => "int",
  91. "category_weight" => "int",
  92. "search_weight" => "int",
  93. "is_custom" => "int",
  94. ]);
  95. return $this->ok($this->specService->specStore($params));
  96. }
  97. public function specInfo()
  98. {
  99. $params = $this->valid([
  100. "id" => "required",
  101. ]);
  102. return $this->ok($this->specService->specInfo($params));
  103. }
  104. public function specDelete()
  105. {
  106. $data = $this->valid([
  107. "id" => "required",
  108. ]);
  109. return $this->ok($this->specService->specDelete($data));
  110. }
  111. }