feat: Update console commands for scheduled tasks
- Removed the 'inspire' command and its dependencies. - Added a new daily scheduled command for updating cooperation status.
This commit is contained in:
parent
2b49688f8f
commit
0b15d95395
69
app/Console/Commands/UpdateCooperationStatusCommand.php
Normal file
69
app/Console/Commands/UpdateCooperationStatusCommand.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Enums\CooperationStatus;
|
||||
use App\Models\Cooperation;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UpdateCooperationStatusCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'cooperation:update-status';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Manually trigger the update of cooperation statuses based on deadlines';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Updating cooperation statuses...');
|
||||
|
||||
$today = Carbon::today();
|
||||
|
||||
Log::info('Running UpdateCooperationStatusJob at ' . now());
|
||||
|
||||
// 1. PENDING -> ASSIGNMENT (final_submission_date)
|
||||
$updatedPending = Cooperation::where('status', CooperationStatus::PENDING)
|
||||
->whereDate('final_submission_date', '<=', $today)
|
||||
->update(['status' => CooperationStatus::ASSIGNMENT]);
|
||||
|
||||
if ($updatedPending > 0) {
|
||||
Log::info("Updated {$updatedPending} cooperations from PENDING to ASSIGNMENT.");
|
||||
}
|
||||
|
||||
// 2. ASSIGNMENT -> VERIFICATION (assignment_deadline)
|
||||
$updatedAssignment = Cooperation::where('status', CooperationStatus::ASSIGNMENT)
|
||||
->whereDate('assignment_deadline', '<=', $today)
|
||||
->update(['status' => CooperationStatus::VERIFICATION]);
|
||||
|
||||
if ($updatedAssignment > 0) {
|
||||
Log::info("Updated {$updatedAssignment} cooperations from ASSIGNMENT to VERIFICATION.");
|
||||
}
|
||||
|
||||
// 3. VERIFICATION -> PAYMENT (verification_deadline)
|
||||
$updatedVerification = Cooperation::where('status', CooperationStatus::VERIFICATION)
|
||||
->whereDate('verification_deadline', '<=', $today)
|
||||
->update(['status' => CooperationStatus::PAYMENT]);
|
||||
|
||||
if ($updatedVerification > 0) {
|
||||
Log::info("Updated {$updatedVerification} cooperations from VERIFICATION to PAYMENT.");
|
||||
}
|
||||
|
||||
$this->info('Cooperation statuses updated successfully.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,5 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Foundation\Inspiring;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Schedule;
|
||||
|
||||
Artisan::command('inspire', function () {
|
||||
$this->comment(Inspiring::quote());
|
||||
})->purpose('Display an inspiring quote');
|
||||
Schedule::command('cooperation:update-status')->daily();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user