s_project.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/issue9/conv"
  6. log "github.com/sirupsen/logrus"
  7. "time"
  8. "youngee_b_api/db"
  9. "youngee_b_api/model/common_model"
  10. "youngee_b_api/model/gorm_model"
  11. "youngee_b_api/model/http_model"
  12. )
  13. var SProject *sProject
  14. type sProject struct {
  15. }
  16. // CreateSProject 新建服务商加入商单后的公开种草任务
  17. func (*sProject) CreateSProject(ctx context.Context, request http_model.AddToListRequest) error {
  18. // 1. 建立SProject信息
  19. // 1.1. 根据传入的ProjectId去Project表查找信息补全SProject
  20. newSProject := gorm_model.SProjectInfo{
  21. EnterpriseId: request.EnterpriseId,
  22. SupplierId: request.SupplierId,
  23. ProjectId: request.ProjectId,
  24. SubAccountId: request.SubAccountId,
  25. OperatorType: request.OperatorType,
  26. SProjectStatus: 2,
  27. StrategyStatus: 1,
  28. }
  29. projectInfo, projectErr := db.GetProjectDetail(ctx, request.ProjectId)
  30. if projectErr != nil {
  31. return projectErr
  32. }
  33. if projectInfo != nil {
  34. var currentTime time.Time
  35. currentTime = time.Now()
  36. newSProject.ProjectStatus = projectInfo.ProjectStatus
  37. newSProject.ProjectForm = projectInfo.ProjectForm
  38. newSProject.ContentType = projectInfo.ContentType
  39. newSProject.ProjectPlatform = projectInfo.ProjectPlatform
  40. newSProject.CreateTime = &currentTime
  41. newSProject.ProjectType = 1
  42. newSProject.ProductId = projectInfo.ProductID
  43. newSProject.ProjectName = projectInfo.ProjectName
  44. }
  45. sProjectId, err := db.CreateSProject(ctx, newSProject)
  46. if err != nil {
  47. log.Infof("[CreateEnterpriseSubUser] fail,err:%+v", err)
  48. return err
  49. }
  50. fmt.Println("创建SProject信息成功")
  51. // 2. 建立新的recruitStrategy
  52. // 2.1. 根据projectId去查找原来的recruitStrategy
  53. recruitStrategys, strategyErr := db.GetRecruitStrategyByProjectId(ctx, request.ProjectId)
  54. if strategyErr != nil {
  55. return strategyErr
  56. }
  57. // 2.2. 设置新的结构体以写入
  58. var currRecruitStrategys []gorm_model.RecruitStrategy
  59. for _, strategy := range recruitStrategys {
  60. var currStrategy gorm_model.RecruitStrategy
  61. currStrategy.StrategyID = strategy.StrategyID
  62. currStrategy.QuoteRecruitStrategyId = int(strategy.RecruitStrategyID)
  63. currStrategy.FeeForm = strategy.FeeForm
  64. currStrategy.FollowersLow = strategy.FollowersLow
  65. currStrategy.FollowersUp = strategy.FollowersUp
  66. currStrategy.RecruitNumber = strategy.RecruitNumber
  67. currStrategy.Offer = strategy.Offer
  68. currStrategy.TOffer = strategy.TOffer
  69. currStrategy.ProjectID = "0"
  70. currStrategy.ServiceCharge = strategy.ServiceCharge
  71. currStrategy.ServiceRate = strategy.ServiceRate
  72. currStrategy.SProjectId = sProjectId
  73. currStrategy.StrategyType = 2
  74. currRecruitStrategys = append(currRecruitStrategys, currStrategy)
  75. }
  76. // 2.3. 写入
  77. createStrategyErr := db.CreateSpecialStrategy(ctx, currRecruitStrategys)
  78. if createStrategyErr != nil {
  79. return createStrategyErr
  80. }
  81. fmt.Println("创建招募策略成功")
  82. return nil
  83. }
  84. // GetSProjectList 查找服务商加入商单的种草任务列表
  85. func (*sProject) GetSProjectList(ctx context.Context, supplierId int, pageSize, pageNum int32, condition *common_model.SProjectCondition) (*http_model.SProjectData, error) {
  86. var SProjectList *http_model.SProjectData
  87. SProjectList = &http_model.SProjectData{}
  88. // 1. 加入商单后的种草任务基本信息
  89. sProjects, total, err := db.GetSProjectList(ctx, supplierId, pageSize, pageNum, condition)
  90. if err != nil {
  91. return nil, err
  92. }
  93. SProjectList.Total = total
  94. // 2. 商品信息填入
  95. for _, sProject := range sProjects {
  96. var currSProject *http_model.SProjectListReview
  97. currSProject = &http_model.SProjectListReview{}
  98. currSProject.SProjectId = sProject.SProjectId
  99. currSProject.ProjectId = sProject.ProjectId
  100. currSProject.ProjectPlatform = sProject.ProjectPlatform
  101. currSProject.ContentType = sProject.ContentType
  102. currSProject.ProjectForm = sProject.ProjectForm
  103. currSProject.ProjectStatus = sProject.ProjectStatus
  104. currSProject.SupplierId = sProject.SupplierId
  105. currSProject.SubAccountId = sProject.SubAccountId
  106. currSProject.OperatorType = sProject.OperatorType
  107. currSProject.CreateTime = conv.MustString(sProject.CreateTime)[0:19]
  108. currSProject.ApplyNum = sProject.ApplyNum
  109. currSProject.RecruitNum = sProject.RecruitNum
  110. currSProject.SettleNum = sProject.SettleNum
  111. currSProject.ServiceChargeActual = sProject.ServiceChargeActual
  112. currSProject.ServiceCharge = sProject.ServiceCharge
  113. currSProject.ServiceChargeSettle = sProject.ServiceChargeSettle
  114. // 2.2. 商品信息
  115. productInfo, productErr := db.GetProductByID(ctx, sProject.ProductId)
  116. if productErr != nil {
  117. return nil, productErr
  118. }
  119. if productInfo != nil {
  120. currSProject.ProductId = productInfo.ProductID
  121. currSProject.ProductPrice = productInfo.ProductPrice
  122. currSProject.ProductName = productInfo.ProductName
  123. }
  124. // 2.3. 商品图片信息
  125. productPhotoInfo, productPhotoErr := db.GetProductPhotoByProductID(ctx, sProject.ProductId)
  126. if productPhotoErr != nil {
  127. return nil, productPhotoErr
  128. }
  129. if productPhotoInfo != nil {
  130. for _, photo := range productPhotoInfo {
  131. fmt.Println(photo)
  132. if photo.Symbol == 1 {
  133. currSProject.ProductPhotoSymbol = 1
  134. currSProject.ProductPhotoUrl = photo.PhotoUrl
  135. currSProject.ProductPhotoUid = photo.PhotoUid
  136. }
  137. }
  138. }
  139. SProjectList.SProjectList = append(SProjectList.SProjectList, currSProject)
  140. }
  141. return SProjectList, nil
  142. }
  143. // GetSPorjectDetail 查找服务商种草任务详情
  144. func (*sProject) GetSPorjectDetail(ctx context.Context, sProjectId int) (*http_model.ShowSProjectData, error) {
  145. var sProjectData *http_model.ShowSProjectData
  146. sProjectData = &http_model.ShowSProjectData{}
  147. // 1. 取出服务商种草表中的信息
  148. sProjectInfo, err := db.GetSProjectDetail(ctx, sProjectId)
  149. if err != nil {
  150. return nil, err
  151. }
  152. if sProjectInfo != nil {
  153. sProjectData.SProjectId = sProjectInfo.SProjectId
  154. sProjectData.ProjectName = sProjectInfo.ProjectName
  155. sProjectData.ProjectID = sProjectInfo.ProjectId
  156. sProjectData.ProjectType = sProjectInfo.ProjectType
  157. sProjectData.ProjectPlatform = sProjectInfo.ProjectPlatform
  158. sProjectData.ProjectForm = sProjectInfo.ProjectForm
  159. sProjectData.ContentType = sProjectInfo.ContentType
  160. sProjectData.EnterpriseID = sProjectInfo.EnterpriseId
  161. // 2. 取出商家发布的种草任务表中的信息作为补充
  162. projectInfo, projectErr := db.GetProjectDetail(ctx, sProjectInfo.ProjectId)
  163. if projectErr != nil {
  164. return nil, projectErr
  165. }
  166. if projectInfo != nil {
  167. sProjectData.TalentType = projectInfo.TalentType
  168. sProjectData.RecruitDdl = conv.MustString(projectInfo.RecruitDdl)[0:19]
  169. sProjectData.ProjectDetail = projectInfo.ProjectDetail
  170. // sProjectData.PayAt = conv.MustString(projectInfo.PayAt)
  171. sProjectData.ProjectDetail = projectInfo.ProjectDetail
  172. sProjectData.EstimatedCost = projectInfo.EstimatedCost
  173. sProjectData.PassAt = conv.MustString(projectInfo.PassAt)[0:19]
  174. // 3. 取出招募策略并聚合达人数量信息
  175. recruitStrategy, recruitErr := db.GetRecruitStrategyBySProjectId(ctx, sProjectData.SProjectId)
  176. if recruitErr != nil {
  177. return nil, recruitErr
  178. }
  179. if recruitStrategy != nil {
  180. for _, strategy := range recruitStrategy {
  181. // fmt.Println("recruitStrategy: ", strategy)
  182. selectedNumber, countTaskErr := db.CountTaskNumByStrategyIdAndSProjectId(ctx, sProjectData.SProjectId, strategy.StrategyID)
  183. if countTaskErr != nil {
  184. return nil, countTaskErr
  185. }
  186. showStrategy := http_model.ShowSRecruitStrategy{
  187. StrategyID: strategy.StrategyID,
  188. FeeForm: strategy.FeeForm,
  189. FollowersLow: strategy.FollowersLow,
  190. FollowersUp: strategy.FollowersUp,
  191. RecruitNumber: strategy.RecruitNumber,
  192. ServiceCharge: projectInfo.ServiceChargeRate,
  193. SelectedNumber: selectedNumber,
  194. Offer: strategy.Offer,
  195. }
  196. sProjectData.SRecruitStrategys = append(sProjectData.SRecruitStrategys, showStrategy)
  197. }
  198. }
  199. // 4. 取出种草任务创建者用户信息
  200. if projectInfo.OperatorType == 1 {
  201. // fmt.Println("商家用户")
  202. enterpriseInfo, enterpriseErr := db.GetEnterpriseByEnterpriseID(ctx, projectInfo.EnterpriseID)
  203. if enterpriseErr != nil {
  204. return nil, enterpriseErr
  205. }
  206. sProjectData.CreatorName = enterpriseInfo.BusinessName
  207. sProjectData.CreatorCompany = enterpriseInfo.BusinessName
  208. sProjectData.CreatorType = 1
  209. sProjectData.Phone = enterpriseInfo.BusinessName
  210. } else if projectInfo.OperatorType == 2 {
  211. // fmt.Println("商家子账号")
  212. enterpriseInfo, enterpriseErr := db.GetEnterpriseByEnterpriseID(ctx, projectInfo.EnterpriseID)
  213. if enterpriseErr != nil {
  214. return nil, enterpriseErr
  215. }
  216. sProjectData.CreatorCompany = enterpriseInfo.BusinessName
  217. subAccountInfo, SubAccountErr := db.FindSubAccountById(ctx, projectInfo.SubAccountId)
  218. if SubAccountErr != nil {
  219. return nil, SubAccountErr
  220. }
  221. sProjectData.Phone = subAccountInfo.PhoneNumber
  222. jobInfo, jobErr := db.FindJobByJobId(ctx, subAccountInfo.JobId)
  223. if jobErr != nil {
  224. return nil, jobErr
  225. }
  226. sProjectData.CreatorType = 2
  227. sProjectData.CreatorName = jobInfo.JobName
  228. }
  229. // 5. 商品信息
  230. // 5.1. 取出商品信息并聚合
  231. productInfo, productErr := db.GetProductByID(ctx, projectInfo.ProductID)
  232. if productErr != nil {
  233. return nil, productErr
  234. }
  235. if productInfo != nil {
  236. sProjectData.ProductID = productInfo.ProductID
  237. sProjectData.ProductName = productInfo.ProductName
  238. sProjectData.ProductType = productInfo.ProductType
  239. sProjectData.ProductPrice = productInfo.ProductPrice
  240. sProjectData.ProductCategory = productInfo.ProductCategory
  241. }
  242. // 5.2. 聚合商品图片信息
  243. productPhotoInfo, productPhotoErr := db.GetProductPhotoByProductID(ctx, projectInfo.ProductID)
  244. if productPhotoErr != nil {
  245. return nil, productPhotoErr
  246. }
  247. if productPhotoInfo != nil {
  248. for _, p := range productPhotoInfo {
  249. if p.Symbol == 1 {
  250. sProjectData.ProductMainPhotoUrl = p.PhotoUrl
  251. sProjectData.ProductMainPhotoUid = p.PhotoUid
  252. sProjectData.Symbol = 1
  253. }
  254. }
  255. }
  256. // 6. 执行要求Brief和素材
  257. // 6.1. Brief
  258. projectBrief, briefErr := db.FindProjectBriefByProjectId(ctx, sProjectData.ProjectID)
  259. if briefErr != nil {
  260. return nil, briefErr
  261. }
  262. if projectBrief != nil {
  263. sProjectData.ProjectBriefInfo = projectBrief
  264. }
  265. // 6.2. 素材
  266. projectMaterial, materialErr := db.FindProjectMaterialByProjectId(ctx, sProjectData.ProjectID)
  267. if materialErr != nil {
  268. return nil, materialErr
  269. }
  270. if projectMaterial != nil {
  271. sProjectData.ProjectMaterial = projectMaterial
  272. }
  273. }
  274. }
  275. return sProjectData, nil
  276. }
  277. // GetSpecialProjectList 查找服务商加入商单前的定向种草任务列表
  278. func (*sProject) GetSpecialProjectList(ctx context.Context, supplierId int, pageSize, pageNum int32, condition *common_model.SpecialSProjectCondition) (*http_model.SpecialProjectListData, error) {
  279. var specialProjectListData *http_model.SpecialProjectListData
  280. specialProjectListData = &http_model.SpecialProjectListData{}
  281. // 1. 定向种草任务基本信息填入
  282. specialProjects, total, err := db.GetSpecialProjectList(ctx, supplierId, pageSize, pageNum, condition)
  283. if err != nil {
  284. return nil, err
  285. }
  286. if specialProjects != nil {
  287. specialProjectListData.Total = total
  288. for _, specialProject := range specialProjects {
  289. var currSpecialProject *http_model.SpecialProjectResponse
  290. currSpecialProject = &http_model.SpecialProjectResponse{}
  291. currSpecialProject.SProjectId = specialProject.SProjectId
  292. currSpecialProject.ProjectPlatform = specialProject.ProjectPlatform
  293. currSpecialProject.ProjectForm = specialProject.ProjectForm
  294. currSpecialProject.ContentType = specialProject.ContentType
  295. currSpecialProject.SProjectStatus = specialProject.SProjectStatus
  296. // 2. 定向种草任务商品信息填入
  297. // 2.1. 商品信息
  298. productInfo, productErr := db.GetProductByID(ctx, specialProject.ProductId)
  299. if productErr != nil {
  300. return nil, productErr
  301. }
  302. if productInfo != nil {
  303. currSpecialProject.ProductId = productInfo.ProductID
  304. currSpecialProject.ProductName = productInfo.ProductName
  305. currSpecialProject.ProductPrice = productInfo.ProductPrice
  306. }
  307. // 2.2. 商品图片信息
  308. productPhotoInfo, productPhotoErr := db.GetProductPhotoByProductID(ctx, specialProject.ProductId)
  309. if productPhotoErr != nil {
  310. return nil, productPhotoErr
  311. }
  312. if productPhotoInfo != nil {
  313. for _, p := range productPhotoInfo {
  314. if p.Symbol == 1 {
  315. currSpecialProject.ProductPhotoUrl = p.PhotoUrl
  316. currSpecialProject.ProductPhotoUid = p.PhotoUid
  317. currSpecialProject.ProductPhotoSymbol = 1
  318. }
  319. }
  320. }
  321. // 3. 招募策略信息
  322. recruitStrategy, recruitErr := db.GetRecruitStrategyByProjectId(ctx, specialProject.ProjectId)
  323. if recruitErr != nil {
  324. return nil, recruitErr
  325. }
  326. if recruitStrategy != nil {
  327. for _, strategy := range recruitStrategy {
  328. showStrategy := http_model.EasyRecruitStrategy{
  329. FeeForm: strategy.FeeForm,
  330. RecruitNumber: strategy.RecruitNumber,
  331. StrategyId: strategy.StrategyID,
  332. }
  333. currSpecialProject.RecruitStrategy = append(currSpecialProject.RecruitStrategy, showStrategy)
  334. }
  335. }
  336. // 4. 原种草任务信息
  337. projectInfo, projectErr := db.GetProjectDetail(ctx, specialProject.ProjectId)
  338. if projectErr != nil {
  339. return nil, projectErr
  340. }
  341. if projectInfo != nil {
  342. currSpecialProject.Tools = projectInfo.Tools
  343. }
  344. specialProjectListData.SpecialProjectInfo = append(specialProjectListData.SpecialProjectInfo, currSpecialProject)
  345. }
  346. } else {
  347. specialProjectListData.Total = 0
  348. }
  349. return specialProjectListData, nil
  350. }
  351. // GetSpecialSProjectList 查找服务商加入商单后的定向种草任务列表
  352. func (*sProject) GetSpecialSProjectList(ctx context.Context, supplierId int, pageSize, pageNum int32, condition *common_model.SpecialSProjectCondition) (*http_model.SpecialSProjectListData, error) {
  353. var specialProjectListData *http_model.SpecialSProjectListData
  354. specialProjectListData = &http_model.SpecialSProjectListData{}
  355. specialProjects, total, err := db.GetSpecialProjectList(ctx, supplierId, pageSize, pageNum, condition)
  356. if err != nil {
  357. return nil, err
  358. }
  359. if specialProjects != nil {
  360. specialProjectListData.Total = total
  361. // 1. 定向种草任务基本信息填入
  362. for _, specialProject := range specialProjects {
  363. var currSpecialProject *http_model.SpecialSProjectResponse
  364. currSpecialProject = &http_model.SpecialSProjectResponse{}
  365. currSpecialProject.SProjectId = specialProject.SProjectId
  366. currSpecialProject.ProjectPlatform = specialProject.ProjectPlatform
  367. currSpecialProject.ProjectForm = specialProject.ProjectForm
  368. currSpecialProject.ContentType = specialProject.ContentType
  369. currSpecialProject.SProjectStatus = specialProject.SProjectStatus
  370. currSpecialProject.StrategyStatus = specialProject.StrategyStatus
  371. currSpecialProject.ApplyNum = specialProject.ApplyNum
  372. currSpecialProject.RecruitNum = specialProject.RecruitNum
  373. currSpecialProject.SettleNum = specialProject.SettleNum
  374. currSpecialProject.ProjectId = specialProject.ProjectId
  375. // 2. 定向种草任务商品信息填入
  376. // 2.1. 商品信息
  377. productInfo, productErr := db.GetProductByID(ctx, specialProject.ProductId)
  378. if productErr != nil {
  379. return nil, productErr
  380. }
  381. if productInfo != nil {
  382. currSpecialProject.ProductId = productInfo.ProductID
  383. currSpecialProject.ProductName = productInfo.ProductName
  384. currSpecialProject.ProductPrice = productInfo.ProductPrice
  385. }
  386. // 2.2. 商品图片信息
  387. productPhotoInfo, productPhotoErr := db.GetProductPhotoByProductID(ctx, specialProject.ProductId)
  388. if productPhotoErr != nil {
  389. return nil, productPhotoErr
  390. }
  391. if productPhotoInfo != nil {
  392. for _, p := range productPhotoInfo {
  393. if p.Symbol == 1 {
  394. currSpecialProject.ProductPhotoUrl = p.PhotoUrl
  395. currSpecialProject.ProductPhotoUid = p.PhotoUid
  396. currSpecialProject.ProductPhotoSymbol = 1
  397. }
  398. }
  399. }
  400. // 3. 招募策略信息
  401. // recruitStrategy, recruitErr := db.GetRecruitStrategyByProjectId(ctx, specialProject.ProjectId)
  402. // if recruitErr != nil {
  403. // return nil, recruitErr
  404. // }
  405. // if recruitStrategy != nil {
  406. // for _, strategy := range recruitStrategy {
  407. // showStrategy := http_model.EasyRecruitStrategy{
  408. // FeeForm: strategy.FeeForm,
  409. // RecruitNumber: strategy.RecruitNumber,
  410. // StrategyId: strategy.StrategyID,
  411. // }
  412. // currSpecialProject.RecruitStrategy = append(currSpecialProject.RecruitStrategy, showStrategy)
  413. // }
  414. // }
  415. // 4. 原种草任务信息
  416. projectInfo, projectErr := db.GetProjectDetail(ctx, specialProject.ProjectId)
  417. if projectErr != nil {
  418. return nil, projectErr
  419. }
  420. if projectInfo != nil {
  421. currSpecialProject.Tools = projectInfo.Tools
  422. }
  423. specialProjectListData.SpecialProjectInfo = append(specialProjectListData.SpecialProjectInfo, currSpecialProject)
  424. }
  425. } else {
  426. specialProjectListData.Total = 0
  427. }
  428. return specialProjectListData, nil
  429. }
  430. // UpdateSProject 更新SProject信息
  431. func (*sProject) UpdateSProject(ctx context.Context, request *http_model.SpecialSProjectAddToListRequest) error {
  432. updateSProjectErr := db.UpdateSProjectStatus(ctx, request)
  433. if updateSProjectErr != nil {
  434. return updateSProjectErr
  435. }
  436. return nil
  437. }
  438. // CreateSpecialStrategy 添加服务商招募策略
  439. func (*sProject) CreateSpecialStrategy(ctx context.Context, request *http_model.SpecialAddStrategyRequest) error {
  440. // 1. 添加服务商招募策略
  441. // 1.1. 整理数据
  442. for _, strategy := range request.RecruitStrategys {
  443. // 一口价需要计算服务费率和达人所见报价
  444. strategy.ServiceRate = int(strategy.ServiceCharge / strategy.Offer)
  445. strategy.TOffer = strategy.Offer - strategy.ServiceCharge
  446. }
  447. createErr := db.CreateSpecialStrategy(ctx, request.RecruitStrategys)
  448. if createErr != nil {
  449. return createErr
  450. }
  451. // 2. 修改sProject中的字段
  452. updateErr := db.UpdateSProjectStrategyStatus(ctx, request)
  453. if updateErr != nil {
  454. return updateErr
  455. }
  456. return nil
  457. }
  458. // FullSProjectBillList 种草任务账单列表
  459. func (*sProject) FullSProjectBillList(ctx context.Context, request *http_model.FullSProjectBillListRequest) (*http_model.FullSProjectBillData, error) {
  460. // 1. 根据SupplierId和账单状态查询数据
  461. fullSProjectBillData, total, err := db.GetFullSProjectBillList(ctx, request.SupplierId, request.ProjectPlatform, request.ProjectStatus, request.PageSize, request.PageNum)
  462. if err != nil {
  463. return nil, err
  464. }
  465. var currSProjectBillData *http_model.FullSProjectBillData
  466. currSProjectBillData = &http_model.FullSProjectBillData{}
  467. currSProjectBillData.SProjectList = fullSProjectBillData
  468. currSProjectBillData.Total = total
  469. return currSProjectBillData, nil
  470. }