dever 5 years ago
parent
commit
4066673f69
7 changed files with 180 additions and 10 deletions
  1. 5 5
      config/base.php
  2. 47 0
      doc/apidoc.php
  3. 16 0
      product/database/cart.php
  4. 36 0
      product/database/order.php
  5. 4 0
      product/lib/Manage.php
  6. 2 1
      product/lib/Pay.php
  7. 70 4
      product/src/Api.php

+ 5 - 5
config/base.php

@@ -26,24 +26,24 @@ $config['base'] = array
 		# debug模式
 		'debug' => true,
 		# 发送短信的接口
-		'url' => 'https://feginesms.market.alicloudapi.com/codeNotice',
+		'url' => 'http://api.shumi365.com:8090/sms/send.do',
 		# 发送方法 get、post
 		'method' => 'get',
 		# 是否json编码
 		'json' => false,
 		# header信息
-		'header' => 'Authorization:APPCODE ca584ae21ce54c999067e77b5995a27b',
+		'header' => '',
 		# body信息
-		'body' => 'param={code}&phone={mobile}&sign={sign}&skin={skin}',
+		'body' => 'userid=400092&pwd=268692&timespan=' . date('YmdHis').'&msgfmt=UTF8',
 		# 短信模板 发送短信时,请加上参数skin=1
 		'skin' => array
 		(
 			'reg' => 35247,
 			'order' => 35246,
-			'code' => 35245,
+			//'code' => 35245,
 		),
 		# 短信签名
-		'sign' => 47159,
+		'sign' => 0,
 		# 验证码有效期 默认10分钟
 		'timeout' => 600,
 		# 一天之内的最大发送次数,默认为10次

+ 47 - 0
doc/apidoc.php

@@ -202,6 +202,36 @@
  * @apiParam {String} signature signature
  * @apiParam {String} product_id 产品id
  * @apiParam {String} code 兑换码
+ * @apiParam {String} name 收货人姓名
+ * @apiParam {String} address 收货人地址
+ * @apiParam {String} mobile 收货人联系电话
+ */
+
+/**
+ * @api {get} product/?l=api.checkCode 根据兑换码获取产品信息
+ * @apiVersion 1.0.0
+ * @apiName api.checkCode
+ * @apiGroup Product
+ *
+ * @apiDescription 根据兑换码获取产品信息
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {String} code 兑换码
+
+ * @apiSuccess {Object[]} product 产品信息
+ * @apiSuccess {String}   product.id 产品id
+ * @apiSuccess {String}   product.name 名称
+ * @apiSuccess {String}   product.pic 产品封面
+ * @apiSuccess {String}   product.focus 产品轮播图 多个用逗号隔开
+ * @apiSuccess {String}   product.content 内容
+ * @apiSuccess {String}   product.price 显示价格
+ * @apiSuccess {Number}   product.pay_price 支付价格
+ * @apiSuccess {Number}   product.content 产品介绍
+
+ * @apiSuccess {Object[]} address 收货地址
+ * @apiSuccess {String}   address.name 收货人姓名
+ * @apiSuccess {String}   address.address 收货人地址
+ * @apiSuccess {String}   address.mobile 收货人联系电话
  */
 
 /**
@@ -215,6 +245,9 @@
  * @apiParam {String} signature signature
  * @apiParam {String} product_id 产品id,多个用逗号隔开
  * @apiParam {String} num 产品数量,多个用逗号隔开
+ * @apiParam {String} name 收货人姓名
+ * @apiParam {String} address 收货人地址
+ * @apiParam {String} mobile 收货人联系电话
 *
  * @apiSuccess {Object[]} pay 微信支付返回的数据
  * @apiSuccess {String}   pay.time 服务器时间戳
@@ -268,6 +301,20 @@
  * @apiSuccess {String}   data 返回ok
  */
 
