package dao import ( "enterprise/common/model" "github.com/spf13/cast" "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) 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 }