新增简介审核-医生详情、简介审核-审核医生

This commit is contained in:
wucongxing 2024-02-19 10:28:11 +08:00
parent 3a81941cca
commit 6a4db0422e
9 changed files with 717 additions and 0 deletions

View File

@ -440,3 +440,109 @@ func (r *UserDoctor) GetUserDoctorBankCardPage(c *gin.Context) {
result["data"] = res
responses.OkWithData(result, c)
}
// GetDoctorIntroductionPage 简介审核-获取医生列表-分页
func (r *UserDoctor) GetDoctorIntroductionPage(c *gin.Context) {
userDoctorRequest := requests.UserDoctorRequest{}
req := userDoctorRequest.GetDoctorIntroductionPage
if err := c.ShouldBind(&req); err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 参数验证
if err := global.Validate.Struct(req); err != nil {
responses.FailWithMessage(utils.Translate(err), c)
return
}
if req.Page == 0 {
req.Page = 1
}
if req.PageSize == 0 {
req.PageSize = 20
}
userDoctorDao := dao.UserDoctorDao{}
userDoctor, total, err := userDoctorDao.GetDoctorIntroductionPageSearch(req, req.Page, req.PageSize)
if err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 处理返回值
res := dto.GetUserDoctorIntroductionListDto(userDoctor)
result := make(map[string]interface{})
result["page"] = userDoctorRequest.GetUserDoctorPendingPage.Page
result["page_size"] = userDoctorRequest.GetUserDoctorPendingPage.PageSize
result["total"] = total
result["data"] = res
responses.OkWithData(result, c)
}
// GetUserDoctorIntroduction 简介审核-医生详情
func (r *UserDoctor) GetUserDoctorIntroduction(c *gin.Context) {
id := c.Param("doctor_id")
if id == "" {
responses.FailWithMessage("缺少参数", c)
return
}
// 将 id 转换为 int64 类型
doctorId, err := strconv.ParseInt(id, 10, 64)
if err != nil {
responses.Fail(c)
return
}
// 业务处理
userDoctorService := service.UserDoctorService{}
g, err := userDoctorService.GetUserDoctorIntroduction(doctorId)
if err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
responses.OkWithData(g, c)
}
// PutDoctorIntroduction 简介审核-审核医生
func (r *UserDoctor) PutDoctorIntroduction(c *gin.Context) {
userDoctorRequest := requests.UserDoctorRequest{}
if err := c.ShouldBind(&userDoctorRequest.PutDoctorIntroduction); err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 参数验证
if err := global.Validate.Struct(userDoctorRequest.PutDoctorIntroduction); err != nil {
responses.FailWithMessage(utils.Translate(err), c)
return
}
id := c.Param("doctor_id")
if id == "" {
responses.FailWithMessage("缺少参数", c)
return
}
// 将 id 转换为 int64 类型
doctorId, err := strconv.ParseInt(id, 10, 64)
if err != nil {
responses.Fail(c)
return
}
// 业务处理
userDoctorService := service.UserDoctorService{}
_, err = userDoctorService.PutDoctorIntroduction(doctorId, userDoctorRequest.PutDoctorIntroduction)
if err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
responses.Ok(c)
}

View File

