You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1105 lines
53 KiB

6 months ago
<?php
namespace App\Http\Controllers\Admin;
use App\Helpers\ResponseCode;
use App\Jobs\CancelAppointMeet;
6 months ago
use App\Models\Admin;
use App\Models\Appointment;
use App\Models\AppointmentConfig;
3 weeks ago
use App\Models\Article;
4 months ago
use App\Models\Calendar;
6 months ago
use App\Models\CarparkLog;
5 months ago
use App\Models\Company;
5 months ago
use App\Models\CourseSign;
use App\Models\CourseType;
6 months ago
use App\Models\CustomFormField;
use App\Models\Department;
2 weeks ago
use App\Models\HistoryCourse;
5 months ago
use App\Models\ParameterDetail;
3 weeks ago
use App\Models\SupplyDemand;
3 weeks ago
use App\Models\TimeEvent;
6 months ago
use App\Models\User;
use App\Repositories\DoorRepository;
use App\Repositories\EntranceRepository;
4 months ago
use Illuminate\Support\Carbon;
5 months ago
use Illuminate\Support\Facades\DB;
6 months ago
use Illuminate\Support\Facades\Validator;
use App\Models\Course;
use EasyWeChat\Factory;
use Illuminate\Filesystem\Filesystem;
3 weeks ago
use Maatwebsite\Excel\Facades\Excel;
use App\Exports\CommonExport;
6 months ago
class OtherController extends CommonController
{
5 months ago
/**
* @OA\Get(
* path="/api/admin/other/home",
* tags={"其他"},
* summary="驾驶舱",
* description="",
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response(
* response="200",
* description="暂无"
* )
* )
*/
public function home()
{
// 校友总数
4 months ago
$schoolmate['schoolmate_total'] = User::where('is_schoolmate', 1)->count();
5 months ago
// 2025年校友数
4 months ago
$schoolmate['schoolmate_year'] = User::where('is_schoolmate', 1)->where('created_at', 'like', '%' . date('Y') . '%')->count();
3 months ago
// 开课场次(全部)
$calendar = Calendar::get();
$company['course_total'] = $calendar->count();
$company['course_day_total'] = $calendar->sum(function ($course) {
$start = Carbon::parse($course->start_time);
$end = Carbon::parse($course->end_time);
return $end->diffInDays($start) + 1; // 包含起始和结束日期
});
// 开课场次(当年)
$calendarYear = Calendar::where('date', 'like', '%' . date('Y') . '%')->get();
$company['course_total_year'] = $calendarYear->count();
$company['course_day_total_year'] = $calendarYear->sum(function ($course) {
$start = Carbon::parse($course->start_time);
$end = Carbon::parse($course->end_time);
return $end->diffInDays($start) + 1; // 包含起始和结束日期
});
5 months ago
// 校友企业总融资额
$company['company_fund'] = Company::where('is_schoolmate', 1)->sum('company_fund');
// 校友企业总估值
$company['valuation'] = Company::where('is_schoolmate', 1)->sum('valuation');
3 months ago
5 months ago
// 校友企业所属领域
$industryTotal = [];
$industries = ParameterDetail::where('parameter_id', 4)->get();
foreach ($industries as $item) {
$level2Names = ParameterDetail::where('parameter_id', 10)->where('remark', $item->value)->pluck('value');
$industryTotal[] = [
'industry' => $item->value,
'total' => User::whereIn('company_industry', $level2Names)->count()
];
}
5 months ago
// 课程统计
5 months ago
$courseTypes = CourseType::where('is_chart', 1)->get();
5 months ago
foreach ($courseTypes as $courseType) {
5 months ago
$courseIds = Course::where('type', $courseType->id)->pluck('id');
$courseType->course_signs_total = CourseSign::whereIn('course_id', $courseIds)
5 months ago
->where('status', 1)
->count();
}
5 months ago
// 苏州区域数据
$suzhou = Company::where('company_city', '苏州市')
// 根据company_area分组查询公司数量
->select('company_area', DB::raw('count(*) as company_total'))
->groupBy('company_area')
->get();
// 全国数据
$country = Company::select('company_city', DB::raw('count(*) as company_total'))
->groupBy('company_city')
->get();
return $this->success(compact('courseTypes', 'schoolmate', 'company', 'industryTotal', 'suzhou', 'country'));
5 months ago
}
3 weeks ago
/**
* @OA\Get(
* path="/api/admin/other/home-v2",
* tags={"其他"},
* summary="驾驶舱V2",
* description="",
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response(
* response="200",
* description="暂无"
* )
* )
*/
public function homeV2()
{
3 weeks ago
// 校友总数
$list['schoolmate_total'] = User::where('is_schoolmate', 1)->count();
// 今年新增校友数
$list['schoolmate_year'] = User::where('is_schoolmate', 1)->where('created_at', 'like', '%' . date('Y') . '%')->count();
// 投后企业
2 weeks ago
$list['company_invested_total'] = CourseSign::yhInvested();
2 weeks ago
// 元和员工参与人数
2 weeks ago
$list['company_join_total'] = CourseSign::companyJoin();
3 weeks ago
// 全市干部参与企业
2 weeks ago
$list['company_ganbu_total'] = CourseSign::ganbu();
3 weeks ago
// 三个全覆盖
// 苏州头部企业
2 weeks ago
$list['cover_head_total'] = CourseSign::toubuqiye();
3 weeks ago
// 高层次人才
// 获取人才培训课程
2 weeks ago
$list['cover_rencai_total'] = CourseSign::rencai();
3 weeks ago
// 重点上市公司
2 weeks ago
$list['cover_stock_total'] = CourseSign::shangshi();
3 weeks ago
// 本月课程
2 weeks ago
$monthCourses = Calendar::with('course.teacher')
3 weeks ago
->where('date', 'like', '%' . date('Y-m') . '%')
->get();
3 weeks ago
// 课程统计
$courseTypes = CourseType::where('is_chart', 1)->get();
3 weeks ago
$start_date = CourseType::START_DATE;
3 weeks ago
$end_date = date('Y-m-d');
foreach ($courseTypes as $courseType) {
// 课程
3 weeks ago
$courses = Course::where('type', $courseType->id)->get();
3 weeks ago
// 已开设期数
$courseType->course_periods_total = Course::where('type', $courseType->id)->count();
// 培养人数去重
3 weeks ago
$courseType->course_signs_total = CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1, $courses->pluck('id'), null);
3 weeks ago
}
// 苏州区域数据
3 weeks ago
$suzhouArea = Company::where('company_city', '苏州市')->groupBy('company_area')
->whereNotNull('company_area')
->get(['company_area']);
3 weeks ago
$suzhou = [];
foreach ($suzhouArea as $item) {
$suzhou[] = [
3 weeks ago
'area' => $item->company_area,
3 weeks ago
'total' => User::whereHas('company', function ($query) use ($item) {
3 weeks ago
$query->where('company_area', $item->company_area);
})->where('is_schoolmate', 1)->count()
];
}
3 weeks ago
// 全国数据
2 weeks ago
$countryArea = Company::groupBy('company_city')->whereNotNull('company_city')->get(['company_city']);
3 weeks ago
$country = [];
foreach ($countryArea as $item) {
2 weeks ago
$total = User::whereHas('company', function ($query) use ($item) {
$query->where('company_city', $item->company_city);
})->where('is_schoolmate', 1)->count();
if (empty($total)) {
continue;
}
3 weeks ago
$country[] = [
3 weeks ago
'area' => $item->company_city,
'total' => User::whereHas('company', function ($query) use ($item) {
3 weeks ago
$query->where('company_city', $item->company_city);
})->where('is_schoolmate', 1)->count()
];
}
3 weeks ago
3 weeks ago
// 时间轴
3 weeks ago
$time_axis = TimeEvent::orderBy('sort', 'asc')->get();
3 weeks ago
// 动态信息
3 weeks ago
$article['xiaoyou'] = Article::where('type', 1)->limit(7)->orderBy('sort', 'desc')->get();
$article['yejie'] = Article::where('type', 2)->limit(7)->orderBy('sort', 'desc')->get();
$article['supply_demands'] = SupplyDemand::limit(7)->orderBy('created_at', 'desc')->get();
return $this->success(compact('list', 'courseTypes', 'suzhou', 'country', 'monthCourses', 'time_axis', 'article'));
3 weeks ago
}
4 months ago
/**
* @OA\Get(
* path="/api/admin/other/courses-home",
* tags={"其他"},
* summary="课程统计",
* description="",
* @OA\Parameter(name="start_date", in="query", @OA\Schema(type="string"), required=true, description="开始日期"),
* @OA\Parameter(name="end_date", in="query", @OA\Schema(type="string"), required=true, description="结束日期"),
4 months ago
* @OA\Parameter(name="course_type_id", in="query", @OA\Schema(type="string"), required=true, description="课程体系id多个英文逗号"),
4 months ago
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response(
* response="200",
* description="暂无"
* )
* )
*/
public function coursesHome()
{
3 weeks ago
// 获取公共参数
$params = $this->getCoursesHomeParams();
$start_date = $params['start_date'];
$end_date = $params['end_date'];
$course_type_id = $params['course_type_id'];
$courses = $params['courses'];
3 weeks ago
// 被投企业数
2 weeks ago
$list['course_signs_invested'] = CourseSign::yhInvested($start_date, $end_date, $courses->pluck('id')->toArray());
3 weeks ago
// 报名人数
3 weeks ago
$list['course_signs_total'] = CourseSign::courseSignsTotal($start_date, $end_date, null, $courses->pluck('id'));
3 weeks ago
// 审核通过人数
3 weeks ago
$list['course_signs_pass'] = CourseSign::courseSignsTotal($start_date, $end_date, 1, $courses->pluck('id'));
3 weeks ago
// 审核通过人数去重
3 weeks ago
$list['course_signs_pass_unique'] = CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1, $courses->pluck('id'), null);
3 weeks ago
// 开课场次
2 weeks ago
$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]);
2 weeks ago
})->where(function ($query) {
2 weeks ago
$course_type_id = request('course_type_id');
if ($course_type_id) {
$course_type_id = explode(',', $course_type_id);
$query->whereIn('course_type_id', $course_type_id);
}
2 weeks ago
});
2 weeks ago
$list['course_total'] = (clone $calendar)->count();
3 weeks ago
// 开课天数
2 weeks ago
$list['course_day_total'] = (clone $calendar)->where('is_count_days', 1)->sum('days');
3 weeks ago
// 上市公司数(所有上市公司)
$list['company_market_total'] = Company::companyMarket($start_date, $end_date);
// 跟班学员数在指定时间范围内报名的学员中from为'跟班学员'的数量)
$course_ids = $courses->pluck('id');
2 weeks ago
$list['ganbu_total'] = CourseSign::genban($start_date, $end_date, $course_ids);
3 weeks ago
// 今年上市公司数量stock_date在今年
$list['company_market_year_total'] = Company::companyMarketYear($start_date, $end_date, $course_ids);
// 入学后上市公司数量(在指定时间范围内报名的学员所在公司中,在入学后上市的公司数量)
$list['company_market_after_enrollment_total'] = CourseSign::companyMarketAfterEnrollment($start_date, $end_date, $course_ids);
2 weeks ago
// 入学后被投企业数量(在指定时间范围内报名的学员所在公司中,在入学后被投的公司数量)
$list['company_invested_after_enrollment_total'] = CourseSign::companyInvestedAfterEnrollment($start_date, $end_date, $course_ids);
2 weeks ago
// 元和员工参与人数
2 weeks ago
$list['company_join_total'] = CourseSign::companyJoin($start_date, $end_date, $course_ids);
2 weeks ago
// 全市干部参与企业
$list['company_ganbu_total'] = CourseSign::ganbu($start_date, $end_date, $course_ids);
2 weeks ago
// 苏州头部企业
$list['cover_head_total'] = CourseSign::toubuqiye($start_date, $end_date, $course_ids);
// 高层次人才
$list['cover_rencai_total'] = CourseSign::rencai($start_date, $end_date, $course_ids);
// 重点上市公司
$list['cover_stock_total'] = CourseSign::shangshi($start_date, $end_date, $course_ids);
3 weeks ago
// 课程分类明细统计
4 months ago
$courseTypesSum = [];
4 months ago
$courseTypes = CourseType::whereIn('id', $course_type_id)->get();
4 months ago
foreach ($courseTypes as $courseType) {
3 weeks ago
// 获取课程
2 weeks ago
$courses2 = Course::where('type', $courseType->id)
2 weeks ago
->where(function ($query) use ($start_date, $end_date) {
2 weeks ago
// 开始结束日期的筛选。or查询
if ($start_date && $end_date) {
$query->whereBetween('start_date', [$start_date, $end_date])
->orWhereBetween('end_date', [$start_date, $end_date]);
}
})->orderBy('start_date', 'asc')->get();
4 months ago
foreach ($courses2 as $course) {
4 months ago
$courseTypesSum[] = [
'course_type' => $courseType->name,
3 weeks ago
// 培养人数
4 weeks ago
'course_type_signs_pass' => CourseSign::courseSignsTotal($start_date, $end_date, 1, $courses2->pluck('id')),
3 weeks ago
// 去重培养人数
3 weeks ago
'course_type_signs_pass_unique' => CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1, $courses2->pluck('id'), null),
4 months ago
'course_name' => $course->name,
4 weeks ago
'course_signs_pass' => CourseSign::courseSignsTotal($start_date, $end_date, 1, [$course->id]),
2 weeks ago
// 跟班学员数量
'genban_total' => CourseSign::genban($start_date, $end_date, [$course->id]),
// 被投企业数
'yh_invested_total' => CourseSign::yhInvested($start_date, $end_date, [$course->id]),
// 元禾同事数
'company_join_total' => CourseSign::companyJoin($start_date, $end_date, [$course->id]),
4 months ago
];
}
}
2 weeks ago
// 附加历史课程数据
2 weeks ago
$historyCourses = HistoryCourse::whereHas('calendar', function ($query) {
2 weeks ago
$query->where('is_count_people', 1);
})->where(function ($query) use ($start_date, $end_date) {
2 weeks ago
// 开始结束日期的筛选。or查询
2 weeks ago
$query->whereBetween('start_time', [$start_date, $end_date])
->orWhereBetween('end_time', [$start_date, $end_date]);
2 weeks ago
})->where(function ($query) {
$course_type_id = request('course_type_id', '');
$course_type_id = explode(',', $course_type_id);
if ($course_type_id) {
$query->whereIn('type', $course_type_id);
}
})->get();
2 weeks ago
foreach ($historyCourses as $historyCourse) {
$courseTypesSum[] = [
2 weeks ago
'course_type' => $historyCourse->typeDetail->name,
2 weeks ago
// 培养人数
'course_type_signs_pass' => $historyCourse->course_type_signs_pass,
// 去重培养人数
'course_type_signs_pass_unique' => $historyCourse->course_type_signs_pass_unique,
'course_name' => $historyCourse->course_name,
'course_signs_pass' => $historyCourse->course_signs_pass,
];
}
3 weeks ago
// 区域明细统计
2 weeks ago
$areas = CourseSign::area($start_date, $end_date, 1, $courses->pluck('id'), true);
3 weeks ago
return $this->success(compact('list', 'courseTypesSum', 'areas'));
4 months ago
}
3 weeks ago
/**
* @OA\Get(
* path="/api/admin/other/courses-home-export",
* tags={"其他"},
* summary="课程统计明细导出",
* description="导出课程统计数据的明细",
2 weeks ago
* @OA\Parameter(name="export_type", in="query", @OA\Schema(type="string"), required=true, description="导出类型course_signs_invested-被投企业明细, course_signs_total-报名人数明细, course_signs_pass-审核通过人数明细, course_signs_pass_unique-审核通过人数去重明细, courseTypesSum-课程分类明细, areas-区域明细, company_market_total-上市公司明细, ganbu_total-跟班学员明细, company_market_year_total-今年上市公司明细, company_market_after_enrollment_total-入学后上市公司明细, company_invested_after_enrollment_total-入学后被投企业明细, course_total-开课场次明细, course_day_total-开课天数明细, company_join_total-元和员工参与企业明细, company_ganbu_total-全市干部参与企业明细, cover_head_total-苏州头部企业明细, cover_rencai_total-高层次人才明细, cover_stock_total-重点上市公司明细"),
3 weeks ago
* @OA\Parameter(name="start_date", in="query", @OA\Schema(type="string"), required=false, description="开始日期"),
* @OA\Parameter(name="end_date", in="query", @OA\Schema(type="string"), required=false, description="结束日期"),
* @OA\Parameter(name="course_type_id", in="query", @OA\Schema(type="string"), required=false, description="课程体系id多个英文逗号"),
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response(
* response="200",
* description="导出Excel文件"
* )
* )
*/
public function coursesHomeExport()
{
$export_type = request('export_type');
if (!$export_type) {
return $this->fail([ResponseCode::ERROR_PARAMETER, '导出类型不能为空']);
}
// 获取参数与coursesHome保持一致
$params = $this->getCoursesHomeParams();
$start_date = $params['start_date'];
$end_date = $params['end_date'];
$course_type_id = $params['course_type_id'];
$courses = $params['courses'];
$course_ids = $courses->pluck('id');
$data = [];
$fields = [];
$filename = '';
switch ($export_type) {
3 weeks ago
case 'course_signs_invested':
3 weeks ago
// 被投企业明细 - 使用与coursesHome相同的算法
2 weeks ago
$companies = CourseSign::yhInvested($start_date, $end_date, $course_ids, true);
3 weeks ago
foreach ($companies as $company) {
$data[] = [
'company_name' => $company->company_name,
3 weeks ago
'company_legal_representative' => $company->company_legal_representative ?? '',
'company_date' => $company->company_date ?? '',
'company_address' => $company->company_address ?? '',
'business_scope' => $company->business_scope ?? '',
'contact_phone' => $company->contact_phone ?? '',
2 weeks ago
'contact_mail' => $company->contact_mail ?? '',
'company_tag' => $company->company_tag ?? '',
2 weeks ago
'credit_code' => ' ' . $company->credit_code ?? '',
3 weeks ago
];
}
$fields = [
'company_name' => '企业名称',
3 weeks ago
'company_legal_representative' => '法人',
'company_date' => '成立时间',
'company_address' => '地址',
'business_scope' => '营业范围',
'contact_phone' => '联系电话',
2 weeks ago
'contact_mail' => '联系邮箱',
'company_tag' => '企业资质',
'credit_code' => '统一社会信用代码',
3 weeks ago
];
$filename = '被投企业明细';
break;
case 'course_signs_total':
// 报名人数明细 - 使用courseSignsTotal方法获取列表与coursesHome算法一致
2 weeks ago
$courseSigns = CourseSign::courseSignsTotal($start_date, $end_date, null, $course_ids, true);
3 weeks ago
// 加载关联关系
$courseSigns->load(['user', 'course']);
foreach ($courseSigns as $sign) {
$data[] = [
'user_name' => $sign->user->name ?? '',
'mobile' => $sign->user->mobile ?? '',
'company_name' => $sign->user->company_name ?? '',
'company_area' => $sign->user->company_area ?? '',
'course_name' => $sign->course->name ?? '',
'status_text' => $sign->status_text ?? '',
'created_at' => $sign->created_at ? $sign->created_at->format('Y-m-d H:i:s') : '',
];
}
$fields = [
'user_name' => '学员姓名',
'mobile' => '手机号',
'company_name' => '企业名称',
'company_area' => '所在区域',
'course_name' => '课程名称',
'status_text' => '审核状态',
'created_at' => '报名时间',
];
$filename = '报名人数明细';
break;
case 'course_signs_pass':
// 审核通过人数明细 - 使用courseSignsTotal方法获取列表与coursesHome算法一致
2 weeks ago
$courseSigns = CourseSign::courseSignsTotal($start_date, $end_date, 1, $course_ids, true);
2 weeks ago
// 加载关联关系
$courseSigns->load(['user', 'course']);
3 weeks ago
foreach ($courseSigns as $sign) {
$data[] = [
'user_name' => $sign->user->name ?? '',
'mobile' => $sign->user->mobile ?? '',
'company_name' => $sign->user->company_name ?? '',
'company_area' => $sign->user->company_area ?? '',
'course_name' => $sign->course->name ?? '',
2 weeks ago
'course_type' => $sign->course->typeDetail->name ?? '',
2 weeks ago
// 'created_at' => $sign->created_at ? $sign->created_at->format('Y-m-d H:i:s') : '',
3 weeks ago
];
}
$fields = [
'user_name' => '学员姓名',
'mobile' => '手机号',
'company_name' => '企业名称',
'company_area' => '所在区域',
'course_name' => '课程名称',
2 weeks ago
'course_type' => '课程类型',
2 weeks ago
// 'created_at' => '报名时间',
3 weeks ago
];
$filename = '审核通过人数明细';
break;
case 'course_signs_pass_unique':
// 审核通过人数去重明细 - 使用courseSignsTotalByUnique方法获取列表
2 weeks ago
$users = CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1, $course_ids, true);
3 weeks ago
foreach ($users as $user) {
// 获取该学员报名的课程列表与coursesHome逻辑保持一致
$userCourseSigns = CourseSign::where('user_id', $user->id)
2 weeks ago
->whereHas('course', function ($query) use ($start_date, $end_date) {
// 开始结束日期的筛选。or查询
$query->whereBetween('start_date', [$start_date, $end_date])
->whereBetween('end_date', [$start_date, $end_date]);
})->where('status', 1)
3 weeks ago
->where(function ($query) use ($course_ids) {
if ($course_ids->isNotEmpty()) {
$query->whereIn('course_id', $course_ids);
}
3 weeks ago
})->whereNotIn('status', [4, 5])
3 weeks ago
->with('course')
->get();
2 weeks ago
$courseNames = $userCourseSigns->pluck('course.name')->filter()->unique()->implode("\n\r");
3 weeks ago
$data[] = [
'user_name' => $user->name ?? '',
'mobile' => $user->mobile ?? '',
'company_name' => $user->company_name ?? '',
'company_area' => $user->company_area ?? '',
'company_industry' => $user->company_industry ?? '',
'course_names' => $courseNames,
'course_count' => $userCourseSigns->count(),
];
}
$fields = [
'user_name' => '学员姓名',
'mobile' => '手机号',
'company_name' => '企业名称',
'company_area' => '所在区域',
'company_industry' => '所属行业',
'course_names' => '报名课程',
'course_count' => '报名课程数',
];
$filename = '审核通过人数去重明细';
break;
3 weeks ago
case 'courseTypesSum':
3 weeks ago
// 课程分类明细 - 与coursesHome中的courseTypesSum逻辑保持一致
$courseTypes = CourseType::whereIn('id', $course_type_id)->get();
foreach ($courseTypes as $courseType) {
$courses2 = Course::where('type', $courseType->id)->get();
foreach ($courses2 as $course) {
$data[] = [
'course_type' => $courseType->name,
'course_name' => $course->name,
'course_type_signs_pass' => CourseSign::courseSignsTotal($start_date, $end_date, 1, $courses2->pluck('id')),
'course_type_signs_pass_unique' => CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1, $courses2->pluck('id'), null),
'course_signs_pass' => CourseSign::courseSignsTotal($start_date, $end_date, 1, [$course->id]),
2 weeks ago
'genban_total' => CourseSign::genban($start_date, $end_date, [$course->id]),
'yh_invested_total' => CourseSign::yhInvested($start_date, $end_date, [$course->id]),
'company_join_total' => CourseSign::companyJoin($start_date, $end_date, [$course->id]),
3 weeks ago
];
}
}
$fields = [
'course_type' => '课程体系',
'course_name' => '课程名称',
'course_type_signs_pass' => '课程体系培养人数',
'course_type_signs_pass_unique' => '课程体系去重培养人数',
'course_signs_pass' => '课程培养人数',
2 weeks ago
'genban_total' => '跟班学员数',
'yh_invested_total' => '被投企业数',
'company_join_total' => '元禾同事数',
3 weeks ago
];
$filename = '课程分类明细';
break;
case 'areas':
3 weeks ago
// 区域明细 - 导出course_signs_pass列表数据附加区域信息
2 weeks ago
$courseSigns = CourseSign::area($start_date, $end_date, 1, $courses->pluck('id'), false);
3 weeks ago
// 加载关联关系
2 weeks ago
$courseSigns->load(['user.company', 'course']);
3 weeks ago
foreach ($courseSigns as $sign) {
3 weeks ago
$data[] = [
2 weeks ago
'company_name' => $sign->user->company->company_name ?? '',
2 weeks ago
'company_area' => $sign->user->company->company_area ?? '',
2 weeks ago
'company_city' => $sign->user->company->company_city ?? '',
'company_province' => $sign->user->company->company_province ?? '',
3 weeks ago
'user_name' => $sign->user->name ?? '',
'mobile' => $sign->user->mobile ?? '',
'course_name' => $sign->course->name ?? '',
2 weeks ago
// 'created_at' => $sign->created_at ? $sign->created_at->format('Y-m-d H:i:s') : '',
3 weeks ago
];
}
$fields = [
2 weeks ago
'company_name' => '企业名称',
'company_area' => '公司区域',
'company_city' => '公司城市',
'company_province' => '公司省份',
3 weeks ago
'user_name' => '学员姓名',
'mobile' => '手机号',
'course_name' => '课程名称',
2 weeks ago
// 'created_at' => '报名时间',
3 weeks ago
];
$filename = '区域明细';
break;
3 weeks ago
case 'company_market_total':
3 weeks ago
// 上市公司明细 - 所有上市公司
$companies = Company::companyMarket($start_date, $end_date, true);
foreach ($companies as $company) {
$data[] = [
'company_name' => $company->company_name,
'company_legal_representative' => $company->company_legal_representative ?? '',
'company_date' => $company->company_date ?? '',
'stock_date' => $company->stock_date ?? '',
'company_address' => $company->company_address ?? '',
'company_city' => $company->company_city ?? '',
'company_area' => $company->company_area ?? '',
];
}
$fields = [
'company_name' => '企业名称',
'company_legal_representative' => '法人',
'company_date' => '成立时间',
'stock_date' => '上市日期',
'company_address' => '地址',
'company_city' => '营业范围',
'company_area' => '联系电话',
];
$filename = '上市公司明细';
break;
3 weeks ago
case 'ganbu_total':
3 weeks ago
// 跟班学员明细 - 使用模型方法
2 weeks ago
$users = CourseSign::genban($start_date, $end_date, $course_ids, true);
3 weeks ago
foreach ($users as $user) {
$data[] = [
3 weeks ago
'name' => $user->username ?? '',
'sex' => $user->sex ?? '',
3 weeks ago
'mobile' => $user->mobile ?? '',
'company_name' => $user->company_name ?? '',
3 weeks ago
'company_position' => $user->company_position ?? '',
2 weeks ago
'from' => $user->from ?? '',
3 weeks ago
];
}
$fields = [
3 weeks ago
'name' => '姓名',
3 weeks ago
'sex' => '性别',
3 weeks ago
'mobile' => '手机号',
'company_name' => '企业名称',
3 weeks ago
'company_position' => '职位',
2 weeks ago
'from' => '标签',
3 weeks ago
];
$filename = '跟班学员明细';
break;
3 weeks ago
case 'company_market_year_total':
3 weeks ago
// 今年上市公司明细 - 使用模型方法
3 weeks ago
$companies = Company::companyMarketYear($start_date, $end_date, $course_ids, true);
3 weeks ago
foreach ($companies as $company) {
$data[] = [
'company_name' => $company->company_name,
'company_legal_representative' => $company->company_legal_representative ?? '',
'company_date' => $company->company_date ?? '',
'stock_date' => $company->stock_date ?? '',
'company_address' => $company->company_address ?? '',
'company_city' => $company->company_city ?? '',
'company_area' => $company->company_area ?? '',
];
}
$fields = [
'company_name' => '企业名称',
'company_legal_representative' => '法人',
'company_date' => '成立时间',
'stock_date' => '上市日期',
'company_address' => '地址',
'company_city' => '营业范围',
'company_area' => '联系电话',
];
$filename = '今年上市公司明细';
break;
3 weeks ago
case 'company_market_after_enrollment_total':
3 weeks ago
// 入学后上市公司明细 - 使用模型方法
2 weeks ago
$companiesAfterEnrollment = CourseSign::companyMarketAfterEnrollment($start_date, $end_date, $course_ids, true);
3 weeks ago
foreach ($companiesAfterEnrollment as $item) {
$company = $item['company'];
2 weeks ago
$userNames = collect($item['users'])->pluck('name')->filter()->unique()->implode("\n\r");
3 weeks ago
$data[] = [
'company_name' => $company->company_name,
'company_legal_representative' => $company->company_legal_representative ?? '',
'company_date' => $company->company_date ?? '',
'stock_date' => $company->stock_date ?? '',
'first_sign_date' => $item['first_sign_date'],
'user_names' => $userNames,
'company_address' => $company->company_address ?? '',
'company_city' => $company->company_city ?? '',
];
}
$fields = [
'company_name' => '企业名称',
'company_legal_representative' => '法人',
'company_date' => '成立时间',
'stock_date' => '上市日期',
'first_sign_date' => '首次报名时间',
'user_names' => '学员姓名',
'company_address' => '地址',
'company_city' => '所在城市',
];
$filename = '入学后上市公司明细';
break;
2 weeks ago
case 'company_invested_after_enrollment_total':
// 入学后被投企业明细 - 使用模型方法
$companiesAfterEnrollment = CourseSign::companyInvestedAfterEnrollment($start_date, $end_date, $course_ids, true);
foreach ($companiesAfterEnrollment as $item) {
$company = $item['company'];
$userNames = collect($item['users'])->pluck('name')->filter()->unique()->implode("\n\r");
$data[] = [
'company_name' => $company->company_name,
'company_legal_representative' => $company->company_legal_representative ?? '',
'company_date' => $company->company_date ?? '',
'invest_date' => $item['invest_date'] ?? '',
'first_sign_date' => $item['first_sign_date'],
'user_names' => $userNames,
'company_address' => $company->company_address ?? '',
'company_city' => $company->company_city ?? '',
'company_area' => $company->company_area ?? '',
];
}
$fields = [
'company_name' => '企业名称',
'company_legal_representative' => '法人',
'company_date' => '成立时间',
'invest_date' => '被投日期',
'first_sign_date' => '首次报名时间',
'user_names' => '学员姓名',
'company_address' => '地址',
'company_city' => '所在城市',
'company_area' => '所在区域',
];
$filename = '入学后被投企业明细';
break;
3 weeks ago
case 'course_total':
// 开课场次明细 - 与coursesHome算法一致
2 weeks ago
$calendars = Calendar::whereBetween('date', [$start_date, $end_date])
->where(function ($query) use ($course_ids) {
2 weeks ago
$course_type_id = request('course_type_id', '');
$course_type_id = explode(',', $course_type_id);
if ($course_type_id) {
$query->whereIn('course_type_id', $course_type_id);
2 weeks ago
}
2 weeks ago
})->with('course')
3 weeks ago
->get();
foreach ($calendars as $calendar) {
$data[] = [
'course_name' => $calendar->course->name ?? '',
'title' => $calendar->title ?? '',
'date' => $calendar->date ?? '',
'start_time' => $calendar->start_time,
'end_time' => $calendar->end_time,
'address' => $calendar->address ?? '',
];
}
$fields = [
'course_name' => '课程名称',
'title' => '标题',
'date' => '日期',
'start_time' => '开始时间',
'end_time' => '结束时间',
'address' => '地址',
];
$filename = '开课场次明细';
break;
case 'course_day_total':
// 开课天数明细 - 与coursesHome算法一致
2 weeks ago
$calendars = Calendar::whereBetween('date', [$start_date, $end_date])
->where(function ($query) use ($course_ids) {
if (request('course_type_id')) {
2 weeks ago
$query->whereIn('course_type_id', request('course_type_id'));
2 weeks ago
}
})->where('is_count_days', 1)
3 weeks ago
->with('course')
->get();
foreach ($calendars as $calendar) {
$data[] = [
'course_name' => $calendar->course->name ?? '',
'title' => $calendar->title ?? '',
'date' => $calendar->date ?? '',
'start_time' => $calendar->start_time ? date('Y-m-d H:i:s', strtotime($calendar->start_time)) : '',
'end_time' => $calendar->end_time ? date('Y-m-d H:i:s', strtotime($calendar->end_time)) : '',
'days' => $calendar->days ?? 0,
'address' => $calendar->address ?? '',
];
}
$fields = [
'course_name' => '课程名称',
'title' => '标题',
'date' => '日期',
'start_time' => '开始时间',
'end_time' => '结束时间',
'days' => '天数',
'address' => '地址',
];
$filename = '开课天数明细';
break;
2 weeks ago
case 'company_join_total':
2 weeks ago
// 元和员工参与人员明细 - 使用模型方法(现在返回的是用户列表)
2 weeks ago
$users = CourseSign::companyJoin($start_date, $end_date, $course_ids, true);
// 加载关联关系
$users->load('company');
foreach ($users as $user) {
2 weeks ago
$data[] = [
2 weeks ago
'user_name' => $user->name ?? '',
'mobile' => $user->mobile ?? '',
'company_name' => $user->company->company_name ?? '',
'company_position' => $user->company_position ?? '',
'company_city' => $user->company->company_city ?? '',
'company_area' => $user->company->company_area ?? '',
'company_legal_representative' => $user->company->company_legal_representative ?? '',
'company_date' => $user->company->company_date ?? '',
'company_address' => $user->company->company_address ?? '',
2 weeks ago
];
}
$fields = [
2 weeks ago
'user_name' => '学员姓名',
'mobile' => '手机号',
2 weeks ago
'company_name' => '企业名称',
2 weeks ago
'company_position' => '职位',
'company_city' => '所在城市',
'company_area' => '所在区域',
2 weeks ago
'company_legal_representative' => '法人',
'company_date' => '成立时间',
'company_address' => '地址',
];
$filename = '元和员工参与企业明细';
break;
case 'company_ganbu_total':
// 全市干部参与企业明细 - 使用模型方法
$users = CourseSign::ganbu($start_date, $end_date, $course_ids, true);
foreach ($users as $user) {
$data[] = [
'user_name' => $user->name ?? '',
'mobile' => $user->mobile ?? '',
'company_name' => $user->company->company_name ?? '',
'company_area' => $user->company->company_area ?? '',
'company_city' => $user->company->company_city ?? '',
'company_position' => $user->company_position ?? '',
];
}
$fields = [
'user_name' => '学员姓名',
'mobile' => '手机号',
'company_name' => '企业名称',
'company_area' => '所在区域',
'company_city' => '所在城市',
'company_position' => '职位',
];
$filename = '全市干部参与企业明细';
break;
case 'cover_head_total':
// 苏州头部企业明细 - 使用模型方法
$companies = CourseSign::toubuqiye($start_date, $end_date, $course_ids, true);
foreach ($companies as $company) {
$data[] = [
'company_name' => $company->company_name,
'company_legal_representative' => $company->company_legal_representative ?? '',
'company_date' => $company->company_date ?? '',
'company_address' => $company->company_address ?? '',
'company_city' => $company->company_city ?? '',
'company_area' => $company->company_area ?? '',
'company_tag' => $company->company_tag ?? '',
'business_scope' => $company->business_scope ?? '',
'contact_phone' => $company->contact_phone ?? '',
'contact_mail' => $company->contact_mail ?? '',
];
}
$fields = [
'company_name' => '企业名称',
'company_legal_representative' => '法人',
'company_date' => '成立时间',
'company_address' => '地址',
'company_city' => '所在城市',
'company_area' => '所在区域',
'company_tag' => '企业资质',
'business_scope' => '营业范围',
'contact_phone' => '联系电话',
'contact_mail' => '联系邮箱',
];
$filename = '苏州头部企业明细';
break;
case 'cover_rencai_total':
// 高层次人才明细 - 使用模型方法
$users = CourseSign::rencai($start_date, $end_date, $course_ids, true);
// 加载关联关系
$users->load('company');
foreach ($users as $user) {
$data[] = [
'user_name' => $user->name ?? '',
'mobile' => $user->mobile ?? '',
'company_name' => $user->company_name ?? '',
'company_area' => $user->company_area ?? '',
'company_city' => $user->company->company_city ?? '',
'company_position' => $user->company_position ?? '',
'education' => $user->education ?? '',
];
}
$fields = [
'user_name' => '学员姓名',
'mobile' => '手机号',
'company_name' => '企业名称',
'company_area' => '所在区域',
'company_city' => '所在城市',
'company_position' => '职位',
'education' => '学历',
];
$filename = '高层次人才明细';
break;
case 'cover_stock_total':
// 重点上市公司明细 - 使用模型方法
$companies = CourseSign::shangshi($start_date, $end_date, $course_ids, true);
foreach ($companies as $company) {
$data[] = [
'company_name' => $company->company_name,
'company_legal_representative' => $company->company_legal_representative ?? '',
'company_date' => $company->company_date ?? '',
'stock_date' => $company->stock_date ?? '',
'company_address' => $company->company_address ?? '',
'company_city' => $company->company_city ?? '',
'company_area' => $company->company_area ?? '',
'business_scope' => $company->business_scope ?? '',
'contact_phone' => $company->contact_phone ?? '',
'contact_mail' => $company->contact_mail ?? '',
];
}
$fields = [
'company_name' => '企业名称',
'company_legal_representative' => '法人',
'company_date' => '成立时间',
'stock_date' => '上市日期',
'company_address' => '地址',
'company_city' => '所在城市',
'company_area' => '所在区域',
'business_scope' => '营业范围',
'contact_phone' => '联系电话',
'contact_mail' => '联系邮箱',
];
$filename = '重点上市公司明细';
break;
3 weeks ago
default:
return $this->fail([ResponseCode::ERROR_PARAMETER, '不支持的导出类型']);
}
if (empty($data)) {
return $this->fail([ResponseCode::ERROR_PARAMETER, '暂无数据可导出']);
}
return Excel::download(
new CommonExport($data, $fields),
$filename . '_' . date('YmdHis') . '.xlsx'
);
}
/**
* 获取coursesHome方法的公共参数提取公共逻辑
* @return array
*/
private function getCoursesHomeParams()
{
$start_date = request('start_date', CourseType::START_DATE);
2 weeks ago
// 默认结束日期一年以后
2 weeks ago
$end_date = request('end_date', date('Y-m-d', strtotime('+10 year')));
3 weeks ago
$course_type_id = request('course_type_id', '');
if ($course_type_id) {
// 部分
3 weeks ago
$course_type_id = explode(',', $course_type_id);
3 weeks ago
} else {
// 全部
$course_type_id = CourseType::pluck('id')->toArray();
}
// 课程
$courses = Course::whereIn('type', $course_type_id)->get();
return [
'start_date' => $start_date,
'end_date' => $end_date,
'course_type_id' => $course_type_id,
'courses' => $courses,
];
}
6 months ago
/**
* @OA\Post(
* path="/api/admin/other/admin-user-list",
* tags={"其他"},
* summary="后台用户列表",
* description="",
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="string"), required=false, description="每页显示的条数"),
* @OA\Parameter(name="page", in="query", @OA\Schema(type="string"), required=false, description="页码"),
* @OA\Parameter(name="sort_name", in="query", @OA\Schema(type="string"), required=false, description="排序字段名字"),
* @OA\Parameter(name="sort_type", in="query", @OA\Schema(type="string"), required=false, description="排序类型"),
* @OA\Parameter(name="department_id", in="query", @OA\Schema(type="int"), required=false, description="部门id"),
* @OA\Parameter(name="keyword", in="query", @OA\Schema(type="string"), required=false, description="关键词"),
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response(
* response="200",
* description="暂无"
* )
* )
*/
public function adminUserList()
{
$all = \request()->all();
$list = Admin::where(function ($query) use ($all) {
if (isset($all['department_id'])) {
$query->where('department_id', $all['department_id']);
}
if (isset($all['keyword'])) {
$query->where('name', 'like', '%' . $all['keyword'] . '%')->orWhere('username', 'like', '%' . $all['keyword'] . '%')->orWhere('mobile', 'like', '%' . $all['keyword'] . '%');
}
})->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc')
->paginate($all['page_size'] ?? 20);
return $this->success($list);
}
/**
* @OA\Post(
* path="/api/admin/other/admin-department-list",
* tags={"其他"},
* summary="后台部门列表",
* description="",
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="string"), required=false, description="每页显示的条数"),
* @OA\Parameter(name="page", in="query", @OA\Schema(type="string"), required=false, description="页码。不传则全部,传入则分页"),
* @OA\Parameter(name="sort_name", in="query", @OA\Schema(type="string"), required=false, description="排序字段名字"),
* @OA\Parameter(name="sort_type", in="query", @OA\Schema(type="string"), required=false, description="排序类型"),
* @OA\Parameter(name="keyword", in="query", @OA\Schema(type="string"), required=false, description="关键词"),
* @OA\Parameter(name="show_tree", in="query", @OA\Schema(type="string"), required=false, description="是否显示树形结构 0否1是"),
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response(
* response="200",
* description="暂无"
* )
* )
*/
public function adminDepartmentList()
{
$all = \request()->all();
$list = Department::with('users')->where(function ($query) use ($all) {
if (isset($all['keyword'])) {
$query->where('name', 'like', '%' . $all['keyword'] . '%');
}
});
if (isset($all['show_tree']) && $all['show_tree']) {
// 显示树形结构
$list = array2tree($list->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc')->get()->toArray());
} else {
$list = $list->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc')->paginate($all['page_size'] ?? 20);
}
return $this->success($list);
}
/**
* @OA\Get(
* path="/api/admin/other/table-fileds",
* tags={"其他"},
* summary="获取表字段",
* description="",
* @OA\Parameter(name="table_name", in="query", @OA\Schema(type="string"), required=true, description="table_name"),
* @OA\Parameter(name="except", in="query", @OA\Schema(type="string"), required=true, description="排除的字段数组"),
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response(
* response="200",
* description="暂无"
* )
* )
*/
public function tableFileds()
{
$all = \request()->all();
$messages = [
'table_name.required' => '表名必填',
];
$validator = Validator::make($all, [
'table_name' => 'required'
], $messages);
if ($validator->fails()) {
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
}
$except = request('except');
$detail = (new CustomFormField())->getRowTableFieldsByComment($all['table_name']);
$list = [];
if ($except) {
foreach ($detail as $key => $item) {
if (in_array($key, $except)) {
continue;
}
$list[] = $item;
}
} else {
$list = $detail;
}
return $this->success($list);
}
public function test()
{
2 months ago
$model = new DoorRepository();
$result = $model->getAllDoorInfo();
4 weeks ago
dd(json_encode($result, JSON_UNESCAPED_UNICODE));
6 months ago
}
/**
* 车辆进出场日志
*/
public function postCarInInfo()
{
$all = request()->all();
CarparkLog::add(1, $all, $all['plateNo']);
return $this->success($all);
}
/**
* 车辆出场日志
*/
public function postCarOutInfo()
{
$all = request()->all();
CarparkLog::add(2, $all, $all['plateNo']);
return $this->success($all);
}
}