| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace backend\modules\mall\services;
- use common\models\backend\BackendNotice;
- use common\models\backend\BackendUnreadCount;
- use yii\data\Pagination;
- /**
- *
- * 应用置顶服务
- */
- class NoticeService extends BaseService
- {
- /**
- * 获取分页列表
- *
- * @param array $params
- * @return array
- */
- public function getPageList(array $params = [])
- {
- $limit = $params['limit'] ?? 20;
- $page = $params['page'] ?? 1;
- $model = BackendNotice::find();
- $model->andWhere(['mall_id' => $this->mall_id]);
- $pagination = new Pagination(['totalCount' => $model->count(), 'pageSize' => $limit]);
- $model->limit($pagination->limit)->offset($pagination->offset);
- $list = $model->orderBy('id desc')
- ->asArray()
- ->all();
- $data['list'] = $list;
- $data['page_count'] = $pagination->pageCount;
- $data['current_page'] = $page + 1;
- return $data;
- }
- /**
- * 获取未读消息数量
- *
- * @return int
- */
- public function getUnReadCount()
- {
- $count = BackendUnreadCount::getUnReadCount([
- 'mall_id' => $this->mall_id
- ]);
- return $count ? $count : 0;
- }
- /**
- * 阅读消息
- *
- * @param integer $id
- * @return boolean
- */
- public function readNotice(int $id)
- {
- return (boolean) BackendNotice::readNotice($id, $this->mall_id);
- }
- }
|