+/**
+ * @api {get} product/?l=api.delCarts 从购物车删除产品
+ * @apiVersion 1.0.0
+ * @apiName api.delCarts
+ * @apiGroup Product
+ *
+ * @apiDescription 从购物车删除产品
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {String} product_id 产品id
+ *
+ * @apiSuccess {String}   data 返回ok
+ */
+
 
 /**
  * @api {get} product/?l=api.carts 获取购物车列表

+ 16 - 0
product/database/cart.php

@@ -88,4 +88,20 @@ return array
 		'edit' => false,
 		'insert' => false,
 	),
+
+	'request' => array
+	(
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'state' => 1,
+				'uid' => 'yes',
+			),
+			'type' => 'all',
+			'order' => array('cdate' => 'desc'),
+			'col' => '*',
+		),
+	),
 );

+ 36 - 0
product/database/order.php

@@ -158,6 +158,42 @@ return array
 			'list'		=> true,
 		),
 
+		'address_name'		=> array
+		(
+			'type' 		=> 'varchar-80',
+			'name' 		=> '收货姓名',
+			'default' 	=> '',
+			'desc' 		=> '请输入收货姓名',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			//'search'	=> 'fulltext',
+			//'list'		=> true,
+		),
+
+		'address_mobile'		=> array
+		(
+			'type' 		=> 'varchar-80',
+			'name' 		=> '联系电话',
+			'default' 	=> '',
+			'desc' 		=> '请输入联系电话',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			//'search'	=> 'fulltext',
+			//'list'		=> true,
+		),
+
+		'address_address'		=> array
+		(
+			'type' 		=> 'varchar-800',
+			'name' 		=> '收货地址',
+			'default' 	=> '',
+			'desc' 		=> '请输入收货地址',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			//'search'	=> 'fulltext',
+			//'list'		=> true,
+		),
+
 		'fastatus'		=> array
 		(
 			'type' 		=> 'tinyint-1',

+ 4 - 0
product/lib/Manage.php

@@ -24,6 +24,10 @@ class Manage
             $table['兑换码'] = $info['code'];
         }
 
+        $table['收货人姓名'] = $info['address_name'];
+        $table['收货人手机'] = $user['address_mobile'];
+        $table['收货人地址'] = $user['address_address'];
+
 
         return Dever::table($table);
     }

+ 2 - 1
product/lib/Pay.php

@@ -18,7 +18,8 @@ class Pay
             $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));
+                $address = Dever::db('product/address')->one(array('uid' => $uid));
+                Dever::db('product/order')->insert(array('order_id' => $order_id, 'product_id' => $product_id, 'cash' => $cash,'uid' => $uid, 'type' => 1, 'name' => $product['name'], 'address_name' => $address['name'], 'address_mobile' => $address['mobile'], 'address_address' => $address['address'], 'status' => 2));
             }
         }
 	}

+ 70 - 4
product/src/Api.php

@@ -135,6 +135,48 @@ class Api extends Base
         return $this->data;
     }
 
+    # 根据code检索是否存在
+    public function checkCode()
+    {
+        $code = Dever::input('code');
+
+        if ($code) {
+
+            $info = Dever::db('code/info')->one(array('code' => $code));
+
+            if (!$info) {
+                Dever::alert('兑换码不存在');
+            }
+
+            if ($info['type'] == 3) {
+                Dever::alert('兑换码已被使用');
+            }
+
+            if ($info['type'] == 2 && $this->data['uid'] != $info['uid']) {
+                //Dever::alert('兑换码已被领取');
+            }
+
+            $order = Dever::db('product/order')->one('code' => $code);
+
+            if ($order) {
+                Dever::alert('兑换码已被使用');
+            }
+
+            if ($info['product_id']) {
+                $product = Dever::db('product/info')->one($product_id);
+                $this->data['product'] = array($product);
+                $this->data['address'] = Dever::db('product/address')->one(array('uid' => $this->data['uid']));
+
+                return $this->data;
+            }
+
+        } else {
+            Dever::alert('请输入完整的兑换码');
+        }
+
+        return true;
+    }
+
     # 兑换
     public function code()
     {
@@ -142,7 +184,11 @@ class Api extends Base
 
         $code = Dever::input('code');
 
-        if ($code) {
+        $name = Dever::input('name');
+        $mobile = Dever::input('mobile');
+        $address = Dever::input('address');
+
+        if ($code && $name && $mobile && $address) {
 
             $product = Dever::db('product/info')->one($product_id);
 
@@ -169,10 +215,10 @@ class Api extends Base
             Dever::db('code/info')->update(array('where_id' => $info['id'], 'type' => 3, 'uid' => $this->data['uid'], 'ldate' => time()));
 
             $order_id = $this->createOrder();
-            Dever::db('product/order')->insert(array('order_id' => $order_id, 'product_id' => $product_id, 'code' => $code, 'uid' => $this->data['uid'], 'type' => 2, 'name' => $product['name'], 'status' => 2));
+            Dever::db('product/order')->insert(array('order_id' => $order_id, 'product_id' => $product_id, 'code' => $code, 'uid' => $this->data['uid'], 'type' => 2, 'name' => $product['name'], 'address_name' => $name, 'address_mobile' => $mobile, 'address_address' => $address, 'status' => 2));
 
         } else {
-            Dever::alert('请输入完整的兑换码');
+            Dever::alert('请输入完整的兑换码或者收货信息');
         }
 
         return true;
@@ -239,7 +285,7 @@ class Api extends Base
         $where = array();
         $where['uid'] = $this->data['uid'];
         
-        $this->data['carts'] = Dever::db('product/cart')->state($where);
+        $this->data['carts'] = Dever::db('product/cart')->getAll($where);
 
         if ($this->data['carts']) {
             foreach ($this->data['carts'] as $k => $v) {
@@ -252,6 +298,26 @@ class Api extends Base
         return $this->data;
     }
 
+    # 删除购物车的数据
+    public function delCarts()
+    {
+        $product_id = Dever::input('product_id', false, '> 0', '请传入正确的产品id');
+        $uid = $this->data['uid'];
+        if ($product_id > 0) {
+            $update = array();
+            $update['product_id'] = $product_id;
+            $update['uid'] = $this->data['uid'];
+            
+            $info = Dever::db('product/cart')->one($update);
+            if ($info) {
+                $update['where_id'] = $info['id'];
+                Dever::db('product/cart')->delete($update);
+            }
+        }
+
+        return 'ok';
+    }
+
     # 添加收货地址
     public function addAddress()
     {