s_local_life.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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.ServiceChargeRate = localInfo.ServiceChargeRate
  113. if localInfo.PayAt != nil {
  114. sLocalInfo.PayAt = conv.MustString(localInfo.PayAt)[0:19]
  115. }
  116. sLocalInfo.EstimatedCost = 0.0
  117. // 2. 关联主体
  118. // 2.1. 门店信息
  119. storeInfo, storeErr := db.FindStoreById(ctx, localInfo.StoreId)
  120. if storeErr != nil {
  121. return nil, storeErr
  122. }
  123. if storeInfo != nil {
  124. sLocalInfo.StoreId = storeInfo.StoreId
  125. sLocalInfo.StoreName = storeInfo.StoreName
  126. sLocalInfo.StoreCategory = storeInfo.StoreCategory
  127. sLocalInfo.StoreRelatedAt = conv.MustString(localInfo.StoreRelatedAt)
  128. // 2.2. 门店图片信息
  129. storePhotoInfo, storePhotoErr := db.GetStorePhotoByStoreID(ctx, localInfo.StoreId)
  130. if storePhotoErr != nil {
  131. return nil, storePhotoErr
  132. }
  133. if storePhotoInfo != nil {
  134. for _, photo := range storePhotoInfo {
  135. if photo.Symbol == 1 {
  136. sLocalInfo.StoreMainPhotoSymbol = 1
  137. sLocalInfo.StoreMainPhotoUrl = photo.PhotoUrl
  138. sLocalInfo.StoreMainPhotoUid = photo.PhotoUid
  139. }
  140. }
  141. }
  142. }
  143. // 2.3. 团购信息
  144. teamInfo, teamErr := db.FindTeamById(ctx, localInfo.TeamBuyingId)
  145. if teamErr != nil {
  146. return nil, teamErr
  147. }
  148. if teamInfo != nil {
  149. sLocalInfo.TeamBuyingId = teamInfo.TeamBuyingId
  150. sLocalInfo.TeamBuyingName = teamInfo.TeamBuyingName
  151. sLocalInfo.TeamBuyingCategory = teamInfo.TeamBuyingCategory
  152. sLocalInfo.TeamBuyingRelatedAt = conv.MustString(localInfo.TeamBuyingRelatedAt)
  153. // 2.4. 团购图片信息
  154. teamPhotoInfo, teamPhotoErr := db.GetTeamPhotoByTeamID(ctx, localInfo.TeamBuyingId)
  155. if teamPhotoErr != nil {
  156. return nil, teamPhotoErr
  157. }
  158. if teamPhotoInfo != nil {
  159. for _, photo := range teamPhotoInfo {
  160. if photo.Symbol == 1 {
  161. sLocalInfo.TeamMainPhotoSymbol = 1
  162. sLocalInfo.TeamMainPhotoUrl = photo.PhotoUrl
  163. sLocalInfo.TeamMainPhotoUid = photo.PhotoUid
  164. }
  165. }
  166. }
  167. }
  168. // 3. 招募要求
  169. // sLocalInfo.TalentType = localInfo.TalentType
  170. parts := strings.Split(localInfo.TalentType, ",")
  171. var result []int
  172. for _, part := range parts {
  173. num, strErr := strconv.Atoi(strings.TrimSpace(part))
  174. if strErr != nil {
  175. return nil, strErr
  176. }
  177. result = append(result, num)
  178. }
  179. fmt.Println(result)
  180. talentTypeCategory, talentTypeErr := db.GetTalentCategory(ctx, result)
  181. if talentTypeErr != nil {
  182. return nil, talentTypeErr
  183. }
  184. if talentTypeCategory != nil {
  185. categories := make([]string, 0, len(talentTypeCategory))
  186. for _, talentType := range talentTypeCategory {
  187. categories = append(categories, talentType.Category)
  188. }
  189. sLocalInfo.TalentType = strings.Join(categories, ",")
  190. }
  191. sLocalInfo.RecruitDdl = conv.MustString(localInfo.RecruitDdl)
  192. recruitStrategy, recruitErr := db.GetRecruitStrategyBySLocalId(ctx, req.SLocalId)
  193. if recruitErr != nil {
  194. return nil, recruitErr
  195. }
  196. if recruitStrategy != nil {
  197. for _, strategy := range recruitStrategy {
  198. sLocalInfo.EstimatedCost += strategy.Offer * float64(strategy.RecruitNumber)
  199. showStrategy := http_model.ShowSRecruitStrategy{
  200. StrategyID: strategy.StrategyID,
  201. FeeForm: strategy.FeeForm,
  202. FollowersLow: strategy.FollowersLow,
  203. FollowersUp: strategy.FollowersUp,
  204. RecruitNumber: strategy.RecruitNumber,
  205. Offer: strategy.Offer,
  206. }
  207. sLocalInfo.RecruitStrategys = append(sLocalInfo.RecruitStrategys, showStrategy)
  208. }
  209. }
  210. // 4. 执行要求
  211. sLocalInfo.TaskForm = localInfo.TaskForm
  212. sLocalInfo.ContentType = localInfo.ContentType
  213. briefInfo, briefErr := db.FindBriefByLocalId(ctx, req.LocalId)
  214. if briefErr != nil {
  215. return nil, briefErr
  216. }
  217. if briefInfo != nil {
  218. sLocalInfo.LocalBrief = briefInfo
  219. }
  220. materialInfo, materialErr := db.FindMaterialByLocalId(ctx, req.LocalId)
  221. if materialErr != nil {
  222. return nil, materialErr
  223. }
  224. if materialInfo != nil {
  225. sLocalInfo.LocalMaterial = materialInfo
  226. }
  227. }
  228. return sLocalInfo, nil
  229. }
  230. func (*sLocalLife) GetFullSLocalLifeList(ctx context.Context, pageSize, pageNum int32, supplierId int, condition *common_model.SLocalLifeCondition) (*http_model.FullSLocalListData, error) {
  231. // 1. 查询本地生活任务基本信息
  232. fullLocals, total, err := db.GetFullSLocalLifeList(ctx, pageSize, pageNum, supplierId, condition)
  233. if err != nil {
  234. logrus.WithContext(ctx).Errorf("[fullLocals service] call GetFullSLocalLifeList error,err:%+v", err)
  235. return nil, err
  236. }
  237. var fullLocalData *http_model.FullSLocalListData
  238. fullLocalData = &http_model.FullSLocalListData{}
  239. fullLocalData.Total = total
  240. for _, fullLocal := range fullLocals {
  241. var fullLocalPreview *http_model.FullSLocalPreview
  242. fullLocalPreview = &http_model.FullSLocalPreview{}
  243. fullLocalPreview.LocalId = fullLocal.LocalId
  244. fullLocalPreview.SLocalId = fullLocal.SLocalId
  245. fullLocalPreview.EnterpriseId = fullLocal.EnterpriseId
  246. fullLocalPreview.LocalName = fullLocal.LocalName
  247. fullLocalPreview.StoreId = fullLocal.StoreId
  248. fullLocalPreview.TeamBuyingId = fullLocal.TeamBuyingId
  249. fullLocalPreview.TaskStatus = fullLocal.TaskStatus
  250. fullLocalPreview.LocalPlatform = fullLocal.LocalPlatform
  251. fullLocalPreview.TaskForm = fullLocal.TaskForm
  252. if fullLocal.OperatorType == 1 {
  253. fullLocalPreview.AddToListOperator = conv.MustString(fullLocal.SupplierId)
  254. } else {
  255. fullLocalPreview.AddToListOperator = conv.MustString(fullLocal.SubAccountId)
  256. }
  257. fullLocalPreview.LocalType = fullLocal.LocalType
  258. fullLocalPreview.LocalContentType = fullLocal.ContentType
  259. fullLocalPreview.SupplierId = supplierId
  260. fullLocalPreview.SubAccountId = fullLocal.SubAccountId
  261. fullLocalPreview.OperatorType = fullLocal.OperatorType
  262. fullLocalPreview.CreateTime = conv.MustString(fullLocal.CreateTime)[0:19]
  263. fullLocalPreview.ServiceCharge = fullLocal.ServiceCharge
  264. fullLocalPreview.ServiceChargeActual = fullLocal.ServiceChargeActual
  265. fullLocalPreview.ApplyNum = fullLocal.ApplyNum
  266. fullLocalPreview.RecruitNum = fullLocal.RecruitNum
  267. fullLocalPreview.SettleNum = fullLocal.SettleNum
  268. fullLocalData.FullSLocalPreview = append(fullLocalData.FullSLocalPreview, fullLocalPreview)
  269. }
  270. // 2. 查询本地生活补充信息:门店信息,招募策略
  271. for _, local := range fullLocalData.FullSLocalPreview {
  272. // 2.1. 门店信息
  273. storeInfo, productErr := db.FindStoreById(ctx, local.StoreId)
  274. if productErr != nil {
  275. return nil, productErr
  276. }
  277. if storeInfo != nil {
  278. local.StoreId = storeInfo.StoreId
  279. local.StoreName = storeInfo.StoreName
  280. }
  281. // 2.2. 门店图片信息
  282. productPhotoInfo, productPhotoErr := db.GetStorePhotoByStoreID(ctx, local.StoreId)
  283. if productPhotoErr != nil {
  284. return nil, productPhotoErr
  285. }
  286. if productPhotoInfo != nil {
  287. for _, photo := range productPhotoInfo {
  288. // fmt.Println(photo)
  289. if photo.Symbol == 1 {
  290. local.StoreMainPhotoSymbol = 1
  291. local.StoreMainPhotoUrl = photo.PhotoUrl
  292. local.StoreMainPhotoUid = photo.PhotoUid
  293. }
  294. }
  295. }
  296. }
  297. return fullLocalData, nil
  298. }
  299. // GetLocalTaskList 查询本地生活子任务
  300. func (*sLocalLife) GetLocalTaskList(ctx context.Context, pageSize, pageNum int32, orderBy []string, orderDesc []int, condition *common_model.LocalTaskConditions) (*http_model.LocalTaskListData, error) {
  301. var localTaskListData *http_model.LocalTaskListData
  302. localTaskListData = &http_model.LocalTaskListData{}
  303. // 1. 根据condition查询子任务信息
  304. localTaskList, total, localTaskErr := db.GetLocalTaskList(ctx, pageSize, pageNum, orderBy, orderDesc, condition)
  305. if localTaskErr != nil {
  306. return nil, localTaskErr
  307. }
  308. if localTaskList != nil {
  309. localTaskListData.Total = total
  310. for _, localTask := range localTaskList {
  311. var localTaskInfo *http_model.LocalTaskPreview
  312. localTaskInfo = &http_model.LocalTaskPreview{}
  313. // 2. 补充查询达人身份信息
  314. talentInfo, talentErr := db.FindUserInfoByTalentId(ctx, localTask.TalentID)
  315. if talentErr != nil {
  316. return nil, talentErr
  317. }
  318. if talentInfo != nil {
  319. localTaskInfo.TaskId = localTask.TaskID
  320. localTaskInfo.TaskStage = localTask.TaskStage
  321. localTaskInfo.ServiceCharge = localTask.ServiceCharge
  322. localTaskInfo.DraftFee = localTask.DraftFee
  323. localTaskInfo.SupportFee = localTask.SupportFee
  324. localTaskInfo.StrategyId = localTask.StrategyID
  325. localTaskInfo.TaskStatus = localTask.TaskStatus
  326. localTaskInfo.CreateDate = conv.MustString(localTask.CreateDate)
  327. localTaskInfo.SelectDate = conv.MustString(localTask.SelectDate)
  328. localTaskInfo.DeliveryDate = conv.MustString(localTask.DeliveryDate)
  329. localTaskInfo.SignedTime = conv.MustString(localTask.SignedTime)
  330. localTaskInfo.CurBreakAt = conv.MustString(localTask.CurBreakAt)
  331. localTaskInfo.FansNum = localTask.FansNum
  332. localTaskInfo.VoteAvg = localTask.VoteAvg
  333. localTaskInfo.CommitAvg = localTask.CommitAvg
  334. localTaskInfo.BOperator = localTask.BOperator
  335. localTaskInfo.BOperatorType = localTask.BOperatorType
  336. localTaskInfo.SOperator = localTask.SOperator
  337. localTaskInfo.SOperatorType = localTask.SOperatorType
  338. localTaskInfo.PlatformNickname = talentInfo.NickName
  339. localTaskInfo.FansCount = talentInfo.Fan
  340. localTaskInfo.AvatarUrl = talentInfo.HeadUri
  341. localTaskInfo.Location = talentInfo.City
  342. localTaskInfo.Gender = talentInfo.Gender
  343. localTaskListData.LocalTaskPreview = append(localTaskListData.LocalTaskPreview, localTaskInfo)
  344. }
  345. }
  346. // 3. 本地生活任务信息补充
  347. sLocalInfo, sLocalErr := db.GetSLocalLifeDetail(ctx, condition.SLocalId)
  348. if sLocalErr != nil {
  349. return nil, sLocalErr
  350. }
  351. if sLocalInfo != nil {
  352. localTaskListData.SettleNum = sLocalInfo.SettleNum
  353. localTaskListData.RecruitNum = sLocalInfo.RecruitNum
  354. localTaskListData.ServiceChargeActual = sLocalInfo.ServiceChargeActual
  355. localTaskListData.ServiceChargeSettle = sLocalInfo.ServiceChargeSettle
  356. localTaskListData.EstimateServiceCharge = sLocalInfo.ServiceChargeActual
  357. localTaskListData.EstimateDraftFee = sLocalInfo.EstimateDraftFee
  358. localTaskListData.EstimateSupportFee = sLocalInfo.EstimateSupportFee
  359. }
  360. }
  361. return localTaskListData, nil
  362. }
  363. // ChangeTaskSupplierStatus 本地生活达人报名通过、拒绝报名
  364. func (*sLocalLife) ChangeTaskSupplierStatus(ctx context.Context, req *http_model.LocalChangeSupplierStatusRequest) error {
  365. // 1. 同意/拒绝
  366. RecruitStrategyIDs, err := db.ChangeLocalTaskStatus(ctx, req.TaskIds, req.SupplierStatus, req.SupplierId, req.SubAccountId)
  367. if err != nil {
  368. logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  369. return err
  370. }
  371. fmt.Println(RecruitStrategyIDs)
  372. return nil
  373. }
  374. // ChangeSupplierStatus 定向本地生活加入商单或拒绝
  375. func (*sLocalLife) ChangeSupplierStatus(ctx context.Context, req *http_model.SpecialLocalAddToListRequest) error {
  376. var sLocalInfo *gorm_model.YounggeeSLocalLifeInfo
  377. sLocalInfo = &gorm_model.YounggeeSLocalLifeInfo{}
  378. var operatorType int
  379. if req.SubAccountId == 0 {
  380. operatorType = 1
  381. } else {
  382. operatorType = 2
  383. }
  384. sLocalInfo.SLocalId = req.SLocalId
  385. sLocalInfo.SupplierId = req.SupplierId
  386. sLocalInfo.SubAccountId = req.SubAccountId
  387. sLocalInfo.OperatorType = operatorType
  388. sLocalInfo.SLocalStatus = req.SLocalStatus
  389. err := db.UpdateSLocal(ctx, sLocalInfo)
  390. if err != nil {
  391. return err
  392. }
  393. return nil
  394. }
  395. // CreateSpecialStrategy 定向本地生活替换服务费率
  396. func (*sLocalLife) CreateSpecialStrategy(ctx context.Context, request *http_model.LocalSpecialAddStrategyRequest) error {
  397. // 1. 添加服务商招募策略
  398. // 1.1. 整理数据
  399. for _, strategy := range request.RecruitStrategys {
  400. // 一口价需要计算服务费率和达人所见报价
  401. strategy.ServiceRate = int(strategy.ServiceCharge / strategy.Offer)
  402. strategy.TOffer = strategy.Offer - strategy.ServiceCharge
  403. strategy.ProjectID = "0"
  404. strategy.SLocalId = request.SLocalId
  405. strategy.QuoteRecruitStrategyId = int(strategy.RecruitStrategyID)
  406. }
  407. createErr := db.CreateSpecialStrategy(ctx, request.RecruitStrategys)
  408. if createErr != nil {
  409. return createErr
  410. }
  411. // 2. 修改sProject中的字段
  412. var sLocalInfo *gorm_model.YounggeeSLocalLifeInfo
  413. sLocalInfo = &gorm_model.YounggeeSLocalLifeInfo{}
  414. if request.SubAccountId == 0 {
  415. sLocalInfo.CreateStrategyType = 1
  416. sLocalInfo.CreateStrategyId = request.SupplierId
  417. } else {
  418. sLocalInfo.CreateStrategyType = 2
  419. sLocalInfo.CreateStrategyId = request.SubAccountId
  420. }
  421. sLocalInfo.SLocalId = request.SLocalId
  422. sLocalInfo.StrategyStatus = 1
  423. updateErr := db.UpdateSLocal(ctx, sLocalInfo)
  424. if updateErr != nil {
  425. return updateErr
  426. }
  427. return nil
  428. }
  429. // GetFullSLocalBillList 服务商本地生活任务账单列表
  430. func (*sLocalLife) GetFullSLocalBillList(ctx context.Context, req *http_model.FullSLocalBillListRequest) (*http_model.FullSLocalBillData, error) {
  431. // 1. 查询本地生活任务基本信息
  432. fullLocals, total, err := db.GetFullSLocalBillList(ctx, req.PageSize, req.PageNum, req.SupplierId)
  433. if err != nil {
  434. logrus.WithContext(ctx).Errorf("[fullLocals service] call GetFullSLocalLifeList error,err:%+v", err)
  435. return nil, err
  436. }
  437. var fullLocalData *http_model.FullSLocalBillData
  438. fullLocalData = &http_model.FullSLocalBillData{}
  439. fullLocalData.Total = total
  440. for _, fullLocal := range fullLocals {
  441. var fullLocalPreview *http_model.FullSLocalBillListData
  442. fullLocalPreview = &http_model.FullSLocalBillListData{}
  443. fullLocalPreview.SLocalId = fullLocal.SLocalId
  444. fullLocalPreview.LocalId = fullLocal.LocalId
  445. fullLocalPreview.LocalPlatform = fullLocal.LocalPlatform
  446. fullLocalPreview.TaskForm = fullLocal.TaskForm
  447. fullLocalPreview.ContentType = fullLocal.ContentType
  448. fullLocalPreview.TaskStatus = fullLocal.TaskStatus
  449. fullLocalPreview.EnterpriseId = fullLocal.EnterpriseId
  450. fullLocalPreview.SupplierId = fullLocal.SupplierId
  451. fullLocalPreview.SubAccountId = fullLocal.SubAccountId
  452. fullLocalPreview.ServiceChargeActual = fullLocal.ServiceChargeActual
  453. fullLocalPreview.ServiceChargeSettle = fullLocal.ServiceChargeSettle
  454. fullLocalPreview.StoreId = fullLocal.StoreId
  455. fullLocalData.SLocalList = append(fullLocalData.SLocalList, fullLocalPreview)
  456. }
  457. // 2. 查询本地生活补充信息:门店信息,招募策略
  458. for _, local := range fullLocalData.SLocalList {
  459. // 2.1. 门店信息
  460. storeInfo, productErr := db.FindStoreById(ctx, local.StoreId)
  461. if productErr != nil {
  462. return nil, productErr
  463. }
  464. if storeInfo != nil {
  465. local.StoreId = storeInfo.StoreId
  466. local.StoreName = storeInfo.StoreName
  467. }
  468. // 2.2. 门店图片信息
  469. productPhotoInfo, productPhotoErr := db.GetStorePhotoByStoreID(ctx, local.StoreId)
  470. if productPhotoErr != nil {
  471. return nil, productPhotoErr
  472. }
  473. if productPhotoInfo != nil {
  474. for _, photo := range productPhotoInfo {
  475. fmt.Println(photo)
  476. if photo.Symbol == 1 {
  477. local.StorePhotoSymbol = 1
  478. local.StorePhotoUrl = photo.PhotoUrl
  479. local.StorePhotoUid = photo.PhotoUid
  480. }
  481. }
  482. }
  483. }
  484. return fullLocalData, nil
  485. }
  486. // FullSLocalTaskBillList 服务商本地生活子任务账单列表
  487. func (*sLocalLife) FullSLocalTaskBillList(ctx context.Context, request *http_model.FullSLocalTaskBillListRequest) (*http_model.FullSLocalTaskBillData, error) {
  488. var currSLocalTaskBillData *http_model.FullSLocalTaskBillData
  489. currSLocalTaskBillData = &http_model.FullSLocalTaskBillData{}
  490. currSLocalTaskBillData.DraftFee = 0
  491. currSLocalTaskBillData.DraftFeeSettle = 0
  492. // 1. 查找子任务
  493. taskList, total, taskListErr := db.GetSLocalTaskList(ctx, request.SLocalId, request.TalentId, request.PageSize, request.PageNum)
  494. if taskListErr != nil {
  495. return nil, taskListErr
  496. }
  497. if taskList != nil {
  498. currSLocalTaskBillData.Total = total
  499. for _, task := range taskList {
  500. var curr *http_model.FullSLocalTaskBillListData
  501. curr = &http_model.FullSLocalTaskBillListData{}
  502. curr.TaskId = task.TaskID
  503. curr.ServiceCharge = task.ServiceCharge
  504. curr.ViewNum = 0
  505. curr.VoteNum = 0
  506. curr.CommitNum = 0
  507. curr.CollectNum = 0
  508. curr.ServiceCharge = task.ServiceCharge
  509. curr.DraftFee = task.DraftFee
  510. curr.DelayRate = task.ScriptBreakRate + task.SketchBreakRate + task.LinkBreakRate + task.DataBreakRate
  511. curr.RealServiceCharge = task.RealPayment - task.SettleAmount
  512. curr.SettleAmount = task.SettleAmount
  513. curr.SettleTime = conv.MustString(task.CompleteDate)
  514. currSLocalTaskBillData.DraftFee += curr.DraftFee
  515. currSLocalTaskBillData.DraftFeeSettle += curr.SettleAmount
  516. currSLocalTaskBillData.SLocalTaskList = append(currSLocalTaskBillData.SLocalTaskList, curr)
  517. }
  518. // 2. 补充任务信息
  519. sLocalInfo, sLocalErr := db.GetSLocalLifeDetail(ctx, request.SLocalId)
  520. if sLocalErr != nil {
  521. return nil, sLocalErr
  522. }
  523. if sLocalInfo != nil {
  524. currSLocalTaskBillData.SettleNum = sLocalInfo.SettleNum
  525. currSLocalTaskBillData.ChooseNum = sLocalInfo.ApplyNum
  526. currSLocalTaskBillData.ServiceCharge = sLocalInfo.ServiceCharge
  527. currSLocalTaskBillData.ServiceChargeSettle = sLocalInfo.ServiceChargeSettle
  528. }
  529. }
  530. return currSLocalTaskBillData, nil
  531. }
  532. // CountLocalTask 按照状态统计子任务数量
  533. func (*sLocalLife) CountLocalTask(ctx context.Context, req *http_model.LocalTaskCountRequest) (*http_model.LocalTaskCountData, error) {
  534. var counter *http_model.LocalTaskCountData
  535. counter = &http_model.LocalTaskCountData{}
  536. // 1. Stage1
  537. stage1, stage1Err := db.CountLocalTaskNumByTaskStage(ctx, 0, 1, req.SLocalId)
  538. if stage1Err != nil {
  539. return nil, stage1Err
  540. }
  541. counter.Stage1 = stage1
  542. // 2. Stage2
  543. stage2, stage2Err := db.CountLocalTaskNumByTaskStage(ctx, 0, 2, req.SLocalId)
  544. if stage2Err != nil {
  545. return nil, stage2Err
  546. }
  547. counter.Stage2 = stage2
  548. // 3. Stage3
  549. stage3, stage3Err := db.CountLocalTaskNumByTaskStage(ctx, 0, 3, req.SLocalId)
  550. if stage3Err != nil {
  551. return nil, stage3Err
  552. }
  553. counter.Stage3 = stage3
  554. // 4. Stage4
  555. stage4, stage4Err := db.CountLocalTaskNumByTaskStage(ctx, 1, 2, req.SLocalId)
  556. if stage4Err != nil {
  557. return nil, stage4Err
  558. }
  559. counter.Stage4 = stage4
  560. // 5. Stage5
  561. stage5, stage5Err := db.CountLocalTaskNumByTaskStage(ctx, 2, 2, req.SLocalId)
  562. if stage5Err != nil {
  563. return nil, stage5Err
  564. }
  565. counter.Stage5 = stage5
  566. // 6. Stage6
  567. stage6, stage6Err := db.CountLocalTaskNumByTaskStage(ctx, 3, 2, req.SLocalId)
  568. if stage6Err != nil {
  569. return nil, stage6Err
  570. }
  571. counter.Stage6 = stage6
  572. // 7. Stage7
  573. stage7, stage7Err := db.CountLocalTaskNumByTaskStage(ctx, 0, 0, req.SLocalId)
  574. if stage7Err != nil {
  575. return nil, stage7Err
  576. }
  577. counter.Stage7 = stage7
  578. return counter, nil
  579. }
  580. func (p *sLocalLife) GetLocalStrategys(ctx *gin.Context, req *http_model.LocalStrategyRequest) ([]gorm_model.RecruitStrategy, error) {
  581. slocalInfo, slocalErr := db.GetSLocalLifeDetail(ctx, req.SLocalId)
  582. if slocalErr != nil {
  583. return nil, slocalErr
  584. }
  585. if slocalInfo != nil {
  586. if slocalInfo.StrategyStatus == 1 {
  587. recruitStrategys, getProjectStrategysErr := db.GetRecruitStrategyBySProjectId(ctx, req.SLocalId)
  588. if getProjectStrategysErr != nil {
  589. return nil, getProjectStrategysErr
  590. }
  591. return recruitStrategys, nil
  592. } else {
  593. recruitStrategys, getProjectStrategysErr := db.GetRecruitStrategyByProjectId(ctx, req.LocalId)
  594. if getProjectStrategysErr != nil {
  595. return nil, getProjectStrategysErr
  596. }
  597. return recruitStrategys, nil
  598. }
  599. }
  600. return nil, nil
  601. }