diff --git a/api/dao/orderProduct.go b/api/dao/orderProduct.go index e72d137..91aeb9c 100644 --- a/api/dao/orderProduct.go +++ b/api/dao/orderProduct.go @@ -92,6 +92,9 @@ func (r *OrderProductDao) GetOrderProductPageSearch(req requests.GetOrderProduct // 构建查询条件 query := global.Db.Model(&model.OrderProduct{}) + // 药品数据 + query = query.Preload("OrderProductItem") + // 医生 query = query.Preload("UserDoctor", func(db *gorm.DB) *gorm.DB { return db.Omit("open_id", "union_id", "wx_session_key") diff --git a/api/dto/OrderProduct.go b/api/dto/OrderProduct.go index 313f297..e4e37b1 100644 --- a/api/dto/OrderProduct.go +++ b/api/dto/OrderProduct.go @@ -3,6 +3,7 @@ package dto import ( "fmt" "hospital-admin-api/api/model" + "strings" ) // OrderProductDto 订单详情 @@ -58,6 +59,7 @@ type OrderProductDto struct { OrderPrescription *OrderPrescriptionDto `json:"order_prescription"` // 处方数据 OrderInquiryCase *OrderInquiryCaseDto `json:"order_inquiry_case"` // 问诊病例 OrderProductCoupon *OrderProductCouponDto `json:"order_product_coupon"` // 优惠卷 + ProductName string `json:"product_name"` // 药品数据 } // OrderProductConsigneeDto 药品订单收货人数据 @@ -115,8 +117,8 @@ func GetOrderProductDto(m *model.OrderProduct) *OrderProductDto { } } -// GetOrderProductConsigneeDtoDto 药品订单收货人数据 -func GetOrderProductConsigneeDtoDto(m *model.OrderProduct) *OrderProductConsigneeDto { +// GetOrderProductConsigneeDto 药品订单收货人数据 +func GetOrderProductConsigneeDto(m *model.OrderProduct) *OrderProductConsigneeDto { return &OrderProductConsigneeDto{ ProvinceId: m.ProvinceId, Province: m.Province, @@ -181,6 +183,11 @@ func GetOrderProductListDto(m []*model.OrderProduct) []*OrderProductDto { response = response.LoadOrderPrescriptionCode(v.OrderPrescription) } + // 加载药品数据 + if v.OrderProductItem != nil { + response = response.LoadProductName(v.OrderProductItem) + } + // 将转换后的结构体添加到新切片中 responses[i] = response } @@ -274,3 +281,21 @@ func (r *OrderProductDto) LoadOrderProductCoupon(m *model.OrderProductCoupon) *O } 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 +} diff --git a/api/model/orderProduct.go b/api/model/orderProduct.go index bbd63f9..f4d27c0 100644 --- a/api/model/orderProduct.go +++ b/api/model/orderProduct.go @@ -8,51 +8,52 @@ import ( // OrderProduct 订单-商品订单表 type OrderProduct struct { - OrderProductId int64 `gorm:"column:order_product_id;type:bigint(20);primary_key;comment:主键id" json:"order_product_id"` - OrderInquiryId int64 `gorm:"column:order_inquiry_id;type:bigint(19);comment:订单-问诊id;NOT NULL" json:"order_inquiry_id"` - OrderPrescriptionId int64 `gorm:"column:order_prescription_id;type:bigint(19);comment:订单-处方id;NOT NULL" json:"order_prescription_id"` - OrderId int64 `gorm:"column:order_id;type:bigint(19);comment:订单id" json:"order_id"` - DoctorId int64 `gorm:"column:doctor_id;type:bigint(19);comment:医生id" json:"doctor_id"` - PatientId int64 `gorm:"column:patient_id;type:bigint(19);comment:患者id" json:"patient_id"` - FamilyId int64 `gorm:"column:family_id;type:bigint(19);comment:家庭成员id(就诊用户)" json:"family_id"` - OrderProductNo string `gorm:"column:order_product_no;type:varchar(100);comment:订单编号" json:"order_product_no"` - EscrowTradeNo string `gorm:"column:escrow_trade_no;type:varchar(100);comment:第三方支付流水号" json:"escrow_trade_no"` - OrderProductStatus int `gorm:"column:order_product_status;type:tinyint(1);comment:订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)" json:"order_product_status"` - PayChannel int `gorm:"column:pay_channel;type:tinyint(1);comment:支付渠道(1:小程序支付 2:微信扫码支付);NOT NULL" json:"pay_channel"` - PayStatus int `gorm:"column:pay_status;type:tinyint(4);default:1;comment:支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)" json:"pay_status"` - IsDelete int `gorm:"column:is_delete;type:tinyint(1);default:0;comment:删除状态(0:否 1:是)" json:"is_delete"` - CancelReason int `gorm:"column:cancel_reason;type:tinyint(1);comment:订单取消原因(1:主动取消 2:复核失败/库存不足 3:支付超时 4:客服取消)" json:"cancel_reason"` - AmountTotal float64 `gorm:"column:amount_total;type:decimal(10,2);default:0.00;comment:订单金额" json:"amount_total"` - PaymentAmountTotal float64 `gorm:"column:payment_amount_total;type:decimal(10,2);default:0.00;comment:实际付款金额" json:"payment_amount_total"` - LogisticsFee float64 `gorm:"column:logistics_fee;type:decimal(10,2);default:0.00;comment:运费金额" json:"logistics_fee"` - LogisticsNo string `gorm:"column:logistics_no;type:varchar(100);comment:物流编号" json:"logistics_no"` - LogisticsCompanyCode string `gorm:"column:logistics_company_code;type:varchar(255);comment:快递公司编码" json:"logistics_company_code"` - SubLogisticsStatus int `gorm:"column:sub_logistics_status;type:tinyint(1);default:0;comment:快递推送订阅状态(0:未订阅/无需订阅 1:已订阅 2:订阅失败)" json:"sub_logistics_status"` - DeliveryTime LocalTime `gorm:"column:delivery_time;type:datetime;comment:发货时间" json:"delivery_time"` - PayTime LocalTime `gorm:"column:pay_time;type:datetime;comment:支付时间" json:"pay_time"` - Remarks string `gorm:"column:remarks;type:varchar(255);comment:订单备注" json:"remarks"` - RefundStatus int `gorm:"column:refund_status;type:tinyint(1);default:0;comment:商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)" json:"refund_status"` - CancelTime LocalTime `gorm:"column:cancel_time;type:datetime;comment:订单取消时间" json:"cancel_time"` - CancelRemarks string `gorm:"column:cancel_remarks;type:varchar(255);comment:订单取消备注(自动添加)" json:"cancel_remarks"` - ReportPreStatus int `gorm:"column:report_pre_status;type:tinyint(1);default:0;comment:上报处方平台状态(0:未上报 1:已上报 2:上报失败))" json:"report_pre_status"` - ReportPreTime LocalTime `gorm:"column:report_pre_time;type:datetime;comment:上报处方平台时间" json:"report_pre_time"` - ReportPreFailReason string `gorm:"column:report_pre_fail_reason;type:text;comment:上报失败原因" json:"report_pre_fail_reason"` - ProvinceId int `gorm:"column:province_id;type:int(11);comment:省份id" json:"province_id"` - Province string `gorm:"column:province;type:varchar(40);comment:省份" json:"province"` - CityId int `gorm:"column:city_id;type:int(11);comment:城市id" json:"city_id"` - City string `gorm:"column:city;type:varchar(50);comment:城市" json:"city"` - CountyId int `gorm:"column:county_id;type:int(11);comment:区县id" json:"county_id"` - County string `gorm:"column:county;type:varchar(255);comment:区县" json:"county"` - Address string `gorm:"column:address;type:varchar(255);comment:详细地址" json:"address"` - AddressMask string `gorm:"column:address_mask;type:varchar(255);comment:详细地址(掩码)" json:"address_mask"` - ConsigneeName string `gorm:"column:consignee_name;type:varchar(150);comment:收货人姓名" json:"consignee_name"` - ConsigneeNameMask string `gorm:"column:consignee_name_mask;type:varchar(150);comment:收货人姓名(掩码)" json:"consignee_name_mask"` - ConsigneeTel string `gorm:"column:consignee_tel;type:varchar(50);comment:收货人电话" json:"consignee_tel"` - ConsigneeTelMask string `gorm:"column:consignee_tel_mask;type:varchar(50);comment:收货人电话(掩码)" json:"consignee_tel_mask"` - UserDoctor *UserDoctor `gorm:"foreignKey:DoctorId;references:doctor_id" json:"user_doctor"` // 医生 - OrderInquiry *OrderInquiry `gorm:"foreignKey:OrderInquiryId;references:order_inquiry_id" json:"order_inquiry"` // 问诊 - UserPatient *UserPatient `gorm:"foreignKey:PatientId;references:patient_id" json:"user_patient"` // 患者 - OrderPrescription *OrderPrescription `gorm:"foreignKey:OrderPrescriptionId;references:order_prescription_id" json:"order_prescription"` // 处方 + OrderProductId int64 `gorm:"column:order_product_id;type:bigint(20);primary_key;comment:主键id" json:"order_product_id"` + OrderInquiryId int64 `gorm:"column:order_inquiry_id;type:bigint(19);comment:订单-问诊id;NOT NULL" json:"order_inquiry_id"` + OrderPrescriptionId int64 `gorm:"column:order_prescription_id;type:bigint(19);comment:订单-处方id;NOT NULL" json:"order_prescription_id"` + OrderId int64 `gorm:"column:order_id;type:bigint(19);comment:订单id" json:"order_id"` + DoctorId int64 `gorm:"column:doctor_id;type:bigint(19);comment:医生id" json:"doctor_id"` + PatientId int64 `gorm:"column:patient_id;type:bigint(19);comment:患者id" json:"patient_id"` + FamilyId int64 `gorm:"column:family_id;type:bigint(19);comment:家庭成员id(就诊用户)" json:"family_id"` + OrderProductNo string `gorm:"column:order_product_no;type:varchar(100);comment:订单编号" json:"order_product_no"` + EscrowTradeNo string `gorm:"column:escrow_trade_no;type:varchar(100);comment:第三方支付流水号" json:"escrow_trade_no"` + OrderProductStatus int `gorm:"column:order_product_status;type:tinyint(1);comment:订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)" json:"order_product_status"` + PayChannel int `gorm:"column:pay_channel;type:tinyint(1);comment:支付渠道(1:小程序支付 2:微信扫码支付);NOT NULL" json:"pay_channel"` + PayStatus int `gorm:"column:pay_status;type:tinyint(4);default:1;comment:支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)" json:"pay_status"` + IsDelete int `gorm:"column:is_delete;type:tinyint(1);default:0;comment:删除状态(0:否 1:是)" json:"is_delete"` + CancelReason int `gorm:"column:cancel_reason;type:tinyint(1);comment:订单取消原因(1:主动取消 2:复核失败/库存不足 3:支付超时 4:客服取消)" json:"cancel_reason"` + AmountTotal float64 `gorm:"column:amount_total;type:decimal(10,2);default:0.00;comment:订单金额" json:"amount_total"` + PaymentAmountTotal float64 `gorm:"column:payment_amount_total;type:decimal(10,2);default:0.00;comment:实际付款金额" json:"payment_amount_total"` + LogisticsFee float64 `gorm:"column:logistics_fee;type:decimal(10,2);default:0.00;comment:运费金额" json:"logistics_fee"` + LogisticsNo string `gorm:"column:logistics_no;type:varchar(100);comment:物流编号" json:"logistics_no"` + LogisticsCompanyCode string `gorm:"column:logistics_company_code;type:varchar(255);comment:快递公司编码" json:"logistics_company_code"` + SubLogisticsStatus int `gorm:"column:sub_logistics_status;type:tinyint(1);default:0;comment:快递推送订阅状态(0:未订阅/无需订阅 1:已订阅 2:订阅失败)" json:"sub_logistics_status"` + DeliveryTime LocalTime `gorm:"column:delivery_time;type:datetime;comment:发货时间" json:"delivery_time"` + PayTime LocalTime `gorm:"column:pay_time;type:datetime;comment:支付时间" json:"pay_time"` + Remarks string `gorm:"column:remarks;type:varchar(255);comment:订单备注" json:"remarks"` + RefundStatus int `gorm:"column:refund_status;type:tinyint(1);default:0;comment:商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)" json:"refund_status"` + CancelTime LocalTime `gorm:"column:cancel_time;type:datetime;comment:订单取消时间" json:"cancel_time"` + CancelRemarks string `gorm:"column:cancel_remarks;type:varchar(255);comment:订单取消备注(自动添加)" json:"cancel_remarks"` + ReportPreStatus int `gorm:"column:report_pre_status;type:tinyint(1);default:0;comment:上报处方平台状态(0:未上报 1:已上报 2:上报失败))" json:"report_pre_status"` + ReportPreTime LocalTime `gorm:"column:report_pre_time;type:datetime;comment:上报处方平台时间" json:"report_pre_time"` + ReportPreFailReason string `gorm:"column:report_pre_fail_reason;type:text;comment:上报失败原因" json:"report_pre_fail_reason"` + ProvinceId int `gorm:"column:province_id;type:int(11);comment:省份id" json:"province_id"` + Province string `gorm:"column:province;type:varchar(40);comment:省份" json:"province"` + CityId int `gorm:"column:city_id;type:int(11);comment:城市id" json:"city_id"` + City string `gorm:"column:city;type:varchar(50);comment:城市" json:"city"` + CountyId int `gorm:"column:county_id;type:int(11);comment:区县id" json:"county_id"` + County string `gorm:"column:county;type:varchar(255);comment:区县" json:"county"` + Address string `gorm:"column:address;type:varchar(255);comment:详细地址" json:"address"` + AddressMask string `gorm:"column:address_mask;type:varchar(255);comment:详细地址(掩码)" json:"address_mask"` + ConsigneeName string `gorm:"column:consignee_name;type:varchar(150);comment:收货人姓名" json:"consignee_name"` + ConsigneeNameMask string `gorm:"column:consignee_name_mask;type:varchar(150);comment:收货人姓名(掩码)" json:"consignee_name_mask"` + ConsigneeTel string `gorm:"column:consignee_tel;type:varchar(50);comment:收货人电话" json:"consignee_tel"` + ConsigneeTelMask string `gorm:"column:consignee_tel_mask;type:varchar(50);comment:收货人电话(掩码)" json:"consignee_tel_mask"` + UserDoctor *UserDoctor `gorm:"foreignKey:DoctorId;references:doctor_id" json:"user_doctor"` // 医生 + OrderInquiry *OrderInquiry `gorm:"foreignKey:OrderInquiryId;references:order_inquiry_id" json:"order_inquiry"` // 问诊 + UserPatient *UserPatient `gorm:"foreignKey:PatientId;references:patient_id" json:"user_patient"` // 患者 + OrderPrescription *OrderPrescription `gorm:"foreignKey:OrderPrescriptionId;references:order_prescription_id" json:"order_prescription"` // 处方 + OrderProductItem []*OrderProductItem `gorm:"foreignKey:OrderProductId;references:order_product_id" json:"order_product_item"` // 处方 Model } diff --git a/api/service/orderProduct.go b/api/service/orderProduct.go index 5783684..f45ae63 100644 --- a/api/service/orderProduct.go +++ b/api/service/orderProduct.go @@ -286,7 +286,7 @@ func (r *OrderProductService) GetOrderProductConsignee(orderProductId int64) (*d } // 处理返回值 - u := dto.GetOrderProductConsigneeDtoDto(orderProduct) + u := dto.GetOrderProductConsigneeDto(orderProduct) return u, nil }