order

package
v1.20.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const TempOrderCacheKey = "temp_order:%s"

TempOrderCacheKey Cache to Redis Key eg: temp_order:order_no

Variables

This section is empty.

Functions

func CheckoutTokenHash added in v1.20.3

func CheckoutTokenHash(token string) string

CheckoutTokenHash returns the durable representation of the guest checkout capability. Only the caller receives the original high-entropy token.

func EventChannel added in v1.20.3

func EventChannel(orderNo string) string

EventChannel returns the Redis Pub/Sub channel for one order's durable event stream. The channel is only a wake-up path; consumers still read events from the database by id.

func GenerateTradeNo added in v1.20.2

func GenerateTradeNo() string

GenerateTradeNo returns a fixed-width numeric trade number: a 14-digit timestamp plus 8 digits from crypto/rand. Seeding from the clock alone produced identical numbers for concurrent requests within the same nanosecond; the database's unique trade-no index turns those collisions into visible purchase failures. crypto/rand cannot fail in practice; the panic matches how the password salt handles the same error.

Types

type DailyBreakdown added in v1.15.16

type DailyBreakdown struct {
	// Name is the plan name or the payment platform, depending on the group.
	Name string
	// Id is the grouped plan id; zero for a payment-method group and for
	// orders that carry no plan, such as balance top-ups.
	Id     int64
	Orders int64
	Amount int64
}

DailyBreakdown is one row of a settled-order breakdown, grouped by plan or by payment method for the daily report.

type DailyReport added in v1.15.16

type DailyReport struct {
	Date     time.Time
	Orders   int64
	Amount   int64
	ByPlan   []DailyBreakdown
	ByMethod []DailyBreakdown
}

DailyReport totals the orders settled on one day, alongside the plan and payment-method breakdowns.

type Details

type Details struct {
	Id              int64                `gorm:"primaryKey"`
	ParentId        int64                `gorm:"type:bigint;default:null;comment:Parent Order Id"`
	SubOrders       []*Order             `gorm:"foreignKey:ParentId;references:Id"`
	UserId          int64                `gorm:"type:bigint;not null;default:0;comment:User Id"`
	OrderNo         string               `gorm:"type:varchar(255);not null;default:'';unique;comment:Order No"`
	Type            uint8                `gorm:"type:tinyint(1);not null;default:1;comment:Order Type: 1: Subscribe, 2: Renewal, 3: ResetTraffic, 4: Recharge"`
	Quantity        int64                `gorm:"type:bigint;not null;default:1;comment:Quantity"`
	Price           int64                `gorm:"type:int;not null;default:0;comment:Original price"`
	Amount          int64                `gorm:"type:int;not null;default:0;comment:Order Amount"`
	Discount        int64                `gorm:"type:int;not null;default:0;comment:Order Discount"`
	Coupon          string               `gorm:"type:varchar(255);default:null;comment:Coupon"`
	CouponDiscount  int64                `gorm:"type:int;not null;default:0;comment:Coupon Discount"`
	PaymentId       int64                `gorm:"type:bigint;not null;default:0;comment:Payment Id"`
	Payment         *payment.Payment     `gorm:"foreignKey:PaymentId;references:Id"`
	Method          string               `gorm:"type:varchar(255);not null;default:'';comment:Payment Method"`
	FeeAmount       int64                `gorm:"type:int;not null;default:0;comment:Fee Amount"`
	PaymentAmount   int64                `gorm:"type:bigint;not null;default:0;comment:Amount requested by payment gateway in minor units"`
	PaymentCurrency string               `gorm:"type:varchar(16);not null;default:'';comment:Payment gateway currency"`
	TradeNo         string               `gorm:"type:varchar(255);default:null;comment:Trade No"`
	GiftAmount      int64                `gorm:"type:int;not null;default:0;comment:User Gift Amount"`
	Commission      int64                `gorm:"type:int;not null;default:0;comment:Order Commission"`
	Status          uint8                `gorm:"type:tinyint(1);not null;default:1;comment:Order Status: 1: Pending, 2: Paid, 3: Failed"`
	SubscribeId     int64                `gorm:"type:bigint;not null;default:0;comment:Subscribe Id"`
	SubscribeToken  string               `gorm:"type:varchar(255);default:null;comment:Renewal Subscribe Token"`
	Subscribe       *subscribe.Subscribe `gorm:"foreignKey:SubscribeId;references:Id"`
	IsNew           bool                 `gorm:"type:tinyint(1);not null;default:0;comment:Is New Order"`
	CreatedAt       time.Time            `gorm:"<-:create;comment:Create Time"`
	UpdatedAt       time.Time            `gorm:"comment:Update Time"`
}

type Event

type Event struct {
	ID          int64      `gorm:"primaryKey;autoIncrement"`
	OrderID     int64      `gorm:"type:bigint;not null;index:idx_order_event_order_id_id,priority:1"`
	OrderNo     string     `gorm:"type:varchar(255);not null;index:idx_order_event_order_no_id,priority:1"`
	EventType   string     `gorm:"type:varchar(64);not null"`
	Payload     string     `gorm:"type:text;not null"`
	CreatedAt   time.Time  `gorm:"<-:create"`
	PublishedAt *time.Time `gorm:"index:idx_order_event_published_at_id,priority:1"`
}

Event is the durable order event outbox. Redis only distributes these records with low latency; reconnecting clients always recover from this table.

func (Event) TableName

