user_permission.go 10 KB

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