Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
38fdcf398e
@ -5,6 +5,11 @@ import "gorm.io/datatypes"
|
|||||||
// Product 商品表
|
// Product 商品表
|
||||||
type Product struct {
|
type Product struct {
|
||||||
ID int64 `json:"id" gorm:"primarykey;comment:商品ID"`
|
ID int64 `json:"id" gorm:"primarykey;comment:商品ID"`
|
||||||
|
AboutId int64 `json:"about_id" gorm:"not null;default:0;index;comment:租户ID"`
|
||||||
|
WarehouseID int64 `json:"warehouse_id" gorm:"not null;default:0;index;comment:仓库ID"`
|
||||||
|
WarehouseName string `json:"warehouse_name" gorm:"size:100;not null;default:'';comment:仓库名称"`
|
||||||
|
LocationID int64 `json:"location_id" gorm:"not null;default:0;index;comment:库位ID"`
|
||||||
|
LocationName string `json:"location_name" gorm:"size:100;not null;default:'';comment:库位名称"`
|
||||||
CategoryID int64 `json:"category_id" gorm:"not null;default:0;comment:分类ID"`
|
CategoryID int64 `json:"category_id" gorm:"not null;default:0;comment:分类ID"`
|
||||||
StandardProductID int64 `json:"standard_product_id" gorm:"not null;default:0;index;comment:关联标品ID"`
|
StandardProductID int64 `json:"standard_product_id" gorm:"not null;default:0;index;comment:关联标品ID"`
|
||||||
Name string `json:"name" gorm:"size:255;not null;default:'';comment:商品名称"`
|
Name string `json:"name" gorm:"size:255;not null;default:'';comment:商品名称"`
|
||||||
|
|||||||
@ -115,6 +115,7 @@ type UserListItem struct {
|
|||||||
Phone string `json:"phone"` // 手机号
|
Phone string `json:"phone"` // 手机号
|
||||||
From string `json:"from"` // 来源
|
From string `json:"from"` // 来源
|
||||||
LastLoginIp string `json:"last_login_ip"` // 最后登录IP
|
LastLoginIp string `json:"last_login_ip"` // 最后登录IP
|
||||||
|
LastLoginAt int64 `json:"last_login_at"` // 最后登录时间
|
||||||
Code string `json:"code"` // 机械码
|
Code string `json:"code"` // 机械码
|
||||||
ExpireTime int64 `json:"expire_time"` // 到期时间
|
ExpireTime int64 `json:"expire_time"` // 到期时间
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1053,6 +1053,7 @@ func (s *EmployeeService) GetUserList(req systemReq.GetUserListRequest) (*system
|
|||||||
Phone: emp.Phone,
|
Phone: emp.Phone,
|
||||||
From: emp.From,
|
From: emp.From,
|
||||||
LastLoginIp: emp.LastLoginIp,
|
LastLoginIp: emp.LastLoginIp,
|
||||||
|
LastLoginAt: emp.LastLoginAt,
|
||||||
Code: emp.Code,
|
Code: emp.Code,
|
||||||
ExpireTime: emp.ExpireTime,
|
ExpireTime: emp.ExpireTime,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -115,7 +115,9 @@ func (s *ProductService) GetProductList(req systemReq.GetProductListRequest, db
|
|||||||
if outTaskInfo, exists := outTaskInfoMap[product.ID]; exists {
|
if outTaskInfo, exists := outTaskInfoMap[product.ID]; exists {
|
||||||
item.ShopList = outTaskInfo.ShopList
|
item.ShopList = outTaskInfo.ShopList
|
||||||
}
|
}
|
||||||
|
// item.LiveImage[0] 按照 , 分割数组
|
||||||
|
liveImage := strings.Split(item.LiveImage[0], ",")
|
||||||
|
item.LiveImage[0] = liveImage[0]
|
||||||
productItems = append(productItems, item)
|
productItems = append(productItems, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -659,13 +661,41 @@ func (s *ProductService) GetProductInventory(req systemReq.GetProductInventoryRe
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("获取数据库连接失败: %v", err)
|
return nil, fmt.Errorf("获取数据库连接失败: %v", err)
|
||||||
}
|
}
|
||||||
|
// 验证商品是否存在,并获取商品信息
|
||||||
|
var product models.Product
|
||||||
|
if err := databaseConn.Where("id = ? AND is_del = ?", req.ProductID, 0).First(&product).Error; err != nil {
|
||||||
|
return nil, fmt.Errorf("商品不存在")
|
||||||
|
}
|
||||||
|
|
||||||
var totalQuantity int64
|
var totalQuantity int64
|
||||||
databaseConn.Table("inventory").
|
// type=1: 按品相+ISBN+仓库分组后统计总数量
|
||||||
Select("COALESCE(SUM(quantity), 0)").
|
if req.Type == 1 {
|
||||||
Where("product_id = ? AND is_del = ?", req.ProductID, 0).
|
type GroupStock struct {
|
||||||
Scan(&totalQuantity)
|
TotalQuantity int64 `gorm:"column:total_quantity"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var groupList []GroupStock
|
||||||
|
// 先根据商品的 ISBN 和品相,查询所有匹配的库存记录,再按仓库分组统计
|
||||||
|
databaseConn.Table("inventory").
|
||||||
|
Select(`
|
||||||
|
COALESCE(SUM(inventory.quantity), 0) as total_quantity
|
||||||
|
`).
|
||||||
|
Joins("LEFT JOIN product p ON inventory.product_id = p.id AND p.is_del = ?", 0).
|
||||||
|
Where("p.barcode = ? AND p.appearance = ? AND inventory.warehouse_id IS NOT NULL AND inventory.is_del = ?",
|
||||||
|
product.Barcode, product.Appearance, 0).
|
||||||
|
Group("inventory.warehouse_id").
|
||||||
|
Scan(&groupList)
|
||||||
|
|
||||||
|
// 累加所有分组的数量
|
||||||
|
for _, group := range groupList {
|
||||||
|
totalQuantity += group.TotalQuantity
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
databaseConn.Table("inventory").
|
||||||
|
Select("COALESCE(SUM(quantity), 0)").
|
||||||
|
Where("product_id = ? AND is_del = ?", req.ProductID, 0).
|
||||||
|
Scan(&totalQuantity)
|
||||||
|
}
|
||||||
return &systemRes.ProductInventoryResponse{
|
return &systemRes.ProductInventoryResponse{
|
||||||
Quantity: totalQuantity,
|
Quantity: totalQuantity,
|
||||||
}, nil
|
}, nil
|
||||||
@ -805,7 +835,6 @@ func (s *ProductService) RetryOutTask(req systemReq.RetryOutTaskRequest, db ...*
|
|||||||
"error": fmt.Sprintf("更新失败: %v", updateErr),
|
"error": fmt.Sprintf("更新失败: %v", updateErr),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2735,3 +2764,12 @@ func (s *ProductService) getShopTypeName(shopType int8) string {
|
|||||||
return "未知"
|
return "未知"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 在 service 中使用
|
||||||
|
/*func (s *ProcessService) asyncWriteToMainDB(aboutID int64, data interface{}) {
|
||||||
|
go func() {
|
||||||
|
mainDB := database.DB
|
||||||
|
// 写入主库逻辑
|
||||||
|
mainDB.Create(data)
|
||||||
|
}()
|
||||||
|
}*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user