whitefang 1 год назад
Родитель
Сommit
acaa7690d3
2 измененных файлов с 61 добавлено и 2 удалено
  1. 60 1
      app/common/logic/PaymentLogic.php
  2. 1 1
      app/workerapi/controller/PayController.php

+ 60 - 1
app/common/logic/PaymentLogic.php

@@ -179,7 +179,66 @@ class PaymentLogic extends BaseLogic
      * @author mjf
      * @date 2024/3/18 16:49
      */
-    public static function pay($payWay, $from, $order, $userInfo, $redirectUrl)
+    public static function pay($payWay, $from, $order, $terminal, $redirectUrl)
+    {
+        // 支付编号-仅为微信支付预置(同一商户号下不同客户端支付需使用唯一订单号)
+        $paySn = $order['sn'];
+        if ($payWay == PayEnum::WECHAT_PAY) {
+            $paySn = self::formatOrderSn($order['sn'], $terminal);
+        }
+        //更新支付方式
+        switch ($from) {
+            case 'recharge':
+                RechargeOrder::update(['pay_way' => $payWay, 'pay_sn' => $paySn], ['id' => $order['id']]);
+                break;
+            case 'goods':
+                RechargeOrder::update(['pay_way' => $payWay, 'pay_sn' => $paySn], ['id' => $order['id']]);
+                break;
+        }
+
+        if ($order['order_amount'] == 0) {
+            PayNotifyLogic::handle($from, $order['sn']);
+            return ['sn' => $order['sn'],'need_pay'=>0];
+        }
+
+        $payService = null;
+        switch ($payWay) {
+            case PayEnum::WECHAT_PAY:
+                $payService = (new WeChatPayService($terminal, $order['user_id'] ?? null));
+                $order['pay_sn'] = $paySn;
+                $order['redirect_url'] = $redirectUrl;
+                $result = $payService->pay($from, $order);
+                break;
+            case PayEnum::ALI_PAY:
+                $payService = (new AliPayService($terminal));
+                $order['redirect_url'] = $redirectUrl;
+                $result = $payService->pay($from, $order);
+                break;
+            default:
+                self::$error = '订单异常';
+                $result = false;
+        }
+
+        if (false === $result && !self::hasError()) {
+            self::setError($payService->getError());
+        }
+        $result['need_pay'] = 1;
+        return $result;
+    }
+
+    /**
+     * @notes 支付
+     * @param $payWay
+     * @param $from
+     * @param $order
+     * @param $terminal
+     * @param $redirectUrl
+     * @return array|false|mixed|string|string[]
+     * @throws \Exception
+     * @author mjf
+     * @date 2024/3/18 16:49
+     */
+    public static function workerPay($payWay, $from, $order, $userInfo, $redirectUrl)
     {
         $terminal = $userInfo['terminal'];
         // 支付编号-仅为微信支付预置(同一商户号下不同客户端支付需使用唯一订单号)

+ 1 - 1
app/workerapi/controller/PayController.php

@@ -32,7 +32,7 @@ class PayController extends \app\workerapi\controller\BaseApiController
         }
         //支付流程
         $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
-        $result = PaymentLogic::pay($params['pay_way'], $params['from'], $order, $this->userInfo, $redirectUrl);
+        $result = PaymentLogic::workerPay($params['pay_way'], $params['from'], $order, $this->userInfo, $redirectUrl);
         if (false === $result) {
             return $this->fail(PaymentLogic::getError(), $params);
         }