NoticeController.php 2.4 KB

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