dever 5 years ago
parent
commit
d5c8a611b0
2 changed files with 40 additions and 6 deletions
  1. 24 6
      lib/Wechat.php
  2. 16 0
      src/Api.php

+ 24 - 6
lib/Wechat.php

@@ -39,9 +39,7 @@ class Wechat extends Core
 		if ($info) {
 			$this->updateOrder($info['order_id'], 1);
 			return $info;
-		}
-
-		if (!$info) { 
+		} else {
 			$input = new \WxPayOrderQuery();
 			$input->SetOut_trade_no($order_id);
 			$result = \WxPayApi::orderQuery($this->config, $input);
@@ -51,10 +49,30 @@ class Wechat extends Core
 			}
 
 			return $result;
-		} else {
-			return $info;
 		}
-		
+	}
+
+	# 退款
+	public function refund($order_id)
+	{
+		$info = Dever::db('pay/order')->one(array('order_id' => $order_id));
+		if ($info && $info['status'] <= 2) {
+			$out_trade_no = $info['order_id'];
+			$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);
+
+			return $result;
+		}
+
+		return false;
 	}
 
 	/**

+ 16 - 0
src/Api.php

@@ -134,6 +134,22 @@ class Api
 		return $this->method->search($this->order_id);
 	}
 
+	/**
+	 * 退款
+	 *
+	 * @return mixed
+	 */
+	public function refund($param = array())
+	{
+		$this->account_id = Dever::input('account_id', false);
+		if (!$this->account_id) {
+			Dever::alert('没有账户信息');
+		}
+		$this->pay();
+		$this->order_id = $this->getParam($param, 'order_id');
+		return $this->method->refund($this->order_id);
+	}
+
 	/**
 	 * 初始化 设置参数
 	 *