Quellcode durchsuchen

Remove PingLog & Fix temporary ping api & Improve code

兔姬桑 vor 4 Jahren
Ursprung
Commit
88ca3c2d87
32 geänderte Dateien mit 136 neuen und 349 gelöschten Zeilen
  1. 20 0
      app/Components/Helpers.php
  2. 36 12
      app/Components/NetworkDetection.php
  3. 8 35
      app/Console/Commands/AutoJob.php
  4. 0 47
      app/Console/Commands/AutoPingNode.php
  5. 3 23
      app/Console/Commands/DailyJob.php
  6. 1 1
      app/Console/Commands/NodeBlockedDetection.php
  7. 0 3
      app/Console/Kernel.php
  8. 1 1
      app/Http/Controllers/Admin/NodeAuthController.php
  9. 2 23
      app/Http/Controllers/Admin/NodeController.php
  10. 1 1
      app/Http/Controllers/Gateway/CodePay.php
  11. 1 1
      app/Http/Controllers/Gateway/EPay.php
  12. 1 1
      app/Http/Controllers/Gateway/PayJs.php
  13. 2 2
      app/Http/Controllers/Gateway/PayPal.php
  14. 2 2
      app/Http/Controllers/Gateway/Stripe.php
  15. 1 1
      app/Http/Controllers/PaymentController.php
  16. 2 21
      app/Http/Controllers/UserController.php
  17. 0 5
      app/Models/Node.php
  18. 0 20
      app/Models/NodePing.php
  19. 20 0
      app/Models/Order.php
  20. 10 0
      app/Models/Payment.php
  21. 1 1
      app/Observers/OrderObserver.php
  22. 1 1
      app/Services/OrderService.php
  23. 0 36
      database/migrations/2020_08_21_145711_create_node_ping_table.php
  24. 0 8
      database/migrations/2020_11_10_075555_improve_table.php
  25. 0 4
      database/migrations/2020_12_24_074739_table_improvement.php
  26. 20 0
      database/migrations/2021_01_04_094946_drop_node_ping.php
  27. 1 8
      resources/views/admin/layouts.blade.php
  28. 1 3
      resources/views/admin/node/index.blade.php
  29. 0 80
      resources/views/admin/node/ping.blade.php
  30. 1 1
      resources/views/user/layouts.blade.php
  31. 0 7
      resources/views/user/nodeList.blade.php
  32. 0 1
      routes/admin.php

+ 20 - 0
app/Components/Helpers.php

@@ -7,6 +7,7 @@ use App\Models\CouponLog;
 use App\Models\NotificationLog;
 use App\Models\SsConfig;
 use App\Models\User;
+use App\Models\UserBanedLog;
 use App\Models\UserCreditLog;
 use App\Models\UserDataModifyLog;
 use App\Models\UserSubscribe;
@@ -252,4 +253,23 @@ class Helpers
 
         return $log->save();
     }
+
+    /**
+     * 添加用户封禁日志.
+     *
+     * @param  int  $userId  用户ID
+     * @param  int  $time  封禁时长,单位分钟
+     * @param  string  $description  封禁理由
+     *
+     * @return bool
+     */
+    public static function addUserBanLog(int $userId, int $time, string $description)
+    {
+        $log = new UserBanedLog();
+        $log->user_id = $userId;
+        $log->time = $time;
+        $log->description = $description;
+
+        return $log->save();
+    }
 }

+ 36 - 12
app/Components/NetworkDetection.php

@@ -14,23 +14,47 @@ class NetworkDetection
      *
      * @return bool|array
      */
-    public static function ping(string $ip)
+    public function ping(string $ip)
     {
-        $url = 'https://api.oioweb.cn/api/hostping.php?host='.$ip; // https://api.iiwl.cc/api/ping.php?host=
-        $response = Http::timeout(15)->retry(2)->get($url);
+        $round = 0;
+        // 依次尝试接口
+        while (true) {
+            switch ($round) {
+                case 0:
+                    $ret = $this->oiowebPing($ip);
+                    break;
+                default:
+                    return false;
+            }
+            if ($ret !== false) {
+                return $ret;
+            }
+            $round++;
+        }
+    }
 
