purchase.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package purchase
  2. import (
  3. "errors"
  4. "hongze/hongze_yb/models/response/purchase"
  5. activity2 "hongze/hongze_yb/services/activity"
  6. "hongze/hongze_yb/services/company"
  7. "hongze/hongze_yb/services/report"
  8. "hongze/hongze_yb/services/user"
  9. "sort"
  10. "sync"
  11. )
  12. func GetLatestReportAndActivity(user user.UserInfo) (list purchase.PurchaseList, err error) {
  13. permissionIds, err := company.GetPurchasePermissionIdsByCompany2ProductId(user.CompanyID, 1)
  14. if err != nil {
  15. return
  16. }
  17. if len(permissionIds) == 0 {
  18. err = errors.New("用户无权限")
  19. return
  20. }
  21. w := sync.WaitGroup{}
  22. //查找最新的报告
  23. w.Add(1)
  24. go func() {
  25. defer w.Done()
  26. list, err = report.GetLatestClassReport(permissionIds, user.UserID)
  27. }()
  28. //查找最新的活动
  29. w.Add(1)
  30. var purItem *purchase.PurchaseListItem
  31. var err2 error
  32. go func() {
  33. defer w.Done()
  34. purItem, err2 = activity2.GetLatestActivity(permissionIds, user.UserID)
  35. }()
  36. w.Wait()
  37. if err != nil {
  38. return
  39. }
  40. if err2 != nil {
  41. err = err2
  42. return
  43. }
  44. list = append(list, purItem)
  45. if len(list) > 0 {
  46. sort.Sort(list)
  47. }
  48. return
  49. }
  50. // GetDetail 已购详情页面
  51. func GetDetail(user user.UserInfo, classifyIdFirst int, activityId, pageIndex, pageSize int) (ret *purchase.DetailResp, err error) {
  52. permissionIds, err := company.GetPurchasePermissionIdsByCompany2ProductId(user.CompanyID, 1)
  53. if err != nil {
  54. return
  55. }
  56. if len(permissionIds) <= 0 {
  57. err = errors.New("用户无权限")
  58. return
  59. }
  60. if classifyIdFirst != 0 {
  61. ret, err = report.GetPurchaseDetail(permissionIds, user.UserID, classifyIdFirst, pageIndex, pageSize)
  62. }else if activityId > 0 {
  63. ret, err = activity2.GetPurchaseDetail(permissionIds, user.UserID, pageIndex, pageSize)
  64. }
  65. return
  66. }