浏览代码

feat:用户信息api返回值调整

zhangxinlei1996 3 年之前
父节点
当前提交
1870dbb5bf
共有 3 个文件被更改,包括 140 次插入92 次删除
  1. 15 1
      api/internal/logic/getuserinfologic.go
  2. 116 0
      entity/ent.go
  3. 9 91
      entity/subscribe.go

+ 15 - 1
api/internal/logic/getuserinfologic.go

@@ -43,6 +43,20 @@ func (l *GetUserInfoLogic) GetUserInfo(req *types.UserReq) (resp *types.Resp, er
 		resp.Error_code = -1
 		l.Error(fmt.Sprintf("%+v", req), res.ErrorMsg)
 	}
-	resp.Data = res.Data
+	data := map[string]interface{}{
+		"start_time":      res.Data.StartTime,
+		"end_time":        res.Data.EndTime,
+		"area":            res.Data.Area,
+		"matchway":        res.Data.Matchway,
+		"items":           res.Data.Items,
+		"projectmatch":    res.Data.Projectmatch,
+		"infotype":        res.Data.Infotype,
+		"types":           res.SubscribeType, //订阅设置类型 f:免费订阅 v:超级订阅 m:大会员订阅 e:商机管理订阅
+		"vip_status":      res.VipStatus,
+		"member_status":   res.MemberStatus,
+		"entniche_status": res.EntnicheStatus,
+		"phone":           res.Phone,
+	}
+	resp.Data = data
 	return
 }

+ 116 - 0
entity/ent.go

@@ -10,6 +10,7 @@ import (
 	"time"
 
 	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/mysql"
 	resourcepb "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/resource"
@@ -735,3 +736,118 @@ func (e *EntInfo) GetById(id int) *EntInfo {
 	}
 	return entInfo
 }
+
+type EntDeptParent struct {
+	Id  int
+	Pid int
+}
+type EntDept struct {
+	Id     int
+	Pid    int
+	Name   string
+	Nodiff int
+	Subdis int
+}
+
+type EntDistribute struct {
+	Id         string
+	DeptId     int
+	Area       map[string]interface{}
+	Buyerclass []interface{}
+	Items      []string
+}
+
+type EntRuleUser struct {
+	UserId int
+	RuleId string
+}
+
+//查找父级部门(跨级)
+func GetEntDeptParent(mysq *mysql.Mysql, entParentDept map[int][]*EntDeptParent, deptid int) map[int][]*EntDeptParent {
+
+	//先获取用户组织架构权益
+	//查找父级部门(跨级)
+	list := mysq.SelectBySql(`select id,pid from entniche_department_parent where id =?`, deptid)
+	for _, v := range *list {
+		id := common.IntAll(v["id"])
+		pid := common.IntAll(v["pid"])
+		entParentDept[id] = append(entParentDept[id], &EntDeptParent{
+			Id:  id,
+			Pid: pid,
+		})
+	}
+	return entParentDept
+}
+
+//查看部门相关设置
+func GetEntDepts(mysq *mysql.Mysql, entDepts map[int]*EntDept, entid int64) map[int]*EntDept {
+
+	//查看部门相关设置
+	lis := mysq.SelectBySql(`select * from entniche_department where ent_id=?`, entid)
+	for _, v := range *lis {
+		//获取部门相关
+		deptid := common.IntAll(v["id"])
+		pid := common.IntAll(v["pid"])
+		name := common.ObjToString(v["name"])
+		subdis := common.IntAll(v["subdis"])
+		nodiff := common.IntAll(v["nodiff"])
+		entDepts[deptid] = &EntDept{
+			Id:     deptid,
+			Pid:    pid,
+			Name:   name,
+			Nodiff: nodiff,
+			Subdis: subdis,
+		}
+	}
+	return entDepts
+}
+
+//获取某个用户的所有分发规则
+func GetUserRules(mysq *mysql.Mysql, entUserId int64) map[int][]*EntRuleUser {
+	entUserRules := map[int][]*EntRuleUser{} //用户下所有的分发规则
+	// 分发规则遍历  查询用户是否有被分发的规则
+	data := mysq.SelectBySql(`SELECT * FROM entniche_user_rule WHERE  user_id=?`, entUserId)
+	if data != nil {
+		for _, v := range *data {
+			ruleId := common.ObjToString(v["rule_id"])
+			userId := common.IntAll(v["user_id"])
+			entRuleUser := &EntRuleUser{
+				UserId: userId,
+				RuleId: ruleId,
+			}
+			entUserRules[userId] = append(entUserRules[userId], entRuleUser)
+
+		}
+	}
+
+	return entUserRules
+}
+
+//获取企业下的所有分发规则详情
+func GetEntDistribute(mgo mongodb.MongodbSim, entId int64) map[string]*EntDistribute {
+
+	entDis := map[string]*EntDistribute{} //分发规则的相关设置
+
+	//获取具体分发规则
+	disData, ok := mgo.Find("entniche_distribute", map[string]interface{}{
+		"i_status": map[string]interface{}{"$ne": 1},
+		"i_entid":  entId,
+	}, nil, nil, false, -1, -1)
+	if ok && disData != nil && len(*disData) > 0 {
+		for _, v := range *disData {
+			deptId := common.IntAll(v["i_deptid"])
+			a_items, _ := v["a_items"].([]interface{})
+			o_area, _ := v["o_area"].(map[string]interface{})
+			a_buyerclass, _ := v["a_buyerclass"].([]interface{})
+			ruleId := mongodb.BsonIdToSId(v["_id"])
+			entDis[ruleId] = &EntDistribute{
+				Id:         ruleId,
+				DeptId:     deptId,
+				Area:       o_area,
+				Buyerclass: a_buyerclass,
+				Items:      common.ObjArrToStringArr(a_items),
+			}
+		}
+	}
+	return entDis
+}

