package response import ( "gorm.io/datatypes" "psi/models" ) type SalesOrderWithInfo struct { models.SalesOrder CustomerName string `gorm:"column:customer_name"` WarehouseName string `gorm:"column:warehouse_name"` } type SalesOrderItemWithProduct struct { models.SalesOrderItem ProductName string `gorm:"column:product_name"` ProductCode string `gorm:"column:product_code"` ProductSalePrice int64 `gorm:"column:product_sale_price"` CategoryID int64 `gorm:"column:category_id"` CategoryName string `gorm:"column:category_name"` LiveImage datatypes.JSON `gorm:"column:live_image"` LocationCode string `gorm:"column:location_code"` } // SalesOrderListResponse 销售订单列表响应 type SalesOrderListResponse struct { List []SalesOrderItem `json:"list"` Total int64 `json:"total"` Page int `json:"page"` PageSize int `json:"pageSize"` } // SalesOrderItem 销售订单项 type SalesOrderItem struct { ID int64 `json:"id"` SoNo string `json:"so_no"` AssociationOrderId int64 `json:"association_order_id"` AssociationOrderNo string `json:"association_order_no"` FromType int8 `json:"from_type"` ShopType int8 `json:"shop_type"` ShopTypeText string `json:"shop_type_text"` CustomerID int64 `json:"customer_id"` CustomerName string `json:"customer_name"` WarehouseID int64 `json:"warehouse_id"` WarehouseName string `json:"warehouse_name"` OrderDate int64 `json:"order_date"` RequiredDeliveryDate int64 `json:"required_delivery_date"` TotalAmount int64 `json:"total_amount"` Status int8 `json:"status"` StatusText string `json:"status_text"` SalesPerson string `json:"sales_person"` SalesPersonID int64 `json:"sales_person_id"` Remark string `json:"remark"` LogisticsNo string `json:"logistics_no"` LocationCode string `json:"location_code"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` } // SalesOrderDetailResponse 销售订单详情响应 type SalesOrderDetailResponse struct { ID int64 `json:"id"` SoNo string `json:"so_no"` CustomerID int64 `json:"customer_id"` CustomerName string `json:"customer_name"` WarehouseID int64 `json:"warehouse_id"` WarehouseName string `json:"warehouse_name"` OrderDate int64 `json:"order_date"` RequiredDeliveryDate int64 `json:"required_delivery_date"` TotalAmount int64 `json:"total_amount"` Status int8 `json:"status"` StatusText string `json:"status_text"` ShopTypeText string `json:"shop_type_text"` SalesPerson string `json:"sales_person"` SalesPersonID int64 `json:"sales_person_id"` AssociationOrderNo string `json:"association_order_no"` LogisticsNo string `json:"logistics_no"` Remark string `json:"remark"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` Items []SalesOrderDetailItem `json:"items"` } // SalesOrderDetailItem 销售订单明细项 type SalesOrderDetailItem struct { ID int64 `json:"id"` SalesOrderID int64 `json:"sales_order_id"` ProductID int64 `json:"product_id"` ProductName string `json:"product_name"` ProductCode string `json:"product_code"` ProductSalePrice int64 `json:"product_sale_price"` CategoryID int64 `json:"category_id"` CategoryName string `json:"category_name"` LiveImage []string `json:"live_image"` Quantity int64 `json:"quantity"` AllocatedQuantity int64 `json:"allocated_quantity"` ShippedQuantity int64 `json:"shipped_quantity"` UnitPrice int64 `json:"unit_price"` Amount int64 `json:"amount"` ReceiverName string `json:"receiver_name"` ReceiverPhone string `json:"receiver_phone"` ReceiverAddress string `json:"receiver_address"` LogisticsCompany string `json:"logistics_company"` LogisticsNo string `json:"logistics_no"` LocationCode string `json:"location_code"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` } // ConvertSalesOrderToItem 将销售订单模型转换为响应项 func ConvertSalesOrderToItem(order models.SalesOrder, customerName string, warehouseName string, logisticsNo string, locationCode string) SalesOrderItem { return SalesOrderItem{ ID: order.ID, SoNo: order.SoNo, AssociationOrderId: order.AssociationOrderId, AssociationOrderNo: order.AssociationOrderNo, FromType: order.FromType, ShopType: order.ShopType, ShopTypeText: GetShopTypeStatusText(order.ShopType), CustomerID: order.CustomerID, CustomerName: customerName, WarehouseID: order.WarehouseID, WarehouseName: warehouseName, OrderDate: order.OrderDate, RequiredDeliveryDate: order.RequiredDeliveryDate, TotalAmount: order.TotalAmount, Status: order.Status, StatusText: GetSalesOrderStatusText(order.Status), SalesPerson: order.SalesPerson, SalesPersonID: order.SalesPersonID, Remark: order.Remark, LogisticsNo: logisticsNo, LocationCode: locationCode, CreatedAt: order.CreatedAt, UpdatedAt: order.UpdatedAt, } } // ConvertSalesOrderToDetail 将销售订单模型转换为详情响应 func ConvertSalesOrderToDetail(order models.SalesOrder, customerName string, warehouseName string, items []SalesOrderDetailItem) SalesOrderDetailResponse { return SalesOrderDetailResponse{ ID: order.ID, SoNo: order.SoNo, CustomerID: order.CustomerID, CustomerName: customerName, WarehouseID: order.WarehouseID, WarehouseName: warehouseName, OrderDate: order.OrderDate, RequiredDeliveryDate: order.RequiredDeliveryDate, TotalAmount: order.TotalAmount, Status: order.Status, StatusText: GetSalesOrderStatusText(order.Status), ShopTypeText: GetShopTypeStatusText(order.ShopType), SalesPerson: order.SalesPerson, SalesPersonID: order.SalesPersonID, AssociationOrderNo: order.AssociationOrderNo, LogisticsNo: "", Remark: order.Remark, CreatedAt: order.CreatedAt, UpdatedAt: order.UpdatedAt, Items: items, } } // SalesOrderDetailListResponse 销售订单详情列表响应 type SalesOrderDetailListResponse struct { List []SalesOrderDetailResponse `json:"list"` Total int64 `json:"total"` Page int `json:"page"` PageSize int `json:"pageSize"` } // GetSalesOrderStatusText 获取销售订单状态文本 func GetSalesOrderStatusText(status int8) string { statusMap := map[int8]string{ 1: "草稿", 2: "已确认", 3: "已分配库存", 4: "拣货完成", 5: "已发货", 6: "已取消", } if text, ok := statusMap[status]; ok { return text } return "未知" } // GetShopTypeStatusText 获取店铺类型文本 func GetShopTypeStatusText(status int8) string { statusMap := map[int8]string{ 1: "拼多多", 2: "孔夫子", 5: "闲鱼", } if text, ok := statusMap[status]; ok { return text } return "未知" }