重构优惠券表结构与功能
This commit is contained in:
@@ -35,7 +35,7 @@ func newBill(db *gorm.DB, opts ...gen.DOOption) bill {
|
||||
_bill.TradeID = field.NewInt32(tableName, "trade_id")
|
||||
_bill.ResourceID = field.NewInt32(tableName, "resource_id")
|
||||
_bill.RefundID = field.NewInt32(tableName, "refund_id")
|
||||
_bill.CouponID = field.NewInt32(tableName, "coupon_id")
|
||||
_bill.CouponUserID = field.NewInt32(tableName, "coupon_id")
|
||||
_bill.BillNo = field.NewString(tableName, "bill_no")
|
||||
_bill.Info = field.NewString(tableName, "info")
|
||||
_bill.Type = field.NewInt(tableName, "type")
|
||||
@@ -198,6 +198,22 @@ func newBill(db *gorm.DB, opts ...gen.DOOption) bill {
|
||||
RelationField: field.NewRelation("Refund", "models.Refund"),
|
||||
}
|
||||
|
||||
_bill.CouponUser = billBelongsToCouponUser{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("CouponUser", "models.CouponUser"),
|
||||
Coupon: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("CouponUser.Coupon", "models.Coupon"),
|
||||
},
|
||||
User: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("CouponUser.User", "models.User"),
|
||||
},
|
||||
}
|
||||
|
||||
_bill.fillFieldMap()
|
||||
|
||||
return _bill
|
||||
@@ -206,22 +222,22 @@ func newBill(db *gorm.DB, opts ...gen.DOOption) bill {
|
||||
type bill struct {
|
||||
billDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int32
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
UserID field.Int32
|
||||
TradeID field.Int32
|
||||
ResourceID field.Int32
|
||||
RefundID field.Int32
|
||||
CouponID field.Int32
|
||||
BillNo field.String
|
||||
Info field.String
|
||||
Type field.Int
|
||||
Amount field.Field
|
||||
Actual field.Field
|
||||
User billBelongsToUser
|
||||
ALL field.Asterisk
|
||||
ID field.Int32
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
UserID field.Int32
|
||||
TradeID field.Int32
|
||||
ResourceID field.Int32
|
||||
RefundID field.Int32
|
||||
CouponUserID field.Int32
|
||||
BillNo field.String
|
||||
Info field.String
|
||||
Type field.Int
|
||||
Amount field.Field
|
||||
Actual field.Field
|
||||
User billBelongsToUser
|
||||
|
||||
Trade billBelongsToTrade
|
||||
|
||||
@@ -229,6 +245,8 @@ type bill struct {
|
||||
|
||||
Refund billBelongsToRefund
|
||||
|
||||
CouponUser billBelongsToCouponUser
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
@@ -252,7 +270,7 @@ func (b *bill) updateTableName(table string) *bill {
|
||||
b.TradeID = field.NewInt32(table, "trade_id")
|
||||
b.ResourceID = field.NewInt32(table, "resource_id")
|
||||
b.RefundID = field.NewInt32(table, "refund_id")
|
||||
b.CouponID = field.NewInt32(table, "coupon_id")
|
||||
b.CouponUserID = field.NewInt32(table, "coupon_id")
|
||||
b.BillNo = field.NewString(table, "bill_no")
|
||||
b.Info = field.NewString(table, "info")
|
||||
b.Type = field.NewInt(table, "type")
|
||||
@@ -274,7 +292,7 @@ func (b *bill) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
}
|
||||
|
||||
func (b *bill) fillFieldMap() {
|
||||
b.fieldMap = make(map[string]field.Expr, 18)
|
||||
b.fieldMap = make(map[string]field.Expr, 19)
|
||||
b.fieldMap["id"] = b.ID
|
||||
b.fieldMap["created_at"] = b.CreatedAt
|
||||
b.fieldMap["updated_at"] = b.UpdatedAt
|
||||
@@ -283,7 +301,7 @@ func (b *bill) fillFieldMap() {
|
||||
b.fieldMap["trade_id"] = b.TradeID
|
||||
b.fieldMap["resource_id"] = b.ResourceID
|
||||
b.fieldMap["refund_id"] = b.RefundID
|
||||
b.fieldMap["coupon_id"] = b.CouponID
|
||||
b.fieldMap["coupon_id"] = b.CouponUserID
|
||||
b.fieldMap["bill_no"] = b.BillNo
|
||||
b.fieldMap["info"] = b.Info
|
||||
b.fieldMap["type"] = b.Type
|
||||
@@ -302,6 +320,8 @@ func (b bill) clone(db *gorm.DB) bill {
|
||||
b.Resource.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
b.Refund.db = db.Session(&gorm.Session{Initialized: true})
|
||||
b.Refund.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
b.CouponUser.db = db.Session(&gorm.Session{Initialized: true})
|
||||
b.CouponUser.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
return b
|
||||
}
|
||||
|
||||
@@ -311,6 +331,7 @@ func (b bill) replaceDB(db *gorm.DB) bill {
|
||||
b.Trade.db = db.Session(&gorm.Session{})
|
||||
b.Resource.db = db.Session(&gorm.Session{})
|
||||
b.Refund.db = db.Session(&gorm.Session{})
|
||||
b.CouponUser.db = db.Session(&gorm.Session{})
|
||||
return b
|
||||
}
|
||||
|
||||
@@ -692,6 +713,94 @@ func (a billBelongsToRefundTx) Unscoped() *billBelongsToRefundTx {
|
||||
return &a
|
||||
}
|
||||
|
||||
type billBelongsToCouponUser struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
|
||||
Coupon struct {
|
||||
field.RelationField
|
||||
}
|
||||
User struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
|
||||
func (a billBelongsToCouponUser) Where(conds ...field.Expr) *billBelongsToCouponUser {
|
||||
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 billBelongsToCouponUser) WithContext(ctx context.Context) *billBelongsToCouponUser {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a billBelongsToCouponUser) Session(session *gorm.Session) *billBelongsToCouponUser {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a billBelongsToCouponUser) Model(m *models.Bill) *billBelongsToCouponUserTx {
|
||||
return &billBelongsToCouponUserTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a billBelongsToCouponUser) Unscoped() *billBelongsToCouponUser {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type billBelongsToCouponUserTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a billBelongsToCouponUserTx) Find() (result *models.CouponUser, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a billBelongsToCouponUserTx) Append(values ...*models.CouponUser) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a billBelongsToCouponUserTx) Replace(values ...*models.CouponUser) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a billBelongsToCouponUserTx) Delete(values ...*models.CouponUser) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a billBelongsToCouponUserTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a billBelongsToCouponUserTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a billBelongsToCouponUserTx) Unscoped() *billBelongsToCouponUserTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type billDo struct{ gen.DO }
|
||||
|
||||
func (b billDo) Debug() *billDo {
|
||||
|
||||
Reference in New Issue
Block a user