shish před 2 roky
rodič
revize
6e6e683d0e

+ 102 - 0
app-mall/controllers/NoticeController.php

@@ -369,4 +369,106 @@ class NoticeController extends PublicController
         }
     }
 
+    //收银台支付回调
+    public function actionCashPayCallback()
+    {
+        header("Content-type: text/html; charset=utf-8");
+
+        Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'mall');
+
+        $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
+        if (empty($postStr)) {
+            util::end();
+        }
+
+        $headers = Yii::$app->getRequest()->getHeaders();
+        $Authorization = $headers->get('Authorization');
+
+        $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',
+            'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
+            'lklCertificatePath' => $lklCertificatePath,
+        ];
+        $laResource = new Lakala($params);
+        $return = $laResource->signatureVerification($Authorization, $postStr);
+
+        $postData = json_decode($postStr, true);
+        $orderSn = $postData['out_order_no'] ?? '';
+        $payer_amount = $postData['total_amount'] ?? 0;
+        $payMode = $postData['pay_mode'] ?? '';
+        if (empty($payMode)) {
+            noticeUtil::push('收银台支付回调失败了,没有找到钱包类型,请注意,orderSn:' . $orderSn, '15280215347');
+            util::end();
+        }
+        $totalFee = $payer_amount / 100;
+        $transactionId = $postData['pay_order_no'] ?? 0;
+
+        if ($return == false) {
+            noticeUtil::push('收银台支付回调验证失败了,请注意,orderSn:' . $orderSn, '15280215347');
+            util::end();
+        }
+
+
+        $orderStatus = $postData['order_status'];
+        $tradeType = $postData['trade_type'];
+        if ($tradeType != 'PAY') {
+            noticeUtil::push('收银台支付回调验证失败了,不是消费的回调,orderSn:' . $orderSn, '15280215347');
+            util::end();
+        }
+
+        $capitalType = isset($capitalType) ? $capitalType : null;
+
+
+        if (isset($capitalType) == false) {
+            Yii::warning('capitalType empty, orderSn:' . $orderSn);
+            util::end();
+        }
+
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            if ($orderStatus == 2) {
+                $payWayType = null;
+                if ($payMode == 'ALIPAY') {
+                    $payWayType = dict::getDict('payWay', 'alipay');
+                }
+                if ($payMode == 'WECHAT') {
+                    $payWayType = dict::getDict('wxPay', 'alipay');
+                }
+                if (isset($payWayType) == false) {
+                    noticeUtil::push('收银台支付回调验证失败了,没有找到支付方式,orderSn:' . $orderSn, '15280215347');
+                    util::end();
+                }
+
+                $attach = '';
+                payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
+                $transaction->commit();
+
+                //打印小票和语音播报
+                $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
+                ShopExtClass::hdGatheringReport($order);
+                OrderClass::onlinePrint($order);
+
+                $shopId = $order->shopId ?? 0;
+                $shop = ShopClass::getById($shopId, true);
+                if (in_array($order->fromType, [dict::getDict("fromType", "shop"), dict::getDict("fromType", "friend")])) {
+                    //您有新的收入提醒
+                    WxMessageClass::gatheringIncomeInform($shop, $order);
+                }
+                if ($order->fromType == dict::getDict("fromType", "mall")) {
+                    //来自商城的新订单微信通知
+                    WxMessageClass::hdNewOrderInform($shop, $order);
+                }
+            }
+            //请不要修改
+            echo "SUCCESS";
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::error("失败原因:" . $e->getMessage());
+        }
+    }
+
 }

+ 24 - 8
app-mall/controllers/OrderController.php

@@ -617,16 +617,32 @@ class OrderController extends BaseController
             util::success($new);
 
         } elseif ($payWay == 1) {
-            //Yii::$app->params['mallHost'] . "/notice/ali-callback"
+
             $totalFee = $order['realPrice'];
-            $out_trade_no = $orderSn;//商户订单号,商户网站订单系统中唯一订单号,必填
-            $subject = '购买商品';//订单名称,必填
-            $total_amount = $totalFee;//付款金额,必填
-            $body = '';//商品描述,可空
-            $timeout_express = "1m";//超时时间
+            $subject = '购买花材';
             $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
-            $passBackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&sjId=' . $sjId;//将流水类型、优惠卷传过去
-
+            $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);
+            $notifyUrl = Yii::$app->params['mallHost'] . "/notice/cash-pay-callback";
+            $cashParams = [
+                'orderSn' => $orderSn,
+                'amount' => $totalFee,
+                'capitalType' => $capitalType,
+                'notifyUrl' => $notifyUrl,
+                'subject' => $subject,
+            ];
+            $response = $laResource->cashierPay($cashParams);
+            print_r($response);
         } elseif ($payWay == 2) {
             util::fail('无效的支付方式');
             //余额支付,验证支付密码是否正确

+ 0 - 1
common/components/payUtil.php

@@ -65,7 +65,6 @@ class payUtil
                 break;
             default:
         }
-
     }
 
 }