Browse Source

Merge branch 'master' of http://git.dever.cc:3000/dever-package/goods

dever 4 years ago
parent
commit
55ddf8a0e4
5 changed files with 75 additions and 12 deletions
  1. 13 0
      database/info_sku.php
  2. 25 1
      database/order.php
  3. 2 1
      lib/Info.php
  4. 24 8
      lib/Order.php
  5. 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
 		(
 			# 匹配的正则或函数 选填项

+ 25 - 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
 (
 	# 表名
@@ -17,6 +25,7 @@ $config = array
 	'lang' => '商品订单',
 	'order' => 300,
 	'auto' => 1000000,
+	'get_status' => $status,
 
 	# 数据结构 不同的字段放这里
 	'struct' => array
@@ -311,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',
@@ -376,8 +398,10 @@ $config = array
 			'option' => array
 			(
 				'uid' => 'yes',
+				'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);

+ 24 - 8
lib/Order.php

@@ -9,29 +9,45 @@ use Dever;
 class Order
 {
 	# 获取我的订单
-	public function getList($uid, $type = false, $type_id = false)
+	public function getMyList($uid, $type = false, $type_id = false, $callback = false)
 	{
 		$where['uid'] = $uid;
+		
 		if ($type && $type_id) {
 			$where['type'] = $type;
 			$where['type_id'] = $type_id;
 		}
 
+		return $this->getData($where, $callback);
+	}
+
+	# 获取某个商品的订单
+	public function getList($info_id, $type = false, $type_id = false, $callback = false)
+	{
+		$where['info_id'] = $info_id;
+		if ($type && $type_id) {
+			$where['type'] = $type;
+			$where['type_id'] = $type_id;
+		}
+
+		return $this->getData($where, $callback);
+	}
+
+	public function getData($where, $callback = false)
+	{
 		$order = Dever::db('goods/order')->getData($where);
 
 		if ($order) {
+			$config = Dever::db('goods/order')->config['get_status'];
 			foreach ($order as $k => $v) {
-				if ($v['status'] == 1) {
-					$order[$k]['status_name'] = '待支付';
-				} elseif ($v['status'] == 2) {
-					$order[$k]['status_name'] = '已支付';
-				} else {
-					$order[$k]['status_name'] = '支付失败';
-				}
+				$order[$k]['status_name'] = $config[$v['status']];
 				$goods = Dever::db('goods/info')->one($v['info_id']);
 				$order[$k]['pic'] = $goods['pic_cover'];
 				$order[$k]['date'] = date('Y-m-d H:i:s', $v['cdate']);
 				$order[$k]['price'] = $v['cash'] * $v['num'] . '元';
+				if ($callback) {
+					$order[$k] = $callback($order[$k]);
+				}
 			}
 		}
 

+ 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) {
                 # 减少库存 增加销量
@@ -143,7 +151,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);