s_local_life.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/gin-gonic/gin"
  6. "github.com/issue9/conv"
  7. "github.com/sirupsen/logrus"
  8. "strconv"
  9. "strings"
  10. "time"
  11. "youngee_b_api/db"
  12. "youngee_b_api/model/common_model"
  13. "youngee_b_api/model/gorm_model"
  14. "youngee_b_api/model/http_model"
  15. )
  16. var SLocalLife *sLocalLife
  17. type sLocalLife struct {
  18. }
  19. // CreateSLocalLife 新建服务商加入商单后的公开本地生活
  20. func (*sLocalLife) CreateSLocalLife(ctx context.Context, request *http_model.LocalLifeAddToListRequest) error {
  21. var sLocalLifeInfo *gorm_model.YounggeeSLocalLifeInfo
  22. sLocalLifeInfo = &gorm_model.YounggeeSLocalLifeInfo{}
  23. // 1. 建立SLocalLife信息
  24. // 1.1. 根据传入的LocalLifeId去LocalLife表查找信息补全SLocalLife
  25. localLifeInfo, localErr := db.GetLocalLifeDetail(ctx, request.LocalId)
  26. if localErr != nil {
  27. return localErr
  28. }
  29. if localLifeInfo != nil {
  30. sLocalLifeInfo.LocalId = localLifeInfo.LocalId
  31. sLocalLifeInfo.SettleNum = 0
  32. sLocalLifeInfo.RecruitNum = 0
  33. sLocalLifeInfo.ApplyNum = 0
  34. sLocalLifeInfo.EnterpriseId = localLifeInfo.EnterpriseId
  35. sLocalLifeInfo.LocalType = localLifeInfo.LocalType
  36. sLocalLifeInfo.LocalName = localLifeInfo.LocalName
  37. sLocalLifeInfo.LocalPlatform = localLifeInfo.LocalPlatform
  38. sLocalLifeInfo.TaskStatus = localLifeInfo.TaskStatus
  39. sLocalLifeInfo.StoreId = localLifeInfo.StoreId
  40. sLocalLifeInfo.TeamBuyingId = localLifeInfo.TeamBuyingId
  41. sLocalLifeInfo.TaskForm = localLifeInfo.TaskForm
  42. sLocalLifeInfo.ContentType = localLifeInfo.ContentType
  43. sLocalLifeInfo.SLocalStatus = 2
  44. // 1.2. 填入加入商单操作人信息
  45. var operatorType int
  46. if request.SubAccountId == 0 {
  47. operatorType = 1
  48. } else {
  49. operatorType = 2
  50. }
  51. sLocalLifeInfo.SubAccountId = request.SubAccountId
  52. sLocalLifeInfo.SupplierId = request.SupplierId
  53. sLocalLifeInfo.OperatorType = operatorType
  54. currTime := time.Now()
  55. sLocalLifeInfo.CreateTime = &currTime
  56. // 2. 入库
  57. sLocalId, createErr := db.CreateSLocalLife(ctx, sLocalLifeInfo)
  58. if createErr != nil {
  59. return createErr
  60. }
  61. // 2. 建立新的recruitStrategy
  62. // 2.1. 根据localId去查找原来的recruitStrategy
  63. recruitStrategys, strategyErr := db.GetRecruitStrategyByProjectId(ctx, request.LocalId)
  64. if strategyErr != nil {
  65. return strategyErr
  66. }
  67. // 2.2. 设置新的结构体以写入
  68. var currRecruitStrategys []gorm_model.RecruitStrategy
  69. for _, strategy := range recruitStrategys {
  70. var currStrategy gorm_model.RecruitStrategy
  71. currStrategy.StrategyID = strategy.StrategyID
  72. currStrategy.QuoteRecruitStrategyId = int(strategy.RecruitStrategyID)
  73. currStrategy.FeeForm = strategy.FeeForm
  74. currStrategy.FollowersLow = strategy.FollowersLow
  75. currStrategy.FollowersUp = strategy.FollowersUp
  76. currStrategy.RecruitNumber = strategy.RecruitNumber
  77. currStrategy.Offer = strategy.Offer
  78. currStrategy.TOffer = strategy.TOffer
  79. currStrategy.ProjectID = "0"
  80. currStrategy.ServiceCharge = strategy.ServiceCharge
  81. currStrategy.ServiceRate = strategy.ServiceRate
  82. currStrategy.SLocalId = sLocalId
  83. currStrategy.StrategyType = 2
  84. currRecruitStrategys = append(currRecruitStrategys, currStrategy)
  85. }
  86. // 2.3. 写入
  87. createStrategyErr := db.CreateSpecialStrategy(ctx, currRecruitStrategys)
  88. if createStrategyErr != nil {
  89. return createStrategyErr
  90. }
  91. }
  92. return nil
  93. }
  94. func (*sLocalLife) ShowSLocalLife(ctx context.Context, req *http_model.ShowSLocalRequest) (*http_model.ShowSLocalData, error) {
  95. var sLocalInfo *http_model.ShowSLocalData
  96. sLocalInfo = &http_model.ShowSLocalData{}
  97. // 1. 查询系统信息
  98. localInfo, localErr := db.GetLocalLifeDetail(ctx, req.LocalId)
  99. if localErr != nil {
  100. return nil, localErr
  101. }
  102. if localInfo != nil {
  103. sLocalInfo.CreateAt = conv.MustString(localInfo.CreatedAt)[0:19]
  104. sLocalInfo.LocalId = localInfo.LocalId
  105. sLocalInfo.LocalName = localInfo.LocalName
  106. sLocalInfo.CreatorName = localInfo.EnterpriseId
  107. sLocalInfo.Donate = localInfo.Donate
  108. sLocalInfo.SLocalId = req.SLocalId
  109. sLocalInfo.LocalPlatform = localInfo.LocalPlatform
  110. sLocalInfo.TaskStatus = localInfo.TaskStatus
  111. sLocalInfo.EnterpriseId = localInfo.EnterpriseId
  112. sLocalInfo.Tools = localInfo.Tools
  113. sLocalInfo.ServiceChargeRate = localInfo.ServiceChargeRate
  114. if localInfo.PayAt != nil {
  115. sLocalInfo.PayAt = conv.MustString(localInfo.PayAt)[0:19]
  116. }
  117. sLocalInfo.EstimatedCost = 0.0
  118. sLocalInfo.CreatorName = localInfo.EnterpriseId
  119. sLocal, sLocalErr := db.GetSLocalLifeDetail(ctx, req.SLocalId)
  120. if sLocalErr != nil {
  121. return nil, sLocalErr
  122. }
  123. if sLocal != nil {
  124. if sLocal.OperatorType == 1 {
  125. sLocalInfo.AddToListOperator = conv.MustString(sLocal.SupplierId)
  126. } else {
  127. sLocalInfo.AddToListOperator = conv.MustString(sLocal.SubAccountId)
  128. }
  129. if sLocal.CreateTime != nil {
  130. sLocalInfo.AgreeTime = conv.MustString(sLocal.CreateTime)[0:19]
  131. }
  132. if sLocal.RejectTime != nil {
  133. sLocalInfo.RejectTime = conv.MustString(sLocal.RejectTime)[0:19]
  134. }
  135. }
  136. // 2. 关联主体
  137. // 2.1. 门店信息
  138. storeInfo, storeErr := db.FindStoreById(ctx, localInfo.StoreId)
  139. if storeErr != nil {
  140. return nil, storeErr
  141. }
  142. if storeInfo != nil {
  143. sLocalInfo.StoreId = storeInfo.StoreId
  144. sLocalInfo.StoreName = storeInfo.StoreName
  145. sLocalInfo.StoreCategory = storeInfo.StoreCategory
  146. sLocalInfo.StoreLocation = storeInfo.StoreLocation
  147. sLocalInfo.TeamNum = storeInfo.TeamNum
  148. sLocalInfo.StoreRelatedAt = conv.MustString(localInfo.StoreRelatedAt)
  149. // 2.2. 门店图片信息
  150. storePhotoInfo, storePhotoErr := db.GetStorePhotoByStoreID(ctx, localInfo.StoreId)
  151. if storePhotoErr != nil {
  152. return nil, storePhotoErr
  153. }
  154. if storePhotoInfo != nil {
  155. for _, photo := range storePhotoInfo {
  156. if photo.Symbol == 1 {
  157. sLocalInfo.StoreMainPhotoSymbol = 1
  158. sLocalInfo.StoreMainPhotoUrl = photo.PhotoUrl
  159. sLocalInfo.StoreMainPhotoUid = photo.PhotoUid
  160. }
  161. }
  162. }
  163. }
  164. // 2.3. 团购信息
  165. teamInfo, teamErr := db.FindTeamById(ctx, localInfo.TeamBuyingId)
  166. if teamErr != nil {
  167. return nil, teamErr
  168. }
  169. if teamInfo != nil {
  170. sLocalInfo.TeamBuyingPrice = teamInfo.TeamBuyingPrice
  171. sLocalInfo.TeamBuyingId = teamInfo.TeamBuyingId
  172. sLocalInfo.TeamBuyingName = teamInfo.TeamBuyingName
  173. sLocalInfo.TeamBuyingCategory = teamInfo.TeamBuyingCategory
  174. sLocalInfo.TeamBuyingRelatedAt = conv.MustString(localInfo.TeamBuyingRelatedAt)
  175. // 2.4. 团购图片信息
  176. teamPhotoInfo, teamPhotoErr := db.GetTeamPhotoByTeamID(ctx, localInfo.TeamBuyingId)
  177. if teamPhotoErr != nil {
  178. return nil, teamPhotoErr
  179. }
  180. if teamPhotoInfo != nil {
  181. for _, photo := range teamPhotoInfo {
  182. if photo.Symbol == 1 {
  183. sLocalInfo.TeamMainPhotoSymbol = 1
  184. sLocalInfo.TeamMainPhotoUrl = photo.PhotoUrl
  185. sLocalInfo.TeamMainPhotoUid = photo.PhotoUid
  186. }
  187. }
  188. }
  189. }
  190. // 3. 招募要求
  191. // sLocalInfo.TalentType = localInfo.TalentType
  192. parts := strings.Split(localInfo.TalentType, ",")
  193. var result []int
  194. for _, part := range parts {
  195. num, strErr := strconv.Atoi(strings.TrimSpace(part))
  196. if strErr != nil {
  197. return nil, strErr
  198. }
  199. result = append(result, num)
  200. }
  201. fmt.Println(result)
  202. talentTypeCategory, talentTypeErr := db.GetTalentCategory(ctx, result)
  203. if talentTypeErr != nil {
  204. return nil, talentTypeErr
  205. }
  206. if talentTypeCategory != nil {
  207. categories := make([]string, 0, len(talentTypeCategory))
  208. for _, talentType := range talentTypeCategory {
  209. categories = append(categories, talentType.Category)
  210. }
  211. sLocalInfo.TalentType = strings.Join(categories, ",")
  212. }
  213. sLocalInfo.RecruitDdl = conv.MustString(localInfo.RecruitDdl)
  214. recruitStrategy, recruitErr := db.GetRecruitStrategyBySLocalId(ctx, req.SLocalId)
  215. if recruitErr != nil {
  216. return nil, recruitErr
  217. }
  218. if recruitStrategy != nil {
  219. for _, strategy := range recruitStrategy {
  220. sLocalInfo.EstimatedCost += strategy.Offer * float64(strategy.RecruitNumber)
  221. showStrategy := http_model.ShowSRecruitStrategy{
  222. StrategyID: strategy.StrategyID,
  223. FeeForm: strategy.FeeForm,
  224. FollowersLow: strategy.FollowersLow,
  225. FollowersUp: strategy.FollowersUp,
  226. RecruitNumber: strategy.RecruitNumber,
  227. Offer: strategy.Offer,
  228. }
  229. sLocalInfo.RecruitStrategys = append(sLocalInfo.RecruitStrategys, showStrategy)
  230. }
  231. }
  232. // 4. 执行要求
  233. sLocalInfo.TaskForm = localInfo.TaskForm
  234. sLocalInfo.ContentType = localInfo.ContentType
  235. briefInfo, briefErr := db.FindBriefByLocalId(ctx, req.LocalId)
  236. if briefErr != nil {
  237. return nil, briefErr
  238. }
  239. if briefInfo != nil {
  240. sLocalInfo.LocalBrief = briefInfo
  241. }
  242. materialInfo, materialErr := db.FindMaterialByLocalId(ctx, req.LocalId)
  243. if materialErr != nil {
  244. return nil, materialErr
  245. }
  246. if materialInfo != nil {
  247. sLocalInfo.LocalMaterial = materialInfo
  248. }
  249. }
  250. return sLocalInfo, nil
  251. }
  252. func (*sLocalLife) GetFullSLocalLifeList(ctx context.Context, pageSize, pageNum int32, supplierId int, condition *common_model.SLocalLifeCondition) (*http_model.FullSLocalListData, error) {
  253. // 1. 查询本地生活任务基本信息
  254. fullLocals, total, err := db.GetFullSLocalLifeList(ctx, pageSize, pageNum, supplierId, condition)
  255. if err != nil {
  256. logrus.WithContext(ctx).Errorf("[fullLocals service] call GetFullSLocalLifeList error,err:%+v", err)
  257. return nil, err
  258. }
  259. var fullLocalData *http_model.FullSLocalListData
  260. fullLocalData = &http_model.FullSLocalListData{}
  261. fullLocalData.Total = total
  262. for _, fullLocal := range fullLocals {
  263. var fullLocalPreview *http_model.FullSLocalPreview
  264. fullLocalPreview = &http_model.FullSLocalPreview{}
  265. fullLocalPreview.LocalId = fullLocal.LocalId
  266. fullLocalPreview.SLocalId = fullLocal.SLocalId
  267. fullLocalPreview.EnterpriseId = fullLocal.EnterpriseId
  268. fullLocalPreview.LocalName = fullLocal.LocalName
  269. fullLocalPreview.StoreId = fullLocal.StoreId
  270. fullLocalPreview.TeamBuyingId = fullLocal.TeamBuyingId
  271. fullLocalPreview.TaskStatus = fullLocal.TaskStatus
  272. fullLocalPreview.LocalPlatform = fullLocal.LocalPlatform
  273. fullLocalPreview.TaskForm = fullLocal.TaskForm
  274. if fullLocal.OperatorType == 1 {
  275. fullLocalPreview.AddToListOperator = conv.MustString(fullLocal.SupplierId)
  276. } else {
  277. fullLocalPreview.AddToListOperator = conv.MustString(fullLocal.SubAccountId)
  278. }
  279. fullLocalPreview.LocalType = fullLocal.LocalType
  280. fullLocalPreview.LocalContentType = fullLocal.ContentType
  281. fullLocalPreview.SupplierId = supplierId
  282. fullLocalPreview.SubAccountId = fullLocal.SubAccountId
  283. fullLocalPreview.OperatorType = fullLocal.OperatorType
  284. fullLocalPreview.CreateTime = conv.MustString(fullLocal.CreateTime)[0:19]
  285. fullLocalPreview.ServiceCharge = fullLocal.ServiceCharge
  286. fullLocalPreview.ServiceChargeActual = fullLocal.ServiceChargeActual
  287. fullLocalPreview.ApplyNum = fullLocal.ApplyNum
  288. fullLocalPreview.RecruitNum = fullLocal.RecruitNum
  289. fullLocalPreview.SettleNum = fullLocal.SettleNum
  290. fullLocalData.FullSLocalPreview = append(fullLocalData.FullSLocalPreview, fullLocalPreview)
  291. }
  292. // 2. 查询本地生活补充信息:门店信息,招募策略
  293. for _, local := range fullLocalData.FullSLocalPreview {
  294. // 2.1. 门店信息
  295. storeInfo, productErr := db.FindStoreById(ctx, local.StoreId)
  296. if productErr != nil {
  297. return nil, productErr
  298. }
  299. if storeInfo != nil {
  300. local.StoreId = storeInfo.StoreId
  301. local.StoreName = storeInfo.StoreName
  302. }
  303. // 2.2. 门店图片信息
  304. productPhotoInfo, productPhotoErr := db.GetStorePhotoByStoreID(ctx, local.StoreId)
  305. if productPhotoErr != nil {
  306. return nil, productPhotoErr
  307. }
  308. if productPhotoInfo != nil {
  309. for _, photo := range productPhotoInfo {
  310. // fmt.Println(photo)
  311. if photo.Symbol == 1 {
  312. local.StoreMainPhotoSymbol = 1
  313. local.StoreMainPhotoUrl = photo.PhotoUrl
  314. local.StoreMainPhotoUid = photo.PhotoUid
  315. }
  316. }
  317. }
  318. }
  319. return fullLocalData, nil
  320. }
  321. // GetLocalTaskList 查询本地生活子任务
  322. func (*sLocalLife) GetLocalTaskList(ctx context.Context, pageSize, pageNum int32, orderBy []string, orderDesc []int, condition *common_model.LocalTaskConditions) (*http_model.LocalTaskListData, error) {
  323. var localTaskListData *http_model.LocalTaskListData
  324. localTaskListData = &http_model.LocalTaskListData{}
  325. // 1. 根据condition查询子任务信息
  326. localTaskList, total, localTaskErr := db.GetLocalTaskList(ctx, pageSize, pageNum, orderBy, orderDesc, condition)
  327. if localTaskErr != nil {
  328. return nil, localTaskErr
  329. }
  330. if localTaskList != nil {
  331. localTaskListData.Total = total
  332. for _, localTask := range localTaskList {
  333. var localTaskInfo *http_model.LocalTaskPreview
  334. localTaskInfo = &http_model.LocalTaskPreview{}
  335. // 2. 补充查询达人身份信息
  336. talentInfo, talentErr := db.FindUserInfoByTalentId(ctx, localTask.TalentID)
  337. if talentErr != nil {
  338. return nil, talentErr
  339. }
  340. if talentInfo != nil {
  341. localTaskInfo.TaskId = localTask.TaskID
  342. localTaskInfo.TaskStage = localTask.TaskStage
  343. localTaskInfo.ServiceCharge = localTask.ServiceCharge
  344. localTaskInfo.DraftFee = localTask.DraftFee
  345. localTaskInfo.SupportFee = localTask.SupportFee
  346. localTaskInfo.StrategyId = localTask.StrategyID
  347. localTaskInfo.TaskStatus = localTask.TaskStatus
  348. if localTask.CreateDate != nil {
  349. localTaskInfo.CreateDate = conv.MustString(localTask.CreateDate)[0:19]
  350. }
  351. if localTask.SelectDate != nil {
  352. localTaskInfo.SelectDate = conv.MustString(localTask.SelectDate)[0:19]
  353. }
  354. if localTask.DeliveryDate != nil {
  355. localTaskInfo.DeliveryDate = conv.MustString(localTask.DeliveryDate)[0:19]
  356. }
  357. if localTask.SignedTime != nil {
  358. localTaskInfo.SignedTime = conv.MustString(localTask.SignedTime)[0:19]
  359. }
  360. if localTask.CurBreakAt != nil {
  361. localTaskInfo.CurBreakAt = conv.MustString(localTask.CurBreakAt)[0:19]
  362. }
  363. if localTask.CompleteDate != nil {
  364. localTaskInfo.CompletedTime = conv.MustString(localTask.CompleteDate)[0:19]
  365. }
  366. if localTask.CancelTime != nil {
  367. localTaskInfo.CancelTime = conv.MustString(localTask.CancelTime)[0:19]
  368. }
  369. localTaskInfo.IfMissing = 0
  370. //localTaskInfo.CreateDate = conv.MustString(localTask.CreateDate)
  371. //localTaskInfo.SelectDate = conv.MustString(localTask.SelectDate)
  372. //localTaskInfo.DeliveryDate = conv.MustString(localTask.DeliveryDate)
  373. //localTaskInfo.SignedTime = conv.MustString(localTask.SignedTime)
  374. //localTaskInfo.CurBreakAt = conv.MustString(localTask.CurBreakAt)
  375. localTaskInfo.FansNum = localTask.FansNum
  376. localTaskInfo.VoteAvg = localTask.VoteAvg
  377. localTaskInfo.CommitAvg = localTask.CommitAvg
  378. localTaskInfo.BOperator = localTask.BOperator
  379. localTaskInfo.BOperatorType = localTask.BOperatorType
  380. localTaskInfo.SOperator = localTask.SOperator
  381. localTaskInfo.SOperatorType = localTask.SOperatorType
  382. localTaskInfo.PlatformNickname = talentInfo.NickName
  383. localTaskInfo.FansCount = talentInfo.Fan
  384. localTaskInfo.AvatarUrl = talentInfo.HeadUri
  385. localTaskInfo.Location = talentInfo.City
  386. localTaskInfo.Gender = talentInfo.Gender
  387. localTaskListData.LocalTaskPreview = append(localTaskListData.LocalTaskPreview, localTaskInfo)
  388. }
  389. }
  390. // 3. 本地生活任务信息补充
  391. sLocalInfo, sLocalErr := db.GetSLocalLifeDetail(ctx, condition.SLocalId)
  392. if sLocalErr != nil {
  393. return nil, sLocalErr
  394. }
  395. if sLocalInfo != nil {
  396. localTaskListData.SettleNum = sLocalInfo.SettleNum
  397. localTaskListData.RecruitNum = sLocalInfo.RecruitNum
  398. localTaskListData.ServiceChargeActual = sLocalInfo.ServiceChargeActual
  399. localTaskListData.ServiceChargeSettle = sLocalInfo.ServiceChargeSettle
  400. localTaskListData.EstimateServiceCharge = sLocalInfo.ServiceChargeActual
  401. localTaskListData.EstimateDraftFee = sLocalInfo.EstimateDraftFee
  402. localTaskListData.EstimateSupportFee = sLocalInfo.EstimateSupportFee
  403. }
  404. }
  405. return localTaskListData, nil
  406. }
  407. // ChangeTaskSupplierStatus 本地生活达人报名通过、拒绝报名
  408. func (*sLocalLife) ChangeTaskSupplierStatus(ctx context.Context, req *http_model.LocalChangeSupplierStatusRequest) error {
  409. // 1. 同意/拒绝
  410. RecruitStrategyIDs, err := db.ChangeLocalTaskStatus(ctx, req.TaskIds, req.SupplierStatus, req.SupplierId, req.SubAccountId)
  411. if err != nil {
  412. logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  413. return err
  414. }
  415. fmt.Println(RecruitStrategyIDs)
  416. return nil
  417. }
  418. // ChangeSupplierStatus 定向本地生活加入商单或拒绝
  419. func (*sLocalLife) ChangeSupplierStatus(ctx context.Context, req *http_model.SpecialLocalAddToListRequest) error {
  420. var sLocalInfo *gorm_model.YounggeeSLocalLifeInfo
  421. sLocalInfo = &gorm_model.YounggeeSLocalLifeInfo{}
  422. var operatorType int
  423. if req.SubAccountId == 0 {
  424. operatorType = 1
  425. } else {
  426. operatorType = 2
  427. }
  428. sLocalInfo.SLocalId = req.SLocalId
  429. sLocalInfo.SupplierId = req.SupplierId
  430. sLocalInfo.SubAccountId = req.SubAccountId
  431. sLocalInfo.OperatorType = operatorType
  432. sLocalInfo.SLocalStatus = req.SLocalStatus
  433. fmt.Println("data: ", sLocalInfo)
  434. err := db.UpdateSLocal(ctx, sLocalInfo)
  435. if err != nil {
  436. return err
  437. }
  438. return nil
  439. }
  440. // CreateSpecialStrategy 定向本地生活替换服务费率
  441. func (*sLocalLife) CreateSpecialStrategy(ctx context.Context, request *http_model.LocalSpecialAddStrategyRequest) error {
  442. // 1. 添加服务商招募策略
  443. // 1.1. 整理数据
  444. var recruitStrategys []gorm_model.RecruitStrategy
  445. for _, strategy := range request.RecruitStrategys {
  446. var recruitStrategy *gorm_model.RecruitStrategy
  447. recruitStrategy = &gorm_model.RecruitStrategy{}
  448. recruitStrategy.StrategyID = strategy.StrategyID
  449. recruitStrategy.QuoteRecruitStrategyId = strategy.QuoteRecruitStrategyId
  450. recruitStrategy.FeeForm = strategy.FeeForm
  451. recruitStrategy.StrategyID = strategy.StrategyID
  452. recruitStrategy.FollowersLow = strategy.FollowersLow
  453. recruitStrategy.FollowersUp = strategy.FollowersUp
  454. recruitStrategy.RecruitNumber = strategy.RecruitNumber
  455. recruitStrategy.Offer = strategy.Offer
  456. recruitStrategy.ServiceCharge = strategy.ServiceCharge
  457. recruitStrategy.StrategyType = 2
  458. recruitStrategy.QuoteRecruitStrategyId = strategy.QuoteRecruitStrategyId
  459. // 一口价需要计算服务费率和达人所见报价
  460. if strategy.FeeForm == 3 {
  461. recruitStrategy.ServiceRate = strategy.ServiceRate
  462. } else {
  463. recruitStrategy.ServiceRate = int(strategy.ServiceCharge / strategy.Offer)
  464. }
  465. recruitStrategy.TOffer = strategy.Offer - strategy.ServiceCharge
  466. recruitStrategy.ProjectID = "0"
  467. recruitStrategy.SLocalId = request.SLocalId
  468. recruitStrategys = append(recruitStrategys, *recruitStrategy)
  469. }
  470. createErr := db.CreateSpecialStrategy(ctx, recruitStrategys)
  471. if createErr != nil {
  472. return createErr
  473. }
  474. // 2. 修改sProject中的字段
  475. var sLocalInfo *gorm_model.YounggeeSLocalLifeInfo
  476. sLocalInfo = &gorm_model.YounggeeSLocalLifeInfo{}
  477. if request.SubAccountId == 0 {
  478. sLocalInfo.CreateStrategyType = 1
  479. sLocalInfo.CreateStrategyId = request.SupplierId
  480. } else {
  481. sLocalInfo.CreateStrategyType = 2
  482. sLocalInfo.CreateStrategyId = request.SubAccountId
  483. }
  484. sLocalInfo.SLocalId = request.SLocalId
  485. sLocalInfo.StrategyStatus = 1
  486. updateErr := db.UpdateSLocal(ctx, sLocalInfo)
  487. if updateErr != nil {
  488. return updateErr
  489. }
  490. return nil
  491. }
  492. // GetFullSLocalBillList 服务商本地生活任务账单列表
  493. func (*sLocalLife) GetFullSLocalBillList(ctx context.Context, req *http_model.FullSLocalBillListRequest) (*http_model.FullSLocalBillData, error) {
  494. // 1. 查询本地生活任务基本信息
  495. fullLocals, total, err := db.GetFullSLocalBillList(ctx, req.PageSize, req.PageNum, req.SupplierId)
  496. if err != nil {
  497. logrus.WithContext(ctx).Errorf("[fullLocals service] call GetFullSLocalLifeList error,err:%+v", err)
  498. return nil, err
  499. }
  500. var fullLocalData *http_model.FullSLocalBillData
  501. fullLocalData = &http_model.FullSLocalBillData{}
  502. fullLocalData.Total = total
  503. for _, fullLocal := range fullLocals {
  504. var fullLocalPreview *http_model.FullSLocalBillListData
  505. fullLocalPreview = &http_model.FullSLocalBillListData{}
  506. fullLocalPreview.SLocalId = fullLocal.SLocalId
  507. fullLocalPreview.LocalId = fullLocal.LocalId
  508. fullLocalPreview.LocalPlatform = fullLocal.LocalPlatform
  509. fullLocalPreview.TaskForm = fullLocal.TaskForm
  510. fullLocalPreview.ContentType = fullLocal.ContentType
  511. fullLocalPreview.TaskStatus = fullLocal.TaskStatus
  512. fullLocalPreview.EnterpriseId = fullLocal.EnterpriseId
  513. fullLocalPreview.SupplierId = fullLocal.SupplierId
  514. fullLocalPreview.SubAccountId = fullLocal.SubAccountId
  515. fullLocalPreview.ServiceChargeActual = fullLocal.ServiceChargeActual
  516. fullLocalPreview.ServiceChargeSettle = fullLocal.ServiceChargeSettle
  517. fullLocalPreview.StoreId = fullLocal.StoreId
  518. fullLocalData.SLocalList = append(fullLocalData.SLocalList, fullLocalPreview)
  519. }
  520. // 2. 查询本地生活补充信息:门店信息,招募策略
  521. for _, local := range fullLocalData.SLocalList {
  522. // 2.1. 门店信息
  523. storeInfo, productErr := db.FindStoreById(ctx, local.StoreId)
  524. if productErr != nil {
  525. return nil, productErr
  526. }
  527. if storeInfo != nil {
  528. local.StoreId = storeInfo.StoreId
  529. local.StoreName = storeInfo.StoreName
  530. }
  531. // 2.2. 门店图片信息
  532. productPhotoInfo, productPhotoErr := db.GetStorePhotoByStoreID(ctx, local.StoreId)
  533. if productPhotoErr != nil {
  534. return nil, productPhotoErr
  535. }
  536. if productPhotoInfo != nil {
  537. for _, photo := range productPhotoInfo {
  538. fmt.Println(photo)
  539. if photo.Symbol == 1 {
  540. local.StorePhotoSymbol = 1
  541. local.StorePhotoUrl = photo.PhotoUrl
  542. local.StorePhotoUid = photo.PhotoUid
  543. }
  544. }
  545. }
  546. }
  547. return fullLocalData, nil
  548. }
  549. // FullSLocalTaskBillList 服务商本地生活子任务账单列表
  550. func (*sLocalLife) FullSLocalTaskBillList(ctx context.Context, request *http_model.FullSLocalTaskBillListRequest) (*http_model.FullSLocalTaskBillData, error) {
  551. var currSLocalTaskBillData *http_model.FullSLocalTaskBillData
  552. currSLocalTaskBillData = &http_model.FullSLocalTaskBillData{}
  553. currSLocalTaskBillData.DraftFee = 0
  554. currSLocalTaskBillData.DraftFeeSettle = 0
  555. // 1. 查找子任务
  556. taskList, total, taskListErr := db.GetSLocalTaskList(ctx, request.SLocalId, request.TalentId, request.PageSize, request.PageNum)
  557. if taskListErr != nil {
  558. return nil, taskListErr
  559. }
  560. if taskList != nil {
  561. currSLocalTaskBillData.Total = total
  562. for _, task := range taskList {
  563. var curr *http_model.FullSLocalTaskBillListData
  564. curr = &http_model.FullSLocalTaskBillListData{}
  565. curr.TaskId = task.TaskID
  566. curr.ServiceCharge = task.ServiceCharge
  567. curr.ViewNum = 0
  568. curr.VoteNum = 0
  569. curr.CommitNum = 0
  570. curr.CollectNum = 0
  571. curr.ServiceCharge = task.ServiceCharge
  572. curr.DraftFee = task.DraftFee
  573. curr.DelayRate = task.ScriptBreakRate + task.SketchBreakRate + task.LinkBreakRate + task.DataBreakRate
  574. curr.RealServiceCharge = task.RealPayment - task.SettleAmount
  575. curr.SettleAmount = task.SettleAmount
  576. curr.SettleTime = conv.MustString(task.CompleteDate)
  577. currSLocalTaskBillData.DraftFee += curr.DraftFee
  578. currSLocalTaskBillData.DraftFeeSettle += curr.SettleAmount
  579. currSLocalTaskBillData.SLocalTaskList = append(currSLocalTaskBillData.SLocalTaskList, curr)
  580. }
  581. // 2. 补充任务信息
  582. sLocalInfo, sLocalErr := db.GetSLocalLifeDetail(ctx, request.SLocalId)
  583. if sLocalErr != nil {
  584. return nil, sLocalErr
  585. }
  586. if sLocalInfo != nil {
  587. currSLocalTaskBillData.SettleNum = sLocalInfo.SettleNum
  588. currSLocalTaskBillData.ChooseNum = sLocalInfo.ApplyNum
  589. currSLocalTaskBillData.ServiceCharge = sLocalInfo.ServiceCharge
  590. currSLocalTaskBillData.ServiceChargeSettle = sLocalInfo.ServiceChargeSettle
  591. }
  592. }
  593. return currSLocalTaskBillData, nil
  594. }
  595. // CountLocalTask 按照状态统计子任务数量
  596. func (*sLocalLife) CountLocalTask(ctx context.Context, req *http_model.LocalTaskCountRequest) (*http_model.LocalTaskCountData, error) {
  597. var counter *http_model.LocalTaskCountData
  598. counter = &http_model.LocalTaskCountData{}
  599. // 1. Stage1
  600. stage1, stage1Err := db.CountLocalTaskNumByTaskStage(ctx, 0, 1, req.SLocalId)
  601. if stage1Err != nil {
  602. return nil, stage1Err
  603. }
  604. counter.Stage1 = stage1
  605. // 2. Stage2
  606. stage2, stage2Err := db.CountLocalTaskNumByTaskStage(ctx, 0, 2, req.SLocalId)
  607. if stage2Err != nil {
  608. return nil, stage2Err
  609. }
  610. counter.Stage2 = stage2
  611. // 3. Stage3
  612. stage3, stage3Err := db.CountLocalTaskNumByTaskStage(ctx, 0, 3, req.SLocalId)
  613. if stage3Err != nil {
  614. return nil, stage3Err
  615. }
  616. counter.Stage3 = stage3
  617. // 4. Stage4
  618. stage4, stage4Err := db.CountLocalTaskNumByTaskStage(ctx, 1, 2, req.SLocalId)
  619. if stage4Err != nil {
  620. return nil, stage4Err
  621. }
  622. counter.Stage4 = stage4
  623. // 5. Stage5
  624. stage5, stage5Err := db.CountLocalTaskNumByTaskStage(ctx, 2, 2, req.SLocalId)
  625. if stage5Err != nil {
  626. return nil, stage5Err
  627. }
  628. counter.Stage5 = stage5
  629. // 6. Stage6
  630. stage6, stage6Err := db.CountLocalTaskNumByTaskStage(ctx, 3, 2, req.SLocalId)
  631. if stage6Err != nil {
  632. return nil, stage6Err
  633. }
  634. counter.Stage6 = stage6
  635. // 7. Stage7
  636. stage7, stage7Err := db.CountLocalTaskNumByTaskStage(ctx, 0, 0, req.SLocalId)
  637. if stage7Err != nil {
  638. return nil, stage7Err
  639. }
  640. counter.Stage7 = stage7
  641. return counter, nil
  642. }
  643. func (p *sLocalLife) GetLocalStrategys(ctx *gin.Context, req *http_model.LocalStrategyRequest) ([]gorm_model.RecruitStrategy, error) {
  644. slocalInfo, slocalErr := db.GetSLocalLifeDetail(ctx, req.SLocalId)
  645. if slocalErr != nil {
  646. return nil, slocalErr
  647. }
  648. if slocalInfo != nil {
  649. if slocalInfo.StrategyStatus == 1 {
  650. recruitStrategys, getProjectStrategysErr := db.GetRecruitStrategyBySLocalId(ctx, req.SLocalId)
  651. if getProjectStrategysErr != nil {
  652. return nil, getProjectStrategysErr
  653. }
  654. return recruitStrategys, nil
  655. } else {
  656. recruitStrategys, getProjectStrategysErr := db.GetRecruitStrategyByProjectId(ctx, req.LocalId)
  657. if getProjectStrategysErr != nil {
  658. return nil, getProjectStrategysErr
  659. }
  660. return recruitStrategys, nil
  661. }
  662. }
  663. return nil, nil
  664. }