model

package
v1.22.7 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2025 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusEnable       uint8 = 1
	StatusDisable      uint8 = 0
	OtherNotifyEnable  uint8 = 1
	OtherNotifyDisable uint8 = 0
)
View Source
const (
	OrderNotifyStateSucc = 1 // 回调成功
	OrderNotifyStateFail = 0 // 回调失败

	OrderStatusWaiting    = 1 // 等待支付
	OrderStatusSuccess    = 2 // 交易确认成功
	OrderStatusExpired    = 3 // 订单过期
	OrderStatusCanceled   = 4 // 订单取消
	OrderStatusConfirming = 5 // 等待交易确认
	OrderStatusFailed     = 6 // 交易确认失败

	OrderTradeTypeTronTrx      = "tron.trx"
	OrderTradeTypeUsdtTrc20    = "usdt.trc20"
	OrderTradeTypeUsdcTrc20    = "usdc.trc20"
	OrderTradeTypeUsdtPolygon  = "usdt.polygon"
	OrderTradeTypeUsdcPolygon  = "usdc.polygon"
	OrderTradeTypeUsdtArbitrum = "usdt.arbitrum"
	OrderTradeTypeUsdcArbitrum = "usdc.arbitrum"
	OrderTradeTypeUsdtErc20    = "usdt.erc20"
	OrderTradeTypeUsdcErc20    = "usdc.erc20"
	OrderTradeTypeUsdtBep20    = "usdt.bep20"
	OrderTradeTypeUsdcBep20    = "usdc.bep20"
	OrderTradeTypeUsdtXlayer   = "usdt.xlayer"
	OrderTradeTypeUsdcXlayer   = "usdc.xlayer"
	OrderTradeTypeUsdcBase     = "usdc.base"
	OrderTradeTypeUsdtSolana   = "usdt.solana"
	OrderTradeTypeUsdcSolana   = "usdc.solana"
	OrderTradeTypeUsdtAptos    = "usdt.aptos"
	OrderTradeTypeUsdcAptos    = "usdc.aptos"
)
View Source
const (
	OrderApiTypeEpusdt = "epusdt" // epusdt
	OrderApiTypeEpay   = "epay"   // 彩虹易支付
)
View Source
const (
	WebhookStatusWait = 0
	WebhookStatusSucc = 1
	WebhookStatusFail = -1
)
View Source
const (
	WebhookEventOrderCreate  = "order.create"  // 订单创建
	WebhookEventOrderPaid    = "order.paid"    // 订单支付
	WebhookEventOrderTimeout = "order.timeout" // 订单超时
	WebhookEventOrderCancel  = "order.cancel"  // 订单取消
	WebhookEventOrderFailed  = "order.failed"  // 订单失败
)

Variables

View Source
var DB *gorm.DB

SupportTradeTypes 目前支持的收款交易类型

View Source
var WebhookHandleQueue = chanx.NewUnboundedChan[Webhook](context.Background(), 30)

Functions

func AutoMigrate added in v1.9.26

func AutoMigrate() error

func CalcTradeExpiredAt added in v1.22.1

func CalcTradeExpiredAt(sec uint64) time.Time

func GetDetailUrl added in v1.20.4

func GetDetailUrl(tradeType, hash string) string

func GetK added in v1.13.29

func GetK(k string) string

func GetTradeRate added in v1.22.1

func GetTradeRate(token TokenType, param string) (float64, error)

func Init

func Init() error

func IsNeedNotifyByTxid

func IsNeedNotifyByTxid(txid string) bool

func ListWaitWebhooks added in v1.20.6

func ListWaitWebhooks()

func PushWebhookEvent added in v1.20.6

func PushWebhookEvent(event string, data any)

func SetK added in v1.13.29

func SetK(k, v string)

Types

type Config added in v1.13.29

type Config struct {
	K string `gorm:"column:k;type:varchar(32);primaryKey"`
	V string `gorm:"column:v;type:varchar(255)"`
}

