s_project.go 28 KB

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