getBindPhoneUser.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package public
  2. import (
  3. "doFreeClueSign/db"
  4. "github.com/gogf/gf/v2/frame/g"
  5. "github.com/gogf/gf/v2/util/gconv"
  6. "time"
  7. )
  8. type BindMsg struct {
  9. MgoUserID string
  10. TimeStamp int64 //绑定手机号时间
  11. Phone string
  12. }
  13. // GetBidPhoneUser 获取绑定手机号
  14. func GetBidPhoneUser(st, ed time.Time) (rData []*BindMsg) {
  15. sess := db.MG.DB("log").GetMgoConn()
  16. if sess != nil {
  17. defer db.MG.DB("log").DestoryMongoConn(sess)
  18. }
  19. it := sess.DB("qfw").C("nsq_logs").Find(g.Map{"body.e_body.types": "bindPhone", "createtime": g.Map{"$gte": st.Unix(), "$lt": ed.Unix()}}).
  20. Select(g.Map{"body.e_userid": 1, "createtime": 1}).Iter()
  21. for _temp := make(map[string]interface{}); it.Next(&_temp); {
  22. var (
  23. userId = gconv.String(gconv.Map(_temp["body"])["e_userid"])
  24. timeStamp = gconv.Int64(_temp["createtime"])
  25. )
  26. if userId == "" {
  27. continue
  28. }
  29. phone := getPhoneByUserId(userId)
  30. rData = append(rData, &BindMsg{
  31. MgoUserID: userId,
  32. TimeStamp: timeStamp,
  33. Phone: phone,
  34. })
  35. _temp = make(map[string]interface{})
  36. }
  37. return
  38. }
  39. func getPhoneByUserId(userId string) (phone string) {
  40. res, _ := db.MG.DB().FindById("user", userId, `{"s_phone":1,"s_m_phone":1}`)
  41. if res == nil || len(*res) == 0 {
  42. return
  43. }
  44. if phone = gconv.String((*res)["s_phone"]); phone != "" {
  45. return
  46. }
  47. if phone = gconv.String((*res)["s_m_phone"]); phone != "" {
  48. return
  49. }
  50. return
  51. }