merchant.active.config.go 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package shanghu
  2. import (
  3. orm "duoduo/database"
  4. "time"
  5. )
  6. // 活动中奖配置,拼团配置,秒杀配置
  7. type MerchantActiveConfig struct {
  8. ID int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
  9. ConfigMode int `gorm:"column:config_mode;type:int(11)" json:"config_mode"` // 模式 1-默认模式
  10. MerchantOpenID string `gorm:"column:merchant_open_id;type:varchar(255)" json:"merchant_open_id"` // openid
  11. DrawMode int `gorm:"column:draw_mode;type:int(11);default:0" json:"draw_mode"` // 抽奖模式 0-不抽奖,1-盲盒
  12. DrawOneBiZhong int64 `gorm:"column:draw_one_bi_zhong;type:bigint(20)" json:"draw_one_bi_zhong"` // 首次必中抽奖商品ID
  13. DrawProduct string `gorm:"column:draw_product;type:json" json:"draw_product"` // 抽奖商品 商品ID 与中奖率
  14. CreateBy int64 `gorm:"column:create_by;type:bigint(20)" json:"create_by"` // 创建者
  15. UpdateBy int64 `gorm:"column:update_by;type:bigint(20)" json:"update_by"` // 更新者
  16. CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` // 创建时间
  17. UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` // 最后更新时间
  18. DeletedAt time.Time `gorm:"column:deleted_at;type:datetime(3);default:null" json:"deleted_at"` // 删除时间
  19. GroupBuyMode int `gorm:"column:group_buy_mode;type:int(11)" json:"group_buy_mode"` // 0-不开团 1-虚拟开团 2-真实开团
  20. GroupBuy string `gorm:"column:group_buy;type:json" json:"group_buy"` // 开团配置
  21. GroupBuyUrl string `gorm:"column:group_buy_url;type:varchar(255)" json:"group_buy_url"` // 介绍图url
  22. ActivityEndTime int64 `gorm:"column:activity_end_time;type:bigint(20)" json:"activity_end_time"` // 活动结束时间
  23. ActivityStartTime int64 `gorm:"column:activity_start_time;type:bigint(20)" json:"activity_start_time"` // 活动开始时间
  24. ActiveName string `gorm:"column:active_name;type:varchar(255)" json:"active_name"` // 活动名称
  25. }
  26. func (m *MerchantActiveConfig) TableName() string {
  27. return "merchant_active_config"
  28. }
  29. func (u *MerchantActiveConfig) Create() (MerchantActiveConfig, error) {
  30. var doc MerchantActiveConfig
  31. var err error
  32. doc = *u
  33. err = orm.ShMysql.Table(u.TableName()).Create(&doc).Error
  34. if err != nil {
  35. return doc, err
  36. }
  37. return doc, nil
  38. }
  39. func (m *MerchantActiveConfig) GetConfigInfoById() (MerchantActiveConfig, error) {
  40. var doc MerchantActiveConfig
  41. table := orm.ShMysql.Table(m.TableName())
  42. table = table.Where("id = ? ", m.ID)
  43. if err := table.Select("*").First(&doc).Error; err != nil {
  44. return doc, err
  45. }
  46. return doc, nil
  47. }
  48. func (m *MerchantActiveConfig) GetActiveConfigList(pageSize int, pageIndex int) ([]MerchantActiveConfig, int, error) {
  49. var doc []MerchantActiveConfig
  50. table := orm.ShMysql.Table(m.TableName())
  51. table = table.Where("merchant_open_id = ? ", m.MerchantOpenID)
  52. var count int
  53. if err := table.Select("*").Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
  54. return nil, 0, err
  55. }
  56. table.Count(&count)
  57. return doc, count, nil
  58. }