Files

51 lines
1.4 KiB
Go
Raw Normal View History

2021-12-29 12:03:34 +08:00
package model
import (
"SciencesServer/app/common/model"
"SciencesServer/serve/orm"
2021-12-29 16:12:25 +08:00
"fmt"
2021-12-29 12:03:34 +08:00
)
// UserWithdrawal 用户提现模型
type UserWithdrawal struct {
*model.UserWithdrawal
}
2021-12-29 16:12:25 +08:00
type UserWithdrawalInfo struct {
*model.UserWithdrawal
BankCard string `json:"bank_card"`
}
2021-12-29 12:03:34 +08:00
// Withdrawal 提现记录
2021-12-29 16:12:25 +08:00
func (m *UserWithdrawal) Withdrawal(page, pageSize int, count *int64, amount, actualAmount *float64, where ...*model.ModelWhere) ([]*UserWithdrawalInfo, error) {
db := orm.GetDB().Table(m.TableName()+" AS w").
Select("w.*", "b.bank_card").
Joins(fmt.Sprintf("LEFT JOIN %s AS b ON w.bank_id = b.id", model.NewUserBank().TableName())).
Where("w.is_deleted = ?", model.DeleteStatusForNot)
2021-12-29 12:03:34 +08:00
if len(where) > 0 {
for _, v := range where {
db = db.Where(v.Condition, v.Value)
}
}
2021-12-29 16:12:25 +08:00
out := make([]*UserWithdrawalInfo, 0)
2021-12-29 12:03:34 +08:00
if err := db.Count(count).Error; err != nil {
return nil, err
}
2021-12-29 16:12:25 +08:00
if err := db.Pluck("SUM(w.amount) AS amount", amount).Error; err != nil {
2021-12-29 12:03:34 +08:00
return nil, err
}
2021-12-29 16:12:25 +08:00
if err := db.Pluck("SUM(w.actual_amount) AS actual_amount", actualAmount).Error; err != nil {
2021-12-29 12:03:34 +08:00
return nil, err
}
2021-12-29 16:12:25 +08:00
if err := db.Order("w.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
2021-12-29 12:03:34 +08:00
return nil, err
}
return out, nil
}
func NewUserWithdrawal() *UserWithdrawal {
return &UserWithdrawal{model.NewUserWithdrawal()}
}