active.cancel.log.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // 统计cancel数量
  30. func (m *ActiveCancelLog) GetActiveCancelNumByProjectID() int {
  31. var count int
  32. tableCount := orm.ShMysql.Table(m.TableName()).Where("active_config_id = ? and client_open_id = ? and group_by_project_id = ?", m.ActiveConfigID, m.ClientOpenID, m.GroupByProjectID)
  33. tableCount.Count(&count)
  34. return count
  35. }
  36. func (m *ActiveCancelLog) TXActiveCancelLogCreate(log []ActiveCancelLog) error {
  37. var err error
  38. tx := orm.ShMysql.Begin()
  39. defer func() {
  40. if err != nil {
  41. tx.Rollback()
  42. } else {
  43. tx.Commit()
  44. }
  45. }()
  46. for i := 0; i < len(log); i++ {
  47. err = tx.Table(log[i].TableName()).Create(&log[i]).Error
  48. if err != nil {
  49. return err
  50. }
  51. }
  52. return nil
  53. }