active.cancel.log.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package shanghu
  2. import (
  3. orm "duoduo/database"
  4. "time"
  5. )
  6. type ActiveCancelLog struct {
  7. ID int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"` // 主键
  8. ClientOpenID string `gorm:"column:client_open_id;type:varchar(255)" json:"client_open_id"`
  9. MerchantOpenID string `gorm:"column:merchant_open_id;type:varchar(255)" json:"merchant_open_id"`
  10. ActiveConfigID int64 `gorm:"column:active_config_id;type:bigint(20)" json:"active_config_id"` // 活动id
  11. GroupByProjectID int64 `gorm:"column:group_by_project_id;type:bigint(20)" json:"group_by_project_id"` // 拼团商品id
  12. SeckillID int64 `gorm:"column:seckill_id;type:bigint(20)" json:"seckill_id"` // 秒杀id
  13. UpdateBy int64 `gorm:"column:update_by;type:bigint(20)" json:"update_by"`
  14. CreateBy int64 `gorm:"column:create_by;type:bigint(20)" json:"create_by"`
  15. CreatedAt time.Time `gorm:"column:created_at;type:datetime" json:"created_at"`
  16. UpdatedAt time.Time `gorm:"column:updated_at;type:datetime" json:"updated_at"`
  17. DeletedAt time.Time `gorm:"column:deleted_at;type:datetime;default:null" json:"deleted_at"`
  18. }
  19. func (m *ActiveCancelLog) TableName() string {
  20. return "active_cancel_log"
  21. }
  22. // 统计cancel数量
  23. func (m *ActiveCancelLog) GetActiveCancelNum() int {
  24. var count int
  25. tableCount := orm.ShMysql.Table(m.TableName()).Where("active_config_id = ? and client_open_id = ?", m.ActiveConfigID, m.ClientOpenID)
  26. tableCount.Count(&count)
  27. return count
  28. }
  29. func (m *ActiveCancelLog) TXActiveCancelLogCreate(log []ActiveCancelLog) error {
  30. var err error
  31. tx := orm.ShMysql.Begin()
  32. defer func() {
  33. if err != nil {
  34. tx.Rollback()
  35. } else {
  36. tx.Commit()
  37. }
  38. }()
  39. for i := 0; i < len(log); i++ {
  40. err = tx.Table(log[i].TableName()).Create(&log[i]).Error
  41. if err != nil {
  42. return err
  43. }
  44. }
  45. return nil
  46. }