Codebase update
- Remove default pic assignments for unsold commodity notifications - Check wabot credential complete first before notification blast, if incomplete no notification be sent - Change migration column order for settings table, column group first - Resolve error of not showing select after updating any PIC for selected day
This commit is contained in:
@@ -57,6 +57,11 @@ class SettingController extends Controller
|
||||
|
||||
array_walk($unique_pic_input, function ($item) use (&$transformed_unique_pic_input) {
|
||||
foreach ($item as $key => $value) {
|
||||
|
||||
if(count($value) === 0){
|
||||
$value = [new \stdClass()];
|
||||
}
|
||||
|
||||
$transformed_unique_pic_input[$key] = $value;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -37,7 +37,8 @@ class WhatsappUnsoldCommodityNotification extends Job
|
||||
$start_time = $settings->where('key', 'start_time')->first()->value;
|
||||
$end_time = $settings->where('key', 'end_time')->first()->value;
|
||||
$message = $settings->where('key', 'message')->first()->value;
|
||||
$isKomoditiStillSold = KomuditiPurchase::on('mysql7')->latest()->first()->unit_komuditi === 0;
|
||||
$isAllKomoditiSold = KomuditiPurchase::on('mysql7')->latest()->first()->unit_komuditi === 0;
|
||||
$isWabotCredentialNotComplete = env('WABOT_API') === null || env('WABOT_INSTANCES_ID') === null || env('WABOT_TOKEN_KEYS') === null;
|
||||
|
||||
$pic_key = 'pic_' . strtolower(Carbon::now()->englishDayOfWeek);
|
||||
$pic = json_decode($settings->where('key', $pic_key)->first()->value);
|
||||
@@ -48,12 +49,18 @@ class WhatsappUnsoldCommodityNotification extends Job
|
||||
}
|
||||
}, $pic);
|
||||
|
||||
if ($isWabotCredentialNotComplete) {
|
||||
Log::error('Wabot credential not complete');
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($phone_numbers[0] === NULL) {
|
||||
Log::error('No PIC phone numbers detected');
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($status === '0') {
|
||||
Log::info('Unsold commodity notifications are turned off, no notification will be sent');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -65,10 +72,12 @@ class WhatsappUnsoldCommodityNotification extends Job
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($isKomoditiStillSold) {
|
||||
if ($isAllKomoditiSold) {
|
||||
Log::info('All komoditi is sold');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
foreach ($phone_numbers as $phone_number) {
|
||||
$response = Http::get(env('WABOT_API'), [
|
||||
'number' => $phone_number,
|
||||
@@ -89,12 +98,11 @@ class WhatsappUnsoldCommodityNotification extends Job
|
||||
$logblastwasap->updated_at = Carbon::now();
|
||||
$logblastwasap->save();
|
||||
|
||||
Log::info("WABOT - Notifikasi Komoditi Tidak Terjual".$response);
|
||||
Log::info("WABOT - Notifikasi Komoditi Tidak Terjual" . $response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
dispatch((new WhatsappUnsoldCommodityNotification($this->message))->delay(Carbon::now()->addMinutes(5)));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user