From a14383c5c6285bef5b9c646b52df871f5237ea3f Mon Sep 17 00:00:00 2001 From: hitsword Date: Mon, 20 May 2019 17:21:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=9F=BA=E6=9C=AC=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hitsword --- class-wc-huayi-score.php | 15 +++------ includes/huayi-score-sdk.php | 59 +++++++++++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 17 deletions(-) diff --git a/class-wc-huayi-score.php b/class-wc-huayi-score.php index 5b4bf1e..84607d3 100644 --- a/class-wc-huayi-score.php +++ b/class-wc-huayi-score.php @@ -142,15 +142,10 @@ class WC_Huayi_Score extends WC_Payment_Gateway { return; } - //debug - wc_add_notice( __('查询成功:', 'huayi_score') . $balanceResult, 'error' ); - return; - //debug - - if ($balanceResult >= $order->order_total ) {//积分够扣 - $payResult = $huayiScoreSdk->pay($huayi_uid,$order->order_total,'订单号:'.$order_id);//执行扣款 TODO + if ($balanceResult['data']['score'] >= $order->order_total ) {//积分够扣 + $payResult = $huayiScoreSdk->pay($huayi_uid,$order->order_total,'订单号:'.$order_id);//执行扣款 //支付成功 - if ( $payResult['uid'] > 0 ) {//TODO 修正状态判断 + if ( $payResult['data']['pay_status'] == 'success' ) {//TODO TEST //更新订单状态 //$order->update_status( 'on-hold', __( '等待积分支付', 'huayi_score' ) );//需要支付回调的接口才需要 @@ -197,10 +192,10 @@ class WC_Huayi_Score extends WC_Payment_Gateway { $huayi_uid = get_user_meta( $order->get_user_id() , 'huayi_uid',true ); if ( $huayi_uid > 0 ) { - $huayiScoreSdk = new HuayiScoreSdk(array('apiurl'=>'1','token'=>'1')); + $huayiScoreSdk = new HuayiScoreSdk(array('apiurl'=>$this->apiurl,'token'=>$this->token)); $result = $huayiScoreSdk->refund($huayi_uid,$amount,'退款订单号:'.$order_id.'.退款原因:'.$reason);//执行退款 - if ( $result['uid'] > 0 ) {//TODO 修正状态判断 + if ( $result['data']['refund_status'] == 'success' ) {//TODO TEST $order->add_order_note( sprintf( __( '退款时间: %s - 退款会员ID: %s', 'huayi_score' ), date("Y-m-d H:i:s"),$result['uid'] ) ); return true; } else { diff --git a/includes/huayi-score-sdk.php b/includes/huayi-score-sdk.php index 938d6c3..920c407 100644 --- a/includes/huayi-score-sdk.php +++ b/includes/huayi-score-sdk.php @@ -15,6 +15,10 @@ class HuayiScoreSdk //查询积分接口 protected $get_balance_url = '/api/scoreshopv1/balance/index'; + //支出积分接口 + protected $pay_url = '/api/scoreshopv1/pay/index'; + //退回积分接口 + protected $refund_url = '/api/scoreshopv1/refund/index'; public function __construct($option) { @@ -23,6 +27,7 @@ class HuayiScoreSdk } /** + * PASS * 获取积分余额 * @param $huayi_uid * @return bool @@ -39,7 +44,7 @@ class HuayiScoreSdk if (!$response) {//请求失败 return false; } elseif ($response['body']['code'] == 1) {//请求成功 - return $response; + return $response['body']; } else {//请求成功但是返回错误 $this->error = $response['body']['msg']; return false; @@ -47,21 +52,61 @@ class HuayiScoreSdk } /** + * TODO TEST * 支出积分 - * @return string + * @param $huayi_uid + * @param $amount + * @param $note + * @return bool */ - public function pay($huayi_uid,$amount,$note) + public function pay($huayi_uid, $amount, $note) { - return $huayi_uid.$amount.$note; + $url = $this->apiurl.$this->pay_url; + + $data = [ + 'uid'=>$huayi_uid, + 'amount'=>$amount, + 'note'=>$note, + 'timestamp'=>time() + ]; + $response = $this->postRequest($url, $data); + if (!$response) {//请求失败 + return false; + } elseif ($response['body']['code'] == 1) {//请求成功 + return $response['body']; + } else {//请求成功但是返回错误 + $this->error = $response['body']['msg']; + return false; + } } /** + * TODO TEST * 退还积分 - * @return string + * @param $huayi_uid + * @param $amount + * @param $note + * @return bool */ - public function refund($huayi_uid,$amount,$note) + public function refund($huayi_uid, $amount, $note) { - return $huayi_uid.$amount.$note; + $url = $this->apiurl.$this->refund_url; + + $data = [ + 'uid'=>$huayi_uid, + 'amount'=>$amount, + 'note'=>$note, + 'timestamp'=>time() + ]; + $response = $this->postRequest($url, $data); + if (!$response) {//请求失败 + return false; + } elseif ($response['body']['code'] == 1) {//请求成功 + return $response['body']; + } else {//请求成功但是返回错误 + $this->error = $response['body']['msg']; + return false; + } } /**