shish 2 ani în urmă
părinte
comite
79a95a9e2e
1 a modificat fișierele cu 31 adăugiri și 1 ștergeri
  1. 31 1
      app-hd/controllers/PurchaseClearController.php

+ 31 - 1
app-hd/controllers/PurchaseClearController.php

@@ -24,7 +24,9 @@ class PurchaseClearController extends BaseController
         $post = Yii::$app->request->post();
         $ghsId = $post['ghsId'] ?? 0;
         $ghs = GhsClass::getById($ghsId, true);
-
+        if (empty($ghs)) {
+            util::fail('没有供货商');
+        }
         //解决重复请求问题
         $staffId = $this->shopAdminId ?? 0;
         $cacheKey = 'hd_clear_order_pay_' . $ghsId . '_' . $staffId;
@@ -37,9 +39,37 @@ class PurchaseClearController extends BaseController
         //老的没有清的结账单直接过期掉
         $list = PurchaseClearClass::getAllByCondition(['ghsId' => $ghsId, 'status' => PurchaseClearClass::STATUS_AWAIT_PAY], null, '*', null, true);
         if (!empty($list)) {
+            $ghsShopId = $ghs->shopId ?? 0;
+            $ghsShop = ShopClass::getById($ghsShopId, true);
             foreach ($list as $item) {
                 $item->status = PurchaseClearClass::STATUS_EXPIRE;
                 $item->save();
+
+                if (!empty($ghsShop)) {
+                    $orderSn = $item->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' => $orderSn,
+                    ];
+                    $response = $laResource->close($closeParams);
+                    if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
+                        $msg = $response['msg'] ?? '';
+                        noticeUtil::push("\n花店结账单:" . $orderSn . "\n关单失败了\n{$msg} ", '15280215347');
+                    } else {
+                        noticeUtil::push("\n花店结账单:" . $orderSn . "\n关单成功", '15280215347');
+                    }
+                }
+
             }
         }
         $post['ghsShopId'] = $ghs->shopId ?? 0;