shish 2 лет назад
Родитель
Сommit
fa8261376a
1 измененных файлов с 37 добавлено и 35 удалено
  1. 37 35
      biz-hd/purchase/classes/PurchaseClass.php

+ 37 - 35
biz-hd/purchase/classes/PurchaseClass.php

@@ -454,45 +454,47 @@ class PurchaseClass extends BaseClass
             //收入统计
             StatIncomeClass::updateOrInsert($main, $shop, $refundPrice);
 
-            //花掌柜收款的原路退回
-            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->bookPrice * 100;
-            $refundFee = $refundPrice * 100;
-            $transaction_id = $cg->thirdNo ?? '';
-
-            $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') {
-                $msg = $return['return_msg'] ?? '';
-                Yii::info("退款失败 cgId:{$cgId} msg:{$msg}");
+            
+            $ghsId = $cg->ghsId ?? 0;
+            $ghs = GhsClass::getLockById($ghsId);
+            if (empty($ghs)) {
+                util::fail('没有找到供货商');
+            }
+            $ghsShopId = $ghs->shopId ?? 0;
+            $ghsShop = ShopClass::getById($ghsShopId, true);
+            if (empty($ghsShop)) {
+                util::fail('没有找到供货商的门店');
+            }
+            $refundFee = bcmul($refundPrice, 100);
+            $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') {
+                $errMsg = $response['msg'] ?? '';
+                noticeUtil::push('退款失败了哦,请注意:' . $errMsg . ' 金额:' . $refundFee, '15280215347');
                 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;
             $cg->tkPrice = bcadd($cg->tkPrice, $refundPrice, 2);
             $cg->refund = self::REFUND_YES;