| @@ -95,11 +95,22 @@ module.exports = class extends Base { | |||||
| .where({ id: user.patient_id, is_deleted: 0 }).find(); | .where({ id: user.patient_id, is_deleted: 0 }).find(); | ||||
| if (think.isEmpty(patient)) { | if (think.isEmpty(patient)) { | ||||
| // 关联的患者已被删除,清除关联 | // 关联的患者已被删除,清除关联 | ||||
| await userModel.where({ id: user.id }).update({ patient_id: 0 }); | |||||
| user.patient_id = 0; | user.patient_id = 0; | ||||
| patient = null; | 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: { | return this.json({ code: 0, data: { token, userInfo: { | ||||
| id: user.id, nickname: user.nickname || '', avatar: user.avatar || '', | id: user.id, nickname: user.nickname || '', avatar: user.avatar || '', | ||||
| phone: user.phone || mobile, patient_id: user.patient_id || null, patient | phone: user.phone || mobile, patient_id: user.patient_id || null, patient | ||||