Skip to content

Commit b6438ca

Browse files
committed
1.加入用户流量变动日志
2.加入IPIP的IP库
1 parent 3091bfe commit b6438ca

File tree

16 files changed

+309
-19
lines changed

16 files changed

+309
-19
lines changed

app/Components/IPIP.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Components;
4+
5+
use ipip\db\Reader;
6+
7+
class IPIP
8+
{
9+
/**
10+
* 查询IP地址的详细信息
11+
*
12+
* @param string $ip IPv4
13+
*
14+
* @return \ipip\db\Info|null
15+
* @throws \Exception
16+
*/
17+
public function ip($ip)
18+
{
19+
$filePath = storage_path('ipip.ipdb');
20+
21+
$db = new Reader($filePath);
22+
//$loc = $db->find($ip);
23+
//$loc = $db->findMap($ip);
24+
$loc = $db->findInfo($ip);
25+
26+
return $loc;
27+
}
28+
}

app/Console/Commands/AutoCheckNodeStatus.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,18 @@ private function checkNodes()
6464
$text = '正常';
6565
}
6666

67-
// 已通知次数
68-
$cacheKey = 'tcp_check_warning_times_' . $node->id;
69-
if (Cache::has($cacheKey)) {
70-
$times = Cache::get($cacheKey);
71-
} else {
72-
Cache::put($cacheKey, 1, 725); // 因为每小时检测一次,最多设置提醒12次,12*60=720分钟缓存时效,多5分钟防止异常
73-
$times = 1;
74-
}
75-
7667
// 异常才发通知消息
77-
if ($tcpCheck > 0) {
78-
if (self::$config['tcp_check_warning_times'] > 0) {
68+
if ($tcpCheck) {
69+
if (self::$config['tcp_check_warning_times']) {
70+
// 已通知次数
71+
$cacheKey = 'tcp_check_warning_times_' . $node->id;
72+
if (Cache::has($cacheKey)) {
73+
$times = Cache::get($cacheKey);
74+
} else {
75+
Cache::put($cacheKey, 1, 725); // 因为每小时检测一次,最多设置提醒12次,12*60=720分钟缓存时效,多5分钟防止异常
76+
$times = 1;
77+
}
78+
7979
if ($times < self::$config['tcp_check_warning_times']) {
8080
Cache::increment('tcp_check_warning_times_' . $node->id);
8181

app/Http/Controllers/AdminController.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use App\Http\Models\UserTrafficDaily;
2929
use App\Http\Models\UserTrafficHourly;
3030
use App\Http\Models\UserTrafficLog;
31+
use App\Http\Models\UserTrafficModifyLog;
3132
use PhpOffice\PhpSpreadsheet\Spreadsheet;
3233
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
3334
use Illuminate\Http\Request;
@@ -2152,6 +2153,24 @@ public function userBanLogList(Request $request)
21522153
return Response::view('admin/userBanLogList', $view);
21532154
}
21542155

2156+
// 用户流量变动记录
2157+
public function userTrafficLogList(Request $request)
2158+
{
2159+
$username = trim($request->get('username'));
2160+
2161+
$query = UserTrafficModifyLog::query()->with(['user', 'order'])->orderBy('id', 'desc');
2162+
2163+
if ($username) {
2164+
$query->whereHas('user', function ($q) use ($username) {
2165+
$q->where('username', 'like', '%' . $username . '%');
2166+
});
2167+
}
2168+
2169+
$view['list'] = $query->paginate(15);
2170+
2171+
return Response::view('admin/userTrafficLogList', $view);
2172+
}
2173+
21552174
// 转换成某个用户的身份
21562175
public function switchToUser(Request $request)
21572176
{

app/Http/Controllers/Controller.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Http\Models\UserBalanceLog;
99
use App\Http\Models\UserScoreLog;
1010
use App\Http\Models\UserSubscribe;
11+
use App\Http\Models\UserTrafficModifyLog;
1112
use Illuminate\Foundation\Bus\DispatchesJobs;
1213
use Illuminate\Routing\Controller as BaseController;
1314
use Illuminate\Foundation\Validation\ValidatesRequests;
@@ -253,6 +254,29 @@ public function addUserBalanceLog($userId, $oid, $before, $after, $amount, $desc
253254
return $log->save();
254255
}
255256

257+
/**
258+
* 记录流量变动日志
259+
*
260+
* @param int $userId 用户ID
261+
* @param string $oid 订单ID
262+
* @param int $before 记录前的值
263+
* @param int $after 记录后的值
264+
* @param string $desc 描述
265+
*
266+
* @return int
267+
*/
268+
public function addUserTrafficModifyLog($userId, $oid, $before, $after, $desc = '')
269+
{
270+
$log = new UserTrafficModifyLog();
271+
$log->user_id = $userId;
272+
$log->order_id = $oid;
273+
$log->before = $before;
274+
$log->after = $after;
275+
$log->desc = $desc;
276+
277+
return $log->save();
278+
}
279+
256280
/**
257281
* 添加返利日志
258282
*
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Http\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
/**
8+
* 用户流量变动记录
9+
* Class UserTrafficModifyLog
10+
*
11+
* @package App\Http\Models
12+
*/
13+
class UserTrafficModifyLog extends Model
14+
{
15+
protected $table = 'user_traffic_modify_log';
16+
protected $primaryKey = 'id';
17+
18+
// 关联账号
19+
public function User()
20+
{
21+
return $this->hasOne(User::class, 'id', 'user_id');
22+
}
23+
24+
// 关联订单
25+
public function Order()
26+
{
27+
return $this->hasOne(Order::class, 'oid', 'order_id');
28+
}
29+
30+
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"php": ">=5.6.4",
99
"barryvdh/laravel-ide-helper": "^2.4",
1010
"guzzlehttp/guzzle": "^6.3",
11+
"ipip/db": "^0.6.0",
1112
"itbdw/ip-database": "^2.0",
1213
"jenssegers/agent": "^2.5",
1314
"laravel/framework": "5.4.*",

composer.lock

Lines changed: 53 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/views/admin/layouts.blade.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
</li>
168168
</ul>
169169
</li>
170-
<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' : ''}}">
170+
<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' : ''}}">
171171
<a href="javascript:;" class="nav-link nav-toggle">
172172
<i class="fa fa-users"></i>
173173
<span class="title">用户管理</span>
@@ -186,6 +186,12 @@
186186
<span class="title">余额变动记录</span>
187187
</a>
188188
</li>
189+
<li class="nav-item {{in_array(Request::path(), ['admin/userTrafficLogList']) ? 'active open' : ''}}">
190+
<a href="{{url('admin/userTrafficLogList')}}" class="nav-link ">
191+
<i class="fa fa-bar-chart"></i>
192+
<span class="title">流量变动记录</span>
193+
</a>
194+
</li>
189195
<li class="nav-item {{in_array(Request::path(), ['admin/userBanLogList']) ? 'active open' : ''}}">
190196
<a href="{{url('admin/userBanLogList')}}" class="nav-link ">
191197
<i class="fa fa-user-times"></i>

resources/views/admin/system.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@
585585
<button class="btn btn-success" type="button" onclick="setPushBearQrCode()">修改</button>
586586
</span>
587587
</div>
588-
<span class="help-block"> 创建消息通道后,在二维码上点击右键“复制图片地址”,展示于个人中心 </span>
588+
<span class="help-block"> 创建消息通道后,在二维码上点击右键“复制图片地址”并粘贴至此处 </span>
589589
</div>
590590
</div>
591591
<div class="col-md-6"></div>
@@ -660,7 +660,7 @@
660660
<label for="is_traffic_ban" class="col-md-3 control-label">异常自动封号</label>
661661
<div class="col-md-9">
662662
<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="关闭">
663-
<span class="help-block"> 1小时内流量超过异常阈值则自动封号(仅禁用SSR(R)) </span>
663+
<span class="help-block"> 1小时内流量超过异常阈值则自动封号(仅禁用代理) </span>
664664
</div>
665665
</div>
666666
<div class="col-md-6">

resources/views/admin/userBalanceLogList.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<th> 发生金额 </th>
4040
<th> 操作后金额 </th>
4141
<th> 描述 </th>
42-
<th> 操作时间 </th>
42+
<th> 发生时间 </th>
4343
</tr>
4444
</thead>
4545
<tbody>
@@ -51,7 +51,7 @@
5151
@foreach($list as $vo)
5252
<tr class="odd gradeX">
5353
<td> {{$vo->id}} </td>
54-
<td> {{empty($vo->user) ? '【账号已删除】' : $vo->user->username}} </td>
54+
<td> {!! empty($vo->user) ? '【账号已删除】' : '<a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fadmin%2FuserBalanceLogList%3Fusername%3D%3C%2Fspan%3E%3Cspan+class%3D"pl-pds x">' . $vo->user->username . '">' . $vo->user->username . '</a>' !!} </td>
5555
<td> {{$vo->order_id}} </td>
5656
<td> {{$vo->before}} </td>
5757
<td> {{$vo->amount}} </td>

0 commit comments

Comments
 (0)