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.

91 lines
2.2 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
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Admin\CommonController;
  4. use DB;
  5. class MenuController extends CommonController
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function index()
  12. {
  13. $posts = parent::pageList('menu');
  14. $data['posts'] = $posts;
  15. return view('admin.menu.index', $data);
  16. }
  17. public function add()
  18. {
  19. if(!empty($_GET["pid"])){$pid = $_GET["pid"];}else{$pid=0;}
  20. $data['pid'] = $pid;
  21. $data['menu'] = category_tree(get_category('menu',0));
  22. return view('admin.menu.add', $data);
  23. }
  24. public function doadd()
  25. {
  26. unset($_POST["_token"]);
  27. $menuid = DB::table('menu')->insertGetId($_POST);
  28. if($menuid)
  29. {
  30. DB::table('access')->insert(['role_id' => 1, 'menu_id' => $menuid]);
  31. success_jump('添加成功!', route('admin_menu'));
  32. }
  33. else
  34. {
  35. error_jump('添加失败!请修改后重新添加');
  36. }
  37. }
  38. public function edit()
  39. {
  40. if(!empty($_GET["id"])){$id = $_GET["id"];}else{$id="";}
  41. if(preg_match('/[0-9]*/',$id)){}else{exit;}
  42. $data['id'] = $id;
  43. $data['post'] = object_to_array(DB::table('menu')->where('id', $id)->first(), 1);
  44. $data['menu'] = category_tree(get_category('menu',0));
  45. return view('admin.menu.edit', $data);
  46. }
  47. public function doedit()
  48. {
  49. if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else {$id="";exit;}
  50. unset($_POST["_token"]);
  51. if(DB::table('menu')->where('id', $id)->update($_POST))
  52. {
  53. success_jump('修改成功!', route('admin_menu'));
  54. }
  55. else
  56. {
  57. error_jump('修改失败!');
  58. }
  59. }
  60. public function del()
  61. {
  62. if(!empty($_GET["id"])){$id = $_GET["id"];}else{error_jump('删除失败!请重新提交');}
  63. if(DB::table('menu')->whereIn("id", explode(',', $id))->delete())
  64. {
  65. DB::table('access')->where('role_id', 1)->whereIn("menu_id", explode(',', $id))->delete();
  66. success_jump('删除成功');
  67. }
  68. else
  69. {
  70. error_jump('删除失败!请重新提交');
  71. }
  72. }
  73. }