shish před 2 roky
rodič
revize
1cc7b073c5

+ 36 - 0
app-hd/controllers/PurchaseController.php

@@ -718,9 +718,45 @@ class PurchaseController extends BaseController
             util::fail('订单已失效,请重新下单');
         }
 
+        $ghsId = $order->ghsId ?? 0;
+        $ghs = GhsClass::getById($ghsId, true);
+        if (empty($ghs)) {
+            util::fail('没有供货商信息');
+        }
+        $ghsShopId = $ghs->shopId ?? 0;
+        $ghsShop = ShopClass::getById($ghsShopId, true);
+        if (empty($ghsShop)) {
+            util::fail('没有供货商门店信息');
+        }
+        if (isset($ghsShop->lklSjNo) && empty($ghsShop->lklSjNo)) {
+            util::fail('商家支付功能未开通');
+        }
+
         //已经唤起过微信支付了,根据拉卡拉的规则,需要生成新的订单号
         if ($order->changePrice == 2) {
             $oldOrderSn = $orderSn;
+
+            //老单号需要关单,否则有付款成功的风险,老单号关闭成功了,才能生成新单号
+            $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);
+            $closeParams = [
+                'orderSn' => $oldOrderSn,
+            ];
+            $response = $laResource->cashClose($closeParams);
+            if (isset($response['code']) == false || $response['code'] != '000000') {
+                $msg = $response['msg'] ?? '';
+                noticeUtil::push('注意花店买花更换单号没有成功,单号:' . $oldOrderSn . ',关单没有成功(收银台-支付宝),' . $msg, '15280215347');
+            }
+
             $newOrderSn = orderSn::getPurchaseSn();
             $newGhsOrderSn = orderSn::getGhsOrderSn();
             $orderSn = $newOrderSn;

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

@@ -258,6 +258,28 @@ class Lakala
         return $this->post($lklUrl, $body, $authorization);
     }
 
+    public function cashClose($params)
+    {
+        $orderSn = $params['orderSn'];
+        $ip = $this->getClientIp();
+        $location_info = ['request_ip' => $ip];
+        $arr = [
+            'merchant_no' => $this->merchant_no,
+            'term_no' => $this->term_no,
+            'location_info' => $location_info,
+            'out_order_no' => $orderSn,
+        ];
+        $baseRequestVO = [
+            'req_data' => $arr,
+            'req_time' => date("YmdHis"),
+            'version' => '1.0',
+        ];
+        $body = json_encode($baseRequestVO, JSON_UNESCAPED_UNICODE);
+        $authorization = $this->getAuthorization($body);
+        $lklUrl = 'https://s2.lakala.com/api/v3/ccss/counter/order/close';
+        return $this->post($lklUrl, $body, $authorization);
+    }
+
     //退款 ssh 20231009
     public function refund($params)
     {