local_life.go 14 KB

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