rabin 1 year ago
parent
commit
ed1e16ea34
3 changed files with 153 additions and 44 deletions
  1. 33 1
      src/bao/connect/api/Notify.php
  2. 55 30
      src/dai/seller/lib/Manage.php
  3. 65 13
      src/dai/seller/lib/Order.php

+ 33 - 1
src/bao/connect/api/Notify.php

@@ -113,7 +113,39 @@ class Notify extends Api
             $update['official_order_num'] = $data['official_order_num'] ?? '';
             $update['channel_callback'] = json_encode($input, JSON_UNESCAPED_UNICODE);
             $update['channel_callback_date'] = time();
-            Dever::load('order', 'seller')->notify($order, $msg, $update);
+
+            if ($msg != 'ok') {
+                $channel_num = Dever::db('channel', 'seller')->count(array('seller_id' => $order['seller_id'], 'goods_id' => $order['goods_id'], 'status' => 1));
+                if ($channel_num > 1) {
+                    # 记录渠道错误信息
+                    $selected = array();
+                    $selected[$order['channel_id']] = true;
+                    $order_error_data = Dever::db('order_error', 'seller')->select(array('order_num' => $order['order_num']));
+                    if ($order_error_data) {
+                        foreach ($order_error_data as $k => $v) {
+                            $selected[$v['channel_id']] = true;
+                        }
+                    }
+                    $order_error = array();
+                    $order_error['order_num'] = $order['order_num'];
+                    $order_error['buy_price'] = $order['buy_price'];
+                    $order_error['channel_id'] = $order['channel_id'];
+                    $order_error['channel_goods_id'] = $order['channel_goods_id'];
+                    $order_error['channel_goods_discount'] = $order['channel_goods_discount'];
+                    $order_error['channel_order_date'] = $order['channel_order_date'];
+                    $order_error['channel_order_num'] = $order['channel_order_num'];
+                    $order_error['channel_request'] = $order['channel_request'];
+                    $order_error['channel_response'] = $order['channel_response'];
+                    $order_error['channel_callback'] = $update['channel_callback'];
+                    $order_error['channel_callback_date'] = $update['channel_callback_date'];
+                    Dever::db('order_error', 'seller')->insert($order_error);
+                    Dever::load('order', 'seller')->handleAct($order, $selected);
+                } else {
+                    Dever::load('order', 'seller')->notify($order, $msg, $update);
+                }
+            } else {
+                Dever::load('order', 'seller')->notify($order, $msg, $update);
+            }
             echo $this->info['notify_success'];die;
         }
         $this->error('error');

+ 55 - 30
src/dai/seller/lib/Manage.php

@@ -108,7 +108,8 @@ class Manage extends Auth
             $num = $data['data'];
             # 验证是否有剩余的卡密
             # 获取渠道
-            $channel = $class->channel($seller['id'], $goods['id'], $sku['id']);
+            $channel_num = 0;
+            $channel = $class->channel($seller['id'], $goods['id'], $sku['id'], $channel_num);
             if (!$channel) {
                 Dever::error('通道未开启');
             }
@@ -165,7 +166,7 @@ class Manage extends Auth
         foreach ($id as $k => $v) {
             $info = Dever::db('order', 'seller')->find($v);
             if ($info['status'] >= 10) {
-                Dever::load('order', 'seller')->finish($info);
+                Dever::load('order', 'seller')->finish($info, 2);
             }
         }
     }
@@ -452,46 +453,39 @@ class Manage extends Auth
                 array('系统订单ID', $data['id']),
                 array('系统订单号', $data['order_num']),
                 array('订单状态', $value),
-                array('系统发起请求', $data['channel_request']),
-                array('请求时间', $data['channel_order_date'] ? date('Y-m-d H:i', $data['channel_order_date']) : '-'),
             ), 
         );
-        if ($channel) {
-            $result['content'][] = array
-            (
-                'title' => '渠道响应信息',
-                'border' => true,
-                'direction' => 'horizontal',
-                'size' => 'small',
-                'column' => 1,
-                'content' => array
+
+        $order_error = Dever::db('order_error', 'seller')->select(array('order_num' => $data['order_num']));
+        if ($order_error) {
+            foreach ($order_error as $k => $v) {
+                $error_channel = Dever::db('info', 'channel')->find($v['channel_id']);
+                $content = $this->showOrderExpandContent($error_channel, $data);
+                $result['content'][] = array
                 (
-                    array('渠道名称', $channel['name']),
-                    array('渠道地址', $channel['host']),
-                    array('渠道订单号', $data['channel_order_num']),
-                    array('渠道响应信息', $data['channel_response']),
-                ), 
-            );
+                    'title' => '轮巡渠道失败信息-' . ($k+1),
+                    'border' => true,
+                    'direction' => 'horizontal',
+                    'size' => 'small',
+                    'column' => 1,
+                    'content' => $content,
+                );
+            }
         }
