|
@@ -4,72 +4,188 @@
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
|
|
+ * 全部退款,单个商品退货
|
|
*
|
|
*
|
|
-
|
|
|
|
*/
|
|
*/
|
|
|
|
|
|
//use Shopnc\Tpl;
|
|
//use Shopnc\Tpl;
|
|
|
|
|
|
defined('InShopNC') or exit('Access Invalid!');
|
|
defined('InShopNC') or exit('Access Invalid!');
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
class member_refundControl extends mbMemberControl
|
|
class member_refundControl extends mbMemberControl
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+ static private $refund_type = array('1','2');
|
|
public function __construct()
|
|
public function __construct()
|
|
{
|
|
{
|
|
parent::__construct();
|
|
parent::__construct();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 退款接口(全退, 商品,全款全退, 不能指定)
|
|
|
|
|
|
+ * 向商家添加全部退款请求,即付完款后取消订单
|
|
*/
|
|
*/
|
|
|
|
+ public function add_refund_allOp()
|
|
|
|
+ {
|
|
|
|
+ $order_info = Model('order')->getOrderInfo(array('order_sn' => $_GET['order_sn']));
|
|
|
|
+ if (empty($order_info)) {
|
|
|
|
+ return self::outerr(errcode::ErrOrderNotExist);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $model_refund = Model('refund_return');
|
|
|
|
+ $order_id = intval($order_info['order_id']);
|
|
|
|
+ $order = $model_refund->getRightOrderList(array('buyer_id' => $_SESSION['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');//订单状态20:已付款
|
|
|
|
+ $payment_code = $order['payment_code'];//支付方式
|
|
|
|
+ if ($refund['refund_id'] > 0 || $order['order_state'] != $order_paid || $payment_code == 'offline') {//检查订单状态,防止页面刷新不及时造成数据错误
|
|
|
|
+ return self::outerr(errcode::ErrOrderState,"只有付完款尚未发货的时才能退款。");
|
|
|
|
+ }
|
|
|
|
|
|
- public function refundOp()
|
|
|
|
|
|
+ $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'] = $_POST['buyer_message'];
|
|
|
|
+ $refund_array['add_time'] = time();
|
|
|
|
+
|
|
|
|
+ $pic_array = array();
|
|
|
|
+ $pic_array['buyer'] = array();
|
|
|
|
+ $refund_array['pic_info'] = serialize($pic_array);
|
|
|
|
+ $state = $model_refund->addRefundReturn($refund_array,$order);
|
|
|
|
+
|
|
|
|
+ if ($state) {
|
|
|
|
+ $model_refund->editOrderLock($order_id);
|
|
|
|
+ return self::outsuccess(array("ret" => 1));
|
|
|
|
+ } else {
|
|
|
|
+ return self::outerr(errcode::ErrOrderRefundError,"退款失败.");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function refund_one_infoOp()
|
|
{
|
|
{
|
|
$order_info = Model('order')->getOrderInfo(array('order_sn' => $_GET['order_sn']));
|
|
$order_info = Model('order')->getOrderInfo(array('order_sn' => $_GET['order_sn']));
|
|
if (empty($order_info)) {
|
|
if (empty($order_info)) {
|
|
- joutput_error(array("errorMessage" => "订单为空"));
|
|
|
|
- return;
|
|
|
|
|
|
+ return self::outerr(errcode::ErrOrderNotExist);
|
|
|
|
+ }
|
|
|
|
+ $order_id = intval($order_info['order_id']);
|
|
|
|
+ $order_goods_id = intval($_GET['order_goods_id']);//订单商品表编号
|
|
|
|
+ if ($order_id < 1 || $order_goods_id < 1) { //参数验证
|
|
|
|
+ return self::outerr(errcode::ErrParamter,"商品参数错误.");
|
|
}
|
|
}
|
|
|
|
|
|
$model_refund = Model('refund_return');
|
|
$model_refund = Model('refund_return');
|
|
$condition = array();
|
|
$condition = array();
|
|
$reason_list = $model_refund->getReasonList($condition);//退款退货原因
|
|
$reason_list = $model_refund->getReasonList($condition);//退款退货原因
|
|
- $order_id = intval($order_info['order_id']);
|
|
|
|
- $goods_id = intval($_GET['goods_id']);//订单商品表编号(不传参数为全退, 传的话,为退 为指定退商品)
|
|
|
|
- if (strstr($_GET['goods_id'], ',')) {
|
|
|
|
- $goods_id = explode(',', $_GET['goods_id']);
|
|
|
|
|
|
+
|
|
|
|
+ $condition = array();
|
|
|
|
+ $condition['buyer_id'] = $_SESSION['member_id'];
|
|
|
|
+ $condition['order_id'] = $order_id;
|
|
|
|
+ $order = $model_refund->getRightOrderList($condition, $order_goods_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) {
|
|
|
|
+ return self::outerr(errcode::ErrOrderRefundError,"不能重复退货.");
|
|
|
|
+ }
|
|
|
|
+ if($refund_state != 1) {
|
|
|
|
+ return self::outerr(errcode::ErrOrderState,'请确认订单状态,在已经付款后才能退款,已经发货后才能退货.');
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ $goods['goods_image'] = cthumb($goods['goods_image'], 360, $order_info['store_id']);
|
|
|
|
+ $goods['order_goods_id'] = $order_goods_id;
|
|
|
|
+
|
|
|
|
+ return self::outsuccess(array('ret' => 1, 'reason_list' => $reason_list,'goods' => $goods));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function add_refund_oneOp()
|
|
|
|
+ {
|
|
|
|
+ if(!isset($_GET['refund_type']) || empty($_GET['refund_type'])
|
|
|
|
+ || !in_array($_GET['refund_type'],self::$refund_type))
|
|
|
|
+ {
|
|
|
|
+ return self::outerr(errcode::ErrParamter,"请使用正确的退款类型,1:退款,2:退货.");
|
|
|
|
+ }
|
|
|
|
+ $refund_type = $_GET['refund_type'];
|
|
|
|
+
|
|
|
|
+ $order_info = Model('order')->getOrderInfo(array('order_sn' => $_GET['order_sn']));
|
|
|
|
+ if (empty($order_info)) {
|
|
|
|
+ return self::outerr(errcode::ErrOrderNotExist);
|
|
|
|
+ }
|
|
|
|
+ $order_id = $order_info['order_id'];
|
|
|
|
+ $order_goods_id = intval($_GET['order_goods_id']);//订单商品表编号
|
|
|
|
+ if ($order_id < 1 || $order_goods_id < 1) { //参数验证
|
|
|
|
+ return self::outerr(errcode::ErrParamter,"商品参数错误.");
|
|
|
|
+ }
|
|
|
|
+ $buyer_msg = isset($_GET['buyer_msg']) ? $_GET['buyer_msg'] : '';
|
|
|
|
+
|
|
|
|
+ $model_refund = Model('refund_return');
|
|
|
|
+
|
|
|
|
+ $reason_list = $model_refund->getReasonList();//退款退货原因
|
|
|
|
+ $reason_id = intval($_POST['reason_id']);//退货退款原因
|
|
|
|
+ $reson_info = '其他';
|
|
|
|
+ if (!empty($reason_list[$reason_id])) {
|
|
|
|
+ $reason_array = $reason_list[$reason_id];
|
|
|
|
+ $reson_info = $reason_array['reason_info'];
|
|
|
|
+ }
|
|
|
|
+ $goods_num = intval($_POST['goods_num']);//退货数量
|
|
|
|
+ $refund_amount = floatval($_POST['refund_amount']);//退款金额
|
|
|
|
+
|
|
|
|
+ ////////////////////////////////////////////////////////////////
|
|
$condition = array();
|
|
$condition = array();
|
|
- $condition['buyer_id'] = $order_info['buyer_id'];
|
|
|
|
- $condition['order_id'] = $order_info['order_id'];
|
|
|
|
- $order = $model_refund->getRightOrderList($condition, 0);
|
|
|
|
|
|
+ $condition['buyer_id'] = $_SESSION['member_id'];
|
|
|
|
+ $condition['order_id'] = $order_id;
|
|
|
|
+ $order = $model_refund->getRightOrderList($condition, $order_goods_id);
|
|
$order_id = $order['order_id'];
|
|
$order_id = $order['order_id'];
|
|
$order_amount = $order['order_amount'];//订单金额
|
|
$order_amount = $order['order_amount'];//订单金额
|
|
$order_refund_amount = $order['refund_amount'];//订单退款金额
|
|
$order_refund_amount = $order['refund_amount'];//订单退款金额
|
|
$goods_list = $order['goods_list'];
|
|
$goods_list = $order['goods_list'];
|
|
-
|
|
|
|
$goods = $goods_list[0];
|
|
$goods = $goods_list[0];
|
|
- //$goods_pay_price = $goods['goods_pay_price'];//商品实际成交价
|
|
|
|
- $goods_pay_price = $order_amount; // 默认全退款
|
|
|
|
- $goods_num = 1; // 数量, 默认为1
|
|
|
|
- if (is_array($goods_id))
|
|
|
|
- {// 计算物品数量
|
|
|
|
- $goods_pay_price = 0.0;
|
|
|
|
- $goods_num = count($goods_id);
|
|
|
|
- foreach ($goods_list as $value)
|
|
|
|
- {
|
|
|
|
- $tmp_goods_id = $value['goods_id'];
|
|
|
|
- foreach ($goods_id as $goods_id_value)
|
|
|
|
- {
|
|
|
|
- if (intval($goods_id_value) == intval($tmp_goods_id)) {
|
|
|
|
- $goods_pay_price += floatval($value['goods_pay_price']);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ $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;
|
|
}
|
|
}
|
|
-
|
|
|
|
- $refund_amount = $goods_pay_price;
|
|
|
|
|
|
+
|
|
$goods_id = $goods['rec_id'];
|
|
$goods_id = $goods['rec_id'];
|
|
$condition = array();
|
|
$condition = array();
|
|
$condition['buyer_id'] = $order['buyer_id'];
|
|
$condition['buyer_id'] = $order['buyer_id'];
|
|
@@ -83,43 +199,37 @@ class member_refundControl extends mbMemberControl
|
|
}
|
|
}
|
|
$refund_state = $model_refund->getRefundState($order);//根据订单状态判断是否可以退款退货
|
|
$refund_state = $model_refund->getRefundState($order);//根据订单状态判断是否可以退款退货
|
|
if ($refund['refund_id'] > 0 || $refund_state != 1) {//检查订单状态,防止页面刷新不及时造成数据错误
|
|
if ($refund['refund_id'] > 0 || $refund_state != 1) {//检查订单状态,防止页面刷新不及时造成数据错误
|
|
- joutput_error(array("errorMessage" => "订单状态不正确"));
|
|
|
|
|
|
+ return self::outerr(errcode::ErrOrderState);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
$refund_array = array();
|
|
$refund_array = array();
|
|
- $refund_array['reason_info'] = '';
|
|
|
|
- $reason_id = intval($_GET['reason_id']);//退货退款原因
|
|
|
|
- $refund_array['reason_id'] = $reason_id;
|
|
|
|
- $reason_array = array();
|
|
|
|
- $reason_array['reason_info'] = '其他';
|
|
|
|
- $reason_list[0] = $reason_array;
|
|
|
|
- if (!empty($reason_list[$reason_id])) {
|
|
|
|
- $reason_array = $reason_list[$reason_id];
|
|
|
|
- $refund_array['reason_info'] = $reason_array['reason_info'];
|
|
|
|
|
|
+
|
|
|
|
+ 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;
|
|
}
|
|
}
|
|
|
|
|
|
- $pic_array = array();
|
|
|
|
- $pic_array['buyer'] = '';//$this->upload_pic();//上传凭证
|
|
|
|
- $info = serialize($pic_array);
|
|
|
|
- $refund_array['pic_info'] = $info;
|
|
|
|
|
|
+ $refund_array['reason_info'] = $reson_info;
|
|
|
|
+ $refund_array['reason_id'] = $reason_id;
|
|
|
|
+ $refund_array['pic_info'] = serialize(array('buyer' => array()));
|
|
|
|
|
|
$model_trade = Model('trade');
|
|
$model_trade = Model('trade');
|
|
$order_shipped = $model_trade->getOrderState('order_shipped');//订单状态30:已发货
|
|
$order_shipped = $model_trade->getOrderState('order_shipped');//订单状态30:已发货
|
|
if ($order['order_state'] == $order_shipped) {
|
|
if ($order['order_state'] == $order_shipped) {
|
|
$refund_array['order_lock'] = '2';//锁定类型:1为不用锁定,2为需要锁定
|
|
$refund_array['order_lock'] = '2';//锁定类型:1为不用锁定,2为需要锁定
|
|
}
|
|
}
|
|
- $refund_array['refund_type'] = $_GET['refund_type'];//类型:1为退款,2为退货
|
|
|
|
- $show_url = 'index.php?act=member_return&op=index';
|
|
|
|
- $refund_array['return_type'] = $_GET['return_type'];//退货类型:1为不用退货,2为需要退货
|
|
|
|
|
|
+ $refund_array['refund_type'] = $refund_type;//类型:1为退款,2为退货
|
|
|
|
+ $refund_array['return_type'] = '2';//退货类型:1为不用退货,2为需要退货
|
|
if ($refund_array['refund_type'] != '2') {
|
|
if ($refund_array['refund_type'] != '2') {
|
|
$refund_array['refund_type'] = '1';
|
|
$refund_array['refund_type'] = '1';
|
|
$refund_array['return_type'] = '1';
|
|
$refund_array['return_type'] = '1';
|
|
- $show_url = 'index.php?act=member_refund&op=index';
|
|
|
|
}
|
|
}
|
|
$refund_array['seller_state'] = '1';//状态:1为待审核,2为同意,3为不同意
|
|
$refund_array['seller_state'] = '1';//状态:1为待审核,2为同意,3为不同意
|
|
$refund_array['refund_amount'] = ncPriceFormat($refund_amount);
|
|
$refund_array['refund_amount'] = ncPriceFormat($refund_amount);
|
|
$refund_array['goods_num'] = $goods_num;
|
|
$refund_array['goods_num'] = $goods_num;
|
|
- $refund_array['buyer_message'] = $_GET['buyer_message'];
|
|
|
|
|
|
+ $refund_array['buyer_message'] = $buyer_msg;
|
|
$refund_array['add_time'] = time();
|
|
$refund_array['add_time'] = time();
|
|
$state = $model_refund->addRefundReturn($refund_array,$order,$goods);
|
|
$state = $model_refund->addRefundReturn($refund_array,$order,$goods);
|
|
|
|
|
|
@@ -128,9 +238,9 @@ class member_refundControl extends mbMemberControl
|
|
if ($order['order_state'] == $order_shipped) {
|
|
if ($order['order_state'] == $order_shipped) {
|
|
$model_refund->editOrderLock($order_id);
|
|
$model_refund->editOrderLock($order_id);
|
|
}
|
|
}
|
|
- joutput_data(array("errorMessage" => ""));
|
|
|
|
|
|
+ return self::outsuccess(array('ret' => 1));
|
|
} else {
|
|
} else {
|
|
- joutput_error(array("errorMessage" => "更新退款退货记录失败"));
|
|
|
|
|
|
+ return self::outerr(errcode::ErrOrderRefundError,"退货失败.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|