|
@@ -58,8 +58,7 @@ func (this *UserInfoReq) GetUserInfo() (ret map[string]interface{}, msg string)
|
|
|
case "e":
|
|
|
//商机管理
|
|
|
entnicheJy := this.EntnicheSub()
|
|
|
- power := common.Int64All((*entnicheJy)["power"])
|
|
|
- if entnicheJy == nil || power != 1 {
|
|
|
+ if entnicheJy == nil {
|
|
|
entniche_status = -1
|
|
|
return nil, "未查询到用户信息"
|
|
|
}
|
|
@@ -157,6 +156,31 @@ 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{
|
|
@@ -171,21 +195,150 @@ func (this *UserInfoReq) EntnicheSub() *map[string]interface{} {
|
|
|
res := &map[string]interface{}{}
|
|
|
switch model {
|
|
|
case 1:
|
|
|
+ deptId := entInfo.Dept.Id
|
|
|
+ nodiff := false
|
|
|
+ //我所有的父部门
|
|
|
+ var 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,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ 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,
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var EntDis = map[string]*EntDistribute{} //分发规则的相关设置
|
|
|
+ var EntUserRules = map[int][]*EntRuleUser{} //用户下所有的分发规则
|
|
|
+ var res_ = map[string]interface{}{} //临时map
|
|
|
+
|
|
|
+ // 分发规则遍历 查询用户是否有被分发的规则
|
|
|
+ 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)
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //获取具体分发规则
|
|
|
+ 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] {
|
|
|
+ //看我的上级部门,有没有开启订阅分发
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
res, _ = this.Mgo.FindOne("entniche_rule", map[string]interface{}{
|
|
|
- "i_deptid": entInfo.Dept.Id,
|
|
|
+ "i_deptid": deptId,
|
|
|
"i_entid": this.EntId,
|
|
|
})
|
|
|
+ log.Println(res_, "+++")
|
|
|
+ if len(res_) > 0 {
|
|
|
+ oenitche, _ := (*res)["o_entniche"].(map[string]interface{})
|
|
|
+ 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,
|
|
|
})
|
|
|
- }
|
|
|
- if len(*res) == 0 {
|
|
|
- return nil
|
|
|
- }
|
|
|
- if (*res)["o_entniche"] == nil {
|
|
|
- return nil
|
|
|
+
|
|
|
}
|
|
|
entnicheJy := common.ObjToMap((*res)["o_entniche"])
|
|
|
(*entnicheJy)["starttime"] = entInfo.Ent.Startdate
|