models

package
v0.0.0-...-402233a Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLuckyMoneyID = 100000

默认红包ID

Variables

View Source
var (
	// 资产不足
	ErrInsufficientAmount = errors.New("insufficient amount")
	// 没有此类型账户
	ErrNoSuchTypeAccount = errors.New("no such type of account")
)
View Source
var (
	// 领完了
	ErrNothingLeft = errors.New("nothing left")
	// 重复领取
	ErrRepeatReceive = errors.New("repeat receive")
	// 没有激活
	ErrNotActivated = errors.New("not activated")
	// 已经激活
	ErrAlreadyActivated = errors.New("already activated")
	// 没有权限
	ErrPermissionDenied = errors.New("permission denied")
	// 红包已过期
	ErrLuckyMoneydExpired = errors.New("lucky money expired")
)

Functions

This section is empty.

Types

type Account

type Account struct {
	Symbol  string     `json:"symbol"`  // 货币符号
	Amount  *big.Float `json:"amount"`  // 资产金额
	Locked  *big.Float `json:"locked"`  // 锁定金额
	Disable bool       `json:"disable"` // 禁用账户
}

账户数据

func (*Account) Normalization

func (account *Account) Normalization()

标准化

type AccountModel

type AccountModel struct {
}

账户模型

func (*AccountModel) Deposit

func (model *AccountModel) Deposit(userID int64, symbol string, amount *big.Float) (*Account, error)

账户存款操作

func (*AccountModel) GetAccount

func (model *AccountModel) GetAccount(userID int64, symbol string) (*Account, error)

获取账户信息

func (*AccountModel) GetAccounts

func (model *AccountModel) GetAccounts(userID int64) ([]*Account, error)

获取账户列表

func (*AccountModel) LockAccount

func (model *AccountModel) LockAccount(userID int64, symbol string, amount *big.Float) (*Account, error)

锁定账户资金

func (*AccountModel) TransferFromLockAccount

func (model *AccountModel) TransferFromLockAccount(from, to int64, symbol string,
	amount *big.Float) (*Account, *Account, error)

从锁定账户转账

func (*AccountModel) UnlockAccount

func (model *AccountModel) UnlockAccount(userID int64, symbol string, amount *big.Float) (*Account, error)

解锁账户资金

func (*AccountModel) Withdraw

func (model *AccountModel) Withdraw(userID int64, symbol string, amount *big.Float) (*Account, error)

账户取款操作

type AccountVersionModel

type AccountVersionModel struct {
}

账户版本模型

func (*AccountVersionModel) GetVersions

func (model *AccountVersionModel) GetVersions(userID int64, offset, limit uint, reverse bool) ([]*Version, int, error)

获取版本

func (*AccountVersionModel) InsertVersion

func (model *AccountVersionModel) InsertVersion(userID int64, version *Version) (*Version, error)

插入版本

type DepositModel

type DepositModel struct {
}

充值模型

func (*DepositModel) Add

func (model *DepositModel) Add(txid string, data []byte) error

添加充值记录

func (*DepositModel) Exist

func (model *DepositModel) Exist(txid string) bool

记录是否存在

type LuckyMoney

type LuckyMoney struct {
	ID         uint64     `json:"id"`          // 红包ID
	SN         string     `json:"sn"`          // 唯一编号
	SenderID   int64      `json:"sender_id"`   // 发送者
	SenderName string     `json:"sender_name"` // 发送者名字
	Asset      string     `json:"asset"`       // 资产类型
	Amount     *big.Float `json:"amount"`      // 红包金额
	Received   *big.Float `json:"received"`    // 领取金额
	Number     uint32     `json:"number"`      // 红包个数
	Lucky      bool       `json:"lucky"`       // 是否随机
	Value      *big.Float `json:"value"`       // 单个价值
	Active     bool       `json:"active"`      // 是否激活
	Message    string     `json:"message"`     // 红包留言
	Timestamp  int64      `json:"timestamp"`   // 时间戳
}

红包信息

func (*LuckyMoney) Normalization

func (luckymoney *LuckyMoney) Normalization()

标准化

type LuckyMoneyHistory

type LuckyMoneyHistory struct {
	Value *big.Float      `json:"value"`          // 红包金额
	User  *LuckyMoneyUser `json:"user,omitempty"` // 用户信息
}

红包记录

func (*LuckyMoneyHistory) Normalization

func (history *LuckyMoneyHistory) Normalization()

标准化

type LuckyMoneyModel

type LuckyMoneyModel struct {
}

红包模型

func (*LuckyMoneyModel) Collection

func (model *LuckyMoneyModel) Collection(userID int64, pending bool, offset, limit uint, reverse bool) ([]uint64, uint, error)