-        // 发送成功
-        if ($response->ok()) {
-            $message = $response->json();
-            if ($message && $message['code']) {
-                return $message['data'];
+    private function oiowebPing(string $ip)
+    {
+        $msg = null;
+        foreach ([1, 6, 14] as $line) {
+            $url = "https://api.oioweb.cn/api/hostping.php?host={$ip}&node={$line}"; // https://api.iiwl.cc/api/ping.php?host=
+            $response = Http::timeout(15)->get($url);
+
+            // 发送成功
+            if ($response->ok()) {
+                $message = $response->json();
+                if ($message && $message['code']) {
+                    $msg .= "{$message['node']}:{$message['data']['Time']}<br>";
+                }
+            } else {
+                return false;
             }
-            // 发送失败
-            Log::warning('【PING】检测'.$ip.'时,返回'.var_export($message, true));
+        }
 
-            return false;
+        if ($msg) {
+            return $msg;
         }
-        Log::warning('【PING】检测'.$ip.'时,接口返回异常访问链接:'.$url);
+        Log::warning('【PING】检测'.$ip.'时,api.oioweb.cn无结果');
 
         // 发送错误
         return false;

+ 8 - 35
app/Console/Commands/AutoJob.php

@@ -11,7 +11,6 @@ use App\Models\Node;
 use App\Models\NodeHeartBeat;
 use App\Models\Order;
 use App\Models\User;
-use App\Models\UserBanedLog;
 use App\Models\VerifyCode;
 use Cache;
 use Illuminate\Console\Command;
@@ -30,7 +29,7 @@ class AutoJob extends Command
         $jobStartTime = microtime(true);
 
         // 关闭超时未支付本地订单
-        $this->closeOrders();
+        Order::query()->recentUnPay()->update(['status' => -1]);
 
         //过期验证码、优惠券、邀请码无效化
         $this->expireCode();
@@ -63,16 +62,6 @@ class AutoJob extends Command
         Log::info('---【'.$this->description.'】完成---,耗时'.$jobUsedTime.'秒');
     }
 
-    // 关闭超时未支付本地订单
-    private function closeOrders(): void
-    {
-        // 关闭超时未支付的本地支付订单
-        foreach (Order::recentUnPay()->get() as $order) {
-            // 关闭订单
-            $order->update(['status' => -1]);
-        }
-    }
-
     // 注册验证码自动置无效 & 优惠券无效化
     private function expireCode(): void
     {
@@ -108,28 +97,12 @@ class AutoJob extends Command
                     ]);
 
                     // 记录封禁日志
-                    $this->addUserBanLog($user->id, 0, '【完全封禁订阅】-订阅24小时内请求异常');
+                    Helpers::addUserBanLog($user->id, 0, '【完全封禁订阅】-订阅24小时内请求异常');
                 }
             }
         }
     }
 
-    /**
-     * 添加用户封禁日志.
-     *
-     * @param  int  $userId  用户ID
-     * @param  int  $time  封禁时长,单位分钟
-     * @param  string  $description  封禁理由
-     */
-    private function addUserBanLog(int $userId, int $time, string $description): void
-    {
-        $log = new UserBanedLog();
-        $log->user_id = $userId;
-        $log->time = $time;
-        $log->description = $description;
-        $log->save();
-    }
-
     // 封禁账号
     private function blockUsers(): void
     {
@@ -138,7 +111,7 @@ class AutoJob extends Command
             $user->update(['enable' => 0]);
 
             // 写入日志
-            $this->addUserBanLog($user->id, 0, '【封禁代理】-流量已用完');
+            Helpers::addUserBanLog($user->id, 0, '【封禁代理】-流量已用完');
         }
 
         // 封禁1小时内流量异常账号
@@ -153,7 +126,7 @@ class AutoJob extends Command
                     ]);
 
                     // 写入日志
-                    $this->addUserBanLog($user->id, $trafficBanTime, '【临时封禁代理】-1小时内流量异常');
+                    Helpers::addUserBanLog($user->id, $trafficBanTime, '【临时封禁代理】-1小时内流量异常');
                 }
             }
         }
@@ -169,7 +142,7 @@ class AutoJob extends Command
                 $user->update(['enable' => 1, 'ban_time' => null]);
 
                 // 写入操作日志
-                $this->addUserBanLog($user->id, 0, '【自动解封】-临时封禁到期');
+                Helpers::addUserBanLog($user->id, 0, '【自动解封】-临时封禁到期');
             }
         }
 
@@ -184,7 +157,7 @@ class AutoJob extends Command
             $user->update(['enable' => 1]);
 
             // 写入操作日志
-            $this->addUserBanLog($user->id, 0, '【自动解封】-有流量解封');
+            Helpers::addUserBanLog($user->id, 0, '【自动解封】-有流量解封');
         }
     }
 
