123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace App\Modules\Admin\Controllers\Admin;
- use App\Base\BaseController;
- use App\Models\Goods\Goods;
- use App\Modules\Admin\Services\GoodsService;
- use App\Modules\Admin\Services\SpecService;
- class GoodsController extends BaseController
- {
- protected SpecService $specService;
- protected GoodsService $service;
- public function __construct(GoodsService $service, SpecService $authService)
- {
- $this->specService = $authService;
- $this->service = $service;
- }
- public function paginate()
- {
- $params = $this->valid([
- "page_size" => "",
- "name" => "",
- "status" => "",
- "category_id" => "",
- ]);
- return $this->ok($this->service->paginate($params));
- }
- public function changeStatus()
- {
- $id = request()->input("id", 0);
- $m = Goods::findOrFail($id);
- if ($m->status == Goods::STATUS_OK) {
- $m->status = Goods::STATUS_OFF;
- } else {
- $m->status = Goods::STATUS_OK;
- }
- $m->save();
- return $this->ok();
- }
- public function makeSkuTable()
- {
- $data = $this->valid([
- "spec_list" => "required|array",
- ]);
- return $this->ok([
- "sku_table" => $this->specService->cartesian($data['spec_list']),
- ]);
- }
- public function info()
- {
- $params = $this->valid([
- "id" => "required",
- ]);
- return $this->ok($this->service->info($params));
- }
- public function store()
- {
- $params = $this->valid([
- "id" => "",
- "name" => "required|max:50",
- "en_name" => "max:255",
- "image_list" => "required|array",
- "category" => "required|array",
- "spec" => 'array',
- "spec_map" => "array",
- 'weight' => "int",
- "desc_html" => "",
- "spec_attr_html" => "",
- "faq_html" => "",
- "url_3d" => "",
- "sn" => "",
- "custom" => "array",
- ]);
- return $this->ok($this->service->store($params));
- }
- public function specPaginate()
- {
- $data = $this->valid([
- "name" => "",
- "status" => "",
- "page_size" => "",
- ]);
- return $this->ok($this->specService->paginate($data));
- }
- public function specStore()
- {
- $params = $this->valid([
- "id" => "",
- "name" => "required",
- "en_name" => "",
- "attr" => "array",
- "index_weight" => "int",
- "category_weight" => "int",
- "search_weight" => "int",
- "is_custom" => "int",
- ]);
- return $this->ok($this->specService->specStore($params));
- }
- public function specInfo()
- {
- $params = $this->valid([
- "id" => "required",
- ]);
- return $this->ok($this->specService->specInfo($params));
- }
- public function specDelete()
- {
- $data = $this->valid([
- "id" => "required",
- ]);
- return $this->ok($this->specService->specDelete($data));
- }
- }
|