classify.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package pc
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_yb/global"
  6. "hongze/hongze_yb/models/response/pc"
  7. "hongze/hongze_yb/models/tables/company_product"
  8. "hongze/hongze_yb/models/tables/rddp/classify"
  9. "hongze/hongze_yb/services/user"
  10. "hongze/hongze_yb/utils"
  11. "sort"
  12. "strings"
  13. )
  14. // GetClassifyFirstList 获取一级分类列表
  15. func GetClassifyFirstList(user user.UserInfo) (list pc.ClassifyFirstList, err error) {
  16. var errMsg string
  17. defer func() {
  18. if err != nil {
  19. global.LOG.Critical(fmt.Sprintf("GetClassifyFirstList: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
  20. }
  21. }()
  22. classifyParents, err := classify.GetParentList()
  23. if err != nil {
  24. errMsg = err.Error()
  25. err = errors.New("分类查询出错")
  26. return
  27. }
  28. if len(classifyParents) == 0 {
  29. err = errors.New("分类不存在")
  30. return
  31. }
  32. classifyIconMap := make(map[string]string)
  33. classifySortMap := make(map[string]int)
  34. var names []string
  35. for _, v := range classifyParents {
  36. classifyIconMap[v.ClassifyName] = v.YbFiccPcIcon
  37. classifySortMap[v.ClassifyName] = v.YbFiccSort
  38. names = append(names, v.ClassifyName)
  39. }
  40. reportList,err := pc.GetLatestStage(names)
  41. if err != nil {
  42. errMsg = err.Error()
  43. err = errors.New("报告查询出错")
  44. return
  45. }
  46. for _, item := range classifyParents {
  47. temp := new(pc.ClassifyFirstListItem)
  48. temp.ClassifyIdFirst = item.Id
  49. temp.ClassifyNameFirst = item.ClassifyName
  50. temp.BackImgUrl = classifyIconMap[item.ClassifyName]
  51. temp.Sort = classifySortMap[item.ClassifyName]
  52. if temp.Sort == 0 {
  53. continue
  54. }
  55. // ShowType展示类型:1-列表 2-专栏; RedirectType跳转类型:1-专栏列表 2-报告列表 3-专栏详情 4-品种类型列表
  56. temp.RedirectType = 2
  57. if item.ShowType == 2 {
  58. temp.RedirectType = 1
  59. classifyChild, _ := classify.GetChildByPid(item.Id)
  60. if classifyChild != nil && len(classifyChild) == 1 {
  61. // 存在二级分类且仅有一个时直接跳转专栏详情
  62. temp.ClassifyIdSecond = classifyChild[0].Id
  63. temp.ClassifyNameSecond = classifyChild[0].ClassifyName
  64. temp.RedirectType = 3
  65. }
  66. } else if item.ShowType == 3 {
  67. temp.RedirectType = 4
  68. }
  69. list = append(list, temp)
  70. }
  71. // 判断用户状态是否是正常和永续
  72. var productAuthOk bool
  73. companyProduct, err := company_product.GetByCompany2ProductId(user.CompanyID, 1)
  74. if err == utils.ErrNoRow {
  75. err = nil
  76. return
  77. }
  78. if err != nil {
  79. errMsg = err.Error()
  80. err = errors.New("查询用户购买产品出错")
  81. return
  82. }
  83. if companyProduct != nil {
  84. // 无FICC权限的客户不可见
  85. if companyProduct.CompanyProductID > 0 {
  86. // 已购或者试用用户可见
  87. if strings.Contains("永续,正式", companyProduct.Status) || (companyProduct.Status == "试用" && companyProduct.IsSuspend != 1) {
  88. productAuthOk = true
  89. }
  90. }
  91. }
  92. for i, item := range list {
  93. //无权限用户关闭大宗商品入口
  94. if item.ClassifyNameFirst == "大宗商品" && !productAuthOk{
  95. list = append(list[:i], list[i+1:]...)
  96. }
  97. for _, report := range reportList {
  98. if report.ClassifyNameFirst == item.ClassifyNameFirst {
  99. item.Latest = report.Stage
  100. }
  101. }
  102. }
  103. if len(list) > 0 {
  104. sort.Sort(list)
  105. }
  106. return
  107. }