onQueue('stat'); $this->u = $u; $this->d = $d; $this->server = $server; $this->protocol = $protocol; $this->recordType = $recordType; } /** * Execute the job. * * @return void */ public function handle() { $recordAt = strtotime(date('Y-m-d')); if ($this->recordType === 'm') { // } $data = StatServer::where('record_at', $recordAt) ->where('server_id', $this->server->id) ->first(); if ($data) { try { $data->update([ 'u' => $data['u'] + $this->u, 'd' => $data['d'] + $this->d ]); } catch (\Exception $e) { abort(500, '节点统计数据更新失败'); } } else { if (!StatServer::create([ 'server_id' => $this->server->id, 'server_type' => $this->protocol, 'u' => $this->u, 'd' => $this->d, 'record_type' => $this->recordType, 'record_at' => $recordAt ])) { abort(500, '节点统计数据创建失败'); } } } }