+ 9 - 91
entity/subscribe.go

@@ -156,31 +156,6 @@ func (this *UserInfoReq) format(data *map[string]interface{}) *map[string]interf
 	return data
 }
 
-type EntDeptParent struct {
-	Id  int
-	Pid int
-}
-type EntDept struct {
-	Id     int
-	Pid    int
-	Name   string
-	Nodiff int
-	Subdis int
-}
-
-type EntDistribute struct {
-	Id         string
-	DeptId     int
-	Area       map[string]interface{}
-	Buyerclass []interface{}
-	Items      []string
-}
-
-type EntRuleUser struct {
-	UserId int
-	RuleId string
-}
-
 //商机管理订阅设置
 func (this *UserInfoReq) EntnicheSub() *map[string]interface{} {
 	currentUser := &CurrentUser{
@@ -197,79 +172,22 @@ func (this *UserInfoReq) EntnicheSub() *map[string]interface{} {
 	case 1:
 		deptId := entInfo.Dept.Id
 		nodiff := false
+		res_ := map[string]interface{}{} //临时map
 		//我所有的父部门
-		var EntParentDept = map[int][]*EntDeptParent{}
+		EntParentDept := map[int][]*EntDeptParent{}
 
 		//先获取用户组织架构权益
-		//查找父级部门(跨级)
-		list := this.Mysql.SelectBySql(`select id,pid from entniche_department_parent where id =?`, entInfo.Dept.Id)
-		log.Println(list, entInfo.Dept.Id, entInfo.Dept.Name)
-		for _, v := range *list {
-			id := common.IntAll(v["id"])
-			pid := common.IntAll(v["pid"])
-			EntParentDept[id] = append(EntParentDept[id], &EntDeptParent{
-				Id:  id,
-				Pid: pid,
-			})
-		}
+		EntParentDept = GetEntDeptParent(this.Mysql, EntParentDept, deptId)
+
 		EntDepts := map[int]*EntDept{}
-		//查看部门相关设置
-		lis := this.Mysql.SelectBySql(`select * from entniche_department where ent_id=?`, this.EntId)
-		for _, v := range *lis {
-			//获取部门相关
-			deptid := common.IntAll(v["id"])
-			pid := common.IntAll(v["pid"])
-			name := common.ObjToString(v["name"])
-			subdis := common.IntAll(v["subdis"])
-			nodiff := common.IntAll(v["nodiff"])
-			EntDepts[deptid] = &EntDept{
-				Id:     deptid,
-				Pid:    pid,
-				Name:   name,
-				Nodiff: nodiff,
-				Subdis: subdis,
-			}
-		}
+		EntDepts = GetEntDepts(this.Mysql, EntDepts, this.EntId)
 
-		var EntDis = map[string]*EntDistribute{}    //分发规则的相关设置
-		var EntUserRules = map[int][]*EntRuleUser{} //用户下所有的分发规则
-		var res_ = map[string]interface{}{}         //临时map
+		// //用户下所有的分发规则
+		EntUserRules := GetUserRules(this.Mysql, this.EntUserId)
 
-		// 分发规则遍历  查询用户是否有被分发的规则
-		data := this.Mysql.SelectBySql(`SELECT * FROM entniche_user_rule WHERE  user_id=?`, this.EntUserId)
-		if data != nil {
-			for _, v := range *data {
-				ruleId := common.ObjToString(v["rule_id"])
-				userId := common.IntAll(v["user_id"])
-				entRuleUser := &EntRuleUser{
-					UserId: userId,
-					RuleId: ruleId,
-				}
-				EntUserRules[userId] = append(EntUserRules[userId], entRuleUser)
+		///分发规则的相关设置
+		EntDis := GetEntDistribute(this.Mgo, this.EntId)
 
-			}
-		}
-		//获取具体分发规则
-		disData, ok := this.Mgo.Find("entniche_distribute", map[string]interface{}{
-			"i_status": map[string]interface{}{"$ne": 1},
-			"i_entid":  this.EntId,
-		}, nil, nil, false, -1, -1)
-		if ok && disData != nil && len(*disData) > 0 {
-			for _, v := range *disData {
-				deptId := common.IntAll(v["i_deptid"])
-				a_items, _ := v["a_items"].([]interface{})
-				o_area, _ := v["o_area"].(map[string]interface{})
-				a_buyerclass, _ := v["a_buyerclass"].([]interface{})
-				ruleId := mongodb.BsonIdToSId(v["_id"])
-				EntDis[ruleId] = &EntDistribute{
-					Id:         ruleId,
-					DeptId:     deptId,
-					Area:       o_area,
-					Buyerclass: a_buyerclass,
-					Items:      common.ObjArrToStringArr(a_items),
-				}
-			}
-		}
 		//我的上级部门
 		for _, v := range EntParentDept[entInfo.Dept.Id] {
 			//看我的上级部门,有没有开启订阅分发