dao.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package util
  2. import (
  3. "strconv"
  4. "strings"
  5. "time"
  6. "go-common/app/admin/main/feed/model/common"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/queue/databus/report"
  9. )
  10. //AddLog add action log
  11. func AddLog(id int, uname string, uid int64, oid int64, action string, obj interface{}) (err error) {
  12. report.Manager(&report.ManagerInfo{
  13. Uname: uname,
  14. UID: uid,
  15. Business: id,
  16. Type: 0,
  17. Oid: oid,
  18. Action: action,
  19. Ctime: time.Now(),
  20. // extra
  21. Index: []interface{}{},
  22. Content: map[string]interface{}{
  23. "json": obj,
  24. },
  25. })
  26. return
  27. }
  28. //AddLogs add action logs
  29. func AddLogs(logtype int, uname string, uid int64, oid int64, action string, obj interface{}) (err error) {
  30. report.Manager(&report.ManagerInfo{
  31. Uname: uname,
  32. UID: uid,
  33. Business: common.BusinessID,
  34. Type: logtype,
  35. Oid: oid,
  36. Action: action,
  37. Ctime: time.Now(),
  38. // extra
  39. Index: []interface{}{},
  40. Content: map[string]interface{}{
  41. "json": obj,
  42. },
  43. })
  44. return
  45. }
  46. //UserInfo get login userinfo
  47. func UserInfo(c *bm.Context) (uid int64, username string) {
  48. if nameInter, ok := c.Get("username"); ok {
  49. username = nameInter.(string)
  50. }
  51. if uidInter, ok := c.Get("uid"); ok {
  52. uid = uidInter.(int64)
  53. }
  54. if username == "" {
  55. cookie, _ := c.Request.Cookie("username")
  56. if cookie == nil || cookie.Value == "" {
  57. return
  58. }
  59. username = cookie.Value
  60. cookie, _ = c.Request.Cookie("uid")
  61. if cookie == nil || cookie.Value == "" {
  62. return
  63. }
  64. uidInt, _ := strconv.Atoi(cookie.Value)
  65. uid = int64(uidInt)
  66. }
  67. return
  68. }
  69. //TrimStrSpace trim string space
  70. func TrimStrSpace(v string) string {
  71. return strings.TrimSpace(v)
  72. }
  73. //CTimeStr current time string
  74. func CTimeStr() (cTime string) {
  75. return time.Unix(time.Now().Unix(), 0).Format("2006-01-02 15:04:05")
  76. }