|
|
@@ -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')) {
|