package dto import ( "fmt" "hospital-admin-api/api/model" "strings" ) // OrderProductDto 订单详情 type OrderProductDto struct { OrderProductId string `json:"order_product_id"` // 主键id OrderInquiryId string `json:"order_inquiry_id"` // 订单-问诊id;NOT NULL OrderPrescriptionId string `json:"order_prescription_id"` // 订单-处方id;NOT NULL OrderId string `json:"order_id"` // 订单id DoctorId string `json:"doctor_id"` // 医生id PatientId string `json:"patient_id"` // 患者id FamilyId string `json:"family_id"` // 家庭成员id(就诊用户) OrderProductNo string `json:"order_product_no"` // 订单编号 EscrowTradeNo string `json:"escrow_trade_no"` // 第三方支付流水号 OrderProductStatus int `json:"order_product_status"` // 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消) PayChannel int `json:"pay_channel"` // 支付渠道(1:小程序支付 2:微信扫码支付);NOT NULL PayStatus int `json:"pay_status"` // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款) CancelReason int `json:"cancel_reason"` // 订单取消原因(1:主动取消 2:复核失败/库存不足 3:支付超时 4:客服取消) AmountTotal float64 `json:"amount_total"` // 订单金额 PaymentAmountTotal float64 `json:"payment_amount_total"` // 实际付款金额 LogisticsFee float64 `json:"logistics_fee"` // 运费金额 LogisticsNo string `json:"logistics_no"` // 物流编号 LogisticsCompanyCode string `json:"logistics_company_code"` // 快递公司编码 DeliveryTime model.LocalTime `json:"delivery_time"` // 发货时间 PayTime model.LocalTime `json:"pay_time"` // 支付时间 Remarks string `json:"remarks"` // 订单备注 RefundStatus int `json:"refund_status"` // 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常) CancelTime model.LocalTime `json:"cancel_time"` // 订单取消时间 CancelRemarks string `json:"cancel_remarks"` // 订单取消备注(自动添加) ReportPreStatus int `json:"report_pre_status"` // 上报处方平台状态(0:未上报 1:已上报 2:上报失败)) ReportPreTime model.LocalTime `json:"report_pre_time"` // 上报处方平台时间 ReportPreFailReason string `json:"report_pre_fail_reason"` // 上报失败原因 ProvinceId int `json:"province_id"` // 省份id Province string `json:"province"` // 省份 CityId int `json:"city_id"` // 城市id City string `json:"city"` // 城市 CountyId int `json:"county_id"` // county_id County string `json:"county"` // 区县 AddressMask string `json:"address_mask"` // 详细地址(掩码) ConsigneeNameMask string `json:"consignee_name_mask"` // 收货人姓名(掩码) ConsigneeTelMask string `json:"consignee_tel_mask"` // 收货人电话(掩码) CreatedAt model.LocalTime `json:"created_at"` // 创建时间 UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间 PrescriptionCode string `json:"prescription_code"` // 处方编号 DoctorName string `json:"doctor_name"` // 医生姓名 PatientNameMask string `json:"patient_name_mask"` // 患者姓名-就诊人(掩码) PatientSex int `json:"patient_sex"` // 患者性别-就诊人(0:未知 1:男 2:女) PatientAge int `json:"patient_age"` // 患者年龄-就诊人 PatientMobile string `json:"patient_mobile"` // 患者电话 OrderProductRefund *OrderProductRefundDto `json:"order_product_refund"` // 退款数据 OrderProductItem []*OrderProductItemDto `json:"order_product_item"` // 商品数据 OrderProductLogistics *OrderProductLogisticsDto `json:"order_product_logistics"` // 物流数据 UserDoctor *UserDoctorDto `json:"user_doctor"` // 医生数据 OrderPrescription *OrderPrescriptionDto `json:"order_prescription"` // 处方数据 OrderInquiryCase *OrderInquiryCaseDto `json:"order_inquiry_case"` // 问诊病例 OrderProductCoupon *OrderProductCouponDto `json:"order_product_coupon"` // 优惠卷 ProductName string `json:"product_name"` // 药品数据 DiscountAmount float64 `json:"discount_amount"` // 优惠金额 } // OrderProductConsigneeDto 药品订单收货人数据 type OrderProductConsigneeDto struct { ProvinceId int `json:"province_id"` // 省份id Province string `json:"province"` // 省份 CityId int `json:"city_id"` // 城市id City string `json:"city"` // 城市 CountyId int `json:"county_id"` // county_id County string `json:"county"` // 区县 Address string `json:"address"` // 详细地址 ConsigneeName string `json:"consignee_name"` // 收货人姓名 ConsigneeTel string `json:"consignee_tel"` // 收货人电话 } func GetOrderProductDto(m *model.OrderProduct) *OrderProductDto { return &OrderProductDto{ OrderProductId: fmt.Sprintf("%d", m.OrderProductId), OrderInquiryId: fmt.Sprintf("%d", m.OrderInquiryId), OrderPrescriptionId: fmt.Sprintf("%d", m.OrderPrescriptionId), DoctorId: fmt.Sprintf("%d", m.DoctorId), PatientId: fmt.Sprintf("%d", m.PatientId), FamilyId: fmt.Sprintf("%d", m.FamilyId), OrderProductNo: m.OrderProductNo, EscrowTradeNo: m.EscrowTradeNo, OrderProductStatus: m.OrderProductStatus, PayChannel: m.PayChannel, PayStatus: m.PayStatus, CancelReason: m.CancelReason, AmountTotal: m.AmountTotal, PaymentAmountTotal: m.PaymentAmountTotal, LogisticsFee: m.LogisticsFee, LogisticsNo: m.LogisticsNo, LogisticsCompanyCode: m.LogisticsCompanyCode, DeliveryTime: m.DeliveryTime, PayTime: m.PayTime, Remarks: m.Remarks, RefundStatus: m.RefundStatus, CancelTime: m.CancelTime, CancelRemarks: m.CancelRemarks, ReportPreStatus: m.ReportPreStatus, ReportPreTime: m.ReportPreTime, ReportPreFailReason: m.ReportPreFailReason, ProvinceId: m.ProvinceId, Province: m.Province, CityId: m.CityId, City: m.City, CountyId: m.CountyId, County: m.County, AddressMask: m.AddressMask, ConsigneeNameMask: m.ConsigneeNameMask, ConsigneeTelMask: m.ConsigneeTelMask, CreatedAt: m.CreatedAt, UpdatedAt: m.UpdatedAt, } } // GetOrderProductConsigneeDto 药品订单收货人数据 func GetOrderProductConsigneeDto(m *model.OrderProduct) *OrderProductConsigneeDto { return &OrderProductConsigneeDto{ ProvinceId: m.ProvinceId, Province: m.Province, CityId: m.CityId, City: m.City, CountyId: m.CountyId, County: m.County, Address: m.Address, ConsigneeName: m.ConsigneeName, ConsigneeTel: m.ConsigneeTel, } } func GetOrderProductListDto(m []*model.OrderProduct) []*OrderProductDto { // 处理返回值 responses := make([]*OrderProductDto, len(m)) if len(m) > 0 { for i, v := range m { response := &OrderProductDto{ OrderProductId: fmt.Sprintf("%d", v.OrderProductId), OrderInquiryId: fmt.Sprintf("%d", v.OrderInquiryId), OrderPrescriptionId: fmt.Sprintf("%d", v.OrderPrescriptionId), DoctorId: fmt.Sprintf("%d", v.DoctorId), PatientId: fmt.Sprintf("%d", v.PatientId), FamilyId: fmt.Sprintf("%d", v.FamilyId), OrderProductNo: v.OrderProductNo, EscrowTradeNo: v.OrderProductNo, OrderProductStatus: v.OrderProductStatus, PayChannel: v.PayChannel, PayStatus: v.PayStatus, CancelReason: v.CancelReason, AmountTotal: v.AmountTotal, PaymentAmountTotal: v.PaymentAmountTotal, LogisticsFee: v.LogisticsFee, LogisticsNo: v.LogisticsNo, LogisticsCompanyCode: v.LogisticsCompanyCode, DeliveryTime: v.DeliveryTime, PayTime: v.PayTime, Remarks: v.Remarks, RefundStatus: v.RefundStatus, ReportPreStatus: v.ReportPreStatus, ConsigneeNameMask: v.ConsigneeNameMask, ConsigneeTelMask: v.ConsigneeTelMask, PatientMobile: v.UserPatient.User.Mobile, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, } // 加载医生名称 if v.UserDoctor != nil { response = response.LoadDoctorName(v.UserDoctor) } // 加载问诊属性 if v.OrderInquiry != nil { response = response.LoadOrderInquiryAttr(v.OrderInquiry) } // 加载处方编号 if v.OrderPrescription != nil { response = response.LoadOrderPrescriptionCode(v.OrderPrescription) } // 加载药品数据 if v.OrderProductItem != nil { response = response.LoadProductName(v.OrderProductItem) } // 将转换后的结构体添加到新切片中 responses[i] = response } } return responses } // LoadDoctorName 加载医生名称 func (r *OrderProductDto) LoadDoctorName(m *model.UserDoctor) *OrderProductDto { if m != nil { r.DoctorName = m.UserName } return r } // LoadOrderInquiryAttr 加载问诊属性 func (r *OrderProductDto) LoadOrderInquiryAttr(m *model.OrderInquiry) *OrderProductDto { if m != nil { r.PatientNameMask = m.PatientNameMask r.PatientSex = m.PatientSex r.PatientAge = m.PatientAge } return r } // LoadOrderPrescriptionCode 加载处方编号 func (r *OrderProductDto) LoadOrderPrescriptionCode(m *model.OrderPrescription) *OrderProductDto { if m != nil { r.PrescriptionCode = m.PrescriptionCode } return r } // LoadOrderInquiryCase 加载问诊病例 func (r *OrderProductDto) LoadOrderInquiryCase(m *model.OrderInquiryCase) *OrderProductDto { if m != nil { d := GetOrderInquiryCaseDto(m) r.OrderInquiryCase = d } return r } // LoadOrderPrescription 加载处方数据 func (r *OrderProductDto) LoadOrderPrescription(m *model.OrderPrescription) *OrderProductDto { if m != nil { d := GetOrderPrescriptionDto(m) r.OrderPrescription = d } return r } // LoadOrderProductLogistics 加载物流数据 func (r *OrderProductDto) LoadOrderProductLogistics(m *model.OrderProductLogistics) *OrderProductDto { if m != nil { d := GetOrderProductLogisticsDto(m) r.OrderProductLogistics = d } return r } // LoadOrderProductItem 加载商品数据 func (r *OrderProductDto) LoadOrderProductItem(m []*model.OrderProductItem) *OrderProductDto { if m != nil { d := GetOrderProductItemListDto(m) r.OrderProductItem = d } return r } // LoadOrderProductRefund 加载退款数据 func (r *OrderProductDto) LoadOrderProductRefund(m *model.OrderProductRefund) *OrderProductDto { if m != nil { d := GetOrderProductRefundDto(m) r.OrderProductRefund = d } return r } // LoadOrderProductCoupon 加载药品订单优惠卷数据 func (r *OrderProductDto) LoadOrderProductCoupon(m *model.OrderProductCoupon) *OrderProductDto { if m != nil { d := GetOrderProductCouponDto(m) r.OrderProductCoupon = d } return r } // LoadProductName 加载药品数据 func (r *OrderProductDto) LoadProductName(m []*model.OrderProductItem) *OrderProductDto { if len(m) > 0 { var products []string for _, item := range m { amount := fmt.Sprintf("%d", item.Amount) productPrice := fmt.Sprintf("%.2f", item.ProductPrice) product := item.ProductName + "(N:" + amount + " " + "P:" + productPrice + ")" products = append(products, product) r.ProductName = strings.Join(products, "; ") } } return r }