getList($this->postData()); return $this->renderSuccess('', compact('list')); } /** * 添加团购商品 */ public function add() { if ($this->request->isGet()) { // 获取店铺的商品列表用于选择 $commonProductModel = new CommonProductModel(); $postData = $this->postData(); $postData['shop_supplier_id'] = $this->getSupplierId(); $productList = $commonProductModel->getList($postData); return $this->renderSuccess('', compact('productList')); } $model = new ProductModel(); $data = $this->postData(); // 设置店铺ID为自营供应商ID $data['shop_supplier_id'] = $this->getSupplierId(); if ($model->add($data)) { return $this->renderSuccess('添加成功'); } return $this->renderError($model->getError() ?: '添加失败'); } /** * 编辑团购商品 */ public function edit() { $groupbuy_product_id = $this->request->param('groupbuy_product_id'); if (empty($groupbuy_product_id)) { return $this->renderError('缺少必要参数:groupbuy_product_id'); } $model = ProductModel::detail($groupbuy_product_id, [ 'product', 'groupbuySku' ]); if (!$model) { return $this->renderError('团购商品不存在'); } // 验证权限 - 商家端可以编辑所有商品,不需要权限验证 /* if ($model['shop_supplier_id'] != $this->getStoreId()) { return $this->renderError('没有权限操作此商品'); } */ if ($this->request->isGet()) { return $this->renderSuccess('', compact('model')); } $data = $this->postData(); if ($model->edit($data)) { return $this->renderSuccess('更新成功'); } return $this->renderError($model->getError() ?: '更新失败'); } /** * 删除团购商品 */ public function delete() { $groupbuy_product_id = $this->request->param('groupbuy_product_id'); if (empty($groupbuy_product_id)) { return $this->renderError('缺少必要参数:groupbuy_product_id'); } $model = ProductModel::detail($groupbuy_product_id); if (!$model) { return $this->renderError('团购商品不存在'); } // 验证权限 - 商家端可以删除所有商品,不需要权限验证 /* if ($model['shop_supplier_id'] != $this->getStoreId()) { return $this->renderError('没有权限操作此商品'); } */ if ($model->remove()) { return $this->renderSuccess('删除成功'); } return $this->renderError('删除失败'); } /** * 获取团购商品详情 */ public function detail() { $groupbuy_product_id = $this->request->param('groupbuy_product_id'); if (empty($groupbuy_product_id)) { return $this->renderError('缺少必要参数:groupbuy_product_id'); } $model = ProductModel::detail($groupbuy_product_id, [ 'product', 'groupbuySku' ]); if (!$model) { return $this->renderError('团购商品不存在'); } // 验证权限 - 商家端可以查看所有商品,不需要权限验证 /* if ($model['shop_supplier_id'] != $this->getStoreId()) { return $this->renderError('没有权限查看此商品'); } */ return $this->renderSuccess('', compact('model')); } }