| | |
| | | |
| | | $model = new ProductModel(); |
| | | $data = $this->postData(); |
| | | // 设置店铺ID为自营供应商ID |
| | | $data['shop_supplier_id'] = $this->getSupplierId(); |
| | | if ($model->add($data)) { |
| | | return $this->renderSuccess('添加成功'); |
| | | |
| | | // 如果传递的是批量数据,则处理多个商品 |
| | | if (isset($data['product_list']) && is_array($data['product_list']) && count($data['product_list']) > 0) { |
| | | // 处理批量添加 |
| | | $successCount = 0; |
| | | $errors = []; |
| | | |
| | | foreach ($data['product_list'] as $productData) { |
| | | $productData['shop_supplier_id'] = $this->getSupplierId(); |
| | | if ($model->add($productData)) { |
| | | $successCount++; |
| | | } else { |
| | | $errors[] = "商品ID {$productData['product_id']} 添加失败: " . $model->getError(); |
| | | } |
| | | } |
| | | |
| | | if ($successCount > 0) { |
| | | $message = "成功添加 {$successCount} 个商品"; |
| | | if (!empty($errors)) { |
| | | $message .= ", 部分商品添加失败: " . implode(', ', $errors); |
| | | return $this->renderSuccess($message); |
| | | } |
| | | return $this->renderSuccess($message); |
| | | } else { |
| | | return $this->renderError('所有商品添加失败: ' . implode(', ', $errors)); |
| | | } |
| | | } else { |
| | | // 单个商品添加 |
| | | $data['shop_supplier_id'] = $this->getSupplierId(); |
| | | if ($model->add($data)) { |
| | | return $this->renderSuccess('添加成功'); |
| | | } |
| | | return $this->renderError($model->getError() ?: '添加失败'); |
| | | } |
| | | return $this->renderError($model->getError() ?: '添加失败'); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | $model = ProductModel::detail($groupbuy_product_id, [ |
| | | 'product', 'groupbuySku' |
| | | 'product', 'groupbuySku', 'active' |
| | | ]); |
| | | if (!$model) { |
| | | return $this->renderError('团购商品不存在'); |