互动
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.6 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package models
  2. import (
  3. "hudongzhuanjia/utils/define"
  4. "time"
  5. "github.com/ouxuanserver/osmanthuswine/src/core"
  6. )
  7. const NewAuctionActivityTableName = TableNamePrefix + "new_auction_activity"
  8. type NewAuctionActivity struct {
  9. Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
  10. Pid int64 `json:"pid" xorm:"not null default(0) comment('排序id') INT(11)"`
  11. ActivityId int64 `json:"activity_id" xorm:"not null default(0) comment('主活动id') INT(11)"`
  12. Histories []*AuctionHistory `json:"histories" xorm:"-"`
  13. AuctionModel string `json:"auction_model" xorm:"not null default('加价竞拍') comment('竞拍模式:加价竞拍|减价竞拍') VARCHAR(128)"`
  14. AuctionGoodsName string `json:"auction_goods_name" xorm:"not null default('') comment('竞拍商品名字') VARCHAR(255)"`
  15. AuctionDuration string `json:"auction_duration" xorm:"not null default(0) comment('竞拍时长单位秒') INT(11)"`
  16. AuctionEndTime int64 `json:"auction_end_time" xorm:"not null default(0) comment('竞拍结束时间') INT(11)"`
  17. GoodsNum int `json:"goods_num" xorm:"not null default(0) comment('减价竞拍的商品数量') INT(11)"`
  18. StartPrice float64 `json:"start_price" xorm:"not null default(0.00) comment('起拍价格') DECIMAL(18)"`
  19. Step float64 `json:"step" xorm:"not null default(0.00) comment('加价或减价幅度') DECIMAL(18)"`
  20. ReduceRate string `json:"reduce_rate" xorm:"not null default(0) comment('减价频率单位秒') VARCHAR(255)"`
  21. Desc string `json:"desc" xorm:"not null comment('商品描述') TEXT"`
  22. GoodsPicUrl string `json:"goods_pic_url" xorm:"not null default('') comment('商品图片url') VARCHAR(255)"`
  23. Status string `json:"status" xorm:"not null default('未开始') comment('状态[未开始,装备中, 进行中,已结束]') VARCHAR(128)"`
  24. CurrentMoney float64 `json:"current_money,omitempty" xorm:"-" description:"当前价格"`
  25. Unit int `json:"unit" xorm:"not null default(1) comment('单位') TINYINT(1)"`
  26. IsSort int `json:"is_sort" xorm:"not null default(0) comment('1表示排过序') INT(11)"`
  27. IsDelete bool `json:"-" xorm:"not null default(0) comment('软删除') TINYINT(1)" description:"删除 "`
  28. CreatedAt time.Time `json:"-" xorm:"not null created comment('创建时间') DATETIME" description:"创建"`
  29. UpdatedAt time.Time `json:"-" xorm:"not null updated comment('更新时间') DATETIME" description:"更新"`
  30. }
  31. func (t *NewAuctionActivity) TableName() string {
  32. return NewAuctionActivityTableName
  33. }
  34. func (t *NewAuctionActivity) Alias(name string) string {
  35. return AliasTableName(t, name)
  36. }
  37. func (t *NewAuctionActivity) IncrMoneyById(id int64, money float64) (int64, error) {
  38. return core.GetXormAuto().Where("id=?", id).Incr("money", money).Update(t)
  39. }
  40. func (t *NewAuctionActivity) DecrMoneyById(id int64, money float64) (int64, error) {
  41. return core.GetXormAuto().Where("id=?", id).Decr("money", money).Decr("goods_num", 1).Update(t)
  42. }
  43. func (t *NewAuctionActivity) UpdateToStatusByAid(aid int64, before, after string) (int64, error) {
  44. t.Status = after
  45. t.UpdatedAt = time.Now()
  46. return core.GetXormAuto().Where("is_delete=0 and activity_id=? and status=?", aid, before).
  47. Cols("status", "updated_at").Update(t)
  48. }
  49. func (t *NewAuctionActivity) UpdateStatusById(id int64, status string) (int64, error) {
  50. t.Status = status
  51. t.UpdatedAt = time.Now()
  52. return core.GetXormAuto().Where("is_delete=0 and id=?", id).
  53. Cols("status", "updated_at").Update(t)
  54. }
  55. func (t *NewAuctionActivity) GetByActivityId(aid int64, status string) (bool, error) {
  56. return core.GetXormAuto().Where("is_delete=0 and activity_id=? and status=?", aid, status).
  57. Desc("created_at").Get(t)
  58. }
  59. func (t *NewAuctionActivity) GetCurrent(aid int64) (bool, error) {
  60. return core.GetXormAuto().Where("is_delete=0 and activity_id=? and (status=? or status=?)",
  61. aid, define.StatusReady, define.StatusRunning).Get(t)
  62. }
  63. func UpdateAuctionStatusByActivityId(aid int64) (int64, error) {
  64. return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).
  65. Update(&NewAuctionActivity{Status: define.StatusNotBegin})
  66. }
  67. func GetAuctionsByActivityId(aid int64, orderBy string) ([]*NewAuctionActivity, error) {
  68. auctions := make([]*NewAuctionActivity, 0)
  69. err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).
  70. OrderBy(orderBy).Find(&auctions)
  71. return auctions, err
  72. }