s_local_life.go 23 KB

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