|
@@ -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) {
|