dever 4 years ago
parent
commit
9b467fba2d
3 changed files with 27 additions and 16 deletions
  1. 5 2
      lib/Set.php
  2. 21 13
      lib/Wechat.php
  3. 1 1
      src/Api.php

+ 5 - 2
lib/Set.php

@@ -28,6 +28,7 @@ class Set
         $account_id = $send['pay_account_id'];
         $status = $send['pay_status'];
         $uid = $send['pay_uid'];
+        $cash = $send['pay_cash'];
 
         $project_id = Dever::load('pay/lib/core')->checkOrder($order_id);
         if ($project_id) {
@@ -35,6 +36,9 @@ class Set
             $order['account_id'] = $account_id;
         } else {
             $order = Dever::db('pay/order')->one(array('order_id' => $order_id, 'uid' => $uid));
+            if ($order && $order['cash']) {
+                $cash = $order['cash'];
+            }
         }
 
         if ($order) {
@@ -43,8 +47,7 @@ class Set
                 $pay = Dever::db('pay/account')->one($order['account_id']);
                 $method = '\\Pay\\Lib\\' . ucwords($pay['type']);
                 $method = new $method($pay);
-                $result = $method->refund($order_id);
-                print_r($result);die;
+                $result = $method->refund($order_id, $cash);
             } 
             
 

+ 21 - 13
lib/Wechat.php

@@ -53,22 +53,11 @@ class Wechat extends Core
 	}
 
 	# 退款
-	public function refund($order_id)
+	public function refundByOrder($order_id)
 	{
 		$info = Dever::db('pay/order')->one(array('order_id' => $order_id));
 		if ($info && ($info['status'] == 1 || $info['status'] == 2 || $info['status'] == 5)) {
-			$out_trade_no = $info['order_id'];
-			$info['cash'] = $info['cash'] * 100;
-			$total_fee = $info['cash'];
-			$refund_fee = $info['cash'];
-			$input = new \WxPayRefund();
-			$input->SetOut_trade_no($out_trade_no);
-			$input->SetTotal_fee($total_fee);
-			$input->SetRefund_fee($refund_fee);
-
-		    $input->SetOut_refund_no($out_trade_no . '_' . time());
-		    $input->SetOp_user_id($this->config->GetMerchantId());
-			$result = \WxPayApi::refund($this->config, $input);
+			$this->refund($info['order_id'], $info['cash']);
 
 			Dever::db('pay/order')->update(array('where_id' => $info['id'], 'status' => 5));
 
@@ -78,6 +67,25 @@ class Wechat extends Core
 		return false;
 	}
 
+
+	# 退款
+	public function refund($order_id, $cash)
+	{
+		$out_trade_no = $order_id;
+		$info['cash'] = $cash * 100;
+		$total_fee = $cash;
+		$refund_fee = $cash;
+		$input = new \WxPayRefund();
+		$input->SetOut_trade_no($out_trade_no);
+		$input->SetTotal_fee($total_fee);
+		$input->SetRefund_fee($refund_fee);
+
+	    $input->SetOut_refund_no($out_trade_no . '_' . time());
+	    $input->SetOp_user_id($this->config->GetMerchantId());
+		$result = \WxPayApi::refund($this->config, $input);
+		return $result;
+	}
+
 	/**
 	 * 获取统一下单的基本信息
 	 */

+ 1 - 1
src/Api.php

@@ -147,7 +147,7 @@ class Api
 		}
 		$this->pay();
 		$this->order_id = $this->getParam($param, 'order_id');
-		return $this->method->refund($this->order_id);
+		return $this->method->refundByOrder($this->order_id);
 	}
 
 	/**