loginLog.go 999 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package service
  2. import (
  3. "Gwen/global"
  4. "Gwen/model"
  5. "gorm.io/gorm"
  6. )
  7. type LoginLogService struct {
  8. }
  9. // InfoById 根据用户id取用户信息
  10. func (us *LoginLogService) InfoById(id uint) *model.LoginLog {
  11. u := &model.LoginLog{}
  12. global.DB.Where("id = ?", id).First(u)
  13. return u
  14. }
  15. func (us *LoginLogService) List(page, pageSize uint, where func(tx *gorm.DB)) (res *model.LoginLogList) {
  16. res = &model.LoginLogList{}
  17. res.Page = int64(page)
  18. res.PageSize = int64(pageSize)
  19. tx := global.DB.Model(&model.LoginLog{})
  20. if where != nil {
  21. where(tx)
  22. }
  23. tx.Count(&res.Total)
  24. tx.Scopes(Paginate(page, pageSize))
  25. tx.Find(&res.LoginLogs)
  26. return
  27. }
  28. // Create 创建
  29. func (us *LoginLogService) Create(u *model.LoginLog) error {
  30. res := global.DB.Create(u).Error
  31. return res
  32. }
  33. func (us *LoginLogService) Delete(u *model.LoginLog) error {
  34. return global.DB.Delete(u).Error
  35. }
  36. // Update 更新
  37. func (us *LoginLogService) Update(u *model.LoginLog) error {
  38. return global.DB.Model(u).Updates(u).Error
  39. }