hospital-admin-api/api/service/DoctorAccount.go
2023-11-14 14:43:39 +08:00

107 lines
3.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package service
import (
"errors"
"hospital-admin-api/api/dao"
"hospital-admin-api/api/dto"
"math"
"time"
)
// DoctorAccountService 医生账户
type DoctorAccountService struct {
}
// GetDoctorAccount 提现详情
func (r *DoctorAccountService) GetDoctorAccount(doctorId int64) (g *dto.DoctorAccountDto, err error) {
doctorAccountDao := dao.DoctorAccountDao{}
doctorAccount, err := doctorAccountDao.GetDoctorAccountByDoctorId(doctorId)
if doctorAccount == nil {
return nil, errors.New("数据错误")
}
// 医生数据
userDoctorDao := dao.UserDoctorDao{}
userDoctor, err := userDoctorDao.GetUserDoctorById(doctorAccount.DoctorId)
if err != nil {
return nil, errors.New(err.Error())
}
// 医生用户数据
userDao := dao.UserDao{}
user, err := userDao.GetUserById(userDoctor.UserId)
if err != nil {
return nil, errors.New(err.Error())
}
// 已完成待入账金额
var completedWaitEntryAmount float64
// 今日预计收入
var estimateIncome float64
// 获取医生全部已完成订单
orderInquiryDao := dao.OrderInquiryDao{}
maps := make(map[string]interface{})
maps["doctor_id"] = userDoctor.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 nil, err
}
if len(orderInquirys) > 0 {
for _, inquiry := range orderInquirys {
completedWaitEntryAmount = math.Floor((completedWaitEntryAmount+inquiry.AmountTotal)*0.75*100) / 100
}
}
// 获取医生当日接诊订单金额
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")
maps = make(map[string]interface{})
maps["doctor_id"] = userDoctor.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 nil, err
}
if len(orderInquirys) > 0 {
for _, inquiry := range orderInquirys {
estimateIncome = math.Floor((estimateIncome+inquiry.AmountTotal)*0.75*100) / 100
}
}
// 处理返回值
g = dto.GetDoctorAccountDto(doctorAccount)
// 加载医生名称
g.LoadDoctorName(userDoctor)
// 加载医生手机号(掩码)
g.LoadDoctorMobileMask(user)
g.CompletedWaitEntryAmount = completedWaitEntryAmount
g.EstimateIncome = estimateIncome
return g, nil
}