merchant.recharge.client.account.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package shanghu
  2. import (
  3. orm "duoduo/database"
  4. "github.com/shopspring/decimal"
  5. "time"
  6. )
  7. type MerchantRechargeClientAccount struct {
  8. ID int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"` // 主键
  9. ClientOpenID string `gorm:"column:client_open_id;type:varchar(255)" json:"client_open_id"`
  10. MerchantOpenID string `gorm:"column:merchant_open_id;type:varchar(255)" json:"merchant_open_id"` // Open-id
  11. Version int `gorm:"column:version;type:int(11)" json:"version"` // Version
  12. Amount decimal.Decimal `gorm:"column:amount;type:decimal(10,2)" json:"amount"` // 可提现金额
  13. CreateBy int64 `gorm:"column:create_by;type:bigint(20)" json:"create_by"` // 创建者
  14. UpdateBy int64 `gorm:"column:update_by;type:bigint(20)" json:"update_by"` // 更新者
  15. CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` // 创建时间
  16. UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` // 最后更新时间
  17. DeletedAt time.Time `gorm:"column:deleted_at;type:datetime(3);default:null" json:"deleted_at"` // 删除时间
  18. }
  19. func (m *MerchantRechargeClientAccount) TableName() string {
  20. return "merchant_recharge_client_account"
  21. }
  22. // list 接口使用
  23. func (m *MerchantRechargeClientAccount) MerchantRechargeClientAccountList(pageSize int, pageIndex int) ([]MerchantRechargeClientAccount, int, error) {
  24. var doc []MerchantRechargeClientAccount
  25. table := orm.ShMysql.Table(m.TableName())
  26. table = table.Where("client_open_id = ? ", m.ClientOpenID)
  27. var count int
  28. if err := table.Select("*").Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
  29. return nil, 0, err
  30. }
  31. table.Count(&count)
  32. return doc, count, nil
  33. }
  34. func (m *MerchantRechargeClientAccount) MerchantRechargeClientAccount() (MerchantRechargeClientAccount, error) {
  35. var doc MerchantRechargeClientAccount
  36. table := orm.ShMysql.Table(m.TableName())
  37. table = table.Where("client_open_id = ? and merchant_open_id = ?", m.ClientOpenID, m.MerchantOpenID)
  38. if err := table.Select("*").Order("id desc").First(&doc).Error; err != nil {
  39. return doc, err
  40. }
  41. return doc, nil
  42. }
  43. func (m *MerchantRechargeClientAccount) GetMerchantRechargeClientAccount() (MerchantRechargeClientAccount, error) {
  44. var doc MerchantRechargeClientAccount
  45. table := orm.ShMysql.Table(m.TableName())
  46. table = table.Where("id = ?", m.ID)
  47. if err := table.Select("*").First(&doc).Error; err != nil {
  48. return doc, err
  49. }
  50. return doc, nil
  51. }