1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package mysql
- import (
- orm "duoduo/database"
- "github.com/shopspring/decimal"
- )
- type TransRecords struct {
- Amount decimal.Decimal `gorm:"column:amount" json:"amount"`
- CreateTime string `gorm:"column:create_time" json:"createTime"`
- OpenID string `gorm:"column:open_id" json:"openId"`
- TransStatus int `gorm:"column:trans_status" json:"transStatus"`
- UpdateTime string `gorm:"column:update_time" json:"updateTime"`
- }
- // TableName sets the insert table name for this struct type
- func (t *TransRecords) TableName() string {
- return "trans_records"
- }
- func (t *TransRecords) Create() (TransRecords, error) {
- var doc TransRecords
- result := orm.Eloquent.Table(t.TableName()).Create(&t)
- if result.Error != nil {
- err := result.Error
- return doc, err
- }
- doc = *t
- return doc, nil
- }
- func (t *TransRecords) GetAmount() (TransRecords, error) {
- var trans TransRecords
- //可体现金额:5求和-已体现金额
- //已体现金额:提现记录求和
- //历史总收益
- err := orm.Eloquent.Select("SUM(amount) as amount").Where("open_id = ? and trans_status = ? ", t.OpenID, t.TransStatus).Table(t.TableName()).First(&trans).Error
- if err != nil {
- return trans, err
- }
- return trans, nil
- }
|