You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

194 lines
5.6 KiB

package model
import (
"errors"
"gorm.io/gorm"
"time"
"wss-pool/internal/data"
)
const (
AlreadyReceived int = 2 //已领取
Unclaimed int = 1 //未领取
ModifyContract int = 0 //插针
Market int = 2 //现货
Contract int = 1 //合约
)
type ContractMarket struct {
ID int64 `gorm:"column:id;"json:"id"`
TradeName string `gorm:"column:trade_name;" json:"name"`
BeginTime string `gorm:"column:begin_time;" json:"begin_time"`
Step int `gorm:"column:step;" json:"step"`
EndTime string `gorm:"column:end_time;" json:"end_time"`
MaxPrice string `gorm:"column:max_price" json:"max_price"`
IsType int `gorm:"column:type;not null;type:tinyint(2);COMMENT:'0 插针 1 自发合约 2 自发现货 '"json:"type"`
IsGet int `gorm:"column:is_get;not null;type:tinyint(2);DEFAULT:1;COMMENT:'是否完成(1 未领取 2 已领取 ) '"json:"is_get"`
KeepDecimal int `gorm:"column:keep_decimal; '"json:"keep_decimal"`
Gorm *gorm.DB `gorm:"-" json:"-"`
}
func (this *ContractMarket) TableName() string {
return "bot_contract_market"
}
func NewContractMarket() *ContractMarket {
ContractMarket := &ContractMarket{}
ContractMarket.NewGorm()
return ContractMarket
}
func (this *ContractMarket) NewGorm() *ContractMarket {
this.Gorm = data.WebGorm.Table(this.TableName())
return this
}
func (this *ContractMarket) WhereBegin() *ContractMarket {
this.Gorm = this.Gorm.Table(this.TableName()).Where("begin_time >= ?", time.Now().Format("2006-01-02 15:04:05"))
return this
}
func (this *ContractMarket) WhereID() *ContractMarket {
if this.ID == 0 {
this.Gorm.Error = errors.New("param is null")
return this
}
this.Gorm = this.Gorm.Table(this.TableName()).Where(&ContractMarket{ID: this.ID})
return this
}
func (this *ContractMarket) WhereName() *ContractMarket {
if this.TradeName == "" {
this.Gorm.Error = errors.New("param is null")
return this
}
this.Gorm = this.Gorm.Table(this.TableName()).Where(&ContractMarket{TradeName: this.TradeName})
return this
}
func (this *ContractMarket) WhereModifyContract() *ContractMarket {
this.Gorm = this.Gorm.Table(this.TableName()).Where("`bot_contract_market`.`type` = ?", ModifyContract)
return this
}
func (this *ContractMarket) WhereInID(ids []int64) *ContractMarket {
if len(ids) <= 0 {
this.Gorm.Error = errors.New("param is null")
return this
}
this.Gorm = this.Gorm.Table(this.TableName()).Where("id in (?)", ids)
return this
}
func (this *ContractMarket) WhereIsTyep() *ContractMarket {
if this.IsType <= 0 {
this.Gorm.Error = errors.New("param is null")
return this
}
this.Gorm = this.Gorm.Table(this.TableName()).Where(&ContractMarket{IsType: this.IsType})
return this
}
func (this *ContractMarket) WhereIsGet() *ContractMarket {
if this.IsGet == 0 {
this.Gorm.Error = errors.New("param is null")
return this
}
this.Gorm = this.Gorm.Table(this.TableName()).Where(&ContractMarket{IsGet: this.IsGet})
return this
}
func (this *ContractMarket) Update(record *ContractMarket) *ContractMarket {
this.Gorm = this.Gorm.Updates(record)
return this
}
func (this *ContractMarket) Create() *ContractMarket {
this.Gorm = this.Gorm.Create(&this)
return this
}
func (this *ContractMarket) Joins(sql string) *ContractMarket {
this.Gorm = this.Gorm.Joins(sql)
return this
}
func (this *ContractMarket) Limit(limit int) *ContractMarket {
this.Gorm = this.Gorm.Limit(limit)
return this
}
func (this *ContractMarket) Offset(Offset int) *ContractMarket {
this.Gorm = this.Gorm.Offset(Offset)
return this
}
func (this *ContractMarket) First() *ContractMarket {
Accounts := ContractMarket{}
this.Gorm = this.Gorm.First(&Accounts)
return &Accounts
}
func (this *ContractMarket) Assign(ContractMarket *ContractMarket) *ContractMarket {
this.Gorm = this.Gorm.Assign(ContractMarket)
return this
}
func (this *ContractMarket) FirstOrCreate() *ContractMarket {
this.Gorm = this.Gorm.FirstOrCreate(&this)
return this
}
func (this *ContractMarket) Order(value interface{}) *ContractMarket {
this.Gorm = this.Gorm.Order(value)
return this
}
func (this *ContractMarket) Count() int64 {
var num int64
this.Gorm = this.Gorm.Count(&num)
return num
}
func (this *ContractMarket) Select(column string) *ContractMarket {
this.Gorm = this.Gorm.Select(column)
return this
}
func (this *ContractMarket) WhereTime(LoginAt string) *ContractMarket {
if LoginAt == "" {
this.Gorm.Error = errors.New("date require ")
return this
}
this.Gorm = this.Gorm.Table(this.TableName()).Where("login_at = ?", LoginAt)
return this
}
func (this *ContractMarket) Pluck(column string, value interface{}) *ContractMarket {
this.Gorm = this.Gorm.Pluck(column, value)
return this
}
func (this *ContractMarket) Find(list *[]ContractMarket) *ContractMarket {
this.Gorm = this.Gorm.Find(&list)
return this
}
func (this *ContractMarket) List() (result []ContractMarket) {
this.IsGet = Unclaimed
this.WhereIsTyep().WhereIsGet().WhereBegin().WhereName().Order("id asc").Find(&result)
return result
}
func (this *ContractMarket) ListModifyContract() (result []ContractMarket) {
this.IsGet = Unclaimed
this.Select("l.keep_decimal,bot_contract_market.*").WhereModifyContract().Joins("inner join bot_contract_list l on l.trade_name = bot_contract_market.trade_name").WhereIsGet().Order("id asc").Find(&result)
return result
}
func (this *ContractMarket) UpdateIsGet(ids []int64) error {
this.IsGet = Unclaimed
return this.WhereInID(ids).WhereIsGet().Update(&ContractMarket{IsGet: AlreadyReceived}).Gorm.Error
}
func (this *ContractMarket) UpdateIsGetOne() error {
this.IsGet = Unclaimed
return this.WhereID().WhereIsGet().Update(&ContractMarket{IsGet: AlreadyReceived}).Gorm.Error
}