util.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package util
  2. import (
  3. MC "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/encrypt"
  5. "app.yhyue.com/moapp/jybase/mongodb"
  6. "app.yhyue.com/moapp/jybase/mysql"
  7. )
  8. const (
  9. USER = "user"
  10. ENTUSER = "ent_user"
  11. SUBSCRIBE = "jy_subscribe"
  12. )
  13. var ServiceMap = map[string]string{
  14. "app": "85",
  15. "pc": "84",
  16. "wx": "86",
  17. }
  18. var TimeMap = map[int][]string{
  19. 1: []string{},
  20. 2: []string{"09:00", "14:00"},
  21. 3: []string{"09:00"},
  22. 4: []string{"09:00"},
  23. }
  24. // 加密
  25. func EncodeId(sid string) string {
  26. if sid == "" {
  27. return ""
  28. }
  29. return encrypt.EncodeArticleId2ByCheck(sid)
  30. }
  31. // 解密
  32. func DecodeId(eid string) string {
  33. if eid == "" {
  34. return ""
  35. }
  36. return encrypt.DecodeArticleId2ByCheck(eid)[0]
  37. }
  38. //是否是付费用户
  39. type VipState struct {
  40. VipState int64 //超级订阅状态(1普通 2升级版)
  41. BigMember int64 //大会员状态
  42. EntMember int64 //商机管理用户状态
  43. registerData int64 //注册时间
  44. }
  45. func GetVipState(mysql *mysql.Mysql, mg mongodb.MongodbSim, userId string) (vs *VipState) {
  46. vs = &VipState{}
  47. if userId == "" {
  48. return
  49. }
  50. phone := ""
  51. data, ok := mg.FindById("user", userId, `"i_member_status":1,"i_vip_status":1,"s_m_phone":1,"s_phone":1,"o_vipjy":1,"l_registedate":1`)
  52. if data != nil && len(*data) > 0 && ok {
  53. i_vip_status := MC.Int64All((*data)["i_vip_status"])
  54. if i_vip_status > 1 {
  55. vs.VipState = 1
  56. ovipjy, _ := (*data)["o_vipjy"].(map[string]interface{})
  57. if ovipjy["o_buyset"] != nil {
  58. o_buyset := ovipjy["o_buyset"].(map[string]interface{})
  59. if o_buyset["upgrade"] != nil {
  60. vs.VipState = 2
  61. }
  62. }
  63. }
  64. if i_member_status := MC.Int64All((*data)["i_member_status"]); i_member_status > 0 {
  65. vs.BigMember = i_member_status
  66. }
  67. if s_phone, _ := (*data)["s_phone"].(string); s_phone != "" {
  68. phone = s_phone
  69. } else if s_m_phone, _ := (*data)["s_m_phone"].(string); s_m_phone != "" {
  70. phone = s_m_phone
  71. }
  72. if phone != "" {
  73. if mysql.CountBySql(`select count(1) from entniche_user where phone = ? and power =1`, phone) > 0 {
  74. vs.EntMember = 1
  75. }
  76. }
  77. vs.registerData, _ = ((*data)["l_registedate"]).(int64)
  78. }
  79. return
  80. }
  81. //是否是付费账户
  82. func (vs *VipState) IsPayedUser() bool {
  83. return vs.VipState > 0 || vs.BigMember > 0 || vs.EntMember > 0
  84. }