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.

83 lines
2.2 KiB

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. class GoodsBrandController extends CommonController
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function index()
  12. {
  13. $data['posts'] = object_to_array(DB::table("goods_brand")->select('id', 'add_time', 'title', 'litpic', 'status', 'listorder', 'cover_img', 'click')->orderBy('id', 'desc')->get());
  14. return view('admin.GoodsBrand.index', $data);
  15. }
  16. public function doadd()
  17. {
  18. $_POST['add_time'] = time();//更新时间
  19. $_POST['click'] = rand(200,500);//点击
  20. unset($_POST["_token"]);
  21. if(isset($_POST['editorValue'])){unset($_POST['editorValue']);}
  22. if(DB::table("goods_brand")->insert($_POST))
  23. {
  24. success_jump('添加成功!', route('admin_goodsbrand'));
  25. }
  26. else
  27. {
  28. error_jump('添加失败!请修改后重新添加');
  29. }
  30. }
  31. public function add()
  32. {
  33. return view('admin.GoodsBrand.add');
  34. }
  35. public function edit()
  36. {
  37. if(!empty($_GET["id"])){$id = $_GET["id"];}else{$id="";}
  38. if(preg_match('/[0-9]*/',$id)){}else{exit;}
  39. $data['id'] = $id;
  40. $data['post'] = object_to_array(DB::table('goods_brand')->where('id', $id)->first(), 1);
  41. return view('admin.GoodsBrand.edit', $data);
  42. }
  43. public function doedit()
  44. {
  45. if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else {$id="";exit;}
  46. unset($_POST["_token"]);
  47. if(isset($_POST['editorValue'])){unset($_POST['editorValue']);}
  48. if(DB::table('goods_brand')->where('id', $id)->update($_POST))
  49. {
  50. success_jump('修改成功!', route('admin_goodsbrand'));
  51. }
  52. else
  53. {
  54. error_jump('修改失败!请修改后重新添加');
  55. }
  56. }
  57. public function del()
  58. {
  59. if(!empty($_GET["id"])){$id = $_GET["id"];}else{error_jump("删除失败!请重新提交");} //if(preg_match('/[0-9]*/',$id)){}else{exit;}
  60. if(DB::table('goods_brand')->whereIn("id", explode(',', $id))->delete())
  61. {
  62. success_jump('删除成功');
  63. }
  64. else
  65. {
  66. error_jump("删除失败!请重新提交");
  67. }
  68. }
  69. }