fix(backend): 补全多处 Scan/Count 错误未检查,私钥缺失改为 Fatal

- stock.go: ApproveStockIn 入库前库存 Scan 加错误检查
- license.go: Activate 阶段 Count 设备数加错误检查;createTrialLicense
  私钥未配置由静默跳过改为 log.Fatalf,防止生产环境新注册门店无 license
- inventory.go: List 接口两处 Raw Scan 加错误检查并返回 500
- finance.go: ArBalance 汇总 Raw Scan 加错误检查并返回 500
This commit is contained in:
wangjia
2026-06-14 08:12:57 +08:00
parent f251953dbc
commit 2ed0010c67
4 changed files with 23 additions and 11 deletions
+5 -3
View File
@@ -52,10 +52,12 @@ func (s *StockService) ApproveStockIn(shopID, orderID, reviewerID uint64) error
// 计算入库前库存总量(用于流水记录)
var qtyBefore float64
tx.Model(&model.Inventory{}).
if err := tx.Model(&model.Inventory{}).
Where("shop_id = ? AND warehouse_id = ? AND product_id = ? AND deleted_at IS NULL",
shopID, warehouseID, productID).
Select("COALESCE(SUM(quantity), 0)").Scan(&qtyBefore)
Select("COALESCE(SUM(quantity), 0)").Scan(&qtyBefore).Error; err != nil {
return err
}
var unitPricePtr *float64
if itemCopy.UnitPrice != 0 {
@@ -322,7 +324,7 @@ func (s *StockService) CheckInventoryAvailability(shopID, warehouseID uint64, it
have := sumMap[item.ProductID]
if have < item.Quantity {
var p model.Product
s.db.Where("id = ?", item.ProductID).First(&p)
s.db.Where("id = ?", item.ProductID).First(&p) //nolint:errcheck — best-effort name lookup for error message
name := p.Name
if name == "" {
name = fmt.Sprintf("商品ID %d", item.ProductID)