user_permission.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/models/company"
  6. "hongze/hongze_cygx/utils"
  7. "strings"
  8. )
  9. var (
  10. UserPermissionOperationModeApply = "Apply"
  11. UserPermissionOperationModeCall = "Call"
  12. UserPermissionPopupMsgApplyActivity = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  13. UserPermissionPopupMsgCallActivity = "您暂无权限参加此活动,若想参加可以联系对口销售"
  14. UserPermissionPopupMsgApplyMicroVideo = "您暂无权限查看此视频,若想查看可以申请开通对应的试用权限"
  15. UserPermissionPopupMsgCallMicroVideo = "您暂无权限查看此视频若想查看可以联系对口销售"
  16. )
  17. // GetUserRaiPermissionInfo 获取权限类型及信息
  18. // HasPermission 是否有权限:1-有权限; 2-无权限; 3-潜在客户未提交申请; 4-潜在客户已提交申请 5-仅有FICC权限
  19. func GetUserRaiPermissionInfo(userId, companyId int) (authInfo models.UserPermissionAuthInfo, permissionArr []string, err error) {
  20. // 用户申请记录
  21. applyCount, e := models.GetApplyRecordCount(userId)
  22. if e != nil && e.Error() != utils.ErrNoRow() {
  23. err = errors.New("获取用户申请信息失败, Err: " + e.Error())
  24. return
  25. }
  26. // 潜在用户
  27. if companyId <= 1 {
  28. authInfo.HasPermission = 3
  29. if applyCount > 0 {
  30. authInfo.HasPermission = 4
  31. }
  32. authInfo.OperationMode = UserPermissionOperationModeApply
  33. authInfo.PopupMsg = UserPermissionPopupMsgApplyActivity
  34. return
  35. }
  36. // 销售信息
  37. ficcSeller, e := models.GetSellerByCompanyIdCheckFicc(companyId, utils.COMPANY_PRODUCT_FICC_ID)
  38. if e != nil && e.Error() != utils.ErrNoRow() {
  39. err = errors.New("获取FICC销售信息失败, Err: " + e.Error())
  40. return
  41. }
  42. raiSeller, e := models.GetSellerByCompanyIdCheckFicc(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  43. if e != nil && e.Error() != utils.ErrNoRow() {
  44. err = errors.New("获取权益销售信息失败, Err: " + e.Error())
  45. return
  46. }
  47. if raiSeller != nil {
  48. authInfo.SellerMobile = raiSeller.Mobile
  49. authInfo.SellerName = raiSeller.RealName
  50. }
  51. // 仅有FICC权限
  52. if ficcSeller != nil && raiSeller == nil {
  53. authInfo.HasPermission = 5
  54. authInfo.OperationMode = UserPermissionOperationModeApply
  55. authInfo.PopupMsg = UserPermissionPopupMsgApplyActivity
  56. return
  57. }
  58. // permissions示例: 医药,消费,科技,智造,策略,专家,买方研选
  59. permissions, e := models.GetCompanyPermissionName(companyId)
  60. if e != nil {
  61. err = errors.New("获取客户权限失败, Err: " + e.Error())
  62. return
  63. }
  64. if permissions == "" {
  65. // 无权益权限
  66. if raiSeller != nil {
  67. // 有销售信息
  68. authInfo.HasPermission = 2
  69. authInfo.OperationMode = UserPermissionOperationModeCall
  70. authInfo.PopupMsg = UserPermissionPopupMsgCallActivity
  71. return
  72. }
  73. // 无销售信息, 无申请, 视作潜在用户
  74. authInfo.HasPermission = 3
  75. authInfo.OperationMode = UserPermissionOperationModeApply
  76. return
  77. }
  78. // 有基本的权益权限
  79. authInfo.HasPermission = 1
  80. permissionArr = strings.Split(permissions, ",")
  81. return
  82. }
  83. // 查询研选的权限状态
  84. func GetUserRaiPermissionYanXuanInfo(user *models.WxUserItem) (hasPermission int, err error) {
  85. //判断用户是否开通了个人研选权限
  86. mfyxUserPermissionTotal := GetMfyxUserPermissionTotal(user.UserId)
  87. if mfyxUserPermissionTotal == 1 {
  88. hasPermission = 1
  89. return
  90. }
  91. var condition string
  92. var pars []interface{}
  93. condition = " AND company_id = ? AND status IN ('正式','试用') AND chart_permission_id = ? ORDER BY company_report_permission_id DESC LIMIT 1 "
  94. pars = append(pars, user.CompanyId, utils.CHART_PERMISSION_ID_YANXUAN)
  95. companyReportPermissionDetail, e := models.GetCompanyReportPermissionDetailByCondition(condition, pars)
  96. if e != nil && e.Error() != utils.ErrNoRow() {
  97. err = errors.New("GetCompanyReportPermissionDetailByCondition, Err: " + e.Error())
  98. return
  99. }
  100. //如果用户没有研选权限,那么就获取他对应的状态码
  101. if companyReportPermissionDetail == nil {
  102. hasPermission, _, _, _, e = GetUserHasPermissionArticle(user)
  103. if e != nil {
  104. err = errors.New("GetUserHasPermissionArticle, Err: " + e.Error())
  105. return
  106. }
  107. } else {
  108. hasPermission = 1
  109. }
  110. return
  111. }
  112. // 用户详情页获取用户权限状态 https://hzstatic.hzinsights.com/static/images/202402/20240205/LpE6dspJCLzfQoCoE8SFMDiLuxXk.png(状态码说明)这一期先不改2024-05-24。
  113. func GetUserDetailPermissionCode(userId, companyId int) (permission int, err error) {
  114. // 用户申请记录
  115. applyCount, e := models.GetApplyRecordCount(userId)
  116. if e != nil && e.Error() != utils.ErrNoRow() {
  117. err = errors.New("获取用户申请信息失败, Err: " + e.Error())
  118. return
  119. }
  120. if companyId == 1 {
  121. // 潜在用户
  122. if applyCount > 0 {
  123. permission = 5
  124. } else {
  125. permission = 4
  126. }
  127. } else {
  128. //权益客户
  129. raiCount, e := company.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  130. if e != nil {
  131. err = errors.New("获取用户申请信息失败, Err: " + e.Error())
  132. return
  133. }
  134. if raiCount == 1 {
  135. if applyCount > 0 {
  136. permission = 5
  137. } else {
  138. permission = 3
  139. }
  140. } else {
  141. if applyCount > 0 {
  142. permission = 5
  143. } else {
  144. permission = 2
  145. }
  146. }
  147. }
  148. return
  149. }