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:
64
backend/database/models/coupons.gen.go
Normal file
64
backend/database/models/coupons.gen.go
Normal file
@@ -0,0 +1,64 @@
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"go.ipao.vip/gen"
|
||||
)
|
||||
|
||||
const TableNameCoupon = "coupons"
|
||||
|
||||
// Coupon mapped from table <coupons>
|
||||
type Coupon struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
|
||||
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null" json:"tenant_id"`
|
||||
Title string `gorm:"column:title;type:character varying(255);not null" json:"title"`
|
||||
Description string `gorm:"column:description;type:text" json:"description"`
|
||||
Type string `gorm:"column:type;type:character varying(32);not null" json:"type"`
|
||||
Value int64 `gorm:"column:value;type:bigint;not null" json:"value"`
|
||||
MinOrderAmount int64 `gorm:"column:min_order_amount;type:bigint;not null" json:"min_order_amount"`
|
||||
MaxDiscount int64 `gorm:"column:max_discount;type:bigint" json:"max_discount"`
|
||||
TotalQuantity int32 `gorm:"column:total_quantity;type:integer;not null" json:"total_quantity"`
|
||||
UsedQuantity int32 `gorm:"column:used_quantity;type:integer;not null" json:"used_quantity"`
|
||||
StartAt time.Time `gorm:"column:start_at;type:timestamp with time zone" json:"start_at"`
|
||||
EndAt time.Time `gorm:"column:end_at;type:timestamp with time zone" json:"end_at"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now()" json:"updated_at"`
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
// Update applies changed fields to the database using the default DB.
|
||||
func (m *Coupon) Update(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.Coupon.WithContext(ctx).Updates(m)
|
||||
}
|
||||
|
||||
// Save upserts the model using the default DB.
|
||||
func (m *Coupon) Save(ctx context.Context) error { return Q.Coupon.WithContext(ctx).Save(m) }
|
||||
|
||||
// Create inserts the model using the default DB.
|
||||
func (m *Coupon) Create(ctx context.Context) error { return Q.Coupon.WithContext(ctx).Create(m) }
|
||||
|
||||
// Delete removes the row represented by the model using the default DB.
|
||||
func (m *Coupon) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.Coupon.WithContext(ctx).Delete(m)
|
||||
}
|
||||
|
||||
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
||||
func (m *Coupon) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.Coupon.WithContext(ctx).Unscoped().Delete(m)
|
||||
}
|
||||
|
||||
// Reload reloads the model from database by its primary key and overwrites current fields.
|
||||
func (m *Coupon) Reload(ctx context.Context) error {
|
||||
fresh, err := Q.Coupon.WithContext(ctx).GetByID(m.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*m = *fresh
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user