uniqid('', true), 'type' => 'patient_opened_chat', 'doctor_id' => $doctorId, 'patient_id' => $patientId, 'patient_name' => $patientName, 'created_at' => time(), ]; $list = Cache::get($key) ?: []; if (!is_array($list)) { $list = []; } array_unshift($list, $item); $list = array_slice($list, 0, self::MAX_PER_DOCTOR); Cache::set($key, $list, self::CACHE_TTL); return true; } /** * 添加面诊结束通知(医生完成接诊后通知对应医助) * @param int $assistantId 医助ID (admin_id) * @param string $patientName 患者姓名 * @param string $doctorName 医生姓名 * @param int $diagnosisId 诊单ID * @return bool */ public static function addConsultationCompleteNotify(int $assistantId, string $patientName, string $doctorName, int $diagnosisId = 0): bool { $key = self::CACHE_PREFIX . $assistantId; $item = [ 'id' => uniqid('', true), 'type' => 'consultation_complete', 'assistant_id' => $assistantId, 'patient_name' => $patientName, 'doctor_name' => $doctorName, 'diagnosis_id' => $diagnosisId, 'created_at' => time(), ]; $list = Cache::get($key) ?: []; if (!is_array($list)) { $list = []; } array_unshift($list, $item); $list = array_slice($list, 0, self::MAX_PER_DOCTOR); Cache::set($key, $list, self::CACHE_TTL); return true; } /** * 获取未读通知(医生/医助通用,按 admin_id 获取) * @param int $adminId 管理员ID (医生或医助) * @param bool $consume 是否消费(移除)已获取的 * @return array */ public static function getNotifies(int $adminId, bool $consume = true): array { $key = self::CACHE_PREFIX . $adminId; $list = Cache::get($key) ?: []; if (!is_array($list)) { $list = []; } if ($consume && !empty($list)) { Cache::delete($key); } return $list; } }