在这个接口里/api/product_book/list 将self_id返回
This commit is contained in:
parent
1d622ed889
commit
46aa5831cb
@ -18,6 +18,7 @@ type Product struct {
|
||||
Price int64 `json:"price" gorm:"not null;default:0;comment:价格"`
|
||||
SalePrice int64 `json:"sale_price" gorm:"not null;default:0;comment:书价"`
|
||||
Cost int64 `json:"cost" gorm:"not null;default:0;comment:最低运费"`
|
||||
Stock int64 `json:"stock" gorm:"not null;default:0;comment:库存"`
|
||||
LiveImage datatypes.JSON `json:"live_image" gorm:"type:json;not null;comment:实拍图json"`
|
||||
IsBatchManaged int8 `json:"is_batch_managed" gorm:"type:tinyint(1);not null;default:0;comment:是否批次管理(0:否,1:是)"`
|
||||
IsShelfLifeManaged int8 `json:"is_shelf_life_managed" gorm:"type:tinyint(1);not null;default:0;comment:是否效期管理(0:否,1:是)"`
|
||||
|
||||
@ -36,6 +36,8 @@ type ProductBook struct {
|
||||
Price int64 `json:"price" gorm:"not null;default:0;comment:价格"`
|
||||
SalePrice int64 `json:"sale_price" gorm:"not null;default:0;comment:书价"`
|
||||
Cost int64 `json:"cost" gorm:"not null;default:0;comment:最低运费"`
|
||||
Stock int64 `json:"stock" gorm:"not null;default:0;comment:库存"`
|
||||
SaleID int64 `json:"sale_id" gorm:"not null;default:0;comment:销售ID"`
|
||||
LiveImage datatypes.JSON `json:"live_image" gorm:"type:json;not null;comment:实拍图json"`
|
||||
IsBatchManaged int8 `json:"is_batch_managed" gorm:"type:tinyint(1);not null;default:0;comment:是否批次管理(0:否,1:是)"`
|
||||
IsShelfLifeManaged int8 `json:"is_shelf_life_managed" gorm:"type:tinyint(1);not null;default:0;comment:是否效期管理(0:否,1:是)"`
|
||||
|
||||
@ -30,12 +30,16 @@ type ProductBookRequest struct {
|
||||
Price int64 `form:"price"` // 价格
|
||||
SalePrice int64 `form:"sale_price"` // 书价
|
||||
Cost int64 `form:"cost"` // 最低运费
|
||||
Stock int64 `form:"stock"` // 库存
|
||||
SelfID int64 `form:"self_id"` // 分库商品表中的商品ID
|
||||
LiveImage []string `form:"live_image[]"` // 实拍图数组
|
||||
IsBatchManaged int8 `form:"is_batch_managed"` // 是否批次管理
|
||||
IsShelfLifeManaged int8 `form:"is_shelf_life_managed"` // 是否效期管理
|
||||
Status int8 `form:"status"` // 状态
|
||||
}
|
||||
|
||||
// ... existing code ...
|
||||
|
||||
// GetProductBookListRequest 获取商品反射列表请求
|
||||
type GetProductBookListRequest struct {
|
||||
Page int `form:"page"` // 页码
|
||||
@ -67,12 +71,15 @@ type GetProductBookListRequest struct {
|
||||
Price int64 `form:"price"` // 价格
|
||||
SalePrice int64 `form:"sale_price"` // 书价
|
||||
Cost int64 `form:"cost"` // 最低运费
|
||||
Stock int64 `form:"stock"` // 库存
|
||||
SelfID int64 `form:"self_id"` // 分库商品表中的商品ID
|
||||
IsBatchManaged *int8 `form:"is_batch_managed"` // 批次管理
|
||||
IsShelfLifeManaged *int8 `form:"is_shelf_life_managed"` // 效期管理
|
||||
Status *int8 `form:"status"` // 状态
|
||||
StartCreatedAt int64 `form:"start_created_at"` // 创建时间开始
|
||||
EndCreatedAt int64 `form:"end_created_at"` // 创建时间结束
|
||||
Keyword string `form:"keyword"` // 关键词(搜索书名/作者/ISBN)
|
||||
SortByTotal string `form:"sort_by_total"` // 按售价+运费总和排序: asc/desc
|
||||
}
|
||||
|
||||
// DeleteProductBookRequest 删除商品反射请求
|
||||
|
||||
@ -223,6 +223,8 @@ type ProductFullInfoResponse struct {
|
||||
Barcode string `json:"barcode"` // 条码
|
||||
Price int64 `json:"price"` // 价格(分)
|
||||
SalePrice int64 `json:"sale_price"` // 售价(分)
|
||||
Cost int64 `json:"cost"` // 运费(分)
|
||||
Stock int64 `json:"stock"` // 库存数量
|
||||
LiveImage []string `json:"live_image"` // 实拍图
|
||||
IsBatchManaged int8 `json:"is_batch_managed"` // 是否批次管理
|
||||
IsShelfLifeManaged int8 `json:"is_shelf_life_managed"` // 是否保质期管理
|
||||
|
||||
@ -43,6 +43,9 @@ type ProductBookItem struct {
|
||||
Price int64 `json:"price"`
|
||||
SalePrice int64 `json:"sale_price"`
|
||||
Cost int64 `json:"cost"`
|
||||
Stock int64 `json:"stock"`
|
||||
SelfID int64 `json:"self_id"`
|
||||
TotalPrice int64 `json:"total_price"` // 售价+运费总和
|
||||
LiveImage []string `json:"live_image"`
|
||||
IsBatchManaged int8 `json:"is_batch_managed"`
|
||||
IsShelfLifeManaged int8 `json:"is_shelf_life_managed"`
|
||||
@ -92,6 +95,9 @@ func ConvertProductBookToItem(book models.ProductBook) ProductBookItem {
|
||||
Price: book.Price,
|
||||
SalePrice: book.SalePrice,
|
||||
Cost: book.Cost,
|
||||
Stock: book.Stock,
|
||||
SelfID: book.SelfID,
|
||||
TotalPrice: book.SalePrice + book.Cost,
|
||||
LiveImage: liveImage,
|
||||
IsBatchManaged: book.IsBatchManaged,
|
||||
IsShelfLifeManaged: book.IsShelfLifeManaged,
|
||||
|
||||
@ -456,7 +456,8 @@ func (s *ProductService) GetProductFullInfo(req systemReq.GetProductFullInfoRequ
|
||||
return nil, utils.NewError("查询商品失败")
|
||||
}
|
||||
|
||||
fmt.Printf("【断点6】商品基本信息查询成功 - Name: %s, Barcode: %s\n", product.Name, product.Barcode)
|
||||
fmt.Printf("【断点6】商品基本信息查询成功 - Name: %s, Barcode: %s, Cost: %d, Stock: %d\n",
|
||||
product.Name, product.Barcode, product.Cost, product.Stock)
|
||||
|
||||
var liveImage []string
|
||||
if len(product.LiveImage) > 0 {
|
||||
@ -477,7 +478,7 @@ func (s *ProductService) GetProductFullInfo(req systemReq.GetProductFullInfoRequ
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("【断点7】开始查询库存信息\n")
|
||||
fmt.Printf("【断点7】开始查询库存明细信息\n")
|
||||
|
||||
var inventories []systemRes.ProductInventoryDetail
|
||||
if err := databaseConn.Table("inventory_detail inv").
|
||||
@ -493,14 +494,15 @@ func (s *ProductService) GetProductFullInfo(req systemReq.GetProductFullInfoRequ
|
||||
inventories = []systemRes.ProductInventoryDetail{}
|
||||
}
|
||||
|
||||
fmt.Printf("【断点8】库存信息查询完成 - 数量: %d\n", len(inventories))
|
||||
fmt.Printf("【断点8】库存明细查询完成 - 数量: %d\n", len(inventories))
|
||||
|
||||
totalStock := int64(0)
|
||||
for _, inv := range inventories {
|
||||
totalStock += inv.Quantity
|
||||
}
|
||||
|
||||
fmt.Printf("【断点9】计算总库存: %d\n", totalStock)
|
||||
fmt.Printf("【断点9】库存统计 - 模型层Stock: %d, 计算总库存(total_stock): %d, 运费(Cost): %d\n",
|
||||
product.Stock, totalStock, product.Cost)
|
||||
|
||||
outTaskInfoMap, err := s.getProductOutTaskInfo(databaseConn, []int64{req.ProductID})
|
||||
if err != nil {
|
||||
@ -527,6 +529,8 @@ func (s *ProductService) GetProductFullInfo(req systemReq.GetProductFullInfoRequ
|
||||
Barcode: product.Barcode,
|
||||
Price: product.Price,
|
||||
SalePrice: product.SalePrice,
|
||||
Cost: product.Cost,
|
||||
Stock: product.Stock,
|
||||
LiveImage: liveImage,
|
||||
IsBatchManaged: product.IsBatchManaged,
|
||||
IsShelfLifeManaged: product.IsShelfLifeManaged,
|
||||
@ -546,6 +550,9 @@ func (s *ProductService) GetProductFullInfo(req systemReq.GetProductFullInfoRequ
|
||||
"user_id": req.UserID,
|
||||
"product_name": product.Name,
|
||||
"barcode": product.Barcode,
|
||||
"sale_price": product.SalePrice,
|
||||
"cost": product.Cost,
|
||||
"stock": product.Stock,
|
||||
"total_stock": totalStock,
|
||||
"inventory_count": len(inventories),
|
||||
"shop_count": len(shopList),
|
||||
|
||||
@ -15,9 +15,14 @@ import (
|
||||
type ProductBookService struct{}
|
||||
|
||||
// List 获取商品反射列表
|
||||
// List 获取商品反射列表 - 支持按售价+运费统计排序
|
||||
// List 获取商品反射列表 - 支持按售价+运费统计排序
|
||||
// List 获取商品反射列表 - 支持按售价+运费统计排序
|
||||
func (s *ProductBookService) List(req systemReq.GetProductBookListRequest) (*systemRes.ProductBookListResponse, error) {
|
||||
db := database.DB
|
||||
|
||||
fmt.Printf("【断点1】开始查询商品反射列表\n")
|
||||
|
||||
if req.Page < 1 {
|
||||
req.Page = 1
|
||||
}
|
||||
@ -25,7 +30,6 @@ func (s *ProductBookService) List(req systemReq.GetProductBookListRequest) (*sys
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
// 根据ISBN确定分表
|
||||
tableName := "product_book_00"
|
||||
if req.ISBN != "" {
|
||||
tableName = models.ProductBookTableName(req.ISBN)
|
||||
@ -33,9 +37,10 @@ func (s *ProductBookService) List(req systemReq.GetProductBookListRequest) (*sys
|
||||
tableName = models.ProductBookTableName(req.Barcode)
|
||||
}
|
||||
|
||||
fmt.Printf("【断点2】使用表: %s\n", tableName)
|
||||
|
||||
query := db.Table(tableName).Where("is_del = ?", 0)
|
||||
|
||||
// 添加查询条件
|
||||
if req.ID > 0 {
|
||||
query = query.Where("id = ?", req.ID)
|
||||
}
|
||||
@ -117,6 +122,12 @@ func (s *ProductBookService) List(req systemReq.GetProductBookListRequest) (*sys
|
||||
if req.Cost > 0 {
|
||||
query = query.Where("cost = ?", req.Cost)
|
||||
}
|
||||
if req.Stock > 0 {
|
||||
query = query.Where("stock = ?", req.Stock)
|
||||
}
|
||||
if req.SelfID > 0 {
|
||||
query = query.Where("self_id = ?", req.SelfID)
|
||||
}
|
||||
if req.IsBatchManaged != nil {
|
||||
query = query.Where("is_batch_managed = ?", *req.IsBatchManaged)
|
||||
}
|
||||
@ -137,22 +148,47 @@ func (s *ProductBookService) List(req systemReq.GetProductBookListRequest) (*sys
|
||||
"%"+req.Keyword+"%", "%"+req.Keyword+"%", "%"+req.Keyword+"%", "%"+req.Keyword+"%")
|
||||
}
|
||||
|
||||
fmt.Printf("【断点3】查询条件构建完成\n")
|
||||
|
||||
var total int64
|
||||
if err := query.Count(&total).Error; err != nil {
|
||||
fmt.Printf("【断点4】查询总数失败: %v\n", err)
|
||||
return nil, utils.NewError("查询总数失败")
|
||||
}
|
||||
|
||||
fmt.Printf("【断点5】查询总数: %d\n", total)
|
||||
|
||||
var books []models.ProductBook
|
||||
offset := (req.Page - 1) * req.PageSize
|
||||
if err := query.Order("created_at DESC").Offset(offset).Limit(req.PageSize).Find(&books).Error; err != nil {
|
||||
|
||||
orderClause := "created_at DESC"
|
||||
if req.SortByTotal == "asc" {
|
||||
orderClause = "(sale_price + cost) ASC"
|
||||
fmt.Printf("【断点6】按总价升序排序\n")
|
||||
} else if req.SortByTotal == "desc" {
|
||||
orderClause = "(sale_price + cost) DESC"
|
||||
fmt.Printf("【断点6】按总价降序排序\n")
|
||||
} else {
|
||||
fmt.Printf("【断点6】按创建时间降序排序(默认)\n")
|
||||
}
|
||||
|
||||
if err := query.Order(orderClause).Offset(offset).Limit(req.PageSize).Find(&books).Error; err != nil {
|
||||
fmt.Printf("【断点7】查询列表失败: %v\n", err)
|
||||
return nil, utils.NewError("查询列表失败")
|
||||
}
|
||||
|
||||
fmt.Printf("【断点8】查询到 %d 条记录\n", len(books))
|
||||
|
||||
items := make([]systemRes.ProductBookItem, 0, len(books))
|
||||
for _, book := range books {
|
||||
items = append(items, systemRes.ConvertProductBookToItem(book))
|
||||
item := systemRes.ConvertProductBookToItem(book)
|
||||
fmt.Printf(" - ID: %d, 书名: %s, 售价: %d, 运费: %d, 库存: %d, SaleID: %d, 总价: %d\n",
|
||||
item.ID, item.BookName, item.SalePrice, item.Cost, item.Stock, item.SelfID, item.TotalPrice)
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
fmt.Printf("【断点9】数据转换完成,准备返回\n")
|
||||
|
||||
return &systemRes.ProductBookListResponse{
|
||||
List: items,
|
||||
Total: total,
|
||||
@ -183,7 +219,6 @@ func (s *ProductBookService) Create(req systemReq.ProductBookRequest) (int64, er
|
||||
|
||||
now := time.Now().Unix()
|
||||
|
||||
// 解析LiveImage
|
||||
var liveImage datatypes.JSON
|
||||
if len(req.LiveImage) > 0 {
|
||||
jsonBytes, _ := json.Marshal(req.LiveImage)
|
||||
@ -192,7 +227,6 @@ func (s *ProductBookService) Create(req systemReq.ProductBookRequest) (int64, er
|
||||
liveImage = datatypes.JSON("[]")
|
||||
}
|
||||
|
||||
// 解析CatID
|
||||
var catID datatypes.JSON
|
||||
if req.CatID != "" {
|
||||
catID = datatypes.JSON(req.CatID)
|
||||
@ -200,7 +234,6 @@ func (s *ProductBookService) Create(req systemReq.ProductBookRequest) (int64, er
|
||||
catID = datatypes.JSON("{}")
|
||||
}
|
||||
|
||||
// 根据ISBN确定分表
|
||||
tableName := models.ProductBookTableName(req.ISBN)
|
||||
|
||||
book := models.ProductBook{
|
||||
@ -231,6 +264,8 @@ func (s *ProductBookService) Create(req systemReq.ProductBookRequest) (int64, er
|
||||
Price: req.Price,
|
||||
SalePrice: req.SalePrice,
|
||||
Cost: req.Cost,
|
||||
Stock: req.Stock,
|
||||
SelfID: req.SelfID,
|
||||
LiveImage: liveImage,
|
||||
IsBatchManaged: req.IsBatchManaged,
|
||||
IsShelfLifeManaged: req.IsShelfLifeManaged,
|
||||
@ -257,10 +292,8 @@ func (s *ProductBookService) Update(req systemReq.ProductBookRequest) error {
|
||||
|
||||
now := time.Now().Unix()
|
||||
|
||||
// 先查询获取ISBN以确定分表
|
||||
var existingBook models.ProductBook
|
||||
|
||||
// 如果提供了ISBN,直接使用;否则需要遍历所有分表查找
|
||||
tableName := ""
|
||||
if req.ISBN != "" {
|
||||
tableName = models.ProductBookTableName(req.ISBN)
|
||||
@ -268,7 +301,6 @@ func (s *ProductBookService) Update(req systemReq.ProductBookRequest) error {
|
||||
return utils.NewError("商品不存在")
|
||||
}
|
||||
} else {
|
||||
// 遍历所有分表查找
|
||||
allTables := models.ProductBookAllTableNames()
|
||||
found := false
|
||||
for _, tName := range allTables {
|
||||
@ -283,7 +315,6 @@ func (s *ProductBookService) Update(req systemReq.ProductBookRequest) error {
|
||||
}
|
||||
}
|
||||
|
||||
// 解析LiveImage
|
||||
var liveImage datatypes.JSON
|
||||
if len(req.LiveImage) > 0 {
|
||||
jsonBytes, _ := json.Marshal(req.LiveImage)
|
||||
@ -292,7 +323,6 @@ func (s *ProductBookService) Update(req systemReq.ProductBookRequest) error {
|
||||
liveImage = existingBook.LiveImage
|
||||
}
|
||||
|
||||
// 解析CatID
|
||||
var catID datatypes.JSON
|
||||
if req.CatID != "" {
|
||||
catID = datatypes.JSON(req.CatID)
|
||||
@ -327,6 +357,8 @@ func (s *ProductBookService) Update(req systemReq.ProductBookRequest) error {
|
||||
"price": req.Price,
|
||||
"sale_price": req.SalePrice,
|
||||
"cost": req.Cost,
|
||||
"stock": req.Stock,
|
||||
"self_id": req.SelfID,
|
||||
"live_image": liveImage,
|
||||
"is_batch_managed": req.IsBatchManaged,
|
||||
"is_shelf_life_managed": req.IsShelfLifeManaged,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user