完善定价与套餐关联表结构

This commit is contained in:
2026-03-24 16:25:21 +08:00
parent c9995ef566
commit 5ffa151f58
28 changed files with 1550 additions and 112 deletions

View File

@@ -29,6 +29,7 @@ func newResourceLong(db *gorm.DB, opts ...gen.DOOption) resourceLong {
_resourceLong.ALL = field.NewAsterisk(tableName)
_resourceLong.ID = field.NewInt32(tableName, "id")
_resourceLong.ResourceID = field.NewInt32(tableName, "resource_id")
_resourceLong.Code = field.NewString(tableName, "code")
_resourceLong.Live = field.NewInt32(tableName, "live")
_resourceLong.Type = field.NewInt(tableName, "type")
_resourceLong.Quota = field.NewInt32(tableName, "quota")
@@ -36,6 +37,21 @@ func newResourceLong(db *gorm.DB, opts ...gen.DOOption) resourceLong {
_resourceLong.Used = field.NewInt32(tableName, "used")
_resourceLong.Daily = field.NewInt32(tableName, "daily")
_resourceLong.LastAt = field.NewTime(tableName, "last_at")
_resourceLong.Sku = resourceLongHasOneSku{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("Sku", "models.ProductSku"),
Product: struct {
field.RelationField
}{
RelationField: field.NewRelation("Sku.Product", "models.Product"),
},
Discount: struct {
field.RelationField
}{
RelationField: field.NewRelation("Sku.Discount", "models.ProductDiscount"),
},
}
_resourceLong.fillFieldMap()
@@ -48,6 +64,7 @@ type resourceLong struct {
ALL field.Asterisk
ID field.Int32
ResourceID field.Int32
Code field.String
Live field.Int32
Type field.Int
Quota field.Int32
@@ -55,6 +72,7 @@ type resourceLong struct {
Used field.Int32
Daily field.Int32
LastAt field.Time
Sku resourceLongHasOneSku
fieldMap map[string]field.Expr
}
@@ -73,6 +91,7 @@ func (r *resourceLong) updateTableName(table string) *resourceLong {
r.ALL = field.NewAsterisk(table)
r.ID = field.NewInt32(table, "id")
r.ResourceID = field.NewInt32(table, "resource_id")
r.Code = field.NewString(table, "code")
r.Live = field.NewInt32(table, "live")
r.Type = field.NewInt(table, "type")
r.Quota = field.NewInt32(table, "quota")
@@ -96,9 +115,10 @@ func (r *resourceLong) GetFieldByName(fieldName string) (field.OrderExpr, bool)
}
func (r *resourceLong) fillFieldMap() {
r.fieldMap = make(map[string]field.Expr, 9)
r.fieldMap = make(map[string]field.Expr, 11)
r.fieldMap["id"] = r.ID
r.fieldMap["resource_id"] = r.ResourceID
r.fieldMap["code"] = r.Code
r.fieldMap["live"] = r.Live
r.fieldMap["type"] = r.Type
r.fieldMap["quota"] = r.Quota
@@ -106,18 +126,110 @@ func (r *resourceLong) fillFieldMap() {
r.fieldMap["used"] = r.Used
r.fieldMap["daily"] = r.Daily
r.fieldMap["last_at"] = r.LastAt
}
func (r resourceLong) clone(db *gorm.DB) resourceLong {
r.resourceLongDo.ReplaceConnPool(db.Statement.ConnPool)
r.Sku.db = db.Session(&gorm.Session{Initialized: true})
r.Sku.db.Statement.ConnPool = db.Statement.ConnPool
return r
}
func (r resourceLong) replaceDB(db *gorm.DB) resourceLong {
r.resourceLongDo.ReplaceDB(db)
r.Sku.db = db.Session(&gorm.Session{})
return r
}
type resourceLongHasOneSku struct {
db *gorm.DB
field.RelationField
Product struct {
field.RelationField
}
Discount struct {
field.RelationField
}
}
func (a resourceLongHasOneSku) Where(conds ...field.Expr) *resourceLongHasOneSku {
if len(conds) == 0 {
return &a
}
exprs := make([]clause.Expression, 0, len(conds))
for _, cond := range conds {
exprs = append(exprs, cond.BeCond().(clause.Expression))
}
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
return &a
}
func (a resourceLongHasOneSku) WithContext(ctx context.Context) *resourceLongHasOneSku {
a.db = a.db.WithContext(ctx)
return &a
}
func (a resourceLongHasOneSku) Session(session *gorm.Session) *resourceLongHasOneSku {
a.db = a.db.Session(session)
return &a
}
func (a resourceLongHasOneSku) Model(m *models.ResourceLong) *resourceLongHasOneSkuTx {
return &resourceLongHasOneSkuTx{a.db.Model(m).Association(a.Name())}
}
func (a resourceLongHasOneSku) Unscoped() *resourceLongHasOneSku {
a.db = a.db.Unscoped()
return &a
}
type resourceLongHasOneSkuTx struct{ tx *gorm.Association }
func (a resourceLongHasOneSkuTx) Find() (result *models.ProductSku, err error) {
return result, a.tx.Find(&result)
}
func (a resourceLongHasOneSkuTx) Append(values ...*models.ProductSku) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Append(targetValues...)
}
func (a resourceLongHasOneSkuTx) Replace(values ...*models.ProductSku) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Replace(targetValues...)
}
func (a resourceLongHasOneSkuTx) Delete(values ...*models.ProductSku) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Delete(targetValues...)
}
func (a resourceLongHasOneSkuTx) Clear() error {
return a.tx.Clear()
}
func (a resourceLongHasOneSkuTx) Count() int64 {
return a.tx.Count()
}
func (a resourceLongHasOneSkuTx) Unscoped() *resourceLongHasOneSkuTx {
a.tx = a.tx.Unscoped()
return &a
}
type resourceLongDo struct{ gen.DO }
func (r resourceLongDo) Debug() *resourceLongDo {