@@ -192,9 +165,9 @@ class AutoJob extends Command
     private function dispatchPort(): void
     {
         // 自动分配端口
-        foreach (User::activeUser()->wherePort(0)->get() as $user) {
+        User::activeUser()->wherePort(0)->get()->each(function ($user) {
             $user->update(['port' => Helpers::getPort()]);
-        }
+        });
 
         // 被封禁 / 过期一个月 的账号自动释放端口
         User::where('port', '<>', 0)

+ 0 - 47
app/Console/Commands/AutoPingNode.php

@@ -1,47 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use App\Components\NetworkDetection;
-use App\Models\Node;
-use App\Models\NodePing;
-use Illuminate\Console\Command;
-use Log;
-
-class AutoPingNode extends Command
-{
-    protected $signature = 'autoPingNode';
-    protected $description = '节点定时Ping测速';
-
-    public function handle(): void
-    {
-        $jobStartTime = microtime(true);
-
-        foreach (Node::whereIsRelay(0)->whereStatus(1)->get() as $node) {
-            $this->pingNode($node->id, $node->is_ddns ? $node->server : $node->ip);
-        }
-
-        $jobEndTime = microtime(true);
-        $jobUsedTime = round(($jobEndTime - $jobStartTime), 4);
-
-        Log::info('---【'.$this->description.'】完成---,耗时'.$jobUsedTime.'秒');
-    }
-
-    // 节点Ping测速
-    private function pingNode($nodeId, $ip): void
-    {
-        $result = NetworkDetection::ping($ip);
-
-        if ($result) {
-            $obj = new NodePing();
-            $obj->node_id = $nodeId;
-            $obj->ct = (int) $result['telecom']['time']; //电信
-            $obj->cu = (int) $result['Unicom']['time']; // 联通
-            $obj->cm = (int) $result['move']['time']; // 移动
-            $obj->hk = (int) $result['HongKong']['time']; // 香港
-            $obj->save();
-        } else {
-            Log::error('【'.$ip.'】Ping测速获取失败');
-        }
-    }
-}

+ 3 - 23
app/Console/Commands/DailyJob.php

@@ -4,11 +4,9 @@ namespace App\Console\Commands;
 
 use App\Components\Helpers;
 use App\Components\PushNotification;
-use App\Models\Invite;
 use App\Models\Order;
 use App\Models\Ticket;
 use App\Models\User;
-use App\Models\UserBanedLog;
 use App\Services\OrderService;
 use Illuminate\Console\Command;
 use Log;
@@ -57,10 +55,10 @@ class DailyJob extends Command
                     'status' => -1,
                 ]);
 
-                $this->addUserBanLog($user->id, 0, '【禁止登录,清空账户】-账号已过期');
+                Helpers::addUserBanLog($user->id, 0, '【禁止登录,清空账户】-账号已过期');
 
                 // 废除其名下邀请码
-                Invite::whereInviterId($user->id)->whereStatus(0)->update(['status' => 2]);
+                $user->invites()->whereStatus(0)->update(['status' => 2]);
 
                 // 写入用户流量变动记录
                 Helpers::addUserTrafficModifyLog($user->id, null, $user->transfer_enable, 0, '[定时任务]账号已过期(禁止登录,清空账户)');
@@ -75,7 +73,7 @@ class DailyJob extends Command
                     'ban_time' => null,
                 ]);
 
-                $this->addUserBanLog($user->id, 0, '【封禁代理,清空账户】-账号已过期');
+                Helpers::addUserBanLog($user->id, 0, '【封禁代理,清空账户】-账号已过期');
 
                 // 写入用户流量变动记录
                 Helpers::addUserTrafficModifyLog($user->id, null, $user->transfer_enable, 0, '[定时任务]账号已过期(封禁代理,清空账户)');
@@ -83,24 +81,6 @@ class DailyJob extends Command
         }
     }
 
-    /**
-     * 添加用户封禁日志.
-     *
-     * @param  int  $userId  用户ID
-     * @param  int  $time  封禁时长,单位分钟
-     * @param  string  $description  封禁理由
-     * @return bool
-     */
-    private function addUserBanLog(int $userId, int $time, string $description): bool
-    {
-        $log = new UserBanedLog();
-        $log->user_id = $userId;
-        $log->time = $time;
-        $log->description = $description;
-
-        return $log->save();
-    }
-
     // 关闭超过72小时未处理的工单
     private function closeTickets(): void
     {

+ 1 - 1
app/Console/Commands/NodeBlockedDetection.php

@@ -92,7 +92,7 @@ class NodeBlockedDetection extends Command
                     Cache::increment($cacheKey);
                 } else {
                     Cache::forget($cacheKey);
-                    Node::find($node->id)->update(['status' => 0]);
+                    $node->update(['status' => 0]);
                     $additionalMessage .= "\r\n节点【{$node->name}】自动进入维护状态\r\n";
                 }
             }

