package model import "gorm.io/gorm" type PaymentInfoOp struct { db *gorm.DB } func NewPaymentInfoOp() *PaymentInfoOp { return &PaymentInfoOp{ db: payDB, } } func (op *PaymentInfoOp) Count() (count int64, err error) { err = op.db.Raw("SELECT COUNT(pid) FROM t_payment").Scan(&count).Error return count, err } // GetUserPayPrice 获取用户总支付金额 func (op *PaymentInfoOp) GetUserPayPrice(uid int64) (price int64, err error) { var totalPrice int64 err = op.db.Raw("SELECT COALESCE(SUM(p.price), 0) AS total_price FROM t_payment as p WHERE uid = ?", uid).Scan(&totalPrice).Error return totalPrice, err }