company_permission.go 11 KB

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