NoticeService.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace backend\modules\mall\services;
  3. use common\models\backend\BackendNotice;
  4. use common\models\backend\BackendUnreadCount;
  5. use yii\data\Pagination;
  6. /**
  7. *
  8. * 应用置顶服务
  9. */
  10. class NoticeService extends BaseService
  11. {
  12. /**
  13. * 获取分页列表
  14. *
  15. * @param array $params
  16. * @return array
  17. */
  18. public function getPageList(array $params = [])
  19. {
  20. $limit = $params['limit'] ?? 20;
  21. $page = $params['page'] ?? 1;
  22. $model = BackendNotice::find();
  23. $model->andWhere(['mall_id' => $this->mall_id]);
  24. $pagination = new Pagination(['totalCount' => $model->count(), 'pageSize' => $limit]);
  25. $model->limit($pagination->limit)->offset($pagination->offset);
  26. $list = $model->orderBy('id desc')
  27. ->asArray()
  28. ->all();
  29. $data['list'] = $list;
  30. $data['page_count'] = $pagination->pageCount;
  31. $data['current_page'] = $page + 1;
  32. return $data;
  33. }
  34. /**
  35. * 获取未读消息数量
  36. *
  37. * @return int
  38. */
  39. public function getUnReadCount()
  40. {
  41. $count = BackendUnreadCount::getUnReadCount([
  42. 'mall_id' => $this->mall_id
  43. ]);
  44. return $count ? $count : 0;
  45. }
  46. /**
  47. * 阅读消息
  48. *
  49. * @param integer $id
  50. * @return boolean
  51. */
  52. public function readNotice(int $id)
  53. {
  54. return (boolean) BackendNotice::readNotice($id, $this->mall_id);
  55. }
  56. }