Răsfoiți Sursa

一键退款

shish 1 an în urmă
părinte
comite
af36ebffa6

+ 19 - 0
app-hd/controllers/RefundController.php

@@ -17,6 +17,25 @@ use common\components\util;
 class RefundController extends BaseController
 {
 
+    //取消的订单退钱,特殊情况的操作:商家取消订单时,客户同时付款成功了,造成的流程冲突,需要退钱 ssh 20250429
+    public function actionRefundAmount()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? '';
+        $order = OrderClass::getById($id, true);
+        if (empty($order)) {
+            util::fail('没有找到订单');
+        }
+        if ($order->mainId != $this->mainId) {
+            util::fail('不是你的订单');
+        }
+        $shop = $this->shop;
+        $respond = HdRefundClass::onlyRefundAmount($shop, $order);
+        $status = $respond['status'];
+        $msg = $respond['msg'];
+        util::success(['status' => $status], $msg);
+    }
+
     //列表
     public function actionList()
     {

+ 2 - 2
biz-hd/cg/classes/CgRefundClass.php

@@ -40,7 +40,7 @@ class CgRefundClass extends BaseClass
         $refundOrderSn = orderSn::getCgRefundSn();
         $refundPrice = $cg->actPrice ?? 0;
         $orderSn = $cg->orderSn ?? '';
-        $transaction_id = $cg->thirdNo ?? '';
+        //$transaction_id = $cg->thirdNo ?? '';
         $refundFee = bcmul($refundPrice, 100);
         $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
         $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
@@ -59,7 +59,7 @@ class CgRefundClass extends BaseClass
             'orderSn' => $orderSn,
             'refundAmount' => $refundFee,
             'refundReason' => $refundReason,
-            'thirdNo' => $transaction_id,
+            //'thirdNo' => $transaction_id,
         ];
         $response = $laResource->refund($aliParams);
         if (!isset($response['code']) || $response['code'] != 'BBS00000') {

+ 40 - 0
biz-hd/refund/classes/HdRefundClass.php

@@ -2,8 +2,11 @@
 
 namespace bizHd\refund\classes;
 
+use common\components\noticeUtil;
+use common\components\orderSn;
 use Yii;
 use bizHd\base\classes\BaseClass;
+use common\components\lakala\Lakala;
 
 class HdRefundClass extends BaseClass
 {
@@ -16,6 +19,43 @@ class HdRefundClass extends BaseClass
     const STATUS_UN_COMPLETE = 0; //退款处理中
     const STATUS_COMPLETE = 1; //已完成
 
+    public static function onlyRefundAmount($shop, $order)
+    {
+        $refundSn = orderSn::getHdRefundSn();
+        $xsOrderSn = $order->orderSn ?? '';
+        $refundPrice = $order->actPrice ?? 0;
+        $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' => $shop->lklSjNo,
+            'term_no' => $shop->lklScanTermNo,
+            'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
+            'lklCertificatePath' => $lklCertificatePath,
+        ];
+        $laResource = new Lakala($params);
+        $refundReason = '';
+        $aliParams = [
+            'refundSn' => $refundSn,
+            'orderSn' => $xsOrderSn,
+            'refundAmount' => $refundFee,
+            'refundReason' => $refundReason,
+        ];
+        $response = $laResource->refund($aliParams);
+        if (!isset($response['code']) || $response['code'] != 'BBS00000') {
+            $errMsg = $response['msg'] ?? '';
+            return ['status' => 0, 'msg' => $errMsg];
+        } else {
+            $sjName = $shop->merchantName;
+            $shopName = $shop->shopName;
+            $name = $shopName == '首店' ? $sjName : $sjName . '-' . $shopName;
+            noticeUtil::push("零售订单取消,客户还付款成功,钱已经原路退回 {$xsOrderSn} {$name}", '15280215347');
+            return ['status' => 1, 'msg' => '退款成功'];
+        }
+    }
+
     // 订单列表
     public static function getOrderList($where)
     {