Просмотр исходного кода

1.加入用户流量变动日志
2.加入IPIP的IP库

admin 7 лет назад
Родитель
Сommit
b6438cadf8

+ 28 - 0
app/Components/IPIP.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace App\Components;
+
+use ipip\db\Reader;
+
+class IPIP
+{
+    /**
+     * 查询IP地址的详细信息
+     *
+     * @param string $ip IPv4
+     *
+     * @return \ipip\db\Info|null
+     * @throws \Exception
+     */
+    public function ip($ip)
+    {
+        $filePath = storage_path('ipip.ipdb');
+
+        $db = new Reader($filePath);
+        //$loc = $db->find($ip);
+        //$loc = $db->findMap($ip);
+        $loc = $db->findInfo($ip);
+
+        return $loc;
+    }
+}

+ 11 - 11
app/Console/Commands/AutoCheckNodeStatus.php

@@ -64,18 +64,18 @@ class AutoCheckNodeStatus extends Command
                         $text = '正常';
                 }
 
-                // 已通知次数
-                $cacheKey = 'tcp_check_warning_times_' . $node->id;
-                if (Cache::has($cacheKey)) {
-                    $times = Cache::get($cacheKey);
-                } else {
-                    Cache::put($cacheKey, 1, 725); // 因为每小时检测一次,最多设置提醒12次,12*60=720分钟缓存时效,多5分钟防止异常
-                    $times = 1;
-                }
-
                 // 异常才发通知消息
