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.

97 lines
2.9 KiB

7 years ago
4 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
6 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Admin\CommonController;
  4. use Illuminate\Support\Facades\DB;
  5. use App\Http\Model\UserRank;
  6. use App\Common\Helper;
  7. class UserRankController extends BaseController
  8. {
  9. public function __construct()
  10. {
  11. parent::__construct();
  12. }
  13. public function index()
  14. {
  15. $data['posts'] = parent::pageList('user_rank', '', [['listorder', 'asc']]);
  16. if($data['posts'])
  17. {
  18. foreach($data['posts'] as $k=>$v)
  19. {
  20. }
  21. }
  22. return view('admin.userrank.index', $data);
  23. }
  24. public function add()
  25. {
  26. if(Helper::isPostRequest())
  27. {
  28. if(isset($_POST['editorValue'])){unset($_POST['editorValue']);}
  29. unset($_POST["_token"]);
  30. if(DB::table('user_rank')->where('rank', $_POST["rank"])->first()){error_jump('等级已经存在');}
  31. if(DB::table('user_rank')->where('title', $_POST["title"])->first()){error_jump('等级名称已经存在');}
  32. if(DB::table('user_rank')->insert(array_filter($_POST)))
  33. {
  34. success_jump('添加成功', route('admin_userrank'));
  35. }
  36. else
  37. {
  38. error_jump('添加失败!请修改后重新添加');
  39. }
  40. }
  41. return view('admin.userrank.add');
  42. }
  43. public function edit()
  44. {
  45. if(Helper::isPostRequest())
  46. {
  47. if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else{$id="";exit;}
  48. if(isset($_POST['editorValue'])){unset($_POST['editorValue']);}
  49. unset($_POST["_token"]);
  50. if(DB::table('user_rank')->where(['rank'=>$_POST["rank"],'id'=>['<>',$id]])->first()){error_jump('等级已经存在');}
  51. if(DB::table('user_rank')->where(['title'=>$_POST["title"],'id'=>['<>',$id]])->first()){error_jump('等级名称已经存在');}
  52. if(DB::table('user_rank')->where('id', $id)->update($_POST) !== false)
  53. {
  54. success_jump('修改成功', route('admin_userrank'));
  55. }
  56. else
  57. {
  58. error_jump('修改失败');
  59. }
  60. }
  61. if(!empty($_GET["id"])){$id = $_GET["id"];}else{$id="";}
  62. if(preg_match('/[0-9]*/',$id)){}else{exit;}
  63. $data['id'] = $id;
  64. $data['post'] = object_to_array(DB::table('user_rank')->where('id', $id)->first(), 1);
  65. return view('admin.userrank.edit', $data);
  66. }
  67. public function del()
  68. {
  69. if(!empty($_GET["id"])){$id = $_GET["id"];}else{error_jump('删除失败!请重新提交');}
  70. if(DB::table('user_rank')->whereIn("id", explode(',', $id))->delete())
  71. {
  72. success_jump('删除成功');
  73. }
  74. else
  75. {
  76. error_jump('删除失败!请重新提交');
  77. }
  78. }
  79. }