63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package dao
|
|
|
|
import (
|
|
"enterprise/common/model"
|
|
"github.com/spf13/cast"
|
|
"gorm.io/gorm"
|
|
"time"
|
|
)
|
|
|
|
type StaffPayLogDao struct {
|
|
}
|
|
|
|
func NewStaffPayLogDao() *StaffPayLogDao {
|
|
return &StaffPayLogDao{}
|
|
}
|
|
|
|
func (d *StaffPayLogDao) TableName() string {
|
|
return "staff_pay_log"
|
|
}
|
|
|
|
func (d *StaffPayLogDao) Create(o *model.StaffPayLog) (int64, error) {
|
|
o.CreateTime = time.Now().Unix()
|
|
res := GetDB().Table(d.TableName()).Create(o)
|
|
return o.Id, res.Error
|
|
}
|
|
|
|
func (d *StaffPayLogDao) GetByOutTradeNo(outTradeNo string) (*model.StaffPayLog, error) {
|
|
var u model.StaffPayLog
|
|
tx := GetDB().Table(d.TableName())
|
|
tx = tx.Where("out_trade_no = ?", outTradeNo)
|
|
res := tx.First(&u)
|
|
if res.Error == gorm.ErrRecordNotFound {
|
|
return nil, nil
|
|
}
|
|
|
|
if res.Error != nil {
|
|
return nil, res.Error
|
|
}
|
|
return &u, nil
|
|
}
|
|
|
|
func (d *StaffPayLogDao) QueryAdmin(page, size int, corpId int64, staffId string) ([]*model.StaffPayLog, int64, error) {
|
|
var u []*model.StaffPayLog
|
|
tx := GetDB().Table(d.TableName())
|
|
tx.Where("corp_id = ?", corpId)
|
|
|
|
if staffId != "" {
|
|
tx.Where("user_id = ?", cast.ToInt64(staffId))
|
|
}
|
|
|
|
var count int64
|
|
tx.Count(&count)
|
|
tx.Order("month DESC")
|
|
|
|
tx.Offset((page - 1) * size).Limit(size)
|
|
res := tx.Find(&u)
|
|
|
|
if res.Error != nil {
|
|
return nil, 0, res.Error
|
|
}
|
|
return u, count, nil
|
|
}
|