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:
@@ -46,5 +46,5 @@ type Base struct {
|
||||
// TenantBase 含租户隔离的公共字段
|
||||
type TenantBase struct {
|
||||
Base
|
||||
HotelID uint64 `gorm:"not null;index" json:"hotel_id"`
|
||||
ShopID uint64 `gorm:"not null;index" json:"shop_id"`
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ import "time"
|
||||
|
||||
type FinanceRecord struct {
|
||||
Base
|
||||
HotelID uint64 `gorm:"not null;index" json:"hotel_id"`
|
||||
ShopID uint64 `gorm:"not null;index" json:"shop_id"`
|
||||
PartnerID *uint64 `json:"partner_id"`
|
||||
Type string `gorm:"type:enum('receivable','payable','receipt','payment')" json:"type"`
|
||||
Amount float64 `gorm:"type:decimal(14,2)" json:"amount"`
|
||||
Balance float64 `gorm:"type:decimal(14,2)" json:"balance"`
|
||||
Amount float64 `gorm:"type:decimal(16,2)" json:"amount"`
|
||||
Balance float64 `gorm:"type:decimal(16,2)" json:"balance"`
|
||||
RefType string `gorm:"size:30" json:"ref_type"`
|
||||
RefID *uint64 `json:"ref_id"`
|
||||
OperatorID uint64 `gorm:"not null" json:"operator_id"`
|
||||
@@ -20,11 +20,11 @@ type FinanceRecord struct {
|
||||
}
|
||||
|
||||
type NumberRule struct {
|
||||
ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
HotelID uint64 `gorm:"not null;uniqueIndex:uk_hotel_type" json:"hotel_id"`
|
||||
Type string `gorm:"size:30;uniqueIndex:uk_hotel_type" json:"type"`
|
||||
Prefix string `gorm:"size:20;default:''" json:"prefix"`
|
||||
CurrentNo int `gorm:"default:0" json:"current_no"`
|
||||
DateFormat string `gorm:"size:20;default:'YYYYMMDD'" json:"date_format"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
ShopID uint64 `gorm:"not null;uniqueIndex:uk_shop_type" json:"shop_id"`
|
||||
Type string `gorm:"size:30;uniqueIndex:uk_shop_type" json:"type"`
|
||||
Prefix string `gorm:"size:20;default:''" json:"prefix"`
|
||||
CurrentNo int `gorm:"default:0" json:"current_no"`
|
||||
DateFormat string `gorm:"size:20;default:'YYYYMMDD'" json:"date_format"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package model
|
||||
|
||||
type Hotel struct {
|
||||
Base
|
||||
Name string `gorm:"size:100;not null" json:"name"`
|
||||
Code string `gorm:"size:50;uniqueIndex" json:"code"`
|
||||
Address string `gorm:"size:255" json:"address"`
|
||||
Phone string `gorm:"size:30" json:"phone"`
|
||||
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
|
||||
}
|
||||
@@ -4,10 +4,10 @@ import "time"
|
||||
|
||||
type License struct {
|
||||
Base
|
||||
HotelID uint64 `gorm:"not null;index" json:"hotel_id"`
|
||||
ShopID uint64 `gorm:"not null;index" json:"shop_id"`
|
||||
LicenseKey string `gorm:"size:255;uniqueIndex" json:"license_key"`
|
||||
DeviceID string `gorm:"size:255" json:"device_id"`
|
||||
Type string `gorm:"type:enum('trial','annual','lifetime');default:'trial'" json:"type"`
|
||||
Type string `gorm:"type:enum('trial','monthly','annual','lifetime');default:'trial'" json:"type"`
|
||||
ExpiresAt *time.Time `json:"expires_at"`
|
||||
IsActive bool `gorm:"default:true" json:"is_active"`
|
||||
Features JSON `gorm:"type:json" json:"features,omitempty"`
|
||||
|
||||
@@ -3,7 +3,7 @@ package model
|
||||
type Partner struct {
|
||||
TenantBase
|
||||
Code string `gorm:"size:50" json:"code"`
|
||||
Name string `gorm:"size:200;not null" json:"name"`
|
||||
Name string `gorm:"size:200;not null" json:"name" binding:"required"`
|
||||
Type string `gorm:"type:set('supplier','customer');default:'supplier'" json:"type"`
|
||||
Contact string `gorm:"size:50" json:"contact"`
|
||||
Phone string `gorm:"size:30" json:"phone"`
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
type Shop struct {
|
||||
Base
|
||||
Name string `gorm:"size:100;not null" json:"name"`
|
||||
Code string `gorm:"size:50;uniqueIndex" json:"code"`
|
||||
Address string `gorm:"size:255" json:"address"`
|
||||
Phone string `gorm:"size:30" json:"phone"`
|
||||
ManagerName string `gorm:"size:50" json:"manager_name"`
|
||||
BusinessLicense string `gorm:"size:500" json:"business_license"`
|
||||
ShopPhotos JSON `gorm:"type:json" json:"shop_photos,omitempty"`
|
||||
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
|
||||
}
|
||||
@@ -6,15 +6,15 @@ import "time"
|
||||
|
||||
type StockInOrder struct {
|
||||
TenantBase
|
||||
OrderNo string `gorm:"size:50;uniqueIndex:uk_hotel_order_no" json:"order_no"`
|
||||
OrderNo string `gorm:"size:50;uniqueIndex:uk_shop_order_no" json:"order_no"`
|
||||
Type string `gorm:"size:30;default:'purchase'" json:"type"`
|
||||
WarehouseID uint64 `gorm:"not null" json:"warehouse_id"`
|
||||
WarehouseID uint64 `gorm:"not null" json:"warehouse_id" binding:"required,min=1"`
|
||||
PartnerID *uint64 `json:"partner_id"`
|
||||
OperatorID uint64 `gorm:"not null" json:"operator_id"`
|
||||
ReviewerID *uint64 `json:"reviewer_id"`
|
||||
Status string `gorm:"type:enum('draft','pending','approved','rejected');default:'draft'" json:"status"`
|
||||
OrderDate time.Time `gorm:"type:date" json:"order_date"`
|
||||
TotalAmount float64 `gorm:"type:decimal(14,2);default:0" json:"total_amount"`
|
||||
TotalAmount float64 `gorm:"type:decimal(16,2);default:0" json:"total_amount"`
|
||||
ReviewedAt *time.Time `json:"reviewed_at"`
|
||||
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
|
||||
Remark string `gorm:"size:500" json:"remark"`
|
||||
@@ -28,11 +28,11 @@ type StockInOrder struct {
|
||||
type StockInItem struct {
|
||||
Base
|
||||
OrderID uint64 `gorm:"not null;index" json:"order_id"`
|
||||
HotelID uint64 `gorm:"not null" json:"hotel_id"`
|
||||
ShopID uint64 `gorm:"not null" json:"shop_id"`
|
||||
ProductID uint64 `gorm:"not null" json:"product_id"`
|
||||
Quantity float64 `gorm:"type:decimal(12,3);not null" json:"quantity"`
|
||||
UnitPrice float64 `gorm:"type:decimal(12,2);default:0" json:"unit_price"`
|
||||
TotalPrice float64 `gorm:"type:decimal(14,2);default:0" json:"total_price"`
|
||||
UnitPrice float64 `gorm:"type:decimal(16,2);default:0" json:"unit_price"`
|
||||
TotalPrice float64 `gorm:"type:decimal(16,2);default:0" json:"total_price"`
|
||||
BatchNo string `gorm:"size:50" json:"batch_no"`
|
||||
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
|
||||
Remark string `gorm:"size:255" json:"remark"`
|
||||
@@ -44,15 +44,15 @@ type StockInItem struct {
|
||||
|
||||
type StockOutOrder struct {
|
||||
TenantBase
|
||||
OrderNo string `gorm:"size:50;uniqueIndex:uk_hotel_order_no" json:"order_no"`
|
||||
OrderNo string `gorm:"size:50;uniqueIndex:uk_shop_order_no" json:"order_no"`
|
||||
Type string `gorm:"size:30;default:'sale'" json:"type"`
|
||||
WarehouseID uint64 `gorm:"not null" json:"warehouse_id"`
|
||||
WarehouseID uint64 `gorm:"not null" json:"warehouse_id" binding:"required,min=1"`
|
||||
PartnerID *uint64 `json:"partner_id"`
|
||||
OperatorID uint64 `gorm:"not null" json:"operator_id"`
|
||||
ReviewerID *uint64 `json:"reviewer_id"`
|
||||
Status string `gorm:"type:enum('draft','pending','approved','rejected');default:'draft'" json:"status"`
|
||||
OrderDate time.Time `gorm:"type:date" json:"order_date"`
|
||||
TotalAmount float64 `gorm:"type:decimal(14,2);default:0" json:"total_amount"`
|
||||
TotalAmount float64 `gorm:"type:decimal(16,2);default:0" json:"total_amount"`
|
||||
ReviewedAt *time.Time `json:"reviewed_at"`
|
||||
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
|
||||
Remark string `gorm:"size:500" json:"remark"`
|
||||
@@ -66,11 +66,11 @@ type StockOutOrder struct {
|
||||
type StockOutItem struct {
|
||||
Base
|
||||
OrderID uint64 `gorm:"not null;index" json:"order_id"`
|
||||
HotelID uint64 `gorm:"not null" json:"hotel_id"`
|
||||
ShopID uint64 `gorm:"not null" json:"shop_id"`
|
||||
ProductID uint64 `gorm:"not null" json:"product_id"`
|
||||
Quantity float64 `gorm:"type:decimal(12,3);not null" json:"quantity"`
|
||||
UnitPrice float64 `gorm:"type:decimal(12,2);default:0" json:"unit_price"`
|
||||
TotalPrice float64 `gorm:"type:decimal(14,2);default:0" json:"total_price"`
|
||||
UnitPrice float64 `gorm:"type:decimal(16,2);default:0" json:"unit_price"`
|
||||
TotalPrice float64 `gorm:"type:decimal(16,2);default:0" json:"total_price"`
|
||||
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
|
||||
Remark string `gorm:"size:255" json:"remark"`
|
||||
|
||||
@@ -81,9 +81,9 @@ type StockOutItem struct {
|
||||
|
||||
type Inventory struct {
|
||||
ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
HotelID uint64 `gorm:"not null;uniqueIndex:uk_hotel_wh_product" json:"hotel_id"`
|
||||
WarehouseID uint64 `gorm:"not null;uniqueIndex:uk_hotel_wh_product" json:"warehouse_id"`
|
||||
ProductID uint64 `gorm:"not null;uniqueIndex:uk_hotel_wh_product" json:"product_id"`
|
||||
ShopID uint64 `gorm:"not null;uniqueIndex:uk_shop_wh_product" json:"shop_id"`
|
||||
WarehouseID uint64 `gorm:"not null;uniqueIndex:uk_shop_wh_product" json:"warehouse_id"`
|
||||
ProductID uint64 `gorm:"not null;uniqueIndex:uk_shop_wh_product" json:"product_id"`
|
||||
Quantity float64 `gorm:"type:decimal(12,3);default:0" json:"quantity"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
@@ -95,9 +95,9 @@ type Inventory struct {
|
||||
|
||||
type InventoryLog struct {
|
||||
ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
HotelID uint64 `gorm:"not null;index:idx_hotel_product" json:"hotel_id"`
|
||||
ShopID uint64 `gorm:"not null;index:idx_shop_product" json:"shop_id"`
|
||||
WarehouseID uint64 `gorm:"not null" json:"warehouse_id"`
|
||||
ProductID uint64 `gorm:"not null;index:idx_hotel_product" json:"product_id"`
|
||||
ProductID uint64 `gorm:"not null;index:idx_shop_product" json:"product_id"`
|
||||
Direction string `gorm:"type:enum('in','out')" json:"direction"`
|
||||
Quantity float64 `gorm:"type:decimal(12,3)" json:"quantity"`
|
||||
QtyBefore float64 `gorm:"type:decimal(12,3)" json:"qty_before"`
|
||||
@@ -112,7 +112,7 @@ type InventoryLog struct {
|
||||
|
||||
type InventoryCheck struct {
|
||||
TenantBase
|
||||
CheckNo string `gorm:"size:50;uniqueIndex:uk_hotel_check_no" json:"check_no"`
|
||||
CheckNo string `gorm:"size:50;uniqueIndex:uk_shop_check_no" json:"check_no"`
|
||||
WarehouseID uint64 `gorm:"not null" json:"warehouse_id"`
|
||||
OperatorID uint64 `gorm:"not null" json:"operator_id"`
|
||||
Status string `gorm:"type:enum('draft','completed');default:'draft'" json:"status"`
|
||||
@@ -125,7 +125,7 @@ type InventoryCheck struct {
|
||||
type InventoryCheckItem struct {
|
||||
Base
|
||||
CheckID uint64 `gorm:"not null;index" json:"check_id"`
|
||||
HotelID uint64 `gorm:"not null" json:"hotel_id"`
|
||||
ShopID uint64 `gorm:"not null" json:"shop_id"`
|
||||
ProductID uint64 `gorm:"not null" json:"product_id"`
|
||||
SystemQty float64 `gorm:"type:decimal(12,3)" json:"system_qty"`
|
||||
ActualQty float64 `gorm:"type:decimal(12,3)" json:"actual_qty"`
|
||||
|
||||
@@ -2,20 +2,11 @@ package model
|
||||
|
||||
type User struct {
|
||||
TenantBase
|
||||
Username string `gorm:"size:50;uniqueIndex:uk_hotel_username" json:"username"`
|
||||
Username string `gorm:"size:50;uniqueIndex:uk_shop_username" json:"username"`
|
||||
PasswordHash string `gorm:"size:255" json:"-"`
|
||||
RealName string `gorm:"size:50" json:"real_name"`
|
||||
Phone string `gorm:"size:30" json:"phone"`
|
||||
Role string `gorm:"type:enum('admin','operator');default:'operator'" json:"role"`
|
||||
Role string `gorm:"type:enum('admin','operator','readonly');default:'operator'" json:"role"`
|
||||
IsActive bool `gorm:"default:true" json:"is_active"`
|
||||
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
|
||||
}
|
||||
|
||||
type OAuthProvider struct {
|
||||
Base
|
||||
UserID uint64 `gorm:"not null;index" json:"user_id"`
|
||||
Provider string `gorm:"type:enum('wechat','google','apple')" json:"provider"`
|
||||
ProviderUserID string `gorm:"size:255" json:"provider_user_id"`
|
||||
AccessToken string `gorm:"type:text" json:"-"`
|
||||
RefreshToken string `gorm:"type:text" json:"-"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user