@ -0,0 +1,82 @@
package dao
import (
"gorm.io/gorm"
"gorm.io/gorm/clause"
"hospital-admin-api/api/model"
"hospital-admin-api/global"
)
type DoctorIntroductionRecordDao struct {
}
// GetDoctorIntroductionRecordByDoctorId 获取医生简介审核数据-医生id
func (r *DoctorIntroductionRecordDao) GetDoctorIntroductionRecordByDoctorId(doctorId int64) (m *model.DoctorIntroductionRecord, err error) {
err = global.Db.Where("doctor_id = ?", doctorId).First(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// GetDoctorIntroductionRecordPreloadById 获取医生简介审核数据-加载全部关联-医生id
func (r *DoctorIntroductionRecordDao) GetDoctorIntroductionRecordPreloadById(doctorId int64) (m *model.DoctorIntroductionRecord, err error) {
err = global.Db.Preload(clause.Associations).First(&m, doctorId).Error
if err != nil {
return nil, err
}
return m, nil
}
// EditDoctorIntroductionRecord 修改医生简介审核
func (r *DoctorIntroductionRecordDao) EditDoctorIntroductionRecord(tx *gorm.DB, maps interface{}, data interface{}) error {
err := tx.Model(&model.DoctorIntroductionRecord{}).Where(maps).Updates(data).Error
if err != nil {
return err
}
return nil
}
// EditDoctorIntroductionRecordById 修改医生简介审核-医生id
func (r *DoctorIntroductionRecordDao) EditDoctorIntroductionRecordById(tx *gorm.DB, doctorId int64, data interface{}) error {
err := tx.Model(&model.DoctorIntroductionRecord{}).Where("doctor_id = ?", doctorId).Updates(data).Error
if err != nil {
return err
}
return nil
}
// GetDoctorIntroductionRecordList 获取医生简介审核列表
func (r *DoctorIntroductionRecordDao) GetDoctorIntroductionRecordList(maps interface{}) (m []*model.DoctorIntroductionRecord, err error) {
err = global.Db.Where(maps).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// AddDoctorIntroductionRecord 新增医生简介审核
func (r *DoctorIntroductionRecordDao) AddDoctorIntroductionRecord(tx *gorm.DB, model *model.DoctorIntroductionRecord) (*model.DoctorIntroductionRecord, error) {
if err := tx.Create(model).Error; err != nil {
return nil, err
}
return model, nil
}
// GetDoctorIntroductionRecordLast 获取医生简介审核最后一条数据
func (r *DoctorIntroductionRecordDao) GetDoctorIntroductionRecordLast(maps interface{}) (m *model.DoctorIntroductionRecord, err error) {
err = global.Db.Where(maps).Last(&m).Error
if err != nil {
return nil, err
}
return m, nil
}
// DeleteDoctorIntroductionRecord 删除
func (r *DoctorIntroductionRecordDao) DeleteDoctorIntroductionRecord(tx *gorm.DB, maps interface{}) error {
err := tx.Where(maps).Delete(&model.DoctorIntroductionRecord{}).Error
if err != nil {
return err
}
return nil
}

View File

@ -555,3 +555,53 @@ func (r *UserDoctorDao) GetUserDoctorExportListSearch(req requests.UserDoctorExp
}
return m, nil
}
// GetDoctorIntroductionPageSearch 简介审核-获取医生列表-分页
func (r *UserDoctorDao) GetDoctorIntroductionPageSearch(req requests.GetDoctorIntroductionPage, page, pageSize int) (m []*model.UserDoctor, total int64, err error) {
var totalRecords int64
// 构建查询条件
query := global.Db.Model(&model.UserDoctor{}).Omit("open_id", "union_id", "wx_session_key")
// 用户
query = query.Preload("User", func(db *gorm.DB) *gorm.DB {
return db.Omit("user_password", "salt")
})
// 医院
query = query.Preload("Hospital", func(db *gorm.DB) *gorm.DB {
return db.Select("hospital_id,hospital_name,hospital_level_name")
})
// 手机号
if req.Mobile != "" {
subQuery := global.Db.Model(&model.User{}).
Select("user_id").
Where("mobile LIKE ?", "%"+req.Mobile+"%")
query = query.Where(gorm.Expr("user_id IN (?)", subQuery))
}
// 用户名称
if req.UserName != "" {
query = query.Where("user_name LIKE ?", "%"+req.UserName+"%")
}
// 个人简介审核状态
if req.IntroductionStatus == nil {
query = query.Where("introduction_status in (?)", []string{"2"})
} else {
query = query.Where("introduction_status = ?", req.IntroductionStatus)
}
// 查询总数量
if err := query.Count(&totalRecords).Error; err != nil {
return nil, 0, err
}
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
if err != nil {
return nil, 0, err
}
return m, totalRecords, nil
}

View File

@ -87,6 +87,36 @@ type UserDoctorPendingDto struct {
UserCaCert *UserCaCertDto `json:"user_ca_cert"` // ca监管证书
}
// UserDoctorIntroductionDto 简介
type UserDoctorIntroductionDto struct {
DoctorID string `json:"doctor_id"` // 主键id
UserID string `json:"user_id"` // 用户id
UserName string `json:"user_name"` // 用户名称
Status int `json:"status"` // 状态0:禁用 1:正常 2:删除)
IntroductionStatus int `json:"introduction_status"` // 个人简介审核状态0:未审核 1:审核通过 2:审核中 3:审核失败)
IntroductionTime model.LocalTime `json:"introduction_time"` // 审核时间
Avatar string `json:"avatar"` // 头像
DoctorTitle int `json:"doctor_title"` // 医生职称1:主任医师 2:主任中医师 3:副主任医师 4:副主任中医师 5:主治医师 6:住院医师)
DepartmentCustomID string `json:"department_custom_id"` // 科室id-自定义
DepartmentCustomName string `json:"department_custom_name"` // 科室名称(如未自己输入,填入标准科室名称)
DepartmentCustomMobile string `json:"department_custom_mobile"` // 科室电话
HospitalID string `json:"hospital_id"` // 所属医院id
HospitalName string `json:"hospital_name"` // 医院名称
Mobile string `json:"mobile"` // 手机号
Age uint `json:"age"` // 年龄
Sex int `json:"sex"` // 性别0:未知 1:男 2:女)
RegisterMethod int `json:"register_method"` // 注册方式1:微信小程序 2:后台添加
ApplyTime model.LocalTime `json:"apply_time"` // 申请时间
BeGoodAt string `json:"be_good_at"` // 擅长
BriefIntroduction string `json:"brief_introduction"` // 医生简介
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
User *UserDto `json:"user"` // 用户
Hospital *HospitalDto `json:"hospital"` // 医院
UserDoctorInfo *UserDoctorInfoDto `json:"user_doctor_info"` // 医生详情
DoctorExpertise []string `json:"doctor_expertise"` // 医生专长
}
func GetUserDoctorDto(m *model.UserDoctor) *UserDoctorDto {
return &UserDoctorDto{
DoctorID: fmt.Sprintf("%d", m.DoctorId),
@ -259,6 +289,68 @@ func GetUserDoctorPendingListDto(m []*model.UserDoctor) []*UserDoctorDto {
return responses
}
// GetUserDoctorIntroductionListDto 简介审核列表
func GetUserDoctorIntroductionListDto(m []*model.UserDoctor) []*UserDoctorIntroductionDto {
// 处理返回值
responses := make([]*UserDoctorIntroductionDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &UserDoctorIntroductionDto{
DoctorID: fmt.Sprintf("%d", v.DoctorId),
UserID: fmt.Sprintf("%d", v.UserId),
UserName: v.UserName,
Status: v.Status,
IntroductionStatus: v.IntroductionStatus,
IntroductionTime: v.IntroductionTime,
DoctorTitle: v.DoctorTitle,
DepartmentCustomName: v.DepartmentCustomName,
HospitalID: fmt.Sprintf("%d", v.HospitalID),
}
// 加载医院名称
if v.Hospital != nil {
response = response.LoadHospitalName(v.Hospital)
}
// 加载用户属性
if v.User != nil {
response = response.LoadUserAttr(v.User)
}
// 加载简介申请时间
response = response.LoadDoctorIntroductionApplyTime(v.IntroductionStatus)
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
// GetUserDoctorIntroductionDto 简介审核详情
func GetUserDoctorIntroductionDto(m *model.UserDoctor) *UserDoctorIntroductionDto {
return &UserDoctorIntroductionDto{
DoctorID: fmt.Sprintf("%d", m.DoctorId),
UserID: fmt.Sprintf("%d", m.UserId),
UserName: m.UserName,
Status: m.Status,
IntroductionStatus: m.IntroductionStatus,
IntroductionTime: m.IntroductionTime,
Avatar: utils.AddOssDomain(m.Avatar),
DoctorTitle: m.DoctorTitle,
DepartmentCustomID: fmt.Sprintf("%d", m.DepartmentCustomId),
DepartmentCustomName: m.DepartmentCustomName,
DepartmentCustomMobile: m.DepartmentCustomMobile,
HospitalID: fmt.Sprintf("%d", m.HospitalID),
BeGoodAt: m.BeGoodAt,
BriefIntroduction: m.BriefIntroduction,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}
// LoadUser 加载用户
func (r *UserDoctorDto) LoadUser(m *model.User) *UserDoctorDto {
if m != nil {
@ -279,6 +371,16 @@ func (r *UserDoctorPendingDto) LoadUser(m *model.User) *UserDoctorPendingDto {
return r
}
// LoadUser 加载用户
func (r *UserDoctorIntroductionDto) LoadUser(m *model.User) *UserDoctorIntroductionDto {
if m != nil {
userDto := GetUserDto(m)
r.User = userDto
}
return r
}
// LoadUserAttr 加载用户属性
func (r *UserDoctorDto) LoadUserAttr(m *model.User) *UserDoctorDto {
if m != nil {
@ -306,6 +408,14 @@ func (r *UserDoctorDto) LoadHospital(m *model.Hospital) *UserDoctorDto {
return r
}
// LoadHospital 加载医院
func (r *UserDoctorIntroductionDto) LoadHospital(m *model.Hospital) *UserDoctorIntroductionDto {
if m != nil {
r.Hospital = GetHospitalDto(m)
}
return r
}
// LoadDoctorInquiryType 加载医生服务类型
func (r *UserDoctorDto) LoadDoctorInquiryType(m []*model.DoctorInquiryConfig) *UserDoctorDto {
var inquiryTypes []string
@ -364,6 +474,14 @@ func (r *UserDoctorDto) LoadUserDoctorInfo(m *model.UserDoctorInfo) *UserDoctorD
return r
}
// LoadUserDoctorInfo 加载医生详情
func (r *UserDoctorIntroductionDto) LoadUserDoctorInfo(m *model.UserDoctorInfo) *UserDoctorIntroductionDto {
if m != nil {
r.UserDoctorInfo = GetUserDoctorInfoDto(m)
}
return r
}
// LoadUserCaCert 加载医生云证书详情
func (r *UserDoctorDto) LoadUserCaCert(m *model.UserCaCert) *UserDoctorDto {
if m != nil {
@ -424,3 +542,38 @@ func (r *UserDoctorDto) LoadUserOnline(m *model.User) *UserDoctorDto {
}
return r
}
// LoadHospitalName 加载医院名称
func (r *UserDoctorIntroductionDto) LoadHospitalName(m *model.Hospital) *UserDoctorIntroductionDto {
if m != nil {
r.HospitalName = m.HospitalName
}
return r
}
// LoadUserAttr 加载用户属性
func (r *UserDoctorIntroductionDto) LoadUserAttr(m *model.User) *UserDoctorIntroductionDto {
if m != nil {
r.Mobile = utils.MaskPhoneStr(m.Mobile)
r.RegisterMethod = m.RegisterMethod
r.Age = m.Age
r.Sex = m.Sex
}
return r
}
// LoadDoctorIntroductionApplyTime 加载简介申请时间
func (r *UserDoctorIntroductionDto) LoadDoctorIntroductionApplyTime(IntroductionStatus int) *UserDoctorIntroductionDto {
if IntroductionStatus == 2 || IntroductionStatus == 3 {
doctorIntroductionRecordDao := dao.DoctorIntroductionRecordDao{}
maps := make(map[string]interface{})
maps["doctor_id"] = r.DoctorID
maps["introduction_status"] = IntroductionStatus
doctorIntroductionRecord, _ := doctorIntroductionRecordDao.GetDoctorIntroductionRecordLast(maps)
if doctorIntroductionRecord != nil {
r.ApplyTime = doctorIntroductionRecord.CreatedAt
}
}
return r
}

View File

@ -0,0 +1,37 @@
package model
import (
"gorm.io/gorm"
"hospital-admin-api/global"
"time"
)
type DoctorIntroductionRecord struct {
RecordId int64 `gorm:"column:record_id;type:bigint(19);primary_key;comment:主键id" json:"record_id"`
DoctorId int64 `gorm:"column:doctor_id;type:bigint(19);comment:医生id;NOT NULL" json:"doctor_id"`
IntroductionStatus int `gorm:"column:introduction_status;type:tinyint(1);default:1;comment:个人简介审核状态0:未审核 1:审核通过 2:审核中 3:审核失败);NOT NULL" json:"introduction_status"`
Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"`
BeGoodAt string `gorm:"column:be_good_at;type:text;comment:擅长" json:"be_good_at"`
BriefIntroduction string `gorm:"column:brief_introduction;type:text;comment:医生简介" json:"brief_introduction"`
ExpertiseIds string `gorm:"column:expertise_ids;type:varchar(1000);comment:专长id逗号分隔" json:"expertise_ids"`
Model
UserDoctor *UserDoctor `gorm:"foreignKey:DoctorId;references:doctor_id" json:"user_doctor"` // 医生
}
func (m *DoctorIntroductionRecord) TableName() string {
return "gdxz_doctor_introduction_record"
}
func (m *DoctorIntroductionRecord) BeforeCreate(tx *gorm.DB) error {
if m.RecordId == 0 {
m.RecordId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}

View File

@ -22,6 +22,8 @@ type UserDoctor struct {
MultiPointStatus int `gorm:"column:multi_point_status;type:tinyint(1);default:0;comment:医生多点执业认证状态0:未认证 1:认证通过 2:审核中 3:认证失败)" json:"multi_point_status"`
MultiPointTime LocalTime `gorm:"column:multi_point_time;type:datetime;comment:审核时间" json:"multi_point_time"`
MultiPointFailReason string `gorm:"column:multi_point_fail_reason;type:varchar(255);comment:多点执业认证失败原因" json:"multi_point_fail_reason"`
IntroductionStatus int `gorm:"column:introduction_status;type:tinyint(1);default:0;comment:个人简介审核状态0:未审核 1:审核通过 2:审核中 3:审核失败)" json:"introduction_status"`
IntroductionTime LocalTime `gorm:"column:introduction_time;type:datetime;comment:审核时间" json:"introduction_time"`
IsBindBank int `gorm:"column:is_bind_bank;type:tinyint(1);default:0;comment:是否已绑定结算银行卡0:否 1:是);NOT NULL" json:"is_bind_bank"`
IsRecommend int `gorm:"column:is_recommend;type:tinyint(1);default:0;comment:是否首页推荐0:否 1:是)" json:"is_recommend"`
Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"`

View File

@ -12,6 +12,8 @@ type UserDoctorRequest struct {
GetUserDoctorBankCardPage // 获取医生银行卡列表-分页
UserDoctorExportList // 医生列表-导出
UserDoctorBankCardExportList // 医生银行卡列表-导出
GetDoctorIntroductionPage // 简介审核-获取医生列表-分页
PutDoctorIntroduction // 简介审核-审核医生
}
// GetUserDoctorPage 获取医生列表-分页
@ -183,3 +185,21 @@ type UserDoctorBankCardExportList struct {
BankCardCode string `json:"bank_card_code" form:"bank_card_code" label:"银行卡号"`
BankName string `json:"bank_name" form:"bank_name" label:"银行名称"`
}
// GetDoctorIntroductionPage 简介审核-获取医生列表-分页
type GetDoctorIntroductionPage struct {
Page int `json:"page" form:"page" label:"页码"`
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
Mobile string `json:"mobile" form:"mobile" label:"手机号"`
UserName string `json:"user_name" form:"user_name" label:"用户名"`
IntroductionStatus *int `json:"introduction_status" form:"introduction_status" label:"个人简介审核状态"` // 0:未审核 1:审核通过 2:审核中 3:审核失败)
}
// PutDoctorIntroduction 简介审核-审核医生
type PutDoctorIntroduction struct {
IntroductionStatus int `json:"introduction_status" form:"introduction_status" validate:"required,oneof=1 3" label:"个人简介审核状态"` // 0:未审核 1:审核通过 2:审核中 3:审核失败)
AvatarReason string `json:"avatar_reason" form:"avatar_reason" label:"头像失败原因"`
BriefIntroductionReason string `json:"brief_introduction_reason" form:"brief_introduction_reason" label:"医生简介失败原因"`
BeGoodAtReason string `json:"be_good_at_reason" form:"be_good_at_reason" label:"擅长失败原因"`
DoctorExpertiseReason string `json:"doctor_expertise_reason" form:"doctor_expertise_reason" label:"专长失败原因"`
}

View File

@ -382,6 +382,19 @@ func privateRouter(r *gin.Engine, api controller.Api) {
// 获取医生账户关联订单列表-分页
accountGroup.GET("/order", api.OrderInquiry.GetOrderInquiryForAccountPage)
}
// 简介审核列表
doctorIntroductionGroup := doctorGroup.Group("/introduction")
{
// 简介审核-获取医生列表-分页
doctorIntroductionGroup.GET("", api.UserDoctor.GetDoctorIntroductionPage)
// 简介审核-医生详情
doctorIntroductionGroup.GET("/:doctor_id", api.UserDoctor.GetUserDoctorIntroduction)
// 简介审核-审核医生
doctorIntroductionGroup.PUT("/:doctor_id", api.UserDoctor.PutDoctorIntroduction)
}
}
// 订单管理

View File

@ -9,6 +9,7 @@ import (
"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"
@ -1210,6 +1211,8 @@ func (r *UserDoctorService) PutUserDoctorPending(doctorId int64, req requests.Pu
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")
}
// 开始事务
@ -1600,3 +1603,254 @@ func (r *UserDoctorService) GetDoctorEstimateIncome(doctorId int64) (g float64,
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)
}
}
// 处理返回值
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 = expertiseIds
// 加载医生详情
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{}
// 审核不通过
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
}
// 更新医生im资料
if doctorIntroductionRecord.Avatar != "" {
userDoctorData["avatar"] = doctorIntroductionRecord.Avatar
profileItem := []tencentIm.ProfileItem{
{
Tag: "Tag_Profile_IM_Image",
Value: 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
}