util.go 2.0 KB

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