dd/app/Http/Controllers/Api/CountryController.php
2025-07-03 19:43:42 +08:00

63 lines
1.4 KiB
PHP
Executable File

<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api;
use App\Models\BoxCountry as ModelCountry;
final class CountryController
{
// case等于不同的集成方案
public function rand($sCase = "a")
{
if ($sCase == "a") {
$iCountryLimit = rand(4, 8); // 平均6
$iNodeLimit = rand(10, 35); // 平局20多
$iSpeedLimit = rand(5, 30);
}
//test
// $iCountryLimit = 3;
$iNodeCount = $iNodeLimit;
$iSpeed = $iSpeedLimit;
$aCountry = ModelCountry::all()->toArray();
shuffle($aCountry);
$i = 1;
$aRandCountry = [];
foreach ($aCountry as $aCountryRow) {
if (in_array($aCountryRow["name"], $aRandCountry)) {
continue;
}
$aRandCountry[] = $aCountryRow["name"];
if ($i >= $iCountryLimit) {
break;
} else {
$i++;
}
}
$aData["country"] = $aRandCountry;
$aData["nodeCount"] = $iNodeCount;
$aData["speed"] = $iSpeed;
// $aData["str"] = "本次更新共".$iNodeLimit."个可用节点,";
// tomd($iSpeed, 1);
// tomd($aData, 1);
echo json_encode($aData);
exit;
}
}