Blogger Information
Blog 70
fans 4
comment 5
visits 103759
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP:【商城后台管理系统】部署管理员列表,添加/编辑/删除功能
JiaJieChen
Original
1590 people have browsed it

PHP:【商城后台管理系统】部署管理员列表,添加/编辑/删除功能

请点击->友情连接在线测试后台管理页面

一.管理员列表界面


二.部署流程

  1. 部署流程
    • thinkphp:使用thinkphp6.0 ,在数据库表里每个管理员都有相对应的id字段,我们点击编辑的时候,会自动获取管理员id字段,进行判断点击的是哪个管理员,当我们修改信息的时候,会判断所填的信息是否为空,如果不为空则添加或修改成功,会默认给一个修改和添加时间,删除就是判断当前点击的管理员字段id,进行where条件查找,然后进行删除

HTML 代码块

       
  1. lang="en">
  2. charset="UTF-8">
  3. http-equiv="X-UA-Compatible"content="IE=edge">
  4. name="viewport"content="width=device-width, initial-scale=1.0">
  5. </span><span class="pln">管理员账号列表</span><span class="tag">
  6. rel="stylesheet"href="/static/layui-v2.6.8/layui/css/layui.css"/>
  7. src="/static/layui-v2.6.8/layui/layui.js">
  8. style="padding:10px;min-width:737px">
  9. class="layui-item">
  10. style="color:#777;font-size:20px;height:30px;line-height:30px">首页/
  11. style="color:#ccc">管理员列表
  12. class="layui-btn layui-btn-sm"style="float:right;margin:5px"onclick="add()">添加
  • class="layui-table">
  • ID
  • 用户名
  • 管理员级别
  • 真实姓名
  • 注册时间
  • 状态
  • 编辑
  • {foreach $admin as $v}
  • {$v['id']}
  • {$v['username']}
  • {$v['gid']}
  • {$v['truename']}
  • {:date('Y-m-d H:i:s',$v['add_time'])}
  • style="color:{$v['status']==0?'green':'red'};">
  • {$v['status']==0 ? '开启' : '关闭'}
  • class="layui-btn layui-btn-sm "onclick="edit({$v['id']})">编辑
  • class="layui-btn layui-btn-sm layui-btn-danger"onclick="dle({$v['id']})">删除
  • {/foreach}
  • PHP 代码块

           
    1. php
    2. namespaceapp\admin\controller;
    3. useapp\admin\controller\Base;
    4. usethink\facade\Request;
    5. usethink\facade\Db;
    6. usethink\facade\View;
    7. usethink\facade\Session;
    8. /**
    9. * 管理员账号管理
    10. */
    11. classAdminextendsBase
    12. {
    13. //账号列表
    14. publicfunctionindex()
    15. {
    16. //获取信息 渲染到账号列表
    17. $admin=Db::table('admin a')
    18. ->select()
    19. ->toArray();
    20. //管理员角色
    21. $group=Db::table('admin_group')->field(['gid','title'])->select()->toArray();
    22. foreach($adminas$key=>$av){
    23. $admin[$key]['gid']='';
    24. foreach($groupas$gv){
    25. if($av['gid']==$gv['gid']){
    26. $admin[$key]['gid']=$gv['title'];
    27. break;
    28. }
    29. }
    30. }
    31. View::assign([
    32. 'admin'=>$admin
    33. ]);
    34. returnView('/admin/index');
    35. }
    36. //管理员编辑
    37. publicfunctionedit()
    38. {
    39. $aid=(int)Request::get('aid');
    40. $user=Db::table('admin')->where('id',$aid)->find();
    41. $group=$group=Db::table('admin_group')->field(['gid','title'])->select();
    42. View::assign([
    43. 'user'=>$user,
    44. 'group'=>$group,
    45. 'aid'=>$aid
    46. ]);
    47. returnView('/admin/edit');
    48. }
    49. //管理员添加页面
    50. publicfunctionadd()
    51. {
    52. $group=$group=Db::table('admin_group')->field(['gid','title'])->select();
    53. View::assign([
    54. 'group'=>$group,
    55. ]);
    56. returnView('/admin/add');
    57. }
    58. //添加管理员信息
    59. publicfunctionadd_user()
    60. {
    61. //管理员信息接收
    62. $data['username']=Request::post('username');
    63. $data['password']=md5($data['username'].Request::post('password'));
    64. $data['gid']=Request::post('gid');
    65. $data['truename']=Request::post('truename');
    66. $data['add_time']=time();
    67. $data['lastlogin']=time();
    68. $data['status']=Request::post('status');
    69. $data['phone']=Request::post('phone','');
    70. //查询是否有此管理员
    71. if(!empty($data)){
    72. $find=Db::table('admin')->where('username',$data['username'])->field('username')->find();
    73. }
    74. //添加管理员
    75. if(!empty($find)){
    76. exit(json_encode(['id'=>0,"msg"=>'该用户名已存在']));
    77. }else{
    78. if(!empty($data)){
    79. $insert=Db::table('admin')->insert($data);
    80. }
    81. }
    82. if(!empty($insert)){
    83. exit(json_encode(['id'=>1,"msg"=>'添加成功']));
    84. }else{
    85. exit(json_encode(['id'=>0,"msg"=>'添加失败']));
    86. }
    87. }
    88. //管理员账号修改
    89. publicfunctionedit_user()
    90. {
    91. //管理员信息接收
    92. $id=Request::param('aid');
    93. $data['username']=Request::post('username');
    94. $data['password']=md5($data['username'].Request::post('password'));
    95. $data['gid']=Request::post('gid');
    96. $data['truename']=Request::post('truename');
    97. $data['lastlogin']=time();
    98. $data['status']=Request::post('status');
    99. if(!empty($data)){
    100. //更新管理员信息
    101. $update=Db::table("admin")->where('id',$id)->update($data);
    102. }
    103. if(!empty($update)){
    104. echo json_encode(['id'=>1,'msg'=>'修改成功']);
    105. }else{
    106. echo json_encode(['id'=>0,'msg'=>'修改失败']);
    107. }
    108. }
    109. //管理员删除
    110. publicfunctiondle()
    111. {
    112. $aid=Request::param("aid");
    113. if(!empty($aid)){
    114. $delete=Db::table("admin")->where('id',$aid)->delete();
    115. }
    116. if(!empty($delete)){
    117. echo json_encode(['id'=>1,'msg'=>'删除成功']);
    118. }else{
    119. echo json_encode(['id'=>0,'msg'=>'删除失败']);
    120. }
    121. }
    122. }
    Statement of this Website
    The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
    All comments Speak rationally on civilized internet, please comply withNews Comment Service Agreement
    0 comments
    Author's latest blog post
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!