334 lines
9.8 KiB
Go
334 lines
9.8 KiB
Go
package service
|
|
|
|
import (
|
|
"errors"
|
|
"hospital-admin-api/api/dao"
|
|
"hospital-admin-api/api/dto"
|
|
"hospital-admin-api/api/model"
|
|
"hospital-admin-api/api/requests"
|
|
"hospital-admin-api/global"
|
|
"strconv"
|
|
)
|
|
|
|
type DoctorConfigHealthPackageService struct {
|
|
}
|
|
|
|
// GetDoctorHealth 医生健康包配置详情
|
|
func (r *DoctorConfigHealthPackageService) GetDoctorHealth(healthPackageId int64) (res *dto.DoctorConfigHealthPackageDto, err error) {
|
|
doctorConfigHealthPackageDao := dao.DoctorConfigHealthPackageDao{}
|
|
|
|
doctorConfigHealthPackage, err := doctorConfigHealthPackageDao.GetDoctorConfigHealthPackageById(healthPackageId)
|
|
if err != nil || doctorConfigHealthPackage == nil {
|
|
return nil, errors.New("获取失败")
|
|
}
|
|
|
|
// 获取医生数据
|
|
userDoctorDao := dao.UserDoctorDao{}
|
|
userDoctor, err := userDoctorDao.GetUserDoctorById(doctorConfigHealthPackage.DoctorId)
|
|
if err != nil || userDoctor == nil {
|
|
return nil, errors.New("获取失败")
|
|
}
|
|
|
|
// 获取服务包数据
|
|
healthPackageDao := dao.HealthPackageDao{}
|
|
healthPackage, err := healthPackageDao.GetHealthPackageById(doctorConfigHealthPackage.PackageId)
|
|
if err != nil || healthPackage == nil {
|
|
return nil, errors.New("获取失败")
|
|
}
|
|
|
|
// 获取医生医院数据
|
|
hospitalDao := dao.HospitalDao{}
|
|
hospital, err := hospitalDao.GetHospitalById(userDoctor.HospitalID)
|
|
|
|
// 获取医生问诊配置
|
|
doctorInquiryConfigDao := dao.DoctorInquiryConfigDao{}
|
|
maps := make(map[string]interface{})
|
|
maps["doctor_id"] = doctorConfigHealthPackage.DoctorId
|
|
maps["inquiry_type"] = 1
|
|
maps["inquiry_mode"] = 8
|
|
doctorInquiryConfig, err := doctorInquiryConfigDao.GetDoctorInquiryConfig(maps)
|
|
if err != nil {
|
|
return nil, errors.New("获取失败")
|
|
}
|
|
|
|
// 处理返回值
|
|
res = dto.GetDoctorConfigHealthPackageDto(doctorConfigHealthPackage)
|
|
|
|
// 加载医生数据
|
|
res.LoadUserDoctor(userDoctor)
|
|
|
|
// 加载医生医院
|
|
if hospital != nil {
|
|
res.LoadUserDoctorHospital(hospital)
|
|
}
|
|
|
|
if healthPackage != nil {
|
|
res.LoadHealthPackage(healthPackage)
|
|
}
|
|
|
|
// 获取医生问诊配置
|
|
res.LoadDoctorInquiryConfig(doctorInquiryConfig)
|
|
|
|
return res, nil
|
|
}
|
|
|
|
// PutDoctorHealth 修改医生健康包配置
|
|
func (r *DoctorConfigHealthPackageService) PutDoctorHealth(healthPackageId int64, req requests.PutDoctorHealth) (bool, error) {
|
|
doctorConfigHealthPackageDao := dao.DoctorConfigHealthPackageDao{}
|
|
|
|
doctorConfigHealthPackage, err := doctorConfigHealthPackageDao.GetDoctorConfigHealthPackageById(healthPackageId)
|
|
if err != nil || doctorConfigHealthPackage == nil {
|
|
return false, errors.New("修改失败")
|
|
}
|
|
|
|
// 获取医生数据
|
|
userDoctorDao := dao.UserDoctorDao{}
|
|
userDoctor, err := userDoctorDao.GetUserDoctorById(doctorConfigHealthPackage.DoctorId)
|
|
if err != nil || userDoctor == nil {
|
|
return false, errors.New("修改失败")
|
|
}
|
|
|
|
if userDoctor.IdcardStatus != 1 {
|
|
return false, errors.New("该医生未进行实名认证")
|
|
}
|
|
|
|
if userDoctor.IdenAuthStatus != 1 {
|
|
return false, errors.New("该医生未进行身份认证")
|
|
}
|
|
|
|
if userDoctor.IsBindBank != 1 {
|
|
return false, errors.New("该医生未绑定结算银行卡")
|
|
}
|
|
|
|
// 开启
|
|
if req.IsEnable == 1 {
|
|
// 获取医生多点执业状态
|
|
userDoctorService := UserDoctorService{}
|
|
|
|
multiPointStatus, _ := userDoctorService.GetDoctorMultiPointEnable(userDoctor.DoctorId)
|
|
if multiPointStatus == 0 {
|
|
return false, errors.New("该医生未开启多点执业")
|
|
}
|
|
|
|
// 获取专家图文问诊价格
|
|
maps := make(map[string]interface{})
|
|
maps["doctor_id"] = userDoctor.DoctorId
|
|
maps["inquiry_type"] = 1
|
|
maps["inquiry_mode"] = 1
|
|
|
|
doctorInquiryConfigDao := dao.DoctorInquiryConfigDao{}
|
|
doctorInquiryConfig, _ := doctorInquiryConfigDao.GetDoctorInquiryConfig(maps)
|
|
if doctorInquiryConfig == nil && req.IsEnable == 1 {
|
|
return false, errors.New("本服务需设置图文问诊的价格,才可开启")
|
|
}
|
|
}
|
|
|
|
// 开始事务
|
|
tx := global.Db.Begin()
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
tx.Rollback()
|
|
}
|
|
}()
|
|
|
|
doctorConfigHealthPackageData := make(map[string]interface{})
|
|
|
|
// 将 id 转换为 int64 类型
|
|
packageId, err := strconv.ParseInt(req.PackageId, 10, 64)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return false, errors.New("修改失败")
|
|
}
|
|
|
|
if packageId != doctorConfigHealthPackage.PackageId {
|
|
doctorConfigHealthPackageData["package_id"] = packageId
|
|
}
|
|
|
|
servicePrice, err := strconv.ParseFloat(req.ServicePrice, 64)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return false, errors.New("修改失败")
|
|
}
|
|
|
|
if servicePrice != doctorConfigHealthPackage.ServicePrice {
|
|
doctorConfigHealthPackageData["service_price"] = servicePrice
|
|
}
|
|
|
|
if len(doctorConfigHealthPackageData) > 0 {
|
|
err := doctorConfigHealthPackageDao.EditDoctorConfigHealthPackageById(tx, healthPackageId, doctorConfigHealthPackageData)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return false, errors.New("修改失败")
|
|
}
|
|
}
|
|
|
|
// 处理问诊配置
|
|
// 获取医生问诊配置
|
|
doctorInquiryConfigDao := dao.DoctorInquiryConfigDao{}
|
|
maps := make(map[string]interface{})
|
|
maps["doctor_id"] = doctorConfigHealthPackage.DoctorId
|
|
maps["inquiry_type"] = 1
|
|
maps["inquiry_mode"] = 8
|
|
doctorInquiryConfig, _ := doctorInquiryConfigDao.GetDoctorInquiryConfig(maps)
|
|
if doctorInquiryConfig == nil {
|
|
// 新增医生问诊配置
|
|
doctorInquiryConfig = &model.DoctorInquiryConfig{
|
|
DoctorId: doctorConfigHealthPackage.DoctorId,
|
|
InquiryType: 1,
|
|
InquiryMode: 8,
|
|
IsEnable: req.IsEnable,
|
|
LastEnableMethod: 2,
|
|
WorkNumDay: 0,
|
|
InquiryPrice: nil,
|
|
}
|
|
|
|
doctorInquiryConfig, err = doctorInquiryConfigDao.AddDoctorInquiryConfig(tx, doctorInquiryConfig)
|
|
if err != nil || doctorInquiryConfig == nil {
|
|
tx.Rollback()
|
|
return false, errors.New(err.Error())
|
|
}
|
|
} else {
|
|
// 修改医生问诊配置
|
|
doctorInquiryConfigData := make(map[string]interface{})
|
|
if req.IsEnable != doctorInquiryConfig.IsEnable {
|
|
doctorInquiryConfigData["is_enable"] = req.IsEnable
|
|
if req.IsEnable == 1 {
|
|
doctorInquiryConfigData["last_enable_method"] = 2
|
|
}
|
|
}
|
|
|
|
if len(doctorInquiryConfigData) > 0 {
|
|
err = doctorInquiryConfigDao.EditDoctorInquiryConfigById(tx, doctorInquiryConfig.InquiryConfigId, doctorInquiryConfigData)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return false, errors.New("修改失败")
|
|
}
|
|
}
|
|
}
|
|
|
|
tx.Commit()
|
|
return true, nil
|
|
}
|
|
|
|
// AddDoctorHealth 新增医生健康包配置
|
|
func (r *DoctorConfigHealthPackageService) AddDoctorHealth(req requests.AddDoctorHealth) (bool, error) {
|
|
// 将 id 转换为 int64 类型
|
|
packageId, err := strconv.ParseInt(req.PackageId, 10, 64)
|
|
if err != nil {
|
|
return false, errors.New("修改失败")
|
|
}
|
|
|
|
doctorId, err := strconv.ParseInt(req.DoctorId, 10, 64)
|
|
if err != nil {
|
|
return false, errors.New("修改失败")
|
|
}
|
|
|
|
// 获取医生数据
|
|
userDoctorDao := dao.UserDoctorDao{}
|
|
userDoctor, err := userDoctorDao.GetUserDoctorById(doctorId)
|
|
if err != nil || userDoctor == nil {
|
|
return false, errors.New("医生错误")
|
|
}
|
|
|
|
if userDoctor.IdcardStatus != 1 {
|
|
return false, errors.New("该医生未进行实名认证")
|
|
}
|
|
|
|
if userDoctor.IdenAuthStatus != 1 {
|
|
return false, errors.New("该医生未进行身份认证")
|
|
}
|
|
|
|
if userDoctor.IsBindBank != 1 {
|
|
return false, errors.New("该医生未绑定结算银行卡")
|
|
}
|
|
|
|
doctorConfigHealthPackageDao := dao.DoctorConfigHealthPackageDao{}
|
|
|
|
maps := make(map[string]interface{})
|
|
maps["doctor_id"] = doctorId
|
|
doctorConfigHealthPackage, err := doctorConfigHealthPackageDao.GetDoctorConfigHealthPackage(maps)
|
|
if doctorConfigHealthPackage != nil {
|
|
return false, errors.New("该医生存在健康包配置,请勿重复添加")
|
|
}
|
|
|
|
// 获取健康包配置
|
|
healthPackageDao := dao.HealthPackageDao{}
|
|
healthPackage, err := healthPackageDao.GetHealthPackagePreloadById(packageId)
|
|
if err != nil {
|
|
return false, errors.New("健康包错误")
|
|
}
|
|
|
|
// 获取专家图文问诊价格
|
|
maps = make(map[string]interface{})
|
|
maps["doctor_id"] = req.DoctorId
|
|
maps["inquiry_type"] = 1
|
|
maps["inquiry_mode"] = 1
|
|
|
|
doctorInquiryConfigDao := dao.DoctorInquiryConfigDao{}
|
|
doctorInquiryConfig, err := doctorInquiryConfigDao.GetDoctorInquiryConfig(maps)
|
|
if err != nil && req.IsEnable == 1 {
|
|
return false, errors.New("本服务需设置图文问诊的价格,才可开启")
|
|
}
|
|
|
|
// 获取医生多点执业状态
|
|
userDoctorService := UserDoctorService{}
|
|
|
|
multiPointStatus, _ := userDoctorService.GetDoctorMultiPointEnable(userDoctor.DoctorId)
|
|
if multiPointStatus == 0 {
|
|
return false, errors.New("该医生未开启多点执业")
|
|
}
|
|
|
|
// 价格计算
|
|
// 重新价格计算(专家图文问诊价格*费率+30盒35元的干爽颗粒)
|
|
serviceRate, err := strconv.ParseFloat(healthPackage.ServiceRate, 64)
|
|
if err != nil {
|
|
return false, errors.New("修改失败")
|
|
}
|
|
|
|
inquiryPrice := *doctorInquiryConfig.InquiryPrice
|
|
servicePrice := inquiryPrice*serviceRate/100*6 + healthPackage.DiscountProductTotalAmount
|
|
|
|
// 开始事务
|
|
tx := global.Db.Begin()
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
tx.Rollback()
|
|
}
|
|
}()
|
|
|
|
// 创建医生健康包
|
|
doctorConfigHealthPackage = &model.DoctorConfigHealthPackage{
|
|
DoctorId: doctorId,
|
|
PackageId: packageId,
|
|
ServicePrice: servicePrice,
|
|
}
|
|
|
|
doctorConfigHealthPackage, err = doctorConfigHealthPackageDao.AddDoctorConfigHealthPackage(tx, doctorConfigHealthPackage)
|
|
if err != nil || doctorConfigHealthPackage == nil {
|
|
tx.Rollback()
|
|
return false, errors.New(err.Error())
|
|
}
|
|
|
|
// 增加医生问诊配置
|
|
if req.IsEnable == 1 {
|
|
doctorInquiryConfig = &model.DoctorInquiryConfig{
|
|
DoctorId: doctorId,
|
|
InquiryType: 1,
|
|
InquiryMode: 8,
|
|
IsEnable: req.IsEnable,
|
|
LastEnableMethod: 2,
|
|
WorkNumDay: 0,
|
|
InquiryPrice: nil,
|
|
}
|
|
|
|
doctorInquiryConfig, err = doctorInquiryConfigDao.AddDoctorInquiryConfig(tx, doctorInquiryConfig)
|
|
if err != nil || doctorInquiryConfig == nil {
|
|
tx.Rollback()
|
|
return false, errors.New(err.Error())
|
|
}
|
|
}
|
|
|
|
tx.Commit()
|
|
return true, nil
|
|
}
|