s_local_life.go 27 KB

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