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.

87 lines
2.2 KiB

8 years ago
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Admin\CommonController;
  4. use DB;
  5. class SearchwordController extends CommonController
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function index()
  12. {
  13. $data['posts'] = parent::pageList('searchword');
  14. return view('admin.searchword.index', $data);
  15. }
  16. public function add()
  17. {
  18. return view('admin.searchword.add');
  19. }
  20. public function doadd()
  21. {
  22. $_POST['pubdate'] = time();//更新时间
  23. $_POST['click'] = rand(200,500);//点击
  24. unset($_POST["_token"]);
  25. if(isset($_POST['editorValue'])){unset($_POST['editorValue']);}
  26. if($insertId = DB::table('searchword')->insertGetId($_POST))
  27. {
  28. success_jump('添加成功!', route('admin_searchword'));
  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('searchword')->where('id',$id)->first(), 1);
  41. return view('admin.searchword.edit', $data);
  42. }
  43. public function doedit()
  44. {
  45. if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else{$id="";exit;}
  46. if(!empty($_POST["keywords"])){$_POST['keywords']=str_replace("",",",$_POST["keywords"]);}else{$_POST['keywords']="";}//关键词
  47. $_POST['pubdate'] = time();//更新时间
  48. unset($_POST["_token"]);
  49. if(isset($_POST['editorValue'])){unset($_POST['editorValue']);}
  50. if(DB::table('searchword')->where('id', $id)->update($_POST))
  51. {
  52. success_jump('修改成功!', route('admin_searchword'));
  53. }
  54. else
  55. {
  56. error_jump('修改失败!');
  57. }
  58. }
  59. public function del()
  60. {
  61. if(!empty($_GET["id"])){$id = $_GET["id"];}else{error_jump('删除失败!请重新提交');}
  62. if(DB::table("searchword")->whereIn("id", explode(',', $id))->delete())
  63. {
  64. success_jump('删除成功');
  65. }
  66. else
  67. {
  68. error_jump('删除失败!请重新提交');
  69. }
  70. }
  71. }