active.cancel.log.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. TransID int64 `gorm:"column:trans_id;type:bigint(20)" json:"trans_id"` // 交易id
  14. UpdateBy int64 `gorm:"column:update_by;type:bigint(20)" json:"update_by"`
  15. CreateBy int64 `gorm:"column:create_by;type:bigint(20)" json:"create_by"`
  16. CreatedAt time.Time `gorm:"column:created_at;type:datetime" json:"created_at"`
  17. UpdatedAt time.Time `gorm:"column:updated_at;type:datetime" json:"updated_at"`
  18. DeletedAt time.Time `gorm:"column:deleted_at;type:datetime;default:null" json:"deleted_at"`
  19. }
  20. func (m *ActiveCancelLog) TableName() string {
  21. return "active_cancel_log"
  22. }
  23. // 统计cancel数量
  24. func (m *ActiveCancelLog) GetActiveCancelNum() int {
  25. var count int
  26. tableCount := orm.ShMysql.Table(m.TableName()).Where("active_config_id = ? and client_open_id = ?", m.ActiveConfigID, m.ClientOpenID)
  27. tableCount.Count(&count)
  28. return count
  29. }
  30. // 统计cancel数量
  31. func (m *ActiveCancelLog) GetActiveCancelNumByProjectID() int {
  32. var count int
  33. tableCount := orm.ShMysql.Table(m.TableName()).Where("active_config_id = ? and client_open_id = ? and group_by_project_id = ? and trans_id = ?", m.ActiveConfigID, m.ClientOpenID, m.GroupByProjectID, m.TransID)
  34. tableCount.Count(&count)
  35. return count
  36. }
  37. func (m *ActiveCancelLog) TXActiveCancelLogCreate(log []ActiveCancelLog) error {
  38. var err error
  39. tx := orm.ShMysql.Begin()
  40. defer func() {
  41. if err != nil {
  42. tx.Rollback()
  43. } else {
  44. tx.Commit()
  45. }
  46. }()
  47. for i := 0; i < len(log); i++ {
  48. err = tx.Table(log[i].TableName()).Create(&log[i]).Error
  49. if err != nil {
  50. return err
  51. }
  52. }
  53. return nil
  54. }