local_life.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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, supplierId int, condition *common_model.SSpecialLocalLifeCondition) (*http_model.SpecialLocalListData, error) {
  99. // 1. 查询本地生活任务基本信息
  100. specialLocals, total, err := db.GetSpecialLocalLifeList(ctx, pageSize, pageNum, supplierId, condition, 1)
  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. // GetSpecialSLocalLifeList 商单管理-定向本地生活
  174. func (*localLife) GetSpecialSLocalLifeList(ctx context.Context, pageSize, pageNum int32, supplierId int, condition *common_model.SSpecialLocalLifeCondition) (*http_model.SpecialSLocalListData, error) {
  175. // 1. 查询本地生活任务基本信息
  176. specialLocals, total, err := db.GetSpecialLocalLifeList(ctx, pageSize, pageNum, supplierId, condition, 2)
  177. if err != nil {
  178. logrus.WithContext(ctx).Errorf("[fullLocals service] call GetFullLocalLifeList error,err:%+v", err)
  179. return nil, err
  180. }
  181. var specialLocalData *http_model.SpecialSLocalListData
  182. specialLocalData = &http_model.SpecialSLocalListData{}
  183. specialLocalData.Total = total
  184. for _, specialLocal := range specialLocals {
  185. var specialLocalPreview *http_model.SpecialSLocalPreview
  186. specialLocalPreview = &http_model.SpecialSLocalPreview{}
  187. specialLocalPreview.LocalId = specialLocal.LocalId
  188. specialLocalPreview.LocalName = specialLocal.LocalName
  189. specialLocalPreview.TaskStatus = specialLocal.TaskStatus
  190. specialLocalPreview.LocalPlatform = specialLocal.LocalPlatform
  191. specialLocalPreview.TaskForm = specialLocal.TaskForm
  192. specialLocalPreview.LocalType = specialLocal.LocalType
  193. specialLocalPreview.LocalContentType = specialLocal.ContentType
  194. specialLocalPreview.SLocalStatus = specialLocal.SLocalStatus
  195. specialLocalData.SpecialSLocalPreview = append(specialLocalData.SpecialSLocalPreview, specialLocalPreview)
  196. }
  197. // 2. 查询本地生活补充信息:门店信息,招募策略
  198. for _, local := range specialLocalData.SpecialSLocalPreview {
  199. // 2.1. 门店信息
  200. storeInfo, productErr := db.FindStoreById(ctx, local.StoreId)
  201. if productErr != nil {
  202. return nil, productErr
  203. }
  204. if storeInfo != nil {
  205. local.StoreId = storeInfo.StoreId
  206. local.StoreName = storeInfo.StoreName
  207. }
  208. // 2.2. 门店图片信息
  209. productPhotoInfo, productPhotoErr := db.GetStorePhotoByStoreID(ctx, local.StoreId)
  210. if productPhotoErr != nil {
  211. return nil, productPhotoErr
  212. }
  213. if productPhotoInfo != nil {
  214. for _, photo := range productPhotoInfo {
  215. fmt.Println(photo)
  216. if photo.Symbol == 1 {
  217. local.ProductPhotoSymbol = 1
  218. local.ProductPhotoUrl = photo.PhotoUrl
  219. local.ProductPhotoUid = photo.PhotoUid
  220. }
  221. }
  222. }
  223. // 2.3. 招募策略信息
  224. recruitStrategyInfo, recruitErr := db.GetRecruitStrategyByProjectId(ctx, local.LocalId)
  225. if recruitErr != nil {
  226. return nil, recruitErr
  227. }
  228. if recruitStrategyInfo != nil {
  229. for _, strategy := range recruitStrategyInfo {
  230. var recruitStrategy *http_model.EasyRecruitStrategy
  231. recruitStrategy = &http_model.EasyRecruitStrategy{}
  232. recruitStrategy.StrategyId = strategy.StrategyID
  233. recruitStrategy.FeeForm = strategy.FeeForm
  234. recruitStrategy.RecruitNumber = strategy.RecruitNumber
  235. local.RecruitStrategy = append(local.RecruitStrategy, recruitStrategy)
  236. }
  237. }
  238. // 2.4. 原定向本地生活任务信息
  239. localInfo, localErr := db.GetLocalLifeDetail(ctx, local.LocalId)
  240. if localErr != nil {
  241. return nil, localErr
  242. }
  243. if localInfo != nil {
  244. local.Tools = localInfo.Tools
  245. }
  246. }
  247. return specialLocalData, nil
  248. }
  249. // ShowLocalLife 商单广场-本地生活详情
  250. func (*localLife) ShowLocalLife(ctx context.Context, req *http_model.ShowLocalRequest) (*http_model.ShowLocalData, error) {
  251. var localInfo *http_model.ShowLocalData
  252. localInfo = &http_model.ShowLocalData{}
  253. // 1. 查询系统信息
  254. localData, localErr := db.GetLocalLifeDetail(ctx, req.LocalId)
  255. if localErr != nil {
  256. return nil, localErr
  257. }
  258. if localData != nil {
  259. localInfo.LocalId = localData.LocalId
  260. localInfo.LocalPlatform = localData.LocalPlatform
  261. localInfo.TaskStatus = localData.TaskStatus
  262. localInfo.EnterpriseId = localData.EnterpriseId
  263. localInfo.ServiceChargeRate = localData.ServiceChargeRate
  264. localInfo.EstimatedCost = localData.EstimatedCost
  265. localInfo.CreateAt = conv.MustString(localData.CreatedAt)[0:19]
  266. // 2. 关联主体
  267. // 2.1. 门店信息
  268. storeInfo, storeErr := db.FindStoreById(ctx, localData.StoreId)
  269. if storeErr != nil {
  270. return nil, storeErr
  271. }
  272. if storeInfo != nil {
  273. localInfo.StoreId = storeInfo.StoreId
  274. localInfo.StoreName = storeInfo.StoreName
  275. localInfo.StoreCategory = storeInfo.StoreCategory
  276. localInfo.StoreRelatedAt = conv.MustString(localData.StoreRelatedAt)[0:19]
  277. // 2.2. 门店图片信息
  278. storePhotoInfo, storePhotoErr := db.GetStorePhotoByStoreID(ctx, localData.StoreId)
  279. if storePhotoErr != nil {
  280. return nil, storePhotoErr
  281. }
  282. if storePhotoInfo != nil {
  283. for _, photo := range storePhotoInfo {
  284. if photo.Symbol == 1 {
  285. localInfo.StoreMainPhotoSymbol = 1
  286. localInfo.StoreMainPhotoUrl = photo.PhotoUrl
  287. localInfo.StoreMainPhotoUid = photo.PhotoUid
  288. }
  289. }
  290. }
  291. }
  292. // 2.3. 团购信息
  293. // fmt.Println(localData.TeamBuyingId)
  294. teamInfo, teamErr := db.FindTeamById(ctx, localData.TeamBuyingId)
  295. if teamErr != nil {
  296. return nil, teamErr
  297. }
  298. if teamInfo != nil {
  299. localInfo.TeamBuyingId = teamInfo.TeamBuyingId
  300. localInfo.TeamBuyingName = teamInfo.TeamBuyingName
  301. localInfo.TeamBuyingCategory = teamInfo.TeamBuyingCategory
  302. localInfo.TeamBuyingRelatedAt = conv.MustString(localData.TeamBuyingRelatedAt)[0:19]
  303. // 2.4. 团购图片信息
  304. teamPhotoInfo, teamPhotoErr := db.GetTeamPhotoByTeamID(ctx, localData.TeamBuyingId)
  305. if teamPhotoErr != nil {
  306. return nil, teamPhotoErr
  307. }
  308. if teamPhotoInfo != nil {
  309. for _, photo := range teamPhotoInfo {
  310. if photo.Symbol == 1 {
  311. localInfo.TeamMainPhotoSymbol = 1
  312. localInfo.TeamMainPhotoUrl = photo.PhotoUrl
  313. localInfo.TeamMainPhotoUid = photo.PhotoUid
  314. }
  315. }
  316. }
  317. }
  318. // 3. 招募要求
  319. //localInfo.TalentType = localData.TalentType
  320. parts := strings.Split(localData.TalentType, ",")
  321. var result []int
  322. for _, part := range parts {
  323. num, strErr := strconv.Atoi(strings.TrimSpace(part))
  324. if strErr != nil {
  325. return nil, strErr
  326. }
  327. result = append(result, num)
  328. }
  329. // fmt.Println(result)
  330. talentTypeCategory, talentTypeErr := db.GetTalentCategory(ctx, result)
  331. if talentTypeErr != nil {
  332. return nil, talentTypeErr
  333. }
  334. if talentTypeCategory != nil {
  335. categories := make([]string, 0, len(talentTypeCategory))
  336. for _, talentType := range talentTypeCategory {
  337. categories = append(categories, talentType.Category)
  338. }
  339. localInfo.TalentType = strings.Join(categories, ",")
  340. }
  341. localInfo.RecruitDdl = conv.MustString(localData.RecruitDdl)[0:19]
  342. recruitStrategy, recruitErr := db.GetRecruitStrategyByProjectId(ctx, req.LocalId)
  343. if recruitErr != nil {
  344. return nil, recruitErr
  345. }
  346. if recruitStrategy != nil {
  347. for _, strategy := range recruitStrategy {
  348. showStrategy := http_model.ShowSRecruitStrategy{
  349. StrategyID: strategy.StrategyID,
  350. FeeForm: strategy.FeeForm,
  351. FollowersLow: strategy.FollowersLow,
  352. FollowersUp: strategy.FollowersUp,
  353. RecruitNumber: strategy.RecruitNumber,
  354. Offer: strategy.Offer,
  355. }
  356. localInfo.RecruitStrategys = append(localInfo.RecruitStrategys, showStrategy)
  357. }
  358. }
  359. // 4. 执行要求
  360. localInfo.TaskForm = localData.TaskForm
  361. localInfo.ContentType = localData.ContentType
  362. briefInfo, briefErr := db.FindBriefByLocalId(ctx, req.LocalId)
  363. if briefErr != nil {
  364. return nil, briefErr
  365. }
  366. if briefInfo != nil {
  367. localInfo.LocalBrief = briefInfo
  368. }
  369. materialInfo, materialErr := db.FindMaterialByLocalId(ctx, req.LocalId)
  370. if materialErr != nil {
  371. return nil, materialErr
  372. }
  373. if materialInfo != nil {
  374. localInfo.LocalMaterial = materialInfo
  375. }
  376. }
  377. return localInfo, nil
  378. }
  379. // GetStoreInfo 门店信息查找
  380. func (*localLife) GetStoreInfo(ctx context.Context, req *http_model.FindStoreRequest) (*http_model.FindStoreData, error) {
  381. var storeData *http_model.FindStoreData
  382. storeData = &http_model.FindStoreData{}
  383. // 1.1. 门店信息
  384. storeInfo, storeErr := db.FindStoreById(ctx, req.StoreID)
  385. if storeErr != nil {
  386. return nil, storeErr
  387. }
  388. if storeInfo != nil {
  389. storeData.StoreId = storeInfo.StoreId
  390. storeData.StoreName = storeInfo.StoreName
  391. storeData.StoreCategory = storeInfo.StoreCategory
  392. storeData.StoreType = storeInfo.StoreType
  393. storeData.StoreLocation = storeInfo.StoreLocation
  394. storeData.StoreDetail = storeInfo.StoreDetail
  395. storeData.StoreLink = storeInfo.StoreLink
  396. storeData.TeamNum = storeInfo.TeamNum
  397. storeData.BelongEnterpriseId = storeInfo.BelongEnterpriseId
  398. storeData.IsDeleted = storeInfo.IsDeleted
  399. storeData.OperateType = storeInfo.OperateType
  400. storeData.EnterpriseId = storeInfo.EnterpriseId
  401. storeData.SubAccountId = storeInfo.SubAccountId
  402. var Photos *http_model.StorePhoto
  403. Photos = &http_model.StorePhoto{}
  404. // 1.2. 门店图片信息
  405. storePhotoInfo, storePhotoErr := db.GetStorePhotoByStoreID(ctx, req.StoreID)
  406. if storePhotoErr != nil {
  407. return nil, storePhotoErr
  408. }
  409. if storePhotoInfo != nil {
  410. for _, photo := range storePhotoInfo {
  411. Photos.PhotoUrl = photo.PhotoUrl
  412. Photos.PhotoUid = photo.PhotoUid
  413. Photos.Symbol = photo.Symbol
  414. storeData.StorePhotos = append(storeData.StorePhotos, Photos)
  415. }
  416. }
  417. }
  418. return storeData, nil
  419. }
  420. // GetTeamBuyingInfo 团购信息查找
  421. func (*localLife) GetTeamBuyingInfo(ctx context.Context, req *http_model.FindTeamBuyingRequest) (*http_model.FindTeamBuyingData, error) {
  422. var teamBuyingData *http_model.FindTeamBuyingData
  423. teamBuyingData = &http_model.FindTeamBuyingData{}
  424. // 1.1. 门店信息
  425. teamInfo, teamErr := db.FindTeamById(ctx, req.TeamBuyingId)
  426. if teamErr != nil {
  427. return nil, teamErr
  428. }
  429. if teamInfo != nil {
  430. teamBuyingData.TeamBuyingId = teamInfo.TeamBuyingId
  431. teamBuyingData.StoreId = teamInfo.StoreId
  432. teamBuyingData.TeamBuyingCategory = teamInfo.TeamBuyingCategory
  433. teamBuyingData.TeamBuyingName = teamInfo.TeamBuyingName
  434. teamBuyingData.TeamBuyingPrice = teamInfo.TeamBuyingPrice
  435. teamBuyingData.PublicCommission = teamInfo.PublicCommission
  436. teamBuyingData.TeamBuyingDetail = teamInfo.TeamBuyingDetail
  437. teamBuyingData.TeamBuyingLink = teamInfo.TeamBuyingLink
  438. teamBuyingData.IsDeleted = teamInfo.IsDeleted
  439. teamBuyingData.OperateType = teamInfo.OperateType
  440. teamBuyingData.EnterpriseId = teamInfo.EnterpriseId
  441. teamBuyingData.SubAccountId = teamInfo.SubAccountId
  442. var Photos *http_model.TeamBuyingPhoto
  443. Photos = &http_model.TeamBuyingPhoto{}
  444. // 2.4. 团购图片信息
  445. teamPhotoInfo, teamPhotoErr := db.GetTeamPhotoByTeamID(ctx, req.TeamBuyingId)
  446. if teamPhotoErr != nil {
  447. return nil, teamPhotoErr
  448. }
  449. if teamPhotoInfo != nil {
  450. for _, photo := range teamPhotoInfo {
  451. Photos.PhotoUrl = photo.PhotoUrl
  452. Photos.PhotoUid = photo.PhotoUid
  453. Photos.Symbol = photo.Symbol
  454. teamBuyingData.TeamBuyingPhotos = append(teamBuyingData.TeamBuyingPhotos, Photos)
  455. }
  456. }
  457. }
  458. return teamBuyingData, nil
  459. }