12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package shanghu
- import (
- orm "duoduo/database"
- "github.com/shopspring/decimal"
- "time"
- )
- type MerchantClientAccount struct {
- ID int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
- ClientOpenID string `gorm:"column:client_open_id;type:varchar(255)" json:"client_open_id"`
- ReviewAmount decimal.Decimal `gorm:"column:review_amount;type:decimal(10,2)" json:"review_amount"`
- Amount decimal.Decimal `gorm:"column:amount;type:decimal(10,2)" json:"amount"`
- Version int `gorm:"column:version;type:int(11)" json:"version"`
- CreateBy int64 `gorm:"column:create_by;type:bigint(20)" json:"create_by"`
- UpdateBy int64 `gorm:"column:update_by;type:bigint(20)" json:"update_by"`
- CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"`
- UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"`
- DeletedAt time.Time `gorm:"column:deleted_at;type:datetime(3);default:null" json:"deleted_at"`
- }
- func (m *MerchantClientAccount) TableName() string {
- return "merchant_client_account"
- }
- func (m *MerchantClientAccount) GetClientAccount() (MerchantClientAccount, error) {
- var doc MerchantClientAccount
- table := orm.ShMysql.Table(m.TableName())
- table = table.Where("client_open_id = ? ", m.ClientOpenID)
- if err := table.Select("*").First(&doc).Error; err != nil {
- return doc, err
- }
- return doc, nil
- }
- func (m *MerchantClientAccount) UpdateClientAccountStatusById(amount decimal.Decimal) error {
- var merchantClientLog MerchantClientAccountLog
- tx := orm.ShMysql.Begin()
- var err error
- defer func() {
- if err != nil {
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
- merchantClientLog.ClientOpenID = m.ClientOpenID
- merchantClientLog.Amount = amount
- merchantClientLog.TransType = 2
- return nil
- }
|