CrestRoad/laravel/app/Console/Commands/SendMissings.php

74 lines
2.2 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Http\Requests\LambdaRequest;
use Illuminate\Support\Facades\Http;
use Log;
class SendMissings extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'whatsapp:sendmissings';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$records = DB::table("lms_users as u")->select("u.contact_id", "r.is_sent", "u.created_date", "u.phone", "u.name", "u.email")
->leftjoin("raphiwa_send as r", "r.to", "u.phone")
//->wherein("u.phone", ["9720692366","7310790572","9997341855","7417823793","8954762406"])
->where("u.created_date", '>=', date("Y-m-d H:i:s", strtotime("now")-(60*15) ))
->where("r.session_id", 0)
//->limit(1)
->get();
$not_received = [];
foreach($records as $record) {
if(!isset($record->is_sent)) {
$not_received[] = $record->phone.'-'.$record->name;
$rsdata = ['to' => $record->phone,
'text' => json_encode(['countryCode'=>'+91','phoneNumber'=>$record->phone,'callbackData'=>rand(10000,99999).'-'.$record->contact_id,'type'=>'Template','template'=>['name'=>'paramedic_course_registration_success','languageCode'=>'en','bodyValues'=>[$record->name,$record->contact_id] ] ]),
'is_sent' => 0,
'session_id' => 0,
'contact_id' => $record->contact_id,
'status' => 1
];
DB::table("raphiwa_send")->insert($rsdata);
// print_r($rsdata);
}
}
print_r($not_received);
exit;
}
}