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.
84 lines
4.5 KiB
84 lines
4.5 KiB
package models
|
|
|
|
import (
|
|
"hudongzhuanjia/utils/define"
|
|
"time"
|
|
|
|
"github.com/ouxuanserver/osmanthuswine/src/core"
|
|
)
|
|
|
|
const NewAuctionActivityTableName = TableNamePrefix + "new_auction_activity"
|
|
|
|
type NewAuctionActivity struct {
|
|
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
|
|
Pid int `json:"pid" xorm:"not null default(0) comment('排序id') INT(11)"`
|
|
ActivityId int `json:"activity_id" xorm:"not null default(0) comment('主活动id') INT(11)"`
|
|
Histories []*AuctionHistory `json:"histories" xorm:"-"`
|
|
AuctionModel string `json:"auction_model" xorm:"not null default('加价竞拍') comment('竞拍模式:加价竞拍|减价竞拍') VARCHAR(128)"`
|
|
AuctionGoodsName string `json:"auction_goods_name" xorm:"not null default('') comment('竞拍商品名字') VARCHAR(255)"`
|
|
AuctionDuration string `json:"auction_duration" xorm:"not null default(0) comment('竞拍时长单位秒') INT(11)"`
|
|
AuctionEndTime int64 `json:"auction_end_time" xorm:"not null default(0) comment('竞拍结束时间') INT(11)"`
|
|
GoodsNum int `json:"goods_num" xorm:"not null default(0) comment('减价竞拍的商品数量') INT(11)"`
|
|
StartPrice float64 `json:"start_price" xorm:"not null default(0.00) comment('起拍价格') DECIMAL(18)"`
|
|
Step float64 `json:"step" xorm:"not null default(0.00) comment('加价或减价幅度') DECIMAL(18)"`
|
|
ReduceRate string `json:"reduce_rate" xorm:"not null default(0) comment('减价频率单位秒') VARCHAR(255)"`
|
|
Desc string `json:"desc" xorm:"not null comment('商品描述') TEXT"`
|
|
GoodsPicUrl string `json:"goods_pic_url" xorm:"not null default('') comment('商品图片url') VARCHAR(255)"`
|
|
Status string `json:"status" xorm:"not null default('未开始') comment('状态[未开始,装备中, 进行中,已结束]') VARCHAR(128)"`
|
|
CurrentMoney float64 `json:"current_money,omitempty" xorm:"-" description:"当前价格"`
|
|
Unit int `json:"unit" xorm:"not null default(1) comment('单位') TINYINT(1)"`
|
|
IsSort int `json:"is_sort" xorm:"not null default(0) comment('1表示排过序') INT(11)"`
|
|
IsDelete bool `json:"-" xorm:"not null default(0) comment('软删除') TINYINT(1)" description:"删除 "`
|
|
CreatedAt time.Time `json:"-" xorm:"not null created comment('创建时间') DATETIME" description:"创建"`
|
|
UpdatedAt time.Time `json:"-" xorm:"not null updated comment('更新时间') DATETIME" description:"更新"`
|
|
}
|
|
|
|
func (t *NewAuctionActivity) TableName() string {
|
|
return NewAuctionActivityTableName
|
|
}
|
|
|
|
func (t *NewAuctionActivity) Alias(name string) string {
|
|
return Alias(t, name)
|
|
}
|
|
|
|
func (t *NewAuctionActivity) IncrMoneyById(id int, money float64) (int64, error) {
|
|
return core.GetXormAuto().Where("id=?", id).Incr("money", money).Update(t)
|
|
}
|
|
|
|
func (t *NewAuctionActivity) DecrMoneyById(id int, money float64) (int64, error) {
|
|
return core.GetXormAuto().Where("id=?", id).Decr("money", money).Decr("goods_num", 1).Update(t)
|
|
}
|
|
|
|
func (t *NewAuctionActivity) UpdateToStatusByAid(aid int, before, after string) (int64, error) {
|
|
t.Status = after
|
|
t.UpdatedAt = time.Now()
|
|
return core.GetXormAuto().Where("is_delete=0 and activity_id=? and status=?", aid, before).
|
|
Cols("status", "updated_at").Update(t)
|
|
}
|
|
func (t *NewAuctionActivity) UpdateStatusById(id int, status string) (int64, error) {
|
|
t.Status = status
|
|
t.UpdatedAt = time.Now()
|
|
return core.GetXormAuto().Where("is_delete=0 and id=?", id).
|
|
Cols("status", "updated_at").Update(t)
|
|
}
|
|
|
|
func (t *NewAuctionActivity) GetByActivityId(aid int, status string) (bool, error) {
|
|
return core.GetXormAuto().Where("is_delete=0 and activity_id=? and status=?", aid, status).
|
|
Desc("created_at").Get(t)
|
|
}
|
|
func (t *NewAuctionActivity) GetCurrent(aid int) (bool, error) {
|
|
return core.GetXormAuto().Where("is_delete=0 and activity_id=? and (status=? or status=?)",
|
|
aid, define.StatusReady, define.StatusRunning).Get(t)
|
|
}
|
|
|
|
func UpdateAuctionStatusByActivityId(aid int) (int64, error) {
|
|
return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).
|
|
Update(&NewAuctionActivity{Status: define.StatusNotBegin})
|
|
}
|
|
|
|
func GetAuctionsByActivityId(aid int) ([]*NewAuctionActivity, error) {
|
|
auctions := make([]*NewAuctionActivity, 0)
|
|
err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).
|
|
Asc("created_at").Find(&auctions)
|
|
return auctions, err
|
|
}
|