-        
-        if ($data['channel_callback']) {
+
+        if ($channel) {
+            $content = $this->showOrderExpandContent($channel, $data);
             $result['content'][] = array
             (
-                'title' => '渠道回调信息',
+                'title' => '当前渠道响应信息',
                 'border' => true,
                 'direction' => 'horizontal',
                 'size' => 'small',
                 'column' => 1,
-                'content' => array
-                (
-                    array('渠道回调信息', $data['channel_callback']),
-                    array('回调时间', date('Y-m-d H:i', $data['channel_callback_date'])),
-                    array('官方流水号', '<span>' . $data['official_order_num'] . '</span>'),
-                    array('官方充值结果', $data['official_msg']),
-                ), 
+                'content' => $content,
             );
         }
-        
+
         $result['content'][] = array
         (
             'title' => '系统向商户发起回调',
@@ -509,6 +503,37 @@ class Manage extends Auth
         return $result;
     }
 
+    # 展示订单渠道内容
+    public function showOrderExpandContent($channel, $info)
+    {
+        $content = array();
+        $content[] = array('渠道名称', $channel['name']);
+        $content[] = array('渠道地址', $channel['host']);
+        if ($info['channel_order_num']) {
+            $content[] = array('渠道订单号', $info['channel_order_num']);
+        }
+        $content[] = array('请求时间', $info['channel_order_date'] ? date('Y-m-d H:i', $info['channel_order_date']) : '-');
+        if ($info['channel_request']) {
+            $content[] = array('请求信息', $info['channel_request']);
+        }
+        if ($info['channel_response']) {
+            $content[] = array('响应信息', $info['channel_response']);
+        }
+        if ($info['channel_callback']) {
+            $content[] = array('回调信息', $info['channel_callback']);
+        }
+        if ($info['channel_callback_date']) {
+            $content[] = array('回调时间', date('Y-m-d H:i', $info['channel_callback_date']));
+        }
+        if (isset($info['official_order_num']) && $info['official_order_num']) {
+            $content[] = array('官方流水号', '<span>' . $info['official_order_num'] . '</span>');
+        }
+        if (isset($info['official_msg']) && $info['official_msg']) {
+            $content[] = array('官方充值结果', $info['official_msg']);
+        }
+        return $content;
+    }
+
     # 展示订单卡密扩展信息
     public function showOrderExpandKm($data)
     {

+ 65 - 13
src/dai/seller/lib/Order.php

@@ -84,7 +84,8 @@ class Order
         }
         Dever::db('order', 'seller')->update($info['id'], $update);
 
-        $channel = $this->channel($info['seller_id'], $info['goods_id'], $info['sku_id']);
+        $channel_num = 0;
+        $channel = $this->channel($info['seller_id'], $info['goods_id'], $info['sku_id'], $channel_num, $selected);
         if (!$channel) {
             return $this->notify($info, '通道未开启', $update);
         }
@@ -108,6 +109,20 @@ class Order
                 $param['code'] = $sku['code'];
             }
             $result = Dever::load('func/api', 'connect')->run(1, $info['cate_id'], $channel, $param);
+            if ($channel_num > 1 && $result && $result['status'] != 1) {
+                # 记录渠道错误信息
+                $selected[$channel['id']] = true;
+                $order_error_data = Dever::db('order_error', 'seller')->select(array('order_num' => $info['order_num']));
+                if ($order_error_data) {
+                    foreach ($order_error_data as $k => $v) {
+                        $selected[$v['channel_id']] = true;
+                    }
+                }
+                $order_error = $this->channel_update($info, $channel, $result);
+                $order_error['order_num'] = $info['order_num'];
+                Dever::db('order_error', 'seller')->insert($order_error);
+                return $this->handleAct($info, $selected);
+            }
         } elseif ($channel['type'] == 2) {
             # 需要审核
             # 获取卡密并占用
@@ -129,7 +144,19 @@ class Order
         } elseif ($channel['type'] == 11) {
             $result['status'] = 1;
         }
