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.

41 lines
1007 B

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->lt($startDate)) {
return 1;
}
if (! $periodEnd || $today->lte(Carbon::parse($periodEnd)->startOfDay())) {
return 2;
}
}
return 1;
}
}