管理员添加与编辑完成
This commit is contained in:
1 parent
1f7b1fe81f
commit
4ce860a735
3 files changed
+103
-93
No files matched your search
@@ -66,15 +66,19 @@ class Index extends Base
|
||||
// 创建用户信息
|
||||
public function create()
|
||||
{
|
||||
|
||||
// 设置页面标题
|
||||
$list['title'] = '添加管理员';
|
||||
$list['set'] = array(
|
||||
'webtitle'=>'添加管理员',
|
||||
'butname'=>'添加',
|
||||
'formpost'=>'POST',
|
||||
'url'=>'/admin',
|
||||
);
|
||||
|
||||
|
||||
// 模板赋值
|
||||
$this->assign('list',$list);
|
||||
|
||||
// 渲染
|
||||
return $this->fetch();
|
||||
return $this->fetch('create');
|
||||
}
|
||||
|
||||
|
||||
@@ -109,14 +113,13 @@ class Index extends Base
|
||||
// 实例化管理员数据模型类
|
||||
$admin = new AD();
|
||||
$admindata = $admin->create($list);
|
||||
// 重组用户角色列表
|
||||
foreach ($list['group_id'] as $key => $value) {
|
||||
$groupids[]=['group_id'=>$value];
|
||||
}
|
||||
$authgroupdata = $admindata->authgroup()->saveAll($groupids);
|
||||
|
||||
// 更新中间表
|
||||
$groupdata=$admindata->glGroup()->saveAll($list['group_id']);
|
||||
|
||||
|
||||
// 根据更新结果设置返回提示信息
|
||||
$authgroupdata ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0];
|
||||
$admindata&&$groupdata ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0];
|
||||
|
||||
// 返回信息
|
||||
return json($data);
|
||||
@@ -148,16 +151,31 @@ class Index extends Base
|
||||
{
|
||||
|
||||
// 获取用户信息
|
||||
$list = AD::where('id',$id)
|
||||
$list['data'] = AD::where('id',$id)
|
||||
->field('id,school,username,xingming,sex,shengri,phone,beizhu')
|
||||
->with([
|
||||
'adSchool'=>function($query){
|
||||
$query->field('id,jiancheng');
|
||||
}
|
||||
,'glGroup'=>function($query){
|
||||
$query->where('status',1)->field('title');
|
||||
}
|
||||
])
|
||||
->find();
|
||||
// 追加用户id字符串
|
||||
$list = $list->append(['groupids']);
|
||||
|
||||
// 设置页面标题
|
||||
$list['set'] = array(
|
||||
'webtitle'=>'编辑管理员',
|
||||
'butname'=>'修改',
|
||||
'formpost'=>'PUT',
|
||||
'url'=>'/admin/'.$id,
|
||||
);
|
||||
|
||||
|
||||
// 模板赋值
|
||||
$this->assign('list',$list);
|
||||
|
||||
return $this->fetch();
|
||||
// 渲染
|
||||
return $this->fetch('create');
|
||||
|
||||
}
|
||||
|
||||
@@ -171,6 +189,8 @@ class Index extends Base
|
||||
// 获取表单数据
|
||||
$list = request()->only(['xingming','school','username','sex','shengri','phone','beizhu','group_id'],'put');
|
||||
|
||||
$list['group_id'] = array_values($list['group_id']);
|
||||
|
||||
// 验证表单数据
|
||||
$result = $validate->check($list);
|
||||
$msg = $validate->getError();
|
||||
@@ -180,18 +200,14 @@ class Index extends Base
|
||||
return json(['msg'=>$msg,'val'=>0]);;
|
||||
}
|
||||
|
||||
|
||||
// 更新管理员信息
|
||||
$list['id'] = $id;
|
||||
$admindata = AD::update($list);
|
||||
|
||||
// 删除原来角色
|
||||
$aa = $admindata->authgroup()->delete();
|
||||
|
||||
// 重组用户角色列表
|
||||
foreach ($list['group_id'] as $key => $value) {
|
||||
$groupids[]=['group_id'=>$value];
|
||||
}
|
||||
$groupdata = $admindata->authgroup()->saveAll($groupids);
|
||||
// 更新中间表
|
||||
$groupdata=$admindata->glGroup()->detach();
|
||||
$groupdata=$admindata->glGroup()->attach($list['group_id']);
|
||||
|
||||
// 根据更新结果设置返回提示信息
|
||||
$admindata&&$groupdata ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0];
|
||||
|
||||
@@ -3,61 +3,36 @@
|
||||
{block name="form"}
|
||||
<form class="layui-form layui-form-pane" lay-filter="myform">
|
||||
<div class="layui-form-item">
|
||||
<label for="title" class="layui-form-label">
|
||||
<span class="x-red">*</span>单位名称
|
||||
<label for="xingming" class="layui-form-label">
|
||||
<span class="x-red">*</span>用户姓名
|
||||
</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" id="title" name="title" lay-verify="required"
|
||||
autocomplete="off" class="layui-input " value="{$list.data.title|default=''}" placeholder="中文2-25个字符">
|
||||
<input type="text" id="xingming" name="xingming" lay-verify="required"
|
||||
autocomplete="off" class="layui-input " value="{$list.data.xingming|default=''}" placeholder="中文2-25个字符">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="jiancheng" class="layui-form-label">
|
||||
<span class="x-red">*</span>单位简称
|
||||
<label for="username" class="layui-form-label">
|
||||
<span class="x-red">*</span>帐号
|
||||
</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" id="jiancheng" name="jiancheng" lay-verify="required"
|
||||
autocomplete="off" class="layui-input" value="{$list.data.jiancheng|default=''}" placeholder="中文1-6个字符">
|
||||
<input type="text" id="username" name="username" lay-verify="required"
|
||||
autocomplete="off" class="layui-input" value="{$list.data.username|default=''}" placeholder="由字母、数字-_组成 6-12个字符"
|
||||
{eq name="$list.set.formpost" value="PUT" }
|
||||
disabled
|
||||
{/eq}>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="biaoshi" class="layui-form-label">
|
||||
单位标识
|
||||
</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="input" id="biaoshi" name="biaoshi" lay-verify=""
|
||||
autocomplete="off" class="layui-input" value="{$list.data.biaoshi|default=''}" placeholder="数字">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="xingzhi" class="layui-form-label"><span class="x-red">*</span>单位性质</label>
|
||||
<div class="layui-input-block">
|
||||
{php} $category = getCategory(101);{/php}
|
||||
<select name="xingzhi" lay-verify="required">
|
||||
<option value=""></option>
|
||||
{volist name="category" id="vo"}
|
||||
<option value="{$vo.id}"
|
||||
{present name="$list.data.xingzhi"}
|
||||
{eq name="$list.data.xingzhi" value="$vo.id" }
|
||||
selected
|
||||
{/eq}
|
||||
{/present}>
|
||||
{$vo.title}
|
||||
</option>
|
||||
{/volist}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="jibie" class="layui-form-label"><span class="x-red">*</span>单位级别</label>
|
||||
<label for="school" class="layui-form-label"><span class="x-red">*</span>所在单位</label>
|
||||
<div class="layui-input-block">
|
||||
{php} $category = getCategory(102);{/php}
|
||||
<select name="jibie" lay-verify="required">
|
||||
{php} $schlist = schlist('校级','区级');{/php}
|
||||
<select name="school" lay-verify="required">
|
||||
<option value=""></option>
|
||||
{volist name="category" id="vo"}
|
||||
{volist name="schlist" id="vo"}
|
||||
<option value="{$vo.id}"
|
||||
{present name="$list.data.jibie"}
|
||||
{eq name="$list.data.jibie" value="$vo.id" }
|
||||
{present name="$list.data.school"}
|
||||
{eq name="$list.data.school" value="$vo.id" }
|
||||
selected
|
||||
{/eq}
|
||||
{/present}>
|
||||
@@ -68,33 +43,60 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="xueduan" class="layui-form-label">
|
||||
<span class="x-red">*</span>学段
|
||||
</label>
|
||||
<label for="group_id" class="layui-form-label"><span class="x-red">*</span>角色设置</label>
|
||||
<div class="layui-input-block">
|
||||
{php} $category = getCategory(103);{/php}
|
||||
<select name="xueduan" lay-verify="required">
|
||||
<option value=""></option>
|
||||
{volist name="category" id="vo"}
|
||||
<option value="{$vo.id}"
|
||||
{present name="$list.data.xueduan"}
|
||||
{eq name="$list.data.xueduan" value="$vo.id" }
|
||||
selected
|
||||
{/eq}
|
||||
{php}
|
||||
$authgroup = new \app\admin\model\AuthGroup;
|
||||
$authgrouplist = $authgroup->where('status',1)->select();
|
||||
{/php}
|
||||
{volist name="authgrouplist" id="vo"}
|
||||
<input type="checkbox" name="group_id[]" title="{$vo.title}" value="{$vo.id}" lay-skin="primary" {present name="$list.data.gl_group"}
|
||||
{volist name="list.data.gl_group" id="va"}
|
||||
{eq name="$va.title" value="$vo.title"}checked{/eq}
|
||||
{/volist}
|
||||
{/present}>
|
||||
{$vo.title}
|
||||
</option>
|
||||
{/volist}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="paixu" class="layui-form-label">
|
||||
排序
|
||||
<label for="sex" class="layui-form-label"><span class="x-red">*</span>性别</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="sex" value="1" title="男"
|
||||
{present name="$list.data.sex"}
|
||||
{$list.data.sex}
|
||||
{eq name="$list.data.sex" value="男" }
|
||||
checked
|
||||
{/eq}
|
||||
{/present}>
|
||||
<input type="radio" name="sex" value="0" title="女"
|
||||
{present name="$list.data.sex"}
|
||||
{eq name="list.data.sex" value="女" }
|
||||
checked
|
||||
{/eq}
|
||||
{/present}
|
||||
{notpresent name="$list.data.sex"}
|
||||
checked
|
||||
{/notpresent}
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="phone" class="layui-form-label">
|
||||
电话号码
|
||||
</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="input" id="paixu" name="paixu" lay-verify=""
|
||||
autocomplete="off" class="layui-input" value="999" placeholder="数字1-999">
|
||||
<input type="input" id="phone" name="phone" lay-verify=""
|
||||
autocomplete="off" class="layui-input" value="{$list.data.phone|default=''}" placeholder="数字">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label for="beizhu" class="layui-form-label">
|
||||
备注
|
||||
</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="input" id="beizhu" name="beizhu" lay-verify=""
|
||||
autocomplete="off" class="layui-input" value="" placeholder="">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item" style="text-align: right;">
|
||||
|
||||
@@ -25,17 +25,9 @@
|
||||
<label for="school" class="layui-form-label" style="height: 100%">学校</label>
|
||||
<div class="layui-input-block" onclick ="clickSearchButton('#search','mytable')">
|
||||
{php}
|
||||
$school = new \app\system\model\School;
|
||||
$schoollist = $school->where('status',1)
|
||||
->where('jibie','in',function($query){
|
||||
$query->name('category')
|
||||
->where('title','校级')
|
||||
->field('id');
|
||||
})
|
||||
->field('id,jiancheng')
|
||||
->select();
|
||||
$schoollist = schlist('校级','校级');
|
||||
{/php}
|
||||
<input type="radio" name="school" value="" title="无">
|
||||
<input type="radio" name="schoollist" value="" title="无">
|
||||
{volist name="schoollist" id="vo"}
|
||||
<input type="radio" name="school" title="{$vo.jiancheng}" value="{$vo.id}" lay-skin="primary">
|
||||
{/volist}
|
||||
|
||||
Reference in new issue
Block a user