feat: 财务结清、酒行信息、库存备注编辑、标签溯源、入库必填校验

后端
- 新增 shop handler:GET/PUT /shop/info(管理员权限)
- 新增 finance CloseByRef:按单据 ref_type+ref_id 结清账款
- 新增 inventory UpdateRemark:PUT /inventory/:id/remark
- 入库/出库审批自动生成财务应付/应收记录(去除金额>0限制)
- 种子数据 S001-S003 补充真实门店信息

前端
- 设置页新增「酒行信息」Tab,管理员可编辑门店名称/地址/电话/负责人
- 入库单列表新增结清按钮(含确认弹窗),出库单同步
- 入库表单:规格、系列、生产日期、供应商、商品名称改为提交必填
- 入库/出库列表新增入库时间、出库时间、创建时间列
- 商品标签标题改为读取 shop 表门店名,扫码文案改为「扫码溯源 · TRACE」
- 标签页脚显示门店地址和电话(从 API 读取,不再依赖编译时 dart-define)
- 库存备注支持点击编辑,超4字截断显示+Hover展示全文
- ApiClient 新增 patch() 方法(已改用 PUT 规避 CORS)

文档
- 新增 docs/user-manual.md 完整用户操作手册(12章)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-05-23 14:05:41 +08:00
parent c77e1c1490
commit c1ed81dfab
60 changed files with 4664 additions and 1572 deletions
+44 -16
View File
@@ -666,37 +666,65 @@ func createStockOutOrder(
func updateInventoryBatch(db *gorm.DB, shopID, whID, opID uint64, r stockInResult) {
for _, it := range r.items {
var inv model.Inventory
db.Where("shop_id = ? AND warehouse_id = ? AND product_id = ?", shopID, whID, it.productID).First(&inv)
before := inv.Quantity
after := before + it.qty
if inv.ID == 0 {
inv = model.Inventory{ShopID: shopID, WarehouseID: whID, ProductID: it.productID, Quantity: after}
db.Create(&inv)
} else {
db.Model(&inv).Update("quantity", after)
var qtyBefore float64
db.Model(&model.Inventory{}).
Where("shop_id = ? AND warehouse_id = ? AND product_id = ? AND deleted_at IS NULL", shopID, whID, it.productID).
Select("COALESCE(SUM(quantity), 0)").Scan(&qtyBefore)
productIDCopy := it.productID
whIDCopy := whID
inv := model.Inventory{
ShopID: shopID,
WarehouseID: &whIDCopy,
ProductID: &productIDCopy,
Quantity: it.qty,
}
db.Create(&inv)
db.Create(&model.InventoryLog{
ShopID: shopID, WarehouseID: whID, ProductID: it.productID,
Direction: "in", Quantity: it.qty, QtyBefore: before, QtyAfter: after,
Direction: "in", Quantity: it.qty, QtyBefore: qtyBefore, QtyAfter: qtyBefore + it.qty,
RefType: "stock_in", RefID: r.order.ID, OperatorID: &opID,
})
}
}
func deductInventoryBatch(db *gorm.DB, shopID, whID, opID uint64, r stockOutResult) {
now := time.Now()
for _, it := range r.items {
var inv model.Inventory
db.Where("shop_id = ? AND warehouse_id = ? AND product_id = ?", shopID, whID, it.productID).First(&inv)
before := inv.Quantity
after := before - it.qty
var qtyBefore float64
db.Model(&model.Inventory{}).
Where("shop_id = ? AND warehouse_id = ? AND product_id = ? AND deleted_at IS NULL", shopID, whID, it.productID).
Select("COALESCE(SUM(quantity), 0)").Scan(&qtyBefore)
// FIFO deduction
var batches []model.Inventory
db.Where("shop_id = ? AND warehouse_id = ? AND product_id = ? AND quantity > 0 AND deleted_at IS NULL",
shopID, whID, it.productID).
Order("created_at ASC").Find(&batches)
remaining := it.qty
for i := range batches {
if remaining <= 0 {
break
}
b := &batches[i]
if b.Quantity <= remaining {
remaining -= b.Quantity
db.Model(b).Updates(map[string]interface{}{"quantity": 0, "deleted_at": now})
} else {
db.Model(b).Update("quantity", gorm.Expr("quantity - ?", remaining))
remaining = 0
}
}
after := qtyBefore - it.qty
if after < 0 {
after = 0
}
db.Model(&inv).Update("quantity", after)
db.Create(&model.InventoryLog{
ShopID: shopID, WarehouseID: whID, ProductID: it.productID,
Direction: "out", Quantity: it.qty, QtyBefore: before, QtyAfter: after,
Direction: "out", Quantity: it.qty, QtyBefore: qtyBefore, QtyAfter: after,
RefType: "stock_out", RefID: r.order.ID, OperatorID: &opID,
})
}