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.

112 lines
3.0 KiB

4 years ago
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use Illuminate\Support\Facades\DB;
  4. use App\Common\Helper;
  5. use App\Common\ReturnData;
  6. use Illuminate\Http\Request;
  7. use App\Http\Logic\AdLogic;
  8. use App\Http\Model\Ad;
  9. class AdController extends BaseController
  10. {
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. public function getLogic()
  16. {
  17. return new AdLogic();
  18. }
  19. public function index(Request $request)
  20. {
  21. $res = '';
  22. $where = function ($query) use ($res) {
  23. if(isset($_REQUEST["keyword"]))
  24. {
  25. $query->where('name', 'like', '%'.$_REQUEST['keyword'].'%');
  26. }
  27. };
  28. $list = $this->getLogic()->getPaginate($where, array('id', 'desc'));
  29. $data['list'] = $list;
  30. return view('admin.ad.index', $data);
  31. }
  32. public function add(Request $request)
  33. {
  34. if(Helper::isPostRequest())
  35. {
  36. if ($_POST['start_time'] && $_POST['end_time']) {
  37. $_POST['start_time'] = strtotime($_POST['start_time']);
  38. $_POST['end_time'] = strtotime($_POST['end_time']);
  39. }
  40. $res = $this->getLogic()->add($_POST);
  41. if($res['code'] == ReturnData::SUCCESS)
  42. {
  43. success_jump($res['msg'], route('admin_ad'));
  44. }
  45. error_jump($res['msg']);
  46. }
  47. return view('admin.ad.add');
  48. }
  49. public function edit(Request $request)
  50. {
  51. if(!checkIsNumber($request->input('id',null))){error_jump('参数错误');}
  52. $id = $request->input('id');
  53. if(Helper::isPostRequest())
  54. {
  55. if ($_POST['start_time'] && $_POST['end_time']) {
  56. $_POST['start_time'] = strtotime($_POST['start_time']);
  57. $_POST['end_time'] = strtotime($_POST['end_time']);
  58. }
  59. $where['id'] = $id;
  60. $res = $this->getLogic()->edit($_POST, $where);
  61. if($res['code'] == ReturnData::SUCCESS)
  62. {
  63. success_jump($res['msg'], route('admin_ad'));
  64. }
  65. error_jump($res['msg']);
  66. }
  67. $data['id'] = $where['id'] = $id;
  68. $post = $this->getLogic()->getOne($where);
  69. //时间戳转日期格式
  70. if ($post->start_time > 0) {
  71. $post->start_time = date('Y-m-d H:i:s', $post->start_time);
  72. } else {
  73. $post['start_time'] = '';
  74. }
  75. if ($post->end_time > 0) {
  76. $post->end_time = date('Y-m-d H:i:s', $post->end_time);
  77. } else {
  78. $post->end_time = '';
  79. }
  80. $data['post'] = $post;
  81. return view('admin.ad.edit', $data);
  82. }
  83. public function del(Request $request)
  84. {
  85. if(!checkIsNumber($request->input('id',null))){error_jump('参数错误');}
  86. $id = $request->input('id');
  87. $where['id'] = $id;
  88. $res = $this->getLogic()->del($where);
  89. if($res['code'] != ReturnData::SUCCESS)
  90. {
  91. error_jump($res['msg']);
  92. }
  93. success_jump($res['msg']);
  94. }
  95. }