diff --git a/backend/cmd/seed/main.go b/backend/cmd/seed/main.go index 3668cf8..5343abf 100644 --- a/backend/cmd/seed/main.go +++ b/backend/cmd/seed/main.go @@ -132,21 +132,21 @@ func main() { hash := mustHash("password123") admin := upsert(db, &model.User{}, "shop_id = ? AND username = ?", shop.ID, "admin", func() any { return &model.User{ - TenantBase: model.TenantBase{ShopID: shop.ID}, + ShopID: shop.ID, Username: "admin", PasswordHash: hash, RealName: "张三(管理员)", Phone: "13800000001", Role: "admin", IsActive: true, } }).(model.User) operator := upsert(db, &model.User{}, "shop_id = ? AND username = ?", shop.ID, "operator", func() any { return &model.User{ - TenantBase: model.TenantBase{ShopID: shop.ID}, + ShopID: shop.ID, Username: "operator", PasswordHash: hash, RealName: "李四(操作员)", Phone: "13800000002", Role: "operator", IsActive: true, } }).(model.User) upsert(db, &model.User{}, "shop_id = ? AND username = ?", shop.ID, "test", func() any { return &model.User{ - TenantBase: model.TenantBase{ShopID: shop.ID}, + ShopID: shop.ID, Username: "test", PasswordHash: hash, RealName: "王五(只读)", Phone: "13800000003", Role: "readonly", IsActive: true, } diff --git a/backend/internal/handler/user.go b/backend/internal/handler/user.go index eba9eb9..952c4d5 100644 --- a/backend/internal/handler/user.go +++ b/backend/internal/handler/user.go @@ -52,7 +52,7 @@ func (h *UserHandler) Create(c *gin.Context) { role = "operator" } u := model.User{ - TenantBase: model.TenantBase{ShopID: shopID}, + ShopID: shopID, Username: req.Username, PasswordHash: string(hash), RealName: req.RealName, diff --git a/backend/internal/model/user.go b/backend/internal/model/user.go index 22292ab..5afa111 100644 --- a/backend/internal/model/user.go +++ b/backend/internal/model/user.go @@ -1,7 +1,8 @@ package model type User struct { - TenantBase + Base + ShopID uint64 `gorm:"not null;index;uniqueIndex:uk_shop_username" json:"shop_id"` 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"` diff --git a/backend/testutil/setup.go b/backend/testutil/setup.go index 1873237..0d53053 100644 --- a/backend/testutil/setup.go +++ b/backend/testutil/setup.go @@ -349,10 +349,7 @@ func hashPassword(plain string) string { func CreateTestUser(db *gorm.DB, shopID uint64, username, password, role string) *model.User { hash := hashPassword(password) user := &model.User{ - TenantBase: model.TenantBase{ - Base: model.Base{}, - ShopID: shopID, - }, + ShopID: shopID, Username: username, PasswordHash: hash, RealName: "Test User " + username,