NodeService.php 657 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace App\Services;
  3. use App\Components\IP;
  4. use App\Models\Node;
  5. class NodeService
  6. {
  7. public function getNodeGeo($id = false): int
  8. {
  9. if ($id) {
  10. $nodes = Node::whereStatus(1)->whereId($id)->get();
  11. } else {
  12. $nodes = Node::whereStatus(1)->get();
  13. }
  14. $result = 0;
  15. foreach ($nodes as $node) {
  16. $data = IP::IPSB($node->is_ddns ? gethostbyname($node->server) : $node->ip);
  17. if ($data && Node::whereId($node->id)->update(['geo' => $data['latitude'].','.$data['longitude']])) {
  18. $result++;
  19. }
  20. }
  21. return $result;
  22. }
  23. }