company_permission.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_clpt/models"
  5. "hongze/hongze_clpt/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. popupMsg = "需要升级行业套餐权限才可参与此活动,请联系对口销售"
  72. return
  73. }
  74. // 获取用户对应的权限申请状态 文章详情
  75. func GetUserHasPermissionArticle(user *models.WxUserItem) (hasPermission int, sellerName, sellerMobile, popupMsg string, err error) {
  76. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  77. uid := user.UserId
  78. applyCount, e := models.GetApplyRecordCount(uid)
  79. if e != nil {
  80. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  81. return
  82. }
  83. if user.CompanyId <= 1 {
  84. if applyCount == 0 {
  85. hasPermission = 5
  86. } else {
  87. hasPermission = 4
  88. }
  89. } else {
  90. companyPermission, e := models.GetCompanyPermission(user.CompanyId)
  91. if e != nil {
  92. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  93. return
  94. }
  95. if companyPermission != "" {
  96. if applyCount > 0 {
  97. hasPermission = 3
  98. } else {
  99. hasPermission = 2
  100. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  101. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  102. if e != nil && e.Error() != utils.ErrNoRow() {
  103. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  104. return
  105. }
  106. if sellerItemQy != nil {
  107. sellerName = sellerItemQy.Mobile
  108. sellerMobile = sellerItemQy.RealName
  109. }
  110. }
  111. } else {
  112. hasPermission = 2
  113. }
  114. }
  115. popupMsg = "需要升级行业套餐权限才可查看此报告,请联系对口销售"
  116. return
  117. }
  118. // 获取用户对应的权限申请状态 活动详情
  119. func GetUserHasPermissionActivity(user *models.WxUserItem, activityInfo *models.ActivityDetail) (hasPermission int, sellerName, sellerMobile, popupMsg string, err error) {
  120. //HasPermission int `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请,5:有IFCC、无权益"`
  121. uid := user.UserId
  122. applyCount, e := models.GetApplyRecordCount(uid)
  123. if e != nil {
  124. err = errors.New("GetApplyRecordCount, Err: " + e.Error())
  125. return
  126. }
  127. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  128. if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  129. if activityPointsByUserAllMap[activityInfo.ActivityId] {
  130. popupMsg = "签约买方研选套餐才可参与此活动,请联系对口销售"
  131. } else {
  132. popupMsg = "暂无<b>买方研选</b>权限<br/>您可申请开通试用"
  133. }
  134. } else {
  135. popupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  136. }
  137. if user.CompanyId == 1 {
  138. if applyCount > 0 {
  139. hasPermission = 5
  140. } else {
  141. hasPermission = 4
  142. }
  143. return
  144. }
  145. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  146. if err != nil {
  147. if err.Error() == utils.ErrNoRow() {
  148. if applyCount > 0 {
  149. hasPermission = 3
  150. } else {
  151. //获取FICC销售信息
  152. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  153. if e != nil && e.Error() != utils.ErrNoRow() {
  154. err = e
  155. return
  156. }
  157. if sellerItem != nil {
  158. hasPermission = 5
  159. } else {
  160. hasPermission = 3
  161. }
  162. }
  163. err = nil
  164. hasPermission = hasPermission
  165. if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  166. popupMsg = "暂无<b>买方研选</b>权限<br/>您可申请开通试用"
  167. } else {
  168. popupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  169. }
  170. return
  171. } else {
  172. return
  173. }
  174. }
  175. if companyItem.ProductId == 2 {
  176. hasPermission = 3
  177. sellerMobile = companyItem.Mobile
  178. sellerName = companyItem.SellerName
  179. companyPermission, e := models.GetCompanyPermission(user.CompanyId)
  180. if e != nil && e.Error() != utils.ErrNoRow() {
  181. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  182. return
  183. }
  184. if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  185. //popupMsg = "暂无<b>买方研选</b>权限<br/>点击提交申请,提醒对口销售为你开通试用"
  186. if !strings.Contains(companyPermission, utils.CHART_PERMISSION_NAME_YANXUAN) && (activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 5) {
  187. popupMsg = "暂无<b>买方研选</b>权限<br/>点击提交申请,提醒对口销售为你开通试用"
  188. } else {
  189. popupMsg = "签约买方研选套餐才可参与此活动,请联系对口销售"
  190. }
  191. } else {
  192. if companyPermission == "专家" {
  193. popupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  194. } else {
  195. popupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  196. }
  197. }
  198. } else {
  199. hasPermission = 5
  200. }
  201. return
  202. }
  203. // 获取用户对应的权限简单版
  204. func GetUserHasPermissionSimple(user *models.WxUserItem) (hasPermission int, err error) {
  205. //HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下(ficc),3:无该品类权限,已提交过申请,4:无该品类权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  206. uid := user.UserId
  207. applyCount, e := models.GetApplyRecordCount(uid)
  208. if e != nil {
  209. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  210. return
  211. }
  212. if user.CompanyId <= 1 {
  213. if applyCount == 0 {
  214. hasPermission = 5
  215. } else {
  216. hasPermission = 6
  217. }
  218. } else {
  219. companyPermission, e := models.GetCompanyPermission(user.CompanyId)
  220. if e != nil {
  221. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  222. return
  223. }
  224. if companyPermission != "" {
  225. hasPermission = 1
  226. } else {
  227. hasPermission = 3
  228. }
  229. }
  230. return
  231. }
  232. // GetPermissionNameMap 权限名称与权限ID的map
  233. func GetPermissionNameMap() (mapItem map[int]string, err error) {
  234. list, e := models.GetChartPermissionListRai()
  235. if e != nil {
  236. err = e
  237. return
  238. }
  239. mapPermissionName := make(map[int]string)
  240. for _, v := range list {
  241. mapPermissionName[v.ChartPermissionId] = v.PermissionName
  242. }
  243. mapItem = mapPermissionName
  244. return
  245. }
  246. func GetPermissionNameIcoMap() (mapItem map[int]string, err error) {
  247. list, e := models.GetChartPermissionListRai()
  248. if e != nil {
  249. err = e
  250. return
  251. }
  252. mapPermissionName := make(map[int]string)
  253. for _, v := range list {
  254. mapPermissionName[v.ChartPermissionId] = v.ImageUrlM
  255. }
  256. mapItem = mapPermissionName
  257. return
  258. }