+ 0 - 3
app/Console/Kernel.php

@@ -4,7 +4,6 @@ namespace App\Console;
 
 use App\Console\Commands\AutoClearLog;
 use App\Console\Commands\AutoJob;
-use App\Console\Commands\AutoPingNode;
 use App\Console\Commands\AutoReportNode;
 use App\Console\Commands\AutoStatisticsNodeDailyTraffic;
 use App\Console\Commands\AutoStatisticsNodeHourlyTraffic;
@@ -29,7 +28,6 @@ class Kernel extends ConsoleKernel
     protected $commands = [
         AutoClearLog::class,
         AutoJob::class,
-        AutoPingNode::class,
         AutoReportNode::class,
         AutoStatisticsNodeDailyTraffic::class,
         AutoStatisticsNodeHourlyTraffic::class,
@@ -58,7 +56,6 @@ class Kernel extends ConsoleKernel
         $schedule->command('autoStatisticsNodeHourlyTraffic')->hourly();
         $schedule->command('autoStatisticsUserHourlyTraffic')->hourly();
         $schedule->command('userTrafficAbnormalAutoWarning')->hourly();
-        $schedule->command('autoPingNode')->twiceDaily();
         $schedule->command('dailyJob')->daily();
         $schedule->command('autoReportNode')->dailyAt('09:00');
         $schedule->command('userTrafficAutoWarning')->dailyAt('10:30');

+ 1 - 1
app/Http/Controllers/Admin/NodeAuthController.php

@@ -25,7 +25,7 @@ class NodeAuthController extends Controller
         if ($nodes->isEmpty()) {
             return Response::json(['status' => 'success', 'message' => '没有需要生成授权的节点']);
         }
-        $nodes->each(static function ($node) {
+        $nodes->each(function ($node) {
             $node->auth()->create(['key' => Str::random(), 'secret' => Str::random(8)]);
         });
 

+ 2 - 23
app/Http/Controllers/Admin/NodeController.php

@@ -11,7 +11,6 @@ use App\Models\Label;
 use App\Models\Level;
 use App\Models\Node;
 use App\Models\NodeCertificate;
-use App\Models\NodePing;
 use App\Models\RuleGroup;
 use App\Services\NodeService;
 use Arr;
@@ -185,33 +184,13 @@ class NodeController extends Controller
     // Ping节点延迟
     public function pingNode(Node $node): JsonResponse
     {
-        if ($result = NetworkDetection::ping($node->is_ddns ? $node->server : $node->ip)) {
+        if ($result = (new NetworkDetection)->ping($node->is_ddns ? $node->server : $node->ip)) {
             return Response::json([
                 'status' => 'success',
-                'message' => [
-                    $result['telecom']['time'] ?: '无', //电信
-                    $result['Unicom']['time'] ?: '无', // 联通
-                    $result['move']['time'] ?: '无', // 移动
-                    $result['HongKong']['time'] ?: '无', // 香港
-                ],
+                'message' => $result,
             ]);
         }
 
         return Response::json(['status' => 'fail', 'message' => 'Ping访问失败']);
     }
-
-    // Ping节点延迟日志
-    public function pingLog(Request $request)
-    {
-        $node_id = $request->input('id');
-        $query = NodePing::query();
-        if (isset($node_id)) {
-            $query->whereNodeId($node_id);
-        }
-
-        return view('admin.node.ping', [
-            'nodeList' => Node::orderBy('id')->get(),
-            'pingLogs' => $query->latest()->paginate(15)->appends($request->except('page')),
-        ]);
-    }
 }

+ 1 - 1
app/Http/Controllers/Gateway/CodePay.php

@@ -38,7 +38,7 @@ class CodePay extends AbstractPayment
             && $this->verify($request->except('method'), sysConfig('codepay_key'), $request->input('sign'), false)) {
             $payment = Payment::whereTradeNo($trade_no)->first();
             if ($payment) {
-                $ret = $payment->order->update(['status' => 2]);
+                $ret = $payment->order->complete();
                 if ($ret) {
                     exit('success');
                 }

+ 1 - 1
app/Http/Controllers/Gateway/EPay.php

@@ -52,7 +52,7 @@ class EPay extends AbstractPayment
             && $this->verify($request->except('method'), sysConfig('epay_key'), $request->input('sign'))) {
             $payment = Payment::whereTradeNo($request->input('out_trade_no'))->first();
             if ($payment) {
-                $ret = $payment->order->update(['status' => 2]);
+                $ret = $payment->order->complete();
                 if ($ret) {
                     exit('SUCCESS');
                 }

+ 1 - 1
app/Http/Controllers/Gateway/PayJs.php

@@ -45,7 +45,7 @@ class PayJs extends AbstractPayment
         if ($data['return_code'] == 1) {
             $payment = Payment::whereTradeNo($data['out_trade_no'])->first();
             if ($payment) {
-                $ret = $payment->order->update(['status' => 2]);
+                $ret = $payment->order->complete();
                 if ($ret) {
                     exit('success');
                 }

+ 2 - 2
app/Http/Controllers/Gateway/PayPal.php

@@ -102,7 +102,7 @@ class PayPal extends AbstractPayment
 
             if (! strcasecmp($status, 'Completed') || ! strcasecmp($status, 'Processed')) {
                 Log::info("Order $payment->order_id has been paid successfully!");
-                $payment->order->update(['status' => 1]);
+                $payment->order->paid();
             } else {
                 Log::warning("Error processing PayPal payment for Order $payment->id!");
             }
@@ -126,7 +126,7 @@ class PayPal extends AbstractPayment
         if ($response === 'VERIFIED' && $request['invoice']) {
             $payment = Payment::whereTradeNo($request['invoice'])->first();
             if ($payment && $payment->status === 0) {
-                $ret = $payment->order->update(['status' => 2]);
+                $ret = $payment->order->complete();
                 if ($ret) {
                     exit('success');
                 }

+ 2 - 2
app/Http/Controllers/Gateway/Stripe.php

@@ -126,7 +126,7 @@ class Stripe extends AbstractPayment
     {
         $payment = Payment::whereTradeNo($session->client_reference_id)->first();
         if ($payment) {
-            $payment->order->update(['status' => 2]);
+            $payment->order->complete();
         }
     }
 
@@ -135,7 +135,7 @@ class Stripe extends AbstractPayment
     {
         $payment = Payment::whereTradeNo($session->client_reference_id)->first();
         if ($payment) {
-            $payment->order->update(['status' => -1]);
+            $payment->order->close();
         }
     }
 }

+ 1 - 1
app/Http/Controllers/PaymentController.php

@@ -197,7 +197,7 @@ class PaymentController extends Controller
 
     public function close(Order $order): JsonResponse
     {
-        if (! $order->update(['status' => -1])) {
+        if (! $order->close()) {
             return Response::json(['status' => 'fail', 'message' => '关闭订单失败']);
         }
 

+ 2 - 21
app/Http/Controllers/UserController.php

@@ -12,10 +12,8 @@ use App\Models\Goods;
 use App\Models\Invite;
 use App\Models\Node;
 use App\Models\NodeHeartBeat;
-use App\Models\NodePing;
 use App\Models\Order;
 use App\Models\Ticket;
-use App\Models\TicketReply;
 use Cache;
 use DB;
 use Exception;
@@ -118,14 +116,7 @@ class UserController extends Controller
         // 获取当前用户可用节点
         $nodeList = $user->nodes()->with(['labels', 'level_table'])->get();
         $onlineNode = NodeHeartBeat::recently()->distinct()->pluck('node_id')->toArray();
-        $pingNodeLogs = NodePing::whereMonth('created_at', date('m'))->get(['node_id', 'ct', 'cu', 'cm', 'hk']);
         foreach ($nodeList as $node) {
-            $data = $pingNodeLogs->where('node_id', $node->id);
-            $node->ct = round($data->pluck('ct')->filter()->avg(), 2);
-            $node->cu = round($data->pluck('cu')->filter()->avg(), 2);
-            $node->cm = round($data->pluck('cm')->filter()->avg(), 2);
-            $node->hk = round($data->pluck('hk')->filter()->avg(), 2);
-
             // 节点在线状态
             $node->offline = ! in_array($node->id, $onlineNode, true);
         }
@@ -291,12 +282,7 @@ class UserController extends Controller
             return Response::json(['status' => 'fail', 'message' => '请输入标题和内容']);
         }
 
-        $obj = new Ticket();
-        $obj->user_id = $user->id;
-        $obj->title = $title;
-        $obj->content = $content;
-
-        if ($obj->save()) {
+        if ($user->tickets()->create(['title' => $title, 'content' => $content])) {
             $emailTitle = '新工单提醒';
             $content = '标题:【'.$title.'】<br>用户:'.$user->email.'<br>内容:'.$content;
 
@@ -332,12 +318,7 @@ class UserController extends Controller
                 return Response::json(['status' => 'fail', 'message' => '错误:该工单已关闭']);
             }
 
-            $obj = new TicketReply();
-            $obj->ticket_id = $id;
-            $obj->user_id = auth()->user()->id;
-            $obj->content = $content;
-
-            if ($obj->save()) {
+            if ($ticket->reply()->create(['user_id' => auth()->id(), 'content' => $content])) {
                 // 重新打开工单
                 $ticket->status = 0;
                 $ticket->save();

+ 0 - 5
app/Models/Node.php

@@ -46,11 +46,6 @@ class Node extends Model
         return $this->hasMany(RuleLog::class);
     }
 
-    public function pingLogs(): HasMany
-    {
-        return $this->hasMany(NodePing::class);
-    }
-
     public function dailyDataFlows(): HasMany
     {
         return $this->hasMany(NodeDailyDataFlow::class);

+ 0 - 20
app/Models/NodePing.php

@@ -1,20 +0,0 @@
-<?php
-
-namespace App\Models;
-
-use Illuminate\Database\Eloquent\Model;
-use Illuminate\Database\Eloquent\Relations\BelongsTo;
-
-/**
- * 节点定时Ping测速
- */
-class NodePing extends Model
-{
-    public const UPDATED_AT = null;
-    protected $table = 'node_ping';
-
-    public function node(): BelongsTo
-    {
-        return $this->belongsTo(Node::class);
-    }
-}

+ 20 - 0
app/Models/Order.php

@@ -80,6 +80,26 @@ class Order extends Model
         return $query->uid($uid)->activePackage();
     }
 
+    public function close() // 关闭订单
+    {
+        return $this->update(['status' => -1]);
+    }
+
+    public function paid() // 完成订单
+    {
+        return $this->update(['status' => 1]);
+    }
+
+    public function complete() // 完成订单
+    {
+        return $this->update(['status' => 2]);
+    }
+
+    public function prepay() // 预支付订单
+    {
+        return $this->update(['status' => 3]);
+    }
+
     // 订单状态
     public function getStatusLabelAttribute(): string
     {

+ 10 - 0
app/Models/Payment.php

@@ -29,6 +29,16 @@ class Payment extends Model
         return $this->belongsTo(Order::class);
     }
 
+    public function close() // 关闭支付单
+    {
+        return $this->update(['status' => -1]);
+    }
+
+    public function complete() // 完成支付单
+    {
+        return $this->update(['status' => 1]);
+    }
+
     public function getAmountAttribute($value)
     {
         return $value / 100;

+ 1 - 1
app/Observers/OrderObserver.php

@@ -19,7 +19,7 @@ class OrderObserver
                 $payment = $order->payment;
                 if ($payment) {
                     // 关闭在线订单
-                    $payment->update(['status' => -1]);
+                    $payment->close();
                     // 退回优惠券
                     if ($order->coupon_id && $this->returnCoupon($order->coupon)) {
                         Helpers::addCouponLog('订单超时未支付,自动退回', $order->coupon_id, $order->goods_id, $order->id);

+ 1 - 1
app/Services/OrderService.php

@@ -31,7 +31,7 @@ class OrderService
             if (self::$payment->status === 1) {// 已处理
                 return true;
             }
-            self::$payment->update(['status' => 1]);
+            self::$payment->complete();
 
             // 余额充值
             if (self::$order->goods_id === 0 || self::$order->goods_id === null) {

+ 0 - 36
database/migrations/2020_08_21_145711_create_node_ping_table.php

@@ -1,36 +0,0 @@
-<?php
-
-use Illuminate\Database\Migrations\Migration;
-use Illuminate\Database\Schema\Blueprint;
-use Illuminate\Support\Facades\Schema;
-
-class CreateNodePingTable extends Migration
-{
-    /**
-     * Run the migrations.
-     *
-     * @return void
-     */
-    public function up()
-    {
-        Schema::create('node_ping', function (Blueprint $table) {
-            $table->increments('id');
-            $table->unsignedInteger('node_id')->default(0)->index()->comment('对应节点id');
-            $table->integer('ct')->default(0)->comment('电信');
-            $table->integer('cu')->default(0)->comment('联通');
-            $table->integer('cm')->default(0)->comment('移动');
-            $table->integer('hk')->default(0)->comment('香港');
-            $table->dateTime('created_at')->comment('创建时间');
-        });
-    }
-
-    /**
-     * Reverse the migrations.
-     *
-     * @return void
-     */
-    public function down()
-    {
-        Schema::dropIfExists('node_ping');
-    }
-}

+ 0 - 8
database/migrations/2020_11_10_075555_improve_table.php

@@ -60,10 +60,6 @@ class ImproveTable extends Migration
             $table->foreign('label_id')->references('id')->on('label')->cascadeOnDelete();
         });
 
-        Schema::table('node_ping', function (Blueprint $table) {
-            $table->foreign('node_id')->references('id')->on('ss_node')->cascadeOnDelete();
-        });
-
         Schema::table('node_rule', function (Blueprint $table) {
             $table->index(['node_id', 'rule_id']);
             $table->foreign('node_id')->references('id')->on('ss_node')->cascadeOnDelete();
@@ -279,10 +275,6 @@ class ImproveTable extends Migration
             $table->dropIndex('node_label_label_id_foreign');
         });
 
-        Schema::table('node_ping', function (Blueprint $table) {
-            $table->dropForeign(['node_id']);
-        });
-
         Schema::table('node_rule', function (Blueprint $table) {
             $table->dropForeign(['node_id']);
             $table->dropForeign(['rule_id']);

+ 0 - 4
database/migrations/2020_12_24_074739_table_improvement.php

@@ -56,10 +56,6 @@ class TableImprovement extends Migration
             $table->rename('label_node');
         });
 
-        Schema::table('node_ping', function (Blueprint $table) {
-            $table->unsignedInteger('node_id')->comment('对应节点ID')->change();
-        });
-
         Order::whereGoodsId(0)->update(['goods_id' => null]);
         Order::whereCouponId(0)->orWhereNotIn('coupon_id', Coupon::withTrashed()->pluck('id')->toArray())->update(['coupon_id' => null]);
         Schema::table('order', function (Blueprint $table) {

+ 20 - 0
database/migrations/2021_01_04_094946_drop_node_ping.php

@@ -0,0 +1,20 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+use Spatie\Permission\Models\Permission;
+
+class DropNodePing extends Migration
+{
+    public function up()
+    {
+        Schema::dropIfExists('node_ping');
+        Permission::findByName('admin.node.pingLog')->delete();
+    }
+
+    public function down()
+    {
+        //
+    }
+}

+ 1 - 8
resources/views/admin/layouts.blade.php

@@ -186,7 +186,7 @@
                         </ul>
                     </li>
                 @endcanany
-                @canany(['admin.node.index', 'admin.node.auth.index', 'admin.node.cert.index', 'admin.node.pingLog'])
+                @canany(['admin.node.index', 'admin.node.auth.index', 'admin.node.cert.index'])
                     <li class="site-menu-item has-sub {{request()->routeIs('admin.node.*') ? 'active open' : ''}}">
                         <a href="javascript:void(0)">
                             <i class="site-menu-icon wb-grid-4" aria-hidden="true"></i>
@@ -214,13 +214,6 @@
                                     </a>
                                 </li>
                             @endcan
-                            @can('admin.node.pingLog')
-                                <li class="site-menu-item {{request()->routeIs('admin.node.pingLog') ? 'active open' : ''}}">
-                                    <a href="{{route('admin.node.pingLog')}}">
-                                        <span class="site-menu-title">测速日志</span>
-                                    </a>
-                                </li>
-                            @endcan
                         </ul>
                     </li>
                 @endcanany

+ 1 - 3
resources/views/admin/node/index.blade.php

@@ -198,9 +198,7 @@
               if (ret.status === 'success') {
                 swal.fire({
                   icon: 'info',
-                  html: '<table class="my-20"><thead class="thead-default"><tr><th> 电信 </th> <th> 联通 </th> <th> 移动 </th> <th> 香港 </th></thead><tbody><tr><td>' +
-                      ret.message[0] + '</td><td>' + ret.message[1] + '</td><td>' + ret.message[2] + '</td><td>' +
-                      ret.message[3] + '</td></tr></tbody></table>',
+                  html: ret.message,
                   showConfirmButton: false,
                 });
               } else {

+ 0 - 80
resources/views/admin/node/ping.blade.php

@@ -1,80 +0,0 @@
-@extends('admin.layouts')
-@section('css')
-    <link href="/assets/global/vendor/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
-@endsection
-@section('content')
-    <div class="page-content container-fluid">
-        <div class="panel">
-            <div class="panel-heading">
-                <h2 class="panel-title">线路Ping测速日志</h2>
-            </div>
-            <div class="panel-body">
-                <div class="form-row">
-                    <div class="form-group col-lg-2 col-sm-5">
-                        <select name="nodeId" id="nodeId" class="form-control" onChange="Search()">
-                            <option value="" @if(Request::input('nodeId') === '') selected @endif hidden>选择节点</option>
-                            @foreach($nodeList as $node)
-                                <option value="{{$node->id}}" @if((int) Request::input('nodeId') === $node->id) selected @endif>
-                                    {{$node->name}}
-                                </option>
-                            @endforeach
-                        </select>
-                    </div>
-                    <div class="form-group col-lg-1 col-sm-4 btn-group">
-                        <button class="btn btn-primary" onclick="Search()">搜 索</button>
-                        <a href="{{route('admin.node.pingLog')}}" class="btn btn-danger">重 置</a>
-                    </div>
-                </div>
-                <table class="text-md-center" data-toggle="table" data-mobile-responsive="true">
-                    <thead class="thead-default">
-                    <tr>
-                        <th rowspan="2"> #</th>
-                        <th rowspan="2"> 节点</th>
-                        <th colspan="4"> 速度</th>
-                    </tr>
-                    <tr>
-                        <th>电信</th>
-                        <th>联通</th>
-                        <th>移动</th>
-                        <th>香港</th>
-                    </tr>
-                    </thead>
-                    <tbody>
-                    @foreach($pingLogs as $log)
-                        <tr>
-                            <td> {{$log->id}} </td>
-                            <td> {{$log->node->name}} </td>
-                            <td> {{$log->ct? $log->ct.' ms': '无'}} </td>
-                            <td> {{$log->cu? $log->cu.' ms': '无'}} </td>
-                            <td> {{$log->cm? $log->cm.' ms': '无'}} </td>
-                            <td> {{$log->hk? $log->hk.' ms': '无'}} </td>
-                        </tr>
-                    @endforeach
-                    </tbody>
-                </table>
-            </div>
-            <div class="panel-footer">
-                <div class="row">
-                    <div class="col-sm-4">
-                        共 <code>{{$pingLogs->total()}}</code> 条记录
-                    </div>
-                    <div class="col-sm-8">
-                        <nav class="Page navigation float-right">
-                            {{$pingLogs->links()}}
-                        </nav>
-                    </div>
-                </div>
-            </div>
-        </div>
-    </div>
-@endsection
-@section('javascript')
-    <script src="/assets/global/vendor/bootstrap-table/bootstrap-table.min.js"></script>
-    <script src="/assets/global/vendor/bootstrap-table/extensions/mobile/bootstrap-table-mobile.min.js"></script>
-    <script>
-      // 搜索
-      function Search() {
-        window.location.href = '{{route('admin.node.pingLog')}}?&nodeId=' + $('#nodeId option:selected').val();
-      }
-    </script>
-@endsection

+ 1 - 1
resources/views/user/layouts.blade.php

@@ -123,7 +123,7 @@
                     </a>
                 </li>
                 @php
-                    $openTicket = App\Models\Ticket::uid()->whereStatus(1)->count()
+                    $openTicket = auth()->user()->tickets()->where('status','<>',2)->count()
                 @endphp
                 <li class="site-menu-item {{request()->routeIs('ticket', 'replyTicket') ? 'active open' : ''}}">
                     <a href="{{route('ticket')}}">

+ 0 - 7
resources/views/user/nodeList.blade.php

@@ -96,13 +96,6 @@
                                         <i id="text{{$node->id}}" class="icon fa-list"></i>
                                     </button>
                                 </p>
-                                <p class="text-muted">
-                                    <span>电信: {{$node->ct>0 ?$node->ct.' ms' :'无数据'}} </span>
-                                    <span>联通: {{$node->cu>0 ?$node->cu.' ms' :'无数据'}} </span>
-                                    <br>
-                                    <span>移动: {{$node->cm>0 ?$node->cm.' ms' :'无数据'}} </span>
-                                    <span>香港: {{$node->hk>0 ?$node->hk.' ms' :'无数据'}} </span>
-                                </p>
                             </div>
                         </div>
                     </div>

+ 0 - 1
routes/admin.php

@@ -41,7 +41,6 @@ Route::prefix('admin')->name('admin.')->group(function () {
             Route::get('monitor/{node}', 'NodeController@nodeMonitor')->name('monitor'); // 节点流量监控
             Route::post('check/{node}', 'NodeController@checkNode')->name('check'); // 节点阻断检测
             Route::post('ping/{node}', 'NodeController@pingNode')->name('ping'); // 节点ping测速
-            Route::get('pingLog', 'NodeController@pingLog')->name('pingLog'); // 节点Ping测速日志
             Route::get('refreshGeo/{id}', 'NodeController@refreshGeo')->name('geo'); // 更新节点
             Route::post('reload/{node}', 'NodeController@reload')->name('reload'); // 更新节点