wallet.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package mysql
  2. import (
  3. orm "duoduo/database"
  4. "duoduo/tools"
  5. "github.com/shopspring/decimal"
  6. )
  7. type Wallet struct {
  8. AvailableAmount decimal.Decimal `gorm:"column:available_amount" json:"availableAmount"` //可提现金额
  9. CreateTime string `gorm:"column:create_time" json:"createTime"` //创建时间
  10. LatelyAmount decimal.Decimal `gorm:"column:lately_amount" json:"latelyAmount"` //近30日金额
  11. OpenID string `gorm:"column:open_id" json:"openId"` //openId
  12. TodayAmount decimal.Decimal `gorm:"column:today_amount" json:"todayAmount"` //今日金额
  13. TotalAmount decimal.Decimal `gorm:"column:total_amount" json:"totalAmount"` //历史总金额
  14. UpdateTime string `gorm:"column:update_time" json:"updateTime"` //更新时间
  15. WithdrawalAmount decimal.Decimal `gorm:"column:withdrawal_amount" json:"withdrawalAmount"` //已经体现总金额
  16. YesterdayAmount decimal.Decimal `gorm:"column:yesterday_amount" json:"yesterdayAmount"` //昨日收益
  17. Pid string `gorm:"column:pid" json:"pid"`
  18. }
  19. // TableName sets the insert table name for this struct type
  20. func (w *Wallet) TableName() string {
  21. return "wallet"
  22. }
  23. func (w *Wallet) Create() (Wallet, error) {
  24. var doc Wallet
  25. result := orm.Eloquent.Table(w.TableName()).Create(&w)
  26. if result.Error != nil {
  27. err := result.Error
  28. return doc, err
  29. }
  30. doc = *w
  31. return doc, nil
  32. }
  33. func (w *Wallet) Update() (update Wallet, err error) {
  34. if err := orm.Eloquent.Table(w.TableName()).Model(&update).Where("open_id = ? ", w.OpenID).Updates(
  35. map[string]interface{}{
  36. "pid": w.Pid,
  37. "update_time": tools.GetCurrntTimeStr()}).Error; err != nil {
  38. return update, err
  39. }
  40. return update, nil
  41. }
  42. func (w *Wallet) UpdateAll() (update Wallet, err error) {
  43. if err := orm.Eloquent.Table(w.TableName()).Model(&update).Where("open_id = ? ", w.OpenID).Updates(
  44. map[string]interface{}{
  45. "total_amount": w.TotalAmount,
  46. "available_amount": w.AvailableAmount,
  47. "today_amount": w.TodayAmount,
  48. "yesterday_amount": w.YesterdayAmount,
  49. "lately_amount": w.LatelyAmount,
  50. "withdrawal_amount": w.WithdrawalAmount,
  51. "update_time": tools.GetCurrntTimeStr()}).Error; err != nil {
  52. return update, err
  53. }
  54. return update, nil
  55. }