infoService.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. "潜在商机-分发按钮-显示": false,
  82. "潜在商机-跟进-显示": false,
  83. "潜在商机-不跟进-显示": false,
  84. "潜在商机-是否分发-显示": false,
  85. "潜在商机-数据归属-显示": false,
  86. "创建商机-已关联商机-企业": false,
  87. "创建商机-已关联商机-部门": false,
  88. "创建商机-已关联商机-个人": false,
  89. }
  90. //查找用户
  91. data := entity.JyMysql.FindOne("entniche_user", map[string]interface{}{
  92. "id": entUserId,
  93. }, "role", "")
  94. if data != nil && len(*data) > 0 {
  95. role := strings.Split(gconv.String((*data)["role"]), ",")
  96. fool1 := false
  97. fool2 := false
  98. for _, v := range role {
  99. //角色;1:情报处理岗 2:情报分配岗 3:信息浏览岗 4 :销售管理岗
  100. switch v {
  101. case "1":
  102. fool1 = true
  103. equityMap["检索工具-收录按钮-显示"] = true
  104. equityMap["潜在商机-情报列表-个人"] = true
  105. equityMap["潜在商机-转发-企业"] = true
  106. equityMap["潜在商机-跟进-显示"] = true
  107. equityMap["潜在商机-不跟进-显示"] = true
  108. equityMap["创建商机-已关联商机-个人"] = true
  109. equityMap["潜在商机-转发按钮-显示"] = true
  110. case "2":
  111. fool2 = true
  112. if entRole == 1 {
  113. //企业
  114. equityMap["检索工具-收录按钮-显示"] = true
  115. equityMap["潜在商机-情报列表-企业"] = true
  116. equityMap["潜在商机-转发-企业"] = true
  117. equityMap["潜在商机-是否分发-显示"] = true
  118. equityMap["创建商机-已关联商机-企业"] = true
  119. equityMap["潜在商机-转发按钮-显示"] = true
  120. equityMap["潜在商机-分发按钮-显示"] = true
  121. } else {
  122. //部门
  123. equityMap["检索工具-收录按钮-显示"] = true
  124. equityMap["潜在商机-情报列表-部门"] = true
  125. equityMap["潜在商机-转发-部门"] = true
  126. equityMap["潜在商机-是否分发-显示"] = true
  127. equityMap["创建商机-已关联商机-部门"] = true
  128. equityMap["潜在商机-转发按钮-显示"] = true
  129. equityMap["潜在商机-分发按钮-显示"] = true
  130. }
  131. }
  132. }
  133. if fool1 && fool2 {
  134. equityMap["潜在商机-数据归属-显示"] = true
  135. }
  136. }
  137. return equityMap
  138. }