info('Checking Data ...'); $client = new Client([ 'base_uri' => 'https://api.linksehat.com', 'headers' => ['Content-Type' => 'application/json'], 'timeout' => 10, ]); $liveChats = Livechat::query() ->join('tx_livechat_summary', 'tx_livechat_summary.nIDLiveChat', '=', 'tx_livechat.nID') ->whereNull('tx_livechat.sNoSpj') ->whereDate('tx_livechat.dCreateOn', Carbon::today()) ->select('tx_livechat.nID', 'tx_livechat_summary.nID as summary_id') ->get(); foreach ($liveChats as $row) { try { $prescriptionData = [ 'nIDLivechats' => [$row->nID] ]; $response = $client->post('/api/rujukan-dan-sjp', [ 'json' => $prescriptionData, ]); $body = json_decode($response->getBody()->getContents(), true); LivechatUpdateLog::create([ 'nIDLivechat' => $row->nID, 'nIDSummary' => $row->summary_id, 'status' => 'success', 'response' => json_encode($body) ]); $this->info("Nomor SJP berhasil dibuat untuk Livechat {$row->nID}"); } catch (\Exception $e) { LivechatUpdateLog::create([ 'nIDLivechat' => $row->nID, 'nIDSummary' => $row->summary_id, 'status' => 'fail', 'response' => $e->getMessage() ]); $this->error("Gagal generate Nomor SJP Livechat {$row->nID}: " . $e->getMessage()); } } $this->info('Proses selesai.'); return Command::SUCCESS; } }