company_permission.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_web_mfyx/models"
  5. "hongze/hongze_web_mfyx/utils"
  6. "strings"
  7. )
  8. // GetCompanyPermission 获取公司对应的权限名称
  9. func GetCompanyPermission(companyId int) (permissionStr string, err error) {
  10. permissionStr, err = models.GetCompanyPermission(companyId)
  11. if err != nil {
  12. return
  13. }
  14. permissionStr = strings.Replace(permissionStr, "(主观)", "", -1)
  15. permissionStr = strings.Replace(permissionStr, "(客观)", "", -1)
  16. return
  17. }
  18. // GetCompanyPermissionUpgrade 获取公司对应的升级权限名称
  19. func GetCompanyPermissionUpgrade(companyId int) (permissionStr string, err error) {
  20. permissionStr, err = models.GetCompanyPermissionByUserTrip(companyId)
  21. if err != nil {
  22. return
  23. }
  24. permissionStr = strings.Replace(permissionStr, "(主观)", "", -1)
  25. permissionStr = strings.Replace(permissionStr, "(客观)", "", -1)
  26. return
  27. }
  28. // 获取用户对应的权限申请状态
  29. func GetUserHasPermission(user *models.WxUserItem) (hasPermission int, sellerName, sellerMobile, popupMsg string, err error) {
  30. //HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下(ficc),3:无该品类权限,已提交过申请,4:无该品类权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  31. uid := user.UserId
  32. applyCount, e := models.GetApplyRecordCount(uid)
  33. if e != nil {
  34. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  35. return
  36. }
  37. if user.CompanyId <= 1 {
  38. if applyCount == 0 {
  39. hasPermission = 5
  40. } else {
  41. hasPermission = 6
  42. }
  43. } else {
  44. companyPermission, e := models.GetCompanyPermission(user.CompanyId)
  45. if e != nil {
  46. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  47. return
  48. }
  49. if companyPermission != "" {
  50. if applyCount > 0 {
  51. hasPermission = 4
  52. } else {
  53. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  54. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  55. if e != nil && e.Error() != utils.ErrNoRow() {
  56. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  57. return
  58. }
  59. if sellerItemQy != nil {
  60. hasPermission = 3
  61. sellerName = sellerItemQy.Mobile
  62. sellerMobile = sellerItemQy.RealName
  63. } else {
  64. hasPermission = 2
  65. }
  66. }
  67. } else {
  68. hasPermission = 2
  69. }
  70. }
  71. hasPermission, e = GetUserPermissionCode(user.UserId, user.CompanyId)
  72. if e != nil {
  73. err = errors.New("GetUserDetailPermissionCode, Err: " + e.Error())
  74. return
  75. }
  76. popupMsg = "需要升级行业套餐权限才可参与此活动,请联系对口销售"
  77. return
  78. }
  79. // 获取用户对应的权限申请状态 文章详情
  80. func GetUserHasPermissionArticle(user *models.WxUserItem) (hasPermission int, sellerName, sellerMobile, popupMsg string, err error) {
  81. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  82. uid := user.UserId
  83. applyCount, e := models.GetApplyRecordCount(uid)
  84. if e != nil {
  85. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  86. return
  87. }
  88. if user.CompanyId <= 1 {
  89. if applyCount == 0 {
  90. hasPermission = 5
  91. } else {
  92. hasPermission = 4
  93. }
  94. } else {
  95. companyPermission, e := models.GetCompanyPermission(user.CompanyId)
  96. if e != nil {
  97. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  98. return
  99. }
  100. if companyPermission != "" {
  101. if applyCount > 0 {
  102. hasPermission = 3
  103. } else {
  104. hasPermission = 2
  105. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  106. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  107. if e != nil && e.Error() != utils.ErrNoRow() {
  108. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  109. return
  110. }
  111. if sellerItemQy != nil {
  112. sellerName = sellerItemQy.Mobile
  113. sellerMobile = sellerItemQy.RealName
  114. }
  115. }
  116. } else {
  117. hasPermission = 2
  118. }
  119. }
  120. hasPermission, e = GetUserPermissionCode(user.UserId, user.CompanyId)
  121. if e != nil {
  122. err = errors.New("GetUserDetailPermissionCode, Err: " + e.Error())
  123. return
  124. }
  125. popupMsg = "需要升级行业套餐权限才可查看此报告,请联系对口销售"
  126. return
  127. }
  128. // 获取用户对应的权限简单版
  129. func GetUserHasPermissionSimple(user *models.WxUserItem) (hasPermission int, err error) {
  130. //HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下(ficc),3:无该品类权限,已提交过申请,4:无该品类权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  131. uid := user.UserId
  132. applyCount, e := models.GetApplyRecordCount(uid)
  133. if e != nil {
  134. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  135. return
  136. }
  137. if user.CompanyId <= 1 {
  138. if applyCount == 0 {
  139. hasPermission = 5
  140. } else {
  141. hasPermission = 6
  142. }
  143. } else {
  144. companyPermission, e := models.GetCompanyPermission(user.CompanyId)
  145. if e != nil {
  146. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  147. return
  148. }
  149. if companyPermission != "" {
  150. hasPermission = 1
  151. } else {
  152. hasPermission = 3
  153. }
  154. }
  155. return
  156. }
  157. // GetPermissionNameMap 权限名称与权限ID的map
  158. func GetPermissionNameMap() (mapItem map[int]string, err error) {
  159. list, e := models.GetChartPermissionListRai()
  160. if e != nil {
  161. err = e
  162. return
  163. }
  164. mapPermissionName := make(map[int]string)
  165. for _, v := range list {
  166. mapPermissionName[v.ChartPermissionId] = v.PermissionName
  167. }
  168. mapItem = mapPermissionName
  169. return
  170. }
  171. func GetPermissionNameIcoMap() (mapItem map[int]string, err error) {
  172. list, e := models.GetChartPermissionListRai()
  173. if e != nil {
  174. err = e
  175. return
  176. }
  177. mapPermissionName := make(map[int]string)
  178. for _, v := range list {
  179. mapPermissionName[v.ChartPermissionId] = v.ImageUrlM
  180. }
  181. mapItem = mapPermissionName
  182. return
  183. }