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.
189 lines
6.6 KiB
189 lines
6.6 KiB
<?php |
|
|
|
namespace App\Admin\Controllers; |
|
|
|
use App\Models\TeacherScanCodeUsers; |
|
use Dcat\Admin\Form; |
|
use Dcat\Admin\Grid; |
|
use Dcat\Admin\Show; |
|
use Dcat\Admin\Http\Controllers\AdminController; |
|
|
|
class TeacherScanCodeUserController extends AdminController |
|
{ |
|
/** |
|
* Make a grid builder. |
|
* |
|
* @return Grid |
|
*/ |
|
protected function grid() |
|
{ |
|
return Grid::make(new TeacherScanCodeUsers(), function (Grid $grid) { |
|
//开启边框模式 |
|
$grid->withBorder(); |
|
// 开启字段选择器功能 |
|
$grid->showColumnSelector(); |
|
|
|
$grid->column('id')->sortable(); |
|
$grid->column('name'); |
|
$grid->column('mobile'); |
|
$grid->column('belongto')->display(function () { |
|
switch ($this->belongto) { |
|
case TeacherScanCodeUsers::BELONGTO_ONE: //招生办 |
|
return "招生办"; |
|
break; |
|
case TeacherScanCodeUsers::BELONGTO_TWO: //二级学院 |
|
return "二级学院"; |
|
break; |
|
case TeacherScanCodeUsers::BELONGTO_THREE: //宿管 |
|
return "宿管"; |
|
break; |
|
} |
|
|
|
}); |
|
$grid->column('open_number_id')->display(function () { |
|
$open_number_id = $this->open_number_id; |
|
if (!empty($open_number_id)) { |
|
if ($open_number_id == $this->id) { |
|
return $this->name; |
|
} else { |
|
$name = TeacherScanCodeUsers::query()->where("id", $open_number_id)->first("name"); |
|
if(empty($name)){ |
|
return ""; |
|
} |
|
return $name->name; |
|
} |
|
} |
|
return "超级管理员"; |
|
}); |
|
$grid->column('status')->select([1=>"正常", 2=>"禁用"]); |
|
$grid->column('create_time')->display(function (){ |
|
if(!empty($this->create_time)){ |
|
return date("Y-m-d H:i:s", $this->create_time); |
|
} |
|
})->sortable(); |
|
$grid->column('update_time')->display(function (){ |
|
if(!empty($this->update_time)){ |
|
return date("Y-m-d H:i:s", $this->update_time); |
|
} |
|
}); |
|
|
|
$grid->filter(function (Grid\Filter $filter) { |
|
$filter->equal('name'); |
|
$filter->equal('mobile'); |
|
$filter->equal('belongto')->select(function (){ |
|
return [ |
|
TeacherScanCodeUsers::BELONGTO_ONE => "招生办", |
|
TeacherScanCodeUsers::BELONGTO_TWO => "二级学院", |
|
TeacherScanCodeUsers::BELONGTO_THREE => "宿管", |
|
]; |
|
}); |
|
$filter->equal('status')->select([1 => "正常", 2 => "禁用"]); |
|
}); |
|
|
|
// 禁用详情按钮 |
|
$grid->disableViewButton(); |
|
}); |
|
} |
|
|
|
/** |
|
* Make a show builder. |
|
* |
|
* @param mixed $id |
|
* |
|
* @return Show |
|
*/ |
|
protected function detail($id) |
|
{ |
|
return Show::make($id, new TeacherScanCodeUsers(), function (Show $show) { |
|
$show->field('id'); |
|
$show->field('name'); |
|
$show->field('mobile'); |
|
$show->field('belongto'); |
|
$show->field('open_number_id'); |
|
$show->field('status'); |
|
$show->field('create_time'); |
|
$show->field('update_time'); |
|
}); |
|
} |
|
|
|
/** |
|
* Make a form builder. |
|
* |
|
* @return Form |
|
*/ |
|
protected function form() |
|
{ |
|
return Form::make(new TeacherScanCodeUsers(), function (Form $form) { |
|
|
|
$form->display('id'); |
|
$form->text('name')->required(); |
|
$form->text('mobile')->required(); |
|
$form->password('password')->required(); |
|
|
|
$form->select('belongto')->options([ |
|
TeacherScanCodeUsers::BELONGTO_ONE => "招生办", |
|
TeacherScanCodeUsers::BELONGTO_TWO => "二级学院", |
|
TeacherScanCodeUsers::BELONGTO_THREE => "宿管", |
|
])->required(); |
|
$form->select('is_authority', '是否允许创建子账号')->options([1 => '否', 2 => '是'])->required()->help("允许创建子账号时则可以在教师端新增该部门下的教师账号"); |
|
$form->select('open_number_id')->options(function (){ |
|
|
|
$result = [ |
|
"0" => "超级管理员", |
|
]; |
|
$list = TeacherScanCodeUsers::query()->where([ |
|
"status" => TeacherScanCodeUsers::STATUS_SUCCESS, |
|
"is_authority" => TeacherScanCodeUsers::IS_AUTHORITY_YES, |
|
])->get()->toArray(); |
|
if(empty($list)){ |
|
return $result; |
|
} |
|
$belongtoList = [ |
|
TeacherScanCodeUsers::BELONGTO_ONE => "招生办", |
|
TeacherScanCodeUsers::BELONGTO_TWO => "二级学院", |
|
TeacherScanCodeUsers::BELONGTO_THREE => "宿管", |
|
]; |
|
|
|
foreach($list as $item){ |
|
$result[$item["id"]] = $item["name"]."--{$belongtoList[$item['belongto']]}"; |
|
} |
|
return $result; |
|
}); |
|
$form->select('status')->options([1 => '正常', 2 => '禁用'])->required(); |
|
$form->hidden("create_time"); |
|
$form->hidden("update_time"); |
|
|
|
// 去除删除按钮 |
|
$form->disableDeleteButton(); |
|
// 去除跳转详情按钮 |
|
$form->disableViewButton(); |
|
|
|
$form->footer(function ($footer) { |
|
|
|
// 去掉`查看`checkbox |
|
$footer->disableViewCheck(); |
|
|
|
// 去掉`继续编辑`checkbox |
|
$footer->disableEditingCheck(); |
|
|
|
// 去掉`继续创建`checkbox |
|
$footer->disableCreatingCheck(); |
|
|
|
}); |
|
|
|
$form->saving(function (Form $form) { |
|
if (strlen($form->password) < 32) { |
|
$form->password = bcrypt($form->password); |
|
} |
|
if ($form->isCreating()) { |
|
$form->create_time =time(); |
|
// 删除用户提交的数据 |
|
$form->deleteInput('update_time'); |
|
}else{ |
|
$form->update_time =time(); |
|
} |
|
}); |
|
|
|
}); |
|
} |
|
}
|
|
|