func (Config) TableName added in v1.13.29

func (c Config) TableName() string

type NotifyRecord

type NotifyRecord struct {
	Txid      string    `gorm:"primary_key;type:varchar(64);not null;comment:交易哈希"`
	CreatedAt time.Time `gorm:"autoCreateTime;type:timestamp;not null;comment:创建时间"`
	UpdatedAt time.Time `gorm:"autoUpdateTime;type:timestamp;not null;comment:更新时间"`
}

func (*NotifyRecord) TableName

func (nr *NotifyRecord) TableName() string

type TokenType added in v1.22.1

type TokenType string
const (
	TokenTypeUSDT TokenType = "USDT"
	TokenTypeUSDC TokenType = "USDC"
	TokenTypeTRX  TokenType = "TRX"
)

func GetTokenType added in v1.22.1

func GetTokenType(tradeType string) (TokenType, error)

type TradeOrders

type TradeOrders struct {
	Id          int64     `gorm:"primary_key;AUTO_INCREMENT;comment:id"`
	OrderId     string    `gorm:"column:order_id;type:varchar(128);not null;index;comment:商户ID"`
	TradeId     string    `gorm:"column:trade_id;type:varchar(128);not null;uniqueIndex;comment:本地ID"`
	TradeType   string    `gorm:"column:trade_type;type:varchar(20);not null;comment:交易类型"`
	TradeHash   string    `gorm:"column:trade_hash;type:varchar(130);default:'';unique;comment:交易哈希"`
	TradeRate   string    `gorm:"column:trade_rate;type:varchar(10);not null;comment:交易汇率"`
	Amount      string    `gorm:"type:decimal(10,2);not null;default:0;comment:交易数额"`
	Money       float64   `gorm:"type:decimal(10,2);not null;default:0;comment:订单交易金额"`
	Address     string    `gorm:"column:address;type:varchar(64);not null;comment:收款地址"`
	FromAddress string    `gorm:"type:varchar(34);not null;default:'';comment:支付地址"`
	Status      int       `gorm:"type:tinyint(1);not null;default:1;index;comment:交易状态"`
	Name        string    `gorm:"type:varchar(64);not null;default:'';comment:商品名称"`
	ApiType     string    `gorm:"type:varchar(20);not null;default:'epusdt';comment:API类型"`
	ReturnUrl   string    `gorm:"type:varchar(255);not null;default:'';comment:同步地址"`
	NotifyUrl   string    `gorm:"type:varchar(255);not null;default:'';comment:异步地址"`
	NotifyNum   int       `gorm:"column:notify_num;type:int(11);not null;default:0;comment:回调次数"`
	NotifyState int       `gorm:"column:notify_state;type:tinyint(1);not null;default:0;comment:回调状态 1:成功 0:失败"`
	RefBlockNum int64     `gorm:"type:bigint(20);not null;default:0;comment:交易所在区块"`
	ExpiredAt   time.Time `gorm:"column:expired_at;type:timestamp;not null;comment:失效时间"`
	CreatedAt   time.Time `gorm:"autoCreateTime;type:timestamp;not null;comment:创建时间"`
	UpdatedAt   time.Time `gorm:"autoUpdateTime;type:timestamp;not null;comment:更新时间"`
	ConfirmedAt time.Time `gorm:"type:timestamp;null;comment:交易确认时间"`
}

func GetNotifyFailedTradeOrders

func GetNotifyFailedTradeOrders() ([]TradeOrders, error)

func GetOrderByStatus added in v1.19.1

func GetOrderByStatus(Status int) []TradeOrders

func GetTradeOrder

func GetTradeOrder(tradeId string) (TradeOrders, bool)

func (*TradeOrders) GetDetailUrl added in v1.20.4

func (o *TradeOrders) GetDetailUrl() string

func (*TradeOrders) GetStatusEmoji added in v1.17.6

func (o *TradeOrders) GetStatusEmoji() string

func (*TradeOrders) GetStatusLabel added in v1.8.20

