Implement seeders instead of seeding using migrations, log whatasapp message
This commit is contained in:
@@ -104,19 +104,22 @@ class SettingController extends Controller
|
|||||||
// flushed the fail job in queueu
|
// flushed the fail job in queueu
|
||||||
Artisan::call('queue:flush');
|
Artisan::call('queue:flush');
|
||||||
|
|
||||||
$getClassNameString = function($className){
|
$getClassNameString = function ($className) {
|
||||||
$ola = explode("\\", $className);
|
$name = explode("\\", $className);
|
||||||
return end($ola);
|
return end($name);
|
||||||
};
|
};
|
||||||
|
|
||||||
DB::connection('mysql7')
|
$commodityNotificationClasses = [
|
||||||
->table('jobs')
|
WhatsappUnsoldCommodityNotification::class,
|
||||||
->where('payload', 'like', '%' . $getClassNameString(WhatsappUnsoldCommodityNotification::class) . '%')
|
WhatsappUnsoldCommodityScanner::class,
|
||||||
->delete();
|
];
|
||||||
|
|
||||||
DB::connection('mysql7')
|
|
||||||
->table('jobs')
|
foreach ($commodityNotificationClasses as $class) {
|
||||||
->where('payload', 'like', '%' . $getClassNameString(WhatsappUnsoldCommodityScanner::class) . '%')
|
DB::connection('mysql7')
|
||||||
->delete();
|
->table('jobs')
|
||||||
|
->where('payload', 'like', '%' . $getClassNameString($class) . '%')
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Jobs;
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\BlastWasap;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use App\Setting;
|
use App\Setting;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
@@ -64,20 +65,35 @@ class WhatsappUnsoldCommodityNotification extends Job
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (!$isKomoditiStillAvailable) {
|
if (!$isKomoditiStillAvailable) {
|
||||||
// return false;
|
return false;
|
||||||
// }
|
}
|
||||||
|
|
||||||
foreach ($phone_numbers as $phone_number) {
|
foreach ($phone_numbers as $phone_number) {
|
||||||
Http::get(env('WABOT_API'), [
|
$response = Http::get(env('WABOT_API'), [
|
||||||
'number' => $phone_number,
|
'number' => $phone_number,
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
'instance_id' => env('WABOT_INSTANCES_ID'),
|
'instance_id' => env('WABOT_INSTANCES_ID'),
|
||||||
'access_token' => env('WABOT_TOKEN_KEYS')
|
'access_token' => env('WABOT_TOKEN_KEYS')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
//insert log blast wasap
|
||||||
|
$logblastwasap = new BlastWasap();
|
||||||
|
$logblastwasap->kodcaw = 'OPERASI';
|
||||||
|
$logblastwasap->notelefon = $phone_number;
|
||||||
|
$logblastwasap->norujukan = 'Notifikasi Komoditi Tidak Terjual';
|
||||||
|
$logblastwasap->status = $response;
|
||||||
|
$logblastwasap->created_at = Carbon::now();
|
||||||
|
$logblastwasap->updated_at = Carbon::now();
|
||||||
|
$logblastwasap->save();
|
||||||
|
|
||||||
|
Log::info("WABOT - Notifikasi Komoditi Tidak Terjual".$response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dispatch((new WhatsappUnsoldCommodityNotification($this->message))->delay(Carbon::now()->addMinutes(5)));
|
dispatch((new WhatsappUnsoldCommodityNotification($this->message))->delay(Carbon::now()->addMinutes(5)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ class CreateSettingsTable extends Migration
|
|||||||
$table->text('description')->nullable();
|
$table->text('description')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Call the seeder
|
||||||
|
(new UnsoldCommodityNotificationSettingSeeders())->run();
|
||||||
|
(new UnsoldCommodityNotificationPICSeeders())->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Setting;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class UnsoldCommodityNotificationPICSeeders extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$data_pic = [
|
||||||
|
'pic_sunday' => [
|
||||||
|
[
|
||||||
|
'id' => 366, // nurasiah@pkb.net.my
|
||||||
|
'no_telefon' => '0123456789',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'pic_monday' => [
|
||||||
|
[
|
||||||
|
'id' => 343, // syada@pkb.net.my
|
||||||
|
'no_telefon' => '0139403344',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 54, // shahmin@pkb.net.my
|
||||||
|
'no_telefon' => '0196438873',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'pic_tuesday' => [
|
||||||
|
[
|
||||||
|
'id' => 55, // manita@pkb.net.my
|
||||||
|
'no_telefon' => '0179545432',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'pic_wednesday' => [
|
||||||
|
[
|
||||||
|
'id' => 52, // izzudin@pkb.net.my
|
||||||
|
'no_telefon' => '0199011095',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'pic_thursday' => [
|
||||||
|
[
|
||||||
|
'id' => 53, // norosmini@pkb.net.my
|
||||||
|
'no_telefon' => '0129493588',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 56, // rozarina@pkb.net.my
|
||||||
|
'no_telefon' => '0129616201',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'pic_friday' => [[]],
|
||||||
|
'pic_saturday' => [[]],
|
||||||
|
];
|
||||||
|
|
||||||
|
$transformed_data = array_map(function($pic){
|
||||||
|
return json_encode($pic);
|
||||||
|
}, $data_pic);
|
||||||
|
|
||||||
|
$outputs = array_combine(array_keys($data_pic), $transformed_data);
|
||||||
|
|
||||||
|
foreach ($outputs as $key => $data) {
|
||||||
|
Setting::where('group', 'unsold_commodity_notifications')
|
||||||
|
->where('key', $key)
|
||||||
|
->update(['value' => $data]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-17
@@ -1,22 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Setting;
|
use App\Setting;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Seeder;
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
class AddUnsoldCommoditiesSettings extends Migration
|
class UnsoldCommodityNotificationSettingSeeders extends Seeder
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the database seeds.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function up()
|
public function run()
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
[
|
[
|
||||||
'key' => 'status',
|
'key' => 'status',
|
||||||
'value' => 'true',
|
'value' => '1',
|
||||||
'group' => 'unsold_commodity_notifications',
|
'group' => 'unsold_commodity_notifications',
|
||||||
'description' => 'Turn on or turn off notification for unsold commodity notifications',
|
'description' => 'Turn on or turn off notification for unsold commodity notifications',
|
||||||
],
|
],
|
||||||
@@ -83,18 +82,8 @@ class AddUnsoldCommoditiesSettings extends Migration
|
|||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
array_walk($data, function($setting){
|
array_walk($data, function ($setting) {
|
||||||
Setting::create($setting);
|
Setting::create($setting);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function down()
|
|
||||||
{
|
|
||||||
Schema::dropIfExists('settings');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user