user.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package award
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/message/db"
  5. "strings"
  6. "time"
  7. )
  8. //用户redis缓存
  9. type UserBaseMsg struct {
  10. Status int `json:"status"` //大会员状态
  11. VipStatus int `json:"vip_status"` //超级订阅状态
  12. EntnicheStatus int `json:"entniche_status"` //商机管理状态
  13. Registedate int64 `json:"registedate"` //用户注册时间
  14. EntIsNew bool `json:"entIsNew"` //是否是新版商机管理用户
  15. }
  16. // GetUserInfo 查看 22年活动 用户是否满足条件
  17. func GetUserInfo(userId string) *UserBaseMsg {
  18. userPower := UserBaseMsg{}
  19. if userId == "" {
  20. return &userPower
  21. }
  22. user, ok := db.Mgo.FindById("user", userId, `{"i_member_status":1,"l_registedate":1,"i_vip_status":1,"s_phone":1,"s_m_phone":1}`)
  23. if ok && user != nil && len(*user) > 0 {
  24. userPower.Status = common.IntAllDef((*user)["i_member_status"], 0)
  25. userPower.VipStatus = common.IntAllDef((*user)["i_vip_status"], 0)
  26. userPower.Registedate = common.Int64All((*user)["l_registedate"])
  27. phone, _ := common.If((*user)["s_phone"] != nil, (*user)["s_phone"], (*user)["s_m_phone"]).(string)
  28. if phone != "" {
  29. res := db.Mysql.SelectBySql(`SELECT i.isNew,i.name,i.phone,i.status,i.auth_status,u.power FROM entniche_user u LEFT JOIN entniche_info i
  30. ON u.ent_id=i.id
  31. WHERE u.phone=?
  32. ORDER BY i.status DESC,i.auth_status DESC, CASE WHEN i.phone=? THEN 0 ELSE 1 END ASC`, phone, phone)
  33. if res != nil && len(*res) > 0 {
  34. //已购买企业未过期-商机管理用户
  35. for _, v := range *res {
  36. if common.IntAll(v["status"]) == 1 && common.IntAll(v["power"]) == 1 {
  37. userPower.EntnicheStatus = 1
  38. if common.IntAll(v["isNew"]) == 1 {
  39. userPower.EntIsNew = true
  40. break
  41. }
  42. }
  43. }
  44. }
  45. }
  46. }
  47. return &userPower
  48. }
  49. // SaveQuestionnaire 保存问卷
  50. func SaveQuestionnaire(userId, phone, answers string) bool {
  51. id := db.Mgo.Save("double_eleven_22_q", map[string]interface{}{
  52. "l_create": time.Now().Unix(),
  53. "s_userid": userId,
  54. "s_phone": phone,
  55. "s_answers": strings.Split(answers, ","),
  56. })
  57. return id != ""
  58. }
  59. // GetWinnerInfo 查询活动期间内的中奖名单信息
  60. func GetWinnerInfo(startTime, endTime string) (rs []map[string]interface{}) {
  61. winnerInfo := db.Mysql.SelectBySql(`SELECT phone,winnerdate,mold FROM winner_info_22_10 WHERE winnerdate>=? and winnerdate<?`, startTime, endTime)
  62. if winnerInfo != nil && len(*winnerInfo) > 0 {
  63. for i := 0; i < len(*winnerInfo); i++ {
  64. data := (*winnerInfo)[i]
  65. phone := common.ObjToString(data["phone"])
  66. winnerDate := common.ObjToString(data["winnerdate"])
  67. if phone != "" && len([]rune(phone)) == 11 {
  68. data["phone"] = string(phone[0:3]) + "****" + string(phone[(len(phone)-4):])
  69. }
  70. switch common.ObjToString(data["mold"]) {
  71. case "1":
  72. data["mold"] = "获得小米智能音箱"
  73. case "2":
  74. data["mold"] = "获得iPad1台"
  75. case "3":
  76. data["mold"] = "免单"
  77. }
  78. if winnerDate != "" {
  79. data["winnerdate"] = string(winnerDate[0:10])
  80. }
  81. rs = append(rs, data)
  82. }
  83. }
  84. return rs
  85. }