From 713d3a67759625f416f5c9e39f6fa6fac01a4d18 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Sat, 17 Jan 2026 15:26:48 +0800 Subject: [PATCH] update --- .../Controllers/Admin/OtherController.php | 14 ++--- app/Models/CourseSign.php | 60 +++++++++++-------- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/app/Http/Controllers/Admin/OtherController.php b/app/Http/Controllers/Admin/OtherController.php index 663a4b7..83db11f 100755 --- a/app/Http/Controllers/Admin/OtherController.php +++ b/app/Http/Controllers/Admin/OtherController.php @@ -165,17 +165,13 @@ class OtherController extends CommonController ->where('start_time', 'like', '%' . date('Y-m') . '%') ->get(); - // 苏州区域数据 - $suzhouArea = Company::approvedStudents()->where('company_city', '苏州市')->groupBy('company_area') - ->whereNotNull('company_area') - ->get(['company_area']); + // 苏州区域数据 - 使用 CourseSign::area 方法实现数据一致 + $areasData = CourseSign::area($start_date, $end_date, null, null, true, true); $suzhou = []; - foreach ($suzhouArea as $item) { + foreach ($areasData as $item) { $suzhou[] = [ - 'area' => $item->company_area, - 'total' => User::whereHas('company', function ($query) use ($item) { - $query->where('company_area', $item->company_area); - })->where('is_schoolmate', 1)->count() + 'area' => $item['area'], + 'total' => $item['total_unique'] ?? $item['total'] ]; } diff --git a/app/Models/CourseSign.php b/app/Models/CourseSign.php index 651f776..1c4d225 100755 --- a/app/Models/CourseSign.php +++ b/app/Models/CourseSign.php @@ -545,20 +545,42 @@ class CourseSign extends SoftDeletesModel }); } - // 地区 - $suzhouArea = Company::approvedStudents() - ->where('company_city', '苏州市') - ->whereNotNull('company_area') - ->where('company_area', '!=', '') - ->pluck('company_area') - ->unique(); + // 地区 - 从数据字典获取 + $suzhouAreas = ParameterDetail::where('parameter_id', 5) + ->where('status', 1) + ->orderBy('sort', 'asc') + ->pluck('value') + ->toArray(); + $list = []; - foreach ($suzhouArea as $area) { - $sourseSignList2 = (clone $courseSignList)->whereHas('user', function ($query) use ($area) { - $query->whereHas('company', function ($query) use ($area) { - $query->where('company_area', $area); - }); - })->get(); + foreach ($suzhouAreas as $area) { + // 特殊处理:高新区需要统计高新区+虎丘区 + if ($area === '高新区') { + $sourseSignList2 = (clone $courseSignList)->whereHas('user', function ($query) { + $query->whereHas('company', function ($query) { + $query->where('company_city', '苏州市') + ->where(function ($q) { + $q->where('company_area', '高新区') + ->orWhere('company_area', '虎丘区'); + }); + }); + })->get(); + } elseif ($area === '苏州市外') { + // 苏州市外:统计除了苏州之外的所有数据 + $sourseSignList2 = (clone $courseSignList)->whereHas('user', function ($query) { + $query->whereHas('company', function ($query) { + $query->where('company_city', '!=', '苏州市'); + }); + })->get(); + } else { + // 其他区域:正常统计 + $sourseSignList2 = (clone $courseSignList)->whereHas('user', function ($query) use ($area) { + $query->whereHas('company', function ($query) use ($area) { + $query->where('company_city', '苏州市') + ->where('company_area', $area); + }); + })->get(); + } $list[] = [ 'area' => $area, @@ -567,19 +589,7 @@ class CourseSign extends SoftDeletesModel // 已去重 'total_unique' => User::whereIn('id', $sourseSignList2->pluck('user_id'))->groupBy('mobile')->get()->count(), ]; - } - $courseSignList3 = (clone $courseSignList)->whereHas('user', function ($query) { - $query->whereHas('company', function ($query) { - $query->where('company_city', '!=', '苏州市'); - }); - })->get(); - $list[] = [ - 'area' => '苏州市外', - 'total' => $courseSignList3->count(), - // 已去重 - 'total_unique' => User::groupBy('mobile')->whereIn('id', $courseSignList3->pluck('user_id'))->get()->count(), - ]; if ($retList) { // 返回列表