local_life.go 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/sirupsen/logrus"
  6. "youngee_b_api/db"
  7. "youngee_b_api/model/common_model"
  8. "youngee_b_api/model/http_model"
  9. )
  10. var LocalLife *localLife
  11. type localLife struct {
  12. }
  13. func (*localLife) GetFullLocalLifeList(ctx context.Context, pageSize, pageNum int32, supplierId int, condition *common_model.SLocalLifeCondition) (*http_model.FullListData, error) {
  14. // 1. 查询本地生活任务基本信息
  15. fullLocals, total, err := db.GetFullLocalLifeList(ctx, pageSize, pageNum, condition)
  16. if err != nil {
  17. logrus.WithContext(ctx).Errorf("[fullLocals service] call GetFullLocalLifeList error,err:%+v", err)
  18. return nil, err
  19. }
  20. var fullLocalData *http_model.FullListData
  21. fullLocalData = &http_model.FullListData{}
  22. fullLocalData.Total = total
  23. for _, fullLocal := range fullLocals {
  24. var fullLocalPreview *http_model.FullPreview
  25. fullLocalPreview = &http_model.FullPreview{}
  26. fullLocalPreview.LocalId = fullLocal.LocalId
  27. fullLocalPreview.LocalName = fullLocal.LocalName
  28. fullLocalPreview.TaskStatus = fullLocal.TaskStatus
  29. fullLocalPreview.LocalPlatform = fullLocal.LocalPlatform
  30. fullLocalPreview.TaskForm = fullLocal.TaskForm
  31. fullLocalPreview.LocalType = fullLocal.LocalType
  32. fullLocalPreview.LocalContentType = fullLocal.ContentType
  33. fullLocalData.FullPreview = append(fullLocalData.FullPreview, fullLocalPreview)
  34. }
  35. // 2. 查询本地生活补充信息:门店信息,招募策略
  36. for _, local := range fullLocalData.FullPreview {
  37. // 2.1. 门店信息
  38. storeInfo, productErr := db.FindStoreById(ctx, local.StoreId)
  39. if productErr != nil {
  40. return nil, productErr
  41. }
  42. if storeInfo != nil {
  43. local.StoreId = storeInfo.StoreId
  44. local.StoreName = storeInfo.StoreName
  45. }
  46. // 2.2. 门店图片信息
  47. productPhotoInfo, productPhotoErr := db.GetStorePhotoByStoreID(ctx, local.StoreId)
  48. if productPhotoErr != nil {
  49. return nil, productPhotoErr
  50. }
  51. if productPhotoInfo != nil {
  52. for _, photo := range productPhotoInfo {
  53. fmt.Println(photo)
  54. if photo.Symbol == 1 {
  55. local.ProductPhotoSymbol = 1
  56. local.ProductPhotoUrl = photo.PhotoUrl
  57. local.ProductPhotoUid = photo.PhotoUid
  58. }
  59. }
  60. }
  61. // 2.3. 招募策略信息
  62. recruitStrategyInfo, recruitErr := db.GetRecruitStrategyByProjectId(ctx, local.LocalId)
  63. if recruitErr != nil {
  64. return nil, recruitErr
  65. }
  66. if recruitStrategyInfo != nil {
  67. for _, strategy := range recruitStrategyInfo {
  68. var recruitStrategy *http_model.EasyRecruitStrategy
  69. recruitStrategy = &http_model.EasyRecruitStrategy{}
  70. recruitStrategy.StrategyId = strategy.StrategyID
  71. recruitStrategy.FeeForm = strategy.FeeForm
  72. recruitStrategy.RecruitNumber = strategy.RecruitNumber
  73. local.RecruitStrategy = append(local.RecruitStrategy, recruitStrategy)
  74. }
  75. }
  76. // 2.4. 判断是否加入商单
  77. sProjectCount, sProjectErr := db.FindSLocalByLocalIdAndSupplierId(ctx, local.LocalId, supplierId)
  78. if sProjectErr != nil {
  79. return nil, sProjectErr
  80. }
  81. if sProjectCount > 0 {
  82. local.AddToListStatus = 1
  83. } else {
  84. local.AddToListStatus = 2
  85. }
  86. }
  87. return fullLocalData, nil
  88. }