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.

142 lines
4.1 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use DB;
  4. use App\Common\Helper;
  5. use App\Common\ReturnData;
  6. use Illuminate\Http\Request;
  7. use App\Http\Logic\AdminLogic;
  8. use App\Http\Model\Admin;
  9. class AdminController extends CommonController
  10. {
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. public function getLogic()
  16. {
  17. return new AdminLogic();
  18. }
  19. public function index(Request $request)
  20. {
  21. $res = '';
  22. $where = function ($query) use ($res) {
  23. if(isset($_REQUEST["keyword"]))
  24. {
  25. $query->where('username', 'like', '%'.$_REQUEST['keyword'].'%');
  26. }
  27. if(isset($_REQUEST["role_id"]))
  28. {
  29. $query->where('role_id', $_REQUEST["role_id"]);
  30. }
  31. if(isset($_REQUEST["status"]))
  32. {
  33. $query->where('status', $_REQUEST["status"]);
  34. }
  35. };
  36. $posts = $this->getLogic()->getPaginate($where, array('id', 'desc'));
  37. $data['posts'] = $posts;
  38. return view('admin.admin.index', $data);
  39. }
  40. public function add(Request $request)
  41. {
  42. $data['rolelist'] = logic('AdminRole')->getAll('', ['listorder','asc']);
  43. return view('admin.admin.add', $data);
  44. }
  45. public function doadd(Request $request)
  46. {
  47. if(Helper::isPostRequest())
  48. {
  49. $_POST['pwd'] = md5($_POST['pwd']);
  50. $res = $this->getLogic()->add($_POST);
  51. if($res['code'] == ReturnData::SUCCESS)
  52. {
  53. success_jump($res['msg'], route('admin_admin'));
  54. }
  55. error_jump($res['msg']);
  56. }
  57. }
  58. public function edit(Request $request)
  59. {
  60. if(!checkIsNumber($request->input('id',null))){error_jump('参数错误');}
  61. $id = $request->input('id');
  62. $data['id'] = $where['id'] = $id;
  63. $data['post'] = $this->getLogic()->getOne($where);
  64. $data['rolelist'] = logic('AdminRole')->getAll('', ['listorder','asc']);
  65. return view('admin.admin.edit', $data);
  66. }
  67. public function doedit(Request $request)
  68. {
  69. if(!checkIsNumber($request->input('id',null))){error_jump('参数错误');}
  70. $id = $request->input('id');
  71. if(Helper::isPostRequest())
  72. {
  73. $_POST['pwd'] = md5($_POST['pwd']);
  74. $where['id'] = $id;
  75. $res = $this->getLogic()->edit($_POST, $where);
  76. if($res['code'] == ReturnData::SUCCESS)
  77. {
  78. success_jump($res['msg'], route('admin_admin'));
  79. }
  80. error_jump($res['msg']);
  81. }
  82. }
  83. //修改密码
  84. /* public function doedit()
  85. {
  86. if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else {$id="";exit;}
  87. unset($_POST["_token"]);
  88. if(!empty($_POST["username"])){$data['username'] = $map['username'] = $_POST["username"];}else{error_jump('用户名不能为空');exit;}//用户名
  89. if(!empty($_POST["oldpwd"])){$map['pwd'] = md5($_POST["oldpwd"]);}else{error_jump('旧密码错误');exit;}
  90. if($_POST["newpwd"]==$_POST["newpwd2"]){$data['pwd'] = md5($_POST["newpwd"]);}else{error_jump('密码错误');exit;}
  91. if($_POST["oldpwd"]==$_POST["newpwd"]){error_jump('新旧密码不能一致');exit;}
  92. $User = object_to_array(DB::table("admin")->where($map)->first(), 1);
  93. if($User)
  94. {
  95. if(DB::table('admin')->where('id', $id)->update($data))
  96. {
  97. session_unset();
  98. session_destroy();
  99. success_jump('修改成功,请重新登录', route('admin_login'), 3);
  100. }
  101. }
  102. else
  103. {
  104. error_jump('修改失败!旧用户名或密码错误');
  105. }
  106. } */
  107. public function del(Request $request)
  108. {
  109. if(!checkIsNumber($request->input('id',null))){error_jump('参数错误');}
  110. $id = $request->input('id');
  111. $where['id'] = $id;
  112. $res = $this->getLogic()->del($where);
  113. if($res['code'] == ReturnData::SUCCESS)
  114. {
  115. success_jump($res['msg']);
  116. }
  117. error_jump($res['msg']);
  118. }
  119. }