dd/app/Models/BoxCountry.php
2025-07-15 17:08:34 +08:00

69 lines
1.7 KiB
PHP
Executable File

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class boxCountry extends Model
{
protected $table = 'box_country';
public $timestamps = false;
public static function rand($sCase = "a")
{
if ($sCase == "a") {
$iCountryLimit = rand(5, 8); // 平均6
$iNodeLimit = rand(10, 35); // 平局20多
$iSpeedLimit = rand(5, 30);
} else if ($sCase == "b") {
$iCountryLimit = rand(6, 10);
$iNodeCount = rand(12, 35);
$iSpeedLimit = rand(5, 30);
}
//test
// $iCountryLimit = 3;
$iNodeCount = $iNodeLimit;
$iSpeed = $iSpeedLimit;
$aCountry = self::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"] = self::toStr($aData);
return $aData;
}
public static function toStr($randData)
{
$str = "本次更新共".$randData["nodeCount"]."个可用节点,最高速度".$randData["speed"]."M/S。覆盖".implode("", $randData["country"])."等多个区域。";
return $str;
}
}