dao = $dao; } /** * 系统登录-推送消息 * * @param string|int|array $id * * @return void * @throws \Exception */ public function notifyOnFirstLoginToAll(string|int|array $id): void { try { // 获取历史消息记录 $models = $this->selectList(['status' => MessageStatus::UNREAD->value], '*', 0, 0, '', [])->toArray(); if (!empty($models)) { foreach ($models as $value) { Notification::pushOnly(PushClientType::BACKEND, BusinessPlatform::ADMIN->value, '*', $value['receiver_id'], MessageEvent::DEFAULT->value, [], $value,null); } } } catch (\Throwable $e) { throw new \Exception($e->getMessage()); } } /** * 标记已读 * * @param string|array $param * * @throws \Exception */ public function isRead(string|array $param): void { try { $data = Arr::normalize($param); $messageModel = $this->dao->getModel(); $models = $messageModel->find($data); foreach ($models as $model) { $model->status = MessageStatus::READ; $model->read_at = time(); $model->save(); } } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } /** * 标记未读 * * @param string|array $param * * @throws \Exception */ public function isUnread(string|array $param): void { try { $data = Arr::normalize($param); $messageModel = $this->dao->getModel(); $models = $messageModel->find($data); foreach ($models as $model) { $model->status = MessageStatus::UNREAD; $model->updated_at = time(); $model->save(); } } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } }