Skip to content

Commit 7ec2501

Browse files
committed
用户节点订阅地址启用禁用
1 parent 59af796 commit 7ec2501

File tree

8 files changed

+51
-11
lines changed

8 files changed

+51
-11
lines changed

app/Http/Controllers/AdminController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,20 @@ public function subscribeLog(Request $request)
694694
return Response::view('admin/subscribeLog', $view);
695695
}
696696

697+
public function setSubscribeStatus(Request $request)
698+
{
699+
$id = $request->get('id');
700+
$status = $request->get('status', 0);
701+
702+
if (empty($id)) {
703+
return Response::json(['status' => 'fail', 'data' => '', 'message' => '操作异常']);
704+
}
705+
706+
UserSubscribe::where('id', $id)->update(['status' => $status]);
707+
708+
return Response::json(['status' => 'success', 'data' => '', 'message' => '操作成功']);
709+
}
710+
697711
// 格式转换(SS转SSR)
698712
public function convert(Request $request)
699713
{

app/Http/Controllers/SubscribeController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ public function index(Request $request, $code)
3636
}
3737

3838
// 校验合法性
39-
$subscribe = UserSubscribe::where('code', $code)->with('user')->first();
39+
$subscribe = UserSubscribe::where('code', $code)->where('status', 1)->with('user')->first();
4040
if (empty($subscribe)) {
41-
exit('非法请求');
41+
exit('非法请求或者被禁用,请联系管理员');
4242
}
4343

4444
$user = User::where('id', $subscribe->user_id)->whereIn('status', [0, 1])->where('enable', 1)->first();
4545
if (empty($user)) {
46-
exit('非法请求');
46+
exit('非法请求或者被禁用,请联系管理员');
4747
}
4848

4949
// 更新访问次数

config/database.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
'driver' => 'mysql',
4444
'host' => '127.0.0.1',
4545
'port' => '3306',
46-
'database' => '2',
47-
'username' => 'root',
48-
'password' => 'root',
46+
'database' => 'ssrpanel',
47+
'username' => 'mysql_username',
48+
'password' => 'mysql_password',
4949
'unix_socket' => '',
5050
'charset' => 'utf8mb4',
5151
'collation' => 'utf8mb4_unicode_ci',

resources/views/admin/subscribeLog.blade.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@
5353
<th> 请求次数 </th>
5454
<th> 最后请求时间 </th>
5555
<th> 异常 </th>
56+
<th> 操作 </th>
5657
</tr>
5758
</thead>
5859
<tbody>
5960
@if($subscribeList->isEmpty())
6061
<tr>
61-
<td colspan="6">暂无数据</td>
62+
<td colspan="7">暂无数据</td>
6263
</tr>
6364
@else
6465
@foreach($subscribeList as $subscribe)
@@ -70,7 +71,15 @@
7071
<td> {{$subscribe->updated_at}} </td>
7172
<td>
7273
@if($subscribe->isWarning)
73-
<div class="label label-danger">异常</div>
74+
<div class="label label-danger">可能公开</div>
75+
@endif
76+
</td>
77+
<td>
78+
@if($subscribe->status == 0)
79+
<button type="button" class="btn btn-sm green btn-outline" onclick="set_status('{{$subscribe->id}}', 1)">启用</button>
80+
@endif
81+
@if($subscribe->status == 1)
82+
<button type="button" class="btn btn-sm red btn-outline" onclick="set_status('{{$subscribe->id}}', 0)">禁用</button>
7483
@endif
7584
</td>
7685
</tr>
@@ -99,6 +108,8 @@
99108
<!-- END CONTENT BODY -->
100109
@endsection
101110
@section('script')
111+
<script src="/js/layer/layer.js" type="text/javascript"></script>
112+
102113
<script type="text/javascript">
103114
// 搜索
104115
function do_search() {
@@ -112,5 +123,14 @@ function do_search() {
112123
function do_reset() {
113124
window.location.href = '{{url('admin/subscribeLog')}}';
114125
}
126+
127+
// 启用禁用用户的订阅
128+
function set_status(id, status) {
129+
$.post("{{url('admin/setSubscribeStatus')}}", {_token:'{{csrf_token()}}', id:id, status:status}, function(ret) {
130+
layer.msg(ret.message, {time:1000}, function() {
131+
window.location.reload();
132+
});
133+
});
134+
}
115135
</script>
116136
@endsection

routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
Route::post('admin/setDefaultConfig', 'AdminController@setDefaultConfig'); // 设置默认配置
4242
Route::get('admin/trafficLog', 'AdminController@trafficLog'); // 流量日志
4343
Route::get('admin/subscribeLog', 'AdminController@subscribeLog'); // 订阅请求日志
44+
Route::post('admin/setSubscribeStatus', 'AdminController@setSubscribeStatus'); // 启用禁用用户的订阅
4445
Route::any('admin/export', 'AdminController@export'); // 导出配置信息
4546
Route::any('admin/convert', 'AdminController@convert'); // 格式转换
4647
Route::any('admin/import', 'AdminController@import'); // 数据导入

sql/db.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ CREATE TABLE `user_subscribe` (
529529
`user_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户ID',
530530
`code` varchar(255) DEFAULT '' COMMENT '订阅地址唯一识别码',
531531
`times` int(11) NOT NULL DEFAULT '0' COMMENT '地址请求次数',
532+
`status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态:0-禁用、1-启用',
532533
`created_at` datetime DEFAULT NULL COMMENT '创建时间',
533534
`updated_at` datetime DEFAULT NULL COMMENT '最后更新时间',
534535
PRIMARY KEY (`id`)

sql/update/20171019.sql

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
ALTER TABLE `user_subscribe_log`
22
ADD COLUMN `request_header` text COMMENT '请求头部信息' AFTER `request_time`;
3-
4-
ALTER TABLE `user_subscribe`
5-
ADD COLUMN `updated_at` datetime DEFAULT NULL COMMENT '最后更新时间' AFTER `created_at`;

sql/update/20171020.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ALTER TABLE `user_subscribe`
2+
ADD COLUMN `updated_at` datetime DEFAULT NULL COMMENT '最后更新时间' AFTER `created_at`;
3+
4+
ALTER TABLE `user_subscribe`
5+
ADD COLUMN `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态:0-禁用、1-启用' AFTER `times`;
6+
7+
INSERT INTO `config` VALUES ('29', 'subscribe_max', 3);

0 commit comments

Comments
 (0)