master
cody 2 days ago
parent 327d13192e
commit 16cde022f3

@ -1077,27 +1077,35 @@ class CourseController extends CommonController
if ($validator->fails()) {
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
}
$monthTs = strtotime($all['month'] . '-01');
if ($monthTs === false) {
return $this->fail([ResponseCode::ERROR_PARAMETER, '月份格式错误']);
}
$monthStart = date('Y-m-01 00:00:00', $monthTs);
$monthEnd = date('Y-m-t 23:59:59', $monthTs);
$list = Calendar::with('course', 'courseContent')
->where(function ($query) use ($all) {
if (isset($all['type'])) {
$query->where('type', $all['type']);
}
})->where('start_time', 'like', '%' . $all['month'] . '%')
})->where(function ($query) use ($monthStart, $monthEnd) {
$query->whereBetween('start_time', [$monthStart, $monthEnd])
->orWhereBetween('end_time', [$monthStart, $monthEnd])
->orWhere(function ($sub) use ($monthStart, $monthEnd) {
$sub->where('start_time', '<=', $monthStart)
->where('end_time', '>=', $monthEnd);
});
})
->where('is_publish', 1)
->orderBy('start_time', 'asc')
->get();
$list->each(function ($calendar) {
if (!empty($calendar->course)) {
$calendar->course->start_time = $this->formatDateTimeWithSeconds($calendar->course->start_time ?? null);
$calendar->course->end_time = $this->formatDateTimeWithSeconds($calendar->course->end_time ?? null);
}
if (!empty($calendar->courseContent)) {
$calendar->courseContent->each(function ($content) {
$content->start_time = $this->formatDateTimeWithSeconds($content->start_time ?? null);
$content->end_time = $this->formatDateTimeWithSeconds($content->end_time ?? null);
});
}
$rawStartTime = $calendar->start_time ?? null;
$rawEndTime = $calendar->end_time ?? null;
$calendar->start_time = $this->normalizeCalendarDateTime($rawStartTime, $rawEndTime, true);
$calendar->end_time = $this->normalizeCalendarDateTime($rawStartTime, $rawEndTime, false);
});
return $this->success($list);
@ -1112,7 +1120,24 @@ class CourseController extends CommonController
if ($timestamp === false) {
return $value;
}
return date('Y-m-d 00:00:00', $timestamp);
return date('Y-m-d H:i:s', $timestamp);
}
private function normalizeCalendarDateTime($startValue, $endValue, $isStart = true)
{
$start = $this->formatDateTimeWithSeconds($startValue);
$end = $this->formatDateTimeWithSeconds($endValue);
$target = $isStart ? $start : $end;
if (empty($target)) {
return $target;
}
// 跨天事件统一按“日期维度”返回,避免前端以时分秒切段时漏首日
if (!empty($start) && !empty($end) && date('Y-m-d', strtotime($start)) !== date('Y-m-d', strtotime($end))) {
return date('Y-m-d 00:00:00', strtotime($target));
}
return $target;
}
}

Loading…
Cancel
Save