company_permission.go 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_mfyx/models"
  6. "hongze/hongze_mfyx/utils"
  7. "strings"
  8. )
  9. // GetCompanyPermissionUpgrade 获取公司对应的升级权限名称
  10. func GetCompanyPermissionUpgrade(companyId int) (permissionStr string, err error) {
  11. permissionStr, err = models.GetCompanyPermissionByUserTrip(companyId)
  12. if err != nil {
  13. return
  14. }
  15. permissionStr = strings.Replace(permissionStr, "(主观)", "", -1)
  16. permissionStr = strings.Replace(permissionStr, "(客观)", "", -1)
  17. return
  18. }
  19. // 获取用户对应的权限申请状态
  20. func GetUserHasPermission(user *models.WxUserItem) (hasPermission int, sellerName, sellerMobile, popupMsg string, err error) {
  21. //HasPermission int `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请,5:有IFCC、无权益"`
  22. uid := user.UserId
  23. applyCount, e := models.GetApplyRecordCount(uid)
  24. if e != nil {
  25. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  26. return
  27. }
  28. if user.CompanyId <= 1 {
  29. if applyCount == 0 {
  30. hasPermission = 3
  31. } else {
  32. hasPermission = 4
  33. }
  34. } else {
  35. companyPermission, e := models.GetCompanyPermission(user.CompanyId)
  36. if e != nil {
  37. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  38. return
  39. }
  40. if companyPermission != "" {
  41. if applyCount > 0 {
  42. hasPermission = 4
  43. } else {
  44. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  45. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  46. if e != nil && e.Error() != utils.ErrNoRow() {
  47. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  48. return
  49. }
  50. if sellerItemQy != nil {
  51. hasPermission = 2
  52. sellerName = sellerItemQy.Mobile
  53. sellerMobile = sellerItemQy.RealName
  54. } else {
  55. hasPermission = 5
  56. }
  57. }
  58. } else {
  59. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  60. if e != nil && e.Error() != utils.ErrNoRow() {
  61. err = errors.New("GetSellerByCompanyIdCheckFicc_Qy, Err: " + e.Error())
  62. return
  63. }
  64. if sellerItemQy != nil {
  65. hasPermission = 2
  66. sellerMobile = sellerItemQy.Mobile
  67. sellerName = sellerItemQy.RealName
  68. } else {
  69. //获取FICC销售信息
  70. sellerItemFicc, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  71. if e != nil && e.Error() != utils.ErrNoRow() {
  72. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  73. return
  74. }
  75. if sellerItemFicc != nil {
  76. hasPermission = 3
  77. } else {
  78. hasPermission = 5
  79. }
  80. }
  81. }
  82. }
  83. popupMsg = "需要升级行业套餐权限才可参与此活动,请联系对口销售"
  84. return
  85. }
  86. // 获取用户对应的权限申请状态 文章详情
  87. func GetUserHasPermissionArticle(user *models.WxUserItem) (hasPermission int, sellerName, sellerMobile, popupMsg string, err error) {
  88. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  89. uid := user.UserId
  90. applyCount, e := models.GetApplyRecordCount(uid)
  91. if e != nil {
  92. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  93. return
  94. }
  95. if user.CompanyId <= 1 {
  96. if applyCount == 0 {
  97. hasPermission = 4
  98. } else {
  99. hasPermission = 5
  100. }
  101. } else {
  102. companyPermission, e := models.GetCompanyPermission(user.CompanyId)
  103. if e != nil {
  104. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  105. return
  106. }
  107. if companyPermission != "" {
  108. if applyCount > 0 {
  109. hasPermission = 2
  110. } else {
  111. hasPermission = 3
  112. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  113. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  114. if e != nil && e.Error() != utils.ErrNoRow() {
  115. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  116. return
  117. }
  118. if sellerItemQy != nil {
  119. sellerName = sellerItemQy.Mobile
  120. sellerMobile = sellerItemQy.RealName
  121. }
  122. }
  123. }
  124. hasPermission = 3 //弹窗逻辑变更,状态强制改为3
  125. }
  126. popupMsg = "需要升级行业套餐权限才可查看此报告,请联系对口销售"
  127. return
  128. }
  129. // 获取用户对应的权限申请状态 活动详情
  130. func GetUserHasPermissionActivity(user *models.WxUserItem, activityInfo *models.ActivityDetail) (hasPermission int, sellerName, sellerMobile, popupMsg string, err error) {
  131. //HasPermission int `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请,5:有IFCC、无权益"`
  132. uid := user.UserId
  133. applyCount, e := models.GetApplyRecordCount(uid)
  134. if e != nil {
  135. err = errors.New("GetApplyRecordCount, Err: " + e.Error())
  136. return
  137. }
  138. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  139. if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  140. if activityPointsByUserAllMap[activityInfo.ActivityId] {
  141. popupMsg = "签约研选套餐才可参与此活动,请联系对口销售"
  142. } else {
  143. popupMsg = "暂无<b>研选</b>权限<br/>您可申请开通试用"
  144. }
  145. } else {
  146. popupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  147. }
  148. if user.CompanyId == 1 {
  149. if applyCount > 0 {
  150. hasPermission = 4
  151. } else {
  152. hasPermission = 3
  153. }
  154. return
  155. }
  156. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  157. if err != nil {
  158. if err.Error() == utils.ErrNoRow() {
  159. if applyCount > 0 {
  160. hasPermission = 4
  161. } else {
  162. //获取FICC销售信息
  163. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  164. if e != nil && e.Error() != utils.ErrNoRow() {
  165. err = e
  166. return
  167. }
  168. if sellerItem != nil {
  169. hasPermission = 5
  170. } else {
  171. hasPermission = 3
  172. }
  173. }
  174. hasPermission = hasPermission
  175. if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  176. //popupMsg = "暂无<b>研选</b>权限<br/>您可申请开通试用"
  177. popupMsg = "暂无权限<br/>您可申请开通试用"
  178. } else {
  179. popupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  180. }
  181. err = nil
  182. return
  183. } else {
  184. return
  185. }
  186. }
  187. if companyItem.ProductId == 2 {
  188. hasPermission = 2
  189. sellerMobile = companyItem.Mobile
  190. sellerName = companyItem.SellerName
  191. companyPermission, e := models.GetCompanyPermission(user.CompanyId)
  192. if e != nil && e.Error() != utils.ErrNoRow() {
  193. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  194. return
  195. }
  196. if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  197. popupMsg = "暂无权限<br/>点击提交申请,提醒对口销售为你开通试用"
  198. //if !strings.Contains(companyPermission, utils.CHART_PERMISSION_NAME_YANXUAN) && (activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 5) {
  199. // //popupMsg = "暂无<b>研选</b>权限<br/>点击提交申请,提醒对口销售为你开通试用"
  200. // popupMsg = "暂无权限<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. hasPermission, e = GetUserPermissionCode(user.UserId, user.CompanyId)
  215. if e != nil {
  216. err = errors.New("GetUserDetailPermissionCode, Err: " + e.Error())
  217. return
  218. }
  219. return
  220. }
  221. // 根据公司ID获取权益销售名称
  222. func GetSellNameMapByCompanyIds(companyIds []int) (respMap map[int]string) {
  223. var err error
  224. defer func() {
  225. if err != nil {
  226. fmt.Println(err)
  227. go utils.SendAlarmMsg("根据公司ID获取权益销售名称,失败:"+err.Error()+fmt.Sprint(companyIds), 2)
  228. }
  229. }()
  230. lenarr := len(companyIds)
  231. if lenarr == 0 {
  232. return
  233. }
  234. var pars []interface{}
  235. var condition string
  236. respMap = make(map[int]string, 0)
  237. condition = " AND product_id = 2 "
  238. list, e := models.GetCompanyProductList(condition, pars)
  239. if e != nil {
  240. err = errors.New("GetCompanyProductList, Err: " + e.Error())
  241. return
  242. }
  243. for _, v := range list {
  244. respMap[v.CompanyId] = v.SellerName
  245. }
  246. return
  247. }
  248. // 获取用户对应的权限简单版
  249. func GetUserHasPermissionSimple(user *models.WxUserItem) (hasPermission int, err error) {
  250. //HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下(ficc),3:无该品类权限,已提交过申请,4:无该品类权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  251. uid := user.UserId
  252. applyCount, e := models.GetApplyRecordCount(uid)
  253. if e != nil {
  254. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  255. return
  256. }
  257. if user.CompanyId <= 1 {
  258. if applyCount == 0 {
  259. hasPermission = 5
  260. } else {
  261. hasPermission = 6
  262. }
  263. } else {
  264. companyPermission, e := models.GetCompanyPermission(user.CompanyId)
  265. if e != nil {
  266. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  267. return
  268. }
  269. if companyPermission != "" {
  270. hasPermission = 1
  271. } else {
  272. hasPermission = 3
  273. }
  274. }
  275. return
  276. }