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.

90 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. use App\Http\Model\Slide;
  6. class SlideController extends CommonController
  7. {
  8. public function __construct()
  9. {
  10. parent::__construct();
  11. }
  12. public function index()
  13. {
  14. $data['posts'] = parent::pageList('slide', '', [['is_show', 'asc'], ['listorder', 'asc']]);
  15. if($data['posts'])
  16. {
  17. foreach($data['posts'] as $k=>$v)
  18. {
  19. $data['posts'][$k]->type_text = Slide::getTypeText(array('type'=>$v->type));
  20. }
  21. }
  22. return view('admin.slide.index', $data);
  23. }
  24. public function add()
  25. {
  26. return view('admin.slide.add');
  27. }
  28. public function doadd()
  29. {
  30. if(isset($_POST['editorValue'])){unset($_POST['editorValue']);}
  31. unset($_POST["_token"]);
  32. if(DB::table('slide')->insert(array_filter($_POST)))
  33. {
  34. success_jump('添加成功!', route('admin_slide'));
  35. }
  36. else
  37. {
  38. error_jump('添加失败!请修改后重新添加');
  39. }
  40. }
  41. public function edit()
  42. {
  43. if(!empty($_GET["id"])){$id = $_GET["id"];}else{$id="";}
  44. if(preg_match('/[0-9]*/',$id)){}else{exit;}
  45. $data['id'] = $id;
  46. $data['post'] = object_to_array(DB::table('slide')->where('id', $id)->first(), 1);
  47. return view('admin.slide.edit', $data);
  48. }
  49. public function doedit()
  50. {
  51. if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else{$id="";exit;}
  52. if(isset($_POST['editorValue'])){unset($_POST['editorValue']);}
  53. unset($_POST["_token"]);
  54. if(DB::table('slide')->where('id', $id)->update($_POST))
  55. {
  56. success_jump('修改成功!', route('admin_slide'));
  57. }
  58. else
  59. {
  60. error_jump('修改失败!');
  61. }
  62. }
  63. public function del()
  64. {
  65. if(!empty($_GET["id"])){$id = $_GET["id"];}else{error_jump('删除失败!请重新提交');}
  66. if(DB::table('slide')->whereIn("id", explode(',', $id))->delete())
  67. {
  68. success_jump('删除成功');
  69. }
  70. else
  71. {
  72. error_jump('删除失败!请重新提交');
  73. }
  74. }
  75. }