shish 2 éve
szülő
commit
80d347dd69
2 módosított fájl, 59 hozzáadás és 38 törlés
  1. 31 38
      biz-hd/cg/classes/CgRefundClass.php
  2. 28 0
      common/components/lakala/Lakala.php

+ 31 - 38
biz-hd/cg/classes/CgRefundClass.php

@@ -17,6 +17,7 @@ use Yii;
 use bizGhs\base\classes\BaseClass;
 use bizGhs\order\traits\OrderTrait;
 use bizGhs\product\classes\ProductClass;
+use common\components\lakala\Lakala;
 
 class CgRefundClass extends BaseClass
 {
@@ -154,46 +155,38 @@ class CgRefundClass extends BaseClass
         }
 
         if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
-            if ($payWay == dict::getDict('payWay', 'wxPay')) {
+            if ($payWay == dict::getDict('payWay', 'wxPay') || $payWay == dict::getDict('payWay', 'alipay')) {
 
-                //微信收款的原路退回
-                ini_set('date.timezone', 'Asia/Shanghai');
-                $wx = Yii::getAlias("@vendor/wxPayApi_v3.0.10");
-                require_once($wx . '/lib/WxPay.Api.php');
-                require_once($wx . '/example/WxPay.Config.php');
-
-                $totalFee = $cg->book == 1 ? $cg->bookPrice * 100 : $cg->orderPrice * 100;
+                $ghsShopId = $ghs->shopId ?? 0;
+                $ghsShop = ShopClass::getById($ghsShopId, true);
+                if (empty($ghsShop)) {
+                    util::fail('没有找到供货商的门店');
+                }
                 $refundFee = $refundPrice * 100;
-
-                $merchantExt = WxOpenClass::getWxInfo();
-                $mid = $merchantExt['wxPayMerchantId'] ?? '';
-                $appId = $merchantExt['miniAppId'] ?? '';
-                $key = $merchantExt['wxPayKey'] ?? '';
-
-                $input = new \WxPayRefund();
-                $input->SetTransaction_id($transaction_id);
-                $input->SetTotal_fee($totalFee);
-                $input->SetRefund_fee($refundFee);
-                $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-refund-callback/');
-
-                $config = new \WxPayConfig();
-                $config->SetAppId($appId);
-                $config->SetMerchantId($mid);
-                $config->SetKey($key);
-
-                $input->SetOut_refund_no($refundOrderSn);
-                $input->SetOp_user_id($mid);
-                $return = \WxPayApi::refund($config, $input);
-                if (isset($return['return_code']) == false || $return['return_code'] != 'SUCCESS' || isset($return['result_code']) == false || $return['result_code'] != 'SUCCESS') {
-                    $msg = $return['return_msg'] ?? '';
-                    $err_code_des = $return['err_code_des'] ?? '';
-                    Yii::info("退款失败 cgId:{$cgId} msg:{$msg}");
-                    Yii::info($err_code_des);
-                    Yii::info('微信退款返回信息:' . json_encode($return));
-                    util::fail('退款操作失败');
+                $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
+                $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
+                $params = [
+                    'appid' => 'OP00002119',
+                    'serial_no' => '018b08cfddbd',
+                    'merchant_no' => $ghsShop->lklSjNo,
+                    'term_no' => $ghsShop->lklScanTermNo,
+                    'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
+                    'lklCertificatePath' => $lklCertificatePath,
+                ];
+                $laResource = new Lakala($params);
+                $refundReason = '';
+                $aliParams = [
+                    'refundSn' => $refundOrderSn,
+                    'orderSn' => $orderSn,
+                    'refundAmount' => $refundFee,
+                    'refundReason' => $refundReason,
+                ];
+                $response = $laResource->refund($aliParams);
+                if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
+                    util::fail('退款失败');
                 }
-                $wxRefundId = $return['refund_id'] ?? '';
-                $cgRefund->thirdRefundNo = $wxRefundId;
+                $refundTradeNo = isset($response['resp_data']['trade_no']) ? $response['resp_data']['trade_no'] : '';
+                $cgRefund->thirdRefundNo = $refundTradeNo;
                 $cgRefund->save();
 
                 $cg->refundPrice = $refundPrice;
@@ -209,7 +202,7 @@ class CgRefundClass extends BaseClass
                 $cg->realPrice = $currentRealPrice;
                 $cg->save();
             } else {
-                util::fail('目前仅微信支付支持申请售后');
+                util::fail('暂不支持退款');
             }
         } else {
             if ($payWay == dict::getDict('payWay', 'debtPay')) {

+ 28 - 0
common/components/lakala/Lakala.php

@@ -33,6 +33,34 @@ class Lakala
         }
     }
 
+    //退款 ssh 20231009
+    public function refund($params)
+    {
+        $orderSn = $params['orderSn'];
+        $refundSn = $params['refundSn'];
+        $refundReason = $params['refundReason'];
+        $refundAmount = $params['refundAmount'];
+        $location_info = ['request_ip' => $_SERVER['SERVER_ADDR']];
+        $arr = [
+            'merchant_no' => $this->merchant_no,
+            'term_no' => $this->term_no,
+            'out_trade_no' => $refundSn,
+            'refund_amount' => $refundAmount,
+            'location_info' => $location_info,
+            'refund_reason' => $refundReason,
+            'origin_out_trade_no' => $orderSn,
+        ];
+        $baseRequestVO = [
+            'req_data' => $arr,
+            'req_time' => date("YmdHis"),
+            'version' => $this->version,
+        ];
+        $body = json_encode($baseRequestVO, JSON_UNESCAPED_UNICODE);
+        $authorization = $this->getAuthorization($body);
+        $lklUrl = 'https://s2.lakala.com/api/v3/labs/relation/refund';
+        return $this->post($lklUrl, $body, $authorization);
+    }
+
     //主扫交易,支付宝
     public function driveWxPay($orderSn, $amount)
     {