|
@@ -8,6 +8,10 @@ use Dever;
|
|
|
|
|
|
class Buy
|
|
|
{
|
|
|
+
|
|
|
+ public $type = 1;
|
|
|
+
|
|
|
+ public $view = 1;
|
|
|
|
|
|
public $config = array();
|
|
|
|
|
@@ -18,6 +22,16 @@ class Buy
|
|
|
$this->config = Dever::db($this->table)->config;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public function set($type, $view)
|
|
|
+ {
|
|
|
+ $this->type = $type;
|
|
|
+ $this->view = $view;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
public function where($id)
|
|
|
{
|
|
@@ -68,7 +82,7 @@ class Buy
|
|
|
array('value' => 4, 'name' => '待收货确认'),
|
|
|
array('value' => 5, 'name' => '已完成'),
|
|
|
array('value' => 6, 'name' => '已完成(有退款)'),
|
|
|
- array('value' => '7,8,9', 'name' => '已取消'),
|
|
|
+ array('value' => '7,8,11', 'name' => '已取消'),
|
|
|
);
|
|
|
|
|
|
return $result;
|
|
@@ -93,6 +107,16 @@ class Buy
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public function getRefund($id, $order_id)
|
|
|
+ {
|
|
|
+ $data = $this->getView($id, $order_id, false);
|
|
|
+
|
|
|
+ $data['refund'] = Dever::db('shop/buy_order_refund')->select(array('order_id' => $info['id']));
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public function getInfo($info, $view = false)
|
|
|
{
|
|
@@ -117,15 +141,13 @@ class Buy
|
|
|
$info['shop'] = Dever::db('shop/info')->getOne($info['shop_id']);
|
|
|
$info['cdate'] = date('Y-m-d H:i', $info['cdate']);
|
|
|
|
|
|
- $info['tui'] = Dever::db('shop/buy_order_tui')->find(array('order_id' => $info['id'], 'order_goods_id' => -1));
|
|
|
-
|
|
|
$goods_status = Dever::db('shop/buy_order_goods')->config['status'];
|
|
|
+ $goods_process = Dever::db('shop/buy_order_refund')->config['process'];
|
|
|
if ($view) {
|
|
|
foreach ($info['goods'] as $k => $v) {
|
|
|
$info['goods'][$k]['info'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
|
|
|
$info['goods'][$k]['status_name'] = $goods_status[$v['status']];
|
|
|
|
|
|
- $info['goods'][$k]['tui'] = Dever::db('shop/buy_order_tui')->find(array('order_id' => $info['id'], 'order_goods_id' => $v['id']));
|
|
|
}
|
|
|
} else {
|
|
|
foreach ($info['goods'] as $k => $v) {
|
|
@@ -133,11 +155,13 @@ class Buy
|
|
|
$info['goods'][$k]['name'] = $goods['name'];
|
|
|
$info['goods'][$k]['cover'] = $goods['cover'];
|
|
|
$info['goods'][$k]['status_name'] = $goods_status[$v['status']];
|
|
|
-
|
|
|
- $info['goods'][$k]['tui'] = Dever::db('shop/buy_order_tui')->find(array('order_id' => $info['id'], 'order_goods_id' => $v['id']));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if (!$info['refund_cash']) {
|
|
|
+ $info['refund_cash'] = 0;
|
|
|
+ }
|
|
|
+
|
|
|
if ($info['fdate']) {
|
|
|
$info['fdate'] = date('Y-m-d H:i', $info['fdate']);
|
|
|
}
|
|
@@ -147,6 +171,9 @@ class Buy
|
|
|
if ($info['operdate']) {
|
|
|
$info['operdate'] = date('Y-m-d H:i', $info['operdate']);
|
|
|
}
|
|
|
+ if ($info['shdate']) {
|
|
|
+ $info['shdate'] = date('Y-m-d H:i', $info['shdate']);
|
|
|
+ }
|
|
|
|
|
|
return $info;
|
|
|
}
|
|
@@ -325,76 +352,63 @@ class Buy
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public function cancel($id, $order_id)
|
|
|
+
|
|
|
+ public function finish($id, $order_id)
|
|
|
{
|
|
|
$data = $this->getView($id, $order_id, false);
|
|
|
- if ($data['status'] == 1) {
|
|
|
- $state = Dever::db('shop/buy_order')->update(array('where_id' => $data['id'], 'status' => 7, 'operdate' => time()));
|
|
|
+ if ($data['status'] <= 4) {
|
|
|
+ if ($data['refund_cash'] > 0) {
|
|
|
+ $status = 6;
|
|
|
+ } else {
|
|
|
+ $status = 5;
|
|
|
+ }
|
|
|
+ $state = Dever::db('shop/buy_order')->update(array('where_id' => $data['id'], 'status' => $status, 'qsdate' => time()));
|
|
|
if ($state) {
|
|
|
-
|
|
|
+
|
|
|
+ $where['order_id'] = $data['id'];
|
|
|
+ $where['status'] = 1;
|
|
|
+ $data = Dever::db('shop/buy_order_goods')->select($where);
|
|
|
+ if ($data) {
|
|
|
+ Dever::load('shop/lib/goods')->oper(1, 1, $data);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return 'ok';
|
|
|
} else {
|
|
|
- Dever::alert('当前订单状态不允许取消');
|
|
|
+ Dever::alert('您没有权限');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public function tui_yes_api()
|
|
|
+
|
|
|
+ public function cancel($id, $order_id)
|
|
|
{
|
|
|
- $id = Dever::input('id');
|
|
|
- $process = Dever::input('process', 3);
|
|
|
- $info = Dever::db('shop/buy_order_tui')->find($id);
|
|
|
-
|
|
|
- if ($info && $info['process'] == 1) {
|
|
|
- $update['process'] = $process;
|
|
|
- $update['where_id'] = $info['id'];
|
|
|
- $state = Dever::db('shop/buy_order_tui')->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_tui($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_tui($state, $data, $info['cash']);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ $data = $this->getView($id, $order_id, false);
|
|
|
+ if ($data['status'] == 1) {
|
|
|
+ $state = Dever::db('shop/buy_order')->update(array('where_id' => $data['id'], 'status' => 7, 'operdate' => time()));
|
|
|
+ return 'ok';
|
|
|
+ } else {
|
|
|
+ Dever::alert('当前订单状态不允许取消');
|
|
|
}
|
|
|
-
|
|
|
- return 'ok';
|
|
|
}
|
|
|
|
|
|
|
|
|
- public function fahuo_api()
|
|
|
+ public function send_api()
|
|
|
{
|
|
|
$id = Dever::input('id');
|
|
|
$process = Dever::input('process', 3);
|
|
|
- $info = Dever::db('shop/buy_order_tui')->find($id);
|
|
|
+ $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_tui')->update($update);
|
|
|
+ $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_tui($state, $data, $info['cash']);
|
|
|
+ $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));
|
|
@@ -404,7 +418,7 @@ class Buy
|
|
|
} else {
|
|
|
|
|
|
$state = Dever::db('shop/buy_order')->update(array('where_id' => $info['order_id'], 'status' => 8));
|
|
|
- $this->pay_tui($state, $data, $info['cash']);
|
|
|
+ $this->pay_refund($state, $data, $info['cash']);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -413,107 +427,13 @@ class Buy
|
|
|
return 'ok';
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public function tui_action($shop_id, $order_id, $order_goods_id, $status, $price, $num = false, $desc = '', $pic = '')
|
|
|
- {
|
|
|
- $data['shop_id'] = $shop_id;
|
|
|
- $data['order_id'] = $order_id;
|
|
|
- $data['order_goods_id'] = $order_goods_id;
|
|
|
- $info = Dever::db('shop/buy_order_tui')->find($data);
|
|
|
-
|
|
|
- $data['status'] = $status;
|
|
|
- $data['cash'] = $price;
|
|
|
- if ($num) {
|
|
|
- $data['num'] = $num;
|
|
|
- }
|
|
|
- $data['desc'] = $desc;
|
|
|
- $data['pic'] = $pic;
|
|
|
-
|
|
|
- if ($info) {
|
|
|
- $data['where_id'] = $info['id'];
|
|
|
- $data['process'] = 1;
|
|
|
- return Dever::db('shop/buy_order_tui')->update($data);
|
|
|
- } else {
|
|
|
-
|
|
|
- return Dever::db('shop/buy_order_tui')->insert($data);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public function tui($id, $order_id, $status = 1, $desc = '', $pic = '')
|
|
|
- {
|
|
|
- if ($status != 1 && $status != 2) {
|
|
|
- Dever::alert('当前订单状态不允许退货退款');
|
|
|
- }
|
|
|
-
|
|
|
- $data = $this->getView($id, $order_id, false);
|
|
|
- if ($data['status'] == 2) {
|
|
|
-
|
|
|
- $state = $this->tui_action($data['shop_id'], $data['id'], -1, $status, $data['price'], false, $desc, $pic);
|
|
|
-
|
|
|
- return 'ok';
|
|
|
- } else {
|
|
|
- Dever::alert('当前订单状态不允许退货退款');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public function tui_one_info($id, $order_id, $order_goods_id)
|
|
|
- {
|
|
|
- $data = $this->getView($id, $order_id, false);
|
|
|
- if ($data['status'] == 4) {
|
|
|
- $info = Dever::db('shop/buy_order_goods')->find(array('id' => $order_goods_id, 'order_id' => $data['id'], 'shop_id' => $id));
|
|
|
- if ($info && $info['status'] <= 4) {
|
|
|
- $info['tui_price'] = $info['price'];
|
|
|
- $info['tui_one_price'] = round($info['tui_price'] / $info['num'], 2);
|
|
|
- $info['goods'] = Dever::db('goods/info')->find($info['goods_id']);
|
|
|
- }
|
|
|
- return $info;
|
|
|
- } else {
|
|
|
- Dever::alert('当前订单状态不允许退货退款');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public function tui_one($id, $order_id, $order_goods_id, $num = false, $status = 6, $desc = '', $pic = '')
|
|
|
- {
|
|
|
- if ($status != 5 && $status != 6) {
|
|
|
- Dever::alert('当前订单状态不允许退货退款');
|
|
|
- }
|
|
|
-
|
|
|
- $data = $this->getView($id, $order_id, false);
|
|
|
- if ($data['status'] == 4 || $data['status'] == 5) {
|
|
|
- $info = Dever::db('shop/buy_order_goods')->find(array('id' => $order_goods_id, 'order_id' => $data['id'], 'shop_id' => $id));
|
|
|
- if ($info && $info['status'] <= 4) {
|
|
|
- $info['price'] = $info['price'];
|
|
|
- if ($num > 0 && $info['num'] >= $num) {
|
|
|
- $price = round($info['price'] / $info['num'], 2);
|
|
|
- $info['price'] = round($price * $num, 2);
|
|
|
- }
|
|
|
-
|
|
|
- $state = $this->tui_action($data['shop_id'], $data['id'], $order_goods_id, $status, $info['price'], $num, $desc, $pic);
|
|
|
- } else {
|
|
|
- Dever::alert('当前订单状态不允许退货退款');
|
|
|
- }
|
|
|
- return 'ok';
|
|
|
- } else {
|
|
|
- Dever::alert('当前订单状态不允许退货退款');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public function pay_tui($state, $data, $price)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
public function orderStatus($id)
|
|
|
{
|
|
|
$config = Dever::db('shop/buy_order')->config;
|
|
|
|
|
|
$info = Dever::db('shop/buy_order')->one($id);
|
|
|
- $tk = Dever::db('shop/buy_order_tui')->find(array('order_id' => $info['id'], 'process' => 1));
|
|
|
+ $tk = Dever::db('shop/buy_order_refund')->find(array('order_id' => $info['id'], 'process' => 1));
|
|
|
$status = $config['status'][$info['status']];
|
|
|
|
|
|
if ($tk) {
|
|
@@ -522,6 +442,14 @@ class Buy
|
|
|
return $status;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public function refund_api()
|
|
|
+ {
|
|
|
+ $id = Dever::input('id');
|
|
|
+ $process = Dever::input('process');
|
|
|
+ return Dever::load('shop/lib/refund')->set('buy')->action($id, $process, false);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public function show()
|
|
|
{
|
|
@@ -533,12 +461,12 @@ class Buy
|
|
|
|
|
|
$shop = Dever::db('shop/info')->find($info['shop_id']);
|
|
|
|
|
|
- $tk_status = Dever::db('shop/buy_order_tui')->config['status'];
|
|
|
- $tk_process = Dever::db('shop/buy_order_tui')->config['process'];
|
|
|
+ $tk_status = Dever::db('shop/buy_order_refund')->config['status'];
|
|
|
+ $tk_process = Dever::db('shop/buy_order_refund')->config['process'];
|
|
|
|
|
|
$status = $config['status'][$info['status']];
|
|
|
|
|
|
- $tk = Dever::db('shop/buy_order_tui')->find(array('order_id' => $info['id'], 'order_goods_id' => -1));
|
|
|
+ $tk = Dever::db('shop/buy_order_refund')->find(array('order_id' => $info['id'], 'type' => 1));
|
|
|
|
|
|
$html = '[基本信息]:<table class="layui-table"><thead><tr><th style="width:20%">项目</th><th style="width:80%">详情</th></tr> </thead><tbody>';
|
|
|
|
|
@@ -554,7 +482,7 @@ class Buy
|
|
|
|
|
|
</tr>';
|
|
|
|
|
|
- $url = Dever::url('lib/buy.tui_yes', 'mshop');
|
|
|
+ $url = Dever::url('lib/buy.refund', 'mshop');
|
|
|
|
|
|
if ($tk && $tk['process'] == 1) {
|
|
|
$status = '申请' . $tk_status[$tk['status']];
|
|
@@ -566,12 +494,12 @@ class Buy
|
|
|
}
|
|
|
$html .= '<tr>
|
|
|
<td>订单信息</td>
|
|
|
- <td>'.$this->table(array('金额', '数量', '订单状态', '审核状态'), array(array($info['price'], $info['num'], $status, $process))).'</td>
|
|
|
+ <td>'.$this->table(array('金额', '退款金额', '数量', '订单状态', '审核状态'), array(array($info['price'], $info['refund_cash'], $info['num'], $status, $process))).'</td>
|
|
|
</tr>';
|
|
|
} else {
|
|
|
$html .= '<tr>
|
|
|
<td>订单信息</td>
|
|
|
- <td>'.$this->table(array('金额', '数量', '订单状态'), array(array($info['price'], $info['num'], $status))).'</td>
|
|
|
+ <td>'.$this->table(array('金额', '退款金额', '数量', '订单状态'), array(array($info['price'], $info['refund_cash'], $info['num'], $status))).'</td>
|
|
|
</tr>';
|
|
|
}
|
|
|
|
|
@@ -590,7 +518,7 @@ class Buy
|
|
|
foreach ($goods as $k => $v) {
|
|
|
$goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
|
|
|
$status = $goods_status[$v['status']];
|
|
|
- $tk = Dever::db('shop/buy_order_tui')->find(array('order_id' => $info['id'], 'order_goods_id' => $v['id']));
|
|
|
+ $tk = Dever::db('shop/buy_order_refund')->find(array('order_id' => $info['id'], 'order_goods_id' => $v['id'], 'type' => 2));
|
|
|
if ($tk && $tk['process'] == 1) {
|
|
|
$status = '申请' . $tk_status[$tk['status']];
|
|
|
|