dever 5 năm trước cách đây
mục cha
commit
2cd305e066
3 tập tin đã thay đổi với 40 bổ sung61 xóa
  1. 2 2
      database/order.php
  2. 26 0
      database/shop.php
  3. 12 59
      lib/Pay.php

+ 2 - 2
database/order.php

@@ -146,11 +146,11 @@ $config = array
 
 		'source'		=> array
 		(
-			'type' 		=> 'varchar-100',
+			'type' 		=> 'int-11',
 			'name' 		=> '来源',
 			'default' 	=> '',
 			'desc' 		=> '来源',
-			'match' 	=> 'is_string',
+			'match' 	=> 'is_numeric',
 			'update'	=> 'text',
 			//'list'		=> true,
 		),

+ 26 - 0
database/shop.php

@@ -1,5 +1,10 @@
 <?php
 
+$pay_channel = function()
+{
+    return Dever::load('pay/api.channel');
+};
+
 return array
 (
 	# 表名
@@ -36,6 +41,17 @@ return array
 			'edit'		=> true,
 		),
 
+		'pay_channel'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '支付渠道',
+            'default'   => '1',
+            'desc'      => '支付渠道',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'option'    => $pay_channel,
+        ),
+
 		'reorder'		=> array
 		(
 			'type' 		=> 'int-11',
@@ -78,6 +94,16 @@ return array
 
 	),
 
+	# 默认值
+	'default' => array
+	(
+		'col' => 'name,state,cdate',
+		'value' => array
+		(
+			'"官方店铺",1,' . time(),
+		),
+	),
+
 	'request' => array
 	(
 		

+ 12 - 59
lib/Pay.php

@@ -9,56 +9,27 @@ use Dever;
 class Pay
 {
     # 发起支付
-	public function action($parent_uid, $uid, $id, $sku, $num, $source, $type = false, $type_id = false)
+	public function action($parent_uid, $uid, $id, $sku, $num, $address_id, $source, $type = false, $type_id = false)
     {
         if (!$uid) {
             Dever::alert('错误的用户信息');
         }
 
-        $source = 'android';
-
         $goods = Dever::load('goods/lib/info')->getPayInfo($id, $sku);
+        $shop = Dever::db('goods/shop')->one($goods['shop_id']);
 
         $user = Dever::db('passport/user')->one($uid);
-        $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid, 'type' => 1, 'system_id' => 1));
-
-        if ($source == 'ios') {
-            $method = 'apple';
-            $account_id = 3;
-            # 使用苹果内购支付
-            $receipt = Dever::input('receipt');
-            if (!$receipt) {
-                Dever::alert('苹果内购支付失败,没有receipt参数');
-            }
-        } elseif ($source == 'android') {
-            $method = 'app';
-            $account_id = 3;
-        } elseif ($source == 'applet') {
-        	# 小程序支付
-            $method = 'applet';
-            $account_id = 2;
-        } else {
-        	# 默认是网页支付
-        	$method = 'page';
-        	$account_id = 1;
-        }
         
         if ($parent_uid) {
             $order_data['parent_uid'] = $parent_uid;
         }
-
-        if ($type) {
-            $order_data['type'] = $type;
-        }
-
-        if ($type_id) {
-            $order_data['type_id'] = $type_id;
-        }
-        
+        $order_data['type'] = $type;
+        $order_data['type_id'] = $type_id;
         $order_data['uid'] = $uid;
         $order_data['status'] = 1;
         $order_data['info_id'] = $goods['id'];
         $order_data['sku_id'] = $sku;
+        $order_data['address_id'] = $address_id;
         $order_data['name'] = $goods['name'];
         $order_data['cash'] = $goods['price'];
         $order_data['num'] = $num;
@@ -72,27 +43,26 @@ class Pay
 
         $refer = 'test';
 
-        //$param参数
         $param = array
         (
-            'account_id' => $account_id,
             'project_id' => 1,
+            'channel_id' => $shop['channel_id'],
+            'system_source' => $source,
             'uid' => $uid,
             'username' => $user['username'],
             'name' => $order_data['name'],
             'cash' => $order_data['cash'] * $order_data['num'],
-            //'cash' => '0.01',
-            'openid' => isset($wechat['openid']) ? $wechat['openid'] : '',
             'product_id' => $goods['id'],
             'order_id' => $order_data['order_id'],
             'refer' => $refer
         );
 
-        if ($method == 'apple') {
-            $param['other'] = $receipt;
+        $receipt = Dever::input('receipt');
+        if ($receipt) {
+            $param['receipt'] = $receipt;
         }
 
-        $result['pay'] = Dever::load('pay/api.' . $method, $param);
+        $result['pay'] = Dever::load('pay/api.pay', $param);
 
         $result['order_id'] = $order_data['order_id'];
 
@@ -166,7 +136,7 @@ class Pay
     # 生成订单号
     public function getOrderId()
     {
-        $where['order_id'] = $this->createOrderId();
+        $where['order_id'] = Dever::order();
         $state = Dever::db('goods/order')->one($where);
         if (!$state) {
             return $where['order_id'];
@@ -174,21 +144,4 @@ class Pay
             return $this->getOrderId();
         }
     }
-
-    # 生成订单号
-    public function createOrderId()
-    {   
-        if (function_exists('session_create_id')) {
-            return strtoupper(session_create_id());
-        } else {
-            $charid = strtoupper(md5(uniqid(mt_rand(), true)));
-            return substr($charid, 0, 8) . substr($charid, 8, 4) . substr($charid, 12, 4) . substr($charid, 16, 4) . substr($charid, 20, 12);
-        }
-    }
-
-    # 临时订单号 无用
-    public function createTmpOrderId($prefix = '')
-    {
-        return $prefix . (strtotime(date('YmdHis', time()))) . substr(microtime(), 2, 6) . sprintf('%03d', rand(0, 999));
-    }
 }