NoticeController.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/03/14
  6. * Time: 19:02
  7. */
  8. namespace App\Http\Controllers\Mobile\Content;
  9. use App\Http\Controllers\Mobile\MobileBaseController;
  10. use App\Services\Content\NoticeServer;
  11. use App\Services\Company\JobsService;
  12. use Illuminate\Http\Request;
  13. class NoticeController extends MobileBaseController
  14. {
  15. protected $noticeService;
  16. protected $jobsService;
  17. /**
  18. * NoticeController constructor.
  19. * @param $noticeService
  20. * @param $jobsService
  21. */
  22. public function __construct(NoticeServer $noticeService, JobsService $jobsService)
  23. {
  24. $this->noticeService = $noticeService;
  25. $this->jobsService = $jobsService;
  26. }
  27. public function index(Request $request)
  28. {
  29. $size = 5;
  30. $return_data = array();
  31. $where[] = array('is_display','=','1');
  32. $notices = $this->noticeService->getLists($where, $size);
  33. $mobile_dropload = false;
  34. if ($notices->total() > $size) {
  35. $mobile_dropload = true;
  36. }
  37. if ($request->ajax()) {
  38. if ($notices->lastPage() < $notices->currentPage()) {
  39. return response()->json(['status'=>0]);
  40. }
  41. return response()->json(['status'=>1,'data'=>view('mobile.app.content.notice.ajax_notice_list', ['notices'=>$notices])->render()]);
  42. }
  43. $return_data = array(
  44. 'notices' => $notices,
  45. 'mobile_dropload' => $mobile_dropload,
  46. 'wap_title' => '公告',
  47. );
  48. return view('mobile.app.content.notice.index', $return_data);
  49. }
  50. public function show($id)
  51. {
  52. $return_data = array();
  53. $where = array(
  54. 'id' => $id,
  55. 'is_display' => 1
  56. );
  57. $notice_info = $this->noticeService->getNotice($where);
  58. if (!$notice_info) {
  59. $back_url = \Illuminate\Support\Facades\URL::previous();
  60. return $this->showMessage('公告不存在', $back_url, true, '上一页', '3');
  61. }
  62. $this->putSeoData('notice', $notice_info);
  63. $return_data = array(
  64. 'notice' => $notice_info,
  65. 'wap_title' => $notice_info->title,
  66. );
  67. return view('mobile.app.content.notice.show', $return_data);
  68. }
  69. public function click($id)
  70. {
  71. $rst = $this->noticeService->incrementData(array('id'=>$id), 1, 'click');
  72. $data = array('status'=>0);
  73. if ($rst) {
  74. $data = array('status'=>1);
  75. }
  76. return response()->json($data);
  77. }
  78. }