master
cody 3 months ago
parent 474336e3e1
commit 713d3a6775

@ -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']
];
}

@ -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) {
// 返回列表

Loading…
Cancel
Save