dever há 7 anos atrás
pai
commit
36028f4eb6

+ 8 - 1
doc/api_data.js

@@ -577,7 +577,14 @@ define({ "api": [
             "type": "String",
             "optional": false,
             "field": "product_id",
-            "description": "<p>产品id</p>"
+            "description": "<p>产品id,多个用逗号隔开</p>"
+          },
+          {
+            "group": "Parameter",
+            "type": "String",
+            "optional": false,
+            "field": "num",
+            "description": "<p>产品数量,多个用逗号隔开</p>"
           }
         ]
       }

+ 8 - 1
doc/api_data.json

@@ -577,7 +577,14 @@
             "type": "String",
             "optional": false,
             "field": "product_id",
-            "description": "<p>产品id</p>"
+            "description": "<p>产品id,多个用逗号隔开</p>"
+          },
+          {
+            "group": "Parameter",
+            "type": "String",
+            "optional": false,
+            "field": "num",
+            "description": "<p>产品数量,多个用逗号隔开</p>"
           }
         ]
       }

+ 1 - 1
doc/api_project.js

@@ -13,7 +13,7 @@ define({
   "apidoc": "0.3.0",
   "generator": {
     "name": "apidoc",
-    "time": "2018-09-20T08:21:22.625Z",
+    "time": "2018-09-25T10:30:16.143Z",
     "url": "http://apidocjs.com",
     "version": "0.17.6"
   }

+ 1 - 1
doc/api_project.json

@@ -13,7 +13,7 @@
   "apidoc": "0.3.0",
   "generator": {
     "name": "apidoc",
-    "time": "2018-09-20T08:21:22.625Z",
+    "time": "2018-09-25T10:30:16.143Z",
     "url": "http://apidocjs.com",
     "version": "0.17.6"
   }

+ 2 - 1
doc/apidoc.php

@@ -213,7 +213,8 @@
  * @apiDescription 发起微信支付
  *
  * @apiParam {String} signature signature
- * @apiParam {String} product_id 产品id
+ * @apiParam {String} product_id 产品id,多个用逗号隔开
+ * @apiParam {String} num 产品数量,多个用逗号隔开
 *
  * @apiSuccess {Object[]} pay 微信支付返回的数据
  * @apiSuccess {String}   pay.time 服务器时间戳

+ 6 - 6
product/database/order.php

@@ -90,15 +90,15 @@ return array
 
 		'product_id'		=> array
 		(
-			'type' 		=> 'int-11',
-			'name' 		=> '产品',
+			'type' 		=> 'varchar-800',
+			'name' 		=> '产品',
 			'default' 	=> '',
-			'desc' 		=> '产品',
-			'match' 	=> 'is_numeric',
+			'desc' 		=> '产品',
+			'match' 	=> 'is_string',
 			'update'	=> 'select',
 			'option'	=> $product,
-			'search'	=> 'select',
-			//'list'		=> true,
+			//'search'	=> 'select',
+			'list'		=> true,
 		),
 
 		'type'		=> array

+ 1 - 1
product/lib/Manage.php

@@ -15,7 +15,7 @@ class Manage
 
         $table['用户名'] = $user['username'];
         $table['手机号'] = $user['mobile'];
-        $table['产品名'] = $info['name'];
+        //$table['产品名'] = $info['name'];
         if ($info['type'] == 1) {
             $table['支付方式'] = '购买';
             $table['支付金额'] = $info['cash'];

+ 3 - 6
product/lib/Pay.php

@@ -15,13 +15,10 @@ class Pay
 		if ($status == 2) {
             # 支付成功
             $order_id = 'WX' . $order_id;
-            $product = Dever::db('product/info')->one($product_id);
-            if ($product) {
-                $order = Dever::db('product/order')->one(array('product_id' => $product_id, 'order_id' => $order_id, 'uid' => $uid));
+            $order = Dever::db('product/order')->one(array('product_id' => $product_id, 'order_id' => $order_id, 'uid' => $uid));
 
-                if (!$order) {
-                    Dever::db('product/order')->insert(array('order_id' => $order_id, 'product_id' => $product_id, 'cash' => $cash,'uid' => $uid, 'type' => 1, 'name' => $product['name'], 'status' => 2));
-                }
+            if (!$order) {
+                Dever::db('product/order')->insert(array('order_id' => $order_id, 'product_id' => $product_id, 'cash' => $cash,'uid' => $uid, 'type' => 1, 'name' => $product['name'], 'status' => 2));
             }
         }
 	}

+ 31 - 4
product/src/Api.php

@@ -78,8 +78,34 @@ class Api extends Base
     # 购买
     public function buy()
     {
-    	$product_id = Dever::input('product_id', false, '> 0', '请传入正确的产品id');
-        $product = Dever::db('product/info')->one($product_id);
+    	$products = $product_id = Dever::input('products');
+        if (!$products) {
+            Dever::alert('请传入正确的产品id');
+        }
+        $num = Dever::input('num');
+        $products = explode(',', $products);
+        $num = explode(',', $num);
+
+        $name = array();
+        $price = 0;
+        foreach ($products as $k => $v) {
+            $product = Dever::db('product/info')->one($v);
+            if (count($name) >= 3) {
+
+            } else {
+                $name[] = $product['name'];
+            }
+
+            $cart = Dever::db('product/cart')->state(array('product_id' => $v, 'uid' => $this->data['uid']);
+            if ($cart) {
+                foreach ($cart as $k1 => $v1) {
+                    Dever::db('product/cart')->delete($v1['id']);
+                }
+            }
+
+            
+            $price = $price + ($product['pay_price'] * $num[$k]);
+        }
 
         $user = Dever::db('passport/user')->one($this->data['uid']);
         $wechat = Dever::db('passport/wechat')->one(array('uid' => $this->data['uid']));
@@ -90,10 +116,11 @@ class Api extends Base
             'account_id' => 1,
             'uid' => $this->data['uid'],
             'username' => $user['username'],
-            'name' => $product['name'],
-            'cash' => $product['pay_price'],
+            'name' => implode(',', $name),
+            'cash' => $price,
             //'refer' => '1',
             'openid' => $wechat['openid'],
+            'product_id' => $product_id,
         );