trans_records.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package mysql
  2. import (
  3. orm "duoduo/database"
  4. "github.com/shopspring/decimal"
  5. )
  6. type TransRecords struct {
  7. Amount decimal.Decimal `gorm:"column:amount" json:"amount"`
  8. CreateTime string `gorm:"column:create_time" json:"createTime"`
  9. OpenID string `gorm:"column:open_id" json:"openId"`
  10. TransStatus int `gorm:"column:trans_status" json:"transStatus"`
  11. UpdateTime string `gorm:"column:update_time" json:"updateTime"`
  12. }
  13. // TableName sets the insert table name for this struct type
  14. func (t *TransRecords) TableName() string {
  15. return "trans_records"
  16. }
  17. func (t *TransRecords) Create() (TransRecords, error) {
  18. var doc TransRecords
  19. result := orm.Eloquent.Table(t.TableName()).Create(&t)
  20. if result.Error != nil {
  21. err := result.Error
  22. return doc, err
  23. }
  24. doc = *t
  25. return doc, nil
  26. }
  27. func (t *TransRecords) GetAmount() (TransRecords, error) {
  28. var trans TransRecords
  29. //可体现金额:5求和-已体现金额
  30. //已体现金额:提现记录求和
  31. //历史总收益
  32. err := orm.Eloquent.Select("SUM(amount) as amount").Where("open_id = ? and trans_status = ? ", t.OpenID, t.TransStatus).Table(t.TableName()).First(&trans).Error
  33. if err != nil {
  34. return trans, err
  35. }
  36. return trans, nil
  37. }