member_log.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/job/main/member/model"
  5. "go-common/library/log"
  6. "go-common/library/queue/databus/report"
  7. "go-common/library/time"
  8. )
  9. // consts
  10. const (
  11. ExpLogID = 11
  12. MoralLogID = 12
  13. )
  14. // AddExpLog is
  15. func (d *Dao) AddExpLog(ctx context.Context, ul *model.UserLog) {
  16. d.addLog(ctx, ExpLogID, "log_exp_change", ul)
  17. }
  18. // AddMoralLog is
  19. func (d *Dao) AddMoralLog(ctx context.Context, ul *model.UserLog) {
  20. d.addLog(ctx, MoralLogID, "log_moral_change", ul)
  21. }
  22. // AddExpLog is
  23. func (d *Dao) addLog(ctx context.Context, business int, action string, ul *model.UserLog) {
  24. t := time.Time(ul.TS)
  25. content := make(map[string]interface{}, len(ul.Content))
  26. for k, v := range ul.Content {
  27. content[k] = v
  28. }
  29. if ul.LogID == "" {
  30. ul.LogID = model.UUID4()
  31. }
  32. content["log_id"] = ul.LogID
  33. ui := &report.UserInfo{
  34. Mid: ul.Mid,
  35. Platform: "",
  36. Build: 0,
  37. Buvid: "",
  38. Business: business,
  39. Type: 0,
  40. Oid: 0,
  41. Action: action,
  42. Ctime: t.Time(),
  43. IP: ul.IP,
  44. // extra
  45. Index: []interface{}{ul.LogID},
  46. Content: content,
  47. }
  48. report.User(ui)
  49. log.Info("add log to report: userlog: %+v userinfo: %+v", ul, ui)
  50. }