activity_power_check.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. package cygx
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/company"
  7. "hongze/hz_crm_api/models/cygx"
  8. "hongze/hz_crm_api/models/system"
  9. "hongze/hz_crm_api/utils"
  10. "strconv"
  11. "strings"
  12. )
  13. //func init() {
  14. // wxUser, userErr := models.GetWxUserByUserId(52994)
  15. // if userErr != nil {
  16. // fmt.Println(userErr)
  17. // }
  18. // activityInfo, err := cygx.GetAddActivityInfoById(2104)
  19. // if err != nil {
  20. // fmt.Println(err)
  21. // }
  22. // havePower, err := GetActivityDetailUserPower(wxUser, activityInfo)
  23. // fmt.Println(havePower)
  24. // fmt.Println(err)
  25. //}
  26. // GetSpecialDetailUserPower 处理用户查看详情的权限 作废 2023-06-26
  27. func GetActivityDetailUserPowerold(user *models.WxUser, adminInfo *system.Admin, activityInfo *cygx.ActivityDetail) (havePower bool, err error) {
  28. var companyDetailStatus string
  29. var userTypeStr string
  30. if user.CompanyId == utils.HZ_COMPANY_ID {
  31. havePower = true
  32. return
  33. }
  34. //需求707: 不限制人数的活动,销售后台给客户报名时(包括预约外呼、预约纪要、会议提醒),可以不做是否有权限的校验,限制人数的仍需判断是否有权限。2023-06-14
  35. if activityInfo.IsLimitPeople == 0 {
  36. havePower = true
  37. return
  38. }
  39. ////高毅资产的联系人,销售在后台添加报名时,不受行业权限的限制 高毅资产属于其他行业正式客户
  40. ////Ps: 现在就这一家单独的公司需要先写死 2023-03-20 高毅资产 公司ID:5285
  41. //if user.CompanyId == 5285 {
  42. // havePower = true
  43. // return
  44. //}
  45. userType, permissionStr, permissionStrZhengShi, companyStatus, e := GetUserTypeZhengShi(user.CompanyId)
  46. if e != nil {
  47. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  48. return
  49. }
  50. //何伯仪给用户报名不做权限的限制,给他的用户添加所有权限 需求:2023-06-13
  51. //if adminInfo.Mobile == "15216703664" {
  52. // permissionStr = "医药(客观),医药(主观),消费(客观),消费(主观),科技(客观),科技(主观),智造(客观),智造(主观),策略,专家,路演服务,买方研选"
  53. // permissionStrZhengShi = "医药(客观),医药(主观),消费(客观),消费(主观),科技(客观),科技(主观),智造(客观),智造(主观),策略,专家,路演服务,买方研选"
  54. //}
  55. //如果是 公司调研电话会:3,或 专家线下沙龙:5 而且 除易董同步过来的以外的研选类型活动,必须要有研选的正式权限
  56. if (activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 5) && activityInfo.YidongActivityId == "" && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  57. if !strings.Contains(permissionStrZhengShi, activityInfo.ChartPermissionName) {
  58. havePower = false
  59. return
  60. }
  61. }
  62. //如果是易董的活动且属于研选类型,只要开通任何权限就可以查看详情
  63. if activityInfo.YidongActivityId != "" && permissionStr != "" && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  64. havePower = true
  65. return
  66. }
  67. //处理决策人可见权限
  68. if user.IsMaker == 0 && activityInfo.IsMakerShow == 1 {
  69. havePower = false
  70. return
  71. }
  72. //if activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 6 || activityInfo.ActivityTypeId == 7 {
  73. // if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(主观)") {
  74. // havePower = true
  75. // } else {
  76. // havePower = false
  77. // }
  78. //} else {
  79. // if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(客观)") {
  80. // havePower = true
  81. // } else {
  82. // havePower = false
  83. // }
  84. //}
  85. ////如果主客观校验不通过,那么直接返回
  86. //if !havePower {
  87. // return
  88. //}
  89. if activityInfo.IsLimitPeople > 0 {
  90. mapUserType, e := GetActivityCcustomerTypeList()
  91. if e != nil {
  92. err = e
  93. return
  94. }
  95. userTypeStr = mapUserType[userType]
  96. // 永续客户、大套餐客户、30W套餐客户可以查看行业升级套餐客户 权限
  97. if userTypeStr == "1" || userTypeStr == "2" || userTypeStr == "AA" {
  98. if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  99. havePower = true
  100. //return
  101. }
  102. }
  103. } else {
  104. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  105. havePower = true
  106. return
  107. }
  108. }
  109. //判断管理规模是否满足
  110. companyProduct, e := company.GetCompanyProductDetail(user.CompanyId, 2)
  111. if e != nil {
  112. err = e
  113. return
  114. }
  115. if companyProduct != nil && activityInfo.Scale != "" {
  116. if strings.Contains(activityInfo.Scale, companyProduct.Scale) {
  117. havePower = true
  118. }
  119. }
  120. if user.CompanyId <= 1 {
  121. return
  122. } else {
  123. if permissionStr == "" {
  124. return
  125. } else {
  126. //companyDetail, e := models.GetCompanyDetailById(user.CompanyId)
  127. //if e != nil {
  128. // err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  129. // return
  130. //}
  131. //if companyDetail == nil {
  132. // err = errors.New("客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId))
  133. // return
  134. //}
  135. companyDetailStatus = companyStatus
  136. }
  137. }
  138. if activityInfo.ChartPermissionId == 1 {
  139. havePower = true
  140. return
  141. }
  142. if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3) && strings.Contains(permissionStr, "专家") && activityInfo.IsLimitPeople == 0 {
  143. havePower = true
  144. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "正式" && strings.Contains(activityInfo.CustomerTypeIds, "4") {
  145. havePower = true
  146. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "试用" && strings.Contains(activityInfo.CustomerTypeIds, "5") {
  147. havePower = true
  148. } else if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 4 || activityInfo.ActivityTypeId == 5) && strings.Contains(permissionStr, "专家") {
  149. havePower = true
  150. }
  151. //if (strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略") && strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  152. // havePower = true
  153. // return
  154. //}
  155. fmt.Println(havePower)
  156. if strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略" {
  157. if strings.Contains(activityInfo.CustomerTypeIds, "5") {
  158. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  159. havePower = true
  160. return
  161. }
  162. } else {
  163. if strings.Contains(permissionStrZhengShi, activityInfo.ChartPermissionName) {
  164. havePower = true
  165. return
  166. }
  167. }
  168. }
  169. permissionShengji, errs := cygx.GetCompanyPermissionByUserZhengShiTrip(user.CompanyId)
  170. if errs != nil {
  171. err = errs
  172. return
  173. }
  174. //if strings.Contains(permissionShengji, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  175. // havePower = true
  176. //}
  177. //处理升级权限以及用户身份的 双重判断
  178. if activityInfo.CustomerTypeIds != "" {
  179. if !strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && userTypeStr != "8" {
  180. havePower = false
  181. if strings.Contains(permissionShengji, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  182. havePower = true
  183. }
  184. }
  185. }
  186. //if strings.Contains(permissionStr, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) {
  187. // havePower = true
  188. // return
  189. //}
  190. if havePower && activityInfo.IsLimitPeople > 0 {
  191. //对于一些特殊的活动,即使权限满足也不给产看
  192. noPower, e := GetShareNoPoweNew(activityInfo, permissionStr, userType, user)
  193. if e != nil {
  194. err = errors.New("GetShareNoPowe, Err: " + e.Error())
  195. return
  196. }
  197. if noPower {
  198. havePower = false
  199. }
  200. }
  201. return
  202. }
  203. // GetSpecialDetailUserPower 处理用户查看详情的权限
  204. func GetActivityDetailUserPower(user *models.WxUser, adminInfo *system.Admin, activityInfo *cygx.ActivityDetail) (havePower bool, err error) {
  205. var companyDetailStatus string
  206. var userTypeStr string
  207. userId := int(user.UserId)
  208. //如果是弘则的用户或者宏观的权限不做校验
  209. //if user.CompanyId == utils.HZ_COMPANY_ID || activityInfo.ChartPermissionName == "宏观" {
  210. if user.CompanyId == utils.HZ_COMPANY_ID {
  211. havePower = true
  212. return
  213. }
  214. //需求707: 不限制人数的活动,销售后台给客户报名时(包括预约外呼、预约纪要、会议提醒),可以不做是否有权限的校验,限制人数的仍需判断是否有权限。2023-06-14
  215. if activityInfo.IsLimitPeople == 0 {
  216. havePower = true
  217. return
  218. }
  219. userType, permissionStr, permissionStrZhengShi, _, e := GetUserTypeZhengShi(user.CompanyId)
  220. if e != nil {
  221. err = errors.New("GetUserTypeZhengShi, Err: " + e.Error())
  222. return
  223. }
  224. //判断用户是否开通了个人研选权限,如果有权限后缀拼接权限名称
  225. // 查询用户是否开通过
  226. mfyxUserPermissionTotal, e := cygx.GetCygxUserYanxuanPermissionCountByUserId(userId)
  227. if e != nil {
  228. err = errors.New("GetCygxUserYanxuanPermissionCountByUserId, Err: " + e.Error())
  229. return
  230. }
  231. if mfyxUserPermissionTotal == 1 {
  232. permissionStr += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
  233. }
  234. //如果正式权限有开通 研选扣点包 ,那么就拼接一个 研选订阅的权限
  235. if strings.Contains(permissionStrZhengShi, utils.YAN_XUAN_KOU_DIAN_BAO_NAME) {
  236. permissionStr += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
  237. permissionStrZhengShi += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
  238. }
  239. //如果测试权限有开通 研选扣点包 ,那么就拼接一个 研选订阅的权限
  240. if strings.Contains(permissionStr, utils.YAN_XUAN_KOU_DIAN_BAO_NAME) {
  241. permissionStr += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
  242. }
  243. //如果一个权限都没有就返回无权限
  244. if permissionStr == "" {
  245. return
  246. }
  247. permissionStr += "," + utils.HONG_GUAN_NAME // 添加一个宏观权限
  248. if permissionStrZhengShi == "" {
  249. permissionStrZhengShi = utils.HONG_GUAN_NAME // 添加一个宏观权限
  250. } else {
  251. permissionStrZhengShi += "," + utils.HONG_GUAN_NAME // 添加一个宏观权限
  252. }
  253. //如果是易董的活动,主、副权限有一个满足即可
  254. if activityInfo.YidongActivityId != "" {
  255. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) || strings.Contains(permissionStr, activityInfo.ChartPermissionNameDeputy) {
  256. havePower = true
  257. return
  258. }
  259. }
  260. //如果权限不包含那么直接返回
  261. if !strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  262. return
  263. } else {
  264. havePower = true
  265. }
  266. //处理决策人可见权限
  267. if user.IsMaker == 0 && activityInfo.IsMakerShow == 1 {
  268. havePower = false
  269. return
  270. }
  271. // 处理本组可见权限
  272. if activityInfo.VisibleRange == 1 {
  273. adminIds, e := cygx.GetSelleridWhichGroup(user.CompanyId, 2)
  274. if e != nil {
  275. err = errors.New("GetSelleridWhichGroup, Err: " + e.Error())
  276. return
  277. }
  278. haveVisibleRange := false
  279. adminIdSlice := strings.Split(adminIds, ",")
  280. for _, v := range adminIdSlice {
  281. if v == strconv.Itoa(activityInfo.AdminId) {
  282. haveVisibleRange = true
  283. }
  284. }
  285. if !haveVisibleRange {
  286. havePower = false
  287. return
  288. }
  289. }
  290. if permissionStr == "" {
  291. return
  292. }
  293. //如果是易董的活动且属于研选类型,只要开通任何权限就可以查看详情
  294. if activityInfo.YidongActivityId != "" && permissionStr != "" && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  295. havePower = true
  296. return
  297. }
  298. //医药消费,科技,智造四大行业,验证主客观。如果主客观校验不通过,那么直接返回
  299. if strings.Contains(utils.YI_YAO_NAME+utils.XIAO_FEI_NAME+utils.KE_JI_NAME+utils.ZHI_ZAO_NAME, activityInfo.ChartPermissionName) {
  300. if activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 6 || activityInfo.ActivityTypeId == 7 {
  301. if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(主观)") {
  302. havePower = true
  303. } else {
  304. havePower = false
  305. }
  306. } else {
  307. if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(客观)") {
  308. havePower = true
  309. } else {
  310. havePower = false
  311. }
  312. }
  313. if !havePower {
  314. return
  315. }
  316. }
  317. if activityInfo.IsLimitPeople > 0 {
  318. mapUserType, e := GetActivityCcustomerTypeList()
  319. if e != nil {
  320. err = errors.New("GetActivityCcustomerTypeList, Err: " + e.Error())
  321. return
  322. }
  323. userTypeStr = mapUserType[userType]
  324. // 永续客户、大套餐客户、30W套餐客户可以查看行业升级套餐客户 权限
  325. if userTypeStr == "1" || userTypeStr == "2" || userTypeStr == "AA" {
  326. if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  327. havePower = true
  328. //return
  329. }
  330. }
  331. } else {
  332. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  333. havePower = true
  334. return
  335. }
  336. }
  337. //判断管理规模是否满足
  338. companyProduct, e := cygx.GetCompanyProductDetail(user.CompanyId, 2)
  339. if e != nil {
  340. err = e
  341. return
  342. }
  343. if companyProduct != nil && activityInfo.Scale != "" {
  344. if strings.Contains(activityInfo.Scale, companyProduct.Scale) {
  345. havePower = true
  346. }
  347. }
  348. if user.CompanyId <= 1 {
  349. return
  350. } else {
  351. if permissionStr == "" {
  352. return
  353. } else {
  354. companyDetail, e := cygx.GetCompanyDetailById(user.CompanyId)
  355. if e != nil {
  356. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  357. return
  358. }
  359. if companyDetail == nil {
  360. err = errors.New("客户不存在,uid:" + strconv.Itoa(int(user.UserId)) + "CompanyId:" + strconv.Itoa(user.CompanyId))
  361. return
  362. }
  363. companyDetailStatus = companyDetail.Status
  364. }
  365. }
  366. //宏观满足用户可见身份验证权限既满足 2023-9-18
  367. if activityInfo.ChartPermissionId == 1 {
  368. if activityInfo.IsLimitPeople > 0 {
  369. if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) {
  370. havePower = true
  371. return
  372. }
  373. } else {
  374. havePower = true
  375. return
  376. }
  377. }
  378. if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3) && strings.Contains(permissionStr, "专家") && activityInfo.IsLimitPeople == 0 {
  379. havePower = true
  380. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "正式" && strings.Contains(activityInfo.CustomerTypeIds, "4") {
  381. havePower = true
  382. } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "试用" && strings.Contains(activityInfo.CustomerTypeIds, "5") {
  383. havePower = true
  384. } else if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 4 || activityInfo.ActivityTypeId == 5) && strings.Contains(permissionStr, "专家") {
  385. havePower = true
  386. }
  387. if strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略" {
  388. if strings.Contains(activityInfo.CustomerTypeIds, "5") {
  389. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  390. havePower = true
  391. return
  392. }
  393. } else {
  394. if strings.Contains(permissionStrZhengShi, activityInfo.ChartPermissionName) {
  395. havePower = true
  396. return
  397. }
  398. }
  399. }
  400. permissionShengji, errs := cygx.GetCompanyPermissionByUserTrip(user.CompanyId)
  401. if errs != nil {
  402. err = errs
  403. return
  404. }
  405. //fmt.Println("主客观2", havePower)
  406. //if strings.Contains(permissionStr, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) {
  407. // havePower = true
  408. //}
  409. //fmt.Println("主客观3", havePower)
  410. //处理升级权限以及用户身份的 双重判断
  411. if activityInfo.CustomerTypeIds != "" {
  412. if !strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && userTypeStr != "8" {
  413. havePower = false
  414. if strings.Contains(permissionShengji, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  415. havePower = true
  416. }
  417. }
  418. }
  419. if havePower && activityInfo.IsLimitPeople > 0 {
  420. //对于一些特殊的活动,即使权限满足也不给产看
  421. noPower, e := GetShareNoPowe(activityInfo, permissionStr, userType)
  422. if e != nil {
  423. err = errors.New("GetShareNoPowe, Err: " + e.Error())
  424. return
  425. }
  426. if noPower {
  427. havePower = false
  428. }
  429. }
  430. return
  431. }
  432. // 校验被分享的用户是否有查看详情的权限
  433. func GetShareNoPoweNew(activityInfo *cygx.ActivityDetail, permissionStr string, userType int, user *models.WxUser) (noPower bool, err error) {
  434. //如果是弘则的就不进行可见权限校验
  435. if user.CompanyId == utils.HZ_COMPANY_ID {
  436. return
  437. }
  438. //var noPower bool
  439. //if !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(userType)) {
  440. // noPower = true
  441. //}
  442. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户
  443. //if userType == 2 && strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(2)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(4)) {
  444. // noPower = true
  445. //}
  446. //if userType == 2 && !strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(2)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) {
  447. // noPower = true
  448. //}
  449. //if userType == 3 && strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(4)) {
  450. // noPower = true
  451. //}
  452. //if userType == 3 && !strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) {
  453. // noPower = true
  454. //}
  455. if userType == 8 {
  456. permissionShengji, errs := cygx.GetCompanyPermissionByUserZhengShiTrip(user.CompanyId)
  457. if errs != nil {
  458. err = errs
  459. return
  460. }
  461. if !strings.Contains(permissionShengji, activityInfo.ChartPermissionName) {
  462. noPower = true
  463. return
  464. }
  465. }
  466. if !noPower {
  467. noPower, err = CheckUserPowerByActivityChoose(user, activityInfo)
  468. }
  469. return
  470. }
  471. // 处理活动本组们是否决策人权限
  472. func CheckUserPowerByActivityChoose(user *models.WxUser, activityInfo *cygx.ActivityDetail) (noPower bool, err error) {
  473. //处理 见范围 1,仅本组可见 、2,全部客户可见
  474. if activityInfo.VisibleRange == 1 {
  475. adminIds, errAdmin := system.GetSelleridWhichGroup(user.CompanyId, 2)
  476. if errAdmin != nil {
  477. err = errAdmin
  478. return
  479. }
  480. sliceAdminIds := strings.Split(adminIds, ",")
  481. var haveAdminId bool
  482. for _, v := range sliceAdminIds {
  483. if v == strconv.Itoa(activityInfo.AdminId) {
  484. haveAdminId = true
  485. }
  486. }
  487. if !haveAdminId {
  488. noPower = true
  489. }
  490. }
  491. //处理 是否仅决策人可见 0,否 、1,是
  492. if activityInfo.IsMakerShow == 1 {
  493. if user.IsMaker == 0 {
  494. noPower = true
  495. }
  496. }
  497. return
  498. }
  499. // GetSpecialDetailUserPower 处理用户查看专项调研详情的权限
  500. func GetSpecialDetailUserPower(user *models.WxUser, activityInfo *cygx.ActivitySpecialDetail) (havePower bool, err error) {
  501. if user.CompanyId == utils.HZ_COMPANY_ID {
  502. havePower = true
  503. return
  504. }
  505. userType, _, permissionStr, _, e := GetUserType(user.CompanyId)
  506. if e != nil {
  507. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  508. return
  509. }
  510. if userType == 0 {
  511. return
  512. }
  513. mapUserType, e := GetActivityCcustomerTypeList()
  514. if e != nil {
  515. err = e
  516. return
  517. }
  518. var userTypeStr string
  519. userTypeStr = mapUserType[userType]
  520. // 永续客户、大套餐客户可以查看行业升级套餐客户 权限
  521. if userTypeStr == "1" || userTypeStr == "2" {
  522. if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) || strings.Contains(activityInfo.CustomerTypeIds, "8") {
  523. havePower = true
  524. return
  525. }
  526. }
  527. permissionShengji, errs := cygx.GetCompanyPermissionByUserTrip(user.CompanyId)
  528. if errs != nil {
  529. err = errs
  530. return
  531. }
  532. //如果有升级权限的自动添加策略、固收的升级权限
  533. if permissionStr != "" {
  534. if activityInfo.ChartPermissionName == utils.CE_LUE_NAME {
  535. permissionShengji += "," + utils.CE_LUE_NAME
  536. }
  537. if activityInfo.ChartPermissionName == utils.GU_SHOU_NAME {
  538. permissionShengji += "," + utils.GU_SHOU_NAME
  539. }
  540. }
  541. //如果没有对应的升级权限,则返回
  542. if !strings.Contains(permissionShengji, activityInfo.ChartPermissionName) {
  543. return
  544. }
  545. var pars []interface{}
  546. var condition string
  547. var userTypes string
  548. condition += ` AND art.publish_status = 1 AND art.is_offline = 0 `
  549. userTypes = "%" + userTypeStr + "%"
  550. condition += ` AND art.customer_type_ids LIKE ? `
  551. pars = append(pars, userTypes)
  552. condition += ` AND art.activity_id = ? `
  553. pars = append(pars, activityInfo.ActivityId)
  554. total, e := cygx.GetActivitySpecialCount(condition, pars)
  555. if e != nil {
  556. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  557. return
  558. }
  559. if total == 1 {
  560. havePower = true
  561. return
  562. }
  563. if strings.Contains(permissionShengji, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  564. havePower = true
  565. return
  566. }
  567. return
  568. }