|
|
@@ -735,6 +735,142 @@ class OrderController extends BaseController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //微信和支付宝付款码支付验证(带付款码) ssh 20260716
|
|
|
+ public function actionCodePayVerify()
|
|
|
+ {
|
|
|
+ ini_set('date.timezone', 'Asia/Shanghai');
|
|
|
+ header("Content-type: text/html; charset=utf-8");
|
|
|
+ $get = Yii::$app->request->get();
|
|
|
+ $id = isset($get['id']) ? $get['id'] : 0;
|
|
|
+ $authCode = isset($get['authCode']) ? $get['authCode'] : '';
|
|
|
+
|
|
|
+ util::checkRepeatCommit($id, 3);
|
|
|
+
|
|
|
+ $order = OrderClass::getById($id, true);
|
|
|
+ if (empty($order)) {
|
|
|
+ util::success(['returnStatus' => 'SUCCESS']);
|
|
|
+ }
|
|
|
+ if ($order->status == OrderClass::ORDER_STATUS_COMPLETE) {
|
|
|
+ util::complete('订单已付款');
|
|
|
+ }
|
|
|
+ if ($order->status == OrderClass::ORDER_STATUS_CANCEL) {
|
|
|
+ util::complete('订单已取消');
|
|
|
+ }
|
|
|
+ if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
|
|
|
+ util::complete('订单不是待付款状态');
|
|
|
+ }
|
|
|
+ OrderClass::valid($order, $this->shopId);
|
|
|
+ $cgId = $order->purchaseId ?? 0;
|
|
|
+ $cg = PurchaseClass::getById($cgId, true);
|
|
|
+ $orderSn = $cg->orderSn ?? '';
|
|
|
+ $totalFee = $cg->actPrice ?? 0;
|
|
|
+ if (empty($orderSn)) {
|
|
|
+ util::complete('没有找到采购单');
|
|
|
+ }
|
|
|
+
|
|
|
+ $connection = Yii::$app->db;
|
|
|
+ $transaction = $connection->beginTransaction();
|
|
|
+ try {
|
|
|
+
|
|
|
+ $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
|
|
|
+
|
|
|
+ $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);
|
|
|
+ $scanParams = ['orderSn' => $orderSn, 'authCode' => $authCode];
|
|
|
+ $response = $laResource->query($scanParams);
|
|
|
+
|
|
|
+ if (isset($response['code']) && $response['code'] == 'BBS00000') {
|
|
|
+ if (isset($response['resp_data']['trade_state']) && $response['resp_data']['trade_state'] == 'SUCCESS') {
|
|
|
+ //支付成功
|
|
|
+ $transactionId = $response['resp_data']['trade_no'] ?? '';
|
|
|
+ $openId = '';
|
|
|
+ $aliUserId = '';
|
|
|
+
|
|
|
+ $cg->onlinePay = dict::getDict('onlinePay', 'yes');
|
|
|
+ $cg->codePay = 1;
|
|
|
+ $cg->payOpenId = $openId;
|
|
|
+ $cg->aliUserId = $aliUserId;
|
|
|
+ //自取订单
|
|
|
+ $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
|
|
|
+ $cg->save();
|
|
|
+
|
|
|
+ $order->onlinePay = dict::getDict('onlinePay', 'yes');
|
|
|
+ $order->codePay = 1;
|
|
|
+ //自取订单
|
|
|
+ $order->sendType = OrderClass::SEND_TYPE_NO;
|
|
|
+ $order->save();
|
|
|
+
|
|
|
+ $payWayType = dict::getDict('payWay', 'wxPay');
|
|
|
+ $account_type = $response['resp_data']['account_type'] ?? '';
|
|
|
+ if ($account_type == 'WECHAT') {
|
|
|
+ $payWayType = dict::getDict('payWay', 'wxPay');
|
|
|
+ }
|
|
|
+ if ($account_type == 'ALIPAY') {
|
|
|
+ $payWayType = dict::getDict('payWay', 'alipay');
|
|
|
+ }
|
|
|
+ $order->payWay = $payWayType;
|
|
|
+ $order->save();
|
|
|
+ $cg->payWay = $payWayType;
|
|
|
+ $cg->save();
|
|
|
+
|
|
|
+ $attach = '';
|
|
|
+ payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
|
|
|
+ $transaction->commit();
|
|
|
+
|
|
|
+ $saleId = $order->id ?? 0;
|
|
|
+ $order = OrderClass::getById($saleId, true);
|
|
|
+ if (!empty($order)) {
|
|
|
+
|
|
|
+ //解决扫码付重复打印问题
|
|
|
+ $cacheKey = 'scan_pay_print_order_' . $orderSn;
|
|
|
+ $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
|
|
|
+ if (!empty($has)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 1, 'has']);
|
|
|
+
|
|
|
+ //订单生成时唤起在线打印
|
|
|
+ if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
|
|
|
+ if ($order->status != 1 && $order->status != 5) {
|
|
|
+ OrderClass::onlinePrint($order);
|
|
|
+ $ext = $this->shopExt;
|
|
|
+ if (isset($ext->printSn) && !empty($ext->printSn)) {
|
|
|
+ $order->printNum += 1;
|
|
|
+ $order->save();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
|
|
|
+ GhsDeliveryOrderClass::payAfter($order);
|
|
|
+
|
|
|
+ ShopExtClass::ghsGatheringReport($order);
|
|
|
+ }
|
|
|
+ util::success(['returnStatus' => 'SUCCESS']);
|
|
|
+ } else {
|
|
|
+ util::complete('未知状态..');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ util::complete('未知状态....');
|
|
|
+ }
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ noticeUtil::push('查询订单状态失败:' . $e->getMessage(), '15280215347');
|
|
|
+ util::fail('支付失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 微信和支付宝付款码支付
|
|
|
* 职责:处理商户扫描客户付款码(被扫支付)的请求,调用拉卡拉支付接口并更新本地订单状态
|