|
|
|
@ -50,12 +50,30 @@ class CalendarsController extends BaseController
|
|
|
|
public function index()
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$all = \request()->all();
|
|
|
|
$all = \request()->all();
|
|
|
|
|
|
|
|
$isExport = isset($all['is_export']) && $all['is_export'] == 1;
|
|
|
|
|
|
|
|
$validator = Validator::make($all, [
|
|
|
|
|
|
|
|
'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',
|
|
|
|
|
|
|
|
], [
|
|
|
|
|
|
|
|
'start_date.required_with' => '请选择开始日期',
|
|
|
|
|
|
|
|
'end_date.required_with' => '请选择结束日期',
|
|
|
|
|
|
|
|
'start_date.date_format' => '开始日期格式应为YYYY-MM-DD',
|
|
|
|
|
|
|
|
'end_date.date_format' => '结束日期格式应为YYYY-MM-DD',
|
|
|
|
|
|
|
|
'end_date.after_or_equal' => '结束日期不能早于开始日期',
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
|
|
|
|
|
}
|
|
|
|
$list = Calendar::with('course', 'courseContent', 'historyCourses')
|
|
|
|
$list = Calendar::with('course', 'courseContent', 'historyCourses')
|
|
|
|
->where(function ($query) use ($all) {
|
|
|
|
->where(function ($query) use ($all, $isExport) {
|
|
|
|
if (isset($all['month'])) {
|
|
|
|
if ($isExport && !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'] . '%');
|
|
|
|
$query->where('start_time', 'like', $all['month'] . '%');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})->orderBy('date')
|
|
|
|
})->orderBy('start_time', 'asc')
|
|
|
|
|
|
|
|
->orderBy('id')
|
|
|
|
->get();
|
|
|
|
->get();
|
|
|
|
if (isset($all['is_export']) && $all['is_export'] == 1) {
|
|
|
|
if (isset($all['is_export']) && $all['is_export'] == 1) {
|
|
|
|
$list = $list->toArray();
|
|
|
|
$list = $list->toArray();
|
|
|
|
|