update
This commit is contained in:
67
database/seeders/NoSpjSeeder.php
Normal file
67
database/seeders/NoSpjSeeder.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class NoSpjSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Ambil data dari tabel api_logs
|
||||
$apiLogs = DB::connection('oldlms')->table('api_logs')
|
||||
->selectRaw("`sResponse` as sResponse")
|
||||
->where('sTarget', 'INHPostSJPdanRujukan')
|
||||
->orderByDesc('nID')
|
||||
->limit(1000)
|
||||
->get();
|
||||
|
||||
// Proses setiap log untuk mengambil nosjp dan refasalsjp
|
||||
$berhasil = 0;
|
||||
foreach ($apiLogs as $log) {
|
||||
// Decode JSON string
|
||||
$decodedResponse = json_decode($log->sResponse, true);
|
||||
|
||||
// Cek apakah decode berhasil
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
// Ambil data dari field 'data' yang berisi JSON string
|
||||
$data = json_decode($decodedResponse['data'], true);
|
||||
|
||||
// Pastikan data yang diambil ada dan formatnya benar
|
||||
if (isset($data['data'][0]['nosjp'], $data['data'][0]['refasalsjp'])) {
|
||||
$nosjp = $data['data'][0]['nosjp'];
|
||||
$refasalsjp = $data['data'][0]['refasalsjp'];
|
||||
$nIDLiveChat = substr($refasalsjp, -5);
|
||||
|
||||
// // Tampilkan hasil atau lakukan penyimpanan ke tabel lain
|
||||
// echo "nosjp: " . $nosjp . ", refasalsjp: " . $refasalsjp . ", 5 karakter terakhir: " . $lastFiveCharacters . "\n";
|
||||
|
||||
// Contoh penyimpanan ke tabel lain (misal, table `processed_logs`)
|
||||
DB::connection('oldlms')->table('tx_livechat')
|
||||
->where('nID', $nIDLiveChat) // Kondisi where ditempatkan sebelum update
|
||||
->update([
|
||||
'sNoSpj' => $nosjp,
|
||||
]
|
||||
);
|
||||
|
||||
echo "Berhasil data ke: " .$berhasil ++ . "\n";;
|
||||
|
||||
} else {
|
||||
// Tangani kasus jika data tidak sesuai
|
||||
echo "Data tidak ditemukan dalam response: " . $log->sResponse . "\n";
|
||||
}
|
||||
} else {
|
||||
// Tangani kesalahan JSON decode
|
||||
echo "Error decoding JSON: " . json_last_error_msg() . " in response: " . $log->sResponse . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
47
database/seeders/TambahDataKecamatanLMS.php
Normal file
47
database/seeders/TambahDataKecamatanLMS.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TambahDataKecamatanLMS extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Data yang akan dimasukkan ke dalam tabel
|
||||
$kelurahanData = [
|
||||
['nIDKota' => 337205, 'nIDProvinsi' => 33, 'nIDKecamatan' => 337205, 'sKelurahan' => 'Banyuanyar', 'nKodePos' => 57137],
|
||||
['nIDKota' => 337205, 'nIDProvinsi' => 33, 'nIDKecamatan' => 337205, 'sKelurahan' => 'Gilingan', 'nKodePos' => 57134],
|
||||
['nIDKota' => 337205, 'nIDProvinsi' => 33, 'nIDKecamatan' => 337205, 'sKelurahan' => 'Kadipiro', 'nKodePos' => 57136],
|
||||
['nIDKota' => 337205, 'nIDProvinsi' => 33, 'nIDKecamatan' => 337205, 'sKelurahan' => 'Keprabon', 'nKodePos' => 57131],
|
||||
['nIDKota' => 337205, 'nIDProvinsi' => 33, 'nIDKecamatan' => 337205, 'sKelurahan' => 'Kestalan', 'nKodePos' => 57133],
|
||||
['nIDKota' => 337205, 'nIDProvinsi' => 33, 'nIDKecamatan' => 337205, 'sKelurahan' => 'Ketelan', 'nKodePos' => 57132],
|
||||
['nIDKota' => 337205, 'nIDProvinsi' => 33, 'nIDKecamatan' => 337205, 'sKelurahan' => 'Manahan', 'nKodePos' => 57139],
|
||||
['nIDKota' => 337205, 'nIDProvinsi' => 33, 'nIDKecamatan' => 337205, 'sKelurahan' => 'Mangkubumen', 'nKodePos' => 57139],
|
||||
['nIDKota' => 337205, 'nIDProvinsi' => 33, 'nIDKecamatan' => 337205, 'sKelurahan' => 'Nusukan', 'nKodePos' => 57135],
|
||||
['nIDKota' => 337205, 'nIDProvinsi' => 33, 'nIDKecamatan' => 337205, 'sKelurahan' => 'Punggawan', 'nKodePos' => 57132],
|
||||
['nIDKota' => 337205, 'nIDProvinsi' => 33, 'nIDKecamatan' => 337205, 'sKelurahan' => 'Setabelan', 'nKodePos' => 57133],
|
||||
['nIDKota' => 337205, 'nIDProvinsi' => 33, 'nIDKecamatan' => 337205, 'sKelurahan' => 'Sumber', 'nKodePos' => 57138],
|
||||
['nIDKota' => 337205, 'nIDProvinsi' => 33, 'nIDKecamatan' => 337205, 'sKelurahan' => 'Timuran', 'nKodePos' => 57131],
|
||||
];
|
||||
|
||||
|
||||
// Insert data ke dalam tabel kelurahan
|
||||
foreach ($kelurahanData as $data) {
|
||||
DB::connection('oldlms')->table('tm_kelurahan')->insert([
|
||||
'nIDKota' => $data['nIDKota'],
|
||||
'nIDProvinsi' => $data['nIDProvinsi'],
|
||||
'nIDKecamatan' => $data['nIDKecamatan'],
|
||||
'sKelurahan' => $data['sKelurahan'],
|
||||
'nKodePos' => $data['nKodePos'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user