company_permission.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/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:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请,5:有IFCC、无权益"`
  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 = 3
  40. } else {
  41. hasPermission = 4
  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 = 2
  61. sellerName = sellerItemQy.Mobile
  62. sellerMobile = sellerItemQy.RealName
  63. } else {
  64. hasPermission = 5
  65. }
  66. }
  67. } else {
  68. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  69. if e != nil && e.Error() != utils.ErrNoRow() {
  70. err = errors.New("GetSellerByCompanyIdCheckFicc_Qy, Err: " + e.Error())
  71. return
  72. }
  73. if sellerItemQy != nil {
  74. hasPermission = 2
  75. sellerMobile = sellerItemQy.Mobile
  76. sellerName = sellerItemQy.RealName
  77. } else {
  78. //获取FICC销售信息
  79. sellerItemFicc, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  80. if e != nil && e.Error() != utils.ErrNoRow() {
  81. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  82. return
  83. }
  84. if sellerItemFicc != nil {
  85. hasPermission = 3
  86. } else {
  87. hasPermission = 5
  88. }
  89. }
  90. }
  91. }
  92. popupMsg = "需要升级行业套餐权限才可参与此活动,请联系对口销售"
  93. return
  94. }
  95. // 获取用户对应的权限申请状态 文章详情
  96. func GetUserHasPermissionArticle(user *models.WxUserItem) (hasPermission int, sellerName, sellerMobile, popupMsg string, err error) {
  97. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  98. uid := user.UserId
  99. applyCount, e := models.GetApplyRecordCount(uid)
  100. if e != nil {
  101. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  102. return
  103. }
  104. if user.CompanyId <= 1 {
  105. if applyCount == 0 {
  106. hasPermission = 4
  107. } else {
  108. hasPermission = 5
  109. }
  110. } else {
  111. companyPermission, e := models.GetCompanyPermission(user.CompanyId)
  112. if e != nil {
  113. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  114. return
  115. }
  116. if companyPermission != "" {
  117. if applyCount > 0 {
  118. hasPermission = 2
  119. } else {
  120. hasPermission = 3
  121. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  122. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  123. if e != nil && e.Error() != utils.ErrNoRow() {
  124. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  125. return
  126. }
  127. if sellerItemQy != nil {
  128. sellerName = sellerItemQy.Mobile
  129. sellerMobile = sellerItemQy.RealName
  130. }
  131. }
  132. }
  133. }
  134. popupMsg = "需要升级行业套餐权限才可查看此报告,请联系对口销售"
  135. return
  136. }
  137. // 获取用户对应的权限申请状态 活动详情
  138. func GetUserHasPermissionActivity(user *models.WxUserItem, activityInfo *models.ActivityDetail) (hasPermission int, sellerName, sellerMobile, popupMsg string, err error) {
  139. //HasPermission int `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请,5:有IFCC、无权益"`
  140. uid := user.UserId
  141. applyCount, e := models.GetApplyRecordCount(uid)
  142. if e != nil {
  143. err = errors.New("GetApplyRecordCount, Err: " + e.Error())
  144. return
  145. }
  146. if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  147. popupMsg = "暂无<b>买方研选</b>权限<br/>您可申请开通试用"
  148. } else {
  149. popupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  150. }
  151. if user.CompanyId == 1 {
  152. if applyCount > 0 {
  153. hasPermission = 4
  154. } else {
  155. hasPermission = 3
  156. }
  157. return
  158. }
  159. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  160. if err != nil {
  161. if err.Error() == utils.ErrNoRow() {
  162. if applyCount > 0 {
  163. hasPermission = 4
  164. } else {
  165. //获取FICC销售信息
  166. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  167. if e != nil && e.Error() != utils.ErrNoRow() {
  168. err = e
  169. return
  170. }
  171. if sellerItem != nil {
  172. hasPermission = 5
  173. } else {
  174. hasPermission = 3
  175. }
  176. }
  177. hasPermission = hasPermission
  178. if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  179. popupMsg = "暂无<b>买方研选</b>权限<br/>您可申请开通试用"
  180. } else {
  181. popupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  182. }
  183. return
  184. } else {
  185. return
  186. }
  187. }
  188. if companyItem.ProductId == 2 {
  189. hasPermission = 2
  190. sellerMobile = companyItem.Mobile
  191. sellerName = companyItem.SellerName
  192. companyPermission, e := models.GetCompanyPermission(user.CompanyId)
  193. if e != nil && e.Error() != utils.ErrNoRow() {
  194. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  195. return
  196. }
  197. if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  198. //popupMsg = "暂无<b>买方研选</b>权限<br/>点击提交申请,提醒对口销售为你开通试用"
  199. if !strings.Contains(companyPermission, utils.CHART_PERMISSION_NAME_YANXUAN) && (activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 5) {
  200. popupMsg = "暂无<b>买方研选</b>权限<br/>点击提交申请,提醒对口销售为你开通试用"
  201. } else {
  202. popupMsg = "签约买方研选套餐才可参与此活动,请联系对口销售"
  203. }
  204. } else {
  205. if companyPermission == "专家" {
  206. popupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  207. } else {
  208. popupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  209. }
  210. }
  211. } else {
  212. hasPermission = 5
  213. }
  214. return
  215. }