Browse Source

增加售前退款,自动取消订单流程

stanley-king 6 years ago
parent
commit
ba4304be99

+ 62 - 2
data/logic/delivery.logic.php

@@ -15,7 +15,7 @@ require_once (BASE_CORE_PATH . '/framework/function/http.php');
 class deliveryLogic
 {
     const oms_url = 'https://oapi.lrlz.com/lrlzApiRest/router/rest';
-    //const oms_url = 'http://oapitest.lrlz.com/lrlzApiRest/router/rest';
+//    const oms_url = 'http://oapitest.lrlz.com/lrlzApiRest/router/rest';
 
 
     private static $appkey = '2015panda';
@@ -166,7 +166,7 @@ class deliveryLogic
         return $result;
     }
 
-    public function cancel_oms($order_sn)
+    public function cancel_order($order_sn)
     {
         $param = array('type' => 'TRADE_INTERCEPT','data' => array('tids' => $order_sn,'remark' => '用户退款'));
         $body = json_encode($param,JSON_UNESCAPED_UNICODE);
@@ -183,6 +183,66 @@ class deliveryLogic
         return true;
     }
 
+    const CANCEL_SUCCESS = 99;
+    public function query_order($order_sn)
+    {
+        $param = array('type' => 'TIDS_TRADE_STATUTS','data' => array('tids' => $order_sn,'remark' => '订单查询'));
+        $body = json_encode($param,JSON_UNESCAPED_UNICODE);
+        $sign = $this->sign($body);
+        $headers = array('v_appkey: '.self::$appkey, 'v_sign: '.$sign, 'Content-Type: application/json');
+        $resp = http_post_data(self::oms_url,urlencode($body),$headers);
+
+        if($resp === false) {
+            Log::record(__METHOD__ . " NET Error",Log::ERR);
+            return false;
+        }
+        else {
+            Log::record($resp,Log::DEBUG);
+            return $this->order_status($resp,$err_state,$reson);
+        }
+    }
+
+    public function cancel_status($order_sn)
+    {
+        $status = $this->query_order($order_sn);
+        if($status == self::CANCEL_SUCCESS) {
+            return true;
+        }
+        else {
+            return false;
+        }
+    }
+
+    private function order_status($resp,&$err_state,&$reson)
+    {
+        $err_state = 0;
+
+        //1:成功 0 :失败
+        // 1:新订单 2:等待仓库处理 99:已拦截 90:库存不足 7:已发货
+        // -99:发货失败 -2:订单关闭 -3:订单已存在(没有进行拦截的订单不予更新) -1:异常订单 -2:订单关闭
+        $result = json_decode($resp, true);
+        if (!empty($result) && is_array($result))
+        {
+            if ($result['apiCode'] == 'success')
+            {
+                if (!empty($result['data']) && is_array($result['data']) && count($result['data']) > 0)
+                {
+                    // 填充错误理由
+                    $reson = $result['data'][0]['errorMessge'];
+                    if (!empty($result['data'][0]['status'])) {
+                        $status = intval($result['data'][0]['status']);
+                        return $status;
+                    } else {
+                        return false;
+                    }
+                }
+            }
+        }
+
+        return false;
+    }
+
+
     /**
      * @param $pay_sn
      * @param $trade_no

+ 14 - 4
data/model/refund_return.model.php

@@ -130,7 +130,6 @@ class refund_returnModel extends Model
             return false;
         }
     }
-
     /**
      * 平台确认退款处理
      *
@@ -140,10 +139,11 @@ class refund_returnModel extends Model
     public function editOrderRefund($refund)
     {
         $refund_id = intval($refund['refund_id']);
-        if ($refund_id > 0) {
+        if ($refund_id > 0)
+        {
             Language::read('model_lang_index');
             $order_id = $refund['order_id'];//订单编号
-            $field = 'order_id,buyer_id,buyer_name,store_id,order_sn,order_amount,payment_code,order_state,refund_amount,rcb_amount';
+            $field = 'order_id,buyer_id,buyer_name,store_id,order_sn,order_amount,payment_code,order_state,refund_amount,rcb_amount,bonus_amount';
             $model_order = Model('order');
             $order = $model_order->getOrderInfo(array('order_id' => $order_id), array(), $field);
 
@@ -154,7 +154,12 @@ class refund_returnModel extends Model
 
                 $order_amount = $order['order_amount'];//订单金额
                 $rcb_amount = $order['rcb_amount'];//充值卡支付金额
-                $predeposit_amount = $order_amount - $order['refund_amount'] - $rcb_amount;//可退预存款金额
+                $bonus_amount = unserialize($order['bonus_amount']);
+                $user_bonus = floatval($bonus_amount['user_bonus']);
+                $room_bonus = floatval($bonus_amount['room_bonus']);
+                $bonus_amount = $user_bonus + $room_bonus;
+
+                $predeposit_amount = $order_amount - $order['refund_amount'] - $rcb_amount - $bonus_amount;//可退预存款金额
 
                 if (($rcb_amount > 0) && ($refund['refund_amount'] > $predeposit_amount)) {//退充值卡
                     $log_array = array();
@@ -199,6 +204,11 @@ class refund_returnModel extends Model
                     $state = $this->editOrderUnlock($order_id);//订单解锁
                 }
                 $trans->commit();
+
+                if($user_bonus > 0) {
+                    QueueClient::push('onPredeposit',['change_type' => 'bonus_refund','buyer_id' => $order['buyer_id'],'order_sn' => $order['order_sn']]);
+                }
+
                 return $state;
             } catch (Exception $e) {
                 $trans->rollback();

+ 0 - 1
helper/account_helper.php

@@ -280,7 +280,6 @@ class account_helper
 
     public static function onPredeposit($change_type,$member_id,$sn)
     {
-
         if($change_type == 'order_cancel')
         {
             //发送给该用户一个同等额度的红包

+ 6 - 1
helper/order_helper.php

@@ -278,8 +278,13 @@ class refund_helper
         $order = $model_refund->getRightOrderList(array('buyer_id' => $this->member_id, 'order_id' => $order_id));
 
         $order_amount = $order['order_amount'];//订单金额
+
+        $bonus_amount = unserialize($order['bonus_amount']);
+        $user_bonus = floatval($bonus_amount['user_bonus']);
+        $room_bonus = floatval($bonus_amount['room_bonus']);
+
         $pd_amount = $order['pd_amount'];
-        $order_amount -= $pd_amount;
+        $order_amount -= $user_bonus + $room_bonus;
 
         $condition = array();
         {

+ 1 - 1
mobile/control/member_refund.php

@@ -73,7 +73,7 @@ class member_refundControl extends mbMemberControl
             if($order == false) {
                 return self::outerr(errcode::ErrParamter,"查不到该订单");
             } else {
-                Logic('delivery')->cancel_oms($order_sn);
+                Logic('delivery')->cancel_order($order_sn);
                 return self::outsuccess(array('order' => $order));
             }
         }

+ 1 - 1
shop/control/store_deliver.php

@@ -88,7 +88,7 @@ class store_deliverControl extends BaseSellerControl {
 
         if (chksubmit())
         {
-            $ret = Logic('delivery')->cancel_oms($order_info['order_sn']);
+            $ret = Logic('delivery')->cancel_order($order_info['order_sn']);
             if($ret == true)
             {
                 $logic_order = Logic('order');

+ 56 - 2
shop/control/store_refund.php

@@ -84,7 +84,8 @@ class store_refundControl extends BaseSellerControl {
 			    $refund_array['seller_state'] = '2';
 			    $refund_array['refund_state'] = '2';
 			}
-			$state = $model_refund->editRefundReturn($condition, $refund_array);
+
+            $state = $model_refund->editRefundReturn($condition, $refund_array);
 			if ($state) {
     			if ($refund_array['seller_state'] == '3' && $refund['order_lock'] == '2') {
     			    $model_refund->editOrderUnlock($order_id);//订单解锁
@@ -100,7 +101,6 @@ class store_refundControl extends BaseSellerControl {
                     'refund_sn' => $refund['refund_sn']
                 );
                 QueueClient::push('sendMemberMsg', $param);
-
 				showDialog(Language::get('nc_common_save_succ'),$reload,'succ');
 			} else {
 				showDialog(Language::get('nc_common_save_fail'),$reload,'error');
@@ -118,8 +118,62 @@ class store_refundControl extends BaseSellerControl {
 		$condition = array();
 		$condition['order_id'] = $refund['order_id'];
 		$model_refund->getRightOrderList($condition, $refund['order_goods_id']);
+
+        if($refund['seller_state'] == '1') {
+            $status_text = $this->order_status($refund['order_sn']);
+        }
+        else {
+            $status_text = '已经同意,不做查询';
+        }
+        Tpl::output('order_status_text',$status_text);
+
 		Tpl::showpage('store_refund_edit');
 	}
+
+	private function order_status($order_sn)
+    {
+        $delivery = Logic('delivery');
+        $status = $delivery->query_order($order_sn);
+        if($status > 0)
+        {
+            // 1:新订单 2:等待仓库处理 99:已拦截 90:库存不足 7:已发货
+            // -99:发货失败 -2:订单关闭 -3:订单已存在(没有进行拦截的订单不予更新) -1:异常订单 -2:订单关闭
+            if($status == 1) {
+                return '新订单';
+            }
+            elseif ($status == 2) {
+                return '等待仓库处理';
+            }
+            elseif ($status == 99) {
+                return '已拦截';
+            }
+            elseif ($status == 90) {
+                return '库存不足';
+            }
+            elseif ($status == 7) {
+                return '已发货';
+            }
+            elseif ($status == -99) {
+                return '发货失败';
+            }
+            elseif ($status == -1) {
+                return '异常订单';
+            }
+            elseif ($status == -2) {
+                return '订单关闭';
+            }
+            elseif ($status == -3) {
+                return '订单已存在(没有进行拦截的订单不予更新)';
+            }
+            else {
+                return '没有该订单状态,请去OMS系统查询';
+            }
+        }
+        else {
+            return '查询失败,请人工到OMS系统查询';
+        }
+    }
+
 	/**
 	 * 退款记录查看页
 	 *

+ 4 - 0
shop/templates/default/seller/store_refund_edit.php

@@ -60,6 +60,10 @@
       <form id="post_form" method="post" action="index.php?act=store_refund&op=edit&refund_id=<?php echo $output['refund']['refund_id']; ?>">
         <input type="hidden" name="form_submit" value="ok" />
         <h3>商家处理意见</h3>
+          <dl>
+              <dt><i class="required">*</i>订单状态:</dt>
+              <dd> <?php echo $output['order_status_text']; ?> </dd>
+          </dl>
         <dl>
           <dt><i class="required">*</i><?php echo $lang['refund_seller_confirm'].$lang['nc_colon'];?></dt>
           <dd>

+ 8 - 1
test/TestOrder.php

@@ -25,7 +25,7 @@ class TestOrder extends PHPUnit_Framework_TestCase
     public function testCancelOms()
     {
         $oms = Logic('delivery');
-        $oms->cancel_oms('9000000002963603');
+        $oms->cancel_order('9000000002963603');
     }
 
     public static function testSuccess()
@@ -216,4 +216,11 @@ class TestOrder extends PHPUnit_Framework_TestCase
             }
         }
     }
+
+    public function testQueryOrder()
+    {
+        $delivery = Logic('delivery');
+        $order_sn = '2000000000717601';
+        $status = $delivery->query_order($order_sn);
+    }
 }

+ 11 - 11
test/TestPay.php

@@ -59,23 +59,23 @@ class TestPay extends PHPUnit_Framework_TestCase
     public function testHfivePay()
     {
         $body = '<xml><appid><![CDATA[wxfdaeb25e38c4c47e]]></appid>
-<attach><![CDATA[390604494271279490]]></attach>
+<attach><![CDATA[590604488911416534]]></attach>
 <bank_type><![CDATA[CFT]]></bank_type>
-<cash_fee><![CDATA[1490]]></cash_fee>
+<cash_fee><![CDATA[15400]]></cash_fee>
 <fee_type><![CDATA[CNY]]></fee_type>
 <is_subscribe><![CDATA[N]]></is_subscribe>
 <mch_id><![CDATA[1380733702]]></mch_id>
-<nonce_str><![CDATA[6w4eejabo5dqfkmyx9wk1pf56gg568kv]]></nonce_str>
-<openid><![CDATA[oQH7D5MjCxmeWllad4R3axCjfKno]]></openid>
-<out_trade_no><![CDATA[390604494271279490252]]></out_trade_no>
+<nonce_str><![CDATA[0al5w566fsnpvn56zoo5lbf59kymmhbs]]></nonce_str>
+<openid><![CDATA[oQH7D5My2UkjSWv-7YYwM-faZ_3c]]></openid>
+<out_trade_no><![CDATA[590604488911416534686]]></out_trade_no>
 <result_code><![CDATA[SUCCESS]]></result_code>
 <return_code><![CDATA[SUCCESS]]></return_code>
-<sign><![CDATA[10A1445EC765645D7B2A5A7C9D4C6411]]></sign>
-<time_end><![CDATA[20190226110443]]></time_end>
-<total_fee>1490</total_fee>
+<sign><![CDATA[7C677137D72376B9B1815D1F084FC068]]></sign>
+<time_end><![CDATA[20190226093533]]></time_end>
+<total_fee>15400</total_fee>
 <trade_type><![CDATA[MWEB]]></trade_type>
-<transaction_id><![CDATA[4200000276201902261906556992]]></transaction_id>
-</xml>';
-        $resp = http_post_data('http://192.168.0.200/mobile/web_wxnotify.php',$body);
+<transaction_id><![CDATA[4200000279201902260421273158]]></transaction_id>
+</xml>^M';
+        $resp = http_post_data('https://passport.lrlz.com/mobile/web_wxnotify.php',$body);
     }
 }