测试:增加设备数限制功能

This commit is contained in:
wyx2685
2023-10-14 18:32:15 +09:00
parent dffe39b6d9
commit ac38036f8e
14 changed files with 113 additions and 4 deletions

View File

@ -45,6 +45,7 @@ class PlanController extends Controller
User::where('plan_id', $plan->id)->update([
'group_id' => $params['group_id'],
'transfer_enable' => $params['transfer_enable'] * 1073741824,
'device_limit' => $params['device_limit'],
'speed_limit' => $params['speed_limit']
]);
}

View File

@ -157,16 +157,17 @@ class UserController extends Controller
}
}
$data = "邮箱,余额,推广佣金,总流量,剩余流量,套餐到期时间,订阅计划,订阅地址\r\n";
$data = "邮箱,余额,推广佣金,总流量,设备数限制,剩余流量,套餐到期时间,订阅计划,订阅地址\r\n";
foreach($res as $user) {
$expireDate = $user['expired_at'] === NULL ? '长期有效' : date('Y-m-d H:i:s', $user['expired_at']);
$balance = $user['balance'] / 100;
$commissionBalance = $user['commission_balance'] / 100;
$transferEnable = $user['transfer_enable'] ? $user['transfer_enable'] / 1073741824 : 0;
$deviceLimit = $user['devce_limit'] ? $user['devce_limit'] : NULL;
$notUseFlow = (($user['transfer_enable'] - ($user['u'] + $user['d'])) / 1073741824) ?? 0;
$planName = $user['plan_name'] ?? '无订阅';
$subscribeUrl = Helper::getSubscribeUrl('/api/v1/client/subscribe?token=' . $user['token']);
$data .= "{$user['email']},{$balance},{$commissionBalance},{$transferEnable},{$notUseFlow},{$expireDate},{$planName},{$subscribeUrl}\r\n";
$data .= "{$user['email']},{$balance},{$commissionBalance},{$transferEnable}, {$deviceLimit}, {$notUseFlow},{$expireDate},{$planName},{$subscribeUrl}\r\n";
}
echo "\xEF\xBB\xBF" . $data;
}
@ -185,6 +186,7 @@ class UserController extends Controller
'plan_id' => isset($plan->id) ? $plan->id : NULL,
'group_id' => isset($plan->group_id) ? $plan->group_id : NULL,
'transfer_enable' => isset($plan->transfer_enable) ? $plan->transfer_enable * 1073741824 : 0,
'device_limit' => isset($plan->device_limit) ? $plan->device_limit : NULL,
'expired_at' => $request->input('expired_at') ?? NULL,
'uuid' => Helper::guid(true),
'token' => Helper::guid()
@ -220,6 +222,7 @@ class UserController extends Controller
'plan_id' => isset($plan->id) ? $plan->id : NULL,
'group_id' => isset($plan->group_id) ? $plan->group_id : NULL,
'transfer_enable' => isset($plan->transfer_enable) ? $plan->transfer_enable * 1073741824 : 0,
'device_limit' => isset($plan->device_limit) ? $plan->device_limit : NULL,
'expired_at' => $request->input('expired_at') ?? NULL,
'uuid' => Helper::guid(true),
'token' => Helper::guid(),

View File

@ -153,6 +153,7 @@ class AuthController extends Controller
$plan = Plan::find(config('v2board.try_out_plan_id'));
if ($plan) {
$user->transfer_enable = $plan->transfer_enable * 1073741824;
$user->device_limit = $plan->device_limit;
$user->plan_id = $plan->id;
$user->group_id = $plan->group_id;
$user->expired_at = time() + (config('v2board.try_out_hour', 1) * 3600);

View File

@ -43,6 +43,20 @@ class UniProxyController extends Controller
$users = $this->serverService->getAvailableUsers($this->nodeInfo->group_id);
$users = $users->toArray();
$users = array_map(function ($user) {
$count =0;
$ips_array = Cache::get('ALIVE_IP_USER_'. $user['id']);
if ($ips_array) {
foreach ($ips_array as $nodeid => $ip_array) {
foreach ($ip_array['aliveips'] as $ip) {
$count++;
}
}
}
$user['alive_ip'] = $count;
return $user;
}, $users);
$response['users'] = $users;
$eTag = sha1(json_encode($response));
@ -68,6 +82,41 @@ class UniProxyController extends Controller
]);
}
// 后端提交在线数据
public function alive(Request $request)
{
$data = file_get_contents('php://input');
$data = json_decode($data, true);
if ($data === null && json_last_error() !== JSON_ERROR_NONE) {
// JSON decoding error
return response([
'error' => 'Invalid online data'
], 400);
}
foreach ($data as $k => $v) {
$updateAt = time();
$oldips_array = Cache::get('ALIVE_IP_USER_'. $k) ?? [];
// 更新节点数据
$oldips_array[$this->nodeId] = ['aliveips' => $v, 'lastupdateAt' => $updateAt];
//删除过期节点在线数据
$expired_array = [];
foreach($oldips_array as $nodeid => $oldips) {
if ($updateAt - $oldips['lastupdateAt'] > 300){
$expired_array[$nodeid] = '';
}
}
// 清理过期数据并存回缓存
$new_array = array_diff_key($oldips_array, $expired_array);
Cache::put('ALIVE_IP_USER_'. $k, $new_array, 120);
}
return response([
'data' => true
]);
}
// 后端获取配置
public function config(Request $request)
{

View File

@ -87,6 +87,7 @@ class UserController extends Controller
->select([
'email',
'transfer_enable',
'device_limit',
'last_login_at',
'created_at',
'banned',
@ -138,6 +139,7 @@ class UserController extends Controller
'u',
'd',
'transfer_enable',
'device_limit',
'email',
'uuid'
])