-                if ($tcpCheck > 0) {
-                    if (self::$config['tcp_check_warning_times'] > 0) {
+                if ($tcpCheck) {
+                    if (self::$config['tcp_check_warning_times']) {
+                        // 已通知次数
+                        $cacheKey = 'tcp_check_warning_times_' . $node->id;
+                        if (Cache::has($cacheKey)) {
+                            $times = Cache::get($cacheKey);
+                        } else {
+                            Cache::put($cacheKey, 1, 725); // 因为每小时检测一次,最多设置提醒12次,12*60=720分钟缓存时效,多5分钟防止异常
+                            $times = 1;
+                        }
+
                         if ($times < self::$config['tcp_check_warning_times']) {
                             Cache::increment('tcp_check_warning_times_' . $node->id);
 

+ 19 - 0
app/Http/Controllers/AdminController.php

@@ -28,6 +28,7 @@ use App\Http\Models\UserSubscribe;
 use App\Http\Models\UserTrafficDaily;
 use App\Http\Models\UserTrafficHourly;
 use App\Http\Models\UserTrafficLog;
+use App\Http\Models\UserTrafficModifyLog;
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
 use Illuminate\Http\Request;
@@ -2152,6 +2153,24 @@ EOF;
         return Response::view('admin/userBanLogList', $view);
     }
 
+    // 用户流量变动记录
+    public function userTrafficLogList(Request $request)
+    {
+        $username = trim($request->get('username'));
+
+        $query = UserTrafficModifyLog::query()->with(['user', 'order'])->orderBy('id', 'desc');
+
+        if ($username) {
+            $query->whereHas('user', function ($q) use ($username) {
+                $q->where('username', 'like', '%' . $username . '%');
+            });
+        }
+
+        $view['list'] = $query->paginate(15);
+
+        return Response::view('admin/userTrafficLogList', $view);
+    }
+
     // 转换成某个用户的身份
     public function switchToUser(Request $request)
     {

+ 24 - 0
app/Http/Controllers/Controller.php

@@ -8,6 +8,7 @@ use App\Http\Models\SensitiveWords;
 use App\Http\Models\UserBalanceLog;
 use App\Http\Models\UserScoreLog;
 use App\Http\Models\UserSubscribe;
+use App\Http\Models\UserTrafficModifyLog;
 use Illuminate\Foundation\Bus\DispatchesJobs;
 use Illuminate\Routing\Controller as BaseController;
 use Illuminate\Foundation\Validation\ValidatesRequests;
@@ -253,6 +254,29 @@ class Controller extends BaseController
         return $log->save();
     }
 
+    /**
+     * 记录流量变动日志
+     *
+     * @param int    $userId 用户ID
+     * @param string $oid    订单ID
+     * @param int    $before 记录前的值
+     * @param int    $after  记录后的值
+     * @param string $desc   描述
+     *
+     * @return int
+     */
+    public function addUserTrafficModifyLog($userId, $oid, $before, $after, $desc = '')
+    {
+        $log = new UserTrafficModifyLog();
+        $log->user_id = $userId;
+        $log->order_id = $oid;
+        $log->before = $before;
+        $log->after = $after;
+        $log->desc = $desc;
+
+        return $log->save();
+    }
+
     /**
      * 添加返利日志
      *

+ 30 - 0
app/Http/Models/UserTrafficModifyLog.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Http\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * 用户流量变动记录
+ * Class UserTrafficModifyLog
+ *
+ * @package App\Http\Models
+ */
+class UserTrafficModifyLog extends Model
+{
+    protected $table = 'user_traffic_modify_log';
+    protected $primaryKey = 'id';
+
+    // 关联账号
+    public function User()
+    {
+        return $this->hasOne(User::class, 'id', 'user_id');
+    }
+
+    // 关联订单
+    public function Order()
+    {
+        return $this->hasOne(Order::class, 'oid', 'order_id');
+    }
+
+}

+ 1 - 0
composer.json

@@ -8,6 +8,7 @@
         "php": ">=5.6.4",
         "barryvdh/laravel-ide-helper": "^2.4",
         "guzzlehttp/guzzle": "^6.3",
+        "ipip/db": "^0.6.0",
         "itbdw/ip-database": "^2.0",
         "jenssegers/agent": "^2.5",
         "laravel/framework": "5.4.*",

+ 53 - 1
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "e9bd00a2f0ae43e05d3039d3261bc76b",
+    "content-hash": "2b617eb186125f6e385e0b0a0ac6613c",
     "packages": [
         {
             "name": "barryvdh/laravel-ide-helper",
@@ -680,6 +680,58 @@
             ],
             "time": "2018-05-29T14:19:03+00:00"
         },
+        {
+            "name": "ipip/db",
+            "version": "v0.6",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/ipipdotnet/ipdb-php.git",
+                "reference": "f87777301eb886c68dbafb15d6a888bb3003a330"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/ipipdotnet/ipdb-php/zipball/f87777301eb886c68dbafb15d6a888bb3003a330",
+                "reference": "f87777301eb886c68dbafb15d6a888bb3003a330",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "php": ">=5.4.0"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "ipip\\db\\": "src/ipip/db/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "Apache-2.0"
+            ],
+            "authors": [
+                {
+                    "name": "IPIP.net",
+                    "email": "[email protected]",
+                    "homepage": "https://www.ipip.net"
+                }
+            ],
+            "description": "IPIP.net officially supported IP database ipdb format parsing library",
+            "homepage": "https://www.ipip.net",
+            "keywords": [
+                "IP",
+                "geo",
+                "geoip",
+                "geolocation",
+                "ipdb",
+                "ipip.net"
+            ],
+            "time": "2018-08-30T03:32:59+00:00"
+        },
         {
             "name": "itbdw/ip-database",
             "version": "v2.0.5",

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

@@ -167,7 +167,7 @@
                         </li>
                     </ul>
                 </li>
-                <li class="nav-item {{in_array(Request::path(), ['admin/userList', 'admin/addUser', 'admin/editUser', 'admin/userOrderList', 'admin/userBalanceLogList', 'admin/userBanLogList', 'admin/export', 'admin/userMonitor']) ? 'active open' : ''}}">
+                <li class="nav-item {{in_array(Request::path(), ['admin/userList', 'admin/addUser', 'admin/editUser', 'admin/userOrderList', 'admin/userBalanceLogList', 'admin/userTrafficLogList', 'admin/userBanLogList', 'admin/export', 'admin/userMonitor']) ? 'active open' : ''}}">
                     <a href="javascript:;" class="nav-link nav-toggle">
                         <i class="fa fa-users"></i>
                         <span class="title">用户管理</span>
@@ -186,6 +186,12 @@
                                 <span class="title">余额变动记录</span>
                             </a>
                         </li>
+                        <li class="nav-item {{in_array(Request::path(), ['admin/userTrafficLogList']) ? 'active open' : ''}}">
+                            <a href="{{url('admin/userTrafficLogList')}}" class="nav-link ">
+                                <i class="fa fa-bar-chart"></i>
+                                <span class="title">流量变动记录</span>
+                            </a>
+                        </li>
                         <li class="nav-item {{in_array(Request::path(), ['admin/userBanLogList']) ? 'active open' : ''}}">
                             <a href="{{url('admin/userBanLogList')}}" class="nav-link ">
                                 <i class="fa fa-user-times"></i>

+ 2 - 2
resources/views/admin/system.blade.php

@@ -585,7 +585,7 @@
                                                                         <button class="btn btn-success" type="button" onclick="setPushBearQrCode()">修改</button>
                                                                     </span>
                                                                 </div>
-                                                                <span class="help-block"> 创建消息通道后,在二维码上点击右键“复制图片地址”,展示于个人中心 </span>
+                                                                <span class="help-block"> 创建消息通道后,在二维码上点击右键“复制图片地址”并粘贴至此处 </span>
                                                             </div>
                                                         </div>
                                                         <div class="col-md-6"></div>
@@ -660,7 +660,7 @@
                                                             <label for="is_traffic_ban" class="col-md-3 control-label">异常自动封号</label>
                                                             <div class="col-md-9">
                                                                 <input type="checkbox" class="make-switch" @if($is_traffic_ban) checked @endif id="is_traffic_ban" data-on-color="success" data-off-color="danger" data-on-text="启用" data-off-text="关闭">
-                                                                <span class="help-block"> 1小时内流量超过异常阈值则自动封号(仅禁用SSR(R)) </span>
+                                                                <span class="help-block"> 1小时内流量超过异常阈值则自动封号(仅禁用代理) </span>
                                                             </div>
                                                         </div>
                                                         <div class="col-md-6">

+ 2 - 2
resources/views/admin/userBalanceLogList.blade.php

@@ -39,7 +39,7 @@
                                     <th> 发生金额 </th>
                                     <th> 操作后金额 </th>
                                     <th> 描述 </th>
-                                    <th> 操作时间 </th>
+                                    <th> 发生时间 </th>
                                 </tr>
                                 </thead>
                                 <tbody>
@@ -51,7 +51,7 @@
                                         @foreach($list as $vo)
                                             <tr class="odd gradeX">
                                                 <td> {{$vo->id}} </td>
-                                                <td> {{empty($vo->user) ? '【账号已删除】' : $vo->user->username}} </td>
+                                                <td> {!! empty($vo->user) ? '【账号已删除】' : '<a href="/admin/userBalanceLogList?username=' . $vo->user->username . '">' . $vo->user->username . '</a>' !!} </td>
                                                 <td> {{$vo->order_id}} </td>
                                                 <td> {{$vo->before}} </td>
                                                 <td> {{$vo->amount}} </td>

+ 2 - 2
resources/views/admin/userList.blade.php

@@ -53,7 +53,7 @@
                             </div>
                             <div class="col-md-2 col-sm-2">
                                 <select class="form-control input-sm" name="status" id="status" onChange="doSearch()">
-                                    <option value="" @if(Request::get('status') == '') selected @endif>状态</option>
+                                    <option value="" @if(Request::get('status') == '') selected @endif>账号状态</option>
                                     <option value="-1" @if(Request::get('status') == '-1') selected @endif>禁用</option>
                                     <option value="0" @if(Request::get('status') == '0') selected @endif>未激活</option>
                                     <option value="1" @if(Request::get('status') == '1') selected @endif>正常</option>
@@ -61,7 +61,7 @@
                             </div>
                             <div class="col-md-2 col-sm-2">
                                 <select class="form-control input-sm" name="enable" id="enable" onChange="doSearch()">
-                                    <option value="" @if(Request::get('enable') == '') selected @endif>SSR(R)状态</option>
+                                    <option value="" @if(Request::get('enable') == '') selected @endif>代理状态</option>
                                     <option value="1" @if(Request::get('enable') == '1') selected @endif>启用</option>
                                     <option value="0" @if(Request::get('enable') == '0') selected @endif>禁用</option>
                                 </select>

+ 99 - 0
resources/views/admin/userTrafficLogList.blade.php

@@ -0,0 +1,99 @@
+@extends('admin.layouts')
+
+@section('css')
+    <link href="/assets/global/plugins/datatables/datatables.min.css" rel="stylesheet" type="text/css" />
+    <link href="/assets/global/plugins/datatables/plugins/bootstrap/datatables.bootstrap.css" rel="stylesheet" type="text/css" />
+@endsection
+@section('title', '控制面板')
+@section('content')
+    <!-- BEGIN CONTENT BODY -->
+    <div class="page-content" style="padding-top:0;">
+        <!-- BEGIN PAGE BASE CONTENT -->
+        <div class="row">
+            <div class="col-md-12">
+                <!-- BEGIN EXAMPLE TABLE PORTLET-->
+                <div class="portlet light bordered">
+                    <div class="portlet-title">
+                        <div class="caption font-dark">
+                            <span class="caption-subject bold uppercase"> 流量变动记录 </span>
+                        </div>
+                    </div>
+                    <div class="portlet-body">
+                        <div class="row">
+                            <div class="col-md-2 col-sm-2">
+                                <input type="text" class="col-md-4 form-control input-sm" name="username" value="{{Request::get('username')}}" id="username" placeholder="用户名" onkeydown="if(event.keyCode==13){do_search();}">
+                            </div>
+                            <div class="col-md-2 col-sm-2">
+                                <button type="button" class="btn btn-sm blue" onclick="do_search();">查询</button>
+                                <button type="button" class="btn btn-sm grey" onclick="do_reset();">重置</button>
+                            </div>
+                        </div>
+                        <div class="table-scrollable table-scrollable-borderless">
+                            <table class="table table-hover table-light">
+                                <thead>
+                                <tr>
+                                    <th> # </th>
+                                    <th> 用户名 </th>
+                                    <th> 订单ID </th>
+                                    <th> 变动前流量 </th>
+                                    <th> 变动后流量 </th>
+                                    <th> 描述 </th>
+                                    <th> 发生时间 </th>
+                                </tr>
+                                </thead>
+                                <tbody>
+                                    @if($list->isEmpty())
+                                        <tr>
+                                            <td colspan="8" style="text-align: center;">暂无数据</td>
+                                        </tr>
+                                    @else
+                                        @foreach($list as $vo)
+                                            <tr class="odd gradeX">
+                                                <td> {{$vo->id}} </td>
+                                                <td> {!! empty($vo->user) ? '【账号已删除】' : '<a href="/admin/userTrafficLogList?username=' . $vo->user->username . '">' . $vo->user->username . '</a>' !!} </td>
+                                                <td> {{$vo->order_id}} </td>
+                                                <td> {{$vo->before}} </td>
+                                                <td> {{$vo->amount}} </td>
+                                                <td> {{$vo->after}} </td>
+                                                <td> {{$vo->desc}} </td>
+                                                <td> {{$vo->created_at}} </td>
+                                            </tr>
+                                        @endforeach
+                                    @endif
+                                </tbody>
+                            </table>
+                        </div>
+                        <div class="row">
+                            <div class="col-md-4 col-sm-4">
+                                <div class="dataTables_info" role="status" aria-live="polite">共 {{$list->total()}} 条记录</div>
+                            </div>
+                            <div class="col-md-8 col-sm-8">
+                                <div class="dataTables_paginate paging_bootstrap_full_number pull-right">
+                                    {{ $list->links() }}
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+                <!-- END EXAMPLE TABLE PORTLET-->
+            </div>
+        </div>
+        <!-- END PAGE BASE CONTENT -->
+    </div>
+    <!-- END CONTENT BODY -->
+@endsection
+@section('script')
+    <script type="text/javascript">
+        // 搜索
+        function do_search() {
+            var username = $("#username").val();
+
+            window.location.href = '{{url('admin/userTrafficLogList')}}' + '?username=' + username;
+        }
+
+        // 重置
+        function do_reset() {
+            window.location.href = '{{url('admin/userTrafficLogList')}}';
+        }
+    </script>
+@endsection

+ 1 - 0
routes/web.php

@@ -75,6 +75,7 @@ Route::group(['middleware' => ['forbidden', 'user', 'admin']], function () {
     Route::post('admin/resetUserTraffic', 'AdminController@resetUserTraffic'); // 重置用户流量
     Route::post('admin/handleUserBalance', 'AdminController@handleUserBalance'); // 余额充值
     Route::get('admin/userBalanceLogList', 'AdminController@userBalanceLogList'); // 余额变动日志
+    Route::get('admin/userTrafficLogList', 'AdminController@userTrafficLogList'); // 流量变动记录
     Route::get('admin/userBanLogList', 'AdminController@userBanLogList'); // 用户封禁记录
     Route::get('admin/makePort', 'AdminController@makePort'); // 生成端口
     Route::get('admin/makePasswd', 'AdminController@makePasswd'); // 生成密码

+ 16 - 0
sql/db.sql

@@ -605,6 +605,22 @@ CREATE TABLE `user_balance_log` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户余额变动日志';
 
 
+-- ----------------------------
+-- Table structure for `user_traffic_modify_log`
+-- ----------------------------
+CREATE TABLE `user_traffic_modify_log` (
+	`id` INT(11) NOT NULL AUTO_INCREMENT,
+	`user_id` INT(11) NOT NULL DEFAULT '0' COMMENT '用户ID',
+	`order_id` INT(11) NOT NULL DEFAULT '0' COMMENT '发生的订单ID',
+	`before` INT(11) NOT NULL DEFAULT '0',
+	`after` INT(11) NOT NULL DEFAULT '0',
+	`desc` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '描述',
+	`created_at` DATETIME NOT NULL,
+	`updated_at` DATETIME NOT NULL,
+	PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户流量变动日志';
+
+
 -- ----------------------------
 -- Table structure for `referral_apply`
 -- ----------------------------

+ 14 - 0
sql/update/20180927.sql

@@ -0,0 +1,14 @@
+-- ----------------------------
+-- Table structure for `user_traffic_modify_log`
+-- ----------------------------
+CREATE TABLE `user_traffic_modify_log` (
+	`id` INT(11) NOT NULL AUTO_INCREMENT,
+	`user_id` INT(11) NOT NULL DEFAULT '0' COMMENT '用户ID',
+	`order_id` INT(11) NOT NULL DEFAULT '0' COMMENT '发生的订单ID',
+	`before` INT(11) NOT NULL DEFAULT '0',
+	`after` INT(11) NOT NULL DEFAULT '0',
+	`desc` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '描述',
+	`created_at` DATETIME NOT NULL,
+	`updated_at` DATETIME NOT NULL,
+	PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户流量变动日志';

BIN
storage/ipip.ipdb