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.
362 lines
15 KiB
362 lines
15 KiB
<?php |
|
|
|
namespace App\Admin\Controllers; |
|
|
|
use App\Admin\Actions\Grid\ImportExcelBed; |
|
use App\Admin\Extensions\Exporter\ImportBedExporter; |
|
use App\Admin\Metrics\Examples\AllocationExcelBed; |
|
use App\Admin\Metrics\Examples\AllocationExcelBedNotSelect; |
|
use App\Admin\Metrics\Examples\AllocationExcelBedSelect; |
|
use App\Models\AllocationDormitoryBed; |
|
use App\Models\Bed; |
|
use App\Models\Building; |
|
use App\Models\Config; |
|
use App\Models\DormitoryNumber; |
|
use App\Models\DormitoryType; |
|
use App\Models\Floor; |
|
use App\Models\LivingArea; |
|
use App\Models\MultipleWorld; |
|
use App\Models\SecondaryCollege; |
|
use App\Models\SelectedDormitory; |
|
use App\Models\Speciality; |
|
use App\Models\UsersMember; |
|
use Dcat\Admin\Actions\Action; |
|
use Dcat\Admin\Form; |
|
use Dcat\Admin\Grid; |
|
use Dcat\Admin\Layout\Content; |
|
use Dcat\Admin\Layout\Row; |
|
use Dcat\Admin\Show; |
|
use Dcat\Admin\Http\Controllers\AdminController; |
|
use Dcat\Admin\Widgets\Metrics\Card; |
|
use Illuminate\Support\MessageBag; |
|
|
|
class AllocationDormitoryBedController extends AdminController |
|
{ |
|
public function index(Content $content) |
|
{ |
|
return $content |
|
->header('床位管理') |
|
->description('数据统计') |
|
->body(function (Row $row) { |
|
$row->column(4, new AllocationExcelBed()); |
|
$row->column(4, new AllocationExcelBedSelect()); |
|
$row->column(4, new AllocationExcelBedNotSelect()); |
|
}) |
|
->body($this->grid()); |
|
} |
|
|
|
/** |
|
* Make a grid builder. |
|
* |
|
* @return Grid |
|
*/ |
|
protected function grid() |
|
{ |
|
return Grid::make(new AllocationDormitoryBed(), function (Grid $grid) { |
|
|
|
//开启边框模式 |
|
$grid->withBorder(); |
|
// 开启字段选择器功能 |
|
$grid->showColumnSelector(); |
|
//开启导出功能 |
|
$grid->export(new ImportBedExporter()); |
|
|
|
//取出当前年份 |
|
$config = Config::query()->where([ |
|
"unique_identification" => "annual_session" |
|
])->first(); |
|
|
|
$grid->model()->where("annual_session", $config->data); |
|
|
|
$grid->column('id')->sortable(); |
|
|
|
$grid->column('is_select')->display(function (){ |
|
$info = SelectedDormitory::query()->where([ |
|
"allocation_dormitory_id" => $this->id, |
|
"annual_session" => $this->annual_session, |
|
"status" => SelectedDormitory::STATUS_YES |
|
])->first(); |
|
if(!empty($info)){ |
|
return "占用"; |
|
} |
|
|
|
})->help("显示占用时则代表该床位已被学生选中,不建议修改床位的信息"); |
|
|
|
$grid->column('sex')->display(function () { |
|
return $this->sex == 0 ? "未知" : ($this->sex == 1 ? "男" : "女"); |
|
}); |
|
|
|
$grid->column('dormitory_type')->display(function(){ |
|
$info = DormitoryType::query()->where("id", $this->dormitory_type)->first(); |
|
if(!empty($info)){ |
|
return $info->dormitory; |
|
} |
|
})->help("未显示时则找不到对应的宿舍类型或该宿舍类型已被删除"); |
|
$grid->column('multiple_worlds')->display(function(){ |
|
$info = MultipleWorld::query()->where("id", $this->multiple_worlds)->first(); |
|
if(!empty($info)){ |
|
return $info->people; |
|
} |
|
})->help("未显示时则找不到对应的几人间或该几人间已被删除"); |
|
$grid->column('living_area')->display(function(){ |
|
$info = LivingArea::query()->where("id", $this->living_area)->first(); |
|
if(!empty($info)){ |
|
return $info->title; |
|
} |
|
})->help("未显示时则找不到对应的生活区或该生活区已被删除"); |
|
$grid->column('building_id')->display(function(){ |
|
$info = Building::query()->where("id", $this->building_id)->first(); |
|
if(!empty($info)){ |
|
return $info->building_title; |
|
} |
|
})->help("未显示时则找不到对应的楼栋或该楼栋已被删除"); |
|
$grid->column('floor_id')->display(function(){ |
|
$info = Floor::query()->where("id", $this->floor_id)->first(); |
|
if(!empty($info)){ |
|
return $info->floor_title; |
|
} |
|
})->help("未显示时则找不到对应的楼层或该楼层已被删除"); |
|
$grid->column('dormitory_number')->display(function(){ |
|
$info = DormitoryNumber::query()->where("id", $this->dormitory_number)->first(); |
|
if(!empty($info)){ |
|
return $info->dormitory_number; |
|
} |
|
})->help("未显示时则找不到对应的宿舍号或该宿舍号已被删除"); |
|
$grid->column('bed_id')->display(function(){ |
|
$info = Bed::query()->where("id", $this->bed_id)->first(); |
|
if(!empty($info)){ |
|
return $info->bed_number; |
|
} |
|
})->help("未显示时则找不到对应的床位或该床位已被删除"); |
|
$grid->column('secondary_college_id')->display(function () { |
|
$info = Speciality::query()->where("id", $this->speciality_id)->first(); |
|
if(!empty($info)){ |
|
$secondaryInfo = SecondaryCollege::query()->where("id", $info->secondary_college_id)->first(); |
|
if(!empty($secondaryInfo)){ |
|
return $secondaryInfo->name; |
|
} |
|
} |
|
|
|
})->help("未显示学院时请检查是否已经分配专业"); |
|
$grid->column('speciality_id')->display(function () { |
|
$info = Speciality::where("id", $this->speciality_id)->first(); |
|
if(!empty($info)){ |
|
return $info->speciality_name; |
|
} |
|
})->help("未显示专业时请检查是否已经分配专业"); |
|
$grid->column('status')->select([1=>"正常", 2=>"禁用"]); |
|
|
|
$grid->filter(function (Grid\Filter $filter) { |
|
|
|
$filter->equal('id'); |
|
|
|
$filter->where("is_select", function ($query) { |
|
//取出当前年份 |
|
$config = Config::query()->where([ |
|
"unique_identification" => "annual_session" |
|
])->first(); |
|
|
|
$selectList = SelectedDormitory::query()->where([ |
|
"status" => SelectedDormitory::STATUS_YES, |
|
"annual_session" => $config->data, |
|
])->get()->toArray(); |
|
|
|
if(!empty($selectList)){ |
|
$selectIds = array_column($selectList, "allocation_dormitory_id"); |
|
} |
|
|
|
if($this->input == 1){ |
|
//占用时 |
|
$query->whereIn('id', $selectIds); |
|
}else { |
|
//未占用时 |
|
$query->whereNotIn("id", $selectIds); |
|
} |
|
|
|
})->select([ |
|
"1" => "占用", |
|
"2" => "未占用" |
|
]); |
|
|
|
|
|
$filter->equal('speciality_id')->select(function (){ |
|
$list = Speciality::query()->where("status", Speciality::STATUS_YES)->get()->toArray(); |
|
if(empty($list)){ |
|
return []; |
|
} |
|
$select = []; |
|
foreach($list as $item){ |
|
$college = SecondaryCollege::query()->where("id", $item["secondary_college_id"])->first(); |
|
$select[$item["id"]] = $item["speciality_name"]."({$college->name})"; |
|
} |
|
|
|
return $select; |
|
}); |
|
|
|
$filter->equal('dormitory_type')->select(DormitoryType::query()->pluck("dormitory as value", "id")) |
|
->load("multiple_worlds", config("app.url")."/api/getMultipleWorldsByList"); |
|
|
|
$filter->equal("multiple_worlds")->select(); |
|
$filter->equal('living_area')->select(LivingArea::query()->pluck("title as value", "id")); |
|
$filter->equal('building_id')->select(Building::query()->pluck("building_title as value", "id")); |
|
$filter->equal('floor_id')->select(Floor::query()->pluck("floor_title as value", "id")); |
|
$filter->equal('dormitory_number')->select(DormitoryNumber::query()->pluck("dormitory_number as value", "id")); |
|
$filter->equal('bed_id')->select(Bed::query()->pluck("bed_number as value", "id")); |
|
$filter->equal('sex')->select([1 => "男", 2 => "女"]); |
|
$filter->equal('status')->select([1 => "正常", 2 => "禁用"]); |
|
}); |
|
|
|
// 禁用详情按钮 |
|
$grid->disableViewButton(); |
|
|
|
$grid->tools(function (Grid\Tools $tools) { |
|
// excle 导入 |
|
$tools->append(new ImportExcelBed()); |
|
}); |
|
//下载模版 |
|
$grid->tools('<a href="/storage/excelTemplate/dormitoryTemplate.xlsx" download="dormitoryTemplate.xlsx" target="_blank"><button class="btn btn-success ">下载宿舍模版</button></a>'); |
|
|
|
}); |
|
} |
|
|
|
/** |
|
* Make a show builder. |
|
* |
|
* @param mixed $id |
|
* |
|
* @return Show |
|
*/ |
|
protected function detail($id) |
|
{ |
|
return Show::make($id, new AllocationDormitoryBed(), function (Show $show) { |
|
$show->field('id'); |
|
$show->field('dormitory_type'); |
|
$show->field('multiple_worlds'); |
|
$show->field('living_area'); |
|
$show->field('building_id'); |
|
$show->field('floor_id'); |
|
$show->field('dormitory_number'); |
|
$show->field('bed_id'); |
|
$show->field('speciality_id'); |
|
$show->field('status'); |
|
$show->field('create_time'); |
|
$show->field('update_time'); |
|
$show->field('sex'); |
|
}); |
|
} |
|
|
|
/** |
|
* Make a form builder. |
|
* |
|
* @return Form |
|
*/ |
|
protected function form() |
|
{ |
|
return Form::make(new AllocationDormitoryBed(), function (Form $form) { |
|
$form->display('id'); |
|
$form->select('dormitory_type') |
|
->options(DormitoryType::query()->where("status",DormitoryType::STATUS_YES)->pluck("dormitory as value", "id")) |
|
->load("multiple_worlds", config("app.url")."/api/getMultipleWorldsByList") |
|
->required(); |
|
$form->select("multiple_worlds"); |
|
$form->select('living_area')->options(LivingArea::query()->where("status",LivingArea::STATUS_YES)->pluck("title as value", "id"))->required(); |
|
$form->select('building_id')->options(Building::query()->where("status",Building::STATUS_YES)->pluck("building_title as value", "id"))->required(); |
|
$form->select('floor_id')->options(Floor::query()->where("status",Floor::STATUS_YES)->pluck("floor_title as value", "id"))->required(); |
|
$form->select('dormitory_number')->options(DormitoryNumber::query()->where("status",DormitoryNumber::STATUS_YES)->pluck("dormitory_number as value", "id"))->required(); |
|
$form->select('bed_id')->options(Bed::query()->where("status",Bed::STATUS_YES)->pluck("bed_number as value", "id"))->required(); |
|
$form->select("speciality_id")->options(function (){ |
|
$list = Speciality::query()->where("status",Speciality::STATUS_YES)->get()->toArray(); |
|
if(empty($list)){ |
|
return []; |
|
} |
|
$arr = []; |
|
foreach($list as $item){ |
|
//取出所有二级学院 |
|
$seconInfo = SecondaryCollege::query()->where("id", $item["secondary_college_id"])->first(); |
|
|
|
if(empty($seconInfo)){ |
|
$arr[$item["id"]] = $item["speciality_name"]."(未分配二级学院)"; |
|
}else{ |
|
$arr[$item["id"]] = $item["speciality_name"]."({$seconInfo->name})"; |
|
} |
|
|
|
} |
|
|
|
return $arr; |
|
})->required(); |
|
$form->select('sex', '性别')->options([1 => '男', 2 => '女'])->required(); |
|
$form->select('status', '状态')->options([1 => '正常', 2 => '禁用'])->required(); |
|
|
|
$form->hidden("annual_session"); |
|
$form->hidden("create_time"); |
|
$form->hidden("update_time"); |
|
|
|
// 去除跳转详情按钮 |
|
$form->disableViewButton(); |
|
|
|
$form->footer(function ($footer) { |
|
|
|
// 去掉`查看`checkbox |
|
$footer->disableViewCheck(); |
|
|
|
// 去掉`继续编辑`checkbox |
|
$footer->disableEditingCheck(); |
|
|
|
// 去掉`继续创建`checkbox |
|
$footer->disableCreatingCheck(); |
|
|
|
}); |
|
|
|
$form->submitted(function (Form $form) { |
|
// 获取用户提交参数 |
|
$dormitory_type = $form->dormitory_type; |
|
$multiple_worlds = $form->multiple_worlds; |
|
$living_area = $form->living_area; |
|
$building_id = $form->building_id; |
|
$floor_id = $form->floor_id; |
|
$dormitory_number = $form->dormitory_number; |
|
$bed_id = $form->bed_id; |
|
$speciality_id = $form->speciality_id; |
|
$sex = $form->sex; |
|
$annual_session = $form->annual_session; |
|
|
|
$where = [ |
|
"dormitory_type" => $dormitory_type, |
|
"multiple_worlds" => $multiple_worlds, |
|
"living_area" => $living_area, |
|
"building_id" => $building_id, |
|
"floor_id" => $floor_id, |
|
"dormitory_number" => $dormitory_number, |
|
"bed_id" => $bed_id, |
|
"speciality_id" => $speciality_id, |
|
"sex" => $sex, |
|
"annual_session" => $annual_session, |
|
]; |
|
|
|
$check = AllocationDormitoryBed::query()->where($where)->count(); |
|
if(!empty($check)){ |
|
// 中断后续逻辑 |
|
return $form->response()->error('当前床位已存在,无需重复添加~'); |
|
} |
|
|
|
}); |
|
|
|
$form->saving(function (Form $form) { |
|
|
|
if ($form->isCreating()) { |
|
$form->create_time =time(); |
|
// 删除用户提交的数据 |
|
$form->deleteInput('update_time'); |
|
}else{ |
|
$form->update_time =time(); |
|
} |
|
}); |
|
|
|
$config = Config::query()->where([ |
|
"unique_identification" => "annual_session" |
|
])->first(); |
|
$form->annual_session = $config->data; |
|
|
|
}); |
|
} |
|
}
|
|
|