company_permission.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. }
  134. }
  135. popupMsg = "需要升级行业套餐权限才可查看此报告,请联系对口销售"
  136. return
  137. }
  138. // 获取用户对应的权限申请状态 活动详情
  139. func GetUserHasPermissionActivity(user *models.WxUserItem, activityInfo *models.ActivityDetail) (hasPermission int, sellerName, sellerMobile, popupMsg string, err error) {
  140. //HasPermission int `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请,5:有IFCC、无权益"`
  141. uid := user.UserId
  142. applyCount, e := models.GetApplyRecordCount(uid)
  143. if e != nil {
  144. err = errors.New("GetApplyRecordCount, Err: " + e.Error())
  145. return
  146. }
  147. activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
  148. if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  149. if activityPointsByUserAllMap[activityInfo.ActivityId] {
  150. popupMsg = "签约买方研选套餐才可参与此活动,请联系对口销售"
  151. } else {
  152. popupMsg = "暂无<b>买方研选</b>权限<br/>您可申请开通试用"
  153. }
  154. } else {
  155. popupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  156. }
  157. if user.CompanyId == 1 {
  158. if applyCount > 0 {
  159. hasPermission = 4
  160. } else {
  161. hasPermission = 3
  162. }
  163. return
  164. }
  165. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  166. if err != nil {
  167. if err.Error() == utils.ErrNoRow() {
  168. if applyCount > 0 {
  169. hasPermission = 4
  170. } else {
  171. //获取FICC销售信息
  172. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  173. if e != nil && e.Error() != utils.ErrNoRow() {
  174. err = e
  175. return
  176. }
  177. if sellerItem != nil {
  178. hasPermission = 5
  179. } else {
  180. hasPermission = 3
  181. }
  182. }
  183. hasPermission = hasPermission
  184. if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  185. popupMsg = "暂无<b>买方研选</b>权限<br/>您可申请开通试用"
  186. } else {
  187. popupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  188. }
  189. return
  190. } else {
  191. return
  192. }
  193. }
  194. if companyItem.ProductId == 2 {
  195. hasPermission = 2
  196. sellerMobile = companyItem.Mobile
  197. sellerName = companyItem.SellerName
  198. companyPermission, e := models.GetCompanyPermission(user.CompanyId)
  199. if e != nil && e.Error() != utils.ErrNoRow() {
  200. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  201. return
  202. }
  203. if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  204. //popupMsg = "暂无<b>买方研选</b>权限<br/>点击提交申请,提醒对口销售为你开通试用"
  205. if !strings.Contains(companyPermission, utils.CHART_PERMISSION_NAME_YANXUAN) && (activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 5) {
  206. popupMsg = "暂无<b>买方研选</b>权限<br/>点击提交申请,提醒对口销售为你开通试用"
  207. } else {
  208. popupMsg = "签约买方研选套餐才可参与此活动,请联系对口销售"
  209. }
  210. } else {
  211. if companyPermission == "专家" {
  212. popupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  213. } else {
  214. popupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  215. }
  216. }
  217. } else {
  218. hasPermission = 5
  219. }
  220. return
  221. }
  222. // 根据公司ID获取权益销售名称
  223. func GetSellNameMapByCompanyIds(companyIds []int) (respMap map[int]string) {
  224. var err error
  225. defer func() {
  226. if err != nil {
  227. fmt.Println(err)
  228. go utils.SendAlarmMsg("根据公司ID获取权益销售名称,失败:"+err.Error()+fmt.Sprint(companyIds), 2)
  229. }
  230. }()
  231. lenarr := len(companyIds)
  232. if lenarr == 0 {
  233. return
  234. }
  235. var pars []interface{}
  236. var condition string
  237. respMap = make(map[int]string, 0)
  238. condition = " AND product_id = 2 "
  239. list, e := models.GetCompanyProductList(condition, pars)
  240. if e != nil {
  241. err = errors.New("GetCompanyProductList, Err: " + e.Error())
  242. return
  243. }
  244. for _, v := range list {
  245. respMap[v.CompanyId] = v.SellerName
  246. }
  247. return
  248. }
  249. // 获取用户对应的权限简单版
  250. func GetUserHasPermissionSimple(user *models.WxUserItem) (hasPermission int, err error) {
  251. //HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下(ficc),3:无该品类权限,已提交过申请,4:无该品类权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  252. uid := user.UserId
  253. applyCount, e := models.GetApplyRecordCount(uid)
  254. if e != nil {
  255. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  256. return
  257. }
  258. if user.CompanyId <= 1 {
  259. if applyCount == 0 {
  260. hasPermission = 5
  261. } else {
  262. hasPermission = 6
  263. }
  264. } else {
  265. companyPermission, e := models.GetCompanyPermission(user.CompanyId)
  266. if e != nil {
  267. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  268. return
  269. }
  270. if companyPermission != "" {
  271. hasPermission = 1
  272. } else {
  273. hasPermission = 3
  274. }
  275. }
  276. return
  277. }
  278. // GetPermissionNameMap 权限名称与权限ID的map
  279. func GetPermissionNameMap() (mapItem map[int]string, err error) {
  280. list, e := models.GetChartPermissionListRai()
  281. if e != nil {
  282. err = e
  283. return
  284. }
  285. mapPermissionName := make(map[int]string)
  286. for _, v := range list {
  287. mapPermissionName[v.ChartPermissionId] = v.PermissionName
  288. }
  289. mapItem = mapPermissionName
  290. return
  291. }
  292. func GetPermissionNameIcoMap() (mapItem map[int]string, err error) {
  293. list, e := models.GetChartPermissionListRai()
  294. if e != nil {
  295. err = e
  296. return
  297. }
  298. mapPermissionName := make(map[int]string)
  299. for _, v := range list {
  300. mapPermissionName[v.ChartPermissionId] = v.ImageUrlM
  301. }
  302. mapItem = mapPermissionName
  303. return
  304. }