1954 lines
56 KiB
Go
1954 lines
56 KiB
Go
package service
|
||
|
||
import (
|
||
"errors"
|
||
"fmt"
|
||
"github.com/shopspring/decimal"
|
||
"hospital-admin-api/api/dao"
|
||
"hospital-admin-api/api/dto"
|
||
"hospital-admin-api/api/model"
|
||
"hospital-admin-api/api/requests"
|
||
"hospital-admin-api/config"
|
||
"hospital-admin-api/extend/aliyun"
|
||
"hospital-admin-api/extend/ca"
|
||
"hospital-admin-api/extend/tencentIm"
|
||
"hospital-admin-api/extend/verifyDun"
|
||
"hospital-admin-api/global"
|
||
"hospital-admin-api/utils"
|
||
"strconv"
|
||
"strings"
|
||
"time"
|
||
)
|
||
|
||
type UserDoctorService struct {
|
||
}
|
||
|
||
// GetUserDoctor 医生详情
|
||
func (r *UserDoctorService) GetUserDoctor(doctorId int64) (getUserDoctorResponse *dto.UserDoctorDto, err error) {
|
||
// 获取医生数据
|
||
userDoctorDao := dao.UserDoctorDao{}
|
||
userDoctor, err := userDoctorDao.GetUserDoctorPreloadById(doctorId)
|
||
if err != nil || userDoctor == nil {
|
||
return nil, errors.New(err.Error())
|
||
}
|
||
|
||
userDoctorService := UserDoctorService{}
|
||
|
||
// 获取医生专长
|
||
doctorExpertise, err := userDoctorService.GetUserDoctorExpertiseByDoctorId(doctorId)
|
||
|
||
// 获取医生银行卡
|
||
doctorBankCardDao := dao.DoctorBankCardDao{}
|
||
doctorBankCard, err := doctorBankCardDao.GetDoctorBankCardByDoctorId(doctorId)
|
||
|
||
// 获取医生云证书数据
|
||
userCaCertDao := dao.UserCaCertDao{}
|
||
maps := make(map[string]interface{})
|
||
maps["user_id"] = userDoctor.UserId
|
||
maps["type"] = 2
|
||
userCaCert, _ := userCaCertDao.GetUserCaCert(maps)
|
||
|
||
// 处理返回值
|
||
getUserDoctorResponse = dto.GetUserDoctorDto(userDoctor)
|
||
|
||
// 加载用户
|
||
getUserDoctorResponse.LoadUser(userDoctor.User)
|
||
|
||
// 加载医院
|
||
getUserDoctorResponse.LoadHospital(userDoctor.Hospital)
|
||
|
||
// 加载医生专长
|
||
getUserDoctorResponse.DoctorExpertise = doctorExpertise
|
||
|
||
// 加载医生银行卡
|
||
getUserDoctorResponse.LoadDoctorBankCard(doctorBankCard)
|
||
|
||
// 加载医生详情
|
||
getUserDoctorResponse.LoadUserDoctorInfo(userDoctor.UserDoctorInfo)
|
||
|
||
// 加载医生云证书详情
|
||
getUserDoctorResponse.LoadUserCaCert(userCaCert)
|
||
|
||
return getUserDoctorResponse, nil
|
||
}
|
||
|
||
// PutUserDoctor 修改医生
|
||
func (r *UserDoctorService) PutUserDoctor(doctorId int64, req requests.PutUserDoctor) (bool, error) {
|
||
// 获取医生数据
|
||
userDoctorDao := dao.UserDoctorDao{}
|
||
userDoctor, err := userDoctorDao.GetUserDoctorById(doctorId)
|
||
if err != nil || userDoctor == nil {
|
||
return false, errors.New("医生数据错误")
|
||
}
|
||
|
||
// 获取医生详情数据
|
||
userDoctorInfoDao := dao.UserDoctorInfoDao{}
|
||
userDoctorInfo, err := userDoctorInfoDao.GetUserDoctorInfoByDoctorId(doctorId)
|
||
if err != nil {
|
||
return false, errors.New("医生详情数据错误")
|
||
}
|
||
|
||
// 获取用户数据
|
||
userDao := dao.UserDao{}
|
||
user, err := userDao.GetUserById(userDoctor.UserId)
|
||
if err != nil && user == nil {
|
||
return false, errors.New("医生数据错误")
|
||
}
|
||
|
||
if userDoctor.IdenAuthStatus == 2 {
|
||
return false, errors.New("医生身份审核中,不允许修改")
|
||
}
|
||
|
||
// 获取医生绑定银行卡数据
|
||
doctorBankCardDao := dao.DoctorBankCardDao{}
|
||
doctorBankCard, _ := doctorBankCardDao.GetDoctorBankCardByDoctorId(doctorId)
|
||
|
||
userDoctorData := make(map[string]interface{}) // 医生数据
|
||
userDoctorInfoData := make(map[string]interface{}) // 医生详情数据
|
||
userData := make(map[string]interface{}) // 用户数据
|
||
|
||
// 处理头像
|
||
avatar := utils.RemoveOssDomain(req.Avatar)
|
||
if userDoctor.Avatar != avatar {
|
||
userDoctorData["avatar"] = avatar
|
||
userData["avatar"] = avatar
|
||
}
|
||
|
||
// 处理职称
|
||
if userDoctor.DoctorTitle != req.DoctorTitle {
|
||
userDoctorData["doctor_title"] = req.DoctorTitle
|
||
}
|
||
|
||
// 处理科室
|
||
departmentCustomId, err := strconv.ParseInt(req.DepartmentCustomId, 10, 64)
|
||
if err != nil {
|
||
return false, errors.New("科室错误")
|
||
}
|
||
|
||
if departmentCustomId == 0 && userDoctor.DepartmentCustomId != 0 {
|
||
return false, errors.New("未选择科室")
|
||
}
|
||
if userDoctor.DepartmentCustomId != departmentCustomId || userDoctor.DepartmentCustomName != req.DepartmentCustomName {
|
||
// 获取科室数据
|
||
hospitalDepartmentCustomDao := dao.HospitalDepartmentCustomDao{}
|
||
hospitalDepartmentCustom, err := hospitalDepartmentCustomDao.GetHospitalDepartmentCustomById(departmentCustomId)
|
||
if err != nil || hospitalDepartmentCustom == nil {
|
||
return false, errors.New("科室错误")
|
||
}
|
||
|
||
userDoctorData["department_custom_id"] = req.DepartmentCustomId
|
||
userDoctorData["department_custom_name"] = hospitalDepartmentCustom.DepartmentCustomName
|
||
|
||
if req.DepartmentCustomName != "" {
|
||
userDoctorData["department_custom_name"] = req.DepartmentCustomName
|
||
}
|
||
}
|
||
|
||
// 处理科室电话
|
||
if userDoctor.DepartmentCustomMobile != req.DepartmentCustomMobile {
|
||
userDoctorData["department_custom_mobile"] = req.DepartmentCustomMobile
|
||
}
|
||
|
||
// 处理医院
|
||
hospitalId, err := strconv.ParseInt(req.HospitalId, 10, 64)
|
||
if err != nil {
|
||
return false, errors.New("科室错误")
|
||
}
|
||
|
||
if userDoctor.HospitalID != hospitalId {
|
||
// 获取医院数据
|
||
hospitalDao := dao.HospitalDao{}
|
||
hospital, err := hospitalDao.GetHospitalById(hospitalId)
|
||
if err != nil || hospital == nil {
|
||
return false, errors.New("医院错误")
|
||
}
|
||
userDoctorData["hospital_id"] = req.HospitalId
|
||
}
|
||
|
||
// 处理深度合作医生
|
||
if userDoctor.IsPlatformDeepCooperation != req.IsPlatformDeepCooperation {
|
||
userDoctorData["is_platform_deep_cooperation"] = req.IsPlatformDeepCooperation
|
||
}
|
||
|
||
// 处理是否先思达合作医生
|
||
if userDoctor.IsSysDiagnoCooperation != req.IsSysDiagnoCooperation {
|
||
userDoctorData["is_sys_diagno_cooperation"] = req.IsSysDiagnoCooperation
|
||
}
|
||
|
||
// 是否推荐
|
||
if userDoctor.IsRecommend != req.IsRecommend {
|
||
userDoctorData["is_recommend"] = req.IsRecommend
|
||
}
|
||
|
||
// 处理擅长
|
||
if userDoctor.BeGoodAt != req.BeGoodAt {
|
||
userDoctorData["be_good_at"] = req.BeGoodAt
|
||
}
|
||
|
||
// 医生简介
|
||
if userDoctor.BriefIntroduction != req.BriefIntroduction {
|
||
userDoctorData["brief_introduction"] = req.BriefIntroduction
|
||
}
|
||
|
||
// 处理医师执业证
|
||
var licenseCert string
|
||
if len(req.LicenseCert) > 0 {
|
||
result := make([]string, len(req.LicenseCert))
|
||
for i, url := range req.LicenseCert {
|
||
result[i] = strings.TrimPrefix(url, config.C.Oss.OssCustomDomainName)
|
||
}
|
||
|
||
licenseCert = strings.Join(result, ",")
|
||
}
|
||
if userDoctorInfo.LicenseCert != licenseCert {
|
||
userDoctorInfoData["license_cert"] = licenseCert
|
||
}
|
||
|
||
// 处理医师资格证
|
||
var qualificationCert string
|
||
if len(req.QualificationCert) > 0 {
|
||
result := make([]string, len(req.QualificationCert))
|
||
for i, url := range req.QualificationCert {
|
||
result[i] = strings.TrimPrefix(url, config.C.Oss.OssCustomDomainName)
|
||
}
|
||
|
||
qualificationCert = strings.Join(result, ",")
|
||
}
|
||
if userDoctorInfo.QualificationCert != qualificationCert {
|
||
userDoctorInfoData["qualification_cert"] = qualificationCert
|
||
}
|
||
|
||
// 处理医师工作证
|
||
var workCert string
|
||
if len(req.WorkCert) > 0 {
|
||
result := make([]string, len(req.WorkCert))
|
||
for i, url := range req.WorkCert {
|
||
result[i] = strings.TrimPrefix(url, config.C.Oss.OssCustomDomainName)
|
||
}
|
||
|
||
workCert = strings.Join(result, ",")
|
||
}
|
||
if userDoctorInfo.WorkCert != workCert {
|
||
userDoctorInfoData["work_cert"] = workCert
|
||
}
|
||
|
||
// 处理身份证正面图片
|
||
idCardFront := userDoctorInfo.IdCardFront
|
||
if idCardFront != "" && req.IdCardFront == "" {
|
||
return false, errors.New("未上传新的身份证图片")
|
||
}
|
||
if req.IdCardFront != "" {
|
||
if utils.RemoveOssDomain(req.IdCardFront) != idCardFront {
|
||
if userDoctor.MultiPointStatus == 2 {
|
||
return false, errors.New("多点执业审核中,请操作后进行修改")
|
||
}
|
||
|
||
idCardFront = utils.RemoveOssDomain(req.IdCardFront)
|
||
userDoctorInfoData["id_card_front"] = utils.RemoveOssDomain(req.IdCardFront)
|
||
}
|
||
}
|
||
|
||
// 身份证背面图片
|
||
idCardBack := userDoctorInfo.IdCardBack
|
||
if idCardBack != "" && req.IdCardBack == "" {
|
||
return false, errors.New("未上传新的身份证图片")
|
||
}
|
||
if req.IdCardBack != "" {
|
||
if utils.RemoveOssDomain(req.IdCardBack) != idCardBack {
|
||
if userDoctor.MultiPointStatus == 2 {
|
||
return false, errors.New("多点执业审核中,请操作后进行修改")
|
||
}
|
||
|
||
idCardBack = utils.RemoveOssDomain(req.IdCardBack)
|
||
userDoctorInfoData["id_card_back"] = utils.RemoveOssDomain(req.IdCardBack)
|
||
}
|
||
}
|
||
|
||
// 签名图片
|
||
signImage := userDoctorInfo.SignImage
|
||
if signImage != "" && req.SignImage == "" {
|
||
return false, errors.New("未上传新的签名图片")
|
||
}
|
||
if req.SignImage != "" {
|
||
if utils.RemoveOssDomain(req.SignImage) != signImage {
|
||
if userDoctor.MultiPointStatus == 2 {
|
||
return false, errors.New("多点执业审核中,请操作后进行修改")
|
||
}
|
||
|
||
signImage = utils.RemoveOssDomain(req.SignImage)
|
||
userDoctorInfoData["sign_image"] = signImage
|
||
}
|
||
}
|
||
|
||
// 处理专长
|
||
if len(req.DoctorExpertise) > 0 {
|
||
// 检测专长是否存在
|
||
diseaseClassExpertiseDao := dao.DiseaseClassExpertiseDao{}
|
||
for _, v := range req.DoctorExpertise {
|
||
expertiseId, err := strconv.ParseInt(v, 10, 64)
|
||
if err != nil {
|
||
return false, errors.New("专长错误")
|
||
}
|
||
|
||
diseaseClassExpertise, err := diseaseClassExpertiseDao.GetDiseaseClassExpertiseById(expertiseId)
|
||
if err != nil || diseaseClassExpertise == nil {
|
||
return false, errors.New("专长数据错误")
|
||
}
|
||
}
|
||
}
|
||
|
||
// 处理身份审核状态
|
||
if userDoctor.Avatar != avatar || userDoctor.DepartmentCustomMobile != req.DepartmentCustomMobile || userDoctor.DepartmentCustomId != departmentCustomId || userDoctor.DepartmentCustomName != req.DepartmentCustomName || userDoctor.BriefIntroduction != req.BriefIntroduction || userDoctor.BeGoodAt != req.BeGoodAt || userDoctorInfo.LicenseCert != licenseCert || userDoctorInfo.QualificationCert != qualificationCert || userDoctorInfo.WorkCert != workCert {
|
||
if userDoctor.IdenAuthStatus == 3 {
|
||
// 如果认证失败,修改属性会重新进入待审核
|
||
userDoctorData["iden_auth_status"] = 2
|
||
}
|
||
}
|
||
|
||
// 处理身份审核状态-未认证情况下,如果资料补充完整,进入身份待审核
|
||
if userDoctor.IdenAuthStatus == 0 {
|
||
if avatar != "" && req.DepartmentCustomMobile != "" && departmentCustomId != 0 && req.DepartmentCustomName != "" && req.BriefIntroduction != "" && req.BeGoodAt != "" && licenseCert != "" && qualificationCert != "" && workCert != "" {
|
||
userDoctorData["iden_auth_status"] = 2
|
||
}
|
||
}
|
||
|
||
// 处理多点状态更新问题
|
||
if signImage != "" && idCardBack != "" && idCardFront != "" {
|
||
// 审核失败、未审核情况下,如果数据存在修改,重新进入待审核
|
||
if userDoctor.MultiPointStatus == 0 || userDoctor.MultiPointStatus == 3 {
|
||
if signImage != userDoctorInfo.SignImage || idCardBack != userDoctorInfo.IdCardBack || idCardFront != userDoctorInfo.IdCardFront {
|
||
userDoctorData["multi_point_status"] = 2
|
||
userDoctorData["multi_point_fail_reason"] = ""
|
||
|
||
// 检测是否存在正在审核中的处方
|
||
orderPrescriptionDao := dao.OrderPrescriptionDao{}
|
||
|
||
maps := make(map[string]interface{})
|
||
maps["doctor_id"] = doctorId
|
||
maps["prescription_status"] = 1
|
||
orderPrescription, err := orderPrescriptionDao.GetList(maps)
|
||
if err != nil {
|
||
return false, errors.New("修改失败")
|
||
}
|
||
|
||
if len(orderPrescription) > 0 {
|
||
return false, errors.New("存在审核中的处方,请勿修改签名及身份证数据")
|
||
}
|
||
}
|
||
}
|
||
|
||
// 签名、身份证数据不为空的情况下,银行卡数据必填
|
||
if req.BankCardCode == "" || req.BankId == "" || req.BankCardProvinceId == 0 || req.BankCardCountyId == 0 || req.BankCardCityId == 0 {
|
||
return false, errors.New("请填入银行卡数据")
|
||
}
|
||
}
|
||
|
||
var provinceId int
|
||
var province string
|
||
var cityId int
|
||
var city string
|
||
var countyId int
|
||
var county string
|
||
var bankId int64
|
||
var bankCardCode string
|
||
var bankCardCodeMask string
|
||
|
||
// 邮箱问题
|
||
if user.Email != req.Email {
|
||
userData["email"] = req.Email
|
||
}
|
||
|
||
// 原银行卡数据存在的情况下,只允许重新替换,不允许删除
|
||
if doctorBankCard != nil {
|
||
if req.BankCardProvinceId == 0 || req.BankCardCityId == 0 || req.BankCardCountyId == 0 || req.BankCardCode == "" || req.BankId == "" {
|
||
return false, errors.New("未上传新的银行卡数据")
|
||
}
|
||
|
||
if doctorBankCard.ProvinceId != req.BankCardProvinceId {
|
||
provinceId = req.BankCardProvinceId
|
||
}
|
||
|
||
if doctorBankCard.CityId != req.BankCardCityId {
|
||
cityId = req.BankCardCityId
|
||
}
|
||
|
||
if doctorBankCard.CountyId != req.BankCardCountyId {
|
||
countyId = req.BankCardCountyId
|
||
}
|
||
|
||
// 处理银行卡数据
|
||
reqBankId, err := strconv.ParseInt(req.BankId, 10, 64)
|
||
if err != nil {
|
||
return false, errors.New("银行错误")
|
||
}
|
||
|
||
if doctorBankCard.BankId != reqBankId {
|
||
bankId = reqBankId
|
||
}
|
||
|
||
if doctorBankCard.BankCardCode != req.BankCardCode {
|
||
bankCardCode = req.BankCardCode
|
||
}
|
||
}
|
||
if doctorBankCard == nil {
|
||
if req.BankCardCode != "" && req.BankId != "" && req.BankCardProvinceId != 0 && req.BankCardCountyId != 0 && req.BankCardCityId != 0 {
|
||
provinceId = req.BankCardProvinceId
|
||
cityId = req.BankCardCityId
|
||
countyId = req.BankCardCountyId
|
||
|
||
bankId, err = strconv.ParseInt(req.BankId, 10, 64)
|
||
if err != nil {
|
||
return false, errors.New("银行错误")
|
||
}
|
||
|
||
bankCardCode = req.BankCardCode
|
||
}
|
||
}
|
||
|
||
areaDao := dao.AreaDao{}
|
||
if provinceId != 0 {
|
||
area, err := areaDao.GetAreaById(provinceId)
|
||
if err != nil || area == nil {
|
||
return false, errors.New("银行卡省份数据错误")
|
||
}
|
||
province = area.AreaName
|
||
}
|
||
|
||
if cityId != 0 {
|
||
area, err := areaDao.GetAreaById(cityId)
|
||
if err != nil || area == nil {
|
||
return false, errors.New("银行卡城市数据错误")
|
||
}
|
||
city = area.AreaName
|
||
}
|
||
|
||
if countyId != 0 {
|
||
area, err := areaDao.GetAreaById(countyId)
|
||
if err != nil || area == nil {
|
||
return false, errors.New("银行卡城市数据错误")
|
||
}
|
||
county = area.AreaName
|
||
}
|
||
|
||
if bankId != 0 {
|
||
basicBankDao := dao.BasicBankDao{}
|
||
basicBank, err := basicBankDao.GetBasicBankById(bankId)
|
||
if err != nil || basicBank == nil {
|
||
return false, errors.New("银行数据错误")
|
||
}
|
||
}
|
||
|
||
// 处理银行卡号掩码
|
||
if bankCardCode != "" {
|
||
if len(bankCardCode) < 8 {
|
||
return false, errors.New("银行卡号错误")
|
||
}
|
||
|
||
// 检测银行卡号
|
||
if config.C.Env == "prod" {
|
||
res, err := verifyDun.CheckBankCard(userDoctorInfo.CardName, req.BankCardCode, userDoctorInfo.CardNum)
|
||
if err != nil {
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
if !res {
|
||
return false, errors.New("银行卡三要素检测失败")
|
||
}
|
||
}
|
||
|
||
// 获取银行卡号的前4位和后4位
|
||
start := bankCardCode[:4]
|
||
end := bankCardCode[len(bankCardCode)-4:]
|
||
// 拼接前4位、中间的 * 字符串和后4位
|
||
bankCardCodeMask = start + "****" + end
|
||
}
|
||
|
||
// 是否已绑定结算银行卡
|
||
if provinceId != 0 && cityId != 0 && countyId != 0 && bankId != 0 && bankCardCode != "" {
|
||
if userDoctor.IsBindBank != 1 {
|
||
userDoctorData["is_bind_bank"] = 1
|
||
}
|
||
}
|
||
|
||
// 开始事务
|
||
tx := global.Db.Begin()
|
||
defer func() {
|
||
if r := recover(); r != nil {
|
||
tx.Rollback()
|
||
}
|
||
}()
|
||
|
||
// 修改医生数据
|
||
if len(userDoctorData) != 0 {
|
||
err = userDoctorDao.EditUserDoctorById(tx, doctorId, userDoctorData)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("修改失败")
|
||
}
|
||
}
|
||
|
||
// 处理医生详情数据
|
||
if len(userDoctorInfoData) != 0 {
|
||
if userDoctorInfo == nil {
|
||
userDoctorInfo, err := userDoctorInfoDao.AddUserDoctorInfoByMap(tx, userDoctorInfoData)
|
||
if userDoctorInfo == nil || err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("修改失败")
|
||
}
|
||
} else {
|
||
err = userDoctorInfoDao.EditUserDoctorInfoById(tx, userDoctorInfo.DoctorInfoId, userDoctorInfoData)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("修改失败")
|
||
}
|
||
}
|
||
}
|
||
|
||
// 修改用户数据
|
||
if len(userData) != 0 {
|
||
err = userDao.EditUserById(tx, userDoctor.UserId, userData)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("修改失败")
|
||
}
|
||
}
|
||
|
||
// 修改专长数据
|
||
if len(req.DoctorExpertise) > 0 {
|
||
doctorExpertiseDao := dao.DoctorExpertiseDao{}
|
||
|
||
// 删除原专长
|
||
maps := make(map[string]interface{})
|
||
maps["doctor_id"] = userDoctor.DoctorId
|
||
err = doctorExpertiseDao.DeleteDoctorExpertise(tx, maps)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("修改失败")
|
||
}
|
||
|
||
for _, v := range req.DoctorExpertise {
|
||
expertiseId, err := strconv.ParseInt(v, 10, 64)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("专长错误")
|
||
}
|
||
|
||
// 新增专长表数据
|
||
doctorExpertise := &model.DoctorExpertise{
|
||
DoctorId: userDoctor.DoctorId,
|
||
ExpertiseId: expertiseId,
|
||
}
|
||
|
||
doctorExpertise, err = doctorExpertiseDao.AddDoctorExpertise(tx, doctorExpertise)
|
||
if err != nil || doctorExpertise == nil {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
}
|
||
}
|
||
|
||
// 修改医生银行卡数据-新增
|
||
if doctorBankCard == nil {
|
||
if provinceId != 0 && cityId != 0 && countyId != 0 && bankId != 0 && bankCardCode != "" {
|
||
// 新增医生银行卡表
|
||
bankId, err := strconv.ParseInt(req.BankId, 10, 64)
|
||
if err != nil {
|
||
return false, errors.New("银行错误")
|
||
}
|
||
|
||
doctorBankCard := &model.DoctorBankCard{
|
||
DoctorId: userDoctor.DoctorId,
|
||
BankId: bankId,
|
||
BankCardCode: bankCardCode,
|
||
BankCardCodeMask: bankCardCodeMask,
|
||
ProvinceId: provinceId,
|
||
Province: province,
|
||
CityId: cityId,
|
||
City: city,
|
||
CountyId: countyId,
|
||
County: county,
|
||
}
|
||
doctorBankCardDao := dao.DoctorBankCardDao{}
|
||
|
||
doctorBankCard, err = doctorBankCardDao.AddDoctorBankCard(tx, doctorBankCard)
|
||
if err != nil || doctorBankCard == nil {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
}
|
||
}
|
||
|
||
// 修改医生银行卡数据-修改
|
||
if doctorBankCard != nil {
|
||
// 修改
|
||
doctorBankCardData := make(map[string]interface{}) // 医生银行卡数据
|
||
if bankId != 0 {
|
||
doctorBankCardData["bank_id"] = bankId
|
||
}
|
||
|
||
if bankCardCode != "" {
|
||
doctorBankCardData["bank_card_code"] = bankCardCode
|
||
doctorBankCardData["bank_card_code_mask"] = bankCardCodeMask
|
||
}
|
||
|
||
if provinceId != 0 {
|
||
doctorBankCardData["province_id"] = provinceId
|
||
doctorBankCardData["province"] = province
|
||
}
|
||
|
||
if cityId != 0 {
|
||
doctorBankCardData["city_id"] = cityId
|
||
doctorBankCardData["city"] = city
|
||
}
|
||
|
||
if countyId != 0 {
|
||
doctorBankCardData["county_id"] = countyId
|
||
doctorBankCardData["county"] = county
|
||
}
|
||
|
||
if len(doctorBankCardData) > 0 {
|
||
err = doctorBankCardDao.EditDoctorBankCardById(tx, doctorId, doctorBankCardData)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("修改失败")
|
||
}
|
||
}
|
||
}
|
||
|
||
// // 处理科室问题-更新云证书-暂时不更新,更新时调用EditUserCloudCert方法,内部查询的数据还是更新前的数据
|
||
// if userDoctor.DepartmentCustomId != departmentCustomId {
|
||
// if userDoctor.IdenAuthStatus == 1 {
|
||
// // 更新云证书
|
||
// userCaCertService := UserCaCertService{}
|
||
// _, err = userCaCertService.EditUserCloudCert(tx, userDoctor.UserId)
|
||
// if err != nil {
|
||
// tx.Rollback()
|
||
// return false, errors.New(err.Error())
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
// 判断头像是否修改,同步修改im
|
||
if userDoctor.Avatar != avatar {
|
||
profileItem := []tencentIm.ProfileItem{
|
||
{
|
||
Tag: "Tag_Profile_IM_Image",
|
||
Value: req.Avatar,
|
||
},
|
||
}
|
||
res, err := tencentIm.SetProfile(strconv.FormatInt(userDoctor.UserId, 10), profileItem)
|
||
if err != nil || res != true {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
}
|
||
|
||
// 处理签名图片-如果更改,查看是否已添加签章配置,会进行删除
|
||
if req.SignImage != "" {
|
||
// 获取医生云证书
|
||
userCaCertDao := dao.UserCaCertDao{}
|
||
|
||
maps := make(map[string]interface{})
|
||
maps["user_id"] = userDoctor.UserId
|
||
maps["type"] = 2
|
||
maps["is_latest"] = 1
|
||
userCaCert, _ := userCaCertDao.GetUserCaCert(maps)
|
||
|
||
signImage := utils.RemoveOssDomain(req.SignImage)
|
||
if signImage != userDoctorInfo.SignImage && userCaCert != nil {
|
||
// 检测是否已经添加签章配置
|
||
if userCaCert.IsSignConfig == 1 {
|
||
// 修改签章配置为未添加
|
||
data := make(map[string]interface{})
|
||
data["is_sign_config"] = 0
|
||
data["sign_config"] = ""
|
||
err = userCaCertDao.EditUserCaCertById(tx, userCaCert.CertId, data)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
// 删除签章配置
|
||
deleteUserSignConfigRequestData := &ca.DeleteUserSignConfigRequestData{
|
||
UserId: fmt.Sprintf("%d", userDoctor.UserId),
|
||
ConfigKey: fmt.Sprintf("%d", userDoctor.UserId),
|
||
}
|
||
|
||
_, err := ca.DeleteUserSignConfig(deleteUserSignConfigRequestData)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("删除用户签章配置失败")
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
tx.Commit()
|
||
return true, nil
|
||
}
|
||
|
||
// AddUserDoctor 新增医生
|
||
func (r *UserDoctorService) AddUserDoctor(userId string, req requests.AddUserDoctor) (bool, error) {
|
||
userDoctorDao := dao.UserDoctorDao{}
|
||
userDao := dao.UserDao{}
|
||
userDoctorInfoDao := dao.UserDoctorInfoDao{}
|
||
|
||
// 检测手机号是否重复
|
||
maps := make(map[string]interface{})
|
||
maps["mobile"] = req.Mobile
|
||
users, err := userDao.GetUserList(maps)
|
||
if err != nil {
|
||
return false, errors.New("新增失败")
|
||
}
|
||
|
||
if len(users) != 0 {
|
||
return false, errors.New("手机号重复")
|
||
}
|
||
|
||
// 检测身份证号码
|
||
res, err := utils.CheckCardNum(req.CardNum)
|
||
if !res || err != nil {
|
||
return false, errors.New("身份证号错误")
|
||
}
|
||
|
||
if config.C.Env == "prod" {
|
||
// 身份证号码实证认证
|
||
res, err = verifyDun.CheckIdCard(req.CardName, req.CardNum)
|
||
if err != nil {
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
if !res {
|
||
return false, errors.New("身份证认证失败")
|
||
}
|
||
}
|
||
|
||
// 检测身份证号是否重复
|
||
maps = make(map[string]interface{})
|
||
maps["card_num"] = req.CardNum
|
||
userDoctorInfos, err := userDoctorInfoDao.GetUserDoctorInfoList(maps)
|
||
if err != nil {
|
||
return false, errors.New("新增失败")
|
||
}
|
||
|
||
if len(userDoctorInfos) != 0 {
|
||
return false, errors.New("证件号码重复")
|
||
}
|
||
|
||
// 处理年龄
|
||
age, err := utils.GetCardAge(req.CardNum)
|
||
if err != nil {
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
// 处理性别
|
||
sex, err := utils.GetCardSex(req.CardNum)
|
||
if err != nil {
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
// 身份证号码脱敏
|
||
cardNumMask := utils.GetMaskCardNum(req.CardNum)
|
||
|
||
// 身份证名称脱敏
|
||
cardNameMask := utils.GetMaskCardName(req.CardName)
|
||
|
||
// 检测科室
|
||
departmentCustomId, err := strconv.ParseInt(req.DepartmentCustomId, 10, 64)
|
||
if err != nil {
|
||
return false, errors.New("科室错误")
|
||
}
|
||
|
||
// 获取科室数据
|
||
hospitalDepartmentCustomDao := dao.HospitalDepartmentCustomDao{}
|
||
hospitalDepartmentCustom, err := hospitalDepartmentCustomDao.GetHospitalDepartmentCustomById(departmentCustomId)
|
||
if err != nil || hospitalDepartmentCustom == nil {
|
||
return false, errors.New("科室错误")
|
||
}
|
||
|
||
// 检测医院
|
||
hospitalId, err := strconv.ParseInt(req.HospitalId, 10, 64)
|
||
if err != nil {
|
||
return false, errors.New("医院错误")
|
||
}
|
||
|
||
// 获取医院数据
|
||
hospitalDao := dao.HospitalDao{}
|
||
hospital, err := hospitalDao.GetHospitalById(hospitalId)
|
||
if err != nil || hospital == nil {
|
||
return false, errors.New("医院错误")
|
||
}
|
||
|
||
// 处理头像
|
||
avatar := utils.RemoveOssDomain(req.Avatar)
|
||
|
||
// 处理医师执业证
|
||
var licenseCert string
|
||
if len(req.LicenseCert) > 0 {
|
||
result := make([]string, len(req.LicenseCert))
|
||
for i, url := range req.LicenseCert {
|
||
result[i] = utils.RemoveOssDomain(url)
|
||
}
|
||
|
||
licenseCert = strings.Join(result, ",")
|
||
}
|
||
|
||
// 处理医师资格证
|
||
var qualificationCert string
|
||
if len(req.QualificationCert) > 0 {
|
||
result := make([]string, len(req.QualificationCert))
|
||
for i, url := range req.QualificationCert {
|
||
result[i] = utils.RemoveOssDomain(url)
|
||
}
|
||
|
||
qualificationCert = strings.Join(result, ",")
|
||
}
|
||
|
||
// 处理医师资格证
|
||
var workCert string
|
||
if len(req.WorkCert) > 0 {
|
||
result := make([]string, len(req.WorkCert))
|
||
for i, url := range req.WorkCert {
|
||
result[i] = utils.RemoveOssDomain(url)
|
||
}
|
||
|
||
workCert = strings.Join(result, ",")
|
||
}
|
||
|
||
// 处理身份证图片
|
||
var idCardFront string
|
||
var idCardBack string
|
||
|
||
if req.IdCardFront != "" {
|
||
idCardFront = utils.RemoveOssDomain(req.IdCardFront)
|
||
}
|
||
if req.IdCardBack != "" {
|
||
idCardBack = utils.RemoveOssDomain(req.IdCardBack)
|
||
}
|
||
|
||
// 处理签名图片
|
||
var signImage string
|
||
if req.SignImage != "" {
|
||
signImage = utils.RemoveOssDomain(req.SignImage)
|
||
}
|
||
|
||
// 处理专长
|
||
if len(req.DoctorExpertise) > 0 {
|
||
// 检测专长是否存在
|
||
diseaseClassExpertiseDao := dao.DiseaseClassExpertiseDao{}
|
||
for _, v := range req.DoctorExpertise {
|
||
expertiseId, err := strconv.ParseInt(v, 10, 64)
|
||
if err != nil {
|
||
return false, errors.New("专长错误")
|
||
}
|
||
|
||
diseaseClassExpertise, err := diseaseClassExpertiseDao.GetDiseaseClassExpertiseById(expertiseId)
|
||
if err != nil || diseaseClassExpertise == nil {
|
||
return false, errors.New("专长数据错误")
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
// 处理银行卡省市区
|
||
areaDao := dao.AreaDao{}
|
||
var province string
|
||
if req.BankCardProvinceId != 0 {
|
||
area, err := areaDao.GetAreaById(req.BankCardProvinceId)
|
||
if err != nil || area == nil {
|
||
return false, errors.New("银行卡省份数据错误")
|
||
}
|
||
province = area.AreaName
|
||
}
|
||
|
||
var city string
|
||
if req.BankCardCityId != 0 {
|
||
area, err := areaDao.GetAreaById(req.BankCardCityId)
|
||
if err != nil || area == nil {
|
||
return false, errors.New("银行卡城市数据错误")
|
||
}
|
||
city = area.AreaName
|
||
}
|
||
|
||
var county string
|
||
if req.BankCardCountyId != 0 {
|
||
area, err := areaDao.GetAreaById(req.BankCardCountyId)
|
||
if err != nil || area == nil {
|
||
return false, errors.New("银行卡城市数据错误")
|
||
}
|
||
county = area.AreaName
|
||
}
|
||
|
||
// 处理银行卡数据
|
||
if req.BankId != "" {
|
||
bankId, err := strconv.ParseInt(req.BankId, 10, 64)
|
||
if err != nil {
|
||
return false, errors.New("银行错误")
|
||
}
|
||
|
||
basicBankDao := dao.BasicBankDao{}
|
||
basicBank, err := basicBankDao.GetBasicBankById(bankId)
|
||
if err != nil || basicBank == nil {
|
||
return false, errors.New("银行数据错误")
|
||
}
|
||
}
|
||
|
||
// 处理银行卡号掩码
|
||
var bankCardCodeMask string
|
||
if req.BankCardCode != "" {
|
||
if len(req.BankCardCode) < 8 {
|
||
return false, errors.New("银行卡号错误")
|
||
}
|
||
|
||
// 检测银行卡号
|
||
if config.C.Env == "prod" {
|
||
res, err := verifyDun.CheckBankCard(req.CardName, req.BankCardCode, req.CardNum)
|
||
if err != nil {
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
if !res {
|
||
return false, errors.New("银行卡三要素检测失败")
|
||
}
|
||
}
|
||
|
||
// 获取银行卡号的前4位和后4位
|
||
start := req.BankCardCode[:4]
|
||
end := req.BankCardCode[len(req.BankCardCode)-4:]
|
||
// 拼接前4位、中间的 * 字符串和后4位
|
||
bankCardCodeMask = start + "****" + end
|
||
}
|
||
|
||
// 是否已绑定结算银行卡
|
||
var isBindBank int
|
||
if req.BankCardProvinceId != 0 && req.BankCardCityId != 0 && req.BankCardCountyId != 0 && req.BankId != "" && req.BankCardCode != "" {
|
||
isBindBank = 1
|
||
}
|
||
|
||
// 开始事务
|
||
tx := global.Db.Begin()
|
||
defer func() {
|
||
if r := recover(); r != nil {
|
||
tx.Rollback()
|
||
}
|
||
}()
|
||
|
||
// 新增用户表数据
|
||
user := &model.User{
|
||
Email: req.Email,
|
||
UserName: req.CardName,
|
||
Mobile: req.Mobile,
|
||
WxMobile: req.Mobile,
|
||
UserType: 2,
|
||
UserStatus: 1,
|
||
RegisterMethod: 2,
|
||
Age: uint(age),
|
||
Sex: sex,
|
||
Avatar: avatar,
|
||
CreatedBy: userId,
|
||
}
|
||
user, err = userDao.AddUser(tx, user)
|
||
if err != nil || user == nil {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
// 新增医生表
|
||
userDoctor := &model.UserDoctor{
|
||
UserId: user.UserId,
|
||
UserName: req.CardName,
|
||
Status: 1,
|
||
IdcardStatus: 1, // 身份证默认审核通过
|
||
IdenAuthStatus: 2,
|
||
IsBindBank: isBindBank,
|
||
IsRecommend: req.IsRecommend,
|
||
Avatar: avatar,
|
||
DoctorTitle: req.DoctorTitle,
|
||
DepartmentCustomId: departmentCustomId,
|
||
DepartmentCustomName: req.DepartmentCustomName,
|
||
DepartmentCustomMobile: req.DepartmentCustomMobile,
|
||
HospitalID: hospitalId,
|
||
IsPlatformDeepCooperation: req.IsPlatformDeepCooperation,
|
||
IsSysDiagnoCooperation: req.IsSysDiagnoCooperation,
|
||
BeGoodAt: req.BeGoodAt,
|
||
BriefIntroduction: req.BriefIntroduction,
|
||
}
|
||
userDoctor, err = userDoctorDao.AddUserDoctor(tx, userDoctor)
|
||
if err != nil || userDoctor == nil {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
// 新增医生详情表
|
||
userDoctorInfo := &model.UserDoctorInfo{
|
||
UserId: user.UserId,
|
||
DoctorId: userDoctor.DoctorId,
|
||
CardType: 1,
|
||
CardName: req.CardName,
|
||
CardNameMask: cardNameMask,
|
||
CardNum: req.CardNum,
|
||
CardNumMask: cardNumMask,
|
||
LicenseCert: licenseCert,
|
||
QualificationCert: qualificationCert,
|
||
WorkCert: workCert,
|
||
IdCardFront: idCardFront,
|
||
IdCardBack: idCardBack,
|
||
SignImage: signImage,
|
||
}
|
||
userDoctorInfo, err = userDoctorInfoDao.AddUserDoctorInfo(tx, userDoctorInfo)
|
||
if err != nil || userDoctor == nil {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
// 新增医生银行卡表
|
||
if req.BankCardProvinceId != 0 && req.BankCardCityId != 0 && req.BankCardCountyId != 0 && req.BankId != "" && req.BankCardCode != "" {
|
||
bankId, err := strconv.ParseInt(req.BankId, 10, 64)
|
||
if err != nil {
|
||
return false, errors.New("银行错误")
|
||
}
|
||
|
||
doctorBankCard := &model.DoctorBankCard{
|
||
DoctorId: userDoctor.DoctorId,
|
||
BankId: bankId,
|
||
BankCardCode: req.BankCardCode,
|
||
BankCardCodeMask: bankCardCodeMask,
|
||
ProvinceId: req.BankCardProvinceId,
|
||
Province: province,
|
||
CityId: req.BankCardCityId,
|
||
City: city,
|
||
CountyId: req.BankCardCountyId,
|
||
County: county,
|
||
}
|
||
doctorBankCardDao := dao.DoctorBankCardDao{}
|
||
|
||
doctorBankCard, err = doctorBankCardDao.AddDoctorBankCard(tx, doctorBankCard)
|
||
if err != nil || doctorBankCard == nil {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
}
|
||
|
||
// 新增专长数据
|
||
if len(req.DoctorExpertise) > 0 {
|
||
doctorExpertiseDao := dao.DoctorExpertiseDao{}
|
||
|
||
for _, v := range req.DoctorExpertise {
|
||
expertiseId, err := strconv.ParseInt(v, 10, 64)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("专长错误")
|
||
}
|
||
|
||
// 新增专长表数据
|
||
doctorExpertise := &model.DoctorExpertise{
|
||
DoctorId: userDoctor.DoctorId,
|
||
ExpertiseId: expertiseId,
|
||
}
|
||
|
||
doctorExpertise, err = doctorExpertiseDao.AddDoctorExpertise(tx, doctorExpertise)
|
||
if err != nil || doctorExpertise == nil {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
}
|
||
}
|
||
|
||
// 创建im账户
|
||
res, err = tencentIm.CreateAccount(strconv.FormatInt(userDoctor.UserId, 10), req.CardName, req.Avatar)
|
||
if err != nil || res != true {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
tx.Commit()
|
||
return true, nil
|
||
}
|
||
|
||
// GetUserDoctorExpertiseByDoctorId 获取医生专长
|
||
func (r *UserDoctorService) GetUserDoctorExpertiseByDoctorId(doctorId int64) ([]*dto.DoctorExpertiseDto, error) {
|
||
DiseaseClassExpertiseDao := dao.DiseaseClassExpertiseDao{}
|
||
|
||
// 获取医生专长
|
||
doctorExpertiseDao := dao.DoctorExpertiseDao{}
|
||
doctorExpertises, err := doctorExpertiseDao.GetDoctorExpertiseListByDoctorId(doctorId)
|
||
if err != nil {
|
||
return nil, errors.New("用户数据错误")
|
||
}
|
||
|
||
// 处理返回值
|
||
responses := make([]*dto.DoctorExpertiseDto, len(doctorExpertises))
|
||
|
||
if len(doctorExpertises) > 0 {
|
||
for i, v := range doctorExpertises {
|
||
response := dto.GetDoctorExpertiseDto(v)
|
||
|
||
// 获取专长
|
||
diseaseClassExpertise, err := DiseaseClassExpertiseDao.GetDiseaseClassExpertiseById(v.ExpertiseId)
|
||
if err != nil || diseaseClassExpertise == nil {
|
||
return nil, errors.New("专长数据错误")
|
||
}
|
||
|
||
response.LoadExpertiseName(diseaseClassExpertise)
|
||
|
||
// 将转换后的结构体添加到新切片中
|
||
responses[i] = response
|
||
}
|
||
}
|
||
|
||
return responses, nil
|
||
}
|
||
|
||
// GetUserDoctorPending 身份审核-医生详情
|
||
func (r *UserDoctorService) GetUserDoctorPending(doctorId int64) (g *dto.UserDoctorPendingDto, err error) {
|
||
// 获取医生数据
|
||
userDoctorDao := dao.UserDoctorDao{}
|
||
userDoctor, err := userDoctorDao.GetUserDoctorPreloadById(doctorId)
|
||
if err != nil || userDoctor == nil {
|
||
return nil, errors.New("用户数据错误")
|
||
}
|
||
|
||
userDoctorService := UserDoctorService{}
|
||
|
||
// 获取医生专长
|
||
doctorExpertise, err := userDoctorService.GetUserDoctorExpertiseByDoctorId(doctorId)
|
||
|
||
// 获取医生审核失败原因
|
||
doctorIdenFailDao := dao.DoctorIdenFailDao{}
|
||
doctorIdenFail, err := doctorIdenFailDao.GetDoctorIdenFailListByDoctorId(doctorId)
|
||
if err != nil {
|
||
return nil, errors.New(err.Error())
|
||
}
|
||
|
||
// 获取医生云证书数据
|
||
userCaCertDao := dao.UserCaCertDao{}
|
||
maps := make(map[string]interface{})
|
||
maps["user_id"] = userDoctor.UserId
|
||
maps["type"] = 2
|
||
userCaCert, _ := userCaCertDao.GetUserCaCert(maps)
|
||
|
||
// 处理返回值
|
||
g = dto.GetUserDoctorPendingDto(userDoctor)
|
||
|
||
// 加载用户
|
||
g.LoadUser(userDoctor.User)
|
||
|
||
// 加载医院
|
||
g.LoadHospital(userDoctor.Hospital)
|
||
|
||
// 加载医生专长
|
||
g.DoctorExpertise = doctorExpertise
|
||
|
||
// 加载医生详情
|
||
g.LoadUserDoctorInfo(userDoctor.UserDoctorInfo)
|
||
|
||
// 加载医生审核失败原因
|
||
g.IdenAuthFailReason = dto.GetIdenAuthFailReasonDto(doctorIdenFail)
|
||
|
||
// 加载医生云证书详情
|
||
g.LoadUserCaCert(userCaCert)
|
||
|
||
return g, nil
|
||
}
|
||
|
||
// PutUserDoctorPending 身份审核-审核医生
|
||
func (r *UserDoctorService) PutUserDoctorPending(doctorId int64, req requests.PutUserDoctorPending) (bool, error) {
|
||
// 获取医生数据
|
||
userDoctorDao := dao.UserDoctorDao{}
|
||
userDoctor, err := userDoctorDao.GetUserDoctorById(doctorId)
|
||
if err != nil || userDoctor == nil {
|
||
return false, errors.New("医生数据错误")
|
||
}
|
||
|
||
// 获取医生详情数据
|
||
userDoctorInfoDao := dao.UserDoctorInfoDao{}
|
||
userDoctorInfo, err := userDoctorInfoDao.GetUserDoctorInfoByDoctorId(doctorId)
|
||
if err != nil {
|
||
return false, errors.New("医生详情数据错误")
|
||
}
|
||
|
||
// 获取用户数据
|
||
userDao := dao.UserDao{}
|
||
user, err := userDao.GetUserById(userDoctor.UserId)
|
||
if err != nil || user == nil {
|
||
return false, errors.New("医生数据错误")
|
||
}
|
||
|
||
if userDoctor.IdenAuthStatus == 1 {
|
||
return false, errors.New("已审核成功,无法进行操作")
|
||
}
|
||
|
||
// 获取医院名称
|
||
hospitalDao := dao.HospitalDao{}
|
||
hospital, err := hospitalDao.GetHospitalById(userDoctor.HospitalID)
|
||
if err != nil {
|
||
return false, errors.New("审核失败")
|
||
}
|
||
|
||
if req.IdenAuthStatus == 1 {
|
||
// 获取医生云证书数据
|
||
userCaCertDao := dao.UserCaCertDao{}
|
||
maps := make(map[string]interface{})
|
||
maps["user_id"] = userDoctor.UserId
|
||
maps["type"] = 2
|
||
_, err = userCaCertDao.GetUserCaCert(maps)
|
||
if err != nil {
|
||
return false, errors.New("请先申请云证书")
|
||
}
|
||
}
|
||
|
||
userDoctorData := make(map[string]interface{}) // 医生数据
|
||
userDoctorInfoData := make(map[string]interface{}) // 医生详情数据
|
||
|
||
if req.IdenAuthStatus == 1 && req.QualificationCertNum == "" {
|
||
return false, errors.New("缺少医师资格证号,无法审核通过")
|
||
}
|
||
|
||
if userDoctor.IdenAuthStatus == req.IdenAuthStatus {
|
||
return false, errors.New("请勿重复操作")
|
||
}
|
||
|
||
// 审核通过
|
||
if req.IdenAuthStatus == 1 {
|
||
// 处理多点审核状态
|
||
if userDoctorInfo.IdCardFront != "" && userDoctorInfo.IdCardBack != "" && userDoctorInfo.SignImage != "" && userDoctor.DepartmentCustomId != 0 {
|
||
userDoctorData["multi_point_status"] = 2
|
||
}
|
||
|
||
userDoctorData["iden_auth_status"] = 1
|
||
userDoctorInfoData["qualification_cert_num"] = req.QualificationCertNum
|
||
userDoctorData["introduction_status"] = 1
|
||
userDoctorData["introduction_time"] = time.Now().Format("2006-01-02 15:04:05")
|
||
}
|
||
|
||
// 开始事务
|
||
tx := global.Db.Begin()
|
||
defer func() {
|
||
if r := recover(); r != nil {
|
||
tx.Rollback()
|
||
}
|
||
}()
|
||
|
||
doctorIdenFailDao := dao.DoctorIdenFailDao{}
|
||
|
||
// 审核时间
|
||
userDoctorData["iden_auth_time"] = time.Now().Format("2006-01-02 15:04:05")
|
||
|
||
// 审核通过删除所有不通过原因数据
|
||
maps := make(map[string]interface{})
|
||
maps["doctor_id"] = doctorId
|
||
err = doctorIdenFailDao.DeleteDoctorIdenFail(tx, maps)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("审核失败")
|
||
}
|
||
|
||
// 审核不通过
|
||
if req.IdenAuthStatus == 3 {
|
||
userDoctorData["iden_auth_status"] = 3
|
||
|
||
if req.AvatarReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "avatar",
|
||
FailReason: req.AvatarReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
if req.DepartmentCustomMobileReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "department_custom_mobile",
|
||
FailReason: req.DepartmentCustomMobileReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
if req.DepartmentCustomNameReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "department_custom_name",
|
||
FailReason: req.DepartmentCustomNameReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
if req.BriefIntroductionReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "brief_introduction",
|
||
FailReason: req.BriefIntroductionReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
if req.BeGoodAtReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "be_good_at",
|
||
FailReason: req.BeGoodAtReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
if req.LicenseCertReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "license_cert",
|
||
FailReason: req.LicenseCertReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
if req.QualificationCertReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "qualification_cert",
|
||
FailReason: req.QualificationCertReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
if req.WorkCertReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "work_cert",
|
||
FailReason: req.WorkCertReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
}
|
||
|
||
// 修改医生数据
|
||
err = userDoctorDao.EditUserDoctorById(tx, doctorId, userDoctorData)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("审核失败")
|
||
}
|
||
|
||
// 修改医生详情数据
|
||
if len(userDoctorInfoData) != 0 {
|
||
err = userDoctorInfoDao.EditUserDoctorInfoById(tx, userDoctorInfo.DoctorInfoId, userDoctorInfoData)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("审核失败")
|
||
}
|
||
}
|
||
|
||
// 修改im数据-审核通过
|
||
if req.IdenAuthStatus == 1 {
|
||
// 更新医生im资料
|
||
profileItem := []tencentIm.ProfileItem{
|
||
{
|
||
Tag: "Tag_Profile_Custom_Hname", // 医院
|
||
Value: hospital.HospitalName,
|
||
},
|
||
{
|
||
Tag: "Tag_Profile_Custom_Title", // 职称
|
||
Value: strconv.Itoa(userDoctor.DoctorTitle),
|
||
},
|
||
}
|
||
|
||
res, err := tencentIm.SetProfile(strconv.FormatInt(userDoctor.UserId, 10), profileItem)
|
||
if err != nil || res != true {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
}
|
||
|
||
tx.Commit()
|
||
return true, nil
|
||
}
|
||
|
||
// GetMulti 多点-医生详情
|
||
func (r *UserDoctorService) GetMulti(doctorId int64) (g *dto.UserDoctorDto, err error) {
|
||
// 获取医生数据
|
||
userDoctorDao := dao.UserDoctorDao{}
|
||
userDoctor, err := userDoctorDao.GetUserDoctorPreloadById(doctorId)
|
||
if err != nil || userDoctor == nil {
|
||
return nil, errors.New("用户数据错误")
|
||
}
|
||
|
||
// 处理返回值
|
||
g = dto.GetUserDoctorDto(userDoctor)
|
||
|
||
// 加载用户
|
||
g.LoadUser(userDoctor.User)
|
||
|
||
// 加载医院
|
||
g.LoadHospital(userDoctor.Hospital)
|
||
|
||
// 加载医生详情
|
||
g.LoadUserDoctorInfo(userDoctor.UserDoctorInfo)
|
||
|
||
return g, nil
|
||
}
|
||
|
||
// PutMulti 多点-审核医生
|
||
func (r *UserDoctorService) PutMulti(doctorId int64, req requests.PutMulti) (bool, error) {
|
||
// 获取医生数据
|
||
userDoctorDao := dao.UserDoctorDao{}
|
||
userDoctor, err := userDoctorDao.GetUserDoctorById(doctorId)
|
||
if err != nil || userDoctor == nil {
|
||
return false, errors.New("医生数据错误")
|
||
}
|
||
|
||
if userDoctor.MultiPointStatus == 1 {
|
||
return false, errors.New("已审核成功,无法进行操作")
|
||
}
|
||
|
||
if userDoctor.IdenAuthStatus != 1 {
|
||
return false, errors.New("请先通过身份认证")
|
||
}
|
||
|
||
if userDoctor.MultiPointStatus == req.MultiPointStatus {
|
||
return false, errors.New("请勿重复操作")
|
||
}
|
||
|
||
// 开始事务
|
||
tx := global.Db.Begin()
|
||
defer func() {
|
||
if r := recover(); r != nil {
|
||
tx.Rollback()
|
||
}
|
||
}()
|
||
|
||
// 云证书处理-此处去掉了环境判断
|
||
if req.MultiPointStatus == 1 {
|
||
userCaCertService := UserCaCertService{}
|
||
|
||
// 检测是否存在云证书
|
||
userCaCertDao := dao.UserCaCertDao{}
|
||
|
||
maps := make(map[string]interface{})
|
||
maps["user_id"] = userDoctor.UserId
|
||
maps["type"] = 2
|
||
userCaCert, _ := userCaCertDao.GetUserCaCert(maps)
|
||
if userCaCert == nil {
|
||
// 申请云证书
|
||
_, err = userCaCertService.AddUserCloudCert(tx, userDoctor.UserId)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
} else {
|
||
if userCaCert.IsLatest == 0 {
|
||
_, err = userCaCertService.EditUserCloudCert(tx, userDoctor.UserId)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 医生修改数据
|
||
userDoctorData := make(map[string]interface{})
|
||
userDoctorData["multi_point_time"] = time.Now().Format("2006-01-02 15:04:05")
|
||
|
||
// 审核不通过
|
||
if req.MultiPointStatus == 3 {
|
||
userDoctorData["multi_point_status"] = 3
|
||
userDoctorData["multi_point_fail_reason"] = req.MultiPointFailReason
|
||
}
|
||
|
||
// 审核通过
|
||
if req.MultiPointStatus == 1 {
|
||
userDoctorData["multi_point_status"] = 1
|
||
userDoctorData["multi_point_fail_reason"] = ""
|
||
}
|
||
|
||
// 修改医生数据
|
||
err = userDoctorDao.EditUserDoctorById(tx, doctorId, userDoctorData)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("审核失败")
|
||
}
|
||
|
||
// 处理问诊配置数据
|
||
if req.MultiPointStatus == 1 {
|
||
// 审核通过后,创建问诊购药问诊配置
|
||
inquiryConfigService := InquiryConfigService{}
|
||
_, err = inquiryConfigService.HandleDoctorInquiryConfig(tx, doctorId, 4, 1, 1, 0, 0)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("审核失败")
|
||
}
|
||
|
||
}
|
||
tx.Commit()
|
||
return true, nil
|
||
}
|
||
|
||
// GetUserDoctorById 获取医生数据-医生id
|
||
func (r *UserDoctorService) GetUserDoctorById(doctorId int64) (g *dto.UserDoctorDto, err error) {
|
||
if doctorId == 0 {
|
||
return nil, nil
|
||
}
|
||
userDoctorDao := dao.UserDoctorDao{}
|
||
userDoctor, err := userDoctorDao.GetUserDoctorPreloadById(doctorId)
|
||
if err != nil || userDoctor == nil {
|
||
return nil, errors.New("医生数据错误")
|
||
}
|
||
|
||
// 处理返回值
|
||
g = dto.GetUserDoctorDto(userDoctor)
|
||
|
||
// 加载医院
|
||
g.LoadHospital(userDoctor.Hospital)
|
||
|
||
// 加载医生详情
|
||
g.LoadUserDoctorInfo(userDoctor.UserDoctorInfo)
|
||
|
||
return g, nil
|
||
}
|
||
|
||
// GetDoctorCompletedWaitEntryAmount 获取医生已完成待入账金额
|
||
func (r *UserDoctorService) GetDoctorCompletedWaitEntryAmount(doctorId int64) (g float64, err error) {
|
||
// 已完成待入账金额
|
||
var completedWaitEntryAmount = decimal.NewFromFloat(0)
|
||
|
||
// 获取医生全部已完成订单
|
||
orderInquiryDao := dao.OrderInquiryDao{}
|
||
|
||
maps := make(map[string]interface{})
|
||
maps["doctor_id"] = doctorId
|
||
maps["inquiry_status"] = 5 // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||
maps["inquiry_refund_status"] = 0 // 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||
maps["inquiry_pay_status"] = 2 // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||
maps["is_withdrawal"] = 0 // 是否提现(0:否 1:是 2:提现中)
|
||
orderInquirys, err := orderInquiryDao.GetOrderInquiryList(maps)
|
||
if err != nil {
|
||
return 0, err
|
||
}
|
||
|
||
if len(orderInquirys) > 0 {
|
||
for _, inquiry := range orderInquirys {
|
||
// 等同于math.Floor((completedWaitEntryAmount+inquiry.AmountTotal)*0.75*100) / 100
|
||
amountTotal := decimal.NewFromFloat(inquiry.AmountTotal)
|
||
completedWaitEntryAmount = completedWaitEntryAmount.Add(amountTotal)
|
||
}
|
||
}
|
||
|
||
result, _ := completedWaitEntryAmount.Mul(decimal.NewFromFloat(0.75)).Mul(decimal.NewFromFloat(100)).Floor().Div(decimal.NewFromFloat(100)).Float64()
|
||
return result, nil
|
||
}
|
||
|
||
// GetDoctorEstimateIncome 获取医生今日预计收入
|
||
func (r *UserDoctorService) GetDoctorEstimateIncome(doctorId int64) (g float64, err error) {
|
||
// 今日预计收入
|
||
var estimateIncome = decimal.NewFromFloat(0)
|
||
|
||
// 获取医生当日接诊订单金额
|
||
today := time.Now()
|
||
|
||
// 获取今天的开始时间
|
||
startOfDay := time.Date(today.Year(), today.Month(), today.Day(), 0, 0, 0, 0, today.Location())
|
||
|
||
// 获取今天的结束时间
|
||
endOfDay := time.Date(today.Year(), today.Month(), today.Day(), 23, 59, 59, 999999999, today.Location())
|
||
|
||
// 格式化为数据库的 datetime 格式
|
||
startTime := startOfDay.Format("2006-01-02 15:04:05")
|
||
endTime := endOfDay.Format("2006-01-02 15:04:05")
|
||
|
||
orderInquiryDao := dao.OrderInquiryDao{}
|
||
|
||
maps := make(map[string]interface{})
|
||
maps["doctor_id"] = doctorId
|
||
maps["inquiry_refund_status"] = 0 // 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||
maps["inquiry_pay_status"] = 2 // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||
maps["is_withdrawal"] = 0 // 是否提现(0:否 1:是 2:提现中)
|
||
maps["inquiry_status"] = []int{4, 5} // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||
orderInquirys, err := orderInquiryDao.GetOrderInquiryTimeList(maps, startTime, endTime)
|
||
if err != nil {
|
||
return 0, err
|
||
}
|
||
|
||
if len(orderInquirys) > 0 {
|
||
for _, inquiry := range orderInquirys {
|
||
// 等同于math.Floor((estimateIncome+inquiry.AmountTotal)*0.75*100) / 100
|
||
amountTotal := decimal.NewFromFloat(inquiry.AmountTotal)
|
||
estimateIncome = estimateIncome.Add(amountTotal).Mul(decimal.NewFromFloat(0.75)).Mul(decimal.NewFromFloat(100)).Floor().Div(decimal.NewFromFloat(100))
|
||
}
|
||
}
|
||
|
||
result, _ := estimateIncome.Float64()
|
||
return result, nil
|
||
}
|
||
|
||
// GetUserDoctorIntroduction 简介审核-医生详情
|
||
func (r *UserDoctorService) GetUserDoctorIntroduction(doctorId int64) (g *dto.UserDoctorIntroductionDto, err error) {
|
||
// 获取医生数据
|
||
userDoctorDao := dao.UserDoctorDao{}
|
||
userDoctor, err := userDoctorDao.GetUserDoctorPreloadById(doctorId)
|
||
if err != nil || userDoctor == nil {
|
||
return nil, errors.New("用户数据错误")
|
||
}
|
||
|
||
if userDoctor.IntroductionStatus != 2 {
|
||
return nil, errors.New("非审核数据")
|
||
}
|
||
|
||
// 获取简介审核数据
|
||
doctorIntroductionRecordDao := dao.DoctorIntroductionRecordDao{}
|
||
doctorIntroductionRecord, err := doctorIntroductionRecordDao.GetDoctorIntroductionRecordByDoctorId(userDoctor.DoctorId)
|
||
if err != nil || doctorIntroductionRecord == nil {
|
||
return nil, errors.New("用户数据错误")
|
||
}
|
||
|
||
// 处理医生专长
|
||
var expertiseIds []string
|
||
if doctorIntroductionRecord.ExpertiseIds != "" {
|
||
expertiseIds = strings.Split(doctorIntroductionRecord.ExpertiseIds, ",")
|
||
} else {
|
||
// 获取医生专长
|
||
userDoctorService := UserDoctorService{}
|
||
doctorExpertise, err := userDoctorService.GetUserDoctorExpertiseByDoctorId(doctorId)
|
||
if err != nil {
|
||
return nil, errors.New("用户数据错误")
|
||
}
|
||
|
||
for _, expertise := range doctorExpertise {
|
||
expertiseIds = append(expertiseIds, expertise.ExpertiseId)
|
||
}
|
||
}
|
||
|
||
var diseaseClassExpertiseDto []*dto.DiseaseClassExpertiseDto
|
||
diseaseClassExpertiseDao := dao.DiseaseClassExpertiseDao{}
|
||
|
||
if len(expertiseIds) > 0 {
|
||
for _, id := range expertiseIds {
|
||
// 将 id 转换为 int64 类型
|
||
expertiseId, err := strconv.ParseInt(id, 10, 64)
|
||
if err != nil {
|
||
return nil, errors.New("专长数据错误")
|
||
}
|
||
|
||
diseaseClassExpertise, err := diseaseClassExpertiseDao.GetDiseaseClassExpertiseById(expertiseId)
|
||
if err != nil || diseaseClassExpertise == nil {
|
||
return nil, errors.New("专长数据错误")
|
||
}
|
||
|
||
res := dto.GetDiseaseClassExpertiseDto(diseaseClassExpertise)
|
||
|
||
diseaseClassExpertiseDto = append(diseaseClassExpertiseDto, res)
|
||
}
|
||
}
|
||
|
||
// 处理返回值
|
||
g = dto.GetUserDoctorIntroductionDto(userDoctor)
|
||
|
||
if doctorIntroductionRecord.Avatar != "" {
|
||
g.Avatar = utils.AddOssDomain(doctorIntroductionRecord.Avatar)
|
||
}
|
||
|
||
if doctorIntroductionRecord.BeGoodAt != "" {
|
||
g.BeGoodAt = doctorIntroductionRecord.BeGoodAt
|
||
}
|
||
|
||
if doctorIntroductionRecord.BriefIntroduction != "" {
|
||
g.BriefIntroduction = doctorIntroductionRecord.BriefIntroduction
|
||
}
|
||
|
||
// 加载用户
|
||
g.LoadUser(userDoctor.User)
|
||
|
||
// 加载医院
|
||
g.LoadHospital(userDoctor.Hospital)
|
||
|
||
// 加载医生专长
|
||
g.DoctorExpertise = diseaseClassExpertiseDto
|
||
|
||
// 加载医生详情
|
||
g.LoadUserDoctorInfo(userDoctor.UserDoctorInfo)
|
||
|
||
return g, nil
|
||
}
|
||
|
||
// PutDoctorIntroduction 简介审核-审核医生
|
||
func (r *UserDoctorService) PutDoctorIntroduction(doctorId int64, req requests.PutDoctorIntroduction) (bool, error) {
|
||
// 获取医生数据
|
||
userDoctorDao := dao.UserDoctorDao{}
|
||
userDoctor, err := userDoctorDao.GetUserDoctorById(doctorId)
|
||
if err != nil || userDoctor == nil {
|
||
return false, errors.New("医生数据错误")
|
||
}
|
||
|
||
if userDoctor.IntroductionStatus == req.IntroductionStatus {
|
||
return false, errors.New("请勿重复操作")
|
||
}
|
||
|
||
if userDoctor.IntroductionStatus == 1 {
|
||
return false, errors.New("已审核成功,无法进行操作")
|
||
}
|
||
|
||
if userDoctor.IdenAuthStatus != 1 {
|
||
return false, errors.New("请先完成身份认证")
|
||
}
|
||
|
||
// 获取用户数据
|
||
userDao := dao.UserDao{}
|
||
user, err := userDao.GetUserById(userDoctor.UserId)
|
||
if err != nil || user == nil {
|
||
return false, errors.New("医生数据错误")
|
||
}
|
||
|
||
// 获取简介审核数据
|
||
doctorIntroductionRecordDao := dao.DoctorIntroductionRecordDao{}
|
||
doctorIntroductionRecord, err := doctorIntroductionRecordDao.GetDoctorIntroductionRecordByDoctorId(userDoctor.DoctorId)
|
||
if err != nil || doctorIntroductionRecord == nil {
|
||
return false, errors.New("审核失败")
|
||
}
|
||
|
||
// 开始事务
|
||
tx := global.Db.Begin()
|
||
defer func() {
|
||
if r := recover(); r != nil {
|
||
tx.Rollback()
|
||
}
|
||
}()
|
||
|
||
// 修改医生数据-审核状态
|
||
userDoctorData := make(map[string]interface{}) // 医生数据
|
||
|
||
doctorIdenFailDao := dao.DoctorIdenFailDao{}
|
||
doctorExpertiseDao := dao.DoctorExpertiseDao{}
|
||
|
||
// 审核不通过
|
||
if req.IntroductionStatus == 3 {
|
||
if req.AvatarReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "avatar",
|
||
FailReason: req.AvatarReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
if req.BriefIntroductionReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "brief_introduction",
|
||
FailReason: req.BriefIntroductionReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
if req.BeGoodAtReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "be_good_at",
|
||
FailReason: req.BeGoodAtReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
if req.DoctorExpertiseReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "doctor_expertise",
|
||
FailReason: req.DoctorExpertiseReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
}
|
||
|
||
// 审核通过
|
||
if req.IntroductionStatus == 1 {
|
||
// 审核通过删除所有不通过原因数据
|
||
maps := make(map[string]interface{})
|
||
maps["doctor_id"] = doctorId
|
||
err = doctorIdenFailDao.DeleteDoctorIdenFail(tx, maps)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("审核失败")
|
||
}
|
||
|
||
if doctorIntroductionRecord.BeGoodAt != "" {
|
||
userDoctorData["be_good_at"] = doctorIntroductionRecord.BeGoodAt
|
||
}
|
||
|
||
if doctorIntroductionRecord.BriefIntroduction != "" {
|
||
userDoctorData["brief_introduction"] = doctorIntroductionRecord.BriefIntroduction
|
||
}
|
||
|
||
// 医生专长
|
||
if doctorIntroductionRecord.ExpertiseIds != "" {
|
||
// 获取医生专长
|
||
doctorExpertises, err := doctorExpertiseDao.GetDoctorExpertiseListByDoctorId(doctorId)
|
||
if err != nil {
|
||
return false, errors.New("审核失败")
|
||
}
|
||
|
||
if len(doctorExpertises) > 0 {
|
||
// 删除医生专长
|
||
maps = make(map[string]interface{})
|
||
maps["doctor_id"] = doctorId
|
||
err = doctorExpertiseDao.DeleteDoctorExpertise(tx, maps)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("审核失败")
|
||
}
|
||
}
|
||
|
||
// 新增医生专长
|
||
expertiseIds := strings.Split(doctorIntroductionRecord.ExpertiseIds, ",")
|
||
for _, id := range expertiseIds {
|
||
// 将 id 转换为 int64 类型
|
||
expertiseId, err := strconv.ParseInt(id, 10, 64)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("审核失败")
|
||
}
|
||
|
||
doctorExpertise := &model.DoctorExpertise{
|
||
DoctorId: doctorId,
|
||
ExpertiseId: expertiseId,
|
||
}
|
||
|
||
doctorExpertise, err = doctorExpertiseDao.AddDoctorExpertise(tx, doctorExpertise)
|
||
if err != nil || doctorExpertise == nil {
|
||
tx.Rollback()
|
||
return false, errors.New("审核失败")
|
||
}
|
||
}
|
||
}
|
||
|
||
// 更新医生im资料
|
||
if doctorIntroductionRecord.Avatar != "" {
|
||
userDoctorData["avatar"] = doctorIntroductionRecord.Avatar
|
||
|
||
profileItem := []tencentIm.ProfileItem{
|
||
{
|
||
Tag: "Tag_Profile_IM_Image",
|
||
Value: utils.AddOssDomain(doctorIntroductionRecord.Avatar),
|
||
},
|
||
}
|
||
|
||
res, err := tencentIm.SetProfile(strconv.FormatInt(userDoctor.UserId, 10), profileItem)
|
||
if err != nil || res != true {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
}
|
||
|
||
// 删除审核记录表
|
||
maps = make(map[string]interface{})
|
||
maps["doctor_id"] = doctorId
|
||
err = doctorIntroductionRecordDao.DeleteDoctorIntroductionRecord(tx, maps)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("审核失败")
|
||
}
|
||
}
|
||
|
||
// 更新医生表数据
|
||
userDoctorData["introduction_status"] = req.IntroductionStatus
|
||
userDoctorData["introduction_time"] = time.Now().Format("2006-01-02 15:04:05")
|
||
err = userDoctorDao.EditUserDoctorById(tx, doctorId, userDoctorData)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("审核失败")
|
||
}
|
||
|
||
tx.Commit()
|
||
|
||
if config.C.Env == "prod" {
|
||
// 发送短信-医生修改简介审核通过
|
||
if req.IntroductionStatus == 1 {
|
||
templateParam := make(map[string]interface{})
|
||
err := aliyun.SendSms(user.Mobile, "SMS_271990126", "医生修改简介审核通过", templateParam)
|
||
if err != nil {
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
// 发送短信-医生修改简介审核拒绝
|
||
if req.IntroductionStatus == 3 {
|
||
templateParam := make(map[string]interface{})
|
||
err := aliyun.SendSms(user.Mobile, "SMS_271990126", "医生修改简介审核拒绝", templateParam)
|
||
if err != nil {
|
||
return false, err
|
||
}
|
||
}
|
||
}
|
||
|
||
return true, nil
|
||
}
|
||
|
||
// GetDoctorMultiPointEnable 获取医生多点执业状态
|
||
func (r *UserDoctorService) GetDoctorMultiPointEnable(doctorId int64) (int, error) {
|
||
doctorInquiryConfigDao := dao.DoctorInquiryConfigDao{}
|
||
userDoctorDao := dao.UserDoctorDao{}
|
||
|
||
maps := make(map[string]interface{})
|
||
maps["doctor_id"] = doctorId
|
||
maps["inquiry_type"] = 4
|
||
maps["inquiry_mode"] = 1
|
||
doctorInquiryConfig, err := doctorInquiryConfigDao.GetDoctorInquiryConfig(maps)
|
||
if err != nil || doctorInquiryConfig == nil {
|
||
return 0, nil
|
||
}
|
||
|
||
userDoctor, err := userDoctorDao.GetUserDoctorById(doctorId)
|
||
if err != nil || userDoctor == nil {
|
||
return 0, errors.New("医生数据错误")
|
||
}
|
||
|
||
if doctorInquiryConfig.IsEnable == 1 && userDoctor.MultiPointStatus == 1 {
|
||
return 1, nil
|
||
}
|
||
|
||
return 0, nil
|
||
}
|