作者 赵彬吉

update

  1 +<?php
  2 +
  3 +namespace App\Console\Commands\Inquiry;
  4 +
  5 +
  6 +use App\Helper\Arr;
  7 +use App\Models\Domain\DomainInfo;
  8 +use App\Models\Inquiry\ReInquiryForm;
  9 +use App\Models\Inquiry\ReInquiryTask;
  10 +use App\Utils\HttpUtils;
  11 +use GuzzleHttp\Exception\GuzzleException;
  12 +use Illuminate\Console\Command;
  13 +
  14 +/**
  15 + * Class SyncInquiry
  16 + * @package App\Console\Commands\Inquiry
  17 + */
  18 +class UpdateSiteVersion extends Command
  19 +{
  20 + /**
  21 + * The name and signature of the console command.
  22 + *
  23 + * @var string
  24 + */
  25 + protected $signature = 'update_site_version';
  26 +
  27 + /**
  28 + * The console command description.
  29 + *
  30 + * @var string
  31 + */
  32 + protected $description = '更新关联网站版本';
  33 +
  34 + /**
  35 + * Create a new command instance.
  36 + *
  37 + * @return void
  38 + */
  39 + public function __construct()
  40 + {
  41 + parent::__construct();
  42 + }
  43 +
  44 +
  45 + public function handle()
  46 + {
  47 + while (true) {
  48 + $list = ReInquiryTask::select(['target', 'id'])->get();
  49 + foreach ($list as $item){
  50 + $this->output('sync task :' . $item['id']);
  51 + if(empty($item['target'])){
  52 + continue;
  53 + }
  54 + $update = false;
  55 + $target = $item['target'];
  56 + foreach ($target as &$site){
  57 + if(!$site['is_v6']){
  58 + $domain_info = DomainInfo::where('domain', $site['url'])->first();
  59 + if($domain_info){
  60 + $site['is_v6'] = "1";
  61 + $update = true;
  62 +
  63 + echo date('Y-m-d H:i:s') . ' | ' . $site['url'] . ' 升级到V6' . PHP_EOL;
  64 + }
  65 + }
  66 + }
  67 + if($update){
  68 + $item->target = $target;
  69 + $item->save();
  70 + }
  71 + }
  72 + $this->output('sleep');
  73 + sleep(300);
  74 + }
  75 + }
  76 +
  77 +
  78 + public function output($message)
  79 + {
  80 + echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
  81 + }
  82 +}