-        
+        $update = $this->channel_update($info, $channel, $result);
+        if ($result['status'] == 1) {
+            # 下单成功
+            Dever::db('order', 'seller')->update($info['id'], $update);
+            return 'ok';
+        } else {
+            # 下单失败
+            return $this->notify($info, '下单失败', $update);
+        }
+    }
+
+    public function channel_update($info, $channel, $result)
+    {
         $update = array();
         $update['channel_id'] = $channel['id'];
         $update['channel_order_date'] = time();
@@ -150,14 +177,7 @@ class Order
             $update['channel_goods_discount'] = 1;
         }
         $update['buy_price'] = round($info['cash'] * $update['channel_goods_discount'], 2) * $info['num'];
-        if ($result['status'] == 1) {
-            # 下单成功
-            Dever::db('order', 'seller')->update($info['id'], $update);
-            return 'ok';
-        } else {
-            # 下单失败
-            return $this->notify($info, '下单失败', $update);
-        }
+        return $update;
     }
 
     # 向商户发起回调
@@ -217,7 +237,7 @@ class Order
             $update['finish'] = 1;
             $update['finish_date'] = time();
             $info = array_merge($info, $update);
-            Dever::load('order', 'seller')->finish($info);
+            $this->finish($info);
         }
         if (!$info['order_num']) {
             $update['order_num'] = $this->createOrder();
@@ -226,7 +246,7 @@ class Order
         return $msg;
     }
 
-    public function finish($info)
+    public function finish($info, $oper = 1)
     {
         if ($info['status'] == 10) {
             if ($info['channel_id']) {
@@ -257,6 +277,37 @@ class Order
                     Dever::db('card', 'channel')->update($param, array('use_status' => 1));
                 }
             }
+
+            if ($oper == 2) {
+                $channel_num = Dever::db('channel', 'seller')->count(array('seller_id' => $info['seller_id'], 'goods_id' => $info['goods_id'], 'status' => 1));
+                if ($channel_num > 1 && $info['channel_id']) {
+                    $info['status'] = 2;
+                    Dever::db('order', 'seller')->update($info['id'], array('status' => 2, 'finish' => 2, 'finish_date' => '0'));
+                    # 记录渠道错误信息
+                    $selected = array();
+                    $selected[$info['channel_id']] = true;
+                    $order_error_data = Dever::db('order_error', 'seller')->select(array('order_num' => $info['order_num']));
+                    if ($order_error_data) {
+                        foreach ($order_error_data as $k => $v) {
+                            $selected[$v['channel_id']] = true;
+                        }
+                    }
+                    $order_error = array();
+                    $order_error['order_num'] = $info['order_num'];
+                    $order_error['buy_price'] = $info['buy_price'];
+                    $order_error['channel_id'] = $info['channel_id'];
+                    $order_error['channel_goods_id'] = $info['channel_goods_id'];
+                    $order_error['channel_goods_discount'] = $info['channel_goods_discount'];
+                    $order_error['channel_order_date'] = $info['channel_order_date'];
+                    $order_error['channel_order_num'] = $info['channel_order_num'];
+                    $order_error['channel_request'] = $info['channel_request'];
+                    $order_error['channel_response'] = $info['channel_response'];
+                    $order_error['channel_callback'] = $info['channel_callback'];
+                    $order_error['channel_callback_date'] = $info['channel_callback_date'];
+                    Dever::db('order_error', 'seller')->insert($order_error);
+                    return Dever::load('order', 'seller')->handleAct($info, $selected);
+                }
+            }
             
             # 失败,余额加回来
             Dever::load('info', 'seller')->inc($info['seller_id'], $info['price']);
@@ -311,13 +362,14 @@ class Order
     }
 
     # 获取渠道
-    public function channel($seller_id, $goods_id, $sku_id, $selected = array())
+    public function channel($seller_id, $goods_id, $sku_id, &$channel_num, $selected = array())
     {
         # 查找渠道
         $channel_list = Dever::db('channel', 'seller')->select(array('seller_id' => $seller_id, 'goods_id' => $goods_id, 'status' => 1));
         if (!$channel_list) {
             return false;
         }
+        $channel_num = count($channel_list);
         $max = 1;
         $channel = $goods = array();
         foreach ($channel_list as $k => $v) {