project_service.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. package service
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "github.com/sirupsen/logrus"
  6. "reflect"
  7. "time"
  8. "youngee_b_api/app/dao"
  9. "youngee_b_api/app/entity"
  10. "youngee_b_api/app/util"
  11. "youngee_b_api/app/vo"
  12. )
  13. type ProjectService struct{}
  14. // 创建种草任务
  15. func (s ProjectService) CreateProject(param *vo.ProjectCreateParam) (*string, error) {
  16. // a) 生成种草项目id
  17. projectId := util.GetProjectID()
  18. // b) 查找关联商品信息
  19. product, err := dao.ProductDAO{}.GetProductByID(param.ProductId)
  20. if err != nil {
  21. return nil, err
  22. }
  23. if product == nil {
  24. return nil, errors.New("未找到关联商品")
  25. }
  26. productPhotos, err := dao.ProductPhotoDAO{}.GetProductPhotoByProductID(param.ProductId)
  27. productInfoToJson, _ := json.Marshal(product)
  28. productPhotosToJson, _ := json.Marshal(productPhotos)
  29. // d)创建种草任务
  30. var operatorType int64
  31. if param.SubAccountId == 0 {
  32. operatorType = 1
  33. } else {
  34. operatorType = 2
  35. }
  36. // 获取定时任务配置id
  37. infoAutoTask := entity.InfoAutoTask{}
  38. infoAutoTask = dao.InfoAutoTaskDao{}.GetAutoTaskLast(param.EnterpriseId)
  39. infoAutoDefault := entity.InfoAutoDefault{}
  40. infoAutoDefault = dao.InfoAutoDefaultDao{}.GetAutoDefaultLast(param.EnterpriseId)
  41. t := time.Now()
  42. newProject := entity.Project{
  43. ProjectStatus: 1,
  44. ProjectType: param.ProjectType,
  45. ProjectId: projectId,
  46. ProductID: param.ProductId,
  47. ProductCategory: product.ProductCategory,
  48. EnterpriseID: param.EnterpriseId,
  49. SubAccountId: param.SubAccountId,
  50. ProjectPlatform: param.Platform,
  51. OperatorType: operatorType,
  52. ProductSnap: string(productInfoToJson),
  53. ProductPhotoSnap: string(productPhotosToJson),
  54. CreatedAt: t,
  55. AutoTaskID: infoAutoTask.AutoTaskID,
  56. AutoDefaultID: infoAutoDefault.AutoDefaultID,
  57. ServiceChargeRate: param.ServiceChargeRate,
  58. }
  59. if param.ProjectType == 1 {
  60. newProject.ServiceChargeRate = param.ServiceChargeRate
  61. }
  62. err = dao.ProjectDAO{}.CreateProject(newProject)
  63. if err != nil {
  64. return nil, err
  65. }
  66. return &projectId, nil
  67. }
  68. // 更新公开种草任务(招募要求、执行要求)
  69. func (s ProjectService) UpdateProject(projectUpdateParam *vo.ProjectUpdateParam) (*string, error) {
  70. // 1. 检查该项目id有无种草任务
  71. projectID := projectUpdateParam.ProjectID
  72. project, err := dao.ProjectDAO{}.GetProjectById(projectID)
  73. if err != nil {
  74. return nil, err
  75. }
  76. if project == nil {
  77. return nil, errors.New("种草项目不存在")
  78. }
  79. println("更新公开种草任务的招募策略")
  80. // 更新公开种草任务的招募策略
  81. var totalRecruitNum int64
  82. if projectUpdateParam.RecruitStrategys != nil {
  83. // 1. 删除已有的招募策略
  84. err = dao.RecruitStrategyDao{}.DeleteRecruitStrategyByProjectID(projectUpdateParam.ProjectID)
  85. if err != nil {
  86. return nil, err
  87. }
  88. // 2. 接收并创建新的招募策略
  89. if len(projectUpdateParam.RecruitStrategys) != 0 {
  90. var recruits []entity.RecruitStrategy
  91. for _, strategy := range projectUpdateParam.RecruitStrategys {
  92. recruitStrategy := entity.RecruitStrategy{
  93. FeeForm: strategy.FeeForm,
  94. StrategyID: strategy.StrategyID,
  95. FollowersLow: strategy.FollowersLow,
  96. FollowersUp: strategy.FollowersUp,
  97. RecruitNumber: strategy.RecruitNumber,
  98. ProjectID: project.ProjectId,
  99. StrategyType: 1,
  100. ServiceRate: project.ServiceChargeRate,
  101. }
  102. totalRecruitNum += strategy.RecruitNumber
  103. if strategy.FeeForm == 2 {
  104. recruitStrategy.Offer = strategy.Offer
  105. recruitStrategy.ServiceCharge = strategy.Offer * projectUpdateParam.ServiceChargeRate
  106. recruitStrategy.TOffer = strategy.Offer * (1 - projectUpdateParam.ServiceChargeRate)
  107. }
  108. recruits = append(recruits, recruitStrategy)
  109. }
  110. err = dao.RecruitStrategyDao{}.CreateRecruitStrategy(recruits)
  111. if err != nil {
  112. return nil, err
  113. }
  114. }
  115. }
  116. // 2. 数据准备
  117. // a) 查找关联商品信息
  118. product, err := dao.ProductDAO{}.GetProductByID(project.ProductID)
  119. if err != nil {
  120. return nil, err
  121. }
  122. productPhotos, err := dao.ProductPhotoDAO{}.GetProductPhotoByProductID(project.ProductID)
  123. productInfoToJson, _ := json.Marshal(product)
  124. productPhotosToJson, _ := json.Marshal(productPhotos)
  125. // d) 任务截止时间
  126. recruitDdl := time.Time{} //赋零值
  127. recruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", projectUpdateParam.RecruitDdl, time.Local)
  128. // f) 更新选品状态
  129. if projectUpdateParam.ProjectStatus != 2 && projectUpdateParam.ProjectStatus != 8 {
  130. projectUpdateParam.ProjectStatus = 1
  131. }
  132. t := time.Now()
  133. updateProject := entity.Project{
  134. ProjectStatus: projectUpdateParam.ProjectStatus,
  135. ServiceChargeRate: projectUpdateParam.ServiceChargeRate,
  136. ProjectName: projectUpdateParam.ProjectName,
  137. ProductID: projectUpdateParam.ProductId,
  138. TalentType: projectUpdateParam.TalentType,
  139. RecruitDdl: recruitDdl,
  140. ProductSnap: string(productInfoToJson),
  141. ProductPhotoSnap: string(productPhotosToJson),
  142. UpdatedAt: t,
  143. ProjectForm: projectUpdateParam.ProjectForm,
  144. ContentType: projectUpdateParam.ContentType,
  145. ProjectDetail: projectUpdateParam.ProjectDetail,
  146. }
  147. if projectUpdateParam.ProjectStatus == 2 {
  148. updateProject.SubmitAt = t
  149. }
  150. // 合并传入参数和数据表中原记录,若传入参数字段值为空,则将字段赋值为原记录中值
  151. result := util.MergeStructValue(&updateProject, project)
  152. // 利用反射机制将interface类型转换为结构体类型
  153. v := reflect.ValueOf(&result).Elem()
  154. if v.Kind() == reflect.Struct {
  155. updateProject = v.Interface().(entity.Project)
  156. //fmt.Println(p)
  157. }
  158. // c) 计算预估成本(如果有)
  159. /*
  160. var estimatedCost float64
  161. if conv.MustInt(updateSelection.TaskMode, 0) == 1 {
  162. estimatedCost = conv.MustFloat64(updateSelection.TaskReward, 0) * conv.MustFloat64(updateSelection.SampleNum, 0)
  163. }
  164. estimatedCostToString, _ := conv.String(estimatedCost)
  165. updateSelection.EstimatedCost = estimatedCostToString
  166. */
  167. // 3. 更新选品
  168. err = dao.ProjectDAO{}.UpdateProject(updateProject)
  169. if err != nil {
  170. return nil, err
  171. }
  172. // 4. 更新选品brief和示例(种草任务补充信息)
  173. if projectUpdateParam.ProjectBrief != nil {
  174. // 删除已有brief
  175. err = dao.ProjectBriefDao{}.DeleteSecBriefBySelectionId(project.ProjectId)
  176. if err != nil {
  177. return nil, err
  178. }
  179. // 插入新的brief
  180. for _, v := range projectUpdateParam.ProjectBrief {
  181. brief := entity.ProjectBrief{
  182. ProjectID: project.ProjectId,
  183. FileUid: v.FileUid,
  184. FileName: v.Name,
  185. FileUrl: v.FileUrl,
  186. CreatedAt: time.Now(),
  187. }
  188. err = dao.ProjectBriefDao{}.CreateProjectBrief(brief)
  189. if err != nil {
  190. return nil, err
  191. }
  192. }
  193. }
  194. if projectUpdateParam.ProjectMaterial != nil {
  195. // 删除已有示例
  196. err = dao.ProjectMaterialDao{}.DeleteProjectMaterialByProjectId(project.ProjectId)
  197. if err != nil {
  198. return nil, err
  199. }
  200. // 插入新的示例
  201. for _, v := range projectUpdateParam.ProjectMaterial {
  202. projectMaterial := entity.ProjectMaterial{
  203. ProjectID: project.ProjectId,
  204. FileUid: v.FileUid,
  205. FileName: v.Name,
  206. FileUrl: v.FileUrl,
  207. CreatedAt: time.Now(),
  208. }
  209. err = dao.ProjectMaterialDao{}.CreateProjectMaterial(projectMaterial)
  210. if err != nil {
  211. return nil, err
  212. }
  213. }
  214. }
  215. return &updateProject.ProjectId, nil
  216. }
  217. // 更新定向种草任务(招募要求、执行要求)
  218. func (s ProjectService) UpdateProjectTarget(projectUpdateParam *vo.ProjectUpdateParam) (*string, error) {
  219. // 1. 检查该项目id有无种草任务
  220. projectID := projectUpdateParam.ProjectID
  221. project, err := dao.ProjectDAO{}.GetProjectById(projectID)
  222. if err != nil {
  223. return nil, err
  224. }
  225. if project == nil {
  226. return nil, errors.New("种草项目不存在")
  227. }
  228. println("更新定向种草任务的招募策略")
  229. // 更新定向种草任务的招募策略
  230. var totalRecruitNum int64
  231. if projectUpdateParam.RecruitStrategys != nil {
  232. // 1. 删除已有的招募策略
  233. err = dao.RecruitStrategyDao{}.DeleteRecruitStrategyByProjectID(projectUpdateParam.ProjectID)
  234. if err != nil {
  235. return nil, err
  236. }
  237. // 2. 接收并创建新的招募策略
  238. if len(projectUpdateParam.RecruitStrategys) != 0 {
  239. var recruits []entity.RecruitStrategy
  240. for _, strategy := range projectUpdateParam.RecruitStrategys {
  241. recruitStrategy := entity.RecruitStrategy{
  242. FeeForm: strategy.FeeForm,
  243. StrategyID: strategy.StrategyID,
  244. FollowersLow: strategy.FollowersLow,
  245. FollowersUp: strategy.FollowersUp,
  246. RecruitNumber: strategy.RecruitNumber,
  247. ProjectID: project.ProjectId,
  248. StrategyType: 1,
  249. ServiceRate: project.ServiceChargeRate,
  250. }
  251. totalRecruitNum += strategy.RecruitNumber
  252. if strategy.FeeForm == 2 {
  253. recruitStrategy.Offer = strategy.Offer // 报价
  254. }
  255. recruits = append(recruits, recruitStrategy)
  256. }
  257. err = dao.RecruitStrategyDao{}.CreateRecruitStrategy(recruits)
  258. if err != nil {
  259. return nil, err
  260. }
  261. }
  262. }
  263. // 2. 数据准备
  264. // a) 查找关联商品信息
  265. product, err := dao.ProductDAO{}.GetProductByID(project.ProductID)
  266. if err != nil {
  267. return nil, err
  268. }
  269. productPhotos, err := dao.ProductPhotoDAO{}.GetProductPhotoByProductID(project.ProductID)
  270. productInfoToJson, _ := json.Marshal(product)
  271. productPhotosToJson, _ := json.Marshal(productPhotos)
  272. // d) 任务截止时间
  273. recruitDdl := time.Time{} //赋零值
  274. recruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", projectUpdateParam.RecruitDdl, time.Local)
  275. // f) 更新选品状态
  276. if projectUpdateParam.ProjectStatus != 2 && projectUpdateParam.ProjectStatus != 8 {
  277. projectUpdateParam.ProjectStatus = 1
  278. }
  279. t := time.Now()
  280. updateProject := entity.Project{
  281. ProjectStatus: projectUpdateParam.ProjectStatus,
  282. ProjectName: projectUpdateParam.ProjectName,
  283. ProductID: projectUpdateParam.ProductId,
  284. TalentType: projectUpdateParam.TalentType,
  285. RecruitDdl: recruitDdl,
  286. ProductSnap: string(productInfoToJson),
  287. ProductPhotoSnap: string(productPhotosToJson),
  288. CreatedAt: project.CreatedAt,
  289. UpdatedAt: t,
  290. ProjectForm: projectUpdateParam.ProjectForm,
  291. ContentType: projectUpdateParam.ContentType,
  292. ProjectDetail: projectUpdateParam.ProjectDetail,
  293. Tools: projectUpdateParam.Tools,
  294. }
  295. if projectUpdateParam.ProjectStatus == 2 {
  296. updateProject.SubmitAt = t
  297. }
  298. // 合并传入参数和数据表中原记录,若传入参数字段值为空,则将字段赋值为原记录中值
  299. result := util.MergeStructValue(&updateProject, project)
  300. // 利用反射机制将interface类型转换为结构体类型
  301. v := reflect.ValueOf(&result).Elem()
  302. if v.Kind() == reflect.Struct {
  303. updateProject = v.Interface().(entity.Project)
  304. //fmt.Println(p)
  305. }
  306. // c) 计算预估成本(如果有)
  307. /*
  308. var estimatedCost float64
  309. if conv.MustInt(updateSelection.TaskMode, 0) == 1 {
  310. estimatedCost = conv.MustFloat64(updateSelection.TaskReward, 0) * conv.MustFloat64(updateSelection.SampleNum, 0)
  311. }
  312. estimatedCostToString, _ := conv.String(estimatedCost)
  313. updateSelection.EstimatedCost = estimatedCostToString
  314. */
  315. // 3. 更新选品
  316. err = dao.ProjectDAO{}.UpdateProject(updateProject)
  317. if err != nil {
  318. return nil, err
  319. }
  320. // 4. 更新选品brief和示例(种草任务补充信息)
  321. if projectUpdateParam.ProjectBrief != nil {
  322. // 删除已有brief
  323. err = dao.ProjectBriefDao{}.DeleteSecBriefBySelectionId(project.ProjectId)
  324. if err != nil {
  325. return nil, err
  326. }
  327. // 插入新的brief
  328. for _, v := range projectUpdateParam.ProjectBrief {
  329. brief := entity.ProjectBrief{
  330. ProjectID: project.ProjectId,
  331. FileUid: v.FileUid,
  332. FileName: v.Name,
  333. FileUrl: v.FileUrl,
  334. CreatedAt: time.Now(),
  335. }
  336. err = dao.ProjectBriefDao{}.CreateProjectBrief(brief)
  337. if err != nil {
  338. return nil, err
  339. }
  340. }
  341. }
  342. if projectUpdateParam.ProjectMaterial != nil {
  343. // 删除已有示例
  344. err = dao.ProjectMaterialDao{}.DeleteProjectMaterialByProjectId(project.ProjectId)
  345. if err != nil {
  346. return nil, err
  347. }
  348. // 插入新的示例
  349. for _, v := range projectUpdateParam.ProjectMaterial {
  350. projectMaterial := entity.ProjectMaterial{
  351. ProjectID: project.ProjectId,
  352. FileUid: v.FileUid,
  353. FileName: v.Name,
  354. FileUrl: v.FileUrl,
  355. CreatedAt: time.Now(),
  356. }
  357. err = dao.ProjectMaterialDao{}.CreateProjectMaterial(projectMaterial)
  358. if err != nil {
  359. return nil, err
  360. }
  361. }
  362. }
  363. return &updateProject.ProjectId, nil
  364. }
  365. // 种草任务预览
  366. func (s ProjectService) GetProjectDetail(projectId string) (*vo.ReProjectDetail, error) {
  367. reProjectDetail := vo.ReProjectDetail{}
  368. project, err := dao.ProjectDAO{}.GetProjectById(projectId)
  369. if err != nil {
  370. logrus.Errorf("[projectDB service] call GetProject error,err:%+v", err)
  371. return nil, err
  372. }
  373. // 系统信息
  374. reProjectDetail.ProjectId = projectId
  375. reProjectDetail.ProjectStatus = project.ProjectStatus
  376. reProjectDetail.ProjectPlatform = project.ProjectPlatform
  377. reProjectDetail.CreatedAt = project.CreatedAt.Format("2006-01-02 15:04:05")
  378. reProjectDetail.EstimatedCost = project.EstimatedCost
  379. reProjectDetail.ServiceChargeRate = project.ServiceChargeRate
  380. var creatorName, phone string
  381. if project.SubAccountId == 0 {
  382. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(project.EnterpriseID)
  383. if err == nil && enterprise != nil {
  384. creatorName = enterprise.BusinessName
  385. phone, err = dao.UserDao{}.GetPhoneByUserId(enterprise.UserId)
  386. }
  387. } else {
  388. subAccount, err := dao.SubAccountDao{}.GetSubAccount(project.SubAccountId)
  389. if err == nil && subAccount != nil {
  390. creatorName = subAccount.SubAccountName
  391. phone, err = dao.UserDao{}.GetPhoneByUserId(subAccount.UserId)
  392. }
  393. }
  394. reProjectDetail.CreatorName = creatorName
  395. reProjectDetail.Phone = phone
  396. // 关联商品
  397. var reProduct vo.ReTaskProduct
  398. product, err := dao.ProductDAO{}.GetProductByID(project.ProductID)
  399. if err == nil {
  400. photoUrl, e := dao.ProductPhotoDAO{}.GetMainPhotoByProductID(product.ProductID)
  401. if e != nil {
  402. photoUrl = ""
  403. }
  404. reProduct = vo.ReTaskProduct{
  405. ProductID: product.ProductID,
  406. ProductName: product.ProductName,
  407. ProductType: product.ProductType,
  408. ProductCategory: product.ProductCategory,
  409. ProductPrice: product.ProductPrice,
  410. ProductDetail: product.ProductDetail,
  411. CreatedAt: product.CreatedAt.Format("2006-01-02 15:04:05"),
  412. PhotoUrl: photoUrl,
  413. }
  414. }
  415. reProjectDetail.ProductInfo = &reProduct
  416. // 招募要求
  417. reProjectDetail.TalentType = project.TalentType
  418. reProjectDetail.RecruitDdl = project.RecruitDdl.Format("2006-01-02 15:04:05")
  419. reProjectDetail.ProjectForm = project.ProjectForm
  420. reProjectDetail.ContentType = project.ContentType
  421. reProjectDetail.ProjectDetail = project.ProjectDetail
  422. var recruitStrategysPreviews []*vo.RecruitStrategyPreview
  423. recruitStrategys, err := dao.RecruitStrategyDao{}.GetRecruitStrategyByProjectId(projectId)
  424. if err != nil {
  425. logrus.Errorf("[projectDB service] call GetRecruitStrategy error,err:%+v", err)
  426. return nil, err
  427. }
  428. for _, recruitStrategy := range recruitStrategys {
  429. recruitStrategysPreview := &vo.RecruitStrategyPreview{
  430. StrategyId: recruitStrategy.StrategyID,
  431. FeeForm: recruitStrategy.FeeForm,
  432. FollowersLow: recruitStrategy.FollowersLow,
  433. FollowersUp: recruitStrategy.FollowersUp,
  434. RecruitNumber: recruitStrategy.RecruitNumber,
  435. Offer: recruitStrategy.Offer,
  436. TOffer: recruitStrategy.TOffer,
  437. ServiceCharge: recruitStrategy.ServiceCharge,
  438. SelectedNumber: recruitStrategy.SelectedNumber,
  439. TotalOffer: recruitStrategy.TotalOffer,
  440. }
  441. recruitStrategysPreviews = append(recruitStrategysPreviews, recruitStrategysPreview)
  442. }
  443. reProjectDetail.RecruitStrategys = recruitStrategysPreviews
  444. // 执行要求
  445. projectBriefInfos, err := dao.ProjectBriefDao{}.GetProjectBriefInfo(projectId)
  446. if err != nil {
  447. logrus.Errorf("[projectDB service] call GetProjectBriefInfo error,err:%+v", err)
  448. return nil, err
  449. }
  450. projectMaterials, err := dao.ProjectMaterialDao{}.GetProjectMaterialInfo(projectId)
  451. if err != nil {
  452. logrus.Errorf("[projectDB service] call GetprojectMaterialInfo error,err:%+v", err)
  453. return nil, err
  454. }
  455. reProjectDetail.ProjectBriefs = projectBriefInfos
  456. reProjectDetail.ProjectMaterials = projectMaterials
  457. reProjectDetail.Tools = project.Tools
  458. return &reProjectDetail, nil
  459. }
  460. // 种草提交审核
  461. func (s ProjectService) ProjectToReview(projectUpdateParam *vo.ProjectUpdateParam) (*string, error) {
  462. projectId := projectUpdateParam.ProjectID
  463. t := time.Now()
  464. updateProject := entity.Project{
  465. ProjectId: projectId,
  466. ProjectStatus: 2,
  467. UpdatedAt: t,
  468. }
  469. err := dao.ProjectDAO{}.UpdateProject(updateProject)
  470. if err != nil {
  471. return nil, err
  472. }
  473. return &projectId, nil
  474. }
  475. // 种草任务列表
  476. func (s ProjectService) GetProjectTaskList(param *vo.ProjectSearchParam) (vo.ResultVO, error) {
  477. if param.Page == 0 {
  478. param.Page = 1
  479. }
  480. if param.PageSize == 0 {
  481. param.PageSize = 10
  482. }
  483. var result vo.ResultVO
  484. reProjectTaskPreviews, total, err := (&dao.ProjectDAO{}).GetProjectPreviews(param)
  485. if err != nil {
  486. return result, err
  487. }
  488. for i := range reProjectTaskPreviews {
  489. var creatorName string
  490. var productName string
  491. var productPrice float64
  492. var mainImage string
  493. if reProjectTaskPreviews[i].SubAccountId == 0 {
  494. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reProjectTaskPreviews[i].EnterpriseId)
  495. if err == nil && enterprise != nil {
  496. creatorName = enterprise.BusinessName
  497. }
  498. } else {
  499. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reProjectTaskPreviews[i].SubAccountId)
  500. if err == nil && subAccount != nil {
  501. creatorName = subAccount.SubAccountName
  502. }
  503. }
  504. product, err := dao.ProductDAO{}.GetProductByID(reProjectTaskPreviews[i].ProductId)
  505. if err == nil && product != nil {
  506. productName = product.ProductName
  507. productPrice = product.ProductPrice
  508. }
  509. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reProjectTaskPreviews[i].ProductId)
  510. reProjectTaskPreviews[i].CreatorName = creatorName
  511. reProjectTaskPreviews[i].ProductName = productName
  512. reProjectTaskPreviews[i].ProductPrice = productPrice
  513. reProjectTaskPreviews[i].MainImage = mainImage
  514. }
  515. result = vo.ResultVO{
  516. Page: param.Page,
  517. PageSize: param.PageSize,
  518. Total: total,
  519. Data: reProjectTaskPreviews,
  520. }
  521. return result, nil
  522. }
  523. // 删除种草任务
  524. func (s ProjectService) DeleteProject(projectId string) (*string, error) {
  525. res, err := dao.ProjectDAO{}.DeleteProject(projectId)
  526. if err != nil {
  527. logrus.Errorf("[projectDB service] call DeleteProject error,err:%+v", err)
  528. return res, err
  529. }
  530. return res, nil
  531. }
  532. // 草稿箱——品牌种草
  533. func (s ProjectService) GetProjectDraftList(param *vo.ProjectDraftParam) (vo.ResultVO, error) {
  534. if param.Page == 0 {
  535. param.Page = 1
  536. }
  537. if param.PageSize == 0 {
  538. param.PageSize = 10
  539. }
  540. var result vo.ResultVO
  541. reSelectionTaskPreviews, total, err := (&dao.ProjectDAO{}).GetProjectDraftList(param)
  542. if err != nil {
  543. return result, err
  544. }
  545. for i := range reSelectionTaskPreviews {
  546. var creatorName string
  547. var productName string
  548. var productPrice float64
  549. var mainImage string
  550. if reSelectionTaskPreviews[i].SubAccountId == 0 {
  551. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reSelectionTaskPreviews[i].EnterpriseId)
  552. if err == nil && enterprise != nil {
  553. creatorName = enterprise.BusinessName
  554. }
  555. } else {
  556. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reSelectionTaskPreviews[i].SubAccountId)
  557. if err == nil && subAccount != nil {
  558. creatorName = subAccount.SubAccountName
  559. }
  560. }
  561. product, err := dao.ProductDAO{}.GetProductByID(reSelectionTaskPreviews[i].ProductId)
  562. if err == nil && product != nil {
  563. productName = product.ProductName
  564. productPrice = product.ProductPrice
  565. }
  566. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reSelectionTaskPreviews[i].ProductId)
  567. reSelectionTaskPreviews[i].CreatorName = creatorName
  568. reSelectionTaskPreviews[i].ProductName = productName
  569. reSelectionTaskPreviews[i].ProductPrice = productPrice
  570. reSelectionTaskPreviews[i].MainImage = mainImage
  571. }
  572. result = vo.ResultVO{
  573. Page: param.Page,
  574. PageSize: param.PageSize,
  575. Total: total,
  576. Data: reSelectionTaskPreviews,
  577. }
  578. return result, nil
  579. }