update online user stat

This commit is contained in:
Tokumeikoi 2020-06-05 13:25:32 +08:00
parent 3200c427ce
commit 47a6c4077a
6 changed files with 12 additions and 31 deletions

View File

@ -2,12 +2,7 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Utils\Helper;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Stripe\Source;
use Stripe\Stripe;
use Stripe\StripeClient;
use Omnipay\Omnipay;
class Test extends Command class Test extends Command
{ {
@ -42,21 +37,5 @@ class Test extends Command
*/ */
public function handle() public function handle()
{ {
$gateway = Omnipay::create('Stripe');
$gateway->setApiKey('sk_test_gDIIPtUgWZHbnTR7CUWZS8k500NsLS9SYB');
$formData = array('number' => '4242424242424242', 'expiryMonth' => '6', 'expiryYear' => '2030', 'cvv' => '333');
$response = $gateway->purchase(array('amount' => '10.00', 'currency' => 'USD', 'card' => $formData))->send();
if ($response->isRedirect()) {
// redirect to offsite payment gateway
$response->redirect();
} elseif ($response->isSuccessful()) {
// payment was successful: update database
print_r($response);
} else {
// payment failed: display message to customer
echo $response->getMessage();
}
} }
} }

View File

@ -42,7 +42,6 @@ class V2boardCache extends Command
*/ */
public function handle() public function handle()
{ {
$this->cacheServerStat();
} }
private function cacheServerStat() private function cacheServerStat()
@ -63,8 +62,7 @@ class V2boardCache extends Command
'd' => $serverLog->d, 'd' => $serverLog->d,
'online' => $serverLog->online 'online' => $serverLog->online
]; ];
Cache::put(CacheKey::get('SERVER_STAT', $serverLog->server_id), json_encode($data), 3600); // ServerStat::create($data);
ServerStat::create($data);
} }
} }
} }

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\Server;
use App\Services\ServerService; use App\Services\ServerService;
use App\Services\UserService; use App\Services\UserService;
use App\Utils\CacheKey;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\User; use App\Models\User;
@ -36,7 +37,7 @@ class DeepbworkController extends Controller
if (!$server) { if (!$server) {
abort(500, 'fail'); abort(500, 'fail');
} }
Cache::put('server_last_check_at_' . $server->id, time()); Cache::put(CacheKey::get('SERVER_LAST_CHECK_AT', $server->id), time(), 3600);
$serverService = new ServerService(); $serverService = new ServerService();
$users = $serverService->getAvailableUsers(json_decode($server->group_id)); $users = $serverService->getAvailableUsers(json_decode($server->group_id));
$result = []; $result = [];
@ -71,6 +72,7 @@ class DeepbworkController extends Controller
} }
$data = file_get_contents('php://input'); $data = file_get_contents('php://input');
$data = json_decode($data, true); $data = json_decode($data, true);
Cache::put(CacheKey::get('SERVER_ONLINE_USER', $server->id), count($data), 3600);
$serverService = new ServerService(); $serverService = new ServerService();
$userService = new UserService(); $userService = new UserService();
foreach ($data as $item) { foreach ($data as $item) {

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\Server;
use App\Services\ServerService; use App\Services\ServerService;
use App\Services\UserService; use App\Services\UserService;
use App\Utils\CacheKey;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\User; use App\Models\User;
@ -34,7 +35,7 @@ class PoseidonController extends Controller
if (!$server) { if (!$server) {
return $this->error("server could not be found", 404); return $this->error("server could not be found", 404);
} }
Cache::put('server_last_check_at_' . $server->id, time()); Cache::put(CacheKey::get('SERVER_LAST_CHECK_AT', $server->id), time(), 3600);
$serverService = new ServerService(); $serverService = new ServerService();
$users = $serverService->getAvailableUsers(json_decode($server->group_id)); $users = $serverService->getAvailableUsers(json_decode($server->group_id));
$result = []; $result = [];
@ -58,14 +59,13 @@ class PoseidonController extends Controller
public function submit(Request $request) public function submit(Request $request)
{ {
if ($r = $this->verifyToken($request)) { return $r; } if ($r = $this->verifyToken($request)) { return $r; }
// Log::info('serverSubmitData:' . $request->input('node_id') . ':' . file_get_contents('php://input'));
$server = Server::find($request->input('node_id')); $server = Server::find($request->input('node_id'));
if (!$server) { if (!$server) {
return $this->error("server could not be found", 404); return $this->error("server could not be found", 404);
} }
$data = file_get_contents('php://input'); $data = file_get_contents('php://input');
$data = json_decode($data, true); $data = json_decode($data, true);
Cache::put(CacheKey::get('SERVER_ONLINE_USER', $server->id), count($data), 3600);
$serverService = new ServerService(); $serverService = new ServerService();
$userService = new UserService(); $userService = new UserService();
foreach ($data as $item) { foreach ($data as $item) {

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Services\UserService; use App\Services\UserService;
use App\Utils\CacheKey;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use App\Models\Server; use App\Models\Server;
@ -33,9 +34,9 @@ class ServerController extends Controller
for ($i = 0; $i < count($server); $i++) { for ($i = 0; $i < count($server); $i++) {
$server[$i]['link'] = Helper::buildVmessLink($server[$i], $user); $server[$i]['link'] = Helper::buildVmessLink($server[$i], $user);
if ($server[$i]['parent_id']) { if ($server[$i]['parent_id']) {
$server[$i]['last_check_at'] = Cache::get('server_last_check_at_' . $server[$i]['parent_id']); $server[$i]['last_check_at'] = Cache::get(CacheKey::get('SERVER_LAST_CHECK_AT', $server[$i]['parent_id']));
} else { } else {
$server[$i]['last_check_at'] = Cache::get('server_last_check_at_' . $server[$i]['id']); $server[$i]['last_check_at'] = Cache::get(CacheKey::get('SERVER_LAST_CHECK_AT', $server[$i]['id']));
} }
} }
return response([ return response([

View File

@ -7,7 +7,8 @@ class CacheKey
CONST KEYS = [ CONST KEYS = [
'EMAIL_VERIFY_CODE' => '邮箱验证吗', 'EMAIL_VERIFY_CODE' => '邮箱验证吗',
'LAST_SEND_EMAIL_VERIFY_TIMESTAMP' => '最后一次发送邮箱验证码时间', 'LAST_SEND_EMAIL_VERIFY_TIMESTAMP' => '最后一次发送邮箱验证码时间',
'SERVER_STAT' => '节点统计信息' 'SERVER_ONLINE_USER' => '节点在线用户',
'SERVER_LAST_CHECK_AT' => '节点最后检查时间'
]; ];
public static function get(string $key, $uniqueValue) public static function get(string $key, $uniqueValue)