cancel_log.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package shanghu
  2. import (
  3. orm "duoduo/database"
  4. "time"
  5. )
  6. type CancelLog struct {
  7. ID int64 `gorm:"column:id;type:bigint(20)" 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. MerchantID int64 `gorm:"column:merchant_id;type:bigint(20)" json:"merchant_id"` // 商户卡id
  11. UpdateBy int64 `gorm:"column:update_by;type:bigint(20)" json:"update_by"`
  12. CreateBy int64 `gorm:"column:create_by;type:bigint(20)" json:"create_by"`
  13. CreatedAt time.Time `gorm:"column:created_at;type:datetime" json:"created_at"`
  14. UpdatedAt time.Time `gorm:"column:updated_at;type:datetime" json:"updated_at"`
  15. DeletedAt time.Time `gorm:"column:deleted_at;type:datetime;default:null" json:"deleted_at"`
  16. }
  17. func (m *CancelLog) TableName() string {
  18. return "cancel_log"
  19. }
  20. func (u *CancelLog) Create() (CancelLog, error) {
  21. var doc CancelLog
  22. var err error
  23. doc = *u
  24. err = orm.ShMysql.Table(u.TableName()).Create(&doc).Error
  25. if err != nil {
  26. return doc, err
  27. }
  28. return doc, nil
  29. }
  30. func (u *CancelLog) CreateBatches(log []CancelLog) error {
  31. var err error
  32. tx := orm.ShMysql.Begin()
  33. defer func() {
  34. if err != nil {
  35. tx.Rollback()
  36. } else {
  37. tx.Commit()
  38. }
  39. }()
  40. for i := 0; i < len(log); i++ {
  41. err = orm.ShMysql.Table(log[i].TableName()).Create(&log[i]).Error
  42. if err != nil {
  43. return err
  44. }
  45. }
  46. return nil
  47. }
  48. func (u *CancelLog) GetNumber() int {
  49. var count int
  50. tableCount := orm.ShMysql.Table(u.TableName()).Where("client_open_id = ? and merchant_id = ?", u.ClientOpenID, u.MerchantID)
  51. tableCount.Count(&count)
  52. return count
  53. }