From 73b874c72ad55eb9eef21c36160ac0de58f0189e Mon Sep 17 00:00:00 2001
From: quanwei <419654421@qq.com>
Date: Thu, 05 Feb 2026 10:30:43 +0800
Subject: [PATCH] 优化名片

---
 admin/app/shop/controller/plus/groupbuy/Product.php |   40 ++++++++++++++++++++++++++++++++++------
 1 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/admin/app/shop/controller/plus/groupbuy/Product.php b/admin/app/shop/controller/plus/groupbuy/Product.php
index 4901e9f..584f1e3 100644
--- a/admin/app/shop/controller/plus/groupbuy/Product.php
+++ b/admin/app/shop/controller/plus/groupbuy/Product.php
@@ -37,12 +37,40 @@
         
         $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() ?: '添加失败');
     }
 
     /**
@@ -119,7 +147,7 @@
         }
         
         $model = ProductModel::detail($groupbuy_product_id, [
-            'product', 'groupbuySku'
+            'product', 'groupbuySku', 'active'
         ]);
         if (!$model) {
             return $this->renderError('团购商品不存在');

--
Gitblit v1.9.2