From 7dae46cda7b2dc47e4777dc40c0c410b5b0743a8 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Sat, 22 Nov 2025 16:40:55 +0800 Subject: [PATCH] update --- .../Controllers/Admin/CourseController.php | 191 +++++++++--------- 1 file changed, 99 insertions(+), 92 deletions(-) diff --git a/app/Http/Controllers/Admin/CourseController.php b/app/Http/Controllers/Admin/CourseController.php index faa5aae..833c5b7 100755 --- a/app/Http/Controllers/Admin/CourseController.php +++ b/app/Http/Controllers/Admin/CourseController.php @@ -63,102 +63,109 @@ class CourseController extends BaseController $query->whereNotIn('status', [4, 5]); } ])->withCount([ - 'courseSigns as sign_pass_total' => function ($query) { - $query->where('status', 1)->whereHas('user'); - } - ])->withCount([ - 'courseSigns as sign_wait_total' => function ($query) { - $query->where('status', 0)->whereHas('user'); - } - ])->withCount([ - 'courseSigns as sign_fault_total' => function ($query) { - $query->where('status', 2)->whereHas('user'); - } - ])->withCount([ - 'courseSigns as sign_prepare_total' => function ($query) { - $query->where('status', 3)->whereHas('user'); - } - ])->withCount([ - 'courseSigns as sign_cancel_total' => function ($query) { - $query->where('status', 4)->whereHas('user'); - } - ])->withCount([ - 'courseSigns as sign_give_up_total' => function ($query) { - $query->where('status', 5)->whereHas('user'); - } - ])->withCount([ - 'courseSigns as sign_black_total' => function ($query) { - $query->where('status', 6)->whereHas('user'); - } - ])->where(function ($query) use ($all) { - if (isset($all['has_course_forms']) && !empty($all['has_course_forms'])) { - $query->whereHas('courseForms'); - } - if (isset($all['start_date'])) { - $query->where('start_date', '>=', $all['start_date']); - } - if (isset($all['end_date'])) { - $query->where('end_date', '<=', $all['end_date']); - } - if (isset($all['course_type_id'])) { - $course_type_id = explode(',', $all['course_type_id']); - $query->whereIn('type', $course_type_id); - } - if (isset($all['filter']) && !empty($all['filter'])) { - foreach ($all['filter'] as $condition) { - $key = $condition['key'] ?? null; - $op = $condition['op'] ?? null; - $value = $condition['value'] ?? null; - if (!isset($key) || !isset($op) || !isset($value)) { + 'courseSigns as sign_pass_total' => function ($query) { + $query->where('status', 1)->whereHas('user'); + } + ])->withCount([ + 'courseSigns as sign_wait_total' => function ($query) { + $query->where('status', 0)->whereHas('user'); + } + ])->withCount([ + 'courseSigns as sign_fault_total' => function ($query) { + $query->where('status', 2)->whereHas('user'); + } + ])->withCount([ + 'courseSigns as sign_prepare_total' => function ($query) { + $query->where('status', 3)->whereHas('user'); + } + ])->withCount([ + 'courseSigns as sign_cancel_total' => function ($query) { + $query->where('status', 4)->whereHas('user'); + } + ])->withCount([ + 'courseSigns as sign_give_up_total' => function ($query) { + $query->where('status', 5)->whereHas('user'); + } + ])->withCount([ + 'courseSigns as sign_black_total' => function ($query) { + $query->where('status', 6)->whereHas('user'); + } + ])->where(function ($query) use ($all) { + if (isset($all['has_course_forms']) && !empty($all['has_course_forms'])) { + $query->whereHas('courseForms'); + } + if (isset($all['start_date'])) { + $query->where('start_date', '>=', $all['start_date']); + } + if (isset($all['end_date'])) { + $query->where('end_date', '<=', $all['end_date']); + } + if (isset($all['course_type_id'])) { + $course_type_id = explode(',', $all['course_type_id']); + $query->whereIn('type', $course_type_id); + } + if (isset($all['filter']) && !empty($all['filter'])) { + foreach ($all['filter'] as $condition) { + $key = $condition['key'] ?? null; + $op = $condition['op'] ?? null; + $value = $condition['value'] ?? null; + if (!isset($key) || !isset($op) || !isset($value)) { + continue; + } + if ($key == 'start_date') { + list($from, $to) = explode(',', $value); + $query->where(function ($q) use ($from, $to) { + $q->whereBetween('start_date', [$from, $to])->orWhereBetween('end_date', [$from, $to]); + }); + } + + // 等于 + if ($op == 'eq') { + $query->where($key, $value); + } + // 不等于 + if ($op == 'neq') { + $query->where($key, '!=', $value); + } + // 大于 + if ($op == 'gt') { + $query->where($key, '>', $value); + } + // 大于等于 + if ($op == 'egt') { + $query->where($key, '>=', $value); + } + // 小于 + if ($op == 'lt') { + $query->where($key, '<', $value); + } + // 小于等于 + if ($op == 'elt') { + $query->where($key, '<=', $value); + } + // 模糊搜索 + if ($op == 'like') { + $query->where($key, 'like', '%' . $value . '%'); + } + // 否定模糊搜索 + if ($op == 'notlike') { + $query->where($key, 'not like', '%' . $value . '%'); + } + // 范围搜索 + if ($op == 'range') { + list($from, $to) = explode(',', $value); + if (empty($from) || empty($to)) { continue; } - // 等于 - if ($op == 'eq') { - $query->where($key, $value); - } - // 不等于 - if ($op == 'neq') { - $query->where($key, '!=', $value); - } - // 大于 - if ($op == 'gt') { - $query->where($key, '>', $value); - } - // 大于等于 - if ($op == 'egt') { - $query->where($key, '>=', $value); - } - // 小于 - if ($op == 'lt') { - $query->where($key, '<', $value); - } - // 小于等于 - if ($op == 'elt') { - $query->where($key, '<=', $value); - } - // 模糊搜索 - if ($op == 'like') { - $query->where($key, 'like', '%' . $value . '%'); - } - // 否定模糊搜索 - if ($op == 'notlike') { - $query->where($key, 'not like', '%' . $value . '%'); - } - // 范围搜索 - if ($op == 'range') { - list($from, $to) = explode(',', $value); - if (empty($from) || empty($to)) { - continue; - } - $query->whereBetween($key, [$from, $to]); - } - if ($op == 'in') { - $array = explode(',', $value); - $query->whereIn($key, $array); - } + $query->whereBetween($key, [$from, $to]); + } + if ($op == 'in') { + $array = explode(',', $value); + $query->whereIn($key, $array); } } - }); + } + }); $list = $list->orderBy($all['sort_name'] ?? 'sign_status', $all['sort_type'] ?? 'asc'); if (isset($all['is_export']) && !empty($all['is_export'])) { $list = $list->limit(5000)->get()->toArray();