|
@@ -391,42 +391,6 @@ class Buy
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public function send_api()
|
|
|
- {
|
|
|
- $id = Dever::input('id');
|
|
|
- $process = Dever::input('process', 3);
|
|
|
- $info = Dever::db('shop/buy_order_refund')->find($id);
|
|
|
-
|
|
|
- if ($info && $info['process'] == 1) {
|
|
|
- $update['process'] = $process;
|
|
|
- $update['where_id'] = $info['id'];
|
|
|
- $state = Dever::db('shop/buy_order_refund')->update($update);
|
|
|
-
|
|
|
- if ($state && $process == 2) {
|
|
|
- $data = $this->getView($info['shop_id'], $info['order_id'], false);
|
|
|
- if ($data) {
|
|
|
- if ($info['order_goods_id'] > 0) {
|
|
|
- $state = Dever::db('shop/buy_order_goods')->update(array('where_id' => $info['order_goods_id'], 'status' => 3));
|
|
|
- $this->pay_refund($state, $data, $info['cash']);
|
|
|
-
|
|
|
-
|
|
|
- $total = Dever::db('shop/buy_order_goods')->total(array('order_id' => $info['order_id'], 'shop_id' => $id, 'status' => 1));
|
|
|
- if ($total <= 0) {
|
|
|
- $state = Dever::db('shop/buy_order')->update(array('where_id' => $info['order_id'], 'status' => 8));
|
|
|
- }
|
|
|
- } else {
|
|
|
-
|
|
|
- $state = Dever::db('shop/buy_order')->update(array('where_id' => $info['order_id'], 'status' => 8));
|
|
|
- $this->pay_refund($state, $data, $info['cash']);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return 'ok';
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
public function orderStatus($id)
|
|
|
{
|
|
@@ -482,6 +446,29 @@ class Buy
|
|
|
|
|
|
</tr>';
|
|
|
|
|
|
+ if ($info['type_id'] > 0) {
|
|
|
+ if ($info['type'] == 1) {
|
|
|
+
|
|
|
+ $store = Dever::db('store/info')->find($info['type_id']);
|
|
|
+
|
|
|
+ $html .= '<tr>
|
|
|
+ <td>供应商信息</td>
|
|
|
+ <td>'.$this->table(false, array(array('仓库名称:' . $store['name'], '联系人:' . $store['truename'], '联系电话:' . $store['mobile']))).'</td>
|
|
|
+
|
|
|
+ </tr>';
|
|
|
+ } elseif ($info['type'] == 2) {
|
|
|
+
|
|
|
+ $factory = Dever::db('factory/info')->find($info['type_id']);
|
|
|
+
|
|
|
+ $html .= '<tr>
|
|
|
+ <td>供应商信息</td>
|
|
|
+ <td>'.$this->table(false, array(array('工厂名称:' . $factory['name'], '联系人:' . $factory['truename'], '联系电话:' . $factory['mobile']))).'</td>
|
|
|
+
|
|
|
+ </tr>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
$url = Dever::url('lib/buy.refund', 'mshop');
|
|
|
|
|
|
if ($tk && $tk['process'] == 1) {
|
|
@@ -577,19 +564,34 @@ class Buy
|
|
|
return $html;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public function send_commit()
|
|
|
+ {
|
|
|
+ $order_id = Dever::input('order_id');
|
|
|
+ $order = Dever::db('shop/buy_order')->find($order_id);
|
|
|
+
|
|
|
+ if (!$order || ($order && $order['status'] != 3)) {
|
|
|
+ Dever::alert('当前订单状态无法发货');
|
|
|
+ }
|
|
|
+
|
|
|
+ $state = Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'status' => 4, 'fdate' => time()));
|
|
|
+
|
|
|
+ return 'reload';
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public function audit_commit()
|
|
|
{
|
|
|
$order_id = Dever::input('order_id');
|
|
|
- $info = Dever::db('shop/buy_order')->find($order_id);
|
|
|
+ $order = Dever::db('shop/buy_order')->find($order_id);
|
|
|
|
|
|
- if (!$info || ($info && $info['status'] != 2)) {
|
|
|
+ if (!$order || ($order && $order['status'] != 2)) {
|
|
|
Dever::alert('当前订单状态无法拆单');
|
|
|
}
|
|
|
|
|
|
$goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $order_id));
|
|
|
|
|
|
- $shop = Dever::db('shop/info')->find($info['shop_id']);
|
|
|
+ $shop = Dever::db('shop/info')->find($order['shop_id']);
|
|
|
|
|
|
|
|
|
$shop_store = Dever::db('shop/store')->select(array('shop_id' => $shop['id']));
|
|
@@ -622,18 +624,14 @@ class Buy
|
|
|
|
|
|
array_multisort($distance, SORT_ASC, SORT_NUMERIC, $factory);
|
|
|
|
|
|
- print_r($store);
|
|
|
- print_r($factory);die;
|
|
|
-
|
|
|
$num = 0;
|
|
|
- $order = array();
|
|
|
foreach ($goods as $k => $v) {
|
|
|
|
|
|
- $find = $this->store($order_id . '_' . $num, $shop, $store, $v);
|
|
|
+ $find = $this->store($order['order_num'] . '_' . $num, $shop, $store, $v);
|
|
|
if (!$find[1]) {
|
|
|
|
|
|
if ($factory) {
|
|
|
- $find = $this->factory($order_id . '_' . $num, $shop, $factory, $v);
|
|
|
+ $find = $this->factory($order['order_num'] . '_' . $num, $shop, $factory, $v);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -643,20 +641,31 @@ class Buy
|
|
|
}
|
|
|
|
|
|
if ($num > 0) {
|
|
|
- Dever::db('shop/buy_order')->update(array('where_id' => $info['id'], 'state' => 2));
|
|
|
+ if ($num == 1 && count($find[1]) == 1) {
|
|
|
+ Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'status' => 3, 'type' => $find[0], 'type_id' => implode('', $find[1])));
|
|
|
+
|
|
|
+ Dever::db('shop/buy_order')->delete($find[2][0]);
|
|
|
+ Dever::db('shop/buy_order_goods')->delete(array('order_id' => $find[2][0]));
|
|
|
+
|
|
|
+ } else {
|
|
|
+ Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'state' => 2));
|
|
|
+ }
|
|
|
} else {
|
|
|
|
|
|
- Dever::db('shop/buy_order')->update(array('where_id' => $info['id'], 'status' => 8));
|
|
|
- Dever::load('shop/lib/refund')->set('buy')->action($order_id, 2, false);
|
|
|
+ Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'status' => 8));
|
|
|
+ Dever::load('shop/lib/refund')->set('buy')->apply(2, $shop['id'], $order_id, false, 3, 0);
|
|
|
}
|
|
|
+
|
|
|
+ return 'ok';
|
|
|
}
|
|
|
|
|
|
private function store($order_id, $shop, $store, $goods, $state = 2)
|
|
|
{
|
|
|
$find = array();
|
|
|
+ $type_id = array();
|
|
|
$id = array();
|
|
|
if (!$store) {
|
|
|
- return array(1, $id);
|
|
|
+ return array(1, $type_id, $id);
|
|
|
}
|
|
|
foreach ($store as $k => $v) {
|
|
|
$where['store_id'] = $v['id'];
|
|
@@ -669,7 +678,8 @@ class Buy
|
|
|
|
|
|
$state = Dever::load('store/lib/order')->pay($order_id, $shop, $where['store_id'], $goods['price'], $goods['num'], $where['goods_id'], $where['sku_id']);
|
|
|
if ($state) {
|
|
|
- $id[] = $where['store_id'];
|
|
|
+ $type_id[] = $where['store_id'];
|
|
|
+ $id[] = $state;
|
|
|
break;
|
|
|
}
|
|
|
} elseif ($state == 1 && $sku['total'] > 0) {
|
|
@@ -680,7 +690,8 @@ class Buy
|
|
|
if (!$state) {
|
|
|
$goods['num'] = $goods['num'] + $sku['total'];
|
|
|
} else {
|
|
|
- $id[] = $where['store_id'];
|
|
|
+ $type_id[] = $where['store_id'];
|
|
|
+ $id[] = $state;
|
|
|
}
|
|
|
continue;
|
|
|
|
|
@@ -691,26 +702,29 @@ class Buy
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return array(1, $id);
|
|
|
+ return array(1, $type_id, $id);
|
|
|
}
|
|
|
|
|
|
private function factory($order_id, $shop, $factory, $goods)
|
|
|
{
|
|
|
$find = array();
|
|
|
+ $type_id = array();
|
|
|
$id = array();
|
|
|
if (!$factory) {
|
|
|
- return array(1, $id);
|
|
|
+ return array(1, $type_id, $id);
|
|
|
}
|
|
|
+
|
|
|
foreach ($factory as $k => $v) {
|
|
|
$where['factory_id'] = $v['id'];
|
|
|
$where['goods_id'] = $goods['goods_id'];
|
|
|
$where['sku_id'] = ($goods['sku_id'] && $goods['sku_id'] > 0) ? $goods['sku_id'] : -1;
|
|
|
- $sku = Dever::db('factory/goods_sku')->getOne($where);
|
|
|
+ $sku = Dever::db('factory/goods_sku')->select($where);
|
|
|
|
|
|
if ($sku) {
|
|
|
- $state = Dever::load('factory/lib/order')->pay($order_id, $shop['id'], $where['factory_id'], $goods['price'], $goods['num'], $where['goods_id'], $where['sku_id']);
|
|
|
+ $state = Dever::load('factory/lib/order')->pay($order_id, $shop, $where['factory_id'], $goods['price'], $goods['num'], $where['goods_id'], $where['sku_id']);
|
|
|
if ($state) {
|
|
|
- $id[] = $where['factory_id'];
|
|
|
+ $type_id[] = $where['factory_id'];
|
|
|
+ $id[] = $state;
|
|
|
break;
|
|
|
}
|
|
|
} else {
|
|
@@ -718,6 +732,6 @@ class Buy
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return array(2, $id);
|
|
|
+ return array(2, $type_id, $id);
|
|
|
}
|
|
|
}
|