Explorar o código

购物车下订单

lizhen_gitee hai 10 meses
pai
achega
6f16ffd1c1
Modificáronse 2 ficheiros con 37 adicións e 9 borrados
  1. 37 8
      addons/unishop/behavior/Order.php
  2. 0 1
      addons/unishop/controller/Order.php

+ 37 - 8
addons/unishop/behavior/Order.php

@@ -120,18 +120,47 @@ class Order
      */
     public function createOrderBefore(&$params, $extra)
     {
+        if(empty($extra['cart'])){
 
-        $specs = explode(',', $extra['spec']);
-        foreach ($specs as &$spec) {
-            $spec = str_replace('|', ',', $spec);
-        }
-        $numbers = explode(',', $extra['number']);
-        $productIds = explode(',', $extra['product_id']);
+            $specs = explode(',', $extra['spec']);
+            foreach ($specs as &$spec) {
+                $spec = str_replace('|', ',', $spec);
+            }
+            $numbers = explode(',', $extra['number']);
+            $productIds = explode(',', $extra['product_id']);
+
+            if (count($specs) !== count($numbers) || count($specs) !== count($productIds)) {
+                throw new Exception(__('Parameter error'));
+            }
+
+        }else{
+
+            $carts = Db::name('unishop_cart')->field('id,product_id,spec,number')
+                ->whereIn('id', $extra['cart'])
+                ->order(['id' => 'desc'])
+                ->select();
+
+//            dump($carts);
+
+            $numbers    = array_column($carts,'number');
+            $productIds = array_column($carts,'product_id');
+            $specs      = array_column($carts,'spec');
+
+            foreach ($productIds as $key => $productId) {
+                $productIds[$key] = Hashids::encodeHex($productId);
+            }
+
+            foreach ($specs as $key => $spec) {
+                $specs[$key] = is_null($spec) ? '' : $spec;
+            }
 
-        if (count($specs) !== count($numbers) || count($specs) !== count($productIds)) {
-            throw new Exception(__('Parameter error'));
         }
 
+        /*dump($numbers);
+        dump($productIds);
+        dump($specs);
+        exit;*/
+
         // 订单价格
         $orderPrice = 0;
 

+ 0 - 1
addons/unishop/controller/Order.php

@@ -211,7 +211,6 @@ class Order extends Base
     public function submit()
     {
         $data = input();
-        $data['city_id'] = 2;
 
         $pay_type = input('pay_type','alipay');
         if(!in_array($pay_type,['wechat','alipay','wallet'])){