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.

198 lines
7.5 KiB

<?php
namespace App\Http\Controllers\Admin;
use App\Helpers\ResponseCode;
use App\Models\Admin;
use App\Models\Appointment;
use App\Models\AppointmentConfig;
use App\Models\CarparkLog;
use App\Models\CourseSign;
use App\Models\CourseType;
use App\Models\CustomFormField;
use App\Models\Department;
use App\Models\User;
use App\Repositories\DoorRepository;
use App\Repositories\EntranceRepository;
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()
{
// 校友总数
$schoolmateTotal = User::where('is_schoolmate', 1)->count();
// 2025年校友数
$schoolmateTotalYear = User::where('is_schoolmate', 1)->where('created_at', 'like', '%' . date('Y') . '%')->count();
// 课程统计
$courseTypes = CourseType::with('courses')->where('is_chart')->get();
foreach ($courseTypes as $courseType) {
$courseType->course_signs_total = CourseSign::where('course_id', $courseType->courses->pluck('id'))
->where('status', 1)
->count();
}
return $this->success(compact('courseTypes', 'schoolmateTotal', 'schoolmateTotalYear'));
}
/**
* @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()
{
$appointmentModel = Appointment::find(288);
$appointmentConfig = $appointmentModel->site_detail;
$result = (new Appointment())->appointDoor($appointmentModel, $appointmentConfig);
dd($result);
}
/**
* 车辆进出场日志
*/
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);
}
}