shish před 2 roky
rodič
revize
b088376bc9

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

@@ -113,7 +113,7 @@ class PurchaseClearController extends BaseController
         }
 
         if (isset($ghsShop->lklSjNo) && empty($ghsShop->lklSjNo)) {
-            util::fail('商家支付功能冻结');
+            util::fail('商家支付功能未开通');
         }
 
         //已经唤起过微信支付了,根据拉卡拉的规则,需要生成新的订单号
@@ -205,4 +205,113 @@ class PurchaseClearController extends BaseController
         util::success($new);
     }
 
+    public function actionAliPay()
+    {
+        ini_set('date.timezone', 'Asia/Shanghai');
+        $post = Yii::$app->request->post();
+        $couponId = $post['couponId'] ?? 0;
+        $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
+        $order = PurchaseClearClass::getByCondition(['orderSn' => $orderSn], true);
+        if (empty($order)) {
+            util::fail('账单号无效');
+        }
+        if ($order->status == PurchaseClearClass::STATUS_HAS_PAY) {
+            util::fail('账单已结清了');
+        }
+        if ($order->status == PurchaseClearClass::STATUS_EXPIRE) {
+            util::fail('账单已取消了');
+        }
+        $oldOrderSn = $orderSn;
+        $current = time();
+        $deadline = $order->deadline;
+        if ($current > strtotime($deadline)) {
+            $order->status = PurchaseClearClass::STATUS_EXPIRE;
+            $order->save();
+            util::fail('订单已经失效,请重新发起结算');
+        }
+        $name = '采购单结算';
+        $totalFee = $order->actPrice;
+
+        $capitalType = dict::getDict('capitalType', 'hdPurchaseClear', 'id');
+        $ghsShopId = $order->ghsShopId ?? 0;
+        $ghsShop = ShopClass::getById($ghsShopId, true);
+        if (empty($ghsShop)) {
+            util::fail('没有供货商门店信息');
+        }
+
+        if (isset($ghsShop->lklSjNo) && empty($ghsShop->lklSjNo)) {
+            util::fail('商家支付功能未开通');
+        }
+
+        //已经唤起支付,根据拉卡拉的规则,需要生成新的订单号
+        if ($order->changePrice == 2) {
+            //老单号需要关单,否则有付款成功的风险,老单号关单成功了,才能生成新单号
+            $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->close($closeParams);
+            if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
+                $msg = $response['msg'] ?? '';
+                noticeUtil::push('重点注意,花店结账,单号:' . $oldOrderSn . ',关单没有成功,原因:' . $msg . ',可能造成无法结账', '15280215347');
+                util::fail('出错了,请取消本单重试');
+            }
+
+            $newOrderSn = orderSn::getPurchaseClearSn();
+            $orderSn = $newOrderSn;
+            $order->orderSn = $newOrderSn;
+            $order->save();
+        }
+        $order->changePrice = 2;
+        $order->save();
+
+        $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);
+        $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
+        $wxParams = [
+            'orderSn' => $orderSn,
+            'amount' => $totalFee,
+            'capitalType' => $capitalType,
+            'notifyUrl' => $notifyUrl,
+            'subject' => $name,
+            'couponId' => $couponId,
+        ];
+        $response = $laResource->driveWxPay($wxParams);
+        if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
+            $errMsg = $response['msg'] ?? '';
+            $ghsName = $order->ghsName ?? '';
+            $ghsShopName = $order->ghsShopName ?? '';
+            $ghsFullName = $ghsName . $ghsShopName;
+            $customName = $order->customName ?? '';
+            $customFullName = $customName;
+            noticeUtil::push("\n提示:结账付款失败\n原因:" . $errMsg . "。\n商家:" . $ghsFullName . "\n客户:" . $customFullName, '15280215347');
+            util::fail('结账付款失败,' . $errMsg . ',请联系门店');
+        }
+        $payUrl = '';
+        $new = [
+            'payUrl' => $payUrl,
+            'orderSn' => $orderSn,
+        ];
+        util::success($new);
+    }
+
 }

+ 3 - 3
app-hd/controllers/PurchaseController.php

@@ -736,8 +736,8 @@ class PurchaseController extends BaseController
                 OrderItemClass::updateByCondition(['orderSn' => $oldSaleOrderSn], ['orderSn' => $newGhsOrderSn]);
             }
         }
-        $order->changePrice = 2;
-        $order->save();
+        //$order->changePrice = 2;
+        //$order->save();
 
         $name = $orderSn;
         $totalFee = $order->realPrice;
@@ -821,7 +821,7 @@ class PurchaseController extends BaseController
             util::fail('没有供货商门店信息');
         }
         if (isset($ghsShop->lklSjNo) && empty($ghsShop->lklSjNo)) {
-            util::fail('商家支付功能冻结');
+            util::fail('商家支付功能未开通');
         }
 
         //已经唤起过微信支付了,根据拉卡拉的规则,需要生成新的订单号