s_local_life.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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/gorm_model"
  10. "youngee_b_api/model/http_model"
  11. )
  12. var SLcoalLife *sLocalLife
  13. type sLocalLife struct {
  14. }
  15. // CreateSLocalLife 新建服务商加入商单后的公开本地生活
  16. func (*sLocalLife) CreateSLocalLife(ctx context.Context, request *http_model.LocalLifeAddToListRequest) error {
  17. var sLocalLifeInfo *gorm_model.YounggeeSLocalLifeInfo
  18. sLocalLifeInfo = &gorm_model.YounggeeSLocalLifeInfo{}
  19. // 1. 建立SLocalLife信息
  20. // 1.1. 根据传入的LocalLifeId去LocalLife表查找信息补全SLocalLife
  21. localLifeInfo, localErr := db.GetLocalLifeDetail(ctx, request.LocalLifeId)
  22. if localErr != nil {
  23. return localErr
  24. }
  25. if localLifeInfo != nil {
  26. sLocalLifeInfo.LocalId = localLifeInfo.LocalId
  27. sLocalLifeInfo.SettleNum = 0
  28. sLocalLifeInfo.RecruitNum = 0
  29. sLocalLifeInfo.ApplyNum = 0
  30. sLocalLifeInfo.LocalType = localLifeInfo.LocalType
  31. sLocalLifeInfo.LocalPlatform = localLifeInfo.LocalPlatform
  32. sLocalLifeInfo.TaskStatus = localLifeInfo.TaskStatus
  33. sLocalLifeInfo.StoreId = localLifeInfo.StoreId
  34. sLocalLifeInfo.TeamBuyingId = localLifeInfo.TeamBuyingId
  35. sLocalLifeInfo.TaskForm = localLifeInfo.TaskForm
  36. sLocalLifeInfo.ContentType = localLifeInfo.ContentType
  37. sLocalLifeInfo.SLocalStatus = 2
  38. // 1.2. 填入加入商单操作人信息
  39. sLocalLifeInfo.SubAccountId = request.SubAccountId
  40. sLocalLifeInfo.SupplierId = request.SupplierId
  41. sLocalLifeInfo.OperatorType = request.OperatorType
  42. // 2. 入库
  43. createErr := db.CreateSLocalLife(ctx, sLocalLifeInfo)
  44. if createErr != nil {
  45. return createErr
  46. }
  47. }
  48. return nil
  49. }
  50. func (*sLocalLife) ShowSLocalLife(ctx context.Context, req *http_model.ShowSLocalRequest) (*http_model.ShowSLocalData, error) {
  51. var sLocalInfo *http_model.ShowSLocalData
  52. sLocalInfo = &http_model.ShowSLocalData{}
  53. // 1. 查询系统信息
  54. localInfo, localErr := db.GetLocalLifeDetail(ctx, req.LocalId)
  55. if localErr != nil {
  56. return nil, localErr
  57. }
  58. if localInfo != nil {
  59. sLocalInfo.LocalId = localInfo.LocalId
  60. sLocalInfo.SLocalId = req.SLocalId
  61. sLocalInfo.LocalPlatform = localInfo.LocalPlatform
  62. sLocalInfo.TaskStatus = localInfo.TaskStatus
  63. sLocalInfo.EnterpriseId = localInfo.EnterpriseId
  64. sLocalInfo.ServiceChargeRate = localInfo.ServiceChargeRate
  65. sLocalInfo.EstimatedCost = localInfo.EstimatedCost
  66. sLocalInfo.CreateAt = conv.MustString(localInfo.CreatedAt)
  67. // 2. 关联主体
  68. // 2.1. 门店信息
  69. storeInfo, storeErr := db.FindStoreById(ctx, localInfo.StoreId)
  70. if storeErr != nil {
  71. return nil, storeErr
  72. }
  73. if storeInfo != nil {
  74. sLocalInfo.StoreId = storeInfo.StoreId
  75. sLocalInfo.StoreName = storeInfo.StoreName
  76. sLocalInfo.StoreCategory = storeInfo.StoreCategory
  77. sLocalInfo.StoreRelatedAt = conv.MustString(localInfo.StoreRelatedAt)
  78. // 2.2. 门店图片信息
  79. storePhotoInfo, storePhotoErr := db.GetStorePhotoByStoreID(ctx, localInfo.StoreId)
  80. if storePhotoErr != nil {
  81. return nil, storePhotoErr
  82. }
  83. if storePhotoInfo != nil {
  84. for _, photo := range storePhotoInfo {
  85. if photo.Symbol == 1 {
  86. sLocalInfo.StoreMainPhotoSymbol = 1
  87. sLocalInfo.StoreMainPhotoUrl = photo.PhotoUrl
  88. sLocalInfo.StoreMainPhotoUid = photo.PhotoUid
  89. }
  90. }
  91. }
  92. }
  93. // 2.3. 团购信息
  94. teamInfo, teamErr := db.FindTeamById(ctx, localInfo.StoreId)
  95. if teamErr != nil {
  96. return nil, teamErr
  97. }
  98. if teamInfo != nil {
  99. sLocalInfo.TeamBuyingId = teamInfo.StoreId
  100. sLocalInfo.TeamBuyingName = teamInfo.TeamBuyingName
  101. sLocalInfo.TeamBuyingCategory = teamInfo.TeamBuyingCategory
  102. sLocalInfo.TeamBuyingRelatedAt = conv.MustString(localInfo.TeamBuyingRelatedAt)
  103. // 2.4. 团购图片信息
  104. teamPhotoInfo, teamPhotoErr := db.GetTeamPhotoByStoreID(ctx, localInfo.StoreId)
  105. if teamPhotoErr != nil {
  106. return nil, teamPhotoErr
  107. }
  108. if teamPhotoInfo != nil {
  109. for _, photo := range teamPhotoInfo {
  110. if photo.Symbol == 1 {
  111. sLocalInfo.TeamMainPhotoSymbol = 1
  112. sLocalInfo.TeamMainPhotoUrl = photo.PhotoUrl
  113. sLocalInfo.TeamMainPhotoUid = photo.PhotoUid
  114. }
  115. }
  116. }
  117. }
  118. // 3. 招募要求
  119. sLocalInfo.TalentType = localInfo.TalentType
  120. sLocalInfo.RecruitDdl = conv.MustString(localInfo.RecruitDdl)
  121. recruitStrategy, recruitErr := db.GetRecruitStrategyBySLocalId(ctx, req.SLocalId)
  122. if recruitErr != nil {
  123. return nil, recruitErr
  124. }
  125. if recruitStrategy != nil {
  126. for _, strategy := range recruitStrategy {
  127. showStrategy := http_model.ShowSRecruitStrategy{
  128. StrategyID: strategy.StrategyID,
  129. FeeForm: strategy.FeeForm,
  130. FollowersLow: strategy.FollowersLow,
  131. FollowersUp: strategy.FollowersUp,
  132. RecruitNumber: strategy.RecruitNumber,
  133. Offer: strategy.Offer,
  134. }
  135. sLocalInfo.RecruitStrategys = append(sLocalInfo.RecruitStrategys, showStrategy)
  136. }
  137. }
  138. // 4. 执行要求
  139. sLocalInfo.TaskForm = localInfo.TaskForm
  140. sLocalInfo.ContentType = localInfo.ContentType
  141. briefInfo, briefErr := db.FindBriefByLocalId(ctx, req.LocalId)
  142. if briefErr != nil {
  143. return nil, briefErr
  144. }
  145. if briefInfo != nil {
  146. sLocalInfo.LocalBrief = briefInfo
  147. }
  148. materialInfo, materialErr := db.FindMaterialByLocalId(ctx, req.LocalId)
  149. if materialErr != nil {
  150. return nil, materialErr
  151. }
  152. if materialInfo != nil {
  153. sLocalInfo.LocalMaterial = materialInfo
  154. }
  155. }
  156. return sLocalInfo, nil
  157. }
  158. func (*sLocalLife) GetFullSLocalLifeList(ctx context.Context, pageSize, pageNum int32, supplierId int, condition *common_model.SLocalLifeCondition) (*http_model.FullSLocalListData, error) {
  159. // 1. 查询本地生活任务基本信息
  160. fullLocals, total, err := db.GetFullSLocalLifeList(ctx, pageSize, pageNum, condition)
  161. if err != nil {
  162. logrus.WithContext(ctx).Errorf("[fullLocals service] call GetFullSLocalLifeList error,err:%+v", err)
  163. return nil, err
  164. }
  165. var fullLocalData *http_model.FullSLocalListData
  166. fullLocalData = &http_model.FullSLocalListData{}
  167. fullLocalData.Total = total
  168. for _, fullLocal := range fullLocals {
  169. var fullLocalPreview *http_model.FullSLocalPreview
  170. fullLocalPreview = &http_model.FullSLocalPreview{}
  171. fullLocalPreview.LocalId = fullLocal.LocalId
  172. fullLocalPreview.TaskStatus = fullLocal.TaskStatus
  173. fullLocalPreview.LocalPlatform = fullLocal.LocalPlatform
  174. fullLocalPreview.TaskForm = fullLocal.TaskForm
  175. fullLocalPreview.LocalType = fullLocal.LocalType
  176. fullLocalPreview.LocalContentType = fullLocal.ContentType
  177. fullLocalPreview.SupplierId = supplierId
  178. fullLocalPreview.SubAccountId = fullLocal.SubAccountId
  179. fullLocalPreview.OperatorType = fullLocal.OperatorType
  180. fullLocalPreview.CreateTime = conv.MustString(fullLocal.CreateTime)
  181. fullLocalPreview.ServiceCharge = fullLocal.ServiceCharge
  182. fullLocalPreview.ServiceChargeActual = fullLocal.ServiceChargeActual
  183. fullLocalPreview.ApplyNum = fullLocal.ApplyNum
  184. fullLocalPreview.RecruitNum = fullLocal.RecruitNum
  185. fullLocalPreview.SettleNum = fullLocal.SettleNum
  186. fullLocalData.FullSLocalPreview = append(fullLocalData.FullSLocalPreview, fullLocalPreview)
  187. }
  188. // 2. 查询本地生活补充信息:门店信息,招募策略
  189. for _, local := range fullLocalData.FullSLocalPreview {
  190. // 2.1. 门店信息
  191. storeInfo, productErr := db.FindStoreById(ctx, local.StoreId)
  192. if productErr != nil {
  193. return nil, productErr
  194. }
  195. if storeInfo != nil {
  196. local.StoreId = storeInfo.StoreId
  197. local.StoreName = storeInfo.StoreName
  198. }
  199. // 2.2. 门店图片信息
  200. productPhotoInfo, productPhotoErr := db.GetStorePhotoByStoreID(ctx, local.StoreId)
  201. if productPhotoErr != nil {
  202. return nil, productPhotoErr
  203. }
  204. if productPhotoInfo != nil {
  205. for _, photo := range productPhotoInfo {
  206. fmt.Println(photo)
  207. if photo.Symbol == 1 {
  208. local.ProductPhotoSymbol = 1
  209. local.ProductPhotoUrl = photo.PhotoUrl
  210. local.ProductPhotoUid = photo.PhotoUid
  211. }
  212. }
  213. }
  214. }
  215. return fullLocalData, nil
  216. }