fix(backend): JWT config mapstructure tag 修复 + 模型从 hotel 重构为 shop

- 修复 JWTConfig 缺少 mapstructure tag 导致 access_expire_min 解析为 0,
  token 签发即过期,所有 API 请求返回 401
- 全部 config struct 补齐 mapstructure tag(secret/dsn/hmac_secret 等)
- 模型层从 hotel/HotelID 统一重命名为 shop/ShopID
- 删除旧 migrations(001-004),新增 001_init 综合迁移文件
- 更新 schema.sql、testutil、handler/service/model 相关引用

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-04-07 22:20:12 +08:00
parent 37112d6599
commit 31ea370cea
50 changed files with 2675 additions and 951 deletions
+11 -12
View File
@@ -21,11 +21,11 @@ func NewInventoryHandler(db *gorm.DB) *InventoryHandler {
// List GET /api/v1/inventory
func (h *InventoryHandler) List(c *gin.Context) {
hotelID := middleware.GetHotelID(c)
shopID := middleware.GetShopID(c)
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
query := h.db.Model(&model.Inventory{}).Where("hotel_id = ?", hotelID)
query := h.db.Model(&model.Inventory{}).Where("shop_id = ?", shopID)
if warehouseID := c.Query("warehouse_id"); warehouseID != "" {
query = query.Where("warehouse_id = ?", warehouseID)
@@ -33,7 +33,6 @@ func (h *InventoryHandler) List(c *gin.Context) {
if productID := c.Query("product_id"); productID != "" {
query = query.Where("product_id = ?", productID)
}
// 仅显示有库存
if c.Query("in_stock") == "1" {
query = query.Where("quantity > 0")
}
@@ -51,11 +50,11 @@ func (h *InventoryHandler) List(c *gin.Context) {
// Logs GET /api/v1/inventory/logs
func (h *InventoryHandler) Logs(c *gin.Context) {
hotelID := middleware.GetHotelID(c)
shopID := middleware.GetShopID(c)
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
query := h.db.Model(&model.InventoryLog{}).Where("hotel_id = ?", hotelID)
query := h.db.Model(&model.InventoryLog{}).Where("shop_id = ?", shopID)
if productID := c.Query("product_id"); productID != "" {
query = query.Where("product_id = ?", productID)
@@ -72,7 +71,7 @@ func (h *InventoryHandler) Logs(c *gin.Context) {
// CreateCheck POST /api/v1/inventory/checks
func (h *InventoryHandler) CreateCheck(c *gin.Context) {
hotelID := middleware.GetHotelID(c)
shopID := middleware.GetShopID(c)
operatorID := middleware.GetUserID(c)
var req model.InventoryCheck
@@ -81,16 +80,16 @@ func (h *InventoryHandler) CreateCheck(c *gin.Context) {
return
}
req.HotelID = hotelID
req.ShopID = shopID
req.OperatorID = operatorID
req.Status = "draft"
// 自动填入系统库存数量
for i := range req.Items {
req.Items[i].HotelID = hotelID
req.Items[i].ShopID = shopID
var inv model.Inventory
if err := h.db.Where("hotel_id = ? AND warehouse_id = ? AND product_id = ?",
hotelID, req.WarehouseID, req.Items[i].ProductID).First(&inv).Error; err == nil {
if err := h.db.Where("shop_id = ? AND warehouse_id = ? AND product_id = ?",
shopID, req.WarehouseID, req.Items[i].ProductID).First(&inv).Error; err == nil {
req.Items[i].SystemQty = inv.Quantity
}
}
@@ -104,10 +103,10 @@ func (h *InventoryHandler) CreateCheck(c *gin.Context) {
// GetCheck GET /api/v1/inventory/checks/:id
func (h *InventoryHandler) GetCheck(c *gin.Context) {
hotelID := middleware.GetHotelID(c)
shopID := middleware.GetShopID(c)
var check model.InventoryCheck
if err := h.db.Preload("Items.Product").
Where("id = ? AND hotel_id = ?", c.Param("id"), hotelID).
Where("id = ? AND shop_id = ?", c.Param("id"), shopID).
First(&check).Error; err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "not found"})
return