feat: add coupon support to orders and create user_coupons model
- Added CouponID field to Order model to track used coupons. - Updated order query generation to include CouponID. - Introduced UserCoupon model to manage user coupon associations. - Implemented query methods for UserCoupon to facilitate CRUD operations. - Updated query context and default query setup to include UserCoupon.
This commit is contained in:
@@ -43,6 +43,7 @@ func newOrder(db *gorm.DB, opts ...gen.DOOption) orderQuery {
|
||||
_orderQuery.RefundReason = field.NewString(tableName, "refund_reason")
|
||||
_orderQuery.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_orderQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_orderQuery.CouponID = field.NewInt64(tableName, "coupon_id")
|
||||
|
||||
_orderQuery.fillFieldMap()
|
||||
|
||||
@@ -71,6 +72,7 @@ type orderQuery struct {
|
||||
RefundReason field.String
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
CouponID field.Int64 // 使用的优惠券ID (0表示未使用)
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
@@ -105,6 +107,7 @@ func (o *orderQuery) updateTableName(table string) *orderQuery {
|
||||
o.RefundReason = field.NewString(table, "refund_reason")
|
||||
o.CreatedAt = field.NewTime(table, "created_at")
|
||||
o.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
o.CouponID = field.NewInt64(table, "coupon_id")
|
||||
|
||||
o.fillFieldMap()
|
||||
|
||||
@@ -135,7 +138,7 @@ func (o *orderQuery) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
}
|
||||
|
||||
func (o *orderQuery) fillFieldMap() {
|
||||
o.fieldMap = make(map[string]field.Expr, 18)
|
||||
o.fieldMap = make(map[string]field.Expr, 19)
|
||||
o.fieldMap["id"] = o.ID
|
||||
o.fieldMap["tenant_id"] = o.TenantID
|
||||
o.fieldMap["user_id"] = o.UserID
|
||||
@@ -154,6 +157,7 @@ func (o *orderQuery) fillFieldMap() {
|
||||
o.fieldMap["refund_reason"] = o.RefundReason
|
||||
o.fieldMap["created_at"] = o.CreatedAt
|
||||
o.fieldMap["updated_at"] = o.UpdatedAt
|
||||
o.fieldMap["coupon_id"] = o.CouponID
|
||||
}
|
||||
|
||||
func (o orderQuery) clone(db *gorm.DB) orderQuery {
|
||||
|
||||
Reference in New Issue
Block a user