client.account.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package shanghu
  2. import (
  3. orm "duoduo/database"
  4. "github.com/shopspring/decimal"
  5. "time"
  6. )
  7. type MerchantClientAccount 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"` // openid
  10. ReviewAmount decimal.Decimal `gorm:"column:review_amount;type:decimal(10,2)" json:"review_amount"` // 审核金额
  11. Amount decimal.Decimal `gorm:"column:amount;type:decimal(10,2)" json:"amount"` // 可提现金额
  12. Version int `gorm:"column:version;type:int(11)" json:"version"` // 创建者
  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 *MerchantClientAccount) TableName() string {
  20. return "merchant_client_account"
  21. }
  22. func (m *MerchantClientAccount) GetClientAccount() (MerchantClientAccount, error) {
  23. var doc MerchantClientAccount
  24. table := orm.ShMysql.Table(m.TableName())
  25. table = table.Where("client_open_id = ? ", m.ClientOpenID)
  26. if err := table.Select("*").First(&doc).Error; err != nil {
  27. return doc, err
  28. }
  29. return doc, nil
  30. }
  31. func (m *MerchantClientAccount) UpdateClientAccountStatusById(amount decimal.Decimal) error {
  32. var merchantClientLog MerchantClientAccountLog
  33. tx := orm.ShMysql.Begin()
  34. var err error
  35. defer func() {
  36. if err != nil {
  37. tx.Rollback()
  38. } else {
  39. tx.Commit()
  40. }
  41. }()
  42. merchantClientLog.ClientOpenID = m.ClientOpenID
  43. merchantClientLog.Amount = amount
  44. merchantClientLog.TransType = 2 //提现中
  45. return nil
  46. }