s_local_life.go 22 KB

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