|
@@ -8,6 +8,244 @@
|
|
|
*/
|
|
|
require_once (BASE_ROOT_PATH . '/helper/goods_helper.php');
|
|
|
|
|
|
+class refund_helper
|
|
|
+{
|
|
|
+ private $member_id;
|
|
|
+ public function __construct($member_id)
|
|
|
+ {
|
|
|
+ $this->member_id = intval($member_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function list_all()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function refund($order_sn,&$err)
|
|
|
+ {
|
|
|
+ $order_info = Model('order')->getOrderInfo(array('order_sn' => $order_sn));
|
|
|
+ if (empty($order_info)) {
|
|
|
+ $err = array("code" => errcode::ErrOrderNotExist,'msg' => errcode::msg(errcode::ErrOrderNotExist));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $model_refund = Model('refund_return');
|
|
|
+ $order_id = intval($order_info['order_id']);
|
|
|
+ $order = $model_refund->getRightOrderList(array('buyer_id' => $this->member_id, 'order_id' => $order_id));
|
|
|
+
|
|
|
+ $order_amount = $order['order_amount'];//订单金额
|
|
|
+ $condition = array();
|
|
|
+ {
|
|
|
+ $condition['buyer_id'] = $order['buyer_id'];
|
|
|
+ $condition['order_id'] = $order['order_id'];
|
|
|
+ $condition['goods_id'] = '0';
|
|
|
+ $condition['seller_state'] = array('lt', '3'); //状态:1为待审核,2为同意,3为不同意
|
|
|
+ }
|
|
|
+
|
|
|
+ $refund_list = $model_refund->getRefundReturnList($condition);
|
|
|
+ $refund = array();
|
|
|
+ if (!empty($refund_list) && is_array($refund_list)) {
|
|
|
+ $refund = $refund_list[0];
|
|
|
+ }
|
|
|
+ $model_trade = Model('trade');
|
|
|
+ $order_paid = $model_trade->getOrderState('order_paid');
|
|
|
+ $payment_code = $order['payment_code'];
|
|
|
+ if ($refund['refund_id'] > 0 || $order['order_state'] != $order_paid || $payment_code == 'offline') {
|
|
|
+ $err = array("code" => errcode::ErrOrderNotExist,'msg' => "只有付完款尚未发货的时才能退款。");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $refund_array = array();
|
|
|
+ $refund_array['refund_type'] = '1'; //类型:1为退款,2为退货
|
|
|
+ $refund_array['seller_state'] = '1';//状态:1为待审核,2为同意,3为不同意
|
|
|
+ $refund_array['order_lock'] = '2'; //锁定类型:1为不用锁定,2为需要锁定
|
|
|
+ $refund_array['goods_id'] = '0';
|
|
|
+ $refund_array['order_goods_id'] = '0';
|
|
|
+ $refund_array['reason_id'] = '0';
|
|
|
+ $refund_array['reason_info'] = '取消订单,全部退款';
|
|
|
+ $refund_array['goods_name'] = '订单商品全部退款';
|
|
|
+ $refund_array['refund_amount'] = ncPriceFormat($order_amount);
|
|
|
+ $refund_array['buyer_message'] = remove_tags(urldecode($_POST['buyer_message']));
|
|
|
+ $refund_array['add_time'] = time();
|
|
|
+
|
|
|
+ $pic_array = array();
|
|
|
+ $pic_array['buyer'] = array();
|
|
|
+ $refund_array['pic_info'] = serialize($pic_array);
|
|
|
+ $refund_id = $model_refund->addRefundReturn($refund_array, $order);
|
|
|
+
|
|
|
+ return $refund_id;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function reason_list($model_refund)
|
|
|
+ {
|
|
|
+ $condition = array();
|
|
|
+ $reason_data = $model_refund->getReasonList($condition, '', '', 'reason_id,reason_info');
|
|
|
+
|
|
|
+ $reason_list = [];
|
|
|
+ foreach ($reason_data as $data) {
|
|
|
+ $reason_list[] = $data;
|
|
|
+ }
|
|
|
+ $reason_list[] = array('reason_id' => 0, 'reason_info' => '其他');
|
|
|
+
|
|
|
+ return $reason_list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function reason_info($model_refund,$reason_id)
|
|
|
+ {
|
|
|
+ $reason_list = $model_refund->reason_list($model_refund);
|
|
|
+ if (array_key_exists($reason_id,$reason_list)) {
|
|
|
+ return $reason_list[$reason_id];
|
|
|
+ } else {
|
|
|
+ return '其他';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function return_info($order_sn,$rec_id,&$err)
|
|
|
+ {
|
|
|
+ $order_info = Model('order')->getOrderInfo(array('order_sn' => $order_sn));
|
|
|
+ if (empty($order_info)) {
|
|
|
+ $err = array("code" => errcode::ErrOrderNotExist,'msg' => errcode::msg(errcode::ErrOrderNotExist));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $order_id = intval($order_info['order_id']);
|
|
|
+ if ($order_id < 1 || $rec_id < 1) {
|
|
|
+ $err = array("code" => errcode::ErrParamter,'msg' => errcode::msg(errcode::ErrParamter));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $model_refund = Model('refund_return');
|
|
|
+ $reason_list = $this->reason_list($model_refund);
|
|
|
+
|
|
|
+ $condition = array();
|
|
|
+ $condition['buyer_id'] = $this->member_id;
|
|
|
+ $condition['order_id'] = $order_id;
|
|
|
+ $order = $model_refund->getRightOrderList($condition, $rec_id);
|
|
|
+
|
|
|
+ $order_amount = $order['order_amount'];//订单金额
|
|
|
+ $order_refund_amount = $order['refund_amount'];//订单退款金额
|
|
|
+ $goods_list = $order['goods_list'];
|
|
|
+ $goods = $goods_list[0];
|
|
|
+ $goods_pay_price = $goods['goods_pay_price'];//商品实际成交价
|
|
|
+ if ($order_amount < ($goods_pay_price + $order_refund_amount)) {
|
|
|
+ $goods_pay_price = $order_amount - $order_refund_amount;
|
|
|
+ $goods['goods_pay_price'] = $goods_pay_price;
|
|
|
+ }
|
|
|
+
|
|
|
+ $condition = array();
|
|
|
+ $condition['buyer_id'] = $order['buyer_id'];
|
|
|
+ $condition['order_id'] = $order['order_id'];
|
|
|
+ $condition['order_goods_id'] = $rec_id;
|
|
|
+ $condition['seller_state'] = array('lt', '3');
|
|
|
+ $refund_list = $model_refund->getRefundReturnList($condition);
|
|
|
+ $refund = array();
|
|
|
+ if (!empty($refund_list) && is_array($refund_list)) {
|
|
|
+ $refund = $refund_list[0];
|
|
|
+ }
|
|
|
+ $refund_state = $model_refund->getRefundState($order);//根据订单状态判断是否可以退款退货 '申请状态:1为处理中,2为待管理员处理,3为已完成,默认为1',
|
|
|
+
|
|
|
+ if ($refund['refund_id'] > 0) {
|
|
|
+ $err = array("code" => errcode::ErrOrderRefundError,'msg' => "不能重复退货");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($refund_state != 1) {
|
|
|
+ $err = array("code" => errcode::ErrOrderState,'msg' => '请确认订单状态,在已经付款后才能退款,已经发货后才能退货.');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return array('reason_list' => (array)$reason_list, 'goods' => $goods);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function return_goods($order_sn,$rec_id,$goods_num,$refund_amount,$reason_id,$buyer_msg,&$err)
|
|
|
+ {
|
|
|
+ $order_info = Model('order')->getOrderInfo(array('order_sn' => $order_sn));
|
|
|
+ if (empty($order_info) || intval($order_info['order_id'] < 1)) {
|
|
|
+ $err = array("code" => errcode::ErrOrderNotExist,'msg' => errcode::msg(errcode::ErrOrderNotExist));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $order_id = intval($order_info['order_id']);
|
|
|
+
|
|
|
+ $model_refund = Model('refund_return');
|
|
|
+ $reson_info = $this->reason_info($model_refund,$reason_id);
|
|
|
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
+ $condition = array();
|
|
|
+ $condition['buyer_id'] = $this->member_id;
|
|
|
+ $condition['order_id'] = $order_id;
|
|
|
+ $order = $model_refund->getRightOrderList($condition, $rec_id);
|
|
|
+
|
|
|
+ $order_id = $order['order_id'];
|
|
|
+ $order_amount = $order['order_amount'];//订单金额
|
|
|
+ $order_refund_amount = $order['refund_amount'];//订单退款金额
|
|
|
+ $goods_list = $order['goods_list'];
|
|
|
+ $goods = $goods_list[0];
|
|
|
+ $goods_pay_price = $goods['goods_pay_price'];//商品实际成交价
|
|
|
+ if ($order_amount < ($goods_pay_price + $order_refund_amount)) {
|
|
|
+ $goods_pay_price = $order_amount - $order_refund_amount;
|
|
|
+ $goods['goods_pay_price'] = $goods_pay_price;
|
|
|
+ }
|
|
|
+
|
|
|
+ $goods_id = $goods['rec_id'];
|
|
|
+ $condition = array();
|
|
|
+ $condition['buyer_id'] = $order['buyer_id'];
|
|
|
+ $condition['order_id'] = $order['order_id'];
|
|
|
+ $condition['order_goods_id'] = $goods_id;
|
|
|
+ $condition['seller_state'] = array('lt', '3');
|
|
|
+ $refund_list = $model_refund->getRefundReturnList($condition);
|
|
|
+ $refund = array();
|
|
|
+ if (!empty($refund_list) && is_array($refund_list)) {
|
|
|
+ $refund = $refund_list[0];
|
|
|
+ }
|
|
|
+ $refund_state = $model_refund->getRefundState($order);
|
|
|
+ if ($refund['refund_id'] > 0 || $refund_state != 1) {
|
|
|
+ $err = array("code" => errcode::ErrOrderState,'msg' => errcode::msg(errcode::ErrOrderState));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $refund_array = array();
|
|
|
+ if (($refund_amount < 0) || ($refund_amount > $goods_pay_price)) {
|
|
|
+ $refund_amount = $goods_pay_price;
|
|
|
+ }
|
|
|
+ if (($goods_num < 0) || ($goods_num > $goods['goods_num'])) {
|
|
|
+ $goods_num = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ $refund_array['reason_info'] = $reson_info;
|
|
|
+ $refund_array['reason_id'] = $reason_id;
|
|
|
+ $refund_array['pic_info'] = serialize(array('buyer' => array()));
|
|
|
+
|
|
|
+ $model_trade = Model('trade');
|
|
|
+ $order_shipped = $model_trade->getOrderState('order_shipped');//订单状态30:已发货
|
|
|
+ if ($order['order_state'] == $order_shipped) {
|
|
|
+ $refund_array['order_lock'] = '2';//锁定类型:1为不用锁定,2为需要锁定
|
|
|
+ }
|
|
|
+ $refund_array['refund_type'] = 2;//类型:1为退款,2为退货
|
|
|
+ $refund_array['return_type'] = '2';//退货类型:1为不用退货,2为需要退货
|
|
|
+ if ($refund_array['refund_type'] != '2') {
|
|
|
+ $refund_array['refund_type'] = '1';
|
|
|
+ $refund_array['return_type'] = '1';
|
|
|
+ }
|
|
|
+ $refund_array['seller_state'] = '1';//状态:1为待审核,2为同意,3为不同意
|
|
|
+ $refund_array['refund_amount'] = ncPriceFormat($refund_amount);
|
|
|
+ $refund_array['goods_num'] = $goods_num;
|
|
|
+ $refund_array['buyer_message'] = $buyer_msg;
|
|
|
+ $refund_array['add_time'] = time();
|
|
|
+ $refund_id = $model_refund->addRefundReturn($refund_array, $order, $goods);
|
|
|
+
|
|
|
+ if ($refund_id)
|
|
|
+ {
|
|
|
+ if ($order['order_state'] == $order_shipped) {
|
|
|
+ $model_refund->editOrderLock($order_id);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $err = array("code" => errcode::ErrOrderRefundError,'msg' => "退货失败");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
class order_action
|
|
|
{
|
|
|
public function change_state($state_type,$order_id)
|
|
@@ -71,7 +309,6 @@ class order_helper
|
|
|
private $mod_refund;
|
|
|
private $mod_order;
|
|
|
|
|
|
-
|
|
|
public function __construct($order_list)
|
|
|
{
|
|
|
$this->mod_order = Model('order');
|
|
@@ -89,7 +326,6 @@ class order_helper
|
|
|
"if_evaluation" => "评价",
|
|
|
"if_delete" => "删除订单",
|
|
|
"if_lock" => "退款退货中");
|
|
|
-// "if_refund_return" => "退货");
|
|
|
return $actions[$key];
|
|
|
}
|
|
|
|
|
@@ -108,8 +344,6 @@ class order_helper
|
|
|
$state['if_evaluation'] = $this->mod_order->getOrderOperateState('evaluation', $order);
|
|
|
//显示删除
|
|
|
$state['if_delete'] = $this->mod_order->getOrderOperateState('delete', $order);
|
|
|
-// //订单是否能退货
|
|
|
-// $state['if_refund_return'] = $this->mod_refund->getRefundState($order) == '0' ? false : true;
|
|
|
|
|
|
$state['if_lock'] = $this->mod_order->getOrderOperateState('lock', $order);
|
|
|
|
|
@@ -124,6 +358,7 @@ class order_helper
|
|
|
|
|
|
return $actions;
|
|
|
}
|
|
|
+
|
|
|
private function order_info($order)
|
|
|
{
|
|
|
$result["order_id"] = intval($order["order_id"]);
|
|
@@ -209,4 +444,4 @@ class order_helper
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
-}
|
|
|
+}
|