update blast sms dan wasap by sag

This commit is contained in:
Nur Izzati Zulkifli
2023-12-03 09:23:33 +08:00
parent 61f739a3a5
commit 4ddbd631dc
5 changed files with 287 additions and 10 deletions
+12
View File
@@ -241,3 +241,15 @@ DB_PASSWORD_33=G0dz!ll42020
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
WABOT_API=https://md.wabot.my/api/send.php
WABOT_INSTANCES_ID=63F40BD120DB4
# WABOT_INSTANCES_ID=64892FD7440A6
WABOT_TOKEN_KEYS=cbee7e95cf3ffbfa0531d5fddfd44f87
ONEWAYSMS_API=http://gateway.onewaysms.com.my:10001/api.aspx
ONEWAYSMS_AUTH_USER=APIUK330HDAFO
ONEWAYSMS_AUTH_PASS=APIUK330HDAFOUK330
ADMIN_PHONE_NUMBER=60178916936
+81 -10
View File
@@ -35,6 +35,8 @@ use App\Jobs\SMSPelangganSAGLAMA;
use Illuminate\Http\Request;
use App\CawanganDetail;
use App\BlastSMS;
use App\Jobs\WhatsappPelangganSAGLAMAbysag;
use App\Jobs\SMSPelangganSAGLAMAbysag;
use App\Services\OnePercentServices;
@@ -166,16 +168,6 @@ class StokAuditController extends Controller
if($customer->telefon != 'null'){
$telefon=$customer->telefon;
// //insert log blast wasap
// $logblastwasap = new BlastWasap();
// $logblastwasap->kodcaw = $kodcaw;
// $logblastwasap->nokp = $nokp;
// $logblastwasap->notelefon = $customer->telefon;
// $logblastwasap->norujukan = $cal3->norujukan;
// $logblastwasap->tempoh = $cal3->tempoh;
// $logblastwasap->created_at = $current;
// $logblastwasap->updated_at = $current;
// $logblastwasap->save();
//log auditrail
$audit = new Audit();
@@ -202,6 +194,85 @@ class StokAuditController extends Controller
}
public function blastwasapbysag($kodcaw,Request $request)
{
$current = Carbon::now();
$current = new Carbon();
$daritempoh = $request->daritempoh;
$hinggatempoh = $request->hinggatempoh;
$namapengguna = $request->namapengguna;
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
$cawangan_detail = CawanganDetail::on($cawangan['mysql'])->first();
$caw_name = $cawangan->details_caw;
$nofoncaw = $cawangan_detail->notel;
$audit = Gadai::on($cawangan['mysql'])
->where([['tagpalsu','=',0],['tempoh','>=',$daritempoh],['tempoh','<=',$hinggatempoh],['sttebus','=',''],['taglel','=',0]])
->orderBy('t_gadai', 'ASC')
->orderBy('sirig', 'ASC');
$rekodaudit = $audit->get();
$arraynorujukan = $audit->pluck('norujukan')->toArray();
$keybynorujukan = $rekodaudit->keyBy('norujukan');
$gadainokp = Gadai::on($cawangan['mysql'])->whereIn('norujukan', $arraynorujukan)
// ->select('nokp')
// ->groupBy('nokp')
->get();
// dd($gadainokp);
$gadai_all_groupby_nokp = $rekodaudit->groupBy('nokp');
foreach($gadainokp as $index1=>$cal){
// dd($cal->nokp);
if($gadai_all_groupby_nokp[$cal->nokp]){
$gadainokp[$index1]['gadai'] = $gadai_all_groupby_nokp[$cal->nokp];
}
// dd($gadainokp[$index1]['gadai'][$index1]['norujukan']);
$customer = Customer::on('mysql7')->where('kpbaru','=',$cal['nokp'])
->orWhere('kplama','=',$cal['nokp'])
->first();
$nokp=$cal['nokp'];
// foreach($gadainokp[$index1]['gadai'] as $index1=>$cal3){
$checkingnokp = BlastWasap::on('mysql7')
->where('nokp','=',$cal['nokp'])
->where('norujukan','=',$cal->norujukan)
->where('kodcaw','=',$kodcaw)
->first();
if(!$checkingnokp){
if($customer->telefon != 'null'){
$telefon=$customer->telefon;
//log auditrail
$audit = new Audit();
$audit->users = $namapengguna;
$audit->actions = 'Blast Whatsapp & SMS';
$audit->norujukan = $cal->norujukan;
$audit->new_data = $customer->telefon;
$audit->old_data = $nokp;
$audit->kodcaw = $kodcaw;
$audit->created_at = $current;
$audit->updated_at = $current;
$audit->save();
dispatch(new WhatsappPelangganSAGLAMAbysag($nokp,$customer->telefon,$caw_name,$nofoncaw,$kodcaw,$cal->norujukan,$cal->tempoh,$cal->t_matang,$cal->t_matang1,$cal->lelong_tawarruq));
dispatch(new SMSPelangganSAGLAMAbysag($nokp,$customer->telefon,$caw_name,$nofoncaw,$kodcaw,$cal->norujukan,$cal->tempoh,$cal->t_matang,$cal->t_matang1,$cal->lelong_tawarruq));
}
}
else{
return response()->json('failed');
}
// }
}
return response()->json('success');
}
public function rekodblast($kodcaw,Request $request)
{
+97
View File
@@ -0,0 +1,97 @@
<?php
namespace App\Jobs;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Http;
use App\BlastSMS;
use Carbon\Carbon;
class SMSPelangganSAGLAMAbysag extends Job
{
public $nokp;
public $telefon;
public $caw_name;
public $nofoncaw;
public $kodcaw;
public $norujukan;
public $tempoh;
public $tmatang;
public $tmatang1;
public $lelong_tawarruq;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($nokp, $telefon, $caw_name,$nofoncaw,$kodcaw,$norujukan,$tempoh,$tmatang,$tmatang1,$lelong_tawarruq)
{
$this->nokp = $nokp;
$this->telefon = $telefon;
$this->caw_name = $caw_name;
$this->nofoncaw = $nofoncaw;
$this->kodcaw = $kodcaw;
$this->norujukan = $norujukan;
$this->tempoh = $tempoh;
$this->tmatang = $tmatang;
$this->tmatang1 = $tmatang1;
$this->lelong_tawarruq = $lelong_tawarruq;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$current = Carbon::now();
$current = new Carbon();
$mobile_no = ltrim($this->telefon, '+6');
// $mobile_no = '60178916936';
// $message = 'test';
$tarikhmatang = date('d-m-Y',strtotime($this->tmatang));
$tarikhmatang = date('d-m-Y',strtotime($this->tmatang));
$tarikhmatang1 = date('d-m-Y',strtotime($this->tmatang1));
$date = $current->toDateString();
$today = date('d-m-Y',strtotime($date));
// $current_date = new Carbon($current->toDateString());
if($this->lelong_tawarruq == '1'){
if($tarikhmatang > $today){
$message = 'AR-RAHN '.$this->caw_name.': MAKLUMAN, '.$this->norujukan.' telah hampir tamat tempoh untuk tukar ke SAG baru, Sila perbaharui SAG anda di cawangan sebelum '.$tarikhmatang.'.';
}elseif($tarikhmatang < $today){
$message = 'AR-RAHN '.$this->caw_name.': MAKLUMAN, '.$this->norujukan.' telah tamat tempoh pada '.$tarikhmatang.', Sila perbaharui SAG anda di cawangan Ar-Rahn.';}
}else
if($tarikhmatang1 < $today){
$message = 'AR-RAHN '.$this->caw_name.': MAKLUMAN, '.$this->norujukan.' telah hampir tamat tempoh untuk tukar ke SAG baru, Sila perbaharui SAG anda di cawangan sebelum '.$tarikhmatang1.'.';
}elseif($tarikhmatang1 > $today){
$message = 'AR-RAHN '.$this->caw_name.': MAKLUMAN, '.$this->norujukan.' telah tamat tempoh pada '.$tarikhmatang1.', Sila perbaharui SAG anda di cawangan Ar-Rahn.';}
if(env('APP_ENV') != 'production'){
$mobile_no = env('ADMIN_PHONE_NUMBER');
}
$response = Http::get(env('ONEWAYSMS_API'), [
'apiusername' => env('ONEWAYSMS_AUTH_USER'),
'apipassword' => env('ONEWAYSMS_AUTH_PASS'),
'senderid' => 'INFO',
'mobileno' => $mobile_no,
'message' => $message,
'languagetype' => 1
]);
//insert log blast sms
$logblastsms = new BlastSMS();
$logblastsms->kodcaw = $this->kodcaw;
$logblastsms->nokp = $this->nokp;
$logblastsms->notelefon = $this->telefon;
$logblastsms->norujukan = $this->norujukan;
$logblastsms->tempoh = $this->tempoh;
$logblastsms->status = $response;
$logblastsms->created_at = $current;
$logblastsms->updated_at = $current;
$logblastsms->save();
Log::info("SMS - Pelanggan ".$this->caw_name." SAG Tawarruq Lama -".$mobile_no);
}
}
@@ -0,0 +1,96 @@
<?php
namespace App\Jobs;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Http;
use App\BlastWasap;
use Carbon\Carbon;
class WhatsappPelangganSAGLAMAbysag extends Job
{
public $nokp;
public $telefon;
public $caw_name;
public $nofoncaw;
public $kodcaw;
public $norujukan;
public $tempoh;
public $tmatang;
public $tmatang1;
public $lelong_tawarruq;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($nokp, $telefon, $caw_name,$nofoncaw,$kodcaw,$norujukan,$tempoh,$tmatang,$tmatang1,$lelong_tawarruq)
{
$this->nokp = $nokp;
$this->telefon = $telefon;
$this->caw_name = $caw_name;
$this->nofoncaw = $nofoncaw;
$this->kodcaw = $kodcaw;
$this->norujukan = $norujukan;
$this->tempoh = $tempoh;
$this->tmatang = $tmatang;
$this->tmatang1 = $tmatang1;
$this->lelong_tawarruq = $lelong_tawarruq;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$current = Carbon::now();
$current = new Carbon();
$mobile_no = ltrim($this->telefon, '+6');
// $mobile_no = '60178916936';
$tarikhmatang = date('d-m-Y',strtotime($this->tmatang));
$tarikhmatang1 = date('d-m-Y',strtotime($this->tmatang1));
$date = $current->toDateString();
$today = date('d-m-Y',strtotime($date));
// $current_date = new Carbon($current->toDateString());
if($this->lelong_tawarruq == '1'){
if($tarikhmatang > $today){
$message = 'AR-RAHN '.$this->caw_name.': MAKLUMAN, *'.$this->norujukan.'* telah hampir tamat tempoh untuk tukar ke SAG baru, Sila perbaharui SAG anda di cawangan sebelum *'.$tarikhmatang.'*.';
}elseif($tarikhmatang < $today){
$message = 'AR-RAHN '.$this->caw_name.': MAKLUMAN, *'.$this->norujukan.'* telah tamat tempoh pada *'.$tarikhmatang.'*, Sila perbaharui SAG anda di cawangan Ar-Rahn.';}
}else
if($tarikhmatang1 < $today){
$message = 'AR-RAHN '.$this->caw_name.': MAKLUMAN, *'.$this->norujukan.'* telah hampir tamat tempoh untuk tukar ke SAG baru, Sila perbaharui SAG anda di cawangan sebelum *'.$tarikhmatang1.'*.';
}elseif($tarikhmatang1 > $today){
$message = 'AR-RAHN '.$this->caw_name.': MAKLUMAN, *'.$this->norujukan.'* telah tamat tempoh pada *'.$tarikhmatang1.'*, Sila perbaharui SAG anda di cawangan Ar-Rahn.';}
if(env('APP_ENV') != 'production'){
$mobile_no = env('ADMIN_PHONE_NUMBER');
}
$response = Http::get(env('WABOT_API'), [
'number' => $mobile_no,
'type' => 'text',
'message' => $message,
'instance_id' => env('WABOT_INSTANCES_ID'),
'access_token' => env('WABOT_TOKEN_KEYS')
]);
//insert log blast wasap
$logblastwasap = new BlastWasap();
$logblastwasap->kodcaw = $this->kodcaw;
$logblastwasap->nokp = $this->nokp;
$logblastwasap->notelefon = $this->telefon;
$logblastwasap->norujukan = $this->norujukan;
$logblastwasap->tempoh = $this->tempoh;
$logblastwasap->status = $response;
$logblastwasap->created_at = $current;
$logblastwasap->updated_at = $current;
$logblastwasap->save();
Log::info("WABOT - Pelanggan SAG Tawarruq Lama".$response);
}
}
+1
View File
@@ -595,6 +595,7 @@ $router->group(['prefix'=>'api'], function () use ($router){
//API BLAST WASAP
$router->post('blastwasap/{kodcaw}',['uses'=>'StokAuditController@blastwasap']);
$router->post('blastwasapbysag/{kodcaw}',['uses'=>'StokAuditController@blastwasapbysag']);
$router->get('rekodblast/{kodcaw}',['uses'=>'StokAuditController@rekodblast']);
$router->get('rekodblastsms/{kodcaw}',['uses'=>'StokAuditController@rekodblastsms']);