company_permission.go 9.2 KB

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