hospital-admin-api/api/dto/DoctorAccount.go

93 lines
3.5 KiB
Go

package dto
import (
"fmt"
"hospital-admin-api/api/model"
"hospital-admin-api/utils"
"math"
)
type DoctorAccountDto struct {
AccountId string `json:"account_id"` // 账户id
DoctorId string `json:"doctor_id"` // 医生id
TotalAmount float64 `json:"total_amount"` // 总金额(已结束订单的总金额)
BalanceAccount float64 `json:"balance_account"` // 账户余额
AppliedWithdrawalAmount float64 `json:"applied_withdrawal_amount"` // 提现金额
ActualWithdrawalAmount float64 `json:"actual_withdrawal_amount"` // 实际提现金额
IncomeTax float64 `json:"income_tax"`
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
DoctorName string `json:"doctor_name"` // 医生姓名
DoctorMobileMask string `json:"doctor_mobile_mask"` // 医生手机号(掩码)
CompletedWaitEntryAmount float64 `json:"completed_wait_entry_amount"` // 已完成待入账金额
EstimateIncome float64 `json:"estimate_income"` // 今日预计收入
}
func GetDoctorAccountDto(m *model.DoctorAccount) *DoctorAccountDto {
return &DoctorAccountDto{
AccountId: fmt.Sprintf("%d", m.AccountId),
DoctorId: fmt.Sprintf("%d", m.DoctorId),
TotalAmount: math.Floor(m.TotalAmount*100) / 100,
BalanceAccount: math.Floor(m.BalanceAccount*100) / 100,
AppliedWithdrawalAmount: math.Floor(m.AppliedWithdrawalAmount*100) / 100,
ActualWithdrawalAmount: math.Floor(m.ActualWithdrawalAmount*100) / 100,
IncomeTax: math.Floor(m.IncomeTax*100) / 100,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}
func GetDoctorAccountListDto(m []*model.DoctorAccount) []*DoctorAccountDto {
// 处理返回值
responses := make([]*DoctorAccountDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &DoctorAccountDto{
AccountId: fmt.Sprintf("%d", v.AccountId),
DoctorId: fmt.Sprintf("%d", v.DoctorId),
TotalAmount: math.Floor(v.TotalAmount*100) / 100,
BalanceAccount: math.Floor(v.BalanceAccount*100) / 100,
AppliedWithdrawalAmount: math.Floor(v.AppliedWithdrawalAmount*100) / 100,
ActualWithdrawalAmount: math.Floor(v.ActualWithdrawalAmount*100) / 100,
IncomeTax: math.Floor(v.IncomeTax*100) / 100,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 加载医生名称
if v.UserDoctor != nil {
response.LoadDoctorName(v.UserDoctor)
// 加载医生手机号(掩码)
if v.UserDoctor.User != nil {
response.LoadDoctorMobileMask(v.UserDoctor.User)
}
}
// 加载医生已完成待入账金额
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
// LoadDoctorName 加载医生名称
func (r *DoctorAccountDto) LoadDoctorName(m *model.UserDoctor) *DoctorAccountDto {
if m != nil {
r.DoctorName = m.UserName
}
return r
}
// LoadDoctorMobileMask 加载医生手机号(掩码)
func (r *DoctorAccountDto) LoadDoctorMobileMask(m *model.User) *DoctorAccountDto {
if m != nil {
r.DoctorMobileMask = utils.MaskPhoneStr(m.Mobile)
}
return r
}