merchant.active.config.go 4.4 KB

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