'=', 'is_recommend' => '=', 'category_id' => '=', ]; protected array $quickSearchField = ['name']; #[GetRoute(authorize: 'query')] public function query(Request $request): JsonResponse { $params = $request->all(); $pageSize = $params['pageSize'] ?? 10; $query = MerchantProductModel::where('merchant_id', $this->getMerchantId()); $data = $this->buildSearch($params, $query) ->paginate($pageSize) ->toArray(); return $this->success($data); } #[PostRoute(authorize: 'create')] public function create(ProductFormRequest $request): JsonResponse { $data = $request->validated(); $data['merchant_id'] = $this->getMerchantId(); MerchantProductModel::create($data); return $this->success(); } #[PutRoute( route: '/{id}', authorize: 'update', where: ['id' => '[0-9]+'] )] public function update(int $id, ProductFormRequest $request): JsonResponse { $model = MerchantProductModel::where('id', $id) ->where('merchant_id', $this->getMerchantId()) ->first(); if (empty($model)) { return $this->error('商品不存在'); } $model->update($request->validated()); return $this->success(); } #[DeleteRoute( route: '/{id}', authorize: 'delete', where: ['id' => '[0-9]+'] )] public function delete(int $id): JsonResponse { $model = MerchantProductModel::where('id', $id) ->where('merchant_id', $this->getMerchantId()) ->first(); if (empty($model)) { return $this->error('商品不存在'); } $model->delete(); return $this->success(); } }