user_permission.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/models/company"
  7. "hongze/hongze_cygx/utils"
  8. "strings"
  9. )
  10. var (
  11. UserPermissionOperationModeApply = "Apply"
  12. UserPermissionOperationModeCall = "Call"
  13. UserPermissionPopupMsgApplyActivity = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  14. UserPermissionPopupMsgCallActivity = "您暂无权限参加此活动,若想参加可以联系对口销售"
  15. UserPermissionPopupMsgApplyMicroVideo = "您暂无权限查看此视频,若想查看可以申请开通对应的试用权限"
  16. UserPermissionPopupMsgCallMicroVideo = "您暂无权限查看此视频若想查看可以联系对口销售"
  17. )
  18. // GetUserRaiPermissionInfo 获取权限类型及信息
  19. // HasPermission 是否有权限:1-有权限; 2-无权限; 3-潜在客户未提交申请; 4-潜在客户已提交申请 5-仅有FICC权限
  20. func GetUserRaiPermissionInfo(userId, companyId int) (authInfo models.UserPermissionAuthInfo, permissionArr []string, err error) {
  21. // 用户申请记录
  22. applyCount, e := models.GetApplyRecordCount(userId)
  23. if e != nil && e.Error() != utils.ErrNoRow() {
  24. err = errors.New("获取用户申请信息失败, Err: " + e.Error())
  25. return
  26. }
  27. // 潜在用户
  28. if companyId <= 1 {
  29. authInfo.HasPermission = 3
  30. if applyCount > 0 {
  31. authInfo.HasPermission = 4
  32. }
  33. authInfo.OperationMode = UserPermissionOperationModeApply
  34. authInfo.PopupMsg = UserPermissionPopupMsgApplyActivity
  35. return
  36. }
  37. // 销售信息
  38. ficcSeller, e := models.GetSellerByCompanyIdCheckFicc(companyId, utils.COMPANY_PRODUCT_FICC_ID)
  39. if e != nil && e.Error() != utils.ErrNoRow() {
  40. err = errors.New("获取FICC销售信息失败, Err: " + e.Error())
  41. return
  42. }
  43. raiSeller, e := models.GetSellerByCompanyIdCheckFicc(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  44. if e != nil && e.Error() != utils.ErrNoRow() {
  45. err = errors.New("获取权益销售信息失败, Err: " + e.Error())
  46. return
  47. }
  48. if raiSeller != nil {
  49. authInfo.SellerMobile = raiSeller.Mobile
  50. authInfo.SellerName = raiSeller.RealName
  51. }
  52. // 仅有FICC权限
  53. if ficcSeller != nil && raiSeller == nil {
  54. authInfo.HasPermission = 5
  55. authInfo.OperationMode = UserPermissionOperationModeApply
  56. authInfo.PopupMsg = UserPermissionPopupMsgApplyActivity
  57. return
  58. }
  59. // permissions示例: 医药,消费,科技,智造,策略,专家,买方研选
  60. permissions, e := models.GetCompanyPermissionName(companyId)
  61. if e != nil {
  62. err = errors.New("获取客户权限失败, Err: " + e.Error())
  63. return
  64. }
  65. if permissions == "" {
  66. // 无权益权限
  67. if raiSeller != nil {
  68. // 有销售信息
  69. authInfo.HasPermission = 2
  70. authInfo.OperationMode = UserPermissionOperationModeCall
  71. authInfo.PopupMsg = UserPermissionPopupMsgCallActivity
  72. return
  73. }
  74. // 无销售信息, 无申请, 视作潜在用户
  75. authInfo.HasPermission = 3
  76. authInfo.OperationMode = UserPermissionOperationModeApply
  77. return
  78. }
  79. // 有基本的权益权限
  80. authInfo.HasPermission = 1
  81. permissionArr = strings.Split(permissions, ",")
  82. return
  83. }
  84. // 查询研选的权限状态
  85. func GetUserRaiPermissionYanXuanInfo(user *models.WxUserItem) (hasPermission int, err error) {
  86. //判断用户是否开通了个人研选权限
  87. mfyxUserPermissionTotal := GetMfyxUserPermissionTotal(user.UserId)
  88. if mfyxUserPermissionTotal == 1 {
  89. hasPermission = 1
  90. return
  91. }
  92. var condition string
  93. var pars []interface{}
  94. condition = " AND company_id = ? AND status IN ('正式','试用') AND chart_permission_id = ? ORDER BY company_report_permission_id DESC LIMIT 1 "
  95. pars = append(pars, user.CompanyId, utils.CHART_PERMISSION_ID_YANXUAN)
  96. companyReportPermissionDetail, e := models.GetCompanyReportPermissionDetailByCondition(condition, pars)
  97. if e != nil && e.Error() != utils.ErrNoRow() {
  98. err = errors.New("GetCompanyReportPermissionDetailByCondition, Err: " + e.Error())
  99. return
  100. }
  101. //如果用户没有研选权限,那么就获取他对应的状态码
  102. if companyReportPermissionDetail == nil {
  103. hasPermission, _, _, _, e = GetUserHasPermissionArticle(user)
  104. if e != nil {
  105. err = errors.New("GetUserHasPermissionArticle, Err: " + e.Error())
  106. return
  107. }
  108. } else {
  109. hasPermission = 1
  110. }
  111. return
  112. }
  113. // 获取权益销售姓名
  114. func GetSellerName(user *models.WxUserItem) (sellerName, mobile string, sellerId int) {
  115. var err error
  116. defer func() {
  117. if err != nil {
  118. fmt.Println(err)
  119. go utils.SendAlarmMsg(fmt.Sprint("获取权益销售姓名失败 GetSellerName, err:", err.Error()), 2)
  120. }
  121. }()
  122. companyId := user.CompanyId
  123. //潜在客户没有销售
  124. if user.CompanyId <= 1 {
  125. return
  126. }
  127. //权益客户
  128. raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  129. if e != nil {
  130. err = errors.New("GetCompanyProductCount, Err: " + e.Error())
  131. return
  132. }
  133. //仅开通FICC的客户不展示销售姓名
  134. if raiCount == 0 {
  135. return
  136. }
  137. sealldetail, e := models.GetRaiSellerByCompanyId(companyId)
  138. if e != nil {
  139. err = errors.New("GetRaiSellerByCompanyId, Err: " + e.Error())
  140. return
  141. }
  142. sellerName = sealldetail.RealName
  143. sellerId = sealldetail.AdminId
  144. mobile = sealldetail.Mobile
  145. return
  146. }
  147. // 用户详情页获取用户权限状态 https://hzstatic.hzinsights.com/static/images/202402/20240205/LpE6dspJCLzfQoCoE8SFMDiLuxXk.png(状态码说明)这一期先不改2024-05-24。
  148. func GetUserDetailPermissionCode(userId, companyId int) (permission int, err error) {
  149. // 用户申请记录
  150. applyCount, e := models.GetApplyRecordCount(userId)
  151. if e != nil && e.Error() != utils.ErrNoRow() {
  152. err = errors.New("获取用户申请信息失败, Err: " + e.Error())
  153. return
  154. }
  155. if companyId == 1 {
  156. // 潜在用户
  157. if applyCount > 0 {
  158. permission = 5
  159. } else {
  160. permission = 4
  161. }
  162. } else {
  163. //权益客户
  164. raiCount, e := company.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  165. if e != nil {
  166. err = errors.New("获取用户申请信息失败, Err: " + e.Error())
  167. return
  168. }
  169. if raiCount == 1 {
  170. if applyCount > 0 {
  171. permission = 5
  172. } else {
  173. permission = 3
  174. }
  175. } else {
  176. if applyCount > 0 {
  177. permission = 5
  178. } else {
  179. permission = 2
  180. }
  181. }
  182. }
  183. return
  184. }
  185. // 获取用户权限状态 https://hzstatic.hzinsights.com/static/images/202402/20240205/LpE6dspJCLzfQoCoE8SFMDiLuxXk.png(状态码说明)
  186. func GetUserPermissionCode(userId, companyId int) (permission int, err error) {
  187. // 用户申请记录
  188. applyCount, e := models.GetApplyRecordCount(userId)
  189. if e != nil && e.Error() != utils.ErrNoRow() {
  190. err = errors.New("获取用户申请信息失败, Err: " + e.Error())
  191. return
  192. }
  193. if companyId == 1 {
  194. // 潜在用户
  195. if applyCount > 0 {
  196. permission = 6
  197. } else {
  198. permission = 7
  199. }
  200. } else {
  201. //权益客户
  202. raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  203. if e != nil {
  204. err = errors.New("获取用户申请信息失败, Err: " + e.Error())
  205. return
  206. }
  207. if raiCount == 1 {
  208. if applyCount > 0 {
  209. permission = 2
  210. } else {
  211. permission = 3
  212. }
  213. } else {
  214. //ficc 客户
  215. ficcCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_FICC_ID)
  216. if e != nil {
  217. err = errors.New("获取用户申请信息失败, Err: " + e.Error())
  218. return
  219. }
  220. if ficcCount == 1 {
  221. if applyCount > 0 {
  222. permission = 4
  223. } else {
  224. permission = 5
  225. }
  226. }
  227. }
  228. }
  229. return
  230. }