228 lines
6.9 KiB
Go
228 lines
6.9 KiB
Go
package dto
|
||
|
||
import (
|
||
"fmt"
|
||
"hospital-admin-api/api/model"
|
||
"hospital-admin-api/utils"
|
||
"math"
|
||
)
|
||
|
||
type DoctorWithdrawalOrderDto struct {
|
||
WithdrawalOrderId string `json:"withdrawal_order_id"` // 主键id
|
||
WithdrawalId string `json:"withdrawal_id"`
|
||
DoctorId string `json:"doctor_id"` // 医生id;NOT NULL
|
||
OrderInquiryId string `json:"order_inquiry_id"` // 订单-问诊id
|
||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||
OrderInquiry *OrderInquiryDto `json:"order_inquiry"` // 关联问诊订单
|
||
UserDoctor *UserDoctorDto `json:"user_doctor"` // 关联医生
|
||
DoctorName string `json:"doctor_name"` // 医生姓名
|
||
PatientNameMask string `json:"patient_name_mask"` // 患者姓名-就诊人(掩码)
|
||
PatientSex int `json:"patient_sex"` // 患者性别-就诊人(0:未知 1:男 2:女)
|
||
PatientAge int `json:"patient_age"` // 患者年龄-就诊人
|
||
PatientMobileMask string `json:"patient_mobile_mask"` // 患者电话(掩码)
|
||
DoctorAmount float64 `json:"doctor_amount"` // 医生收益
|
||
PayChannel int `json:"pay_channel"` // 支付渠道(1:小程序支付 2:微信扫码支付 3:模拟支付)
|
||
PayTime model.LocalTime `json:"pay_time"` // 支付时间
|
||
InquiryNo string `json:"inquiry_no"` // 系统订单编号
|
||
OrderNo string `json:"order_no"` // 系统订单编号
|
||
EscrowTradeNo string `json:"escrow_trade_no"` // 第三方支付流水号
|
||
InquiryStatus int `json:"inquiry_status"` // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||
}
|
||
|
||
func GetDoctorWithdrawalOrderDto(m *model.DoctorWithdrawalOrder) *DoctorWithdrawalOrderDto {
|
||
return &DoctorWithdrawalOrderDto{
|
||
WithdrawalOrderId: fmt.Sprintf("%d", m.WithdrawalOrderId),
|
||
WithdrawalId: fmt.Sprintf("%d", m.WithdrawalId),
|
||
DoctorId: fmt.Sprintf("%d", m.DoctorId),
|
||
OrderInquiryId: fmt.Sprintf("%d", m.OrderInquiryId),
|
||
CreatedAt: m.CreatedAt,
|
||
UpdatedAt: m.UpdatedAt,
|
||
}
|
||
}
|
||
|
||
func GetDoctorWithdrawalOrderListDto(m []*model.DoctorWithdrawalOrder) []*DoctorWithdrawalOrderDto {
|
||
// 处理返回值
|
||
responses := make([]*DoctorWithdrawalOrderDto, len(m))
|
||
|
||
if len(m) > 0 {
|
||
for i, v := range m {
|
||
response := &DoctorWithdrawalOrderDto{
|
||
WithdrawalOrderId: fmt.Sprintf("%d", v.WithdrawalOrderId),
|
||
WithdrawalId: fmt.Sprintf("%d", v.WithdrawalId),
|
||
DoctorId: fmt.Sprintf("%d", v.DoctorId),
|
||
OrderInquiryId: fmt.Sprintf("%d", v.OrderInquiryId),
|
||
CreatedAt: v.CreatedAt,
|
||
UpdatedAt: v.UpdatedAt,
|
||
}
|
||
|
||
// 加载医生名称
|
||
if v.UserDoctor != nil {
|
||
response.LoadDoctorName(v.UserDoctor)
|
||
}
|
||
|
||
// 加载患者姓名-就诊人(掩码)
|
||
response.LoadPatientNameMask(v.Order)
|
||
|
||
// 加载患者性别-就诊人
|
||
response.LoadPatientSex(v.Order)
|
||
|
||
// 加载患者年龄-就诊人
|
||
response.LoadPatientAge(v.Order)
|
||
|
||
// 加载患者电话(掩码)
|
||
if v.Order.User != nil {
|
||
response.LoadPatientMobileMask(v.Order.User)
|
||
}
|
||
|
||
// 加载支付渠道
|
||
if v.Order != nil {
|
||
response.LoadPayChannel(v.Order)
|
||
}
|
||
|
||
// 加载支付时间
|
||
if v.Order != nil {
|
||
response.LoadPayTime(v.Order)
|
||
}
|
||
|
||
// 加载系统订单编号
|
||
if v.Order != nil {
|
||
response.LoadInquiryNo(v.Order)
|
||
response.LoadOrderNo(v.Order)
|
||
}
|
||
|
||
// 加载第三方支付流水号
|
||
if v.Order != nil {
|
||
response.LoadEscrowTradeNo(v.Order)
|
||
}
|
||
|
||
// 加载问诊订单状态
|
||
if v.Order.OrderInquiry != nil {
|
||
response.LoadInquiryStatus(v.Order.OrderInquiry)
|
||
}
|
||
|
||
// 加载医生收益
|
||
if v.Order.OrderInquiry != nil {
|
||
response.LoadDoctorAmount(v.Order.OrderInquiry)
|
||
}
|
||
|
||
// 将转换后的结构体添加到新切片中
|
||
responses[i] = response
|
||
}
|
||
}
|
||
|
||
return responses
|
||
}
|
||
|
||
// LoadDoctorName 加载医生名称
|
||
func (r *DoctorWithdrawalOrderDto) LoadDoctorName(m *model.UserDoctor) *DoctorWithdrawalOrderDto {
|
||
if m != nil {
|
||
r.DoctorName = m.UserName
|
||
}
|
||
return r
|
||
}
|
||
|
||
// LoadPatientNameMask 加载患者姓名-就诊人(掩码)
|
||
func (r *DoctorWithdrawalOrderDto) LoadPatientNameMask(m *model.Order) *DoctorWithdrawalOrderDto {
|
||
if m.OrderInquiry != nil {
|
||
r.PatientNameMask = m.OrderInquiry.PatientNameMask
|
||
}
|
||
|
||
if m.OrderServicePackage != nil {
|
||
r.PatientNameMask = m.OrderServicePackage.PatientNameMask
|
||
}
|
||
|
||
return r
|
||
}
|
||
|
||
// LoadPatientSex 加载患者性别-就诊人
|
||
func (r *DoctorWithdrawalOrderDto) LoadPatientSex(m *model.Order) *DoctorWithdrawalOrderDto {
|
||
if m.OrderInquiry != nil {
|
||
r.PatientSex = m.OrderInquiry.PatientSex
|
||
}
|
||
|
||
if m.OrderServicePackage != nil {
|
||
r.PatientSex = m.OrderServicePackage.PatientSex
|
||
}
|
||
|
||
return r
|
||
}
|
||
|
||
// LoadPatientAge 加载患者年龄-就诊人
|
||
func (r *DoctorWithdrawalOrderDto) LoadPatientAge(m *model.Order) *DoctorWithdrawalOrderDto {
|
||
if m.OrderInquiry != nil {
|
||
r.PatientAge = m.OrderInquiry.PatientAge
|
||
}
|
||
|
||
if m.OrderServicePackage != nil {
|
||
r.PatientAge = m.OrderServicePackage.PatientAge
|
||
}
|
||
|
||
return r
|
||
}
|
||
|
||
// LoadPatientMobileMask 加载患者电话(掩码)
|
||
func (r *DoctorWithdrawalOrderDto) LoadPatientMobileMask(m *model.User) *DoctorWithdrawalOrderDto {
|
||
if m != nil {
|
||
r.PatientMobileMask = utils.MaskPhoneStr(m.Mobile)
|
||
}
|
||
|
||
return r
|
||
}
|
||
|
||
// LoadPayChannel 加载支付渠道
|
||
func (r *DoctorWithdrawalOrderDto) LoadPayChannel(m *model.Order) *DoctorWithdrawalOrderDto {
|
||
if m != nil {
|
||
r.PayChannel = m.PayChannel
|
||
}
|
||
return r
|
||
}
|
||
|
||
// LoadPayTime 加载支付时间
|
||
func (r *DoctorWithdrawalOrderDto) LoadPayTime(m *model.Order) *DoctorWithdrawalOrderDto {
|
||
if m != nil {
|
||
r.PayTime = m.PayTime
|
||
}
|
||
return r
|
||
}
|
||
|
||
// LoadInquiryNo 加载系统订单编号
|
||
func (r *DoctorWithdrawalOrderDto) LoadInquiryNo(m *model.Order) *DoctorWithdrawalOrderDto {
|
||
if m != nil {
|
||
r.InquiryNo = m.OrderNo
|
||
}
|
||
return r
|
||
}
|
||
|
||
// LoadOrderNo 加载系统订单编号
|
||
func (r *DoctorWithdrawalOrderDto) LoadOrderNo(m *model.Order) *DoctorWithdrawalOrderDto {
|
||
if m != nil {
|
||
r.OrderNo = m.OrderNo
|
||
}
|
||
return r
|
||
}
|
||
|
||
// LoadEscrowTradeNo 加载第三方支付流水号
|
||
func (r *DoctorWithdrawalOrderDto) LoadEscrowTradeNo(m *model.Order) *DoctorWithdrawalOrderDto {
|
||
if m != nil {
|
||
r.EscrowTradeNo = m.EscrowTradeNo
|
||
}
|
||
return r
|
||
}
|
||
|
||
// LoadInquiryStatus 加载问诊订单状态
|
||
func (r *DoctorWithdrawalOrderDto) LoadInquiryStatus(m *model.OrderInquiry) *DoctorWithdrawalOrderDto {
|
||
if m != nil {
|
||
r.InquiryStatus = m.InquiryStatus
|
||
}
|
||
return r
|
||
}
|
||
|
||
// LoadDoctorAmount 加载医生收益
|
||
func (r *DoctorWithdrawalOrderDto) LoadDoctorAmount(m *model.OrderInquiry) *DoctorWithdrawalOrderDto {
|
||
if m != nil {
|
||
r.DoctorAmount = math.Floor(m.AmountTotal*0.75*100000) / 100000
|
||
}
|
||
return r
|
||
}
|