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.

112 lines
3.2 KiB

8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
7 years ago
8 years ago
8 years ago
8 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
7 years ago
8 years ago
8 years ago
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Admin\CommonController;
  4. use DB;
  5. class UserController extends CommonController
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function index()
  12. {
  13. $posts = parent::pageList('admin_user');
  14. $data['posts'] = $posts;
  15. return view('admin.user.index', $data);
  16. }
  17. public function add()
  18. {
  19. $data['rolelist'] = object_to_array(DB::table('admin_user_role')->orderBy('listorder','desc')->get());
  20. return view('admin.user.add', $data);
  21. }
  22. public function doadd()
  23. {
  24. unset($_POST["_token"]);
  25. $_POST['pwd'] = md5($_POST['pwd']);
  26. if(DB::table('admin_user')->insert($_POST))
  27. {
  28. success_jump('添加成功!', route('admin_user'));
  29. }
  30. else
  31. {
  32. error_jump('添加失败!请修改后重新添加');
  33. }
  34. }
  35. public function edit()
  36. {
  37. if(!empty($_GET["id"])){$id = $_GET["id"];}else{$id="";}
  38. if(preg_match('/[0-9]*/',$id)){}else{exit;}
  39. $data['id'] = $id;
  40. $data['post'] = object_to_array(DB::table('admin_user')->where('id', $id)->first(), 1);
  41. $data['rolelist'] = object_to_array(DB::table('admin_user_role')->orderBy('listorder','desc')->get());
  42. return view('admin.user.edit', $data);
  43. }
  44. public function doedit()
  45. {
  46. if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else {$id="";exit;}
  47. unset($_POST["_token"]);
  48. $_POST['pwd'] = md5($_POST['pwd']);
  49. if(DB::table('admin_user')->where('id', $id)->update($_POST))
  50. {
  51. success_jump('修改成功!', route('admin_user'));
  52. }
  53. else
  54. {
  55. error_jump('修改失败!');
  56. }
  57. }
  58. //修改密码
  59. /* public function doedit()
  60. {
  61. if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else {$id="";exit;}
  62. unset($_POST["_token"]);
  63. if(!empty($_POST["username"])){$data['username'] = $map['username'] = $_POST["username"];}else{error_jump('用户名不能为空');exit;}//用户名
  64. if(!empty($_POST["oldpwd"])){$map['pwd'] = md5($_POST["oldpwd"]);}else{error_jump('旧密码错误');exit;}
  65. if($_POST["newpwd"]==$_POST["newpwd2"]){$data['pwd'] = md5($_POST["newpwd"]);}else{error_jump('密码错误');exit;}
  66. if($_POST["oldpwd"]==$_POST["newpwd"]){error_jump('新旧密码不能一致!');exit;}
  67. $User = object_to_array(DB::table("user")->where($map)->first(), 1);
  68. if($User)
  69. {
  70. if(DB::table('user')->where('id', $id)->update($data))
  71. {
  72. session_unset();
  73. session_destroy();
  74. success_jump('修改成功,请重新登录', route('admin_login'), 3);
  75. }
  76. }
  77. else
  78. {
  79. error_jump('修改失败!旧用户名或密码错误');
  80. }
  81. } */
  82. public function del()
  83. {
  84. if(!empty($_GET["id"])){$id = $_GET["id"];}else{error_jump('删除失败!请重新提交');}
  85. if(DB::table('admin_user')->whereIn("id", explode(',', $id))->delete())
  86. {
  87. success_jump('删除成功');
  88. }
  89. else
  90. {
  91. error_jump('删除失败!请重新提交');
  92. }
  93. }
  94. }