with('server')->whereIn('status', [2, 3, 5, 8, 9])->get(); DB::table('num_log')->insert([ 'title' => 'count', 'content' => $allSites->count(), 'created_at' => date('Y-m-d H:i:s') ]); $errorCount = 0; foreach ($allSites as $site) { try { if (empty($site->server)) { continue; } $top10 = $rankCon->table('project_history')->selectRaw('top10') ->where(['project_id' => $site->old_id])->orderByDesc('create_time')->first(); //流程程序开发流程 部署 $config = [ 'connection_name' => sprintf('connection_name_%s', $site->id), 'host' => $site->server->server_ip, 'port' => '3306', 'database' => $site->database, 'username' => $site->server->mysql_user_name, 'password' => $site->server->mysql_passwd, ]; config_connection($config); $inquire = DB::connection($config['connection_name'])->table('user_msg')->count(); $traffic = DB::connection($config['connection_name'])->table('traffic_report_hourly')->selectRaw('SUM(pv) as pvTotal')->first(); DB::table('num')->insert([ 'site_id' => $site->id, 'cn_title' => $site->cn_title, 'domain' => $site->domain, 'ymd' => date('Ymd'), 'traffic' => $traffic->pvTotal ?? 0, 'inquire' => $inquire, 'top10' => $top10->top10 ?? 0, 'created_at' => date('Y-m-d H:i:s') ]); } catch (\Throwable $throwable) { $errorCount++; Log::error(substr(var_export($throwable->getMessage(), 1), 0, 200)); echo $site->cn_title . PHP_EOL; } } DB::table('num_log')->insert([ 'title' => 'error', 'content' => $errorCount, 'created_at' => date('Y-m-d H:i:s') ]); $this->info('success'); } }