12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package shanghu
- import (
- orm "duoduo/database"
- "time"
- )
- type CancelLog struct {
- ID int64 `gorm:"column:id;type:bigint(20)" json:"id"` // 主键
- ClientOpenID string `gorm:"column:client_open_id;type:varchar(255)" json:"client_open_id"`
- MerchantOpenID string `gorm:"column:merchant_open_id;type:varchar(255)" json:"merchant_open_id"`
- MerchantID int64 `gorm:"column:merchant_id;type:bigint(20)" json:"merchant_id"` // 商户卡id
- UpdateBy int64 `gorm:"column:update_by;type:bigint(20)" json:"update_by"`
- CreateBy int64 `gorm:"column:create_by;type:bigint(20)" json:"create_by"`
- CreatedAt time.Time `gorm:"column:created_at;type:datetime" json:"created_at"`
- UpdatedAt time.Time `gorm:"column:updated_at;type:datetime" json:"updated_at"`
- DeletedAt time.Time `gorm:"column:deleted_at;type:datetime;default:null" json:"deleted_at"`
- }
- func (m *CancelLog) TableName() string {
- return "cancel_log"
- }
- func (u *CancelLog) Create() (CancelLog, error) {
- var doc CancelLog
- var err error
- doc = *u
- err = orm.ShMysql.Table(u.TableName()).Create(&doc).Error
- if err != nil {
- return doc, err
- }
- return doc, nil
- }
- func (u *CancelLog) CreateBatches(log []CancelLog) error {
- var err error
- tx := orm.ShMysql.Begin()
- defer func() {
- if err != nil {
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
- for i := 0; i < len(log); i++ {
- err = orm.ShMysql.Table(log[i].TableName()).Create(&log[i]).Error
- if err != nil {
- return err
- }
- }
- return nil
- }
- func (u *CancelLog) GetNumber() int {
- var count int
- tableCount := orm.ShMysql.Table(u.TableName()).Where("client_open_id = ? and merchant_id = ?", u.ClientOpenID, u.MerchantID)
- tableCount.Count(&count)
- return count
- }
|