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.

91 lines
2.4 KiB

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