|
|
|
|
@ -233,28 +233,26 @@ class OtherController extends CommonController
|
|
|
|
|
$calendar = Calendar::where(function ($query) use ($start_date, $end_date) {
|
|
|
|
|
$query->whereBetween('start_time', [$start_date, $end_date])
|
|
|
|
|
->orWhereBetween('end_time', [$start_date, $end_date]);
|
|
|
|
|
})->where(function ($query) use ($course_type_id, $courses) {
|
|
|
|
|
// course_type_id 和 course id 是或关系,满足其中一个就行
|
|
|
|
|
$hasCondition = false;
|
|
|
|
|
})->where(function ($query) use ($course_type_id) {
|
|
|
|
|
// 条件1:有 course_id 的数据,通过 course.type 匹配课程体系
|
|
|
|
|
// 条件2:没有 course_id 的数据,直接用 course_type_id 字段匹配
|
|
|
|
|
// 两个条件是或关系
|
|
|
|
|
|
|
|
|
|
// 条件1:course_type_id 筛选
|
|
|
|
|
if ($course_type_id) {
|
|
|
|
|
$course_type_id_array = $course_type_id;
|
|
|
|
|
$query->whereIn('course_type_id', $course_type_id_array);
|
|
|
|
|
$hasCondition = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 条件2:course id 筛选(或关系)
|
|
|
|
|
if ($courses && $courses->count() > 0) {
|
|
|
|
|
// if ($hasCondition) {
|
|
|
|
|
// $query->orWhereHas('course', function ($q) use ($courses) {
|
|
|
|
|
// $q->whereIn('id', $courses->pluck('id'));
|
|
|
|
|
// });
|
|
|
|
|
// } else {
|
|
|
|
|
// $query->whereHas('course', function ($q) use ($courses) {
|
|
|
|
|
// $q->whereIn('id', $courses->pluck('id'));
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
$course_type_id_array = is_array($course_type_id) ? $course_type_id : explode(',', $course_type_id);
|
|
|
|
|
|
|
|
|
|
// 条件1:有 course_id 时,通过关联的 course.type 匹配
|
|
|
|
|
$query->where(function ($q) use ($course_type_id_array) {
|
|
|
|
|
$q->whereNotNull('course_id')
|
|
|
|
|
->whereHas('course', function ($subQ) use ($course_type_id_array) {
|
|
|
|
|
$subQ->whereIn('type', $course_type_id_array);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 条件2:没有 course_id 时,直接用 course_type_id 字段匹配(或关系)
|
|
|
|
|
$query->orWhere(function ($q) use ($course_type_id_array) {
|
|
|
|
|
$q->whereNull('course_id')->whereIn('course_type_id', $course_type_id_array);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
})->get();
|
|
|
|
|
|
|
|
|
|
|