NoticeController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2017/11/15/015
  6. * Time: 19:18
  7. */
  8. namespace backend\modules\ib\controllers;
  9. use Yii;
  10. use backend\models\NoticeApi;
  11. use backend\models\searches\NoticeSearch;
  12. class NoticeController extends BaseController
  13. {
  14. /**
  15. * 公告首页
  16. * @return string
  17. */
  18. public function actionIndex()
  19. {
  20. return $this->render('index');
  21. }
  22. /**
  23. * ajax获取公告列表
  24. * @return \yii\web\Response
  25. */
  26. public function actionNoticeAjax()
  27. {
  28. $searchModel = new NoticeSearch();
  29. $request = \Yii::$app->getRequest()->getQueryParams();
  30. $request['type'] = 1;
  31. $dataProvider = $searchModel->search($request);
  32. return $this->asJson($searchModel->outResult($dataProvider));
  33. }
  34. /**
  35. * 获取未读公告数
  36. */
  37. public function actionFindNotReadCount()
  38. {
  39. $params = [];
  40. $params['member_id'] = $this->getMemberId();
  41. $noticeApi = new NoticeApi();
  42. $rs = $noticeApi->findNotReadCount($params['member_id'], 1);
  43. return $this->asJson((int)$rs['data']['unReadNum']);
  44. }
  45. /**
  46. * 获取公告详细信息
  47. */
  48. public function actionNview()
  49. {
  50. $request = \Yii::$app->getRequest()->getQueryParams();
  51. $params = [];
  52. $params['id'] = isset($request['id']) ? (int)$request['id'] : '';
  53. $params['member_id'] = $this->getMemberId();
  54. $params['is_admin'] = 0;
  55. $noticeApi = new NoticeApi();
  56. $rs = $noticeApi->view($params);
  57. return $this->render('view', ['data' => $rs['data']]);
  58. }
  59. /**
  60. * 最新的公告
  61. */
  62. public function actionLastUnreadNotice()
  63. {
  64. $params['member_id'] = $this->getMemberId();
  65. $params['type'] = 1;
  66. $noticeApi = new NoticeApi();
  67. $rs = $noticeApi->lastUnreadNotice($params);
  68. $cachePrefix = 'last_unread_notice-';
  69. $noticeId = Yii::$app->cache->get($cachePrefix . $params['member_id']);
  70. if ($noticeId && isset($rs['data']['notice']['id']) && $noticeId == $rs['data']['notice']['id']) {
  71. return $this->asJson(['code' => 0]);
  72. }
  73. if (isset($rs['data']['notice']['id'])) {
  74. Yii::$app->cache->set($cachePrefix . $params['member_id'], $rs['data']['notice']['id'], 86400 * 30);
  75. }
  76. return $this->asJson($rs);
  77. }
  78. }