完善定价与套餐关联表结构
This commit is contained in:
@@ -132,13 +132,56 @@ func newBill(db *gorm.DB, opts ...gen.DOOption) bill {
|
||||
},
|
||||
Short: struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Short", "models.ResourceShort"),
|
||||
Sku: struct {
|
||||
field.RelationField
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Short.Sku", "models.ProductSku"),
|
||||
Product: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Short.Sku.Product", "models.Product"),
|
||||
},
|
||||
Discount: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Short.Sku.Discount", "models.ProductDiscount"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Long: struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Long", "models.ResourceLong"),
|
||||
Sku: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Long.Sku", "models.ProductSku"),
|
||||
},
|
||||
},
|
||||
Product: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Product", "models.Product"),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -456,9 +499,24 @@ type billBelongsToResource struct {
|
||||
}
|
||||
Short struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Long struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,13 +129,56 @@ func newChannel(db *gorm.DB, opts ...gen.DOOption) channel {
|
||||
},
|
||||
Short: struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Short", "models.ResourceShort"),
|
||||
Sku: struct {
|
||||
field.RelationField
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Short.Sku", "models.ProductSku"),
|
||||
Product: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Short.Sku.Product", "models.Product"),
|
||||
},
|
||||
Discount: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Short.Sku.Discount", "models.ProductDiscount"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Long: struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Long", "models.ResourceLong"),
|
||||
Sku: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Long.Sku", "models.ProductSku"),
|
||||
},
|
||||
},
|
||||
Product: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Product", "models.Product"),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -435,9 +478,24 @@ type channelBelongsToResource struct {
|
||||
}
|
||||
Short struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Long struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ var (
|
||||
LogsUserUsage *logsUserUsage
|
||||
Permission *permission
|
||||
Product *product
|
||||
ProductDiscount *productDiscount
|
||||
ProductSku *productSku
|
||||
ProductSkuUser *productSkuUser
|
||||
Proxy *proxy
|
||||
@@ -73,6 +74,7 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
LogsUserUsage = &Q.LogsUserUsage
|
||||
Permission = &Q.Permission
|
||||
Product = &Q.Product
|
||||
ProductDiscount = &Q.ProductDiscount
|
||||
ProductSku = &Q.ProductSku
|
||||
ProductSkuUser = &Q.ProductSkuUser
|
||||
Proxy = &Q.Proxy
|
||||
@@ -110,6 +112,7 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
LogsUserUsage: newLogsUserUsage(db, opts...),
|
||||
Permission: newPermission(db, opts...),
|
||||
Product: newProduct(db, opts...),
|
||||
ProductDiscount: newProductDiscount(db, opts...),
|
||||
ProductSku: newProductSku(db, opts...),
|
||||
ProductSkuUser: newProductSkuUser(db, opts...),
|
||||
Proxy: newProxy(db, opts...),
|
||||
@@ -148,6 +151,7 @@ type Query struct {
|
||||
LogsUserUsage logsUserUsage
|
||||
Permission permission
|
||||
Product product
|
||||
ProductDiscount productDiscount
|
||||
ProductSku productSku
|
||||
ProductSkuUser productSkuUser
|
||||
Proxy proxy
|
||||
@@ -187,6 +191,7 @@ func (q *Query) clone(db *gorm.DB) *Query {
|
||||
LogsUserUsage: q.LogsUserUsage.clone(db),
|
||||
Permission: q.Permission.clone(db),
|
||||
Product: q.Product.clone(db),
|
||||
ProductDiscount: q.ProductDiscount.clone(db),
|
||||
ProductSku: q.ProductSku.clone(db),
|
||||
ProductSkuUser: q.ProductSkuUser.clone(db),
|
||||
Proxy: q.Proxy.clone(db),
|
||||
@@ -233,6 +238,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
LogsUserUsage: q.LogsUserUsage.replaceDB(db),
|
||||
Permission: q.Permission.replaceDB(db),
|
||||
Product: q.Product.replaceDB(db),
|
||||
ProductDiscount: q.ProductDiscount.replaceDB(db),
|
||||
ProductSku: q.ProductSku.replaceDB(db),
|
||||
ProductSkuUser: q.ProductSkuUser.replaceDB(db),
|
||||
Proxy: q.Proxy.replaceDB(db),
|
||||
@@ -269,6 +275,7 @@ type queryCtx struct {
|
||||
LogsUserUsage *logsUserUsageDo
|
||||
Permission *permissionDo
|
||||
Product *productDo
|
||||
ProductDiscount *productDiscountDo
|
||||
ProductSku *productSkuDo
|
||||
ProductSkuUser *productSkuUserDo
|
||||
Proxy *proxyDo
|
||||
@@ -305,6 +312,7 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
LogsUserUsage: q.LogsUserUsage.WithContext(ctx),
|
||||
Permission: q.Permission.WithContext(ctx),
|
||||
Product: q.Product.WithContext(ctx),
|
||||
ProductDiscount: q.ProductDiscount.WithContext(ctx),
|
||||
ProductSku: q.ProductSku.WithContext(ctx),
|
||||
ProductSkuUser: q.ProductSkuUser.WithContext(ctx),
|
||||
Proxy: q.Proxy.WithContext(ctx),
|
||||
|
||||
@@ -119,13 +119,56 @@ func newLogsUserUsage(db *gorm.DB, opts ...gen.DOOption) logsUserUsage {
|
||||
},
|
||||
Short: struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Short", "models.ResourceShort"),
|
||||
Sku: struct {
|
||||
field.RelationField
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Short.Sku", "models.ProductSku"),
|
||||
Product: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Short.Sku.Product", "models.Product"),
|
||||
},
|
||||
Discount: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Short.Sku.Discount", "models.ProductDiscount"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Long: struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Long", "models.ResourceLong"),
|
||||
Sku: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Long.Sku", "models.ProductSku"),
|
||||
},
|
||||
},
|
||||
Product: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Product", "models.Product"),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -336,9 +379,24 @@ type logsUserUsageBelongsToResource struct {
|
||||
}
|
||||
Short struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Long struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
339
web/queries/product_discount.gen.go
Normal file
339
web/queries/product_discount.gen.go
Normal file
@@ -0,0 +1,339 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"platform/web/models"
|
||||
)
|
||||
|
||||
func newProductDiscount(db *gorm.DB, opts ...gen.DOOption) productDiscount {
|
||||
_productDiscount := productDiscount{}
|
||||
|
||||
_productDiscount.productDiscountDo.UseDB(db, opts...)
|
||||
_productDiscount.productDiscountDo.UseModel(&models.ProductDiscount{})
|
||||
|
||||
tableName := _productDiscount.productDiscountDo.TableName()
|
||||
_productDiscount.ALL = field.NewAsterisk(tableName)
|
||||
_productDiscount.ID = field.NewInt32(tableName, "id")
|
||||
_productDiscount.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_productDiscount.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_productDiscount.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_productDiscount.Name = field.NewString(tableName, "name")
|
||||
_productDiscount.Discount = field.NewInt32(tableName, "discount")
|
||||
|
||||
_productDiscount.fillFieldMap()
|
||||
|
||||
return _productDiscount
|
||||
}
|
||||
|
||||
type productDiscount struct {
|
||||
productDiscountDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int32
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
Name field.String
|
||||
Discount field.Int32
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (p productDiscount) Table(newTableName string) *productDiscount {
|
||||
p.productDiscountDo.UseTable(newTableName)
|
||||
return p.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (p productDiscount) As(alias string) *productDiscount {
|
||||
p.productDiscountDo.DO = *(p.productDiscountDo.As(alias).(*gen.DO))
|
||||
return p.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (p *productDiscount) updateTableName(table string) *productDiscount {
|
||||
p.ALL = field.NewAsterisk(table)
|
||||
p.ID = field.NewInt32(table, "id")
|
||||
p.CreatedAt = field.NewTime(table, "created_at")
|
||||
p.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
p.DeletedAt = field.NewField(table, "deleted_at")
|
||||
p.Name = field.NewString(table, "name")
|
||||
p.Discount = field.NewInt32(table, "discount")
|
||||
|
||||
p.fillFieldMap()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *productDiscount) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := p.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (p *productDiscount) fillFieldMap() {
|
||||
p.fieldMap = make(map[string]field.Expr, 6)
|
||||
p.fieldMap["id"] = p.ID
|
||||
p.fieldMap["created_at"] = p.CreatedAt
|
||||
p.fieldMap["updated_at"] = p.UpdatedAt
|
||||
p.fieldMap["deleted_at"] = p.DeletedAt
|
||||
p.fieldMap["name"] = p.Name
|
||||
p.fieldMap["discount"] = p.Discount
|
||||
}
|
||||
|
||||
func (p productDiscount) clone(db *gorm.DB) productDiscount {
|
||||
p.productDiscountDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p productDiscount) replaceDB(db *gorm.DB) productDiscount {
|
||||
p.productDiscountDo.ReplaceDB(db)
|
||||
return p
|
||||
}
|
||||
|
||||
type productDiscountDo struct{ gen.DO }
|
||||
|
||||
func (p productDiscountDo) Debug() *productDiscountDo {
|
||||
return p.withDO(p.DO.Debug())
|
||||
}
|
||||
|
||||
func (p productDiscountDo) WithContext(ctx context.Context) *productDiscountDo {
|
||||
return p.withDO(p.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) ReadDB() *productDiscountDo {
|
||||
return p.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (p productDiscountDo) WriteDB() *productDiscountDo {
|
||||
return p.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Session(config *gorm.Session) *productDiscountDo {
|
||||
return p.withDO(p.DO.Session(config))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Clauses(conds ...clause.Expression) *productDiscountDo {
|
||||
return p.withDO(p.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Returning(value interface{}, columns ...string) *productDiscountDo {
|
||||
return p.withDO(p.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Not(conds ...gen.Condition) *productDiscountDo {
|
||||
return p.withDO(p.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Or(conds ...gen.Condition) *productDiscountDo {
|
||||
return p.withDO(p.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Select(conds ...field.Expr) *productDiscountDo {
|
||||
return p.withDO(p.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Where(conds ...gen.Condition) *productDiscountDo {
|
||||
return p.withDO(p.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Order(conds ...field.Expr) *productDiscountDo {
|
||||
return p.withDO(p.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Distinct(cols ...field.Expr) *productDiscountDo {
|
||||
return p.withDO(p.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Omit(cols ...field.Expr) *productDiscountDo {
|
||||
return p.withDO(p.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Join(table schema.Tabler, on ...field.Expr) *productDiscountDo {
|
||||
return p.withDO(p.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) LeftJoin(table schema.Tabler, on ...field.Expr) *productDiscountDo {
|
||||
return p.withDO(p.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) RightJoin(table schema.Tabler, on ...field.Expr) *productDiscountDo {
|
||||
return p.withDO(p.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Group(cols ...field.Expr) *productDiscountDo {
|
||||
return p.withDO(p.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Having(conds ...gen.Condition) *productDiscountDo {
|
||||
return p.withDO(p.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Limit(limit int) *productDiscountDo {
|
||||
return p.withDO(p.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Offset(offset int) *productDiscountDo {
|
||||
return p.withDO(p.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *productDiscountDo {
|
||||
return p.withDO(p.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Unscoped() *productDiscountDo {
|
||||
return p.withDO(p.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Create(values ...*models.ProductDiscount) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Create(values)
|
||||
}
|
||||
|
||||
func (p productDiscountDo) CreateInBatches(values []*models.ProductDiscount, batchSize int) error {
|
||||
return p.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (p productDiscountDo) Save(values ...*models.ProductDiscount) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Save(values)
|
||||
}
|
||||
|
||||
func (p productDiscountDo) First() (*models.ProductDiscount, error) {
|
||||
if result, err := p.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ProductDiscount), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Take() (*models.ProductDiscount, error) {
|
||||
if result, err := p.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ProductDiscount), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Last() (*models.ProductDiscount, error) {
|
||||
if result, err := p.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ProductDiscount), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Find() ([]*models.ProductDiscount, error) {
|
||||
result, err := p.DO.Find()
|
||||
return result.([]*models.ProductDiscount), err
|
||||
}
|
||||
|
||||
func (p productDiscountDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.ProductDiscount, err error) {
|
||||
buf := make([]*models.ProductDiscount, 0, batchSize)
|
||||
err = p.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (p productDiscountDo) FindInBatches(result *[]*models.ProductDiscount, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return p.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Attrs(attrs ...field.AssignExpr) *productDiscountDo {
|
||||
return p.withDO(p.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Assign(attrs ...field.AssignExpr) *productDiscountDo {
|
||||
return p.withDO(p.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Joins(fields ...field.RelationField) *productDiscountDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Joins(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Preload(fields ...field.RelationField) *productDiscountDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Preload(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p productDiscountDo) FirstOrInit() (*models.ProductDiscount, error) {
|
||||
if result, err := p.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ProductDiscount), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p productDiscountDo) FirstOrCreate() (*models.ProductDiscount, error) {
|
||||
if result, err := p.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ProductDiscount), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p productDiscountDo) FindByPage(offset int, limit int) (result []*models.ProductDiscount, count int64, err error) {
|
||||
result, err = p.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = p.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (p productDiscountDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = p.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = p.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Scan(result interface{}) (err error) {
|
||||
return p.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (p productDiscountDo) Delete(models ...*models.ProductDiscount) (result gen.ResultInfo, err error) {
|
||||
return p.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (p *productDiscountDo) withDO(do gen.Dao) *productDiscountDo {
|
||||
p.DO = *do.(*gen.DO)
|
||||
return p
|
||||
}
|
||||
@@ -32,16 +32,22 @@ func newProductSku(db *gorm.DB, opts ...gen.DOOption) productSku {
|
||||
_productSku.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_productSku.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_productSku.ProductID = field.NewInt32(tableName, "product_id")
|
||||
_productSku.DiscountId = field.NewInt32(tableName, "discount_id")
|
||||
_productSku.Code = field.NewString(tableName, "code")
|
||||
_productSku.Name = field.NewString(tableName, "name")
|
||||
_productSku.Price = field.NewField(tableName, "price")
|
||||
_productSku.Discount = field.NewFloat32(tableName, "discount")
|
||||
_productSku.Product = productSkuBelongsToProduct{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Product", "models.Product"),
|
||||
}
|
||||
|
||||
_productSku.Discount = productSkuBelongsToDiscount{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Discount", "models.ProductDiscount"),
|
||||
}
|
||||
|
||||
_productSku.fillFieldMap()
|
||||
|
||||
return _productSku
|
||||
@@ -50,17 +56,19 @@ func newProductSku(db *gorm.DB, opts ...gen.DOOption) productSku {
|
||||
type productSku struct {
|
||||
productSkuDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int32
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
ProductID field.Int32
|
||||
Code field.String
|
||||
Name field.String
|
||||
Price field.Field
|
||||
Discount field.Float32
|
||||
Product productSkuBelongsToProduct
|
||||
ALL field.Asterisk
|
||||
ID field.Int32
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
ProductID field.Int32
|
||||
DiscountId field.Int32
|
||||
Code field.String
|
||||
Name field.String
|
||||
Price field.Field
|
||||
Product productSkuBelongsToProduct
|
||||
|
||||
Discount productSkuBelongsToDiscount
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
@@ -82,10 +90,10 @@ func (p *productSku) updateTableName(table string) *productSku {
|
||||
p.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
p.DeletedAt = field.NewField(table, "deleted_at")
|
||||
p.ProductID = field.NewInt32(table, "product_id")
|
||||
p.DiscountId = field.NewInt32(table, "discount_id")
|
||||
p.Code = field.NewString(table, "code")
|
||||
p.Name = field.NewString(table, "name")
|
||||
p.Price = field.NewField(table, "price")
|
||||
p.Discount = field.NewFloat32(table, "discount")
|
||||
|
||||
p.fillFieldMap()
|
||||
|
||||
@@ -102,16 +110,16 @@ func (p *productSku) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
}
|
||||
|
||||
func (p *productSku) fillFieldMap() {
|
||||
p.fieldMap = make(map[string]field.Expr, 10)
|
||||
p.fieldMap = make(map[string]field.Expr, 11)
|
||||
p.fieldMap["id"] = p.ID
|
||||
p.fieldMap["created_at"] = p.CreatedAt
|
||||
p.fieldMap["updated_at"] = p.UpdatedAt
|
||||
p.fieldMap["deleted_at"] = p.DeletedAt
|
||||
p.fieldMap["product_id"] = p.ProductID
|
||||
p.fieldMap["discount_id"] = p.DiscountId
|
||||
p.fieldMap["code"] = p.Code
|
||||
p.fieldMap["name"] = p.Name
|
||||
p.fieldMap["price"] = p.Price
|
||||
p.fieldMap["discount"] = p.Discount
|
||||
|
||||
}
|
||||
|
||||
@@ -119,12 +127,15 @@ func (p productSku) clone(db *gorm.DB) productSku {
|
||||
p.productSkuDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
p.Product.db = db.Session(&gorm.Session{Initialized: true})
|
||||
p.Product.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
|
||||
}
|
||||
|
||||
func (p productSku) replaceDB(db *gorm.DB) productSku {
|
||||
p.productSkuDo.ReplaceDB(db)
|
||||
p.Product.db = db.Session(&gorm.Session{})
|
||||
p.Discount.db = db.Session(&gorm.Session{})
|
||||
return p
|
||||
}
|
||||
|
||||
@@ -209,6 +220,87 @@ func (a productSkuBelongsToProductTx) Unscoped() *productSkuBelongsToProductTx {
|
||||
return &a
|
||||
}
|
||||
|
||||
type productSkuBelongsToDiscount struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a productSkuBelongsToDiscount) Where(conds ...field.Expr) *productSkuBelongsToDiscount {
|
||||
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 productSkuBelongsToDiscount) WithContext(ctx context.Context) *productSkuBelongsToDiscount {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a productSkuBelongsToDiscount) Session(session *gorm.Session) *productSkuBelongsToDiscount {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a productSkuBelongsToDiscount) Model(m *models.ProductSku) *productSkuBelongsToDiscountTx {
|
||||
return &productSkuBelongsToDiscountTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a productSkuBelongsToDiscount) Unscoped() *productSkuBelongsToDiscount {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type productSkuBelongsToDiscountTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a productSkuBelongsToDiscountTx) Find() (result *models.ProductDiscount, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a productSkuBelongsToDiscountTx) 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 productSkuBelongsToDiscountTx) 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 productSkuBelongsToDiscountTx) 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 productSkuBelongsToDiscountTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a productSkuBelongsToDiscountTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a productSkuBelongsToDiscountTx) Unscoped() *productSkuBelongsToDiscountTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type productSkuDo struct{ gen.DO }
|
||||
|
||||
func (p productSkuDo) Debug() *productSkuDo {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -141,9 +141,24 @@ func newProxy(db *gorm.DB, opts ...gen.DOOption) proxy {
|
||||
}
|
||||
Short struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Long struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Channels.Resource", "models.Resource"),
|
||||
@@ -154,13 +169,56 @@ func newProxy(db *gorm.DB, opts ...gen.DOOption) proxy {
|
||||
},
|
||||
Short: struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Channels.Resource.Short", "models.ResourceShort"),
|
||||
Sku: struct {
|
||||
field.RelationField
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Channels.Resource.Short.Sku", "models.ProductSku"),
|
||||
Product: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Channels.Resource.Short.Sku.Product", "models.Product"),
|
||||
},
|
||||
Discount: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Channels.Resource.Short.Sku.Discount", "models.ProductDiscount"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Long: struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Channels.Resource.Long", "models.ResourceLong"),
|
||||
Sku: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Channels.Resource.Long.Sku", "models.ProductSku"),
|
||||
},
|
||||
},
|
||||
Product: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Channels.Resource.Product", "models.Product"),
|
||||
},
|
||||
},
|
||||
Proxy: struct {
|
||||
@@ -314,9 +372,24 @@ type proxyHasManyChannels struct {
|
||||
}
|
||||
Short struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
Long struct {
|
||||
field.RelationField
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
Proxy struct {
|
||||
|
||||
@@ -35,16 +35,49 @@ func newResource(db *gorm.DB, opts ...gen.DOOption) resource {
|
||||
_resource.ResourceNo = field.NewString(tableName, "resource_no")
|
||||
_resource.Active = field.NewBool(tableName, "active")
|
||||
_resource.Type = field.NewInt(tableName, "type")
|
||||
_resource.Code = field.NewString(tableName, "code")
|
||||
_resource.Short = resourceHasOneShort{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Short", "models.ResourceShort"),
|
||||
Sku: struct {
|
||||
field.RelationField
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
}{
|
||||
RelationField: field.NewRelation("Short.Sku", "models.ProductSku"),
|
||||
Product: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Short.Sku.Product", "models.Product"),
|
||||
},
|
||||
Discount: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Short.Sku.Discount", "models.ProductDiscount"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
_resource.Long = resourceHasOneLong{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Long", "models.ResourceLong"),
|
||||
Sku: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Long.Sku", "models.ProductSku"),
|
||||
},
|
||||
}
|
||||
|
||||
_resource.Product = resourceHasOneProduct{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Product", "models.Product"),
|
||||
}
|
||||
|
||||
_resource.User = resourceBelongsToUser{
|
||||
@@ -135,10 +168,13 @@ type resource struct {
|
||||
ResourceNo field.String
|
||||
Active field.Bool
|
||||
Type field.Int
|
||||
Code field.String
|
||||
Short resourceHasOneShort
|
||||
|
||||
Long resourceHasOneLong
|
||||
|
||||
Product resourceHasOneProduct
|
||||
|
||||
User resourceBelongsToUser
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
@@ -164,6 +200,7 @@ func (r *resource) updateTableName(table string) *resource {
|
||||
r.ResourceNo = field.NewString(table, "resource_no")
|
||||
r.Active = field.NewBool(table, "active")
|
||||
r.Type = field.NewInt(table, "type")
|
||||
r.Code = field.NewString(table, "code")
|
||||
|
||||
r.fillFieldMap()
|
||||
|
||||
@@ -180,7 +217,7 @@ func (r *resource) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
}
|
||||
|
||||
func (r *resource) fillFieldMap() {
|
||||
r.fieldMap = make(map[string]field.Expr, 11)
|
||||
r.fieldMap = make(map[string]field.Expr, 13)
|
||||
r.fieldMap["id"] = r.ID
|
||||
r.fieldMap["created_at"] = r.CreatedAt
|
||||
r.fieldMap["updated_at"] = r.UpdatedAt
|
||||
@@ -189,6 +226,7 @@ func (r *resource) fillFieldMap() {
|
||||
r.fieldMap["resource_no"] = r.ResourceNo
|
||||
r.fieldMap["active"] = r.Active
|
||||
r.fieldMap["type"] = r.Type
|
||||
r.fieldMap["code"] = r.Code
|
||||
|
||||
}
|
||||
|
||||
@@ -198,6 +236,8 @@ func (r resource) clone(db *gorm.DB) resource {
|
||||
r.Short.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
r.Long.db = db.Session(&gorm.Session{Initialized: true})
|
||||
r.Long.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
r.Product.db = db.Session(&gorm.Session{Initialized: true})
|
||||
r.Product.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
r.User.db = db.Session(&gorm.Session{Initialized: true})
|
||||
r.User.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
return r
|
||||
@@ -207,6 +247,7 @@ func (r resource) replaceDB(db *gorm.DB) resource {
|
||||
r.resourceDo.ReplaceDB(db)
|
||||
r.Short.db = db.Session(&gorm.Session{})
|
||||
r.Long.db = db.Session(&gorm.Session{})
|
||||
r.Product.db = db.Session(&gorm.Session{})
|
||||
r.User.db = db.Session(&gorm.Session{})
|
||||
return r
|
||||
}
|
||||
@@ -215,6 +256,16 @@ type resourceHasOneShort struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (a resourceHasOneShort) Where(conds ...field.Expr) *resourceHasOneShort {
|
||||
@@ -296,6 +347,10 @@ type resourceHasOneLong struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
|
||||
Sku struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
|
||||
func (a resourceHasOneLong) Where(conds ...field.Expr) *resourceHasOneLong {
|
||||
@@ -373,6 +428,87 @@ func (a resourceHasOneLongTx) Unscoped() *resourceHasOneLongTx {
|
||||
return &a
|
||||
}
|
||||
|
||||
type resourceHasOneProduct struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a resourceHasOneProduct) Where(conds ...field.Expr) *resourceHasOneProduct {
|
||||
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 resourceHasOneProduct) WithContext(ctx context.Context) *resourceHasOneProduct {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a resourceHasOneProduct) Session(session *gorm.Session) *resourceHasOneProduct {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a resourceHasOneProduct) Model(m *models.Resource) *resourceHasOneProductTx {
|
||||
return &resourceHasOneProductTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a resourceHasOneProduct) Unscoped() *resourceHasOneProduct {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type resourceHasOneProductTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a resourceHasOneProductTx) Find() (result *models.Product, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a resourceHasOneProductTx) Append(values ...*models.Product) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a resourceHasOneProductTx) Replace(values ...*models.Product) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a resourceHasOneProductTx) Delete(values ...*models.Product) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a resourceHasOneProductTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a resourceHasOneProductTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a resourceHasOneProductTx) Unscoped() *resourceHasOneProductTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type resourceBelongsToUser struct {
|
||||
db *gorm.DB
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -29,6 +29,7 @@ func newResourceShort(db *gorm.DB, opts ...gen.DOOption) resourceShort {
|
||||
_resourceShort.ALL = field.NewAsterisk(tableName)
|
||||
_resourceShort.ID = field.NewInt32(tableName, "id")
|
||||
_resourceShort.ResourceID = field.NewInt32(tableName, "resource_id")
|
||||
_resourceShort.Code = field.NewString(tableName, "code")
|
||||
_resourceShort.Live = field.NewInt32(tableName, "live")
|
||||
_resourceShort.Type = field.NewInt(tableName, "type")
|
||||
_resourceShort.Quota = field.NewInt32(tableName, "quota")
|
||||
@@ -36,6 +37,21 @@ func newResourceShort(db *gorm.DB, opts ...gen.DOOption) resourceShort {
|
||||
_resourceShort.Used = field.NewInt32(tableName, "used")
|
||||
_resourceShort.Daily = field.NewInt32(tableName, "daily")
|
||||
_resourceShort.LastAt = field.NewTime(tableName, "last_at")
|
||||
_resourceShort.Sku = resourceShortHasOneSku{
|
||||
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"),
|
||||
},
|
||||
}
|
||||
|
||||
_resourceShort.fillFieldMap()
|
||||
|
||||
@@ -48,6 +64,7 @@ type resourceShort 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 resourceShort struct {
|
||||
Used field.Int32
|
||||
Daily field.Int32
|
||||
LastAt field.Time
|
||||
Sku resourceShortHasOneSku
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
@@ -73,6 +91,7 @@ func (r *resourceShort) updateTableName(table string) *resourceShort {
|
||||
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 *resourceShort) GetFieldByName(fieldName string) (field.OrderExpr, bool)
|
||||
}
|
||||
|
||||
func (r *resourceShort) 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 *resourceShort) fillFieldMap() {
|
||||
r.fieldMap["used"] = r.Used
|
||||
r.fieldMap["daily"] = r.Daily
|
||||
r.fieldMap["last_at"] = r.LastAt
|
||||
|
||||
}
|
||||
|
||||
func (r resourceShort) clone(db *gorm.DB) resourceShort {
|
||||
r.resourceShortDo.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 resourceShort) replaceDB(db *gorm.DB) resourceShort {
|
||||
r.resourceShortDo.ReplaceDB(db)
|
||||
r.Sku.db = db.Session(&gorm.Session{})
|
||||
return r
|
||||
}
|
||||
|
||||
type resourceShortHasOneSku struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
|
||||
Product struct {
|
||||
field.RelationField
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
|
||||
func (a resourceShortHasOneSku) Where(conds ...field.Expr) *resourceShortHasOneSku {
|
||||
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 resourceShortHasOneSku) WithContext(ctx context.Context) *resourceShortHasOneSku {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a resourceShortHasOneSku) Session(session *gorm.Session) *resourceShortHasOneSku {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a resourceShortHasOneSku) Model(m *models.ResourceShort) *resourceShortHasOneSkuTx {
|
||||
return &resourceShortHasOneSkuTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a resourceShortHasOneSku) Unscoped() *resourceShortHasOneSku {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type resourceShortHasOneSkuTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a resourceShortHasOneSkuTx) Find() (result *models.ProductSku, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a resourceShortHasOneSkuTx) 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 resourceShortHasOneSkuTx) 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 resourceShortHasOneSkuTx) 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 resourceShortHasOneSkuTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a resourceShortHasOneSkuTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a resourceShortHasOneSkuTx) Unscoped() *resourceShortHasOneSkuTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type resourceShortDo struct{ gen.DO }
|
||||
|
||||
func (r resourceShortDo) Debug() *resourceShortDo {
|
||||
|
||||
Reference in New Issue
Block a user