Skip to content

Commit

Permalink
1.加入用户流量变动日志
Browse files Browse the repository at this point in the history
2.加入IPIP的IP库
  • Loading branch information
lordlezehaf committed Sep 27, 2018
1 parent 3091bfe commit b6438ca
Show file tree
Hide file tree
Showing 16 changed files with 309 additions and 19 deletions.
28 changes: 28 additions & 0 deletions app/Components/IPIP.php
Original file line number Diff line number Diff line change
@@ -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;
}
}
22 changes: 11 additions & 11 deletions app/Console/Commands/AutoCheckNodeStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ private function checkNodes()
$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);

Expand Down
19 changes: 19 additions & 0 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -2152,6 +2153,24 @@ public function userBanLogList(Request $request)
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)
{
Expand Down
24 changes: 24 additions & 0 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand Down Expand Up @@ -253,6 +254,29 @@ public function addUserBalanceLog($userId, $oid, $before, $after, $amount, $desc
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();
}

/**
* 添加返利日志
*
Expand Down
30 changes: 30 additions & 0 deletions app/Http/Models/UserTrafficModifyLog.php
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.*",
Expand Down
54 changes: 53 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion resources/views/admin/layouts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/admin/system.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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">
Expand Down
4 changes: 2 additions & 2 deletions resources/views/admin/userBalanceLogList.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<th> 发生金额 </th>
<th> 操作后金额 </th>
<th> 描述 </th>
<th> 操作时间 </th>
<th> 发生时间 </th>
</tr>
</thead>
<tbody>
Expand All @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/admin/userList.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@
</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>
</select>
</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>
Expand Down
Loading

0 comments on commit b6438ca

Please sign in to comment.