fly há 5 anos atrás
pai
commit
e91955d8c2

+ 2 - 14
app/Http/Controllers/Wap/Pay/OrdersController.php

@@ -42,6 +42,7 @@ use App\Modules\Activity\Services\ActivityService;
 use App\Modules\SendOrder\Services\SendOrderService;
 use App\Modules\Subscribe\Models\Order;
 use App\Modules\Trade\Models\PayMerchant;
+use App\Modules\Trade\Pay\PayWait;
 use GuzzleHttp\Client;
 
 class OrdersController extends Controller
@@ -970,23 +971,10 @@ class OrdersController extends Controller
                     if (!$bind_info) {
                         $page = 'pay.order.bindPhone';
                     }
-                    $url = urldecode($request->input('redirect'));
                     return view($page, compact('order', 'url', 'from'));
                 }
             } else {
-                $url = urldecode($request->input('redirect'));
-                if (strpos($url, '/reader') !== false) {
-                    preg_match('/bid=(\w+)/', $url, $matchs);
-                    $bid = Hashids::decode($matchs[1])[0];
-                    $record =  ReadRecordService::getRecordByUidBid($uid, $bid);
-                    if ($record) {
-                        $cid = explode('_', $record)[0];
-                        $url = preg_replace('/cid=(\d+)/', 'cid=' . $cid, $url);
-                    } else {
-                        $url = preg_replace(['/bid=(\w+)/', '/\/reader\?/'], ['', '/catalog?id=' . $matchs[1] . '&'], $url);
-                    }
-                    Log::info('reader_url :' . $url);
-                }
+                $url = PayWait::getReaderWaitUrl($uid, $url);
                 return redirect($url);
             }
         }

+ 59 - 0
app/Modules/Trade/Pay/PayWait.php

@@ -0,0 +1,59 @@
+<?php
+
+namespace App\Modules\Trade\Pay;
+
+use App\Modules\User\Services\ReadRecordService;
+use Hashids;
+use Log;
+
+
+/**
+ * 充值等待
+ * 
+ * @property int $uid 
+ * @method static string getReaderWaitUrl(int $uid, string $url) 获取支付跳转地址
+ */
+class PayWait
+{
+    private $uid;
+
+    private static $_instatnce;
+
+    /**
+     * $arguments 第一个参数默认$uid
+     */
+    public function __callStatic($name, $arguments)
+    {
+        if (!self::$_instatnce) {
+            self::$_instatnce = new PayWait($arguments[0]);
+        }
+        $args = array_shift($arguments);
+        self::$_instatnce->$name(...$args);
+    }
+
+    public function __construct(int $uid)
+    {
+        $this->uid = $uid;
+    }
+
+    /**
+     * 获取支付跳转地址
+     * @param string $url 前端传入的阅读器地址
+     */
+    protected function getReaderWaitUrl(string $url)
+    {
+        if (strpos($url, '/reader') !== false) {
+            preg_match('/bid=(\w+)/', $url, $matchs);
+            $bid = Hashids::decode($matchs[1])[0];
+            $record =  ReadRecordService::getRecordByUidBid($this->uid, $bid);
+            if ($record) {
+                $cid = explode('_', $record)[0];
+                $url = preg_replace('/cid=(\d+)/', 'cid=' . $cid, $url);
+            } else {
+                $url = preg_replace(['/bid=(\w+)/', '/\/reader\?/'], ['', '/catalog?id=' . $matchs[1] . '&'], $url);
+            }
+            Log::info('reader_url :' . $url);
+        }
+        return $url;
+    }
+}