local_life.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. fmt.Println(local.LocalId)
  78. sProjectCount, sProjectErr := db.FindSLocalByLocalIdAndSupplierId(ctx, local.LocalId, supplierId)
  79. if sProjectErr != nil {
  80. return nil, sProjectErr
  81. }
  82. if sProjectCount > 0 {
  83. local.AddToListStatus = 1
  84. } else {
  85. local.AddToListStatus = 2
  86. }
  87. }
  88. return fullLocalData, nil
  89. }
  90. // GetSpecialLocalLifeList 商单广场-定向本地生活
  91. func (*localLife) GetSpecialLocalLifeList(ctx context.Context, pageSize, pageNum int32, condition *common_model.SSpecialLocalLifeCondition) (*http_model.SpecialLocalListData, error) {
  92. // 1. 查询本地生活任务基本信息
  93. specialLocals, total, err := db.GetSpecialLocalLifeList(ctx, pageSize, pageNum, condition)
  94. if err != nil {
  95. logrus.WithContext(ctx).Errorf("[fullLocals service] call GetFullLocalLifeList error,err:%+v", err)
  96. return nil, err
  97. }
  98. var specialLocalData *http_model.SpecialLocalListData
  99. specialLocalData = &http_model.SpecialLocalListData{}
  100. specialLocalData.Total = total
  101. for _, specialLocal := range specialLocals {
  102. var specialLocalPreview *http_model.SpecialLocalPreview
  103. specialLocalPreview = &http_model.SpecialLocalPreview{}
  104. specialLocalPreview.LocalId = specialLocal.LocalId
  105. specialLocalPreview.LocalName = specialLocal.LocalName
  106. specialLocalPreview.TaskStatus = specialLocal.TaskStatus
  107. specialLocalPreview.LocalPlatform = specialLocal.LocalPlatform
  108. specialLocalPreview.TaskForm = specialLocal.TaskForm
  109. specialLocalPreview.LocalType = specialLocal.LocalType
  110. specialLocalPreview.LocalContentType = specialLocal.ContentType
  111. specialLocalPreview.SLocalStatus = specialLocal.SLocalStatus
  112. specialLocalData.SpecialLocalPreview = append(specialLocalData.SpecialLocalPreview, specialLocalPreview)
  113. }
  114. // 2. 查询本地生活补充信息:门店信息,招募策略
  115. for _, local := range specialLocalData.SpecialLocalPreview {
  116. // 2.1. 门店信息
  117. storeInfo, productErr := db.FindStoreById(ctx, local.StoreId)
  118. if productErr != nil {
  119. return nil, productErr
  120. }
  121. if storeInfo != nil {
  122. local.StoreId = storeInfo.StoreId
  123. local.StoreName = storeInfo.StoreName
  124. }
  125. // 2.2. 门店图片信息
  126. productPhotoInfo, productPhotoErr := db.GetStorePhotoByStoreID(ctx, local.StoreId)
  127. if productPhotoErr != nil {
  128. return nil, productPhotoErr
  129. }
  130. if productPhotoInfo != nil {
  131. for _, photo := range productPhotoInfo {
  132. fmt.Println(photo)
  133. if photo.Symbol == 1 {
  134. local.ProductPhotoSymbol = 1
  135. local.ProductPhotoUrl = photo.PhotoUrl
  136. local.ProductPhotoUid = photo.PhotoUid
  137. }
  138. }
  139. }
  140. // 2.3. 招募策略信息
  141. recruitStrategyInfo, recruitErr := db.GetRecruitStrategyByProjectId(ctx, local.LocalId)
  142. if recruitErr != nil {
  143. return nil, recruitErr
  144. }
  145. if recruitStrategyInfo != nil {
  146. for _, strategy := range recruitStrategyInfo {
  147. var recruitStrategy *http_model.EasyRecruitStrategy
  148. recruitStrategy = &http_model.EasyRecruitStrategy{}
  149. recruitStrategy.StrategyId = strategy.StrategyID
  150. recruitStrategy.FeeForm = strategy.FeeForm
  151. recruitStrategy.RecruitNumber = strategy.RecruitNumber
  152. local.RecruitStrategy = append(local.RecruitStrategy, recruitStrategy)
  153. }
  154. }
  155. // 2.4. 原定向本地生活任务信息
  156. localInfo, localErr := db.GetLocalLifeDetail(ctx, local.LocalId)
  157. if localErr != nil {
  158. return nil, localErr
  159. }
  160. if localInfo != nil {
  161. local.Tools = localInfo.Tools
  162. }
  163. }
  164. return specialLocalData, nil
  165. }