Advertisement
Purwadi

feeding

Jul 1st, 2025
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.34 KB | None | 0 0
  1. public function FeedTaskIdBpjs()
  2. {
  3.   date_default_timezone_set('Asia/Jakarta');
  4.  
  5.   $tglAntrianAwal = now()->format('Y-m-d');
  6.   $tglAntrianAkhir = now()->format('Y-m-d');
  7.  
  8.   /* update status antrol ----------------------------------------------------- */
  9.   $query = DB::connection('simak')->table('tbt_antrian_pendaftaran')->select([
  10.     'tbt_antrian_pendaftaran.id',
  11.     'tbt_antrian_pendaftaran.no_trans',
  12.     'tbt_antrian_pendaftaran.tgl',
  13.     'tbt_antrian_pendaftaran.tgl_panggil',
  14.     'tbt_antrian_pendaftaran.wkt_panggil',
  15.     'tbt_antrian_pendaftaran.loket',
  16.     'tbt_antrian_pendaftaran.no_urut',
  17.   ])->whereBetween('tgl', [$tglAntrianAwal, $tglAntrianAkhir])->whereNotNull('no_trans')->where('no_trans', '!=', '')->where('st_antrol', '0')->orderBy('tgl', 'asc');
  18.  
  19.   dump(count($query->get()));
  20.  
  21.   $query->chunk(100, function (Collection $rows) {
  22.     foreach ($rows as $rowData) {
  23.       $kodebooking = date('Ymd', strtotime($rowData->tgl)) . $rowData->loket . $rowData->no_urut;
  24.  
  25.       $output = $this->antrean->antreanPerKodeBooking($kodebooking);
  26.       if ($output['metadata']['code'] == '200') {
  27.         DB::connection('simak')->table('tbt_antrian_pendaftaran')->where('id', $rowData->id)->update([
  28.           'st_antrol' => '1',
  29.         ]);
  30.       }
  31.     }
  32.     sleep(60);
  33.   });
  34.  
  35.   /* update task id antrol ---------------------------------------------------- */
  36.   $query = DB::connection('simak')->table('tbt_antrian_pendaftaran')->select([
  37.     'tbt_antrian_pendaftaran.id',
  38.     'tbt_antrian_pendaftaran.no_trans',
  39.     'tbt_antrian_pendaftaran.tgl',
  40.     'tbt_antrian_pendaftaran.tgl_panggil',
  41.     'tbt_antrian_pendaftaran.wkt_panggil',
  42.     'tbt_antrian_pendaftaran.loket',
  43.     'tbt_antrian_pendaftaran.no_urut',
  44.   ])->whereBetween('tgl', [$tglAntrianAwal, $tglAntrianAkhir])->whereNotNull('no_trans')->where('no_trans', '!=', '')->where('st_antrol', '!=', '0')->orderBy('tgl', 'asc');
  45.  
  46.   dump(count($query->get()));
  47.  
  48.   $query->chunk(100, function (Collection $rows) {
  49.     foreach ($rows as $rowData) {
  50.       $kodebooking = date('Ymd', strtotime($rowData->tgl)) . $rowData->loket . $rowData->no_urut;
  51.  
  52.       /* START: TASK ID 1 --------------------------------------------------------- */
  53.       $tglPanggil = date_format(date_create($rowData->tgl_panggil . ' ' . $rowData->wkt_panggil), 'Y-m-d H:i:s');
  54.       $start = strtotime(date('Y-m-d H:i:s', strtotime($tglPanggil . '-10 minutes')));
  55.       $end = strtotime($tglPanggil);
  56.  
  57.       $newTimestamp = mt_rand($start, $end);
  58.       $newTime = date('Y-m-d H:i:s', $newTimestamp);
  59.       $timestamp = $newTimestamp * 1000;
  60.  
  61.       $this->FeedTaskIdBpjsProcess('1', $rowData, $kodebooking, $timestamp);
  62.       /* END: TASK ID 1 ----------------------------------------------------------- */
  63.  
  64.       /* START: TASK ID 2 --------------------------------------------------------- */
  65.       $timestamp = $end * 1000;
  66.       $this->FeedTaskIdBpjsProcess('2', $rowData, $kodebooking, $timestamp);
  67.       /* END: TASK ID 2 ----------------------------------------------------------- */
  68.  
  69.       $RwtjlnRecord = DB::connection('simak')->table('tbt_rawat_jalan')->where('no_trans', $rowData->no_trans)->first();
  70.       if ($RwtjlnRecord) {
  71.         /* START: TASK ID 3 --------------------------------------------------------- */
  72.         $tglKunjungan = date_format(date_create($RwtjlnRecord->tgl_visit . ' ' . $RwtjlnRecord->wkt_visit), 'Y-m-d H:i:s');
  73.  
  74.         $startTimestamp = $timestamp;
  75.         $endTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+3 minutes', $startTimestamp / 1000)));
  76.         $tolTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+1 minutes', $startTimestamp / 1000)));
  77.  
  78.         $newTimestamp = mt_rand($tolTimestamp, $endTimestamp);
  79.         $timestamp = $newTimestamp * 1000;
  80.  
  81.         $this->FeedTaskIdBpjsProcess('3', $rowData, $kodebooking, $timestamp);
  82.         /* END: TASK ID 3 ----------------------------------------------------------- */
  83.  
  84.         /* START: TASK ID 4 --------------------------------------------------------- */
  85.         $startTimestamp = $timestamp;
  86.         $endTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+20 minutes', $startTimestamp / 1000)));
  87.         $tolTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+10 minutes', $startTimestamp / 1000)));
  88.  
  89.         $newTimestamp = mt_rand($tolTimestamp, $endTimestamp);
  90.         $timestamp = $newTimestamp * 1000;
  91.  
  92.         $this->FeedTaskIdBpjsProcess('4', $rowData, $kodebooking, $timestamp);
  93.         /* END: TASK ID 4 ----------------------------------------------------------- */
  94.  
  95.         /* START: TASK ID 5 --------------------------------------------------------- */
  96.         $startTimestamp = $timestamp;
  97.         $endTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+20 minutes', $startTimestamp / 1000)));
  98.         $tolTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+10 minutes', $startTimestamp / 1000)));
  99.  
  100.         $newTimestamp = mt_rand($tolTimestamp, $endTimestamp);
  101.         $timestamp = $newTimestamp * 1000;
  102.  
  103.         $this->FeedTaskIdBpjsProcess('5', $rowData, $kodebooking, $timestamp);
  104.         /* END: TASK ID 5 ----------------------------------------------------------- */
  105.  
  106.         /* START: TASK ID 6 --------------------------------------------------------- */
  107.         $startTimestamp = $timestamp;
  108.         $endTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+15 minutes', $startTimestamp / 1000)));
  109.         $tolTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+5 minutes', $startTimestamp / 1000)));
  110.  
  111.         $newTimestamp = mt_rand($tolTimestamp, $endTimestamp);
  112.         $timestamp = $newTimestamp * 1000;
  113.  
  114.         $this->FeedTaskIdBpjsProcess('6', $rowData, $kodebooking, $timestamp);
  115.         /* END: TASK ID 6 ----------------------------------------------------------- */
  116.  
  117.         /* START: TASK ID 7 --------------------------------------------------------- */
  118.         $startTimestamp = $timestamp;
  119.         $endTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+20 minutes', $startTimestamp / 1000)));
  120.         $tolTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+10 minutes', $startTimestamp / 1000)));
  121.  
  122.         $newTimestamp = mt_rand($tolTimestamp, $endTimestamp);
  123.         $timestamp = $newTimestamp * 1000;
  124.  
  125.         $this->FeedTaskIdBpjsProcess('7', $rowData, $kodebooking, $timestamp);
  126.         /* END: TASK ID 7 ----------------------------------------------------------- */
  127.       }
  128.     }
  129.     sleep(60);
  130.   });
  131. }
  132.  
  133. public function FeedTaskIdBpjsProcess($taskid, $rowData, $kodebooking, $timestamp)
  134. {
  135.   $timestampnow = now()->timestamp * 1000;
  136.   $execute = $timestamp < $timestampnow;
  137.  
  138.   if (!$execute) return;
  139.  
  140.   $AntreanOnlineRecord = DB::connection('simak')->table('tbt_antrean_online')->where('id_antrian', $rowData->id)->where('taskid', $taskid)->first();
  141.   if (!$AntreanOnlineRecord) {
  142.     $insert = DB::connection('simak')->table('tbt_antrean_online')->insertGetId([
  143.       'tgl' => $rowData->tgl,
  144.       'wkt' => now()->format('Y-m-d H:i:s'),
  145.       'id_antrian' => $rowData->id,
  146.       'taskid' => $taskid,
  147.       'timestamp' => $timestamp,
  148.       'st' => '0',
  149.     ]);
  150.     $AntreanOnlineRecord = DB::connection('simak')->table('tbt_antrean_online')->where('id', $insert)->first();
  151.     $st = $AntreanOnlineRecord->st;
  152.   } else {
  153.     $st = $AntreanOnlineRecord->st;
  154.   }
  155.  
  156.   dump('x ------------------------------------------------------------------------');
  157.   dump("status taskid {$taskid} kodebooking: {$kodebooking} | id: {$rowData->id} => ".($st == '0' ? 'belum' : 'sudah')." submit");
  158.   dump('x ------------------------------------------------------------------------');
  159.  
  160.   if ($st != '1') {
  161.     $dataUpdateAntrean = [
  162.       'kodebooking' => $kodebooking,
  163.       'taskid' => $taskid,
  164.       'waktu' => $timestamp,
  165.     ];
  166.     $output = $this->antrean->updateWaktuAntrean($dataUpdateAntrean);
  167.  
  168.     DB::connection('simak')->table('api_response_antrean')->insert([
  169.       'tgl' => $rowData->tgl,
  170.       'waktu' => now()->format('H:i:s'),
  171.       'source' => 'feeding',
  172.       'id_antrian' => $rowData->id,
  173.       'data_content' => addslashes(json_encode($dataUpdateAntrean)),
  174.       'response_type' => '0',
  175.       'response' => json_encode($output),
  176.     ]);
  177.  
  178.     if ($output['metadata']['code'] == '200') {
  179.       DB::connection('simak')->table('tbt_antrean_online')->where('id', $AntreanOnlineRecord->id)->update([
  180.         'st' => '1',
  181.       ]);
  182.     }
  183.   }
  184. }
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement