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.

135 lines
3.4 KiB

7 years ago
4 years ago
6 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
6 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use Illuminate\Support\Facades\DB;
  4. use App\Common\ReturnData;
  5. use Illuminate\Http\Request;
  6. class CategoryController extends BaseController
  7. {
  8. public function __construct()
  9. {
  10. parent::__construct();
  11. }
  12. public function index()
  13. {
  14. $catlist = category_tree(get_category('arctype',0));
  15. if($catlist)
  16. {
  17. foreach($catlist as $k=>$v)
  18. {
  19. $arctype = DB::table("arctype")->where('id', $v['id'])->first();
  20. $catlist[$k]['typedir'] = $arctype->typedir;
  21. $catlist[$k]['addtime'] = $arctype->addtime;
  22. }
  23. }
  24. $data['catlist'] = $catlist;
  25. return view('admin.category.index', $data);
  26. }
  27. public function add()
  28. {
  29. if(!empty($_GET["reid"]))
  30. {
  31. $id = $_GET["reid"];
  32. if(preg_match('/[0-9]*/',$id)){}else{exit;}
  33. if($id!=0)
  34. {
  35. $data['postone'] = object_to_array(DB::table("arctype")->where('id', $id)->first(), 1);
  36. }
  37. $data['id'] = $id;
  38. }
  39. else
  40. {
  41. $data['id'] = 0;
  42. }
  43. return view('admin.category.add', $data);
  44. }
  45. public function doadd()
  46. {
  47. if(!empty($_POST["prid"])){if($_POST["prid"]=="top"){$_POST['pid']=0;}else{$_POST['pid'] = $_POST["prid"];}}//父级栏目id
  48. $_POST['addtime'] = time();//添加时间
  49. unset($_POST["prid"]);
  50. unset($_POST["_token"]);
  51. if(isset($_POST['editorValue'])){unset($_POST['editorValue']);}
  52. if(DB::table('arctype')->insert($_POST))
  53. {
  54. success_jump('添加成功');
  55. }
  56. else
  57. {
  58. error_jump('添加失败!请修改后重新添加');
  59. }
  60. }
  61. public function edit()
  62. {
  63. $id = $_GET["id"];if(preg_match('/[0-9]*/',$id)){}else{exit;}
  64. $data['id'] = $id;
  65. $post = object_to_array(DB::table('arctype')->where('id', $id)->first(), 1);
  66. $reid = $post['pid'];
  67. if($reid!=0){$data['postone'] = object_to_array(DB::table('arctype')->where('id', $reid)->first());}
  68. $data['post'] = $post;
  69. return view('admin.category.edit', $data);
  70. }
  71. public function doedit()
  72. {
  73. if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else {$id="";exit;}
  74. $_POST['addtime'] = time(); //添加时间
  75. unset($_POST["_token"]);
  76. if(isset($_POST['editorValue'])){unset($_POST['editorValue']);}
  77. if(DB::table('arctype')->where('id', $id)->update($_POST))
  78. {
  79. success_jump('修改成功', route('admin_category'));
  80. }
  81. else
  82. {
  83. error_jump('修改失败!请修改后重新添加');
  84. }
  85. }
  86. public function del()
  87. {
  88. if(!empty($_REQUEST["id"])){$id = $_REQUEST["id"];}else{error_jump('删除失败!请重新提交');} //if(preg_match('/[0-9]*/',$id)){}else{exit;}
  89. if(DB::table('arctype')->where('pid', $id)->first())
  90. {
  91. error_jump('删除失败!请先删除子栏目');
  92. }
  93. else
  94. {
  95. if(DB::table('arctype')->where('id', $id)->delete())
  96. {
  97. if(DB::table("article")->where('typeid', $id)->count()>0) //判断该分类下是否有文章,如果有把该分类下的文章也一起删除
  98. {
  99. if(DB::table("article")->where('typeid', $id)->delete())
  100. {
  101. success_jump('删除成功');
  102. }
  103. else
  104. {
  105. error_jump('栏目下的文章删除失败');
  106. }
  107. }
  108. else
  109. {
  110. success_jump('删除成功');
  111. }
  112. }
  113. else
  114. {
  115. error_jump('删除失败!请重新提交');
  116. }
  117. }
  118. }
  119. }