完善定价与套餐关联表结构
This commit is contained in:
@@ -30,8 +30,7 @@ func newProductSkuUser(db *gorm.DB, opts ...gen.DOOption) productSkuUser {
|
||||
_productSkuUser.ID = field.NewInt32(tableName, "id")
|
||||
_productSkuUser.UserID = field.NewInt32(tableName, "user_id")
|
||||
_productSkuUser.ProductSkuID = field.NewInt32(tableName, "product_sku_id")
|
||||
_productSkuUser.Price = field.NewField(tableName, "price")
|
||||
_productSkuUser.Discount = field.NewFloat32(tableName, "discount")
|
||||
_productSkuUser.DiscountId = field.NewInt32(tableName, "discount_id")
|
||||
_productSkuUser.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_productSkuUser.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_productSkuUser.User = productSkuUserBelongsToUser{
|
||||
@@ -114,6 +113,17 @@ func newProductSkuUser(db *gorm.DB, opts ...gen.DOOption) productSkuUser {
|
||||
}{
|
||||
RelationField: field.NewRelation("ProductSku.Product", "models.Product"),
|
||||
},
|
||||
Discount: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("ProductSku.Discount", "models.ProductDiscount"),
|
||||
},
|
||||
}
|
||||
|
||||
_productSkuUser.Discount = productSkuUserBelongsToDiscount{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Discount", "models.ProductDiscount"),
|
||||
}
|
||||
|
||||
_productSkuUser.fillFieldMap()
|
||||
@@ -128,14 +138,15 @@ type productSkuUser struct {
|
||||
ID field.Int32
|
||||
UserID field.Int32
|
||||
ProductSkuID field.Int32
|
||||
Price field.Field
|
||||
Discount field.Float32
|
||||
DiscountId field.Int32
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
User productSkuUserBelongsToUser
|
||||
|
||||
ProductSku productSkuUserBelongsToProductSku
|
||||
|
||||
Discount productSkuUserBelongsToDiscount
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
@@ -154,8 +165,7 @@ func (p *productSkuUser) updateTableName(table string) *productSkuUser {
|
||||
p.ID = field.NewInt32(table, "id")
|
||||
p.UserID = field.NewInt32(table, "user_id")
|
||||
p.ProductSkuID = field.NewInt32(table, "product_sku_id")
|
||||
p.Price = field.NewField(table, "price")
|
||||
p.Discount = field.NewFloat32(table, "discount")
|
||||
p.DiscountId = field.NewInt32(table, "discount_id")
|
||||
p.CreatedAt = field.NewTime(table, "created_at")
|
||||
p.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
|
||||
@@ -178,8 +188,7 @@ func (p *productSkuUser) fillFieldMap() {
|
||||
p.fieldMap["id"] = p.ID
|
||||
p.fieldMap["user_id"] = p.UserID
|
||||
p.fieldMap["product_sku_id"] = p.ProductSkuID
|
||||
p.fieldMap["price"] = p.Price
|
||||
p.fieldMap["discount"] = p.Discount
|
||||
p.fieldMap["discount_id"] = p.DiscountId
|
||||
p.fieldMap["created_at"] = p.CreatedAt
|
||||
p.fieldMap["updated_at"] = p.UpdatedAt
|
||||
|
||||
@@ -191,6 +200,8 @@ func (p productSkuUser) clone(db *gorm.DB) productSkuUser {
|
||||
p.User.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
p.ProductSku.db = db.Session(&gorm.Session{Initialized: true})
|
||||
p.ProductSku.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
p.Discount.db = db.Session(&gorm.Session{Initialized: true})
|
||||
p.Discount.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
return p
|
||||
}
|
||||
|
||||
@@ -198,6 +209,7 @@ func (p productSkuUser) replaceDB(db *gorm.DB) productSkuUser {
|
||||
p.productSkuUserDo.ReplaceDB(db)
|
||||
p.User.db = db.Session(&gorm.Session{})
|
||||
p.ProductSku.db = db.Session(&gorm.Session{})
|
||||
p.Discount.db = db.Session(&gorm.Session{})
|
||||
return p
|
||||
}
|
||||
|
||||
@@ -312,6 +324,9 @@ type productSkuUserBelongsToProductSku struct {
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
|
||||
func (a productSkuUserBelongsToProductSku) Where(conds ...field.Expr) *productSkuUserBelongsToProductSku {
|
||||
@@ -389,6 +404,87 @@ func (a productSkuUserBelongsToProductSkuTx) Unscoped() *productSkuUserBelongsTo
|
||||
return &a
|
||||
}
|
||||
|
||||
type productSkuUserBelongsToDiscount struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a productSkuUserBelongsToDiscount) Where(conds ...field.Expr) *productSkuUserBelongsToDiscount {
|
||||
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 productSkuUserBelongsToDiscount) WithContext(ctx context.Context) *productSkuUserBelongsToDiscount {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a productSkuUserBelongsToDiscount) Session(session *gorm.Session) *productSkuUserBelongsToDiscount {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a productSkuUserBelongsToDiscount) Model(m *models.ProductSkuUser) *productSkuUserBelongsToDiscountTx {
|
||||
return &productSkuUserBelongsToDiscountTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a productSkuUserBelongsToDiscount) Unscoped() *productSkuUserBelongsToDiscount {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type productSkuUserBelongsToDiscountTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a productSkuUserBelongsToDiscountTx) Find() (result *models.ProductDiscount, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a productSkuUserBelongsToDiscountTx) Append(values ...*models.ProductDiscount) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a productSkuUserBelongsToDiscountTx) Replace(values ...*models.ProductDiscount) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a productSkuUserBelongsToDiscountTx) Delete(values ...*models.ProductDiscount) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a productSkuUserBelongsToDiscountTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a productSkuUserBelongsToDiscountTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a productSkuUserBelongsToDiscountTx) Unscoped() *productSkuUserBelongsToDiscountTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type productSkuUserDo struct{ gen.DO }
|
||||
|
||||
func (p productSkuUserDo) Debug() *productSkuUserDo {
|
||||
|
||||
Reference in New Issue
Block a user