dever 4 years ago
parent
commit
b1f55c0f94
4 changed files with 49 additions and 4 deletions
  1. 13 0
      database/info_sku.php
  2. 23 1
      database/order.php
  3. 2 1
      lib/Info.php
  4. 11 2
      lib/Pay.php

+ 13 - 0
database/info_sku.php

@@ -166,6 +166,19 @@ $config = array
 			'col' => '*,num-sell_num as num|key',
 		),
 
+		# 获取单条数据
+		'getOne' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'info_id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'one',
+			'col' => '*,num-sell_num as num',
+		),
+
 		'getMinOne' => array
 		(
 			# 匹配的正则或函数 选填项

+ 23 - 1
database/order.php

@@ -8,7 +8,15 @@ $confirm = array
 	1 => '未确认',
 	2 => '已确认',
 );
-$status = Dever::config('base', 'pay')->pay['status'];
+$pay_status = Dever::config('base', 'pay')->pay['status'];
+$status = array
+(
+	1 => '进行中',
+	2 => '已支付',
+	3 => '配送中',
+	4 => '已收货',
+	5 => '已完成',
+);
 $config = array
 (
 	# 表名
@@ -312,6 +320,19 @@ $config = array
             'search'    => 'select',
         ),
 
+		'pay_status'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '支付状态',
+			'default' 	=> '1',
+			'desc' 		=> '支付状态',
+			'match' 	=> 'is_numeric',
+			//'update'	=> 'radio',
+			'option'	=> $pay_status,
+			'search'	=> 'select',
+			'list'      => true,
+		),
+
 		'status'		=> array
 		(
 			'type' 		=> 'tinyint-1',
@@ -380,6 +401,7 @@ $config = array
 				'info_id' => 'yes',
 				'type' => 'yes',
 				'type_id' => 'yes',
+				'pay_status' => 2,
 				'status' => 'yes',
 				'state' => 1,
 			),

+ 2 - 1
lib/Info.php

@@ -250,9 +250,10 @@ class Info
             if ($sku > 0) {
                 $where['info_id'] = $info['id'];
                 $where['id'] = $sku;
-                $sku = Dever::db('goods/info_sku')->one($where);
+                $sku = Dever::db('goods/info_sku')->getOne($where);
                 if ($sku) {
                     $info['price'] = $sku['price'];
+                    $info['num'] = $sku['num'];
                 }
             }
             $freight = $this->freight($info, $info['price'], $user, $num);

+ 11 - 2
lib/Pay.php

@@ -21,7 +21,15 @@ class Pay
         if (!$goods) {
             Dever::alert('错误的商品信息');
         }
+        # 验证库存
+        if ($goods['num'] < $num) {
+            Dever::alert('已售空');
+        }
+
         $shop = Dever::db('goods/shop')->one($goods['shop_id']);
+        if (!$shop) {
+            Dever::alert('店铺不存在');
+        }
         
         if ($parent_uid) {
             $order_data['parent_uid'] = $parent_uid;
@@ -109,7 +117,7 @@ class Pay
         $msg = $send['pay_msg'];
 
         $order = Dever::db('goods/order')->one(array('order_id' => $order_id, 'time' => time()));
-        if ($order && $order['status'] == 1) {
+        if ($order && $order['pay_status'] == 1) {
 
             if ($status == 2) {
                 # 减少库存 增加销量
@@ -138,7 +146,8 @@ class Pay
                 }
             }
 
-            $update['status'] = $status;
+            $update['pay_status'] = $status;
+            $update['status'] = 2;
             $update['where_id'] = $order['id'];
             $update['pay_time'] = time();
             Dever::db('goods/order')->update($update);