Parcourir la source

取消订单,关闭拉卡拉订单

shish il y a 3 semaines
Parent
commit
69fd06ed9a
1 fichiers modifiés avec 27 ajouts et 5 suppressions
  1. 27 5
      app-ghs/controllers/OrderController.php

+ 27 - 5
app-ghs/controllers/OrderController.php

@@ -2755,18 +2755,40 @@ class OrderController extends BaseController
     public function actionCancel()
     {
         $shopAdmin = $this->shopAdmin;
-        if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
+        if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
             util::fail('超管才能取消订单');
         }
-        $id = Yii::$app->request->get('id');
+        $get = Yii::$app->request->get();
+        $cashierId = $get['cashierId'] ?? 0;
+        $id = $get['id'] ?? 0;
         $order = OrderClass::getById($id, true);
-
+        OrderClass::valid($order, $this->shopId);
         if ($order->orderType == 2) {
             util::fail('客户下单,不能主动取消');
         }
+        //如果收银台的订单,取消时要关闭拉卡拉的订单
+        if($cashierId == 1){
+            $cgId = $order->purchaseId ?? 0;
+            $cg = PurchaseClass::getById($cgId, true);
+            $orderSn = $cg->orderSn ?? '';
 
-        OrderClass::valid($order, $this->shopId);
-        OrderService::expire($order, true);
+            $shop = $this->shop;
+            $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);
+            $closeParams = ['orderSn' => $orderSn];
+            //关闭拉卡拉订单
+            $laResource->cashClose($closeParams);
+        }
+        OrderService::expire($order);
         util::complete('已取消');
     }