优化交易创建流程,客户管理新增折扣与来源字段及功能
This commit is contained in:
@@ -97,6 +97,11 @@ func newBill(db *gorm.DB, opts ...gen.DOOption) bill {
|
||||
},
|
||||
},
|
||||
},
|
||||
Discount: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("User.Discount", "models.ProductDiscount"),
|
||||
},
|
||||
Roles: struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
@@ -329,6 +334,9 @@ type billBelongsToUser struct {
|
||||
}
|
||||
}
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
Roles struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
|
||||
@@ -103,6 +103,11 @@ func newChannel(db *gorm.DB, opts ...gen.DOOption) channel {
|
||||
},
|
||||
},
|
||||
},
|
||||
Discount: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("User.Discount", "models.ProductDiscount"),
|
||||
},
|
||||
Roles: struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
@@ -385,6 +390,9 @@ type channelBelongsToUser struct {
|
||||
}
|
||||
}
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
Roles struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
|
||||
@@ -91,6 +91,11 @@ func newLogsLogin(db *gorm.DB, opts ...gen.DOOption) logsLogin {
|
||||
},
|
||||
},
|
||||
},
|
||||
Discount: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("User.Discount", "models.ProductDiscount"),
|
||||
},
|
||||
Roles: struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
@@ -209,6 +214,9 @@ type logsLoginBelongsToUser struct {
|
||||
}
|
||||
}
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
Roles struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
|
||||
@@ -93,6 +93,11 @@ func newLogsRequest(db *gorm.DB, opts ...gen.DOOption) logsRequest {
|
||||
},
|
||||
},
|
||||
},
|
||||
Discount: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("User.Discount", "models.ProductDiscount"),
|
||||
},
|
||||
Roles: struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
@@ -310,6 +315,9 @@ type logsRequestBelongsToUser struct {
|
||||
}
|
||||
}
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
Roles struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
|
||||
@@ -93,6 +93,11 @@ func newLogsUserUsage(db *gorm.DB, opts ...gen.DOOption) logsUserUsage {
|
||||
},
|
||||
},
|
||||
},
|
||||
Discount: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("User.Discount", "models.ProductDiscount"),
|
||||
},
|
||||
Roles: struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
@@ -286,6 +291,9 @@ type logsUserUsageBelongsToUser struct {
|
||||
}
|
||||
}
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
Roles struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
|
||||
@@ -89,6 +89,11 @@ func newProductSkuUser(db *gorm.DB, opts ...gen.DOOption) productSkuUser {
|
||||
},
|
||||
},
|
||||
},
|
||||
Discount: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("User.Discount", "models.ProductDiscount"),
|
||||
},
|
||||
Roles: struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
@@ -233,6 +238,9 @@ type productSkuUserBelongsToUser struct {
|
||||
}
|
||||
}
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
Roles struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
|
||||
@@ -60,6 +60,9 @@ func newProxy(db *gorm.DB, opts ...gen.DOOption) proxy {
|
||||
}
|
||||
}
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
Roles struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
@@ -120,6 +123,11 @@ func newProxy(db *gorm.DB, opts ...gen.DOOption) proxy {
|
||||
},
|
||||
},
|
||||
},
|
||||
Discount: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Channels.User.Discount", "models.ProductDiscount"),
|
||||
},
|
||||
Roles: struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
@@ -358,6 +366,9 @@ type proxyHasManyChannels struct {
|
||||
}
|
||||
}
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
Roles struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
|
||||
@@ -136,6 +136,11 @@ func newResource(db *gorm.DB, opts ...gen.DOOption) resource {
|
||||
},
|
||||
},
|
||||
},
|
||||
Discount: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("User.Discount", "models.ProductDiscount"),
|
||||
},
|
||||
Roles: struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
@@ -529,6 +534,9 @@ type resourceBelongsToUser struct {
|
||||
}
|
||||
}
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
Roles struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
|
||||
@@ -97,6 +97,11 @@ func newSession(db *gorm.DB, opts ...gen.DOOption) session {
|
||||
},
|
||||
},
|
||||
},
|
||||
Discount: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("User.Discount", "models.ProductDiscount"),
|
||||
},
|
||||
Roles: struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
@@ -260,6 +265,9 @@ type sessionBelongsToUser struct {
|
||||
}
|
||||
}
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
Roles struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
|
||||
@@ -103,6 +103,11 @@ func newTrade(db *gorm.DB, opts ...gen.DOOption) trade {
|
||||
},
|
||||
},
|
||||
},
|
||||
Discount: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("User.Discount", "models.ProductDiscount"),
|
||||
},
|
||||
Roles: struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
@@ -257,6 +262,9 @@ type tradeBelongsToUser struct {
|
||||
}
|
||||
}
|
||||
}
|
||||
Discount struct {
|
||||
field.RelationField
|
||||
}
|
||||
Roles struct {
|
||||
field.RelationField
|
||||
Permissions struct {
|
||||
|
||||
@@ -32,10 +32,12 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) user {
|
||||
_user.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_user.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_user.AdminID = field.NewInt32(tableName, "admin_id")
|
||||
_user.DiscountID = field.NewInt32(tableName, "discount_id")
|
||||
_user.Phone = field.NewString(tableName, "phone")
|
||||
_user.Username = field.NewString(tableName, "username")
|
||||
_user.Email = field.NewString(tableName, "email")
|
||||
_user.Password = field.NewString(tableName, "password")
|
||||
_user.Source = field.NewInt(tableName, "source")
|
||||
_user.Name = field.NewString(tableName, "name")
|
||||
_user.Avatar = field.NewString(tableName, "avatar")
|
||||
_user.Status = field.NewInt(tableName, "status")
|
||||
@@ -89,6 +91,12 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) user {
|
||||
},
|
||||
}
|
||||
|
||||
_user.Discount = userBelongsToDiscount{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Discount", "models.ProductDiscount"),
|
||||
}
|
||||
|
||||
_user.Roles = userManyToManyRoles{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
@@ -114,10 +122,12 @@ type user struct {
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
AdminID field.Int32
|
||||
DiscountID field.Int32
|
||||
Phone field.String
|
||||
Username field.String
|
||||
Email field.String
|
||||
Password field.String
|
||||
Source field.Int
|
||||
Name field.String
|
||||
Avatar field.String
|
||||
Status field.Int
|
||||
@@ -132,6 +142,8 @@ type user struct {
|
||||
LastLoginUA field.String
|
||||
Admin userBelongsToAdmin
|
||||
|
||||
Discount userBelongsToDiscount
|
||||
|
||||
Roles userManyToManyRoles
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
@@ -154,10 +166,12 @@ func (u *user) updateTableName(table string) *user {
|
||||
u.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
u.DeletedAt = field.NewField(table, "deleted_at")
|
||||
u.AdminID = field.NewInt32(table, "admin_id")
|
||||
u.DiscountID = field.NewInt32(table, "discount_id")
|
||||
u.Phone = field.NewString(table, "phone")
|
||||
u.Username = field.NewString(table, "username")
|
||||
u.Email = field.NewString(table, "email")
|
||||
u.Password = field.NewString(table, "password")
|
||||
u.Source = field.NewInt(table, "source")
|
||||
u.Name = field.NewString(table, "name")
|
||||
u.Avatar = field.NewString(table, "avatar")
|
||||
u.Status = field.NewInt(table, "status")
|
||||
@@ -186,16 +200,18 @@ func (u *user) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
}
|
||||
|
||||
func (u *user) fillFieldMap() {
|
||||
u.fieldMap = make(map[string]field.Expr, 23)
|
||||
u.fieldMap = make(map[string]field.Expr, 26)
|
||||
u.fieldMap["id"] = u.ID
|
||||
u.fieldMap["created_at"] = u.CreatedAt
|
||||
u.fieldMap["updated_at"] = u.UpdatedAt
|
||||
u.fieldMap["deleted_at"] = u.DeletedAt
|
||||
u.fieldMap["admin_id"] = u.AdminID
|
||||
u.fieldMap["discount_id"] = u.DiscountID
|
||||
u.fieldMap["phone"] = u.Phone
|
||||
u.fieldMap["username"] = u.Username
|
||||
u.fieldMap["email"] = u.Email
|
||||
u.fieldMap["password"] = u.Password
|
||||
u.fieldMap["source"] = u.Source
|
||||
u.fieldMap["name"] = u.Name
|
||||
u.fieldMap["avatar"] = u.Avatar
|
||||
u.fieldMap["status"] = u.Status
|
||||
@@ -215,6 +231,8 @@ func (u user) clone(db *gorm.DB) user {
|
||||
u.userDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
u.Admin.db = db.Session(&gorm.Session{Initialized: true})
|
||||
u.Admin.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
u.Discount.db = db.Session(&gorm.Session{Initialized: true})
|
||||
u.Discount.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
u.Roles.db = db.Session(&gorm.Session{Initialized: true})
|
||||
u.Roles.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
return u
|
||||
@@ -223,6 +241,7 @@ func (u user) clone(db *gorm.DB) user {
|
||||
func (u user) replaceDB(db *gorm.DB) user {
|
||||
u.userDo.ReplaceDB(db)
|
||||
u.Admin.db = db.Session(&gorm.Session{})
|
||||
u.Discount.db = db.Session(&gorm.Session{})
|
||||
u.Roles.db = db.Session(&gorm.Session{})
|
||||
return u
|
||||
}
|
||||
@@ -321,6 +340,87 @@ func (a userBelongsToAdminTx) Unscoped() *userBelongsToAdminTx {
|
||||
return &a
|
||||
}
|
||||
|
||||
type userBelongsToDiscount struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a userBelongsToDiscount) Where(conds ...field.Expr) *userBelongsToDiscount {
|
||||
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 userBelongsToDiscount) WithContext(ctx context.Context) *userBelongsToDiscount {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a userBelongsToDiscount) Session(session *gorm.Session) *userBelongsToDiscount {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a userBelongsToDiscount) Model(m *models.User) *userBelongsToDiscountTx {
|
||||
return &userBelongsToDiscountTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a userBelongsToDiscount) Unscoped() *userBelongsToDiscount {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type userBelongsToDiscountTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a userBelongsToDiscountTx) Find() (result *models.ProductDiscount, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a userBelongsToDiscountTx) 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 userBelongsToDiscountTx) 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 userBelongsToDiscountTx) 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 userBelongsToDiscountTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a userBelongsToDiscountTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a userBelongsToDiscountTx) Unscoped() *userBelongsToDiscountTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type userManyToManyRoles struct {
|
||||
db *gorm.DB
|
||||
|
||||
|
||||
Reference in New Issue
Block a user