Browse Source

购物车,下单

lizhen_gitee 10 months ago
parent
commit
a7eacbeac3
2 changed files with 15 additions and 3 deletions
  1. 2 1
      addons/unishop/controller/Cart.php
  2. 13 2
      addons/unishop/controller/Order.php

+ 2 - 1
addons/unishop/controller/Cart.php

@@ -131,6 +131,7 @@ class Cart extends Base
     public function add()
     {
         $id = input('id', 0);
+        $number = input('number',1);
 
         $id = \addons\unishop\extend\Hashids::decodeHex($id);
 
@@ -159,7 +160,7 @@ class Cart extends Base
             $cartModel->user_id = $user_id;
             $cartModel->product_id = $id;
             $spec && $cartModel->spec = $spec;
-            $cartModel->number = 1;
+            $cartModel->number = $number;
             $cartModel->snapshot = json_encode($product->getData(), true);
             $result = $cartModel->save();
         }

+ 13 - 2
addons/unishop/controller/Order.php

@@ -98,11 +98,16 @@ class Order extends Base
 
             // 单个商品
             if ($productId) {
+                $number = input('number',1,'intval');
                 $productId = \addons\unishop\extend\Hashids::decodeHex($productId);
                 $product = (new Product)->where(['id' => $productId, 'switch' => Product::SWITCH_ON, 'deletetime' => null])->find();
                 /** 产品基础数据 **/
                 $spec = input('spec', '');
-                $productData[0] = $product->getDataOnCreateOrder($spec);
+
+                $productData = [];
+                for($i=1;$i<=$number;$i++){
+                    $productData[] = $product->getDataOnCreateOrder($spec);
+                }
             } else {
                 // 多个商品
                 $cart = input('cart');
@@ -123,7 +128,13 @@ class Order extends Base
             }
 
             /** 默认地址 **/
-            $address = (new AddressModel)->where(['user_id' => $user_id, 'is_default' => AddressModel::IS_DEFAULT_YES])->find();
+            $address_map = ['user_id' => $user_id, 'is_default' => AddressModel::IS_DEFAULT_YES];
+
+            $delivery_id = input('delivery_id',0);
+            if($delivery_id){
+                $address_map = ['user_id' => $user_id, 'id' => $delivery_id];
+            }
+            $address = (new AddressModel)->where($address_map)->find();
             if ($address) {
                 /*$area = (new Area)->whereIn('id', [$address->province_id, $address->city_id, $address->area_id])->column('name', 'id');
                 $address = $address->toArray();