From a14d773f17ad9a5eba3100c6b50a5ede0cd9d049 Mon Sep 17 00:00:00 2001 From: leiyun Date: Fri, 29 May 2026 00:34:44 +0800 Subject: [PATCH] fix bugs --- src/controller/mp.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/controller/mp.js b/src/controller/mp.js index d326d9f..be0dcb1 100644 --- a/src/controller/mp.js +++ b/src/controller/mp.js @@ -95,11 +95,22 @@ module.exports = class extends Base { .where({ id: user.patient_id, is_deleted: 0 }).find(); if (think.isEmpty(patient)) { // 关联的患者已被删除,清除关联 - await userModel.where({ id: user.id }).update({ patient_id: 0 }); user.patient_id = 0; patient = null; } } + // 如果没有关联患者,尝试查找该手机号下有效的患者并关联 + if (!user.patient_id) { + const validPatient = await this.model('patient') + .where({ phone: user.phone || mobile, is_deleted: 0 }) + .order('id DESC') + .find(); + if (!think.isEmpty(validPatient)) { + user.patient_id = validPatient.id; + patient = { id: validPatient.id, patient_no: validPatient.patient_no, name: validPatient.name, phone: validPatient.phone, status: validPatient.status, auth_status: validPatient.auth_status }; + } + await userModel.where({ id: user.id }).update({ patient_id: user.patient_id || 0 }); + } return this.json({ code: 0, data: { token, userInfo: { id: user.id, nickname: user.nickname || '', avatar: user.avatar || '', phone: user.phone || mobile, patient_id: user.patient_id || null, patient