util.go 2.1 KB

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