company_permission.go 9.3 KB

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