infoService.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package service
  2. import (
  3. "encoding/base64"
  4. "encoding/json"
  5. "strings"
  6. "app.yhyue.com/moapp/jybase/common"
  7. "app.yhyue.com/moapp/jybase/redis"
  8. "bp.jydev.jianyu360.cn/BaseService/biService/entity"
  9. "github.com/gogf/gf/v2/util/gconv"
  10. "github.com/tjfoc/gmsm/sm4"
  11. )
  12. type InfoService struct {
  13. }
  14. func (l *InfoService) Myinfo(sid string) []byte {
  15. infoMap := map[string]string{}
  16. info_i := redis.Get("session", sid)
  17. if info_i != nil {
  18. info_m, _ := info_i.(map[string]interface{})
  19. entNicheDis := common.Int64All(info_m["entNicheDis"])
  20. depIDArr := ""
  21. if entNicheDis > 0 {
  22. //查询所有部门标识
  23. entId := gconv.String(info_m["entId"])
  24. entDeptId := gconv.String(info_m["entDeptId"])
  25. deptArr := entity.JyMysql.SelectBySql("select GROUP_CONCAT(DISTINCT b.id) as depIDArr from entniche_department_parent a INNER JOIN entniche_department b "+
  26. "on (b.ent_id=? and (b.id=? or (a.pid=? and a.id=b.id)))", entId, entDeptId, entDeptId)
  27. if len(*deptArr) > 0 {
  28. depIDArr = common.InterfaceToStr((*deptArr)[0]["depIDArr"])
  29. }
  30. }
  31. //营销版本查询
  32. accountId := gconv.Int64(info_m["accountId"])
  33. entAccountId := gconv.Int64(info_m["entAccountId"])
  34. entId := gconv.Int64(info_m["entId"])
  35. entUserId := gconv.Int64(info_m["entUserId"])
  36. res := entity.Middleground.ResourceCenter.Haspowers(accountId, entAccountId, entId, entUserId)
  37. version := "0"
  38. for _, pCode := range res.Powers {
  39. //0:通用版 1:物业专版
  40. if pCode == "bi_yx_wyzb" {
  41. version = "1"
  42. }
  43. }
  44. infoMap = map[string]string{
  45. "nickName": RsaEncrypt([]byte(gconv.String(info_m["s_nickname"]))),
  46. "entRole": RsaEncrypt([]byte(gconv.String(info_m["entRole"]))),
  47. "entNicheDis": RsaEncrypt([]byte(gconv.String(entNicheDis))),
  48. "positionId": RsaEncrypt([]byte(gconv.String(info_m["positionId"]))),
  49. "accountId": RsaEncrypt([]byte(gconv.String(info_m["accountId"]))),
  50. "entAccountId": RsaEncrypt([]byte(gconv.String(info_m["entAccountId"]))),
  51. "entId": RsaEncrypt([]byte(gconv.String(info_m["entId"]))),
  52. "entName": RsaEncrypt([]byte(gconv.String(info_m["entName"]))),
  53. "entUserName": RsaEncrypt([]byte(gconv.String(info_m["entUserName"]))),
  54. "entUserId": RsaEncrypt([]byte(gconv.String(info_m["entUserId"]))),
  55. "userId": RsaEncrypt([]byte(gconv.String(info_m["base_user_id"]))),
  56. "entDeptId": RsaEncrypt([]byte(gconv.String(info_m["entDeptId"]))),
  57. "entChildDept": RsaEncrypt([]byte(depIDArr)),
  58. "crmVersion": RsaEncrypt([]byte(version)),
  59. "equityMap": RsaEncrypt([]byte(gconv.String(FindEquity(entUserId, gconv.Int64(info_m["entRole"]))))),
  60. }
  61. }
  62. infoByte, _ := json.Marshal(infoMap)
  63. return infoByte
  64. }
  65. // 加密
  66. func RsaEncrypt(data []byte) string {
  67. key := []byte(entity.PublicKey)
  68. //加密
  69. b, _ := sm4.Sm4Ecb(key, data, true)
  70. return base64.StdEncoding.EncodeToString(b)
  71. }
  72. func FindEquity(entUserId int64, entRole int64) map[string]bool {
  73. equityMap := map[string]bool{
  74. "检索工具-收录按钮-显示": false,
  75. "潜在商机-情报列表-企业": false,
  76. "潜在商机-情报列表-部门": false,
  77. "潜在商机-转发-企业": false,
  78. "潜在商机-转发-部门": false,
  79. "潜在商机-跟进-显示": false,
  80. "潜在商机-不跟进-显示": false,
  81. }
  82. //查找用户
  83. data := entity.JyMysql.FindOne("entniche_user", map[string]interface{}{
  84. "id": entUserId,
  85. }, "role", "")
  86. if data != nil && len(*data) > 0 {
  87. role := strings.Split(gconv.String((*data)["role"]), ",")
  88. fool1 := false
  89. fool2 := false
  90. for _, v := range role {
  91. //角色;1:情报处理岗 2:情报分配岗 3:信息浏览岗 4 :销售管理岗
  92. switch v {
  93. case "1":
  94. fool1 = true
  95. equityMap["检索工具-收录按钮-显示"] = true
  96. equityMap["潜在商机-情报列表-个人"] = true
  97. equityMap["潜在商机-转发-企业"] = true
  98. equityMap["潜在商机-跟进-显示"] = true
  99. equityMap["潜在商机-不跟进-显示"] = true
  100. case "2":
  101. fool2 = true
  102. if entRole == 1 {
  103. //企业
  104. equityMap["检索工具-收录按钮-显示"] = true
  105. equityMap["潜在商机-情报列表-企业"] = true
  106. equityMap["潜在商机-转发-企业"] = true
  107. equityMap["潜在商机-是否分发-显示"] = true
  108. } else {
  109. //部门
  110. equityMap["检索工具-收录按钮-显示"] = true
  111. equityMap["潜在商机-情报列表-部门"] = true
  112. equityMap["潜在商机-转发-部门"] = true
  113. equityMap["潜在商机-是否分发-显示"] = true
  114. }
  115. }
  116. }
  117. if fool1 && fool2 {
  118. equityMap["潜在商机-数据归属-显示"] = true
  119. }
  120. }
  121. return equityMap
  122. }