diff --git a/application/admin/controller/Index.php b/application/admin/controller/Index.php index fbae6e43..69bfed7a 100644 --- a/application/admin/controller/Index.php +++ b/application/admin/controller/Index.php @@ -57,7 +57,7 @@ class Index extends Base //查询数据 $data = $admin - ->field('id,xingming,sex,username,phone,denglucishu,status,create_time') + ->field('id,xingming,sex,username,phone,shengri,denglucishu,status,create_time') ->where('id','>','1') ->order([$order_field=>$order]) ->limit($limit_start,$limit_length) @@ -68,7 +68,7 @@ class Index extends Base // 如果需要查询 if($search){ $data = $admin - ->field('id,xingming,sex,username,phone,denglucishu,status,create_time') + ->field('id,xingming,sex,username,phone,shengri,denglucishu,status,create_time') ->where('id','>','1') ->order([$order_field=>$order]) ->limit($limit_start,$limit_length) @@ -128,9 +128,9 @@ class Index extends Base if($data == 1) { - $data =['msg'=>'添加成功']; + $data =['msg'=>'添加成功','val'=>1]; }else{ - $data =['msg'=>'数据处理错误']; + $data =['msg'=>'数据处理错误','val'=>0]; } @@ -194,4 +194,31 @@ class Index extends Base { // } + + + // 修改管理员状态 + public function setStatus() + { + // 实例化管理员数据模型类 + $admin = new Admin(); + + // 获取id变量 + $id = request()->post('id'); + $value = request()->post('value'); + + // 获取管理员信息 + $list = $admin->get($id); + + // 修改状态值 + $list->status = $value; + + // 更新数据 + $data = $list->save(); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'操作成功'] : $data=['msg'=>'数据处理错误']; + + // 返回信息 + return json($data); + } } diff --git a/application/admin/model/Admin.php b/application/admin/model/Admin.php index a8e75ee2..f2798bcb 100644 --- a/application/admin/model/Admin.php +++ b/application/admin/model/Admin.php @@ -23,4 +23,32 @@ class Admin extends Model { return strtotime($value); } + + // 生日获取器 + public function getShengriAttr($value) + { + return date('Y-m-d',$value); + } + + // 创建时间获取器 + public function getCreateTimeAttr($value) + { + return date('Y-m-d',$value); + } + + // 性别获取器 + public function getSexAttr($value) + { + $sex = array('0'=>'女','1'=>'男','2'=>'保密'); + return $sex[$value]; + } + + // 状态获取器 + public function getStatusAttr($value) + { + $status =array('1'=>'已启用','0'=>'已停用'); + return $status[$value]; + } + + } diff --git a/application/admin/view/index/create.html b/application/admin/view/index/create.html index d4fc1d39..7ced0de2 100644 --- a/application/admin/view/index/create.html +++ b/application/admin/view/index/create.html @@ -1,6 +1,6 @@ {extend name="common@create" /} {block name="formaa"} -
+
@@ -46,7 +46,7 @@
-

10/80

+

0/80

