You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.7 KiB
64 lines
1.7 KiB
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\CourseAppointmentTotal;
|
|
use App\Models\CourseType;
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
class UpdateAppointmentTotal extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'update_appointment_total';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = '可预约次数更新';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$dateTime = date('Y-m-d H:i:s');
|
|
$courseAppointmentTotals = CourseAppointmentTotal::where('course_id', '!=', 0)
|
|
->whereNotNull('course_id')->where('end_time', '<=', $dateTime)->get();
|
|
foreach ($courseAppointmentTotals as $courseAppointmentTotal) {
|
|
// 次数复原
|
|
$courseType = CourseType::whereHas('courses', function ($query) use ($courseAppointmentTotal) {
|
|
$query->where('id', $courseAppointmentTotal->course_id);
|
|
})->first();
|
|
if (empty($courseType)) continue;
|
|
// 获取一年后的日期
|
|
$oneYearLaterTimestamp = strtotime($courseAppointmentTotal->end_time) + (365 * 24 * 60 * 60);
|
|
// 延期
|
|
$courseAppointmentTotal->end_time = date('Y-m-d H:i:s', $oneYearLaterTimestamp);
|
|
// 重置总次数
|
|
$courseAppointmentTotal->total = $courseType->year_total;
|
|
$courseAppointmentTotal->save();
|
|
}
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
}
|