local_life.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/issue9/conv"
  6. "github.com/sirupsen/logrus"
  7. "youngee_b_api/db"
  8. "youngee_b_api/model/common_model"
  9. "youngee_b_api/model/http_model"
  10. )
  11. var LocalLife *localLife
  12. type localLife struct {
  13. }
  14. func (*localLife) GetFullLocalLifeList(ctx context.Context, pageSize, pageNum int32, supplierId int, condition *common_model.SLocalLifeCondition) (*http_model.FullListData, error) {
  15. // 1. 查询本地生活任务基本信息
  16. fullLocals, total, err := db.GetFullLocalLifeList(ctx, pageSize, pageNum, condition)
  17. if err != nil {
  18. logrus.WithContext(ctx).Errorf("[fullLocals service] call GetFullLocalLifeList error,err:%+v", err)
  19. return nil, err
  20. }
  21. var fullLocalData *http_model.FullListData
  22. fullLocalData = &http_model.FullListData{}
  23. fullLocalData.Total = total
  24. for _, fullLocal := range fullLocals {
  25. var fullLocalPreview *http_model.FullPreview
  26. fullLocalPreview = &http_model.FullPreview{}
  27. fullLocalPreview.LocalId = fullLocal.LocalId
  28. fullLocalPreview.LocalName = fullLocal.LocalName
  29. fullLocalPreview.TaskStatus = fullLocal.TaskStatus
  30. fullLocalPreview.LocalPlatform = fullLocal.LocalPlatform
  31. fullLocalPreview.TaskForm = fullLocal.TaskForm
  32. fullLocalPreview.LocalType = fullLocal.LocalType
  33. fullLocalPreview.LocalContentType = fullLocal.ContentType
  34. fullLocalData.FullPreview = append(fullLocalData.FullPreview, fullLocalPreview)
  35. }
  36. // 2. 查询本地生活补充信息:门店信息,招募策略
  37. for _, local := range fullLocalData.FullPreview {
  38. // 2.1. 门店信息
  39. storeInfo, productErr := db.FindStoreById(ctx, local.StoreId)
  40. if productErr != nil {
  41. return nil, productErr
  42. }
  43. if storeInfo != nil {
  44. local.StoreId = storeInfo.StoreId
  45. local.StoreName = storeInfo.StoreName
  46. }
  47. // 2.2. 门店图片信息
  48. productPhotoInfo, productPhotoErr := db.GetStorePhotoByStoreID(ctx, local.StoreId)
  49. if productPhotoErr != nil {
  50. return nil, productPhotoErr
  51. }
  52. if productPhotoInfo != nil {
  53. for _, photo := range productPhotoInfo {
  54. fmt.Println(photo)
  55. if photo.Symbol == 1 {
  56. local.ProductPhotoSymbol = 1
  57. local.ProductPhotoUrl = photo.PhotoUrl
  58. local.ProductPhotoUid = photo.PhotoUid
  59. }
  60. }
  61. }
  62. // 2.3. 招募策略信息
  63. recruitStrategyInfo, recruitErr := db.GetRecruitStrategyByProjectId(ctx, local.LocalId)
  64. if recruitErr != nil {
  65. return nil, recruitErr
  66. }
  67. if recruitStrategyInfo != nil {
  68. for _, strategy := range recruitStrategyInfo {
  69. var recruitStrategy *http_model.EasyRecruitStrategy
  70. recruitStrategy = &http_model.EasyRecruitStrategy{}
  71. recruitStrategy.StrategyId = strategy.StrategyID
  72. recruitStrategy.FeeForm = strategy.FeeForm
  73. recruitStrategy.RecruitNumber = strategy.RecruitNumber
  74. local.RecruitStrategy = append(local.RecruitStrategy, recruitStrategy)
  75. }
  76. }
  77. // 2.4. 判断是否加入商单
  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. func (*localLife) GetFullSLocalLifeList(ctx context.Context, pageSize, pageNum int32, supplierId int, condition *common_model.SLocalLifeCondition) (*http_model.FullSLocalListData, error) {
  91. // 1. 查询本地生活任务基本信息
  92. fullLocals, total, err := db.GetFullSLocalLifeList(ctx, pageSize, pageNum, condition)
  93. if err != nil {
  94. logrus.WithContext(ctx).Errorf("[fullLocals service] call GetFullSLocalLifeList error,err:%+v", err)
  95. return nil, err
  96. }
  97. var fullLocalData *http_model.FullSLocalListData
  98. fullLocalData = &http_model.FullSLocalListData{}
  99. fullLocalData.Total = total
  100. for _, fullLocal := range fullLocals {
  101. var fullLocalPreview *http_model.FullSLocalPreview
  102. fullLocalPreview = &http_model.FullSLocalPreview{}
  103. fullLocalPreview.LocalId = fullLocal.LocalId
  104. fullLocalPreview.TaskStatus = fullLocal.TaskStatus
  105. fullLocalPreview.LocalPlatform = fullLocal.LocalPlatform
  106. fullLocalPreview.TaskForm = fullLocal.TaskForm
  107. fullLocalPreview.LocalType = fullLocal.LocalType
  108. fullLocalPreview.LocalContentType = fullLocal.ContentType
  109. fullLocalPreview.SupplierId = supplierId
  110. fullLocalPreview.SubAccountId = fullLocal.SubAccountId
  111. fullLocalPreview.OperatorType = fullLocal.OperatorType
  112. fullLocalPreview.CreateTime = conv.MustString(fullLocal.CreateTime)
  113. fullLocalPreview.ServiceCharge = fullLocal.ServiceCharge
  114. fullLocalPreview.ServiceChargeActual = fullLocal.ServiceChargeActual
  115. fullLocalPreview.ApplyNum = fullLocal.ApplyNum
  116. fullLocalPreview.RecruitNum = fullLocal.RecruitNum
  117. fullLocalPreview.SettleNum = fullLocal.SettleNum
  118. fullLocalData.FullSLocalPreview = append(fullLocalData.FullSLocalPreview, fullLocalPreview)
  119. }
  120. // 2. 查询本地生活补充信息:门店信息,招募策略
  121. for _, local := range fullLocalData.FullSLocalPreview {
  122. // 2.1. 门店信息
  123. storeInfo, productErr := db.FindStoreById(ctx, local.StoreId)
  124. if productErr != nil {
  125. return nil, productErr
  126. }
  127. if storeInfo != nil {
  128. local.StoreId = storeInfo.StoreId
  129. local.StoreName = storeInfo.StoreName
  130. }
  131. // 2.2. 门店图片信息
  132. productPhotoInfo, productPhotoErr := db.GetStorePhotoByStoreID(ctx, local.StoreId)
  133. if productPhotoErr != nil {
  134. return nil, productPhotoErr
  135. }
  136. if productPhotoInfo != nil {
  137. for _, photo := range productPhotoInfo {
  138. fmt.Println(photo)
  139. if photo.Symbol == 1 {
  140. local.ProductPhotoSymbol = 1
  141. local.ProductPhotoUrl = photo.PhotoUrl
  142. local.ProductPhotoUid = photo.PhotoUid
  143. }
  144. }
  145. }
  146. }
  147. return fullLocalData, nil
  148. }