util.go 1.9 KB

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