|
|
|
@@ -242,29 +242,36 @@ module.exports = class extends Base { |
|
|
|
const userModel = this.model('wechat_user'); |
|
|
|
const currentUser = await userModel.where({ id: mpUser.id }).find(); |
|
|
|
|
|
|
|
// 查找已存在的患者(排除当前用户已绑定的) |
|
|
|
const existCondition = { id_card: idCard, is_deleted: 0 }; |
|
|
|
if (currentUser.patient_id) existCondition.id = ['!=', currentUser.patient_id]; |
|
|
|
const existPatient = await patientModel.where(existCondition).find(); |
|
|
|
|
|
|
|
if (!think.isEmpty(existPatient)) { |
|
|
|
// 手机号+身份证都匹配 → 可绑定已有患者 |
|
|
|
if (existPatient.phone === mobile) { |
|
|
|
// 排除当前用户已绑定的 patient |
|
|
|
const excludeId = currentUser.patient_id || 0; |
|
|
|
|
|
|
|
// 查找身份证是否已存在 |
|
|
|
const idCardCondition = { id_card: idCard, is_deleted: 0 }; |
|
|
|
if (excludeId) idCardCondition.id = ['!=', excludeId]; |
|
|
|
const existByIdCard = await patientModel.where(idCardCondition).find(); |
|
|
|
|
|
|
|
// 查找手机号是否已存在 |
|
|
|
const phoneCondition = { phone: mobile, is_deleted: 0 }; |
|
|
|
if (excludeId) phoneCondition.id = ['!=', excludeId]; |
|
|
|
const existByPhone = await patientModel.where(phoneCondition).find(); |
|
|
|
|
|
|
|
if (!think.isEmpty(existByIdCard)) { |
|
|
|
if (existByIdCard.phone === mobile) { |
|
|
|
// 手机号+身份证都匹配 → 可绑定已有患者 |
|
|
|
if (!confirmBind) { |
|
|
|
// 首次提交,返回 1010 让前端确认 |
|
|
|
const maskedName = existPatient.name.length > 1 |
|
|
|
? existPatient.name[0] + '*'.repeat(existPatient.name.length - 1) |
|
|
|
: existPatient.name; |
|
|
|
const maskedPhone = '****' + existPatient.phone.slice(-4); |
|
|
|
const maskedName = existByIdCard.name.length > 1 |
|
|
|
? existByIdCard.name[0] + '*'.repeat(existByIdCard.name.length - 1) |
|
|
|
: existByIdCard.name; |
|
|
|
const maskedPhone = '****' + existByIdCard.phone.slice(-4); |
|
|
|
return this.json({ |
|
|
|
code: 1010, |
|
|
|
data: { patientName: maskedName, patientPhone: maskedPhone }, |
|
|
|
msg: '该用户信息已存在' |
|
|
|
}); |
|
|
|
} |
|
|
|
// 用户确认绑定:检查该 patient 是否已被其他真实微信用户绑定(排除 H5 登录渠道) |
|
|
|
// 用户确认绑定 |
|
|
|
const boundUser = await userModel.where({ |
|
|
|
patient_id: existPatient.id, |
|
|
|
patient_id: existByIdCard.id, |
|
|
|
id: ['!=', mpUser.id], |
|
|
|
open_id: ['NOT LIKE', 'h5_%'], |
|
|
|
status: 1 |
|
|
|
@@ -272,11 +279,9 @@ module.exports = class extends Base { |
|
|
|
if (!think.isEmpty(boundUser)) { |
|
|
|
return this.json({ code: 1, msg: '该患者信息已被其他微信账号绑定' }); |
|
|
|
} |
|
|
|
// 绑定已有 patient 到当前微信用户 |
|
|
|
const now = think.datetime(new Date()); |
|
|
|
await userModel.where({ id: mpUser.id }).update({ patient_id: existPatient.id, update_time: now }); |
|
|
|
// 更新认证信息 |
|
|
|
await patientModel.where({ id: existPatient.id }).update({ |
|
|
|
await userModel.where({ id: mpUser.id }).update({ patient_id: existByIdCard.id, update_time: now }); |
|
|
|
await patientModel.where({ id: existByIdCard.id }).update({ |
|
|
|
name: realName, phone: mobile, id_card_type: cardTypeInt, |
|
|
|
id_card_front: idCardFront || '', id_card_back: idCardBack || '', photo: photo || '', |
|
|
|
gender: gender || '', birth_date: birthday || null, |
|
|
|
@@ -285,10 +290,15 @@ module.exports = class extends Base { |
|
|
|
}); |
|
|
|
return this.json({ code: 0, data: {}, msg: '实名认证成功' }); |
|
|
|
} |
|
|
|
// 身份证匹配但手机号不同 → 真正的冲突 |
|
|
|
// 身份证存在但手机号不同 |
|
|
|
return this.json({ code: 1, msg: '该证件号已被其他用户认证' }); |
|
|
|
} |
|
|
|
|
|
|
|
// 身份证不存在,但手机号已被其他患者使用 |
|
|
|
if (!think.isEmpty(existByPhone)) { |
|
|
|
return this.json({ code: 1, msg: '该手机号已被其他患者使用' }); |
|
|
|
} |
|
|
|
|
|
|
|
if (cardTypeInt === 1 || cardTypeInt === 3) { |
|
|
|
const faceidConfig = require('../config/faceid.js'); |
|
|
|
if (faceidConfig.enabled) { |
|
|
|
|