s_local_life.go 26 KB

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