local_life.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/issue9/conv"
  6. "github.com/sirupsen/logrus"
  7. "strconv"
  8. "strings"
  9. "youngee_b_api/db"
  10. "youngee_b_api/model/common_model"
  11. "youngee_b_api/model/http_model"
  12. )
  13. var LocalLife *localLife
  14. type localLife struct {
  15. }
  16. func (*localLife) GetFullLocalLifeList(ctx context.Context, pageSize, pageNum int32, supplierId int, condition *common_model.SLocalLifeCondition) (*http_model.FullListData, error) {
  17. // 1. 查询本地生活任务基本信息
  18. fullLocals, total, err := db.GetFullLocalLifeList(ctx, pageSize, pageNum, condition)
  19. if err != nil {
  20. logrus.WithContext(ctx).Errorf("[fullLocals service] call GetFullLocalLifeList error,err:%+v", err)
  21. return nil, err
  22. }
  23. var fullLocalData *http_model.FullListData
  24. fullLocalData = &http_model.FullListData{}
  25. fullLocalData.Total = total
  26. for _, fullLocal := range fullLocals {
  27. var fullLocalPreview *http_model.FullPreview
  28. fullLocalPreview = &http_model.FullPreview{}
  29. fullLocalPreview.LocalId = fullLocal.LocalId
  30. fullLocalPreview.EnterpriseId = fullLocal.EnterpriseId
  31. fullLocalPreview.LocalName = fullLocal.LocalName
  32. fullLocalPreview.TaskStatus = fullLocal.TaskStatus
  33. fullLocalPreview.LocalPlatform = fullLocal.LocalPlatform
  34. fullLocalPreview.TaskForm = fullLocal.TaskForm
  35. fullLocalPreview.LocalType = fullLocal.LocalType
  36. fullLocalPreview.LocalContentType = fullLocal.ContentType
  37. fullLocalPreview.StoreId = fullLocal.StoreId
  38. fullLocalPreview.RecruitDdl = conv.MustString(fullLocal.RecruitDdl)[0:19]
  39. fullLocalData.FullPreview = append(fullLocalData.FullPreview, fullLocalPreview)
  40. }
  41. // 2. 查询本地生活补充信息:门店信息,招募策略
  42. for _, local := range fullLocalData.FullPreview {
  43. // 2.1. 门店信息
  44. storeInfo, productErr := db.FindStoreById(ctx, local.StoreId)
  45. if productErr != nil {
  46. return nil, productErr
  47. }
  48. if storeInfo != nil {
  49. local.StoreId = storeInfo.StoreId
  50. local.StoreName = storeInfo.StoreName
  51. }
  52. // 2.2. 门店图片信息
  53. //fmt.Println("store_id", local.StoreId)
  54. productPhotoInfo, productPhotoErr := db.GetStorePhotoByStoreID(ctx, local.StoreId)
  55. if productPhotoErr != nil {
  56. return nil, productPhotoErr
  57. }
  58. if productPhotoInfo != nil {
  59. for _, photo := range productPhotoInfo {
  60. //fmt.Println(photo)
  61. if photo.Symbol == 1 {
  62. local.ProductPhotoSymbol = 1
  63. local.ProductPhotoUrl = photo.PhotoUrl
  64. local.ProductPhotoUid = photo.PhotoUid
  65. }
  66. }
  67. }
  68. // 2.3. 招募策略信息
  69. recruitStrategyInfo, recruitErr := db.GetRecruitStrategyByProjectId(ctx, local.LocalId)
  70. if recruitErr != nil {
  71. return nil, recruitErr
  72. }
  73. if recruitStrategyInfo != nil {
  74. for _, strategy := range recruitStrategyInfo {
  75. var recruitStrategy *http_model.EasyRecruitStrategy
  76. recruitStrategy = &http_model.EasyRecruitStrategy{}
  77. recruitStrategy.StrategyId = strategy.StrategyID
  78. recruitStrategy.FeeForm = strategy.FeeForm
  79. recruitStrategy.RecruitNumber = strategy.RecruitNumber
  80. local.RecruitStrategy = append(local.RecruitStrategy, recruitStrategy)
  81. }
  82. }
  83. // 2.4. 判断是否加入商单
  84. // fmt.Println(local.LocalId)
  85. sProjectCount, sProjectErr := db.FindSLocalByLocalIdAndSupplierId(ctx, local.LocalId, supplierId)
  86. if sProjectErr != nil {
  87. return nil, sProjectErr
  88. }
  89. if sProjectCount > 0 {
  90. local.AddToListStatus = 1
  91. } else {
  92. local.AddToListStatus = 2
  93. }
  94. }
  95. return fullLocalData, nil
  96. }
  97. // GetSpecialLocalLifeList 商单广场-定向本地生活
  98. func (*localLife) GetSpecialLocalLifeList(ctx context.Context, pageSize, pageNum int32, condition *common_model.SSpecialLocalLifeCondition) (*http_model.SpecialLocalListData, error) {
  99. // 1. 查询本地生活任务基本信息
  100. specialLocals, total, err := db.GetSpecialLocalLifeList(ctx, pageSize, pageNum, condition)
  101. if err != nil {
  102. logrus.WithContext(ctx).Errorf("[fullLocals service] call GetFullLocalLifeList error,err:%+v", err)
  103. return nil, err
  104. }
  105. var specialLocalData *http_model.SpecialLocalListData
  106. specialLocalData = &http_model.SpecialLocalListData{}
  107. specialLocalData.Total = total
  108. for _, specialLocal := range specialLocals {
  109. var specialLocalPreview *http_model.SpecialLocalPreview
  110. specialLocalPreview = &http_model.SpecialLocalPreview{}
  111. specialLocalPreview.LocalId = specialLocal.LocalId
  112. specialLocalPreview.LocalName = specialLocal.LocalName
  113. specialLocalPreview.TaskStatus = specialLocal.TaskStatus
  114. specialLocalPreview.LocalPlatform = specialLocal.LocalPlatform
  115. specialLocalPreview.TaskForm = specialLocal.TaskForm
  116. specialLocalPreview.LocalType = specialLocal.LocalType
  117. specialLocalPreview.LocalContentType = specialLocal.ContentType
  118. specialLocalPreview.SLocalStatus = specialLocal.SLocalStatus
  119. specialLocalData.SpecialLocalPreview = append(specialLocalData.SpecialLocalPreview, specialLocalPreview)
  120. }
  121. // 2. 查询本地生活补充信息:门店信息,招募策略
  122. for _, local := range specialLocalData.SpecialLocalPreview {
  123. // 2.1. 门店信息
  124. storeInfo, productErr := db.FindStoreById(ctx, local.StoreId)
  125. if productErr != nil {
  126. return nil, productErr
  127. }
  128. if storeInfo != nil {
  129. local.StoreId = storeInfo.StoreId
  130. local.StoreName = storeInfo.StoreName
  131. }
  132. // 2.2. 门店图片信息
  133. productPhotoInfo, productPhotoErr := db.GetStorePhotoByStoreID(ctx, local.StoreId)
  134. if productPhotoErr != nil {
  135. return nil, productPhotoErr
  136. }
  137. if productPhotoInfo != nil {
  138. for _, photo := range productPhotoInfo {
  139. fmt.Println(photo)
  140. if photo.Symbol == 1 {
  141. local.ProductPhotoSymbol = 1
  142. local.ProductPhotoUrl = photo.PhotoUrl
  143. local.ProductPhotoUid = photo.PhotoUid
  144. }
  145. }
  146. }
  147. // 2.3. 招募策略信息
  148. recruitStrategyInfo, recruitErr := db.GetRecruitStrategyByProjectId(ctx, local.LocalId)
  149. if recruitErr != nil {
  150. return nil, recruitErr
  151. }
  152. if recruitStrategyInfo != nil {
  153. for _, strategy := range recruitStrategyInfo {
  154. var recruitStrategy *http_model.EasyRecruitStrategy
  155. recruitStrategy = &http_model.EasyRecruitStrategy{}
  156. recruitStrategy.StrategyId = strategy.StrategyID
  157. recruitStrategy.FeeForm = strategy.FeeForm
  158. recruitStrategy.RecruitNumber = strategy.RecruitNumber
  159. local.RecruitStrategy = append(local.RecruitStrategy, recruitStrategy)
  160. }
  161. }
  162. // 2.4. 原定向本地生活任务信息
  163. localInfo, localErr := db.GetLocalLifeDetail(ctx, local.LocalId)
  164. if localErr != nil {
  165. return nil, localErr
  166. }
  167. if localInfo != nil {
  168. local.Tools = localInfo.Tools
  169. }
  170. }
  171. return specialLocalData, nil
  172. }
  173. // ShowLocalLife 商单广场-本地生活详情
  174. func (*localLife) ShowLocalLife(ctx context.Context, req *http_model.ShowLocalRequest) (*http_model.ShowLocalData, error) {
  175. var localInfo *http_model.ShowLocalData
  176. localInfo = &http_model.ShowLocalData{}
  177. // 1. 查询系统信息
  178. localData, localErr := db.GetLocalLifeDetail(ctx, req.LocalId)
  179. if localErr != nil {
  180. return nil, localErr
  181. }
  182. if localData != nil {
  183. localInfo.LocalId = localData.LocalId
  184. localInfo.LocalPlatform = localData.LocalPlatform
  185. localInfo.TaskStatus = localData.TaskStatus
  186. localInfo.EnterpriseId = localData.EnterpriseId
  187. localInfo.ServiceChargeRate = localData.ServiceChargeRate
  188. localInfo.EstimatedCost = localData.EstimatedCost
  189. localInfo.CreateAt = conv.MustString(localData.CreatedAt)[0:19]
  190. // 2. 关联主体
  191. // 2.1. 门店信息
  192. storeInfo, storeErr := db.FindStoreById(ctx, localData.StoreId)
  193. if storeErr != nil {
  194. return nil, storeErr
  195. }
  196. if storeInfo != nil {
  197. localInfo.StoreId = storeInfo.StoreId
  198. localInfo.StoreName = storeInfo.StoreName
  199. localInfo.StoreCategory = storeInfo.StoreCategory
  200. localInfo.StoreRelatedAt = conv.MustString(localData.StoreRelatedAt)[0:19]
  201. // 2.2. 门店图片信息
  202. storePhotoInfo, storePhotoErr := db.GetStorePhotoByStoreID(ctx, localData.StoreId)
  203. if storePhotoErr != nil {
  204. return nil, storePhotoErr
  205. }
  206. if storePhotoInfo != nil {
  207. for _, photo := range storePhotoInfo {
  208. if photo.Symbol == 1 {
  209. localInfo.StoreMainPhotoSymbol = 1
  210. localInfo.StoreMainPhotoUrl = photo.PhotoUrl
  211. localInfo.StoreMainPhotoUid = photo.PhotoUid
  212. }
  213. }
  214. }
  215. }
  216. // 2.3. 团购信息
  217. fmt.Println(localData.TeamBuyingId)
  218. teamInfo, teamErr := db.FindTeamById(ctx, localData.TeamBuyingId)
  219. if teamErr != nil {
  220. return nil, teamErr
  221. }
  222. if teamInfo != nil {
  223. localInfo.TeamBuyingId = teamInfo.TeamBuyingId
  224. localInfo.TeamBuyingName = teamInfo.TeamBuyingName
  225. localInfo.TeamBuyingCategory = teamInfo.TeamBuyingCategory
  226. localInfo.TeamBuyingRelatedAt = conv.MustString(localData.TeamBuyingRelatedAt)[0:19]
  227. // 2.4. 团购图片信息
  228. teamPhotoInfo, teamPhotoErr := db.GetTeamPhotoByTeamID(ctx, localData.TeamBuyingId)
  229. if teamPhotoErr != nil {
  230. return nil, teamPhotoErr
  231. }
  232. if teamPhotoInfo != nil {
  233. for _, photo := range teamPhotoInfo {
  234. if photo.Symbol == 1 {
  235. localInfo.TeamMainPhotoSymbol = 1
  236. localInfo.TeamMainPhotoUrl = photo.PhotoUrl
  237. localInfo.TeamMainPhotoUid = photo.PhotoUid
  238. }
  239. }
  240. }
  241. }
  242. // 3. 招募要求
  243. //localInfo.TalentType = localData.TalentType
  244. parts := strings.Split(localData.TalentType, ",")
  245. var result []int
  246. for _, part := range parts {
  247. num, strErr := strconv.Atoi(strings.TrimSpace(part))
  248. if strErr != nil {
  249. return nil, strErr
  250. }
  251. result = append(result, num)
  252. }
  253. fmt.Println(result)
  254. talentTypeCategory, talentTypeErr := db.GetTalentCategory(ctx, result)
  255. if talentTypeErr != nil {
  256. return nil, talentTypeErr
  257. }
  258. if talentTypeCategory != nil {
  259. categories := make([]string, 0, len(talentTypeCategory))
  260. for _, talentType := range talentTypeCategory {
  261. categories = append(categories, talentType.Category)
  262. }
  263. localInfo.TalentType = strings.Join(categories, ",")
  264. }
  265. localInfo.RecruitDdl = conv.MustString(localData.RecruitDdl)[0:19]
  266. recruitStrategy, recruitErr := db.GetRecruitStrategyByProjectId(ctx, req.LocalId)
  267. if recruitErr != nil {
  268. return nil, recruitErr
  269. }
  270. if recruitStrategy != nil {
  271. for _, strategy := range recruitStrategy {
  272. showStrategy := http_model.ShowSRecruitStrategy{
  273. StrategyID: strategy.StrategyID,
  274. FeeForm: strategy.FeeForm,
  275. FollowersLow: strategy.FollowersLow,
  276. FollowersUp: strategy.FollowersUp,
  277. RecruitNumber: strategy.RecruitNumber,
  278. Offer: strategy.Offer,
  279. }
  280. localInfo.RecruitStrategys = append(localInfo.RecruitStrategys, showStrategy)
  281. }
  282. }
  283. // 4. 执行要求
  284. localInfo.TaskForm = localData.TaskForm
  285. localInfo.ContentType = localData.ContentType
  286. briefInfo, briefErr := db.FindBriefByLocalId(ctx, req.LocalId)
  287. if briefErr != nil {
  288. return nil, briefErr
  289. }
  290. if briefInfo != nil {
  291. localInfo.LocalBrief = briefInfo
  292. }
  293. materialInfo, materialErr := db.FindMaterialByLocalId(ctx, req.LocalId)
  294. if materialErr != nil {
  295. return nil, materialErr
  296. }
  297. if materialInfo != nil {
  298. localInfo.LocalMaterial = materialInfo
  299. }
  300. }
  301. return localInfo, nil
  302. }
  303. // GetStoreInfo 门店信息查找
  304. func (*localLife) GetStoreInfo(ctx context.Context, req *http_model.FindStoreRequest) (*http_model.FindStoreData, error) {
  305. var storeData *http_model.FindStoreData
  306. storeData = &http_model.FindStoreData{}
  307. // 1.1. 门店信息
  308. storeInfo, storeErr := db.FindStoreById(ctx, req.StoreID)
  309. if storeErr != nil {
  310. return nil, storeErr
  311. }
  312. if storeInfo != nil {
  313. storeData.StoreId = storeInfo.StoreId
  314. storeData.StoreName = storeInfo.StoreName
  315. storeData.StoreCategory = storeInfo.StoreCategory
  316. storeData.StoreType = storeInfo.StoreType
  317. storeData.StoreLocation = storeInfo.StoreLocation
  318. storeData.StoreDetail = storeInfo.StoreDetail
  319. storeData.StoreLink = storeInfo.StoreLink
  320. storeData.TeamNum = storeInfo.TeamNum
  321. storeData.BelongEnterpriseId = storeInfo.BelongEnterpriseId
  322. storeData.IsDeleted = storeInfo.IsDeleted
  323. storeData.OperateType = storeInfo.OperateType
  324. storeData.EnterpriseId = storeInfo.EnterpriseId
  325. storeData.SubAccountId = storeInfo.SubAccountId
  326. var Photos *http_model.StorePhoto
  327. Photos = &http_model.StorePhoto{}
  328. // 1.2. 门店图片信息
  329. storePhotoInfo, storePhotoErr := db.GetStorePhotoByStoreID(ctx, req.StoreID)
  330. if storePhotoErr != nil {
  331. return nil, storePhotoErr
  332. }
  333. if storePhotoInfo != nil {
  334. for _, photo := range storePhotoInfo {
  335. Photos.PhotoUrl = photo.PhotoUrl
  336. Photos.PhotoUid = photo.PhotoUid
  337. Photos.Symbol = photo.Symbol
  338. storeData.StorePhotos = append(storeData.StorePhotos, Photos)
  339. }
  340. }
  341. }
  342. return storeData, nil
  343. }
  344. // GetTeamBuyingInfo 团购信息查找
  345. func (*localLife) GetTeamBuyingInfo(ctx context.Context, req *http_model.FindTeamBuyingRequest) (*http_model.FindTeamBuyingData, error) {
  346. var teamBuyingData *http_model.FindTeamBuyingData
  347. teamBuyingData = &http_model.FindTeamBuyingData{}
  348. // 1.1. 门店信息
  349. teamInfo, teamErr := db.FindTeamById(ctx, req.TeamBuyingId)
  350. if teamErr != nil {
  351. return nil, teamErr
  352. }
  353. if teamInfo != nil {
  354. teamBuyingData.TeamBuyingId = teamInfo.TeamBuyingId
  355. teamBuyingData.StoreId = teamInfo.StoreId
  356. teamBuyingData.TeamBuyingCategory = teamInfo.TeamBuyingCategory
  357. teamBuyingData.TeamBuyingName = teamInfo.TeamBuyingName
  358. teamBuyingData.TeamBuyingPrice = teamInfo.TeamBuyingPrice
  359. teamBuyingData.PublicCommission = teamInfo.PublicCommission
  360. teamBuyingData.TeamBuyingDetail = teamInfo.TeamBuyingDetail
  361. teamBuyingData.TeamBuyingLink = teamInfo.TeamBuyingLink
  362. teamBuyingData.IsDeleted = teamInfo.IsDeleted
  363. teamBuyingData.OperateType = teamInfo.OperateType
  364. teamBuyingData.EnterpriseId = teamInfo.EnterpriseId
  365. teamBuyingData.SubAccountId = teamInfo.SubAccountId
  366. var Photos *http_model.TeamBuyingPhoto
  367. Photos = &http_model.TeamBuyingPhoto{}
  368. // 2.4. 团购图片信息
  369. teamPhotoInfo, teamPhotoErr := db.GetTeamPhotoByTeamID(ctx, req.TeamBuyingId)
  370. if teamPhotoErr != nil {
  371. return nil, teamPhotoErr
  372. }
  373. if teamPhotoInfo != nil {
  374. for _, photo := range teamPhotoInfo {
  375. Photos.PhotoUrl = photo.PhotoUrl
  376. Photos.PhotoUid = photo.PhotoUid
  377. Photos.Symbol = photo.Symbol
  378. teamBuyingData.TeamBuyingPhotos = append(teamBuyingData.TeamBuyingPhotos, Photos)
  379. }
  380. }
  381. }
  382. return teamBuyingData, nil
  383. }