project_service.go 20 KB

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