新增医生问诊配置
This commit is contained in:
parent
0d93a7bffb
commit
b1ae0d2bb4
@ -120,3 +120,29 @@ func (r *InquiryConfig) PutDoctorInquiryConfig(c *gin.Context) {
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// AddDoctorInquiryConfig 新增医生问诊配置
|
||||
func (r *InquiryConfig) AddDoctorInquiryConfig(c *gin.Context) {
|
||||
inquiryConfigRequest := requests.InquiryConfigRequest{}
|
||||
req := inquiryConfigRequest.AddDoctorInquiryConfig
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
doctorInquiryConfigService := service.DoctorInquiryConfigService{}
|
||||
_, err := doctorInquiryConfigService.AddDoctorInquiryConfig(req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package requests
|
||||
type InquiryConfigRequest struct {
|
||||
GetDoctorInquiryConfigPage // 获取开启问诊配置医生列表-分页
|
||||
PutDoctorInquiryConfig // 修改医生问诊配置
|
||||
AddDoctorInquiryConfig // 新增医生问诊配置
|
||||
}
|
||||
|
||||
// GetDoctorInquiryConfigPage 获取开启问诊配置医生列表-分页
|
||||
@ -18,18 +19,29 @@ type GetDoctorInquiryConfigPage struct {
|
||||
|
||||
// PutDoctorInquiryConfig 修改医生问诊配置
|
||||
type PutDoctorInquiryConfig struct {
|
||||
DoctorId int `json:"doctor_id" form:"doctor_id"` // 医生id
|
||||
InquiryType int `json:"inquiry_type" form:"inquiry_type" label:"问诊类型"` // 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测
|
||||
InquiryMode int `json:"inquiry_mode" form:"inquiry_mode" label:"问诊方式"` // 1:图文 2:视频 3:语音 4:电话 5:会员
|
||||
WorkNumDay int `json:"work_num_day" label:"每日接诊数量"`
|
||||
InquiryPrice float64 `json:"inquiry_price" label:"接诊价格"`
|
||||
IsEnable int `json:"is_enable" form:"is_enable" label:"是否启用"` // 0:否 1:是
|
||||
PutDoctorInquiryTime []*putDoctorInquiryTime `json:"doctor_inquiry_time" form:"doctor_inquiry_time" label:"医生问诊配置-时间配置"`
|
||||
DoctorId int64 `json:"doctor_id" form:"doctor_id" validate:"required"` // 医生id
|
||||
InquiryType int `json:"inquiry_type" form:"inquiry_type" validate:"required,oneof=1 2 3 4 5" label:"问诊类型"` // 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测
|
||||
InquiryMode int `json:"inquiry_mode" form:"inquiry_mode" validate:"required,oneof=1 2 3 4 5" label:"问诊方式"` // 1:图文 2:视频 3:语音 4:电话 5:会员
|
||||
WorkNumDay int `json:"work_num_day" label:"每日接诊数量"`
|
||||
InquiryPrice float64 `json:"inquiry_price" label:"接诊价格"`
|
||||
IsEnable int `json:"is_enable" form:"is_enable" validate:"oneof=0 1" label:"是否启用"` // 0:否 1:是
|
||||
DoctorInquiryTime []*doctorInquiryTime `json:"doctor_inquiry_time" form:"doctor_inquiry_time" label:"医生问诊配置-时间配置"`
|
||||
}
|
||||
|
||||
// putDoctorInquiryConfigByTime 医生问诊配置-时间配置
|
||||
type putDoctorInquiryTime struct {
|
||||
// doctorInquiryTime 医生问诊配置-时间配置
|
||||
type doctorInquiryTime struct {
|
||||
InquiryDate string `json:"inquiry_date" form:"inquiry_date" label:"坐班日期"`
|
||||
StartTime string `json:"start_time" form:"start_time" label:"开始时间"`
|
||||
EndTime string `json:"end_time" form:"end_time" label:"结束时间"`
|
||||
}
|
||||
|
||||
// AddDoctorInquiryConfig 新增医生问诊配置
|
||||
type AddDoctorInquiryConfig struct {
|
||||
DoctorId int64 `json:"doctor_id" form:"doctor_id" validate:"required"` // 医生id
|
||||
InquiryType int `json:"inquiry_type" form:"inquiry_type" validate:"required,oneof=1 2 3 4 5" label:"问诊类型"` // 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测
|
||||
InquiryMode int `json:"inquiry_mode" form:"inquiry_mode" validate:"required,oneof=1 2 3 4 5" label:"问诊方式"` // 1:图文 2:视频 3:语音 4:电话 5:会员
|
||||
WorkNumDay int `json:"work_num_day" label:"每日接诊数量"`
|
||||
InquiryPrice float64 `json:"inquiry_price" label:"接诊价格"`
|
||||
IsEnable int `json:"is_enable" form:"is_enable" validate:"oneof=0 1" label:"是否启用"` // 0:否 1:是
|
||||
DoctorInquiryTime []*doctorInquiryTime `json:"doctor_inquiry_time" form:"doctor_inquiry_time" label:"医生问诊配置-时间配置"`
|
||||
}
|
||||
|
||||
@ -481,7 +481,7 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
doctorGroup.PUT("/:inquiry_config_id", api.InquiryConfig.PutDoctorInquiryConfig)
|
||||
|
||||
// 新增医生问诊配置
|
||||
doctorGroup.POST("", api.UserDoctor.AddUserDoctor)
|
||||
doctorGroup.POST("", api.InquiryConfig.AddDoctorInquiryConfig)
|
||||
}
|
||||
|
||||
// 系统问诊配置
|
||||
|
||||
@ -187,15 +187,15 @@ func (r *DoctorInquiryConfigService) PutDoctorInquiryConfig(inquiryConfigId int6
|
||||
|
||||
// 判断医生数据
|
||||
if userDoctor.IdcardStatus != 1 {
|
||||
return false, errors.New("请先进行实名认证")
|
||||
return false, errors.New("该医生未进行实名认证")
|
||||
}
|
||||
|
||||
if userDoctor.IdenAuthStatus != 1 {
|
||||
return false, errors.New("请先进行身份认证")
|
||||
return false, errors.New("该医生未进行身份认证")
|
||||
}
|
||||
|
||||
if userDoctor.IsBindBank != 1 {
|
||||
return false, errors.New("请先进行绑定结算银行卡")
|
||||
return false, errors.New("该医生未进行绑定结算银行卡")
|
||||
}
|
||||
|
||||
// 获取系统问诊配置
|
||||
@ -239,7 +239,7 @@ func (r *DoctorInquiryConfigService) PutDoctorInquiryConfig(inquiryConfigId int6
|
||||
|
||||
// 验证医生坐班时间
|
||||
if doctorInquiryConfig.InquiryType == 2 || doctorInquiryConfig.InquiryType == 4 {
|
||||
if userDoctor.IsPlatformDeepCooperation == 1 && len(req.PutDoctorInquiryTime) <= 0 {
|
||||
if userDoctor.IsPlatformDeepCooperation == 1 && len(req.DoctorInquiryTime) <= 0 {
|
||||
return false, errors.New("请填写坐班时间")
|
||||
}
|
||||
}
|
||||
@ -278,52 +278,216 @@ func (r *DoctorInquiryConfigService) PutDoctorInquiryConfig(inquiryConfigId int6
|
||||
}
|
||||
|
||||
// 处理医生问诊时间
|
||||
if userDoctor.IsPlatformDeepCooperation == 1 && len(req.PutDoctorInquiryTime) > 0 {
|
||||
// 获取医生问诊时间-获取一条即可,用以区分添加/删除
|
||||
doctorInquiryTimeDao := dao.DoctorInquiryTimeDao{}
|
||||
if req.InquiryType == 2 || req.InquiryType == 4 {
|
||||
if userDoctor.IsPlatformDeepCooperation == 1 && len(req.DoctorInquiryTime) > 0 {
|
||||
// 获取医生问诊时间-获取一条即可,用以区分添加/删除
|
||||
doctorInquiryTimeDao := dao.DoctorInquiryTimeDao{}
|
||||
|
||||
maps = make(map[string]interface{})
|
||||
maps["doctor_id"] = doctorInquiryConfig.DoctorId
|
||||
maps["inquiry_type"] = doctorInquiryConfig.InquiryType
|
||||
maps["inquiry_mode"] = doctorInquiryConfig.InquiryMode
|
||||
doctorInquiryTime, _ := doctorInquiryTimeDao.GetDoctorInquiryTime(maps)
|
||||
if doctorInquiryTime != nil {
|
||||
// 删除医生全部问诊时间
|
||||
maps = make(map[string]interface{})
|
||||
maps["doctor_id"] = doctorInquiryConfig.DoctorId
|
||||
maps["inquiry_type"] = doctorInquiryConfig.InquiryType
|
||||
maps["inquiry_mode"] = doctorInquiryConfig.InquiryMode
|
||||
err = doctorInquiryTimeDao.DeleteDoctorInquiryTime(tx, maps)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// 添加医生问诊时间
|
||||
for _, v := range req.PutDoctorInquiryTime {
|
||||
inquiryDate, err := time.Parse("2006-01-02", v.InquiryDate)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
doctorInquiryTime, _ := doctorInquiryTimeDao.GetDoctorInquiryTime(maps)
|
||||
if doctorInquiryTime != nil {
|
||||
// 删除医生全部问诊时间
|
||||
maps = make(map[string]interface{})
|
||||
maps["doctor_id"] = doctorInquiryConfig.DoctorId
|
||||
maps["inquiry_type"] = doctorInquiryConfig.InquiryType
|
||||
maps["inquiry_mode"] = doctorInquiryConfig.InquiryMode
|
||||
err = doctorInquiryTimeDao.DeleteDoctorInquiryTime(tx, maps)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
startTime := strings.Replace(v.StartTime, ":", "", -1)
|
||||
endTime := strings.Replace(v.EndTime, ":", "", -1)
|
||||
// 添加医生问诊时间
|
||||
for _, v := range req.DoctorInquiryTime {
|
||||
inquiryDate, err := time.Parse("2006-01-02", v.InquiryDate)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
doctorInquiryTime = &model.DoctorInquiryTime{
|
||||
DoctorId: userDoctor.DoctorId,
|
||||
InquiryType: req.InquiryType,
|
||||
InquiryMode: req.InquiryMode,
|
||||
InquiryDate: model.LocalTime(inquiryDate),
|
||||
StartTime: startTime,
|
||||
EndTime: endTime,
|
||||
}
|
||||
startTime := strings.Replace(v.StartTime, ":", "", -1)
|
||||
endTime := strings.Replace(v.EndTime, ":", "", -1)
|
||||
|
||||
doctorInquiryTime, err = doctorInquiryTimeDao.AddDoctorInquiryTime(tx, doctorInquiryTime)
|
||||
if err != nil || doctorInquiryTime == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
doctorInquiryTime = &model.DoctorInquiryTime{
|
||||
DoctorId: userDoctor.DoctorId,
|
||||
InquiryType: req.InquiryType,
|
||||
InquiryMode: req.InquiryMode,
|
||||
InquiryDate: model.LocalTime(inquiryDate),
|
||||
StartTime: startTime,
|
||||
EndTime: endTime,
|
||||
}
|
||||
|
||||
doctorInquiryTime, err = doctorInquiryTimeDao.AddDoctorInquiryTime(tx, doctorInquiryTime)
|
||||
if err != nil || doctorInquiryTime == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// AddDoctorInquiryConfig 新增医生问诊配置
|
||||
func (r *DoctorInquiryConfigService) AddDoctorInquiryConfig(req requests.AddDoctorInquiryConfig) (bool, error) {
|
||||
doctorInquiryConfigDao := dao.DoctorInquiryConfigDao{}
|
||||
|
||||
// 获取医生问诊配置
|
||||
maps := make(map[string]interface{})
|
||||
maps["doctor_id"] = req.DoctorId
|
||||
maps["inquiry_type"] = req.InquiryType
|
||||
maps["inquiry_mode"] = req.InquiryMode
|
||||
doctorInquiryConfig, err := doctorInquiryConfigDao.GetDoctorInquiryConfig(maps)
|
||||
if doctorInquiryConfig != nil {
|
||||
return false, errors.New("该医生已存在此类型问诊配置")
|
||||
}
|
||||
|
||||
// 获取医生数据
|
||||
userDoctorDao := dao.UserDoctorDao{}
|
||||
userDoctor, err := userDoctorDao.GetUserDoctorById(req.DoctorId)
|
||||
if err != nil || userDoctor == nil {
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 判断医生数据
|
||||
if userDoctor.IdcardStatus != 1 {
|
||||
return false, errors.New("该医生未进行实名认证")
|
||||
}
|
||||
|
||||
if userDoctor.IdenAuthStatus != 1 {
|
||||
return false, errors.New("该医生未进行身份认证")
|
||||
}
|
||||
|
||||
if userDoctor.IsBindBank != 1 {
|
||||
return false, errors.New("该医生未进行绑定结算银行卡")
|
||||
}
|
||||
|
||||
// 获取系统问诊配置
|
||||
systemInquiryConfigDao := dao.SystemInquiryConfigDao{}
|
||||
|
||||
maps = make(map[string]interface{})
|
||||
maps["inquiry_type"] = req.InquiryType
|
||||
maps["inquiry_mode"] = req.InquiryMode
|
||||
systemInquiryConfig, err := systemInquiryConfigDao.GetSystemInquiryConfig(maps)
|
||||
if err != nil || systemInquiryConfig == nil {
|
||||
return false, errors.New("系统问诊配置错误")
|
||||
}
|
||||
|
||||
// 验证问诊数量
|
||||
if req.WorkNumDay > systemInquiryConfig.MaxWorkNumDay {
|
||||
return false, errors.New("超出每日最大接诊数量")
|
||||
}
|
||||
|
||||
// 验证问诊价格-在线问诊
|
||||
if req.InquiryType == 1 {
|
||||
if req.InquiryPrice > systemInquiryConfig.MaxInquiryPrice || req.InquiryPrice < systemInquiryConfig.MinInquiryPrice {
|
||||
return false, errors.New("问诊价格填写错误")
|
||||
}
|
||||
}
|
||||
|
||||
// 验证问诊价格-快速问诊/问诊购药
|
||||
if req.InquiryType == 2 || req.InquiryType == 4 {
|
||||
inquiryPrice := strconv.FormatFloat(req.InquiryPrice, 'f', -1, 64)
|
||||
if inquiryPrice != systemInquiryConfig.InquiryPrice {
|
||||
return false, errors.New("问诊价格填写错误")
|
||||
}
|
||||
}
|
||||
|
||||
// 验证问诊价格-公益问诊
|
||||
if req.InquiryType == 3 {
|
||||
inquiryPrice := strconv.FormatFloat(req.InquiryPrice, 'f', -1, 64)
|
||||
if !strings.Contains(systemInquiryConfig.InquiryPrice, inquiryPrice) {
|
||||
return false, errors.New("问诊价格填写错误")
|
||||
}
|
||||
}
|
||||
|
||||
// 验证医生坐班时间
|
||||
if req.InquiryType == 2 || req.InquiryType == 4 {
|
||||
if userDoctor.IsPlatformDeepCooperation == 1 && len(req.DoctorInquiryTime) <= 0 {
|
||||
return false, errors.New("请填写坐班时间")
|
||||
}
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
// 新增医生问诊配置
|
||||
doctorInquiryConfig = &model.DoctorInquiryConfig{
|
||||
DoctorId: req.DoctorId,
|
||||
InquiryType: req.InquiryType,
|
||||
InquiryMode: req.InquiryMode,
|
||||
IsEnable: req.IsEnable,
|
||||
LastEnableMethod: 2,
|
||||
WorkNumDay: req.WorkNumDay,
|
||||
InquiryPrice: req.InquiryPrice,
|
||||
}
|
||||
|
||||
doctorInquiryConfig, err = doctorInquiryConfigDao.AddDoctorInquiryConfig(tx, doctorInquiryConfig)
|
||||
if err != nil || doctorInquiryConfig == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 处理医生问诊时间
|
||||
if req.InquiryType == 2 || req.InquiryType == 4 {
|
||||
if userDoctor.IsPlatformDeepCooperation == 1 && len(req.DoctorInquiryTime) > 0 {
|
||||
// 获取医生问诊时间-获取一条即可,用以区分添加/删除
|
||||
doctorInquiryTimeDao := dao.DoctorInquiryTimeDao{}
|
||||
|
||||
maps = make(map[string]interface{})
|
||||
maps["doctor_id"] = doctorInquiryConfig.DoctorId
|
||||
maps["inquiry_type"] = doctorInquiryConfig.InquiryType
|
||||
maps["inquiry_mode"] = doctorInquiryConfig.InquiryMode
|
||||
doctorInquiryTime, _ := doctorInquiryTimeDao.GetDoctorInquiryTime(maps)
|
||||
if doctorInquiryTime != nil {
|
||||
// 删除医生全部问诊时间
|
||||
maps = make(map[string]interface{})
|
||||
maps["doctor_id"] = doctorInquiryConfig.DoctorId
|
||||
maps["inquiry_type"] = doctorInquiryConfig.InquiryType
|
||||
maps["inquiry_mode"] = doctorInquiryConfig.InquiryMode
|
||||
err = doctorInquiryTimeDao.DeleteDoctorInquiryTime(tx, maps)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// 添加医生问诊时间
|
||||
for _, v := range req.DoctorInquiryTime {
|
||||
inquiryDate, err := time.Parse("2006-01-02", v.InquiryDate)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
startTime := strings.Replace(v.StartTime, ":", "", -1)
|
||||
endTime := strings.Replace(v.EndTime, ":", "", -1)
|
||||
|
||||
doctorInquiryTime = &model.DoctorInquiryTime{
|
||||
DoctorId: userDoctor.DoctorId,
|
||||
InquiryType: req.InquiryType,
|
||||
InquiryMode: req.InquiryMode,
|
||||
InquiryDate: model.LocalTime(inquiryDate),
|
||||
StartTime: startTime,
|
||||
EndTime: endTime,
|
||||
}
|
||||
|
||||
doctorInquiryTime, err = doctorInquiryTimeDao.AddDoctorInquiryTime(tx, doctorInquiryTime)
|
||||
if err != nil || doctorInquiryTime == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user