local_life.go 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. fmt.Println(local.LocalId)
  79. sProjectCount, sProjectErr := db.FindSLocalByLocalIdAndSupplierId(ctx, local.LocalId, supplierId)
  80. if sProjectErr != nil {
  81. return nil, sProjectErr
  82. }
  83. if sProjectCount > 0 {
  84. local.AddToListStatus = 1
  85. } else {
  86. local.AddToListStatus = 2
  87. }
  88. }
  89. return fullLocalData, nil
  90. }
  91. // GetSpecialLocalLifeList 商单广场-定向本地生活
  92. func (*localLife) GetSpecialLocalLifeList(ctx context.Context, pageSize, pageNum int32, condition *common_model.SSpecialLocalLifeCondition) (*http_model.SpecialLocalListData, error) {
  93. // 1. 查询本地生活任务基本信息
  94. specialLocals, total, err := db.GetSpecialLocalLifeList(ctx, pageSize, pageNum, condition)
  95. if err != nil {
  96. logrus.WithContext(ctx).Errorf("[fullLocals service] call GetFullLocalLifeList error,err:%+v", err)
  97. return nil, err
  98. }
  99. var specialLocalData *http_model.SpecialLocalListData
  100. specialLocalData = &http_model.SpecialLocalListData{}
  101. specialLocalData.Total = total
  102. for _, specialLocal := range specialLocals {
  103. var specialLocalPreview *http_model.SpecialLocalPreview
  104. specialLocalPreview = &http_model.SpecialLocalPreview{}
  105. specialLocalPreview.LocalId = specialLocal.LocalId
  106. specialLocalPreview.LocalName = specialLocal.LocalName
  107. specialLocalPreview.TaskStatus = specialLocal.TaskStatus
  108. specialLocalPreview.LocalPlatform = specialLocal.LocalPlatform
  109. specialLocalPreview.TaskForm = specialLocal.TaskForm
  110. specialLocalPreview.LocalType = specialLocal.LocalType
  111. specialLocalPreview.LocalContentType = specialLocal.ContentType
  112. specialLocalPreview.SLocalStatus = specialLocal.SLocalStatus
  113. specialLocalData.SpecialLocalPreview = append(specialLocalData.SpecialLocalPreview, specialLocalPreview)
  114. }
  115. // 2. 查询本地生活补充信息:门店信息,招募策略
  116. for _, local := range specialLocalData.SpecialLocalPreview {
  117. // 2.1. 门店信息
  118. storeInfo, productErr := db.FindStoreById(ctx, local.StoreId)
  119. if productErr != nil {
  120. return nil, productErr
  121. }
  122. if storeInfo != nil {
  123. local.StoreId = storeInfo.StoreId
  124. local.StoreName = storeInfo.StoreName
  125. }
  126. // 2.2. 门店图片信息
  127. productPhotoInfo, productPhotoErr := db.GetStorePhotoByStoreID(ctx, local.StoreId)
  128. if productPhotoErr != nil {
  129. return nil, productPhotoErr
  130. }
  131. if productPhotoInfo != nil {
  132. for _, photo := range productPhotoInfo {
  133. fmt.Println(photo)
  134. if photo.Symbol == 1 {
  135. local.ProductPhotoSymbol = 1
  136. local.ProductPhotoUrl = photo.PhotoUrl
  137. local.ProductPhotoUid = photo.PhotoUid
  138. }
  139. }
  140. }
  141. // 2.3. 招募策略信息
  142. recruitStrategyInfo, recruitErr := db.GetRecruitStrategyByProjectId(ctx, local.LocalId)
  143. if recruitErr != nil {
  144. return nil, recruitErr
  145. }
  146. if recruitStrategyInfo != nil {
  147. for _, strategy := range recruitStrategyInfo {
  148. var recruitStrategy *http_model.EasyRecruitStrategy
  149. recruitStrategy = &http_model.EasyRecruitStrategy{}
  150. recruitStrategy.StrategyId = strategy.StrategyID
  151. recruitStrategy.FeeForm = strategy.FeeForm
  152. recruitStrategy.RecruitNumber = strategy.RecruitNumber
  153. local.RecruitStrategy = append(local.RecruitStrategy, recruitStrategy)
  154. }
  155. }
  156. // 2.4. 原定向本地生活任务信息
  157. localInfo, localErr := db.GetLocalLifeDetail(ctx, local.LocalId)
  158. if localErr != nil {
  159. return nil, localErr
  160. }
  161. if localInfo != nil {
  162. local.Tools = localInfo.Tools
  163. }
  164. }
  165. return specialLocalData, nil
  166. }
  167. // ShowLocalLife 商单广场-本地生活详情
  168. func (*localLife) ShowLocalLife(ctx context.Context, req *http_model.ShowLocalRequest) (*http_model.ShowLocalData, error) {
  169. var localInfo *http_model.ShowLocalData
  170. localInfo = &http_model.ShowLocalData{}
  171. // 1. 查询系统信息
  172. localData, localErr := db.GetLocalLifeDetail(ctx, req.LocalId)
  173. if localErr != nil {
  174. return nil, localErr
  175. }
  176. if localData != nil {
  177. localInfo.LocalId = localData.LocalId
  178. localInfo.LocalPlatform = localData.LocalPlatform
  179. localInfo.TaskStatus = localData.TaskStatus
  180. localInfo.EnterpriseId = localData.EnterpriseId
  181. localInfo.ServiceChargeRate = localData.ServiceChargeRate
  182. localInfo.EstimatedCost = localData.EstimatedCost
  183. localInfo.CreateAt = conv.MustString(localData.CreatedAt)
  184. // 2. 关联主体
  185. // 2.1. 门店信息
  186. storeInfo, storeErr := db.FindStoreById(ctx, localData.StoreId)
  187. if storeErr != nil {
  188. return nil, storeErr
  189. }
  190. if storeInfo != nil {
  191. localInfo.StoreId = storeInfo.StoreId
  192. localInfo.StoreName = storeInfo.StoreName
  193. localInfo.StoreCategory = storeInfo.StoreCategory
  194. localInfo.StoreRelatedAt = conv.MustString(localData.StoreRelatedAt)
  195. // 2.2. 门店图片信息
  196. storePhotoInfo, storePhotoErr := db.GetStorePhotoByStoreID(ctx, localData.StoreId)
  197. if storePhotoErr != nil {
  198. return nil, storePhotoErr
  199. }
  200. if storePhotoInfo != nil {
  201. for _, photo := range storePhotoInfo {
  202. if photo.Symbol == 1 {
  203. localInfo.StoreMainPhotoSymbol = 1
  204. localInfo.StoreMainPhotoUrl = photo.PhotoUrl
  205. localInfo.StoreMainPhotoUid = photo.PhotoUid
  206. }
  207. }
  208. }
  209. }
  210. // 2.3. 团购信息
  211. teamInfo, teamErr := db.FindTeamById(ctx, localData.StoreId)
  212. if teamErr != nil {
  213. return nil, teamErr
  214. }
  215. if teamInfo != nil {
  216. localInfo.TeamBuyingId = teamInfo.StoreId
  217. localInfo.TeamBuyingName = teamInfo.TeamBuyingName
  218. localInfo.TeamBuyingCategory = teamInfo.TeamBuyingCategory
  219. localInfo.TeamBuyingRelatedAt = conv.MustString(localData.TeamBuyingRelatedAt)
  220. // 2.4. 团购图片信息
  221. teamPhotoInfo, teamPhotoErr := db.GetTeamPhotoByStoreID(ctx, localData.StoreId)
  222. if teamPhotoErr != nil {
  223. return nil, teamPhotoErr
  224. }
  225. if teamPhotoInfo != nil {
  226. for _, photo := range teamPhotoInfo {
  227. if photo.Symbol == 1 {
  228. localInfo.TeamMainPhotoSymbol = 1
  229. localInfo.TeamMainPhotoUrl = photo.PhotoUrl
  230. localInfo.TeamMainPhotoUid = photo.PhotoUid
  231. }
  232. }
  233. }
  234. }
  235. // 3. 招募要求
  236. localInfo.TalentType = localData.TalentType
  237. localInfo.RecruitDdl = conv.MustString(localData.RecruitDdl)
  238. recruitStrategy, recruitErr := db.GetRecruitStrategyByProjectId(ctx, req.LocalId)
  239. if recruitErr != nil {
  240. return nil, recruitErr
  241. }
  242. if recruitStrategy != nil {
  243. for _, strategy := range recruitStrategy {
  244. showStrategy := http_model.ShowSRecruitStrategy{
  245. StrategyID: strategy.StrategyID,
  246. FeeForm: strategy.FeeForm,
  247. FollowersLow: strategy.FollowersLow,
  248. FollowersUp: strategy.FollowersUp,
  249. RecruitNumber: strategy.RecruitNumber,
  250. Offer: strategy.Offer,
  251. }
  252. localInfo.RecruitStrategys = append(localInfo.RecruitStrategys, showStrategy)
  253. }
  254. }
  255. // 4. 执行要求
  256. localInfo.TaskForm = localData.TaskForm
  257. localInfo.ContentType = localData.ContentType
  258. briefInfo, briefErr := db.FindBriefByLocalId(ctx, req.LocalId)
  259. if briefErr != nil {
  260. return nil, briefErr
  261. }
  262. if briefInfo != nil {
  263. localInfo.LocalBrief = briefInfo
  264. }
  265. materialInfo, materialErr := db.FindMaterialByLocalId(ctx, req.LocalId)
  266. if materialErr != nil {
  267. return nil, materialErr
  268. }
  269. if materialInfo != nil {
  270. localInfo.LocalMaterial = materialInfo
  271. }
  272. }
  273. return localInfo, nil
  274. }