|
@@ -0,0 +1,140 @@
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ * 会员退款退货
|
|
|
+ *
|
|
|
+ *
|
|
|
+ *
|
|
|
+ *
|
|
|
+
|
|
|
+ */
|
|
|
+
|
|
|
+//use Shopnc\Tpl;
|
|
|
+
|
|
|
+defined('InShopNC') or exit('Access Invalid!');
|
|
|
+
|
|
|
+class member_refundControl extends mbMemberControl
|
|
|
+{
|
|
|
+
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ parent::__construct();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * 退款接口(全退, 商品,全款全退, 不能指定)
|
|
|
+ */
|
|
|
+ public function refundOp()
|
|
|
+ {
|
|
|
+ // 登录验证
|
|
|
+ // $token = trim($_GET['key']);
|
|
|
+ // if (false == $this->checkToken($token)) {
|
|
|
+ // return joutput_error($this->err_code);
|
|
|
+ // }
|
|
|
+
|
|
|
+ $order_info = Model('order')->getOrderInfo(array('order_sn' => $_GET['order_sn']));
|
|
|
+ if (empty($order_info)) {
|
|
|
+ joutput_error(array("errorMessage" => "订单为空"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $model_refund = Model('refund_return');
|
|
|
+ $condition = array();
|
|
|
+ $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'] = $order_info['buyer_id'];
|
|
|
+ $condition['order_id'] = $order_info['order_id'];
|
|
|
+ $order = $model_refund->getRightOrderList($condition, 0);
|
|
|
+ $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'];//商品实际成交价
|
|
|
+ $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']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $refund_amount = $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) {//检查订单状态,防止页面刷新不及时造成数据错误
|
|
|
+ joutput_error(array("errorMessage" => "订单状态不正确"));
|
|
|
+ }
|
|
|
+
|
|
|
+ $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'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $pic_array = array();
|
|
|
+ $pic_array['buyer'] = '';//$this->upload_pic();//上传凭证
|
|
|
+ $info = serialize($pic_array);
|
|
|
+ $refund_array['pic_info'] = $info;
|
|
|
+
|
|
|
+ $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'] = $_GET['refund_type'];//类型:1为退款,2为退货
|
|
|
+ $show_url = 'index.php?act=member_return&op=index';
|
|
|
+ $refund_array['return_type'] = $_GET['return_type'];//退货类型:1为不用退货,2为需要退货
|
|
|
+ if ($refund_array['refund_type'] != '2') {
|
|
|
+ $refund_array['refund_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['refund_amount'] = ncPriceFormat($refund_amount);
|
|
|
+ $refund_array['goods_num'] = $goods_num;
|
|
|
+ $refund_array['buyer_message'] = $_GET['buyer_message'];
|
|
|
+ $refund_array['add_time'] = time();
|
|
|
+ $state = $model_refund->addRefundReturn($refund_array,$order,$goods);
|
|
|
+
|
|
|
+ if ($state) {
|
|
|
+ if ($order['order_state'] == $order_shipped) {
|
|
|
+ $model_refund->editOrderLock($order_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ joutput_data(array("errorMessage" => ""));
|
|
|
+ } else {
|
|
|
+ joutput_error(array("errorMessage" => "更新退款退货记录失败"));
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|