|
@@ -52,7 +52,7 @@ class Refund
|
|
|
}
|
|
|
|
|
|
|
|
|
- public function up($order_id, $order_goods_id, $status, $price, $num = false, $desc = '', $pic = '', $process = 1)
|
|
|
+ public function up($order_id, $order_goods_id, $status, $price, $p_price, $num = false, $desc = '', $pic = '', $process = 1)
|
|
|
{
|
|
|
$data['order_id'] = $order_id;
|
|
|
if (!$order_goods_id) {
|
|
@@ -70,6 +70,10 @@ class Refund
|
|
|
|
|
|
$data['status'] = $status;
|
|
|
$data['cash'] = $price;
|
|
|
+ if ($p_price && $p_price > 0) {
|
|
|
+ $data['p_cash'] = $p_price;
|
|
|
+ }
|
|
|
+
|
|
|
if ($num) {
|
|
|
$data['num'] = $num;
|
|
|
}
|
|
@@ -80,6 +84,7 @@ class Refund
|
|
|
$data['where_id'] = $info['id'];
|
|
|
$state = Dever::db($this->refund_table)->update($data);
|
|
|
if ($state) {
|
|
|
+ $data['id'] = $info['id'];
|
|
|
return $data;
|
|
|
}
|
|
|
} else {
|
|
@@ -120,8 +125,10 @@ class Refund
|
|
|
Dever::db($this->goods_table)->update(array('where_id' => $info['id'], 'status' => 2));
|
|
|
if (isset($info['coupon_cash']) && $info['coupon_cash']) {
|
|
|
$cash = $info['price'] - $info['coupon_cash'];
|
|
|
+ $p_cash = 0;
|
|
|
} else {
|
|
|
$cash = $info['price'];
|
|
|
+ $p_cash = $info['p_price'];
|
|
|
}
|
|
|
if ($num > 0) {
|
|
|
$dec = $num;
|
|
@@ -133,17 +140,30 @@ class Refund
|
|
|
$dec = $info['num'];
|
|
|
$price = round($cash / $info['num'], 2);
|
|
|
$cash = round($price * $num, 2);
|
|
|
+
|
|
|
+ if ($p_cash > 0) {
|
|
|
+ $price = round($p_cash / $info['num'], 2);
|
|
|
+ $p_cash = round($price * $num, 2);
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
Dever::alert('您没有权限操作');
|
|
|
}
|
|
|
} else {
|
|
|
$cash = $data['price'] - $data['refund_cash'];
|
|
|
+ if (isset($data['refund_p_cash'])) {
|
|
|
+ $p_cash = $data['p_price'] - $data['refund_p_cash'];
|
|
|
+ } else {
|
|
|
+ $p_cash = 0;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if ($cash > 0) {
|
|
|
- $log = $this->up($data['id'], $order_goods_id, $status, $cash, $dec, $desc, $pic, $process);
|
|
|
+ $log = $this->up($data['id'], $order_goods_id, $status, $cash, $p_cash, $dec, $desc, $pic, $process);
|
|
|
|
|
|
+ if (!$log) {
|
|
|
+ Dever::alert('退款失败');
|
|
|
+ }
|
|
|
if ($this->type == 'buy') {
|
|
|
|
|
|
if ($data['status'] == 5 || $data['status'] == 6) {
|
|
@@ -151,8 +171,10 @@ class Refund
|
|
|
Dever::load('shop/lib/goods')->oper($data, 2, 1, $oper_data);
|
|
|
}
|
|
|
|
|
|
- if ($data['type'] == 1) {
|
|
|
- Dever::load('cash/lib/shop')->up($data, 2, 1, 1, 2);
|
|
|
+ if ($data['source_id'] && $data['source_id'] > 0) {
|
|
|
+ Dever::load('cash/lib/order')->up($data, 2, 1, $log['id']);
|
|
|
+ } else {
|
|
|
+ Dever::load('cash/lib/order')->up($data, 1, 3);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -169,9 +191,12 @@ class Refund
|
|
|
$update = array();
|
|
|
$update['where_id'] = $data['id'];
|
|
|
$update['refund_cash'] = $data['refund_cash'] + $cash;
|
|
|
+ if (isset($data['refund_p_cash'])) {
|
|
|
+ $update['refund_p_cash'] = $data['refund_p_cash'] + $cash;
|
|
|
+ }
|
|
|
$update['refund_status'] = 2;
|
|
|
if ($dec > 0) {
|
|
|
- $update['num'] = $data['num'] - $dec;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
Dever::db($this->order_table)->update($update);
|
|
@@ -216,9 +241,12 @@ class Refund
|
|
|
$update = array();
|
|
|
if ($process == 3) {
|
|
|
if ($info['num'] && $info['num'] > 0) {
|
|
|
- $update['num'] = $order['num'] + $info['num'];
|
|
|
+
|
|
|
}
|
|
|
$update['refund_cash'] = $order['refund_cash'] - $info['cash'];
|
|
|
+ if (isset($order['refund_p_cash'])) {
|
|
|
+ $update['refund_p_cash'] = $order['refund_p_cash'] - $info['p_cash'];
|
|
|
+ }
|
|
|
$update['where_id'] = $order['id'];
|
|
|
if ($update['refund_cash'] <= 0) {
|
|
|
$update['refund_status'] = 1;
|
|
@@ -230,8 +258,8 @@ class Refund
|
|
|
Dever::db($this->goods_table)->update(array('where_id' => $info['order_goods_id'], 'status' => 1));
|
|
|
}
|
|
|
|
|
|
- if ($cash && $this->type == 'buy' && $order['type'] == 1) {
|
|
|
- Dever::load('cash/lib/shop')->up($order, 2, 1, 3, 2);
|
|
|
+ if ($cash && $this->type == 'buy' && $order['source_id'] && $order['source_id'] > 0) {
|
|
|
+ Dever::load('cash/lib/order')->up($order, 2, 3, $info['id']);
|
|
|
}
|
|
|
} else {
|
|
|
if ($info['type'] == 2) {
|
|
@@ -267,8 +295,8 @@ class Refund
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if ($cash && $this->type == 'buy' && $order['type'] == 1) {
|
|
|
- Dever::load('cash/lib/shop')->up($order, 2, 2, 2, 2);
|
|
|
+ if ($cash && $this->type == 'buy' && $order['source_id'] && $order['source_id'] > 0) {
|
|
|
+ Dever::load('cash/lib/order')->up($order, 2, 2, $info['id']);
|
|
|
}
|
|
|
}
|
|
|
|