123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- package jy
- import (
- "app.yhyue.com/moapp/jybase/common"
- qutil "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
- "app.yhyue.com/moapp/jybase/go-xweb/log"
- "app.yhyue.com/moapp/jybase/mongodb"
- )
- func GetSubScribeInfo(session *httpsession.Session, mg mongodb.MongodbSim, types, appid string) *map[string]interface{} {
- userId := qutil.ObjToString(session.Get("userId"))
- entId := qutil.Int64All(session.Get("entId"))
- entUserId := qutil.Int64All(session.Get("entUserId"))
- positionType := qutil.Int64All(session.Get("positionType"))
- data := &map[string]interface{}{}
- if positionType == 0 {
- ok := false
- query := map[string]interface{}{
- "_id": mongodb.StringTOBsonId(userId),
- }
- 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}`)
- if !ok || data == nil || len(*data) <= 0 {
- return nil
- }
- }
- object := &map[string]interface{}{}
- jyData := &map[string]interface{}{}
- switch types {
- case MemberFlag:
- //大会员
- if positionType == 0 {
- //个人
- if (*data)["o_member_jy"] != nil {
- jyData = common.ObjToMap((*data)["o_member_jy"])
- }
- } else {
- jyData = EntnicheSub(entUserId, entId, 1, mg)
- }
- case EntnicheFlag:
- //商机管理
- jyData = EntnicheSub(entUserId, entId, 0, mg)
- log.Println("~~~", jyData)
- case SubVipFlag:
- //超级订阅
- if positionType == 0 {
- if (*data)["o_vipjy"] != nil {
- //个人
- jyData = common.ObjToMap((*data)["o_vipjy"])
- }
- } else {
- jyData = EntnicheSub(entUserId, entId, 1, mg)
- }
- case SubFreeFlag:
- if positionType == 0 {
- //个人
- if (*data)["o_jy"] != nil {
- ojy := common.ObjToMap((*data)["o_jy"])
- if (*ojy)["a_key"] != nil {
- akey := common.ObjArrToMapArr((*ojy)["a_key"].([]interface{}))
- (*object)["a_items"] = []map[string]interface{}{ //转换至和其它结构一致
- map[string]interface{}{
- "a_key": akey,
- },
- }
- }
- if (*ojy)["o_area"] == nil {
- (*object)["o_area"] = map[string]interface{}{}
- } else {
- (*object)["o_area"] = (*ojy)["o_area"]
- }
- }
- } else {
- jyData = EntnicheSub(entUserId, entId, 2, mg)
- }
- }
- if jyData != nil {
- object = format(jyData)
- }
- return object
- }
- //商机管理订阅设置
- func EntnicheSub(entUserId, entId int64, types int64, mg mongodb.MongodbSim) *map[string]interface{} {
- object := &map[string]interface{}{}
- entnicheJy := &map[string]interface{}{}
- res, _ := mg.FindOne("entniche_rule", map[string]interface{}{
- "i_userid": entUserId,
- "i_entid": entId,
- "types": types,
- })
- if types == 2 {
- if (*res)["o_entniche"] != nil {
- ojy := common.ObjToMap((*res)["o_jy"])
- object = ojy
- if (*ojy)["a_key"] != nil {
- akey := common.ObjArrToMapArr((*ojy)["a_key"].([]interface{}))
- (*object)["a_items"] = []map[string]interface{}{ //转换至和其它结构一致
- map[string]interface{}{
- "a_key": akey,
- },
- }
- }
- if (*ojy)["o_area"] == nil {
- (*object)["o_area"] = map[string]interface{}{}
- } else {
- (*object)["o_area"] = (*ojy)["o_area"]
- }
- }
- } else {
- entnicheJy = common.ObjToMap((*res)["o_entniche"])
- }
- //获取商机管理的订阅设置
- return entnicheJy
- }
- //格式化数据 大会员/超级订阅/商机管理 结构一致 关键词格式化
- func format(data *map[string]interface{}) *map[string]interface{} {
- if data == nil {
- return nil
- }
- //关键词
- if (*data)["a_items"] != nil {
- a_items := common.ObjArrToMapArr((*data)["a_items"].([]interface{}))
- for k, v := range a_items {
- if v["a_key"] != nil {
- a_keys := []map[string]interface{}{}
- ak, ok := v["a_key"].([]interface{})
- if !ok {
- a_keys, _ = v["a_key"].([]map[string]interface{})
- } else {
- a_keys = common.ObjArrToMapArr(ak)
- }
- for kk, vv := range a_keys {
- if vv["key"] != nil {
- keyArr, ok1 := vv["key"].([]interface{})
- if ok1 {
- if vv["appendkey"] != nil {
- appendkeyArr, ok2 := vv["appendkey"].([]interface{})
- if ok2 {
- key := common.ObjArrToStringArr(keyArr)
- appendkey := common.ObjArrToStringArr(appendkeyArr)
- a_keys[kk]["key"] = append(key, appendkey...)
- }
- }
- }
- }
- delete(a_keys[kk], "appendkey")
- }
- a_items[k]["a_key"] = a_keys
- }
- }
- (*data)["a_items"] = a_items
- }
- return data
- }
|