func (Event) TableName() string

type Order

type Order struct {
	Id                     int64     `gorm:"primaryKey"`
	ParentId               int64     `gorm:"type:bigint;default:null;comment:Parent Order Id"`
	UserId                 int64     `gorm:"type:bigint;not null;default:0;comment:User Id"`
	OrderNo                string    `gorm:"type:varchar(255);not null;default:'';unique;comment:Order No"`
	Type                   uint8     `gorm:"type:tinyint(1);not null;default:1;comment:Order Type: 1: Subscribe, 2: Renewal, 3: ResetTraffic, 4: Recharge"`
	Quantity               int64     `gorm:"type:bigint;not null;default:1;comment:Quantity"`
	Price                  int64     `gorm:"type:int;not null;default:0;comment:Original price"`
	Amount                 int64     `gorm:"type:int;not null;default:0;comment:Order Amount"`
	GiftAmount             int64     `gorm:"type:int;not null;default:0;comment:User Gift Amount"`
	Discount               int64     `gorm:"type:int;not null;default:0;comment:Discount Amount"`
	Coupon                 string    `gorm:"type:varchar(255);default:null;comment:Coupon"`
	CouponDiscount         int64     `gorm:"type:int;not null;default:0;comment:Coupon Discount Amount"`
	CouponReserved         bool      `gorm:"type:tinyint(1);not null;default:0;comment:Coupon usage reserved while order is pending"`
	Commission             int64     `gorm:"type:int;not null;default:0;comment:Order Commission"`
	PaymentId              int64     `gorm:"type:bigint;not null;default:0;comment:Payment Method Id"`
	Method                 string    `gorm:"type:varchar(255);not null;default:'';comment:Payment Method"`
	FeeAmount              int64     `gorm:"type:int;not null;default:0;comment:Fee Amount"`
	PaymentAmount          int64     `gorm:"type:bigint;not null;default:0;comment:Amount requested by payment gateway in minor units"`
	PaymentCurrency        string    `gorm:"type:varchar(16);not null;default:'';comment:Payment gateway currency"`
	TradeNo                string    `gorm:"type:varchar(255);default:null;comment:Trade No"`
	Status                 uint8     `gorm:"type:tinyint(1);not null;default:1;comment:Order Status: 1: Pending, 2: Paid, 3:Close, 4: Failed, 5:Finished;"`
	SubscribeId            int64     `gorm:"type:bigint;not null;default:0;comment:Subscribe Id"`
	SubscribeToken         string    `gorm:"type:varchar(255);default:null;comment:Renewal Subscribe Token"`
	GuestAuthType          string    `gorm:"type:varchar(255);not null;default:'';comment:Guest auth type before account activation"`
	GuestIdentifier        string    `gorm:"type:varchar(255);not null;default:'';comment:Guest auth identifier before account activation"`
	GuestPasswordHash      string    `gorm:"type:varchar(255);not null;default:'';comment:Guest password hash before account activation"`
	GuestInviteCode        string    `gorm:"type:varchar(255);not null;default:'';comment:Guest invite code before account activation"`
	GuestCheckoutTokenHash string    `gorm:"type:char(64);not null;default:'';comment:Hash of guest checkout capability"`
	StateVersion           int64     `gorm:"type:bigint;not null;default:0;comment:Monotonic version for order state transitions"`
	IdempotencyKey         string    `gorm:"type:varchar(128);uniqueIndex;default:null;comment:V2 create idempotency key"`
	IdempotencyHash        string    `gorm:"type:char(64);default:null;comment:Stable hash of the V2 create request"`
	IsNew                  bool      `gorm:"type:tinyint(1);not null;default:0;comment:Is New Order"`
	CreatedAt              time.Time `gorm:"<-:create;comment:Create Time"`
	UpdatedAt              time.Time `gorm:"comment:Update Time"`
}

func (Order) TableName

func (Order) TableName() string

type OrdersTotal

type OrdersTotal struct {
	AmountTotal        int64
	NewOrderAmount     int64
	RenewalOrderAmount int64
}

type OrdersTotalWithDate

type OrdersTotalWithDate struct {
	Date               string
	AmountTotal        int64
	NewOrderAmount     int64
	RenewalOrderAmount int64
}

type TemporaryOrderInfo added in v1.20.3

type TemporaryOrderInfo struct {
	OrderNo       string `json:"order_no"`
	CheckoutToken string `json:"checkout_token"`
	Identifier    string `json:"identifier"`
	AuthType      string `json:"auth_type"`
	// PasswordHash is the one-way encoded password needed to finish a guest
	// account after payment.  Never place the plaintext password in Redis.
	PasswordHash string `json:"password_hash,omitempty"`
	// Password is retained only to finish orders created by older releases.
	// New orders never populate it and it must never be logged.
	Password   string `json:"password,omitempty"`
	InviteCode string `json:"invite_code,omitempty"`
}

func (*TemporaryOrderInfo) Marshal added in v1.20.3

func (t *TemporaryOrderInfo) Marshal() ([]byte, error)

func (*TemporaryOrderInfo) Unmarshal added in v1.20.3

func (t *TemporaryOrderInfo) Unmarshal(data []byte) error

type UserCounts

type UserCounts struct {
	NewUsers     int64 `gorm:"column:new_users"`
	RenewalUsers int64 `gorm:"column:renewal_users"`
}

UserCounts User counts for new and renewal users

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL