check first before check in trolley and added cron for deletecarts hourly and added updateunsuccess split 2 parts and logging change to daily
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\PersonalCarts;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class DeleteCartsHourly extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'carts:hourlydelete';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Soft Delete all carts hourly';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try{
|
||||
$oneHourAgo = Carbon::now()->subHour();
|
||||
$deleted = PersonalCarts::where('created_at', '<', $oneHourAgo)->delete();
|
||||
Log::info('carts hourly have been deleted.');
|
||||
$this->info('carts have been deleted.');
|
||||
}catch(\Exception $e){
|
||||
Log::error('Error deleting hourly carts: ' . $e->getMessage());
|
||||
$this->error('Error deleting hourly carts: ' . $e->getMessage());
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,7 @@ class UpdateUnsuccess extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'update:unsuccess';
|
||||
|
||||
protected $signature = 'update:unsuccess {--type=1}';
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
@@ -33,14 +32,17 @@ class UpdateUnsuccess extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$type = $this->option('type');
|
||||
|
||||
if($type == '1'){
|
||||
$getFailedOnlineTransaction = fn() => Http::arrahn()->get('/api/transaction/online/unsuccessful')->json();
|
||||
$getFailedOnlineTransaction_Koop = fn() => Http::arrahn_koop()->get('/api/transaction/online/unsuccessful')->json();
|
||||
|
||||
$FailedBillplzID = array_map(fn($x) => $x['billplz_id'], $getFailedOnlineTransaction());
|
||||
$FailedBillplzID_Koop = array_map(fn($x) => $x['billplz_id'], $getFailedOnlineTransaction_Koop());
|
||||
|
||||
$this->resolve_payment($FailedBillplzID,CompanyStatus::COM_PKB);
|
||||
}else{
|
||||
$getFailedOnlineTransaction_Koop = fn() => Http::arrahn_koop()->get('/api/transaction/online/unsuccessful')->json();
|
||||
$FailedBillplzID_Koop = array_map(fn($x) => $x['billplz_id'], $getFailedOnlineTransaction_Koop());
|
||||
$this->resolve_payment($FailedBillplzID_Koop,CompanyStatus::COM_KOOPPKB);
|
||||
}
|
||||
|
||||
}
|
||||
public function resolve_payment($FailedBillplzID,$company)
|
||||
@@ -51,7 +53,13 @@ class UpdateUnsuccess extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
$billplzUpdatedTransactionStatus = array_map(fn($x) => $billplzService->getTransactionByBillId($x,$company), $FailedBillplzID);
|
||||
if($company == CompanyStatus::COM_PKB){
|
||||
$companyID = 'PKB';
|
||||
}else{
|
||||
$companyID = 'KOPKB';
|
||||
}
|
||||
|
||||
$billplzUpdatedTransactionStatus = array_map(fn($x) => $billplzService->getTransactionByBillId($x,$companyID), $FailedBillplzID);
|
||||
|
||||
$getCompletedBillplzTransaction = function() use($billplzUpdatedTransactionStatus){
|
||||
|
||||
|
||||
@@ -33,6 +33,16 @@ class BayaranController extends Controller
|
||||
$list_pkb = json_decode($exist_carts['list_pkb'],true);
|
||||
$list_koop = json_decode($exist_carts['list_koop'],true);
|
||||
|
||||
if($this->checkSAG($list_pkb, 'PKB')){
|
||||
$this->removeCartsInternal();
|
||||
return redirect()->route('buffer');
|
||||
}
|
||||
|
||||
if($this->checkSAG($list_koop, 'KOPKB')){
|
||||
$this->removeCartsInternal();
|
||||
return redirect()->route('buffer');
|
||||
}
|
||||
|
||||
if($exist_carts['status_pkb'] == 'PENDING') $list_pkb = ($list_pkb) ? $this->setUpahTawarruq($list_pkb) : []; else $list_pkb = [];
|
||||
if($exist_carts['status_koop'] == 'PENDING') $list_koop = ($list_koop) ? $this->setUpahTawarruq($list_koop) : []; else $list_koop = [];
|
||||
|
||||
@@ -551,4 +561,49 @@ class BayaranController extends Controller
|
||||
: Http::arrahn_koop();
|
||||
|
||||
}
|
||||
|
||||
private function checkSAG($list_sag, $company)
|
||||
{
|
||||
$CallableHttp = $company == 'PKB'
|
||||
? Http::arrahn()
|
||||
: Http::arrahn_koop();
|
||||
|
||||
foreach ($list_sag as $x) {
|
||||
$array_lelong = Http::withOptions(['verify' => config('app.api_verify')])
|
||||
->get(config('api-lelong.url') . '/api/portalApi', ['norujukan' => $x['norujukan']])
|
||||
->json();
|
||||
|
||||
$array_gadai = $CallableHttp->get('/api/gadai/norujukan/' . $x['norujukan'])->json();
|
||||
$isdisabled = $CallableHttp->get('/portal/searchsagonline/', ['norujukan' => $x['norujukan']])->json();
|
||||
|
||||
if ($array_lelong['lelong'] != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($isdisabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sizeof($array_gadai) != 0) {
|
||||
$array_gadai = $array_gadai[0][0];
|
||||
if ($array_gadai['sttebus'] == 'T' || $array_gadai['sttebus'] == 'L') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function removeCartsInternal(){
|
||||
$exist_carts = PersonalCarts::where('ic_no', Auth::user()->icno)
|
||||
->where('user_id', Auth::user()->id)
|
||||
->first();
|
||||
|
||||
if ($exist_carts) {
|
||||
$exist_carts->delete();
|
||||
}
|
||||
|
||||
return $exist_carts;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ return [
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('LOG_CHANNEL', 'stack'),
|
||||
'default' => env('LOG_CHANNEL', 'daily'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user