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.

106 lines
2.6 KiB

7 years ago
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Admin\CommonController;
  4. use DB;
  5. class SysconfigController extends CommonController
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function index()
  12. {
  13. $data['posts'] = parent::pageList('sysconfig', '', ['id', 'desc']);
  14. return view('admin.sysconfig.index', $data);
  15. }
  16. //添加参数,视图
  17. public function add()
  18. {
  19. return view('admin.sysconfig.add');
  20. }
  21. public function doadd()
  22. {
  23. //参数名称
  24. if(!empty($_POST["varname"]))
  25. {
  26. if(!preg_match("/^CMS_[a-z]+$/i", $_POST["varname"]))
  27. {
  28. error_jump('添加失败!参数名称不正确');exit;
  29. }
  30. }
  31. else
  32. {
  33. error_jump('添加失败!参数名称不能为空');exit;
  34. }
  35. unset($_POST["_token"]);
  36. if($_POST['varname']!="" && DB::table('sysconfig')->insert($_POST))
  37. {
  38. cache()->forget('sysconfig'); //删除缓存
  39. success_jump('添加成功!', route('admin_sysconfig'));
  40. }
  41. else
  42. {
  43. error_jump('添加失败!请修改后重新添加');
  44. }
  45. }
  46. //修改参数,视图
  47. public function edit()
  48. {
  49. if(!empty($_REQUEST["id"])){$id = $_REQUEST["id"];}else{$id="";}
  50. if(preg_match('/[0-9]*/',$id)){}else{exit;}
  51. $data['id'] = $id;
  52. $data['post'] = object_to_array(DB::table('sysconfig')->where('id', $id)->first(), 1);
  53. return view('admin.sysconfig.edit', $data);
  54. }
  55. public function doedit()
  56. {
  57. if(isset($_POST["id"]) && !empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else{$id="";exit;}
  58. //参数名称
  59. if(!empty($_POST["varname"]))
  60. {
  61. if(!preg_match("/^CMS_[a-z]+$/i", $_POST["varname"]))
  62. {
  63. error_jump('更新失败!参数名称不正确');exit;
  64. }
  65. }
  66. else
  67. {
  68. error_jump('更新失败!参数名称不能为空');exit;
  69. }
  70. unset($_POST["_token"]);
  71. if(DB::table('sysconfig')->where('id', $id)->update($_POST))
  72. {
  73. cache()->forget('sysconfig'); //删除缓存
  74. success_jump('更新成功!', route('admin_sysconfig'));
  75. }
  76. else
  77. {
  78. error_jump('更新失败!请修改后重新提交');
  79. }
  80. }
  81. public function del()
  82. {
  83. if(!empty($_REQUEST["id"])){$id = $_REQUEST["id"];}else{error_jump('删除失败!请重新提交');}
  84. if(DB::table("sysconfig")->whereIn("id", explode(',', $id))->delete())
  85. {
  86. success_jump('删除成功');
  87. }
  88. else
  89. {
  90. error_jump('删除失败!请重新提交');
  91. }
  92. }
  93. }