func (o *TradeOrders) GetStatusLabel() string

func (*TradeOrders) MarkConfirming added in v1.22.5

func (o *TradeOrders) MarkConfirming(blockNum int64, from, hash string, at time.Time)

func (*TradeOrders) SetCanceled added in v1.22.5

func (o *TradeOrders) SetCanceled() error

func (*TradeOrders) SetExpired added in v1.22.5

func (o *TradeOrders) SetExpired()

func (*TradeOrders) SetFailed added in v1.22.5

func (o *TradeOrders) SetFailed()

func (*TradeOrders) SetNotifyState added in v1.20.6

func (o *TradeOrders) SetNotifyState(state int) error

func (*TradeOrders) SetSuccess added in v1.22.5

func (o *TradeOrders) SetSuccess()

type WalletAddress

type WalletAddress struct {
	ID          int64     `gorm:"integer;primaryKey;not null;comment:id"`
	Status      uint8     `gorm:"column:status;type:tinyint(1);not null;default:1;comment:地址状态"`
	TradeType   string    `gorm:"column:trade_type;type:varchar(20);not null;comment:交易类型"`
	Address     string    `gorm:"column:address;type:varchar(64);not null;index;comment:钱包地址"`
	OtherNotify uint8     `gorm:"column:other_notify;type:tinyint(1);not null;default:0;comment:其它通知"`
	CreatedAt   time.Time `gorm:"column:created_at;autoCreateTime;type:timestamp;not null;comment:创建时间"`
	UpdatedAt   time.Time `gorm:"column:updated_at;autoUpdateTime;type:timestamp;not null;comment:更新时间"`
}

func CalcTradeAmount

func CalcTradeAmount(wa []WalletAddress, rate, money float64, tradeType string) (WalletAddress, string)

CalcTradeAmount 计算当前实际可用的交易金额

func GetAvailableAddress

func GetAvailableAddress(address, tradeType string) []WalletAddress

func (*WalletAddress) Delete

func (wa *WalletAddress) Delete()

func (*WalletAddress) GetEvmRpcEndpoint added in v1.20.4

func (wa *WalletAddress) GetEvmRpcEndpoint() string

func (*WalletAddress) GetTokenContract added in v1.22.1

func (wa *WalletAddress) GetTokenContract() string

func (*WalletAddress) GetTokenDecimals added in v1.22.1

func (wa *WalletAddress) GetTokenDecimals() int32

func (*WalletAddress) SetOtherNotify

func (wa *WalletAddress) SetOtherNotify(notify uint8)

func (*WalletAddress) SetStatus

func (wa *WalletAddress) SetStatus(status uint8)

func (*WalletAddress) TableName

func (wa *WalletAddress) TableName() string

type Webhook added in v1.20.6

type Webhook struct {
	ID        int64           `gorm:"column:id;type:INTEGER PRIMARY KEY AUTOINCREMENT;" json:"id"`
	Status    int8            `gorm:"column:status;type:tinyint;not null;default:0" json:"status"`
	Num       int             `gorm:"column:num;type:int(11);not null;default:0" json:"hook_num"`
	Url       string          `gorm:"column:url;type:varchar(255);not null;default:''" json:"url"`
	Event     string          `gorm:"column:event;type:varchar(64);not null;default:''" json:"event"`
	Data      json.RawMessage `gorm:"column:data;type:json;not null" json:"data"`
	CreatedAt time.Time       `gorm:"autoCreateTime;type:timestamp;not null;comment:创建时间"`
	UpdatedAt time.Time       `gorm:"autoUpdateTime;type:timestamp;not null;comment:更新时间"`
}

func (Webhook) PostData added in v1.20.6

func (w Webhook) PostData() string

func (Webhook) SetStatus added in v1.20.6

func (w Webhook) SetStatus(status int8)

func (Webhook) TableName added in v1.20.6

func (Webhook) TableName() string

Jump to

Keyboard shortcuts

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