123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- package entity
- import (
- "log"
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/mongodb"
- "app.yhyue.com/moapp/jybase/mysql"
- )
- // 获取用户状态
- type UserInfoReq struct {
- Mysql *mysql.Mysql
- Mgo mongodb.MongodbSim
- UserId int64 //base_user_id 不是 mongodb的userid!
- Types string //不传取默认规则
- EntId int64
- EntUserId int64
- BaseMysql *mysql.Mysql
- }
- // 游客信息
- func (this *UserInfoReq) GetTouristInfo() (ret map[string]interface{}, msg string) {
- ret = this.touristInfo()
- if ret == nil {
- msg = "未查询到用户信息"
- return
- }
- return
- }
- // 默认规则:优先大会员、商机管理、超级订阅、免费订阅
- func (this *UserInfoReq) GetUserInfo() (ret map[string]interface{}, msg string) {
- data := this.userInfo()
- ret = map[string]interface{}{}
- if data == nil {
- return nil, "未查询到用户信息"
- }
- //获取用户权益
- vip_status := common.IntAll((*data)["i_vip_status"]) //超级订阅
- member_status := common.IntAll((*data)["i_member_status"]) //大会员
- //获取商机管理信息
- phone := common.ObjToString((*data)["s_phone"])
- if phone == "" {
- phone = common.ObjToString((*data)["s_m_phone"])
- }
- varentinfo := &EntInfo{Mysql: this.Mysql} //商机管理
- this.EntId, this.EntUserId = GetEntByPhone(this.Mysql, phone)
- entinfo := varentinfo.GetById(int(this.EntId))
- entniche_status := entinfo.Status
- //用户相关订阅设置
- object := &map[string]interface{}{}
- if this.Types == "" {
- if member_status > 0 {
- this.Types = "m"
- } else if entniche_status > 0 {
- this.Types = "e"
- } else if vip_status > 0 {
- this.Types = "v"
- } else {
- this.Types = "f"
- }
- }
- switch this.Types {
- case "m":
- //大会员
- if (*data)["o_member_jy"] != nil {
- memberJy := common.ObjToMap((*data)["o_member_jy"])
- object = this.format(memberJy)
- (*object)["starttime"] = (*data)["i_member_starttime"]
- (*object)["endtime"] = (*data)["i_member_endtime"]
- }
- case "e":
- //商机管理
- entnicheJy := this.EntnicheSub()
- log.Println("~~~", entnicheJy)
- if entnicheJy != nil {
- object = this.format(entnicheJy)
- }
- case "v":
- //超级订阅
- if (*data)["o_vipjy"] != nil {
- vipJy := common.ObjToMap((*data)["o_vipjy"])
- object = this.format(vipJy)
- (*object)["starttime"] = (*data)["l_vip_starttime"]
- (*object)["endtime"] = (*data)["l_vip_endtime"]
- }
- case "f":
- 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"]
- }
- }
- }
- //
- ret["area"] = (*object)["o_area"]
- ret["items"] = (*object)["a_items"]
- ret["matchway"] = common.If((*object)["i_matchway"] == nil, 1, (*object)["i_matchway"]) //没有则,默认1
- ret["buyerclass"] = common.If((*object)["a_buyerclass"] == nil, []string{}, (*object)["a_buyerclass"])
- ret["infotype"] = common.If((*object)["a_infotype"] == nil, []string{}, (*object)["a_infotype"])
- ret["projectmatch"] = common.If((*object)["i_projectmatch"] == nil, 0, (*object)["i_projectmatch"])
- ret["starttime"] = (*object)["starttime"]
- ret["endtime"] = (*object)["endtime"]
- ret["phone"] = phone
- ret["vipStatus"] = vip_status
- ret["memberStatus"] = member_status
- ret["entnicheStatus"] = entniche_status
- ret["subscribeType"] = this.Types
- nickname := common.ObjToString((*data)["s_nickname"])
- if nickname == "" && phone != "" && len(phone) == 11 {
- nickname = string(phone[0:3]) + "****" + string(phone[len(phone)-4:])
- }
- if nickname == "" {
- nickname = common.ObjToString((*data)["s_jyname"])
- }
- ret["nickname"] = nickname
- headimg := common.ObjToString((*data)["s_headimageurl"])
- ret["headimg"] = headimg
- if headimg == "" {
- ret["headimg"] = common.ObjToString((*data)["s_headimage"])
- }
- return ret, ""
- }
- // 获取mongodb user表相关数据
- func (this *UserInfoReq) userInfo() *map[string]interface{} {
- data, ok := this.Mgo.FindOneByField("user", map[string]interface{}{"base_user_id": this.UserId}, `{"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 data
- }
- return nil
- }
- // 格式化数据 大会员/超级订阅/商机管理 结构一致 关键词格式化
- func (this *UserInfoReq) 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
- }
- // 商机管理订阅设置
- func (this *UserInfoReq) EntnicheSub() *map[string]interface{} {
- currentUser := &CurrentUser{
- Mysql: this.Mysql,
- }
- entInfo := currentUser.EntInfo(int(this.EntId), int(this.EntUserId))
- model := entInfo.Ent.Model //1-统一订阅 2-个人订阅
- if entInfo.User_power != 1 {
- //用户暂无权限
- return nil
- }
- res := &map[string]interface{}{}
- switch model {
- case 1:
- deptId := entInfo.Dept.Id
- nodiff := false
- res_ := map[string]interface{}{} //临时map
- //我所有的父部门
- EntParentDept := map[int][]*EntDeptParent{}
- //先获取用户组织架构权益
- EntParentDept = GetEntDeptParent(this.Mysql, EntParentDept, deptId)
- EntDepts := map[int]*EntDept{}
- EntDepts = GetEntDepts(this.Mysql, EntDepts, this.EntId)
- // //用户下所有的分发规则
- EntUserRules := GetUserRules(this.Mysql, this.EntUserId)
- ///分发规则的相关设置
- EntDis := GetEntDistribute(this.Mgo, this.EntId)
- //我的上级部门
- for _, v := range EntParentDept[entInfo.Dept.Id] {
- //看我的上级部门,有没有开启订阅分发
- if EntDepts[v.Pid].Subdis == 0 {
- log.Println("暂未开启订阅设置")
- return nil
- }
- //看我的上级部门,有没有全员无差别接收
- if EntDepts[v.Pid].Nodiff == 1 {
- log.Println(EntDepts[v.Pid].Name, EntDepts[v.Pid].Id, "开启全员无差别")
- deptId = EntDepts[v.Pid].Id
- nodiff = true
- break
- }
- log.Println(len(EntUserRules[common.IntAll(this.EntUserId)]) > 0)
- //看我的上级部门,有没有给我设置分发规则
- if !nodiff && len(EntUserRules[common.IntAll(this.EntUserId)]) > 0 {
- for _, v := range EntUserRules[common.IntAll(this.EntUserId)] {
- //获取关键词组相关
- ruleData, _ := this.Mgo.FindOne("entniche_rule", map[string]interface{}{
- "i_deptid": EntDis[v.RuleId].DeptId,
- "i_entid": this.EntId,
- })
- o_entniche, _ := (*ruleData)["o_entniche"].(map[string]interface{})
- itemMap := map[string]interface{}{}
- items, _ := o_entniche["a_items"].([]interface{})
- for _, v := range items {
- item, _ := v.(map[string]interface{})
- if item == nil {
- continue
- }
- item_name, _ := item["s_item"].(string)
- if item_name == "" {
- continue
- }
- itemMap[item_name] = item
- }
- a_items := []interface{}{}
- for _, v := range EntDis[v.RuleId].Items {
- m := map[string]interface{}{
- "s_item": v,
- "a_key": (*common.ObjToMap(itemMap[v]))["a_key"],
- }
- a_items = append(a_items, m)
- }
- (res_)["a_buyerclass"] = EntDis[v.RuleId].Buyerclass
- (res_)["a_items"] = a_items
- (res_)["o_area"] = EntDis[v.RuleId].Area
- }
- }
- }
- var ok bool
- res, ok = this.Mgo.FindOne("entniche_rule", map[string]interface{}{
- "i_deptid": deptId,
- "i_entid": this.EntId,
- })
- log.Println(res_, "+++", res)
- if ok && res != nil && len(res_) > 0 {
- oenitche, ok := (*res)["o_entniche"].(map[string]interface{})
- if ok && oenitche != nil {
- oenitche["a_buyerclass"] = res_["a_buyerclass"]
- oenitche["a_items"] = res_["a_items"]
- oenitche["o_area"] = res_["o_area"]
- (*res)["o_entniche"] = oenitche
- }
- }
- case 2:
- res, _ = this.Mgo.FindOne("entniche_rule", map[string]interface{}{
- "i_userid": this.EntUserId,
- "i_entid": this.EntId,
- })
- }
- log.Println(entInfo.Ent.Name, entInfo.Ent.Id, entInfo.Ent)
- entnicheJy := common.ObjToMap((*res)["o_entniche"])
- if entnicheJy != nil && len(*entnicheJy) > 0 {
- (*entnicheJy)["starttime"] = entInfo.Ent.Startdate
- (*entnicheJy)["endtime"] = entInfo.Ent.Enddate
- (*entnicheJy)["power"] = entInfo.User_power //用户权益
- } else {
- entnicheJy = &map[string]interface{}{
- "starttime": entInfo.Ent.Startdate,
- "endtime": entInfo.Ent.Enddate,
- "power": entInfo.User_power,
- }
- }
- //获取商机管理的订阅设置
- return entnicheJy
- }
- // 游客信息查询
- func (this *UserInfoReq) touristInfo() map[string]interface{} {
- tis := this.BaseMysql.SelectBySql(`SELECT is_tourist,nickname,headimg FROM base_user WHERE id = ?`, this.UserId)
- if tis != nil && len(*tis) > 0 {
- return (*tis)[0]
- }
- return nil
- }
|