22
33namespace App \Http \Controllers ;
44
5- use App \Http \Models \SsGroup ;
6- use App \Http \Models \SsGroupNode ;
7- use App \Http \Models \SsNode ;
85use App \Http \Models \User ;
6+ use App \Http \Models \UserLabel ;
97use App \Http \Models \UserSubscribe ;
108use App \Http \Models \UserSubscribeLog ;
119use Illuminate \Http \Request ;
1210use Redirect ;
11+ use DB ;
1312
1413/**
1514 * 订阅控制器
@@ -33,14 +32,14 @@ public function index(Request $request, $code)
3332 }
3433
3534 // 校验合法性
36- $ subscribe = UserSubscribe::query ()->where ('code ' , $ code )->where ('status ' , 1 )-> with ( ' user ' )->first ();
35+ $ subscribe = UserSubscribe::query ()->with ( ' user ' )-> where ('code ' , $ code )->where ('status ' , 1 )->first ();
3736 if (empty ($ subscribe )) {
38- exit ('非法请求或已被封禁 ,请联系管理员 ' );
37+ exit ('订阅地址不存在或被封禁 ,请联系管理员 ' );
3938 }
4039
4140 $ user = User::query ()->where ('id ' , $ subscribe ->user_id )->whereIn ('status ' , [0 , 1 ])->where ('enable ' , 1 )->first ();
4241 if (empty ($ user )) {
43- exit ('非法请求或已被封禁 ,请联系管理员 ' );
42+ exit ('您的账号已被封禁 ,请联系管理员 ' );
4443 }
4544
4645 // 更新访问次数
@@ -55,13 +54,18 @@ public function index(Request $request, $code)
5554 $ log ->save ();
5655
5756 // 获取这个账号可用节点
58- $ group_ids = SsGroup::query ()->where ('level ' , '<= ' , $ user ->level )->select (['id ' ])->get ();
59- if (empty ($ group_ids )) {
60- exit ();
57+ $ userLabelIds = UserLabel::query ()->where ('user_id ' , $ user ->id )->pluck (['label_id ' ]);
58+ $ nodeList = DB ::table ('ss_node ' )
59+ ->leftJoin ('ss_node_label ' , 'ss_node.id ' , '= ' , 'ss_node_label.node_id ' )
60+ ->whereIn ('ss_node_label.label_id ' , $ userLabelIds )
61+ ->where ('ss_node.status ' , 1 )
62+ ->groupBy ('ss_node.id ' )
63+ ->get ();
64+
65+ if ($ nodeList ->isEmpty ()) {
66+ exit ('没有可用节点 ' );
6167 }
6268
63- $ node_ids = SsGroupNode::query ()->whereIn ('group_id ' , $ group_ids )->select (['node_id ' ])->get ();
64- $ nodeList = SsNode::query ()->where ('status ' , 1 )->whereIn ('id ' , $ node_ids )->get ();
6569 $ scheme = self ::$ config ['subscribe_max ' ] > 0 ? 'MAX= ' . self ::$ config ['subscribe_max ' ] . "\n" : '' ;
6670 foreach ($ nodeList as $ node ) {
6771 $ obfs_param = $ node ->single ? '' : $ user ->obfs_param ;
0 commit comments