logger.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package models
  2. type LoginLog struct {
  3. UserId string `json:"user_id"`
  4. LoginType int `json:"login_type"`
  5. LoginIP string `json:"login_ip"`
  6. Address string `json:"address"`
  7. Latitude float64 `json:"latitude"`
  8. Longitude float64 `json:"longitude"`
  9. }
  10. type TaskLog struct {
  11. TaskID int64 `json:"task_id"`
  12. TaskType int `json:"task_type"`
  13. UserId string `json:"user_id"`
  14. }
  15. type CustomerTmp struct {
  16. SourceType int `json:"source_type"`
  17. SourceID string `json:"source_id"`
  18. Extend string `json:"extend"`
  19. TotalPoint int64 `json:"total_point"`
  20. }
  21. /**
  22. 保存登录日志
  23. */
  24. /*
  25. func (log *LoginLog) Save(db *gorm.DB) error {
  26. // 先校验今天是否已经记录了登录日志
  27. var (
  28. sql string
  29. count int
  30. )
  31. sql = "SELECT COUNT(login_id) as count FROM user_login_log WHERE user_id = ? AND UNIX_TIMESTAMP(CAST(login_time AS DATE)) = UNIX_TIMESTAMP(CAST(SYSDATE() AS DATE))"
  32. db.Raw(sql, log.UserId).Count(&count)
  33. if count > 0 {
  34. return nil
  35. }
  36. sql = `INSERT INTO user_login_log(user_id, login_ip, address, login_type, latitude, longitude) VALUES(?,?,?,?,?,?)`
  37. err := db.Exec(sql, log.UserId, log.LoginIP, log.Address, log.LoginType, log.Latitude, log.Longitude).Error
  38. return err
  39. }
  40. */