mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-12 23:48:53 +00:00
1. 继续修改表表关系,与关联字段的限制; 2. 通过表表关系,简化一部分代码,自动让Laravel建立关联; 3. 拆分验证 与 优化数据创建与修改的获取数据操作; 4. 修改部分无意义的数据名称;
29 lines
657 B
PHP
29 lines
657 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Components\IP;
|
|
use App\Models\Node;
|
|
|
|
class NodeService
|
|
{
|
|
public function getNodeGeo($id = false): int
|
|
{
|
|
if ($id) {
|
|
$nodes = Node::whereStatus(1)->whereId($id)->get();
|
|
} else {
|
|
$nodes = Node::whereStatus(1)->get();
|
|
}
|
|
|
|
$result = 0;
|
|
foreach ($nodes as $node) {
|
|
$data = IP::IPSB($node->is_ddns ? gethostbyname($node->server) : $node->ip);
|
|
if ($data && Node::whereId($node->id)->update(['geo' => $data['latitude'].','.$data['longitude']])) {
|
|
$result++;
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
}
|