|
|
<?php
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
use App\Helpers\ResponseCode;
|
|
|
use App\Jobs\CancelAppointMeet;
|
|
|
use App\Models\Admin;
|
|
|
use App\Models\Appointment;
|
|
|
use App\Models\AppointmentConfig;
|
|
|
use App\Models\Calendar;
|
|
|
use App\Models\CarparkLog;
|
|
|
use App\Models\Company;
|
|
|
use App\Models\CourseSign;
|
|
|
use App\Models\CourseType;
|
|
|
use App\Models\CustomFormField;
|
|
|
use App\Models\Department;
|
|
|
use App\Models\ParameterDetail;
|
|
|
use App\Models\User;
|
|
|
use App\Repositories\DoorRepository;
|
|
|
use App\Repositories\EntranceRepository;
|
|
|
use Illuminate\Support\Carbon;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
use App\Models\Course;
|
|
|
use EasyWeChat\Factory;
|
|
|
use Illuminate\Filesystem\Filesystem;
|
|
|
|
|
|
class OtherController extends CommonController
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
* @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()
|
|
|
{
|
|
|
// 校友总数
|
|
|
$schoolmate['schoolmate_total'] = User::where('is_schoolmate', 1)->count();
|
|
|
// 2025年校友数
|
|
|
$schoolmate['schoolmate_year'] = User::where('is_schoolmate', 1)->where('created_at', 'like', '%' . date('Y') . '%')->count();
|
|
|
|
|
|
// 开课场次(全部)
|
|
|
$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; // 包含起始和结束日期
|
|
|
});
|
|
|
|
|
|
// 校友企业总融资额
|
|
|
$company['company_fund'] = Company::where('is_schoolmate', 1)->sum('company_fund');
|
|
|
// 校友企业总估值
|
|
|
$company['valuation'] = Company::where('is_schoolmate', 1)->sum('valuation');
|
|
|
|
|
|
// 校友企业所属领域
|
|
|
$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()
|
|
|
];
|
|
|
}
|
|
|
// 课程统计
|
|
|
$courseTypes = CourseType::where('is_chart', 1)->get();
|
|
|
foreach ($courseTypes as $courseType) {
|
|
|
$courseIds = Course::where('type', $courseType->id)->pluck('id');
|
|
|
$courseType->course_signs_total = CourseSign::whereIn('course_id', $courseIds)
|
|
|
->where('status', 1)
|
|
|
->count();
|
|
|
}
|
|
|
// 苏州区域数据
|
|
|
$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'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @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="结束日期"),
|
|
|
* @OA\Parameter(name="course_type_id", in="query", @OA\Schema(type="string"), required=true, description="课程体系id,多个英文逗号"),
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description="暂无"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function coursesHome()
|
|
|
{
|
|
|
$start_date = request('start_date', '2020-01-01');
|
|
|
$end_date = request('end_date', date('Y-m-d'));
|
|
|
$course_type_id = request('course_type_id', '');
|
|
|
if ($course_type_id) {
|
|
|
// 部分
|
|
|
$course_type_id = explode(',', $course_type_id);
|
|
|
} else {
|
|
|
// 全部
|
|
|
$course_type_id = CourseType::pluck('id')->toArray();
|
|
|
}
|
|
|
// 课程
|
|
|
$courses = Course::where('start_date', '>=', $start_date)
|
|
|
->where('start_date', '<=', $end_date)
|
|
|
->whereIn('type', $course_type_id)
|
|
|
->get();
|
|
|
// 被投企业数
|
|
|
$list['course_signs_invested'] = CourseSign::yhInvested($start_date, $end_date);
|
|
|
// 报名人数
|
|
|
$list['course_signs_total'] = CourseSign::courseSignsTotal($start_date, $end_date);
|
|
|
// 审核通过人数
|
|
|
$list['course_signs_pass'] = CourseSign::courseSignsTotal($start_date, $end_date, 1);
|
|
|
// 审核通过人数去重
|
|
|
$list['course_signs_pass_unique'] = CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1);
|
|
|
// 开课场次
|
|
|
$calendar = Calendar::whereIn('course_id', $courses->pluck('id'))->whereBetween('date', [$start_date, $end_date])->get();
|
|
|
$list['course_total'] = $calendar->count();
|
|
|
// 开课天数
|
|
|
$list['course_day_total'] = $calendar->sum(function ($course) {
|
|
|
$start = Carbon::parse($course->start_time);
|
|
|
$end = Carbon::parse($course->end_time);
|
|
|
return $end->diffInDays($start) + 1; // 包含起始和结束日期
|
|
|
});
|
|
|
// 课程分类明细统计
|
|
|
$courseTypesSum = [];
|
|
|
$courseTypes = CourseType::whereIn('id', $course_type_id)->get();
|
|
|
foreach ($courseTypes as $courseType) {
|
|
|
// 获取课程
|
|
|
$courses2 = Course::where('start_date', '>=', $start_date)
|
|
|
->where('start_date', '<=', $end_date)
|
|
|
->where('type', $courseType->id)
|
|
|
->get();
|
|
|
foreach ($courses2 as $course) {
|
|
|
$courseTypesSum[] = [
|
|
|
'course_type' => $courseType->name,
|
|
|
// 培养人数
|
|
|
'course_type_signs_pass' => CourseSign::courseSignsTotal($start_date, $end_date, 1, $courses2->pluck('id')->toArray()),
|
|
|
// 去重培养人数
|
|
|
'course_type_signs_pass_unique' => CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1, $courses2->pluck('id')->toArray()),
|
|
|
'course_name' => $course->name,
|
|
|
'course_signs_pass' => CourseSign::courseSignsTotal($start_date, $end_date, 1, [$course->id]),
|
|
|
];
|
|
|
}
|
|
|
|
|
|
}
|
|
|
// 区域明细统计
|
|
|
$areas = ParameterDetail::where('parameter_id', 5)->get();
|
|
|
foreach ($areas as $area) {
|
|
|
$courseSignByArea = CourseSign::where('status', 1)
|
|
|
->whereHas('user', function ($query) use ($area) {
|
|
|
$query->where('company_area', $area->value);
|
|
|
})->whereDate('created_at', '>=', $start_date)
|
|
|
->whereDate('created_at', '<=', $end_date)
|
|
|
->get();
|
|
|
$area->course_signs_pass = $courseSignByArea->count();
|
|
|
$area->course_signs_pass_unique = User::whereIn('id', $courseSignByArea->pluck('user_id'))->distinct('mobile')->count();
|
|
|
}
|
|
|
return $this->success(compact('list', 'courseTypesSum', 'areas'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @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()
|
|
|
{
|
|
|
$model = new DoorRepository();
|
|
|
$result = $model->getAllDoorInfo();
|
|
|
dd(json_encode($result,JSON_UNESCAPED_UNICODE));
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 车辆进出场日志
|
|
|
*/
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
}
|