获取用户红包

func (*LuckyMoneyModel) Foreach

func (model *LuckyMoneyModel) Foreach(startID uint64, callback func(*LuckyMoney)) error

遍历红包列表

func (*LuckyMoneyModel) GetBestAndWorst

func (model *LuckyMoneyModel) GetBestAndWorst(id uint64) (*LuckyMoneyHistory, *LuckyMoneyHistory, error)

获取最佳红包

func (*LuckyMoneyModel) GetLatestExpired

func (model *LuckyMoneyModel) GetLatestExpired() (uint64, error)

获取最新过期红包

func (*LuckyMoneyModel) GetLuckyMoney

func (model *LuckyMoneyModel) GetLuckyMoney(id uint64) (*LuckyMoney, uint32, error)

获取红包信息

func (*LuckyMoneyModel) GetLuckyMoneyIDBySN

func (model *LuckyMoneyModel) GetLuckyMoneyIDBySN(sn string) (uint64, error)

根据SN获取红包ID

func (*LuckyMoneyModel) GetReceiveHistory

func (model *LuckyMoneyModel) GetReceiveHistory(id uint64) ([]*LuckyMoneyHistory, error)

获取领取历史

func (*LuckyMoneyModel) IsExpired

func (model *LuckyMoneyModel) IsExpired(id uint64) bool

是否过期

func (*LuckyMoneyModel) IsReceived

func (model *LuckyMoneyModel) IsReceived(id uint64, userID int64) (bool, error)

是否已领取

func (*LuckyMoneyModel) NewLuckyMoney

func (model *LuckyMoneyModel) NewLuckyMoney(data *LuckyMoney, luckyMoneyArr []*big.Float) (*LuckyMoney, error)

创建新红包

func (*LuckyMoneyModel) ReceiveLuckyMoney

func (model *LuckyMoneyModel) ReceiveLuckyMoney(id uint64, userID int64, firstName string) (*big.Float, int, error)

领取红包

func (*LuckyMoneyModel) SetExpired

func (model *LuckyMoneyModel) SetExpired(id uint64) error

设置过期

func (*LuckyMoneyModel) SetLatestExpired

func (model *LuckyMoneyModel) SetLatestExpired(id uint64) error

设置最新过期红包

type LuckyMoneyUser

type LuckyMoneyUser struct {
	UserID    int64  `json:"user_id"`    // 用户ID
	FirstName string `json:"first_name"` // 用户名
}

红包用户

type Reason

type Reason int

触发原因

const (
	ReasonGive            Reason // 发红包
	ReasonSystem                 // 系统发放
	ReasonReceive                // 领取红包
	ReasonGiveBack               // 退还红包
	ReasonDeposit                // 充值
	ReasonWithdraw               // 提现
	ReasonWithdrawSuccess        // 提现成功
	ReasonWithdrawFailure        // 提现失败
)

type SubscriberModel

type SubscriberModel struct {
}

订户模型

func (*SubscriberModel) AddSubscriber

func (*SubscriberModel) AddSubscriber(userID int64) error

添加订阅者

func (*SubscriberModel) GetSubscriberCount

func (*SubscriberModel) GetSubscriberCount() (int, error)

获取订阅者数量

func (*SubscriberModel) GetSubscribers

func (*SubscriberModel) GetSubscribers() ([]int64, error)

获取订阅者

type Version

type Version struct {
	ID              uint64     `json:"id"`                           // 版本ID
	Symbol          string     `json:"symbol"`                       // 代币符号
	Balance         *big.Float `json:"balance,omitempty"`            // 余额变化
	Locked          *big.Float `json:"locked,omitempty"`             // 锁定变化
	Fee             *big.Float `json:"fee,omitempty"`                // 手续费
	Amount          *big.Float `json:"amount"`                       // 剩余金额
	Timestamp       int64      `json:"timestamp"`                    // 时间戳
	Reason          Reason     `json:"reason"`                       // 触发原因
	RefLuckyMoneyID *uint64    `json:"ref_lucky_money_id,omitempty"` // 关联红包ID
	RefBlockHeight  *uint64    `json:"ref_block_height,omitempty"`   // 关联区块高度
	RefTxID         *string    `json:"ref_tx_id,omitempty"`          // 关联交易ID
	RefUserID       *int64     `json:"ref_user_id,omitempty"`        // 关联用户ID
	RefUserName     *string    `json:"ref_user_name,omitempty"`      // 关联用户名
	RefAddress      *string    `json:"ref_address,omitempty"`        // 关联地址
	RefMemo         *string    `json:"ref_memo,omitempty"`           // 关联备注信息
}

版本信息

Jump to

Keyboard shortcuts

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