subScribe.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package jy
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. qutil "app.yhyue.com/moapp/jybase/common"
  5. "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
  6. "app.yhyue.com/moapp/jybase/go-xweb/log"
  7. "app.yhyue.com/moapp/jybase/mongodb"
  8. )
  9. func GetSubScribeInfo(session *httpsession.Session, mg mongodb.MongodbSim, types, appid string) *map[string]interface{} {
  10. userId := qutil.ObjToString(session.Get("userId"))
  11. entId := qutil.Int64All(session.Get("entId"))
  12. entUserId := qutil.Int64All(session.Get("entUserId"))
  13. positionType := qutil.Int64All(session.Get("positionType"))
  14. data := &map[string]interface{}{}
  15. if positionType == 0 {
  16. ok := false
  17. query := map[string]interface{}{
  18. "_id": mongodb.StringTOBsonId(userId),
  19. }
  20. data, ok = mg.FindOneByField("user", query, `{"i_vip_status":1,"l_vip_starttime":1,"l_vip_endtime":1,"i_member_status":1,"i_member_starttime":1,"i_member_endtime":1,"o_jy":1,"o_vipjy":1,"o_member_jy":1,"s_phone":1,"s_m_phone":1,"s_nickname":1,"s_jyname":1,"s_headimageurl":1,"s_headimage":1}`)
  21. if !ok || data == nil || len(*data) <= 0 {
  22. return nil
  23. }
  24. }
  25. object := &map[string]interface{}{}
  26. jyData := &map[string]interface{}{}
  27. switch types {
  28. case MemberFlag:
  29. //大会员
  30. if positionType == 0 {
  31. //个人
  32. if (*data)["o_member_jy"] != nil {
  33. jyData = common.ObjToMap((*data)["o_member_jy"])
  34. }
  35. } else {
  36. jyData = EntnicheSub(entUserId, entId, 1, mg)
  37. }
  38. case EntnicheFlag:
  39. //商机管理
  40. jyData = EntnicheSub(entUserId, entId, 0, mg)
  41. log.Println("~~~", jyData)
  42. case SubVipFlag:
  43. //超级订阅
  44. if positionType == 0 {
  45. if (*data)["o_vipjy"] != nil {
  46. //个人
  47. jyData = common.ObjToMap((*data)["o_vipjy"])
  48. }
  49. } else {
  50. jyData = EntnicheSub(entUserId, entId, 1, mg)
  51. }
  52. case SubFreeFlag:
  53. if positionType == 0 {
  54. //个人
  55. if (*data)["o_jy"] != nil {
  56. ojy := common.ObjToMap((*data)["o_jy"])
  57. if (*ojy)["a_key"] != nil {
  58. akey := common.ObjArrToMapArr((*ojy)["a_key"].([]interface{}))
  59. (*object)["a_items"] = []map[string]interface{}{ //转换至和其它结构一致
  60. map[string]interface{}{
  61. "a_key": akey,
  62. },
  63. }
  64. }
  65. if (*ojy)["o_area"] == nil {
  66. (*object)["o_area"] = map[string]interface{}{}
  67. } else {
  68. (*object)["o_area"] = (*ojy)["o_area"]
  69. }
  70. }
  71. } else {
  72. jyData = EntnicheSub(entUserId, entId, 2, mg)
  73. }
  74. }
  75. if jyData != nil {
  76. object = format(jyData)
  77. }
  78. return object
  79. }
  80. //商机管理订阅设置
  81. func EntnicheSub(entUserId, entId int64, types int64, mg mongodb.MongodbSim) *map[string]interface{} {
  82. object := &map[string]interface{}{}
  83. entnicheJy := &map[string]interface{}{}
  84. res, _ := mg.FindOne("entniche_rule", map[string]interface{}{
  85. "i_userid": entUserId,
  86. "i_entid": entId,
  87. "types": types,
  88. })
  89. if types == 2 {
  90. if (*res)["o_entniche"] != nil {
  91. ojy := common.ObjToMap((*res)["o_jy"])
  92. object = ojy
  93. if (*ojy)["a_key"] != nil {
  94. akey := common.ObjArrToMapArr((*ojy)["a_key"].([]interface{}))
  95. (*object)["a_items"] = []map[string]interface{}{ //转换至和其它结构一致
  96. map[string]interface{}{
  97. "a_key": akey,
  98. },
  99. }
  100. }
  101. if (*ojy)["o_area"] == nil {
  102. (*object)["o_area"] = map[string]interface{}{}
  103. } else {
  104. (*object)["o_area"] = (*ojy)["o_area"]
  105. }
  106. }
  107. } else {
  108. entnicheJy = common.ObjToMap((*res)["o_entniche"])
  109. }
  110. //获取商机管理的订阅设置
  111. return entnicheJy
  112. }
  113. //格式化数据 大会员/超级订阅/商机管理 结构一致 关键词格式化
  114. func format(data *map[string]interface{}) *map[string]interface{} {
  115. if data == nil {
  116. return nil
  117. }
  118. //关键词
  119. if (*data)["a_items"] != nil {
  120. a_items := common.ObjArrToMapArr((*data)["a_items"].([]interface{}))
  121. for k, v := range a_items {
  122. if v["a_key"] != nil {
  123. a_keys := []map[string]interface{}{}
  124. ak, ok := v["a_key"].([]interface{})
  125. if !ok {
  126. a_keys, _ = v["a_key"].([]map[string]interface{})
  127. } else {
  128. a_keys = common.ObjArrToMapArr(ak)
  129. }
  130. for kk, vv := range a_keys {
  131. if vv["key"] != nil {
  132. keyArr, ok1 := vv["key"].([]interface{})
  133. if ok1 {
  134. if vv["appendkey"] != nil {
  135. appendkeyArr, ok2 := vv["appendkey"].([]interface{})
  136. if ok2 {
  137. key := common.ObjArrToStringArr(keyArr)
  138. appendkey := common.ObjArrToStringArr(appendkeyArr)
  139. a_keys[kk]["key"] = append(key, appendkey...)
  140. }
  141. }
  142. }
  143. }
  144. delete(a_keys[kk], "appendkey")
  145. }
  146. a_items[k]["a_key"] = a_keys
  147. }
  148. }
  149. (*data)["a_items"] = a_items
  150. }
  151. return data
  152. }