user_permission.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_mfyx/models"
  6. "hongze/hongze_mfyx/models/order"
  7. "hongze/hongze_mfyx/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. func GetUserApplyRecordCount(userId int) (applyCount int, err error) {
  85. // 用户申请记录
  86. applyCount, e := models.GetApplyRecordCount(userId)
  87. if e != nil && e.Error() != utils.ErrNoRow() {
  88. err = errors.New("获取用户申请信息失败, Err: " + e.Error())
  89. return
  90. }
  91. return
  92. }
  93. // 是否需要上传名片
  94. func GetCygxUserBusinessCardCount(userId, companyId int) (isNeedBusinessCard bool) {
  95. if companyId > 1 {
  96. return
  97. }
  98. var err error
  99. defer func() {
  100. if err != nil {
  101. fmt.Println(err)
  102. go utils.SendAlarmMsg(fmt.Sprint("判断用户是否需要上传名片失败 GetCygxUserBusinessCardCount, err:", err.Error()), 2)
  103. }
  104. }()
  105. businessCardCount, e := order.GetCygxUserBusinessCardCount(userId)
  106. if e != nil && e.Error() != utils.ErrNoRow() {
  107. err = errors.New("GetCygxUserBusinessCardCount, Err: " + e.Error())
  108. return
  109. }
  110. if businessCardCount > 0 {
  111. return
  112. }
  113. isNeedBusinessCard = true
  114. return
  115. }
  116. // 获取客户是否有过历史申请记录
  117. func GetUserApplyRecordCountByCompanyIdPay(companyIdPay int) (isCompanyApply bool) {
  118. var err error
  119. defer func() {
  120. if err != nil {
  121. fmt.Println(err)
  122. go utils.SendAlarmMsg(fmt.Sprint("获取客户是否有过历史申请记录 GetUserApplyRecordCountByCompanyIdPay, err:", err.Error()), 2)
  123. }
  124. }()
  125. //if companyIdPay >= 1 {
  126. // return
  127. //}
  128. //// 客户申请
  129. //applyCount, e := models.GetApplyRecordCountByCompanyIdPay(companyIdPay)
  130. //if e != nil {
  131. // err = errors.New("GetApplyRecordCountByCompanyIdPay, Err: " + e.Error())
  132. // return
  133. //}
  134. //有研选订阅的权限的也不开放申请按钮
  135. permissionCount, e := models.GetCompanyPermissionCheck(companyIdPay, utils.CHART_PERMISSION_ID_YANXUAN)
  136. if e != nil {
  137. err = errors.New("GetCompanyPermissionCheck, Err: " + e.Error())
  138. return
  139. }
  140. //if applyCount > 0 || permissionCount > 0 {
  141. if permissionCount > 0 {
  142. isCompanyApply = true
  143. }
  144. return
  145. }
  146. // 获取用户权限状态 https://hzstatic.hzinsights.com/static/images/202402/20240205/LpE6dspJCLzfQoCoE8SFMDiLuxXk.png(状态码说明)
  147. func GetUserPermissionCode(userId, companyId int) (permission int, err error) {
  148. // 用户申请记录
  149. applyCount, e := models.GetApplyRecordCount(userId)
  150. if e != nil && e.Error() != utils.ErrNoRow() {
  151. err = errors.New("获取用户申请信息失败, Err: " + e.Error())
  152. return
  153. }
  154. if companyId == 1 {
  155. // 潜在用户
  156. if applyCount > 0 {
  157. permission = 6
  158. } else {
  159. permission = 7
  160. }
  161. } else {
  162. //权益客户
  163. raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  164. if e != nil {
  165. err = errors.New("获取用户申请信息失败, Err: " + e.Error())
  166. return
  167. }
  168. if raiCount == 1 {
  169. if applyCount > 0 {
  170. permission = 2
  171. } else {
  172. permission = 3
  173. }
  174. } else {
  175. //ficc 客户
  176. ficcCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_FICC_ID)
  177. if e != nil {
  178. err = errors.New("获取用户申请信息失败, Err: " + e.Error())
  179. return
  180. }
  181. if ficcCount == 1 {
  182. if applyCount > 0 {
  183. permission = 4
  184. } else {
  185. permission = 5
  186. }
  187. }
  188. }
  189. }
  190. return
  191. }
  192. // 用户详情页获取用户权限状态 https://hzstatic.hzinsights.com/static/images/202402/20240205/LpE6dspJCLzfQoCoE8SFMDiLuxXk.png(状态码说明)
  193. func GetUserDetailPermissionCode(userId, companyId int) (permission int, err error) {
  194. // 用户申请记录
  195. applyCount, e := GetUserApplyRecordCount(userId)
  196. if e != nil && e.Error() != utils.ErrNoRow() {
  197. err = errors.New("获取用户申请信息失败, Err: " + e.Error())
  198. return
  199. }
  200. if companyId == 1 {
  201. // 潜在用户
  202. if applyCount > 0 {
  203. permission = 6
  204. } else {
  205. permission = 7
  206. }
  207. } else {
  208. //权益客户
  209. raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  210. if e != nil {
  211. err = errors.New("获取用户申请信息失败, Err: " + e.Error())
  212. return
  213. }
  214. if raiCount == 1 {
  215. if applyCount > 0 {
  216. permission = 2
  217. } else {
  218. permission = 3
  219. }
  220. } else {
  221. //ficc 客户
  222. ficcCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_FICC_ID)
  223. if e != nil {
  224. err = errors.New("获取用户申请信息失败, Err: " + e.Error())
  225. return
  226. }
  227. if ficcCount == 1 {
  228. if applyCount > 0 {
  229. permission = 4
  230. } else {
  231. permission = 5
  232. }
  233. }
  234. }
  235. }
  236. return
  237. }
  238. // 获取权益销售姓名
  239. func GetSellerName(user *models.WxUserItem) (sellerName string, sellerId int) {
  240. var err error
  241. defer func() {
  242. if err != nil {
  243. fmt.Println(err)
  244. go utils.SendAlarmMsg(fmt.Sprint("获取权益销售姓名失败 GetSellerName, err:", err.Error()), 2)
  245. }
  246. }()
  247. companyId := user.CompanyId
  248. //潜在客户没有销售
  249. if user.CompanyId <= 1 {
  250. return
  251. }
  252. //权益客户
  253. raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  254. if e != nil {
  255. err = errors.New("GetCompanyProductCount, Err: " + e.Error())
  256. return
  257. }
  258. //仅开通FICC的客户不展示销售姓名
  259. if raiCount == 0 {
  260. return
  261. }
  262. sealldetail, e := models.GetRaiSellerByCompanyId(companyId)
  263. if e != nil {
  264. err = errors.New("GetRaiSellerByCompanyId, Err: " + e.Error())
  265. return
  266. }
  267. sellerName = sealldetail.RealName
  268. sellerId = sealldetail.AdminId
  269. return
  270. }