s_project.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/issue9/conv"
  6. log "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 SProject *sProject
  16. type sProject struct {
  17. }
  18. // CreateSProject 新建服务商加入商单后的公开种草任务
  19. func (*sProject) CreateSProject(ctx context.Context, request http_model.AddToListRequest) error {
  20. // 1. 建立SProject信息
  21. // 1.1. 根据传入的ProjectId去Project表查找信息补全SProject
  22. var operatorType int
  23. if request.SubAccountId == 0 {
  24. operatorType = 1
  25. } else {
  26. operatorType = 2
  27. }
  28. newSProject := gorm_model.SProjectInfo{
  29. EnterpriseId: request.EnterpriseId,
  30. SupplierId: request.SupplierId,
  31. ProjectId: request.ProjectId,
  32. SubAccountId: request.SubAccountId,
  33. OperatorType: operatorType,
  34. SProjectStatus: 2,
  35. StrategyStatus: 1,
  36. }
  37. projectInfo, projectErr := db.GetProjectDetail(ctx, request.ProjectId)
  38. if projectErr != nil {
  39. return projectErr
  40. }
  41. if projectInfo != nil {
  42. var currentTime time.Time
  43. currentTime = time.Now()
  44. newSProject.ProjectStatus = projectInfo.ProjectStatus
  45. newSProject.ProjectForm = projectInfo.ProjectForm
  46. newSProject.ContentType = projectInfo.ContentType
  47. newSProject.ProjectPlatform = projectInfo.ProjectPlatform
  48. newSProject.CreateTime = &currentTime
  49. newSProject.ProjectType = 1
  50. newSProject.ProductId = projectInfo.ProductID
  51. newSProject.ProjectName = projectInfo.ProjectName
  52. newSProject.AgreeTime = &currentTime
  53. }
  54. sProjectId, err := db.CreateSProject(ctx, newSProject)
  55. if err != nil {
  56. log.Infof("[CreateEnterpriseSubUser] fail,err:%+v", err)
  57. return err
  58. }
  59. fmt.Println("创建SProject信息成功")
  60. // 2. 建立新的recruitStrategy
  61. // 2.1. 根据projectId去查找原来的recruitStrategy
  62. recruitStrategys, strategyErr := db.GetRecruitStrategyByProjectId(ctx, request.ProjectId)
  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.SProjectId = sProjectId
  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. fmt.Println("创建招募策略成功")
  91. return nil
  92. }
  93. // GetSProjectList 查找服务商加入商单的种草任务列表
  94. func (*sProject) GetSProjectList(ctx context.Context, supplierId int, pageSize, pageNum int32, condition *common_model.SProjectCondition) (*http_model.SProjectData, error) {
  95. var SProjectList *http_model.SProjectData
  96. SProjectList = &http_model.SProjectData{}
  97. // 1. 加入商单后的种草任务基本信息
  98. sProjects, total, err := db.GetSProjectList(ctx, supplierId, pageSize, pageNum, condition)
  99. if err != nil {
  100. return nil, err
  101. }
  102. SProjectList.Total = total
  103. // 2. 商品信息填入
  104. for _, sProjectInfo := range sProjects {
  105. var currSProject *http_model.SProjectListReview
  106. currSProject = &http_model.SProjectListReview{}
  107. currSProject.SProjectId = sProjectInfo.SProjectId
  108. currSProject.ProjectId = sProjectInfo.ProjectId
  109. currSProject.ProjectName = sProjectInfo.ProjectName
  110. currSProject.ProjectPlatform = sProjectInfo.ProjectPlatform
  111. currSProject.ContentType = sProjectInfo.ContentType
  112. currSProject.EnterpriseId = sProjectInfo.EnterpriseId
  113. currSProject.ProjectForm = sProjectInfo.ProjectForm
  114. currSProject.ProjectStatus = sProjectInfo.ProjectStatus
  115. currSProject.SupplierId = sProjectInfo.SupplierId
  116. currSProject.SubAccountId = sProjectInfo.SubAccountId
  117. currSProject.OperatorType = sProjectInfo.OperatorType
  118. if sProjectInfo.OperatorType == 1 {
  119. currSProject.AddToListOperator = conv.MustString(sProjectInfo.SupplierId)
  120. } else {
  121. currSProject.AddToListOperator = conv.MustString(sProjectInfo.SubAccountId)
  122. }
  123. currSProject.CreateTime = conv.MustString(sProjectInfo.CreateTime)[0:19]
  124. currSProject.ApplyNum = sProjectInfo.ApplyNum
  125. currSProject.RecruitNum = sProjectInfo.RecruitNum
  126. currSProject.SettleNum = sProjectInfo.SettleNum
  127. currSProject.ServiceChargeActual = sProjectInfo.ServiceChargeActual
  128. currSProject.ServiceCharge = sProjectInfo.ServiceCharge
  129. currSProject.ServiceChargeSettle = sProjectInfo.ServiceChargeSettle
  130. // 2.2. 商品信息
  131. productInfo, productErr := db.GetProductByID(ctx, sProjectInfo.ProductId)
  132. if productErr != nil {
  133. return nil, productErr
  134. }
  135. if productInfo != nil {
  136. currSProject.ProductId = productInfo.ProductID
  137. currSProject.ProductPrice = productInfo.ProductPrice
  138. currSProject.ProductName = productInfo.ProductName
  139. }
  140. // 2.3. 商品图片信息
  141. productPhotoInfo, productPhotoErr := db.GetProductPhotoByProductID(ctx, sProjectInfo.ProductId)
  142. if productPhotoErr != nil {
  143. return nil, productPhotoErr
  144. }
  145. if productPhotoInfo != nil {
  146. for _, photo := range productPhotoInfo {
  147. fmt.Println(photo)
  148. if photo.Symbol == 1 {
  149. currSProject.ProductPhotoSymbol = 1
  150. currSProject.ProductPhotoUrl = photo.PhotoUrl
  151. currSProject.ProductPhotoUid = photo.PhotoUid
  152. }
  153. }
  154. }
  155. SProjectList.SProjectList = append(SProjectList.SProjectList, currSProject)
  156. }
  157. return SProjectList, nil
  158. }
  159. // GetSProjectDetail 查找服务商种草任务详情
  160. func (*sProject) GetSProjectDetail(ctx context.Context, sProjectId int) (*http_model.ShowSProjectData, error) {
  161. var sProjectData *http_model.ShowSProjectData
  162. sProjectData = &http_model.ShowSProjectData{}
  163. // 1. 取出服务商种草表中的信息
  164. sProjectInfo, err := db.GetSProjectDetail(ctx, sProjectId)
  165. if err != nil {
  166. return nil, err
  167. }
  168. if sProjectInfo != nil {
  169. sProjectData.ProjectStatus = sProjectInfo.ProjectStatus
  170. sProjectData.ProjectType = sProjectInfo.ProjectType
  171. sProjectData.SProjectId = sProjectInfo.SProjectId
  172. sProjectData.ProjectName = sProjectInfo.ProjectName
  173. sProjectData.ProjectID = sProjectInfo.ProjectId
  174. sProjectData.ProjectType = sProjectInfo.ProjectType
  175. sProjectData.ProjectPlatform = sProjectInfo.ProjectPlatform
  176. sProjectData.ProjectForm = sProjectInfo.ProjectForm
  177. sProjectData.ContentType = sProjectInfo.ContentType
  178. sProjectData.EnterpriseID = sProjectInfo.EnterpriseId
  179. sProjectData.CreateAt = conv.MustString(sProjectInfo.CreateTime)[0:19]
  180. // 2. 取出商家发布的种草任务表中的信息作为补充
  181. projectInfo, projectErr := db.GetProjectDetail(ctx, sProjectInfo.ProjectId)
  182. if projectErr != nil {
  183. return nil, projectErr
  184. }
  185. if projectInfo != nil {
  186. //sProjectData.TalentType = projectInfo.TalentType
  187. parts := strings.Split(projectInfo.TalentType, ",")
  188. var result []int
  189. for _, part := range parts {
  190. num, strErr := strconv.Atoi(strings.TrimSpace(part))
  191. if strErr != nil {
  192. return nil, strErr
  193. }
  194. result = append(result, num)
  195. }
  196. fmt.Println(result)
  197. talentTypeCategory, talentTypeErr := db.GetTalentCategory(ctx, result)
  198. if talentTypeErr != nil {
  199. return nil, talentTypeErr
  200. }
  201. if talentTypeCategory != nil {
  202. categories := make([]string, 0, len(talentTypeCategory))
  203. for _, talentType := range talentTypeCategory {
  204. categories = append(categories, talentType.Category)
  205. }
  206. sProjectData.TalentType = strings.Join(categories, ",")
  207. }
  208. sProjectData.RecruitDdl = conv.MustString(projectInfo.RecruitDdl)[0:19]
  209. sProjectData.ProjectDetail = projectInfo.ProjectDetail
  210. if projectInfo.PayAt != nil {
  211. sProjectData.PayAt = conv.MustString(projectInfo.PayAt)[0:19]
  212. }
  213. sProjectData.ProjectDetail = projectInfo.ProjectDetail
  214. sProjectData.EstimatedCost = 0.0
  215. sProjectData.ServiceChargeRate = projectInfo.ServiceChargeRate
  216. sProjectData.PassAt = conv.MustString(projectInfo.PassAt)[0:19]
  217. autoTaskInfo, autoTaskErr := db.GetAutoTaskById(ctx, int(projectInfo.AutoTaskID))
  218. if autoTaskErr != nil {
  219. return nil, autoTaskErr
  220. }
  221. if autoTaskInfo != nil {
  222. newTime := projectInfo.PassAt.Add(time.Duration(autoTaskInfo.Invalid) * time.Hour)
  223. sProjectData.AutoFailAt = conv.MustString(newTime)[0:19]
  224. }
  225. // 3. 取出招募策略并聚合达人数量信息
  226. if sProjectInfo.ProjectType == 1 {
  227. recruitStrategy, recruitErr := db.GetRecruitStrategyBySProjectId(ctx, sProjectData.SProjectId)
  228. if recruitErr != nil {
  229. return nil, recruitErr
  230. }
  231. if recruitStrategy != nil {
  232. for _, strategy := range recruitStrategy {
  233. // fmt.Println("recruitStrategy: ", strategy)
  234. selectedNumber, countTaskErr := db.CountTaskNumByStrategyIdAndSProjectId(ctx, sProjectData.SProjectId, strategy.StrategyID)
  235. if countTaskErr != nil {
  236. return nil, countTaskErr
  237. }
  238. sProjectData.EstimatedCost += strategy.Offer * float64(strategy.RecruitNumber)
  239. showStrategy := http_model.ShowSRecruitStrategy{
  240. StrategyID: strategy.StrategyID,
  241. FeeForm: strategy.FeeForm,
  242. FollowersLow: strategy.FollowersLow,
  243. FollowersUp: strategy.FollowersUp,
  244. RecruitNumber: strategy.RecruitNumber,
  245. ServiceCharge: strategy.ServiceCharge,
  246. ServiceChargeRate: strategy.ServiceRate,
  247. SelectedNumber: selectedNumber,
  248. Offer: strategy.Offer,
  249. }
  250. sProjectData.SRecruitStrategys = append(sProjectData.SRecruitStrategys, showStrategy)
  251. }
  252. }
  253. } else {
  254. recruitStrategy, recruitErr := db.GetRecruitStrategyByProjectId(ctx, sProjectData.ProjectID)
  255. if recruitErr != nil {
  256. return nil, recruitErr
  257. }
  258. if recruitStrategy != nil {
  259. for _, strategy := range recruitStrategy {
  260. // fmt.Println("recruitStrategy: ", strategy)
  261. selectedNumber, countTaskErr := db.CountTaskNumByStrategyId(ctx, sProjectData.ProjectID, strategy.StrategyID)
  262. if countTaskErr != nil {
  263. return nil, countTaskErr
  264. }
  265. sProjectData.EstimatedCost += strategy.Offer * float64(strategy.RecruitNumber)
  266. showStrategy := http_model.ShowSRecruitStrategy{
  267. StrategyID: strategy.StrategyID,
  268. FeeForm: strategy.FeeForm,
  269. FollowersLow: strategy.FollowersLow,
  270. FollowersUp: strategy.FollowersUp,
  271. RecruitNumber: strategy.RecruitNumber,
  272. ServiceCharge: strategy.ServiceCharge,
  273. ServiceChargeRate: strategy.ServiceRate,
  274. SelectedNumber: selectedNumber,
  275. Offer: strategy.Offer,
  276. }
  277. sProjectData.SRecruitStrategys = append(sProjectData.SRecruitStrategys, showStrategy)
  278. }
  279. }
  280. }
  281. // 4. 取出种草任务创建者用户信息
  282. if projectInfo.OperatorType == 1 {
  283. // fmt.Println("商家用户")
  284. enterpriseInfo, enterpriseErr := db.GetEnterpriseByEnterpriseID(ctx, projectInfo.EnterpriseID)
  285. if enterpriseErr != nil {
  286. return nil, enterpriseErr
  287. }
  288. sProjectData.CreatorName = enterpriseInfo.BusinessName
  289. sProjectData.CreatorCompany = enterpriseInfo.BusinessName
  290. sProjectData.CreatorType = 1
  291. sProjectData.Phone = enterpriseInfo.BusinessName
  292. } else if projectInfo.OperatorType == 2 {
  293. // fmt.Println("商家子账号")
  294. enterpriseInfo, enterpriseErr := db.GetEnterpriseByEnterpriseID(ctx, projectInfo.EnterpriseID)
  295. if enterpriseErr != nil {
  296. return nil, enterpriseErr
  297. }
  298. sProjectData.CreatorCompany = enterpriseInfo.BusinessName
  299. subAccountInfo, SubAccountErr := db.FindSubAccountById(ctx, projectInfo.SubAccountId)
  300. if SubAccountErr != nil {
  301. return nil, SubAccountErr
  302. }
  303. sProjectData.Phone = subAccountInfo.PhoneNumber
  304. jobInfo, jobErr := db.FindJobByJobId(ctx, subAccountInfo.JobId)
  305. if jobErr != nil {
  306. return nil, jobErr
  307. }
  308. sProjectData.CreatorType = 2
  309. sProjectData.CreatorName = jobInfo.JobName
  310. }
  311. // 5. 商品信息
  312. // 5.1. 取出商品信息并聚合
  313. productInfo, productErr := db.GetProductByID(ctx, projectInfo.ProductID)
  314. if productErr != nil {
  315. return nil, productErr
  316. }
  317. if productInfo != nil {
  318. sProjectData.ProductID = productInfo.ProductID
  319. sProjectData.ProductName = productInfo.ProductName
  320. sProjectData.ProductType = productInfo.ProductType
  321. sProjectData.ProductPrice = productInfo.ProductPrice
  322. sProjectData.ProductCategory = productInfo.ProductCategory
  323. sProjectData.ProductCreateAt = conv.MustString(projectInfo.CreatedAt)[0:19]
  324. }
  325. // 5.2. 聚合商品图片信息
  326. productPhotoInfo, productPhotoErr := db.GetProductPhotoByProductID(ctx, projectInfo.ProductID)
  327. if productPhotoErr != nil {
  328. return nil, productPhotoErr
  329. }
  330. if productPhotoInfo != nil {
  331. for _, p := range productPhotoInfo {
  332. if p.Symbol == 1 {
  333. sProjectData.ProductMainPhotoUrl = p.PhotoUrl
  334. sProjectData.ProductMainPhotoUid = p.PhotoUid
  335. sProjectData.Symbol = 1
  336. }
  337. }
  338. }
  339. // 6. 执行要求Brief和素材
  340. // 6.1. Brief
  341. projectBrief, briefErr := db.FindProjectBriefByProjectId(ctx, sProjectData.ProjectID)
  342. if briefErr != nil {
  343. return nil, briefErr
  344. }
  345. if projectBrief != nil {
  346. sProjectData.ProjectBriefInfo = projectBrief
  347. }
  348. // 6.2. 素材
  349. projectMaterial, materialErr := db.FindProjectMaterialByProjectId(ctx, sProjectData.ProjectID)
  350. if materialErr != nil {
  351. return nil, materialErr
  352. }
  353. if projectMaterial != nil {
  354. sProjectData.ProjectMaterial = projectMaterial
  355. }
  356. }
  357. }
  358. return sProjectData, nil
  359. }
  360. // GetSpecialProjectList 查找服务商加入商单前的定向种草任务列表
  361. func (*sProject) GetSpecialProjectList(ctx context.Context, supplierId int, pageSize, pageNum int32, condition *common_model.SpecialSProjectCondition) (*http_model.SpecialProjectListData, error) {
  362. var specialProjectListData *http_model.SpecialProjectListData
  363. specialProjectListData = &http_model.SpecialProjectListData{}
  364. // 1. 定向种草任务基本信息填入
  365. specialProjects, total, err := db.GetSpecialProjectList(ctx, supplierId, pageSize, pageNum, condition, 1)
  366. if err != nil {
  367. return nil, err
  368. }
  369. if specialProjects != nil {
  370. specialProjectListData.Total = total
  371. for _, specialProject := range specialProjects {
  372. var currSpecialProject *http_model.SpecialProjectResponse
  373. currSpecialProject = &http_model.SpecialProjectResponse{}
  374. currSpecialProject.ProjectId = specialProject.ProjectId
  375. currSpecialProject.ProjectName = specialProject.ProjectName
  376. currSpecialProject.ProjectStatus = int(specialProject.ProjectStatus)
  377. currSpecialProject.SProjectId = specialProject.SProjectId
  378. currSpecialProject.EnterpriseId = specialProject.EnterpriseId
  379. currSpecialProject.ProjectPlatform = specialProject.ProjectPlatform
  380. currSpecialProject.ProjectForm = specialProject.ProjectForm
  381. currSpecialProject.ContentType = specialProject.ContentType
  382. currSpecialProject.SProjectStatus = specialProject.SProjectStatus
  383. if specialProject.SProjectStatus == 2 {
  384. currSpecialProject.AddToListStatus = 1
  385. } else {
  386. currSpecialProject.AddToListStatus = 2
  387. }
  388. // 2. 定向种草任务商品信息填入
  389. // 2.1. 商品信息
  390. productInfo, productErr := db.GetProductByID(ctx, specialProject.ProductId)
  391. if productErr != nil {
  392. return nil, productErr
  393. }
  394. if productInfo != nil {
  395. currSpecialProject.ProductId = productInfo.ProductID
  396. currSpecialProject.ProductName = productInfo.ProductName
  397. currSpecialProject.ProductPrice = productInfo.ProductPrice
  398. }
  399. // 2.2. 商品图片信息
  400. productPhotoInfo, productPhotoErr := db.GetProductPhotoByProductID(ctx, specialProject.ProductId)
  401. if productPhotoErr != nil {
  402. return nil, productPhotoErr
  403. }
  404. if productPhotoInfo != nil {
  405. for _, p := range productPhotoInfo {
  406. if p.Symbol == 1 {
  407. currSpecialProject.ProductPhotoUrl = p.PhotoUrl
  408. currSpecialProject.ProductPhotoUid = p.PhotoUid
  409. currSpecialProject.ProductPhotoSymbol = 1
  410. }
  411. }
  412. }
  413. // 3. 招募策略信息
  414. recruitStrategy, recruitErr := db.GetRecruitStrategyByProjectId(ctx, specialProject.ProjectId)
  415. if recruitErr != nil {
  416. return nil, recruitErr
  417. }
  418. if recruitStrategy != nil {
  419. for _, strategy := range recruitStrategy {
  420. showStrategy := http_model.EasyRecruitStrategy{
  421. FeeForm: strategy.FeeForm,
  422. RecruitNumber: strategy.RecruitNumber,
  423. StrategyId: strategy.StrategyID,
  424. }
  425. currSpecialProject.RecruitStrategy = append(currSpecialProject.RecruitStrategy, showStrategy)
  426. }
  427. }
  428. // 4. 原种草任务信息
  429. projectInfo, projectErr := db.GetProjectDetail(ctx, specialProject.ProjectId)
  430. if projectErr != nil {
  431. return nil, projectErr
  432. }
  433. if projectInfo != nil {
  434. currSpecialProject.Tools = projectInfo.Tools
  435. }
  436. specialProjectListData.SpecialProjectInfo = append(specialProjectListData.SpecialProjectInfo, currSpecialProject)
  437. }
  438. } else {
  439. specialProjectListData.Total = 0
  440. }
  441. return specialProjectListData, nil
  442. }
  443. // GetSpecialSProjectList 查找服务商加入商单后的定向种草任务列表
  444. func (*sProject) GetSpecialSProjectList(ctx context.Context, supplierId int, pageSize, pageNum int32, condition *common_model.SpecialSProjectCondition) (*http_model.SpecialSProjectListData, error) {
  445. var specialProjectListData *http_model.SpecialSProjectListData
  446. specialProjectListData = &http_model.SpecialSProjectListData{}
  447. specialProjects, total, err := db.GetSpecialProjectList(ctx, supplierId, pageSize, pageNum, condition, 2)
  448. if err != nil {
  449. return nil, err
  450. }
  451. if specialProjects != nil {
  452. specialProjectListData.Total = total
  453. // 1. 定向种草任务基本信息填入
  454. for _, specialProject := range specialProjects {
  455. var currSpecialProject *http_model.SpecialSProjectResponse
  456. currSpecialProject = &http_model.SpecialSProjectResponse{}
  457. currSpecialProject.ProjectId = specialProject.ProjectId
  458. currSpecialProject.ProjectName = specialProject.ProjectName
  459. currSpecialProject.ProjectStatus = int(specialProject.ProjectStatus)
  460. currSpecialProject.SProjectId = specialProject.SProjectId
  461. currSpecialProject.ProjectPlatform = specialProject.ProjectPlatform
  462. currSpecialProject.ProjectForm = specialProject.ProjectForm
  463. currSpecialProject.ContentType = specialProject.ContentType
  464. currSpecialProject.EnterpriseId = specialProject.EnterpriseId
  465. currSpecialProject.SProjectStatus = specialProject.SProjectStatus
  466. currSpecialProject.StrategyStatus = specialProject.StrategyStatus
  467. currSpecialProject.ApplyNum = specialProject.ApplyNum
  468. currSpecialProject.RecruitNum = specialProject.RecruitNum
  469. currSpecialProject.SettleNum = specialProject.SettleNum
  470. currSpecialProject.CreateTime = conv.MustString(specialProject.CreateTime)[0:19]
  471. if specialProject.SProjectStatus == 2 && specialProject.AgreeTime != nil {
  472. currSpecialProject.AgreeTime = conv.MustString(specialProject.AgreeTime)[0:19]
  473. }
  474. // 加入商单操作人信息
  475. if specialProject.OperatorType == 1 {
  476. supplierInfo, supplierErr := db.GetSupplierById(ctx, supplierId)
  477. if supplierErr != nil {
  478. return nil, supplierErr
  479. }
  480. if supplierInfo != nil {
  481. currSpecialProject.AddToListOperator = supplierInfo.SupplierName
  482. }
  483. } else if specialProject.OperatorType == 2 {
  484. subAccountInfo, subAccountErr := db.FindSubAccountById(ctx, specialProject.SubAccountId)
  485. if subAccountErr != nil {
  486. return nil, subAccountErr
  487. }
  488. if subAccountInfo != nil {
  489. currSpecialProject.AddToListOperator = subAccountInfo.SubAccountName
  490. }
  491. }
  492. // 2. 定向种草任务商品信息填入
  493. // 2.1. 商品信息
  494. productInfo, productErr := db.GetProductByID(ctx, specialProject.ProductId)
  495. if productErr != nil {
  496. return nil, productErr
  497. }
  498. if productInfo != nil {
  499. currSpecialProject.ProductId = productInfo.ProductID
  500. currSpecialProject.ProductName = productInfo.ProductName
  501. currSpecialProject.ProductPrice = productInfo.ProductPrice
  502. }
  503. // 2.2. 商品图片信息
  504. productPhotoInfo, productPhotoErr := db.GetProductPhotoByProductID(ctx, specialProject.ProductId)
  505. if productPhotoErr != nil {
  506. return nil, productPhotoErr
  507. }
  508. if productPhotoInfo != nil {
  509. for _, p := range productPhotoInfo {
  510. if p.Symbol == 1 {
  511. currSpecialProject.ProductPhotoUrl = p.PhotoUrl
  512. currSpecialProject.ProductPhotoUid = p.PhotoUid
  513. currSpecialProject.ProductPhotoSymbol = 1
  514. }
  515. }
  516. }
  517. // 3. 招募策略信息
  518. // recruitStrategy, recruitErr := db.GetRecruitStrategyByProjectId(ctx, specialProject.ProjectId)
  519. // if recruitErr != nil {
  520. // return nil, recruitErr
  521. // }
  522. // if recruitStrategy != nil {
  523. // for _, strategy := range recruitStrategy {
  524. // showStrategy := http_model.EasyRecruitStrategy{
  525. // FeeForm: strategy.FeeForm,
  526. // RecruitNumber: strategy.RecruitNumber,
  527. // StrategyId: strategy.StrategyID,
  528. // }
  529. // currSpecialProject.RecruitStrategy = append(currSpecialProject.RecruitStrategy, showStrategy)
  530. // }
  531. // }
  532. // 4. 原种草任务信息
  533. projectInfo, projectErr := db.GetProjectDetail(ctx, specialProject.ProjectId)
  534. if projectErr != nil {
  535. return nil, projectErr
  536. }
  537. if projectInfo != nil {
  538. currSpecialProject.Tools = projectInfo.Tools
  539. }
  540. specialProjectListData.SpecialProjectInfo = append(specialProjectListData.SpecialProjectInfo, currSpecialProject)
  541. }
  542. } else {
  543. specialProjectListData.Total = 0
  544. }
  545. return specialProjectListData, nil
  546. }
  547. // UpdateSProject 更新SProject信息
  548. func (*sProject) UpdateSProject(ctx context.Context, request *http_model.SpecialSProjectAddToListRequest) error {
  549. updateSProjectErr := db.UpdateSProjectStatus(ctx, request)
  550. if updateSProjectErr != nil {
  551. return updateSProjectErr
  552. }
  553. return nil
  554. }
  555. // CreateSpecialStrategy 添加服务商招募策略
  556. func (*sProject) CreateSpecialStrategy(ctx context.Context, request *http_model.SpecialAddStrategyRequest) error {
  557. // 1. 添加服务商招募策略
  558. // 1.1. 整理数据
  559. var recruitStrategys []gorm_model.RecruitStrategy
  560. for _, strategy := range request.RecruitStrategys {
  561. var recruitStrategy *gorm_model.RecruitStrategy
  562. recruitStrategy = &gorm_model.RecruitStrategy{}
  563. recruitStrategy.StrategyID = strategy.StrategyID
  564. recruitStrategy.QuoteRecruitStrategyId = strategy.QuoteRecruitStrategyId
  565. recruitStrategy.FeeForm = strategy.FeeForm
  566. recruitStrategy.StrategyID = strategy.StrategyID
  567. recruitStrategy.FollowersLow = strategy.FollowersLow
  568. recruitStrategy.FollowersUp = strategy.FollowersUp
  569. recruitStrategy.RecruitNumber = strategy.RecruitNumber
  570. recruitStrategy.Offer = strategy.Offer
  571. recruitStrategy.ServiceCharge = strategy.ServiceCharge
  572. recruitStrategy.StrategyType = 2
  573. recruitStrategy.QuoteRecruitStrategyId = strategy.QuoteRecruitStrategyId
  574. // 一口价需要计算服务费率和达人所见报价
  575. if strategy.FeeForm == 3 {
  576. recruitStrategy.ServiceRate = strategy.ServiceRate
  577. } else {
  578. recruitStrategy.ServiceRate = int(strategy.ServiceCharge / strategy.Offer)
  579. }
  580. recruitStrategy.TOffer = strategy.Offer - strategy.ServiceCharge
  581. recruitStrategy.ProjectID = "0"
  582. recruitStrategy.SProjectId = request.SProjectId
  583. recruitStrategys = append(recruitStrategys, *recruitStrategy)
  584. }
  585. createErr := db.CreateSpecialStrategy(ctx, recruitStrategys)
  586. if createErr != nil {
  587. return createErr
  588. }
  589. // 2. 修改sProject中的字段
  590. updateErr := db.UpdateSProjectStrategyStatus(ctx, request)
  591. if updateErr != nil {
  592. return updateErr
  593. }
  594. return nil
  595. }
  596. // FullSProjectBillList 种草任务账单列表
  597. func (*sProject) FullSProjectBillList(ctx context.Context, request *http_model.FullSProjectBillListRequest) (*http_model.FullSProjectBillData, error) {
  598. var currSProjectBillData *http_model.FullSProjectBillData
  599. currSProjectBillData = &http_model.FullSProjectBillData{}
  600. // 1. 根据SupplierId和账单状态查询数据
  601. fullSProjectBillData, total, err := db.GetFullSProjectBillList(ctx, request.SupplierId, request.ProjectType, request.ProjectPlatform, request.ProjectStatus, request.PageSize, request.PageNum-1)
  602. if err != nil {
  603. return nil, err
  604. }
  605. if fullSProjectBillData != nil {
  606. currSProjectBillData.Total = total
  607. for _, b := range fullSProjectBillData {
  608. var billData *http_model.FullSProjectBillListData
  609. billData = &http_model.FullSProjectBillListData{}
  610. billData.SProjectId = b.SProjectId
  611. billData.ProjectId = b.ProjectId
  612. billData.ProjectPlatform = b.ProjectPlatform
  613. billData.ProjectForm = b.ProjectForm
  614. billData.ContentType = b.ContentType
  615. billData.ProjectStatus = b.ProjectStatus
  616. billData.EnterpriseId = b.EnterpriseId
  617. billData.SupplierId = b.SupplierId
  618. billData.SubAccountId = b.SubAccountId
  619. billData.ServiceChargeActual = b.ServiceChargeActual
  620. billData.ServiceChargeSettle = b.ServiceChargeSettle
  621. // 1.2. 补充商品信息
  622. productInfo, productErr := db.GetProductByID(ctx, b.ProductId)
  623. if productErr != nil {
  624. return nil, productErr
  625. }
  626. if productInfo != nil {
  627. billData.ProductId = productInfo.ProductID
  628. billData.ProductPrice = productInfo.ProductPrice
  629. billData.ProductName = productInfo.ProductName
  630. }
  631. // 1.3. 商品图片信息
  632. productPhotoInfo, productPhotoErr := db.GetProductPhotoByProductID(ctx, b.ProductId)
  633. if productPhotoErr != nil {
  634. return nil, productPhotoErr
  635. }
  636. if productPhotoInfo != nil {
  637. for _, photo := range productPhotoInfo {
  638. //fmt.Println(photo)
  639. if photo.Symbol == 1 {
  640. billData.ProductPhotoSymbol = 1
  641. billData.ProductPhotoUrl = photo.PhotoUrl
  642. billData.ProductPhotoUid = photo.PhotoUid
  643. }
  644. }
  645. }
  646. currSProjectBillData.SProjectList = append(currSProjectBillData.SProjectList, billData)
  647. }
  648. }
  649. return currSProjectBillData, nil
  650. }
  651. // FullSProjectTaskBillList 种草子任务账单列表
  652. func (*sProject) FullSProjectTaskBillList(ctx context.Context, request *http_model.FullSProjectTaskBillListRequest) (*http_model.FullSProjectTaskBillData, error) {
  653. var currSProjectTaskBillData *http_model.FullSProjectTaskBillData
  654. currSProjectTaskBillData = &http_model.FullSProjectTaskBillData{}
  655. currSProjectTaskBillData.DraftFee = 0
  656. currSProjectTaskBillData.DraftFeeSettle = 0
  657. // 1. 查找子任务
  658. taskList, total, taskListErr := db.GetSProjectTaskList(ctx, request.SProjectId, request.Condition, request.PageSize, request.PageNum-1)
  659. if taskListErr != nil {
  660. return nil, taskListErr
  661. }
  662. if taskList != nil {
  663. currSProjectTaskBillData.Total = total
  664. for _, task := range taskList {
  665. var curr *http_model.FullSProjectTaskBillListData
  666. curr = &http_model.FullSProjectTaskBillListData{}
  667. curr.TaskId = task.TaskID
  668. curr.ServiceCharge = task.ServiceCharge
  669. curr.ViewNum = 0
  670. curr.VoteNum = 0
  671. curr.CommitNum = 0
  672. curr.CollectNum = 0
  673. curr.ServiceCharge = task.ServiceCharge
  674. curr.DraftFee = task.DraftFee
  675. curr.DelayRate = task.ScriptBreakRate + task.SketchBreakRate + task.LinkBreakRate + task.DataBreakRate
  676. if task.TaskStage < 15 {
  677. curr.RealServiceCharge = 0
  678. } else {
  679. curr.RealServiceCharge = task.RealPayment - task.SettleAmount
  680. }
  681. curr.SettleAmount = task.SettleAmount
  682. if task.CompleteDate != nil {
  683. curr.SettleTime = conv.MustString(task.CompleteDate, "")
  684. }
  685. // 用户第三方平台信息
  686. platformUserInfo, platformUserErr := db.FindUserInfoByOpenId(ctx, task.OpenId)
  687. if platformUserErr != nil {
  688. return nil, platformUserErr
  689. }
  690. if platformUserInfo != nil {
  691. curr.TalentHeadUrl = platformUserInfo.HeadUri
  692. curr.TalentNackName = platformUserInfo.NickName
  693. }
  694. currSProjectTaskBillData.DraftFee += curr.DraftFee
  695. currSProjectTaskBillData.DraftFeeSettle += curr.SettleAmount
  696. currSProjectTaskBillData.SProjectTaskList = append(currSProjectTaskBillData.SProjectTaskList, curr)
  697. }
  698. // 2. 补充任务信息
  699. sProjectInfo, sProjectErr := db.GetSProjectDetail(ctx, request.SProjectId)
  700. if sProjectErr != nil {
  701. return nil, sProjectErr
  702. }
  703. if sProjectInfo != nil {
  704. currSProjectTaskBillData.SettleNum = sProjectInfo.SettleNum
  705. currSProjectTaskBillData.ChooseNum = sProjectInfo.ApplyNum
  706. currSProjectTaskBillData.ServiceCharge = sProjectInfo.ServiceCharge
  707. currSProjectTaskBillData.ServiceChargeSettle = sProjectInfo.ServiceChargeSettle
  708. }
  709. }
  710. return currSProjectTaskBillData, nil
  711. }