company_permission.go 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. var e error
  139. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  140. hasPermission, e = GetUserPermissionCode(user.UserId, user.CompanyId)
  141. if e != nil {
  142. err = errors.New("GetUserDetailPermissionCode, Err: " + e.Error())
  143. return
  144. }
  145. if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  146. if activityPointsByUserAllMap[activityInfo.ActivityId] {
  147. popupMsg = "签约研选套餐才可参与此活动,请联系对口销售"
  148. } else {
  149. popupMsg = "暂无<b>研选</b>权限<br/>您可申请开通试用"
  150. }
  151. } else {
  152. popupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  153. }
  154. if user.CompanyId == 1 {
  155. return
  156. }
  157. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  158. if err != nil {
  159. if err.Error() == utils.ErrNoRow() {
  160. //if applyCount > 0 {
  161. // hasPermission = 4
  162. //} else {
  163. // //获取FICC销售信息
  164. // sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  165. // if e != nil && e.Error() != utils.ErrNoRow() {
  166. // err = e
  167. // return
  168. // }
  169. // if sellerItem != nil {
  170. // hasPermission = 5
  171. // } else {
  172. // hasPermission = 3
  173. // }
  174. //}
  175. //hasPermission = hasPermission
  176. if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  177. //popupMsg = "暂无<b>研选</b>权限<br/>您可申请开通试用"
  178. popupMsg = "暂无权限<br/>您可申请开通试用"
  179. } else {
  180. popupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  181. }
  182. err = nil
  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 = "暂无权限<br/>点击提交申请,提醒对口销售为你开通试用"
  199. //if !strings.Contains(companyPermission, utils.CHART_PERMISSION_NAME_YANXUAN) && (activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 5) {
  200. // //popupMsg = "暂无<b>研选</b>权限<br/>点击提交申请,提醒对口销售为你开通试用"
  201. // popupMsg = "暂无权限<br/>点击提交申请,提醒对口销售为你开通试用"
  202. //} else {
  203. // popupMsg = "签约研选套餐才可参与此活动,请联系对口销售"
  204. //}
  205. } else {
  206. if companyPermission == "专家" {
  207. popupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  208. } else {
  209. popupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  210. }
  211. }
  212. }
  213. return
  214. }
  215. // 根据公司ID获取权益销售名称
  216. func GetSellNameMapByCompanyIds(companyIds []int) (respMap map[int]string) {
  217. var err error
  218. defer func() {
  219. if err != nil {
  220. fmt.Println(err)
  221. go utils.SendAlarmMsg("根据公司ID获取权益销售名称,失败:"+err.Error()+fmt.Sprint(companyIds), 2)
  222. }
  223. }()
  224. lenarr := len(companyIds)
  225. if lenarr == 0 {
  226. return
  227. }
  228. var pars []interface{}
  229. var condition string
  230. respMap = make(map[int]string, 0)
  231. condition = " AND product_id = 2 "
  232. list, e := models.GetCompanyProductList(condition, pars)
  233. if e != nil {
  234. err = errors.New("GetCompanyProductList, Err: " + e.Error())
  235. return
  236. }
  237. for _, v := range list {
  238. respMap[v.CompanyId] = v.SellerName
  239. }
  240. return
  241. }
  242. // 获取用户对应的权限简单版
  243. func GetUserHasPermissionSimple(user *models.WxUserItem) (hasPermission int, err error) {
  244. //HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下(ficc),3:无该品类权限,已提交过申请,4:无该品类权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  245. uid := user.UserId
  246. applyCount, e := models.GetApplyRecordCount(uid)
  247. if e != nil {
  248. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  249. return
  250. }
  251. if user.CompanyId <= 1 {
  252. if applyCount == 0 {
  253. hasPermission = 5
  254. } else {
  255. hasPermission = 6
  256. }
  257. } else {
  258. companyPermission, e := models.GetCompanyPermission(user.CompanyId)
  259. if e != nil {
  260. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  261. return
  262. }
  263. if companyPermission != "" {
  264. hasPermission = 1
  265. } else {
  266. hasPermission = 3
  267. }
  268. }
  269. return
  270. }