package response import ( "gorm.io/datatypes" "psi/models" ) type OrderWithInfo struct { models.PurchaseOrder SupplierName string `gorm:"column:supplier_name"` WarehouseName string `gorm:"column:warehouse_name"` } type ItemWithProduct struct { models.PurchaseOrderItem ProductName string `gorm:"column:product_name"` ProductCode string `gorm:"column:product_code"` SalePrice int64 `gorm:"column:sale_price"` CategoryID int64 `gorm:"column:category_id"` CategoryName string `gorm:"column:category_name"` LiveImage datatypes.JSON `gorm:"column:live_image"` LocationID int64 `gorm:"column:location_id"` LocationCode string `gorm:"column:location_code"` } // PurchaseOrderListResponse 采购订单列表响应 type PurchaseOrderListResponse struct { List []PurchaseOrderItem `json:"list"` Total int64 `json:"total"` Page int `json:"page"` PageSize int `json:"pageSize"` } // PurchaseOrderItem 采购订单项 type PurchaseOrderItem struct { ID int64 `json:"id"` PoNo string `json:"po_no"` SupplierID int64 `json:"supplier_id"` SupplierName string `json:"supplier_name"` WarehouseID int64 `json:"warehouse_id"` WarehouseName string `json:"warehouse_name"` OrderDate int64 `json:"order_date"` ExpectedArrivalDate int64 `json:"expected_arrival_date"` TotalAmount int64 `json:"total_amount"` Status int8 `json:"status"` StatusText string `json:"status_text"` Creator string `json:"creator"` CreatorID int64 `json:"creator_id"` Remark string `json:"remark"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` } // PurchaseOrderDetailResponse 采购订单详情响应 type PurchaseOrderDetailResponse struct { ID int64 `json:"id"` PoNo string `json:"po_no"` SupplierID int64 `json:"supplier_id"` SupplierName string `json:"supplier_name"` WarehouseID int64 `json:"warehouse_id"` WarehouseName string `json:"warehouse_name"` OrderDate int64 `json:"order_date"` ExpectedArrivalDate int64 `json:"expected_arrival_date"` TotalAmount int64 `json:"total_amount"` Status int8 `json:"status"` StatusText string `json:"status_text"` Creator string `json:"creator"` CreatorID int64 `json:"creator_id"` Remark string `json:"remark"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` Items []PurchaseOrderDetailItem `json:"items"` } // PurchaseOrderDetailItem 采购订单明细项 type PurchaseOrderDetailItem struct { ID int64 `json:"id"` PurchaseOrderID int64 `json:"purchase_order_id"` ProductID int64 `json:"product_id"` ProductName string `json:"product_name"` ProductCode string `json:"product_code"` SalePrice int64 `json:"sale_price"` CategoryID int64 `json:"category_id"` CategoryName string `json:"category_name"` LiveImage []string `json:"live_image"` Quantity int64 `json:"quantity"` ReceivedQuantity int64 `json:"received_quantity"` UnitPrice int64 `json:"unit_price"` Amount int64 `json:"amount"` LocationID int64 `json:"location_id"` LocationCode string `json:"location_code"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` } // ConvertPurchaseOrderToItem 将采购订单模型转换为响应项 func ConvertPurchaseOrderToItem(order models.PurchaseOrder, supplierName string, warehouseName string) PurchaseOrderItem { return PurchaseOrderItem{ ID: order.ID, PoNo: order.PoNo, SupplierID: order.SupplierID, SupplierName: supplierName, WarehouseID: order.WarehouseID, WarehouseName: warehouseName, OrderDate: order.OrderDate, ExpectedArrivalDate: order.ExpectedArrivalDate, TotalAmount: order.TotalAmount, Status: order.Status, StatusText: GetPurchaseOrderStatusText(order.Status), Creator: order.Creator, CreatorID: order.CreatorID, Remark: order.Remark, CreatedAt: order.CreatedAt, UpdatedAt: order.UpdatedAt, } } // ConvertPurchaseOrderToDetail 将采购订单模型转换为详情响应 func ConvertPurchaseOrderToDetail(order models.PurchaseOrder, supplierName string, warehouseName string, items []PurchaseOrderDetailItem) PurchaseOrderDetailResponse { return PurchaseOrderDetailResponse{ ID: order.ID, PoNo: order.PoNo, SupplierID: order.SupplierID, SupplierName: supplierName, WarehouseID: order.WarehouseID, WarehouseName: warehouseName, OrderDate: order.OrderDate, ExpectedArrivalDate: order.ExpectedArrivalDate, TotalAmount: order.TotalAmount, Status: order.Status, StatusText: GetPurchaseOrderStatusText(order.Status), Creator: order.Creator, CreatorID: order.CreatorID, Remark: order.Remark, CreatedAt: order.CreatedAt, UpdatedAt: order.UpdatedAt, Items: items, } } // GetPurchaseOrderStatusText 获取采购订单状态文本 func GetPurchaseOrderStatusText(status int8) string { statusMap := map[int8]string{ 1: "草稿", 2: "已提交", 3: "已审核", 4: "部分收货", 5: "已收货", 6: "已取消", } if text, ok := statusMap[status]; ok { return text } return "未知" }