日历课程

master
lion 12 hours ago
parent 243b92c834
commit 1373aa1d3c

@ -52,6 +52,12 @@ class CalendarsController extends BaseController
$all = \request()->all();
$isExport = isset($all['is_export']) && $all['is_export'] == 1;
$validator = Validator::make($all, [
'paginate' => 'nullable|in:0,1',
'page' => 'nullable|integer|min:1',
'page_size' => 'nullable|integer|min:1|max:100',
'keyword' => 'nullable|string|max:255',
'type' => 'nullable|in:1,2,3,4',
'is_publish' => 'nullable|in:0,1',
'start_date' => 'nullable|required_with:end_date|date_format:Y-m-d',
'end_date' => 'nullable|required_with:start_date|date_format:Y-m-d|after_or_equal:start_date',
], [
@ -64,17 +70,36 @@ class CalendarsController extends BaseController
if ($validator->fails()) {
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
}
$list = Calendar::with('course', 'courseContent', 'historyCourses')
$query = Calendar::with('course', 'courseContent', 'historyCourses')
->where(function ($query) use ($all, $isExport) {
if ($isExport && !empty($all['start_date']) && !empty($all['end_date'])) {
if (!empty($all['start_date']) && !empty($all['end_date'])) {
$query->where('start_time', '>=', $all['start_date'] . ' 00:00:00')
->where('start_time', '<', date('Y-m-d', strtotime($all['end_date'] . ' +1 day')) . ' 00:00:00');
} elseif (!empty($all['month'])) {
$query->where('start_time', 'like', $all['month'] . '%');
}
if (isset($all['keyword']) && trim($all['keyword']) !== '') {
$query->where('title', 'like', '%' . trim($all['keyword']) . '%');
}
foreach (['type', 'is_publish'] as $field) {
if (isset($all[$field]) && $all[$field] !== '') {
$query->where($field, $all[$field]);
}
}
})->orderBy('start_time', 'asc')
->orderBy('id')
->get();
->orderBy('id');
// 按需分页,保持月历及现有调用的完整列表结构不变。
if (!$isExport && !empty($all['paginate'])) {
$pageSize = (int) ($all['page_size'] ?? 20);
$paginator = $query->paginate($pageSize);
return $this->success([
'list' => $paginator->items(),
'total' => $paginator->total(),
'page' => $paginator->currentPage(),
'page_size' => $paginator->perPage(),
]);
}
$list = $query->get();
if (isset($all['is_export']) && $all['is_export'] == 1) {
$list = $list->toArray();
return Excel::download(new CommonExport($list, $all['export_fields'] ?? ''), ($all['file_name'] ?? '') . date('YmdHis') . '.xlsx');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save