user_yanxuan_permission.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. "time"
  9. )
  10. // 判断用户是否开通了个人研选权限
  11. func GetMfyxUserPermissionTotal(userId int) (toatal int) {
  12. var err error
  13. defer func() {
  14. if err != nil {
  15. fmt.Println(err)
  16. go utils.SendAlarmMsg(fmt.Sprint("判断用户是否开通了个人研选权限失败 GetMfyxUserPermissionTotal userId", userId, ",err:", err.Error()), 2)
  17. }
  18. }()
  19. //判断用户是否开通了个人研选权限,如果有权限后缀拼接权限名称
  20. toatal, e := models.GetCygxUserYanxuanPermissionCountByUserId(userId)
  21. if e != nil {
  22. err = errors.New("GetCygxUserYanxuanPermissionCountByUserId, Err: " + e.Error())
  23. return
  24. }
  25. return
  26. }
  27. // 查询研选的权限状态
  28. func GetUserRaiPermissionYanXuanInfo(user *models.WxUserItem) (hasPermission int, err error) {
  29. uid := user.UserId
  30. applyCount, e := models.GetApplyRecordCount(uid)
  31. if e != nil {
  32. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  33. return
  34. }
  35. if user.CompanyId <= 1 {
  36. if applyCount == 0 {
  37. hasPermission = 4
  38. } else {
  39. hasPermission = 5
  40. }
  41. } else {
  42. hasPermission = 3
  43. }
  44. //判断用户是否开通了个人研选权限
  45. mfyxUserPermissionTotal := GetMfyxUserPermissionTotal(user.UserId)
  46. if mfyxUserPermissionTotal == 1 {
  47. hasPermission = 1
  48. return
  49. }
  50. var condition string
  51. var pars []interface{}
  52. condition = " AND company_id = ? AND status IN ('正式','试用') AND chart_permission_id = ? ORDER BY company_report_permission_id DESC LIMIT 1 "
  53. pars = append(pars, user.CompanyId, utils.CHART_PERMISSION_ID_YANXUAN)
  54. companyReportPermissionDetail, e := models.GetCompanyReportPermissionDetailByCondition(condition, pars)
  55. if e != nil && e.Error() != utils.ErrNoRow() {
  56. err = errors.New("GetCompanyReportPermissionDetailByCondition, Err: " + e.Error())
  57. return
  58. }
  59. //如果用户没有研选权限,那么就获取他对应的状态码
  60. if companyReportPermissionDetail == nil {
  61. hasPermission, _, _, _, e = GetUserHasPermissionArticle(user)
  62. if e != nil {
  63. err = errors.New("GetUserHasPermissionArticle, Err: " + e.Error())
  64. return
  65. }
  66. } else {
  67. hasPermission = 1
  68. }
  69. return
  70. }
  71. // 判断用户是否持有阅读卡
  72. func GetCygxOrderUserCardTotal(mobile string) (total int) {
  73. var err error
  74. defer func() {
  75. if err != nil {
  76. fmt.Println(err)
  77. go utils.SendAlarmMsg(fmt.Sprint("判断用户是否持有阅读卡失败 GetCygxOrderUserCardTotal mobile", mobile, ",err:", err.Error()), 2)
  78. }
  79. }()
  80. var condition string
  81. var pars []interface{}
  82. condition += ` AND mobile = ? AND is_suspend = 0 AND start_date < ? AND end_date > ? `
  83. pars = append(pars, mobile, time.Now(), time.Now())
  84. total, e := order.GetCygxOrderUserCardCount(condition, pars)
  85. if e != nil {
  86. err = errors.New("GetCygxUserYanxuanPermissionCountByUserId, Err: " + e.Error())
  87. return
  88. }
  89. return
  90. }
  91. // 判断用户是购买了单场付费活动
  92. func GetCygxOrderVirtualAssetdCountTotal(mobile string, activityId int) (total int) {
  93. var err error
  94. defer func() {
  95. if err != nil {
  96. fmt.Println(err)
  97. go utils.SendAlarmMsg(fmt.Sprint("判断用户是购买了单场付费活动失败 GetCygxOrderUserCardTotal mobile", mobile, "activityId:", activityId, ",err:", err.Error()), 2)
  98. }
  99. }()
  100. var condition string
  101. var pars []interface{}
  102. condition += ` AND mobile = ? AND source = 'activity' AND source_id = ? `
  103. pars = append(pars, mobile, activityId)
  104. total, e := order.GetCygxOrderVirtualAssetdCount(condition, pars)
  105. if e != nil {
  106. err = errors.New("GetCygxOrderVirtualAssetdCount, Err: " + e.Error())
  107. return
  108. }
  109. return
  110. }