News.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\home\controller;
  3. use app\common\model\RecruitNewsModel;
  4. use app\home\HomeBaseController;
  5. class News extends HomeBaseController
  6. {
  7. protected function init()
  8. {
  9. $this->tab = 'news';
  10. }
  11. public function index()
  12. {
  13. $keyword = input('keyword', '');
  14. $limit = 10;
  15. $where = [
  16. ['status', '=', RecruitNewsModel::STATUS_PUBLISH],
  17. ['title', 'like', "%$keyword%"],
  18. ];
  19. $total = RecruitNewsModel::where($where)
  20. ->count();
  21. return view('', [
  22. 'keyword' => $keyword,
  23. 'total' => $total,
  24. 'limit' => $limit,
  25. ]);
  26. }
  27. public function list()
  28. {
  29. $page = input('page', 1);
  30. $limit = input('limit', 10);
  31. $keyword = input('keyword', '');
  32. $where = [
  33. ['status', '=', RecruitNewsModel::STATUS_PUBLISH],
  34. ];
  35. if (!empty($keyword)) {
  36. $where[] = ['title', 'like', "%$keyword%"];
  37. }
  38. $list = RecruitNewsModel::with(['recruit'])
  39. ->where($where)
  40. ->page($page, $limit)
  41. ->order(['priority' => 'desc', 'update_time' => 'desc'])
  42. ->append(['summary', 'update_show'])
  43. ->select();
  44. ajax_success($list);
  45. }
  46. public function detail()
  47. {
  48. $id = input('id', 0);
  49. if (empty($id)) {
  50. jump('该招聘公告不存在或已经删除');
  51. }
  52. $info = RecruitNewsModel::with(['recruit'])
  53. ->where('status', RecruitNewsModel::STATUS_PUBLISH)
  54. ->find($id);
  55. if (empty($info)) {
  56. jump('该招聘公告不存在或已经删除');
  57. }
  58. $info->volume++;
  59. $info->save();
  60. return view('', [
  61. 'info' => $info,
  62. ]);
  63. }
  64. }