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.

52 lines
1.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace App\Support;
use Carbon\Carbon;
/**
* 课程/活动进度1 未开始 / 2 进行中 / 3 已结束
* 进行中:处于开课/活动日期内,或处于报名起止日期内(开课前报名阶段也算进行中)
*/
class ScheduleProgressStatus
{
public static function resolve(
?string $periodStart,
?string $periodEnd,
?string $signupStart = null,
?string $signupEnd = null,
): int {
$today = now()->startOfDay();
if ($periodEnd) {
$endDate = Carbon::parse($periodEnd)->startOfDay();
if ($today->gt($endDate)) {
return 3;
}
}
if ($periodStart) {
$startDate = Carbon::parse($periodStart)->startOfDay();
if ($today->gte($startDate)) {
if (! $periodEnd || $today->lte(Carbon::parse($periodEnd)->startOfDay())) {
return 2;
}
}
}
if ($signupStart && $signupEnd) {
$signupFrom = Carbon::parse($signupStart)->startOfDay();
$signupTo = Carbon::parse($signupEnd)->startOfDay();
if ($today->gte($signupFrom) && $today->lte($signupTo)) {
return 2;
}
}
if ($periodStart && $today->lt(Carbon::parse($periodStart)->startOfDay())) {
return 1;
}
return 2;
}
}