purchase.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package purchase
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "hongze/hongze_yb/controller/response"
  6. "hongze/hongze_yb/global"
  7. "hongze/hongze_yb/models/tables/company_product"
  8. "hongze/hongze_yb/services/purchase"
  9. userService "hongze/hongze_yb/services/user"
  10. "hongze/hongze_yb/utils"
  11. "strconv"
  12. "strings"
  13. )
  14. // List 已购列表
  15. func List(c *gin.Context) {
  16. userinfo := userService.GetInfoByClaims(c)
  17. // 判断用户是否有已购权限
  18. if userinfo.CompanyID == 0 {
  19. response.Fail("无权操作", c)
  20. return
  21. }
  22. // 判断用户状态是否是正常和永续
  23. companyProduct, err := company_product.GetByCompany2ProductId(userinfo.CompanyID, 1)
  24. if err != nil {
  25. response.Fail("无权查看", c)
  26. return
  27. }
  28. // 已购仅付费用户可见
  29. if ! strings.Contains("永续,正式", companyProduct.Status) {
  30. response.Fail("无权查看", c)
  31. return
  32. }
  33. list, err := purchase.GetLatestReportAndActivity(userinfo)
  34. if err !=nil {
  35. response.Fail(err.Error(), c)
  36. return
  37. }
  38. response.OkData("获取成功", list, c)
  39. }
  40. // Detail 已购详情
  41. func Detail(c *gin.Context) {
  42. reqClassifyIdFirst := c.DefaultQuery("classify_id_first", "")
  43. reqActivityId := c.DefaultQuery("activity_id", "")
  44. reqPageIndex := c.DefaultQuery("current_index", "1")
  45. reqPageSize := c.DefaultQuery("page_size", strconv.Itoa(utils.PageSize20))
  46. pageIndex, err := strconv.Atoi(reqPageIndex)
  47. if err != nil {
  48. response.Fail("请输入正确的条数限制", c)
  49. return
  50. }
  51. pageSize, err := strconv.Atoi(reqPageSize)
  52. if err != nil {
  53. response.Fail("请输入正确的页码", c)
  54. return
  55. }
  56. if reqClassifyIdFirst == "" && reqActivityId == "" {
  57. response.Fail("请输入分类序号或者活动序号", c)
  58. return
  59. }
  60. var activityId int
  61. if reqActivityId != "" {
  62. activityId, err = strconv.Atoi(reqActivityId)
  63. if err != nil {
  64. response.Fail("请输入正确的活动序号", c)
  65. return
  66. }
  67. }
  68. var classifyIdFirst int
  69. if reqClassifyIdFirst != ""{
  70. classifyIdFirst, err = strconv.Atoi(reqClassifyIdFirst)
  71. if err != nil {
  72. response.Fail("分类ID格式错误", c)
  73. return
  74. }
  75. }
  76. // 判断用户是否有已购权限
  77. userinfo := userService.GetInfoByClaims(c)
  78. if userinfo.CompanyID == 0 {
  79. response.Fail("无权操作", c)
  80. return
  81. }
  82. // 判断用户状态是否是正常和永续
  83. companyProduct, err := company_product.GetByCompany2ProductId(userinfo.CompanyID, 1)
  84. if err != nil {
  85. response.Fail("无权查看", c)
  86. return
  87. }
  88. // 已购仅付费用户可见
  89. if ! strings.Contains("永续,正式", companyProduct.Status) {
  90. response.Fail("无权查看", c)
  91. return
  92. }
  93. list, err := purchase.GetDetail(userinfo, classifyIdFirst, activityId, pageIndex, pageSize)
  94. if err != nil {
  95. response.Fail(err.Error(), c)
  96. global.LOG.Critical(fmt.Sprintf("userId=%d, errMsg:%s", userinfo.UserID, err.Error()))
  97. return
  98. }
  99. response.OkData("获取成功", list, c)
  100. }