@@ -81,7 +81,7 @@ username:{ required:true, ustr:true, - rangelength:[5,12] + rangelength:[5,20] }, sex:{ required:true, @@ -92,9 +92,6 @@ phone:{ isMobile:true, }, - beizhu:{ - rangelength:[10,80] - }, }; {/block} \ No newline at end of file diff --git a/application/admin/view/index/index.html b/application/admin/view/index/index.html index 97d4246f..dd5f8374 100644 --- a/application/admin/view/index/index.html +++ b/application/admin/view/index/index.html @@ -21,7 +21,7 @@ 批量删除 - + 添加管理员 @@ -37,7 +37,8 @@ Name 姓名 - 姓别 + 性别 + 出生日期 帐号 手机号码 登录次数 @@ -57,9 +58,9 @@ // 定义DTajax参数 var myajax = { - "url": "{:url('ajaxdata')}", - "type": "post", - "data": { + url: "{:url('ajaxdata')}", + type: "post", + data: { 'username':'usernames', 'pas':'pas' }, @@ -70,6 +71,7 @@ { "data": "id" }, { "data": "xingming" }, { "data": "sex" }, + { "data": "shengri" }, { "data": "username" }, { "data": "phone" }, { "data": "denglucishu" }, @@ -82,20 +84,48 @@ var mycolumnDefs =[ // 对象格式 { - "targets": 0, + "targets": 0, "render": function(data, type, row, meta) { return '' } }, { "targets": -1, + "className":'.td-manage', "render": function(data, type, row, meta) { - return '\ - \ - \ - '; + // 停用按钮 + stopbut = ''; + // 启用按钮 + startbut = ''; + // 详细信息按钮 + readbut = ''; + // 编辑按钮 + editbut = ''; + delbut = ''; + if(row.status == '已停用') + { + buts = startbut + readbut + editbut + delbut; + }else{ + buts = stopbut + readbut + editbut + delbut; + } + + return buts; } }, + { + "targets": -2, + "className":'.td-status', + "render": function(data, type, row, meta) { + if(row.status == '已停用') + { + d = "" + row.status + ""; + }else{ + d = "" + row.status + ""; + } + + return d; + }, + }, { "orderable": false, "targets": [0,-1] diff --git a/application/common/view/create.html b/application/common/view/create.html index 177e06d5..e2484d26 100644 --- a/application/common/view/create.html +++ b/application/common/view/create.html @@ -62,22 +62,16 @@ $(function(){ success:"valid", submitHandler:function(form){ - $(form).ajaxSubmit( - - { - dataType: "json", - success: function(data){ - layer.alert(data.msg); - - }, - error: function(data){ - layer.alert('保存信息失败'); - } - } - ); - var index = parent.layer.getFrameIndex(window.name); - //parent.$('.btn-refresh').click(); - // parent.layer.close(index); + $(form).ajaxSubmit({ + dataType: "json", + success: function(data){ + layer.alert(data.msg); + window.parent.location.reload(); + }, + error: function(data){ + layer.alert('保存信息失败'); + } + }); } }); }); diff --git a/application/common/view/list.html b/application/common/view/list.html index f4a547a8..c9a0d184 100644 --- a/application/common/view/list.html +++ b/application/common/view/list.html @@ -97,7 +97,7 @@ // renderer: "display", //渲染样式:Bootstrap和jquery-ui // pagingType: "simple_numbers", //分页样式:simple,simple_numbers,full,full_numbers order: [ - [ 1, 'desc' ] + [ 0, 'desc' ] ], //option显示数量 aLengthMenu: [[20, 50, 100, 500], [20, 50, 100, 500]], @@ -134,12 +134,15 @@ function stop(obj,id){ layer.confirm('确认要停用吗?',function(index){ $.ajax({ type: 'POST', - url: '', + url: "{:url('setstatus')}", dataType: 'json', + data:{ + id:id, + value: 0, + }, success: function(data){ - $(obj).parents("tr").find(".td-manage").prepend(''); - $(obj).parents("tr").find(".td-status").html('已停用'); - $(obj).remove(); + $(obj).html(''); + $(obj).parents("tr").find("span").parents("td").html('已停用'); layer.msg('已停用!',{icon: 5,time:1000}); }, error:function(data) { @@ -154,12 +157,15 @@ function start(obj,id){ layer.confirm('确认要启用吗?',function(index){ $.ajax({ type: 'POST', - url: '', + url: "{:url('setstatus')}", dataType: 'json', + data:{ + id:id, + value: 1, + }, success: function(data){ - $(obj).parents("tr").find(".td-manage").prepend(''); - $(obj).parents("tr").find(".td-status").html('已启用'); - $(obj).remove(); + $(obj).html(''); + $(obj).parents("tr").find("span").parents("td").html('已启用'); layer.msg('已启用!',{icon: 6,time:1000}); }, error:function(data) { diff --git a/database/migrations/20181012140355_member.php b/database/migrations/20181012140355_member.php index ed5fc1fb..8f5430ad 100644 --- a/database/migrations/20181012140355_member.php +++ b/database/migrations/20181012140355_member.php @@ -36,7 +36,7 @@ class Member extends Migrator ->addColumn('xingming','string',['limit'=>15,'null'=>false,'comment'=>'用户姓名']) ->addColumn('sex','boolean',['limit'=>1,'default'=>'2','null'=>false,'comment'=>'0=女,1=男,2=未知']) ->addColumn('shengri','integer',['limit'=>11,'null'=>true,'comment'=>'出生日期']) - ->addColumn('username','string',['limit'=>12,'null'=>false,'comment'=>'用户帐号']) + ->addColumn('username','string',['limit'=>20,'null'=>false,'comment'=>'用户帐号']) ->addColumn('password','string',['limit'=>37,'null'=>false,'comment'=>'登录密码']) ->addColumn('phone','string',['limit'=>11,'null'=>true,'comment'=>'联系方式']) ->addColumn('denglucishu','integer',['limit'=>5,'default'=>0,'null'=>false,'comment'=>'登录次数'])