WIN-2308041133\Administrator 10 saat önce
ebeveyn
işleme
bf7c3d4c48
1 değiştirilmiş dosya ile 9 ekleme ve 2 silme
  1. 9 2
      app/model/api/StoreCart.php

+ 9 - 2
app/model/api/StoreCart.php

@@ -35,17 +35,24 @@ class StoreCart extends Model
      */
     public function addToCart($data)
     {
+        // 确保cart_num为整数
+        $cartNum = (int)($data['cart_num'] ?? 1);
+        if ($cartNum <= 0) {
+            $cartNum = 1;
+        }
+        
         // 检查是否已存在
         $exist = $this->where('uid', $data['uid'])
             ->where('product_id', $data['product_id'])
             ->where('product_attr_unique', $data['product_attr_unique'] ?? '')
             ->find();
         if ($exist) {
-            // 更新数量
-            $result = $this->where('id', $exist['id'])->inc('cart_num', $data['cart_num'])->update();
+            // 更新数量,使用整数类型
+            $result = $this->where('id', $exist['id'])->inc('cart_num', $cartNum)->update();
             return $result ? $exist['id'] : false;
         } else {
             // 新增
+            $data['cart_num'] = $cartNum;
             $result = $this->insert($data);
             return $result ? $this->getLastInsID() : false;
         }