Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function FeedTaskIdBpjs()
- {
- date_default_timezone_set('Asia/Jakarta');
- $tglAntrianAwal = now()->format('Y-m-d');
- $tglAntrianAkhir = now()->format('Y-m-d');
- /* update status antrol ----------------------------------------------------- */
- $query = DB::connection('simak')->table('tbt_antrian_pendaftaran')->select([
- 'tbt_antrian_pendaftaran.id',
- 'tbt_antrian_pendaftaran.no_trans',
- 'tbt_antrian_pendaftaran.tgl',
- 'tbt_antrian_pendaftaran.tgl_panggil',
- 'tbt_antrian_pendaftaran.wkt_panggil',
- 'tbt_antrian_pendaftaran.loket',
- 'tbt_antrian_pendaftaran.no_urut',
- ])->whereBetween('tgl', [$tglAntrianAwal, $tglAntrianAkhir])->whereNotNull('no_trans')->where('no_trans', '!=', '')->where('st_antrol', '0')->orderBy('tgl', 'asc');
- dump(count($query->get()));
- $query->chunk(100, function (Collection $rows) {
- foreach ($rows as $rowData) {
- $kodebooking = date('Ymd', strtotime($rowData->tgl)) . $rowData->loket . $rowData->no_urut;
- $output = $this->antrean->antreanPerKodeBooking($kodebooking);
- if ($output['metadata']['code'] == '200') {
- DB::connection('simak')->table('tbt_antrian_pendaftaran')->where('id', $rowData->id)->update([
- 'st_antrol' => '1',
- ]);
- }
- }
- sleep(60);
- });
- /* update task id antrol ---------------------------------------------------- */
- $query = DB::connection('simak')->table('tbt_antrian_pendaftaran')->select([
- 'tbt_antrian_pendaftaran.id',
- 'tbt_antrian_pendaftaran.no_trans',
- 'tbt_antrian_pendaftaran.tgl',
- 'tbt_antrian_pendaftaran.tgl_panggil',
- 'tbt_antrian_pendaftaran.wkt_panggil',
- 'tbt_antrian_pendaftaran.loket',
- 'tbt_antrian_pendaftaran.no_urut',
- ])->whereBetween('tgl', [$tglAntrianAwal, $tglAntrianAkhir])->whereNotNull('no_trans')->where('no_trans', '!=', '')->where('st_antrol', '!=', '0')->orderBy('tgl', 'asc');
- dump(count($query->get()));
- $query->chunk(100, function (Collection $rows) {
- foreach ($rows as $rowData) {
- $kodebooking = date('Ymd', strtotime($rowData->tgl)) . $rowData->loket . $rowData->no_urut;
- /* START: TASK ID 1 --------------------------------------------------------- */
- $tglPanggil = date_format(date_create($rowData->tgl_panggil . ' ' . $rowData->wkt_panggil), 'Y-m-d H:i:s');
- $start = strtotime(date('Y-m-d H:i:s', strtotime($tglPanggil . '-10 minutes')));
- $end = strtotime($tglPanggil);
- $newTimestamp = mt_rand($start, $end);
- $newTime = date('Y-m-d H:i:s', $newTimestamp);
- $timestamp = $newTimestamp * 1000;
- $this->FeedTaskIdBpjsProcess('1', $rowData, $kodebooking, $timestamp);
- /* END: TASK ID 1 ----------------------------------------------------------- */
- /* START: TASK ID 2 --------------------------------------------------------- */
- $timestamp = $end * 1000;
- $this->FeedTaskIdBpjsProcess('2', $rowData, $kodebooking, $timestamp);
- /* END: TASK ID 2 ----------------------------------------------------------- */
- $RwtjlnRecord = DB::connection('simak')->table('tbt_rawat_jalan')->where('no_trans', $rowData->no_trans)->first();
- if ($RwtjlnRecord) {
- /* START: TASK ID 3 --------------------------------------------------------- */
- $tglKunjungan = date_format(date_create($RwtjlnRecord->tgl_visit . ' ' . $RwtjlnRecord->wkt_visit), 'Y-m-d H:i:s');
- $startTimestamp = $timestamp;
- $endTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+3 minutes', $startTimestamp / 1000)));
- $tolTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+1 minutes', $startTimestamp / 1000)));
- $newTimestamp = mt_rand($tolTimestamp, $endTimestamp);
- $timestamp = $newTimestamp * 1000;
- $this->FeedTaskIdBpjsProcess('3', $rowData, $kodebooking, $timestamp);
- /* END: TASK ID 3 ----------------------------------------------------------- */
- /* START: TASK ID 4 --------------------------------------------------------- */
- $startTimestamp = $timestamp;
- $endTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+20 minutes', $startTimestamp / 1000)));
- $tolTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+10 minutes', $startTimestamp / 1000)));
- $newTimestamp = mt_rand($tolTimestamp, $endTimestamp);
- $timestamp = $newTimestamp * 1000;
- $this->FeedTaskIdBpjsProcess('4', $rowData, $kodebooking, $timestamp);
- /* END: TASK ID 4 ----------------------------------------------------------- */
- /* START: TASK ID 5 --------------------------------------------------------- */
- $startTimestamp = $timestamp;
- $endTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+20 minutes', $startTimestamp / 1000)));
- $tolTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+10 minutes', $startTimestamp / 1000)));
- $newTimestamp = mt_rand($tolTimestamp, $endTimestamp);
- $timestamp = $newTimestamp * 1000;
- $this->FeedTaskIdBpjsProcess('5', $rowData, $kodebooking, $timestamp);
- /* END: TASK ID 5 ----------------------------------------------------------- */
- /* START: TASK ID 6 --------------------------------------------------------- */
- $startTimestamp = $timestamp;
- $endTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+15 minutes', $startTimestamp / 1000)));
- $tolTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+5 minutes', $startTimestamp / 1000)));
- $newTimestamp = mt_rand($tolTimestamp, $endTimestamp);
- $timestamp = $newTimestamp * 1000;
- $this->FeedTaskIdBpjsProcess('6', $rowData, $kodebooking, $timestamp);
- /* END: TASK ID 6 ----------------------------------------------------------- */
- /* START: TASK ID 7 --------------------------------------------------------- */
- $startTimestamp = $timestamp;
- $endTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+20 minutes', $startTimestamp / 1000)));
- $tolTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+10 minutes', $startTimestamp / 1000)));
- $newTimestamp = mt_rand($tolTimestamp, $endTimestamp);
- $timestamp = $newTimestamp * 1000;
- $this->FeedTaskIdBpjsProcess('7', $rowData, $kodebooking, $timestamp);
- /* END: TASK ID 7 ----------------------------------------------------------- */
- }
- }
- sleep(60);
- });
- }
- public function FeedTaskIdBpjsProcess($taskid, $rowData, $kodebooking, $timestamp)
- {
- $timestampnow = now()->timestamp * 1000;
- $execute = $timestamp < $timestampnow;
- if (!$execute) return;
- $AntreanOnlineRecord = DB::connection('simak')->table('tbt_antrean_online')->where('id_antrian', $rowData->id)->where('taskid', $taskid)->first();
- if (!$AntreanOnlineRecord) {
- $insert = DB::connection('simak')->table('tbt_antrean_online')->insertGetId([
- 'tgl' => $rowData->tgl,
- 'wkt' => now()->format('Y-m-d H:i:s'),
- 'id_antrian' => $rowData->id,
- 'taskid' => $taskid,
- 'timestamp' => $timestamp,
- 'st' => '0',
- ]);
- $AntreanOnlineRecord = DB::connection('simak')->table('tbt_antrean_online')->where('id', $insert)->first();
- $st = $AntreanOnlineRecord->st;
- } else {
- $st = $AntreanOnlineRecord->st;
- }
- dump('x ------------------------------------------------------------------------');
- dump("status taskid {$taskid} kodebooking: {$kodebooking} | id: {$rowData->id} => ".($st == '0' ? 'belum' : 'sudah')." submit");
- dump('x ------------------------------------------------------------------------');
- if ($st != '1') {
- $dataUpdateAntrean = [
- 'kodebooking' => $kodebooking,
- 'taskid' => $taskid,
- 'waktu' => $timestamp,
- ];
- $output = $this->antrean->updateWaktuAntrean($dataUpdateAntrean);
- DB::connection('simak')->table('api_response_antrean')->insert([
- 'tgl' => $rowData->tgl,
- 'waktu' => now()->format('H:i:s'),
- 'source' => 'feeding',
- 'id_antrian' => $rowData->id,
- 'data_content' => addslashes(json_encode($dataUpdateAntrean)),
- 'response_type' => '0',
- 'response' => json_encode($output),
- ]);
- if ($output['metadata']['code'] == '200') {
- DB::connection('simak')->table('tbt_antrean_online')->where('id', $AntreanOnlineRecord->id)->update([
- 'st' => '1',
- ]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement