project_service.go 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. package service
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "github.com/sirupsen/logrus"
  6. "reflect"
  7. "strings"
  8. "time"
  9. "youngee_m_api/app/dao"
  10. "youngee_m_api/app/entity"
  11. "youngee_m_api/app/service/review_service"
  12. "youngee_m_api/app/util"
  13. "youngee_m_api/app/vo"
  14. )
  15. type ProjectService struct{}
  16. // 创建种草任务
  17. func (s ProjectService) CreateProject(projectCreateParam *vo.ProjectCreateParam) (*string, error) {
  18. // a) 生成种草项目id
  19. projectId := strings.ReplaceAll(util.GenerateUUID(11), "-", "")
  20. // b) 查找关联商品信息
  21. product, err := dao.ProductDAO{}.GetProductByID(projectCreateParam.ProductId)
  22. if err != nil {
  23. return nil, err
  24. }
  25. if product == nil {
  26. return nil, errors.New("未找到关联商品")
  27. }
  28. productMainPhoto, _ := dao.ProductPhotoDAO{}.GetMainProductPhotoInfoByProductID(projectCreateParam.ProductId)
  29. productInfoToJson, _ := json.Marshal(product)
  30. productPhotosToJson, _ := json.Marshal(productMainPhoto)
  31. // d) 任务截止时间
  32. recruitDdl, err1 := time.ParseInLocation("2006-01-02 15:04:05", projectCreateParam.RecruitDdl, time.Local)
  33. if err1 != nil {
  34. return nil, errors.New("failed to parse recruitDdl")
  35. }
  36. // d)创建种草任务
  37. var operatorType int64
  38. if projectCreateParam.SubAccountId == 0 {
  39. operatorType = 1
  40. } else {
  41. operatorType = 2
  42. }
  43. // 获取定时任务配置id
  44. infoAutoTask := entity.InfoAutoTask{}
  45. infoAutoTask = dao.InfoAutoTaskDao{}.GetAutoTaskLast(projectCreateParam.EnterpriseId)
  46. infoAutoDefault := entity.InfoAutoDefault{}
  47. infoAutoDefault = dao.InfoAutoDefaultDao{}.GetAutoDefaultLast(projectCreateParam.EnterpriseId)
  48. t := time.Now()
  49. if recruitDdl.Before(t) {
  50. return nil, errors.New("请修改截止时间")
  51. }
  52. newProject := entity.Project{
  53. ProjectStatus: 1,
  54. ProjectType: projectCreateParam.ProjectType,
  55. ProjectId: projectId,
  56. ProductID: projectCreateParam.ProductId,
  57. ProductCategory: product.ProductCategory,
  58. EnterpriseID: projectCreateParam.EnterpriseId,
  59. SubAccountId: projectCreateParam.SubAccountId,
  60. ProjectPlatform: projectCreateParam.Platform,
  61. OperatorType: operatorType,
  62. ProductSnap: string(productInfoToJson),
  63. ProductPhotoSnap: string(productPhotosToJson),
  64. CreatedAt: t,
  65. AutoTaskID: infoAutoTask.AutoTaskID,
  66. AutoDefaultID: infoAutoDefault.AutoDefaultID,
  67. ProjectName: projectCreateParam.ProjectName,
  68. TalentType: projectCreateParam.TalentType,
  69. RecruitDdl: recruitDdl,
  70. ProjectForm: projectCreateParam.ProjectForm,
  71. ContentType: projectCreateParam.ContentType,
  72. ProjectDetail: projectCreateParam.ProjectDetail,
  73. Tools: projectCreateParam.Tools,
  74. }
  75. if projectCreateParam.ProjectType == 1 {
  76. newProject.ServiceChargeRate = projectCreateParam.ServiceChargeRate
  77. }
  78. err = dao.ProjectDAO{}.CreateProject(newProject)
  79. if err != nil {
  80. return nil, err
  81. }
  82. // 4. 更新选品brief和示例(种草任务补充信息)
  83. if projectCreateParam.ProjectBrief != nil {
  84. // 插入新的brief
  85. for _, v := range projectCreateParam.ProjectBrief {
  86. brief := entity.ProjectBrief{
  87. ProjectID: projectId,
  88. FileUid: v.FileUid,
  89. FileName: v.Name,
  90. FileUrl: v.FileUrl,
  91. CreatedAt: time.Now(),
  92. Type: v.Type,
  93. }
  94. err = dao.ProjectBriefDao{}.CreateProjectBrief(brief)
  95. if err != nil {
  96. return nil, err
  97. }
  98. }
  99. }
  100. if projectCreateParam.ProjectMaterial != nil {
  101. // 插入新的示例
  102. for _, v := range projectCreateParam.ProjectMaterial {
  103. projectMaterial := entity.ProjectMaterial{
  104. ProjectID: projectId,
  105. FileUid: v.FileUid,
  106. FileName: v.Name,
  107. FileUrl: v.FileUrl,
  108. CreatedAt: time.Now(),
  109. Type: v.Type,
  110. }
  111. err = dao.ProjectMaterialDao{}.CreateProjectMaterial(projectMaterial)
  112. if err != nil {
  113. return nil, err
  114. }
  115. }
  116. }
  117. // 更新公开种草任务的招募策略
  118. var totalRecruitNum int64
  119. var estimatedCost float64
  120. if projectCreateParam.RecruitStrategys != nil {
  121. // 2. 接收并创建新的招募策略
  122. if len(projectCreateParam.RecruitStrategys) != 0 {
  123. var recruits []entity.RecruitStrategy
  124. for _, strategy := range projectCreateParam.RecruitStrategys {
  125. if strategy.FeeForm == 2 {
  126. estimatedCost += float64(strategy.RecruitNumber) * strategy.Offer
  127. }
  128. recruitStrategy := entity.RecruitStrategy{
  129. FeeForm: strategy.FeeForm,
  130. StrategyID: strategy.StrategyID,
  131. FollowersLow: strategy.FollowersLow,
  132. FollowersUp: strategy.FollowersUp,
  133. RecruitNumber: strategy.RecruitNumber,
  134. ProjectID: projectId,
  135. StrategyType: 1,
  136. ServiceRate: projectCreateParam.ServiceChargeRate,
  137. }
  138. totalRecruitNum += strategy.RecruitNumber
  139. if strategy.FeeForm == 2 {
  140. recruitStrategy.Offer = strategy.Offer
  141. recruitStrategy.ServiceCharge = strategy.Offer * projectCreateParam.ServiceChargeRate * 0.01
  142. recruitStrategy.TOffer = strategy.Offer * (1 - projectCreateParam.ServiceChargeRate*0.01)
  143. }
  144. recruits = append(recruits, recruitStrategy)
  145. }
  146. err = dao.RecruitStrategyDao{}.CreateRecruitStrategy(recruits)
  147. if err != nil {
  148. return nil, err
  149. }
  150. }
  151. }
  152. _ = dao.ProjectDAO{}.UpdateProject(entity.Project{
  153. ProjectId: projectId,
  154. EstimatedCost: estimatedCost,
  155. TotalRecruitNum: totalRecruitNum,
  156. })
  157. return &projectId, nil
  158. }
  159. // 更新公开种草任务(招募要求、执行要求)
  160. func (s ProjectService) UpdateProject(projectUpdateParam *vo.ProjectUpdateParam) (*string, error) {
  161. // 1. 检查该项目id有无种草任务
  162. projectID := projectUpdateParam.ProjectID
  163. project, err := dao.ProjectDAO{}.GetProjectById(projectID)
  164. if err != nil {
  165. return nil, err
  166. }
  167. if project == nil {
  168. return nil, errors.New("种草项目不存在")
  169. }
  170. recruitDdl := time.Time{} //赋零值
  171. recruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", projectUpdateParam.RecruitDdl, time.Local)
  172. if recruitDdl.Before(project.CreatedAt) {
  173. return nil, errors.New("请修改截止时间")
  174. }
  175. // 更新公开种草任务的招募策略
  176. var totalRecruitNum int64
  177. var estimatedCost float64
  178. if projectUpdateParam.RecruitStrategys != nil {
  179. // 1. 删除已有的招募策略
  180. err = dao.RecruitStrategyDao{}.DeleteRecruitStrategyByProjectID(projectUpdateParam.ProjectID)
  181. if err != nil {
  182. return nil, err
  183. }
  184. // 2. 接收并创建新的招募策略
  185. if len(projectUpdateParam.RecruitStrategys) != 0 {
  186. var recruits []entity.RecruitStrategy
  187. for _, strategy := range projectUpdateParam.RecruitStrategys {
  188. if strategy.FeeForm == 2 {
  189. estimatedCost += float64(strategy.RecruitNumber) * strategy.Offer
  190. }
  191. recruitStrategy := entity.RecruitStrategy{
  192. FeeForm: strategy.FeeForm,
  193. StrategyID: strategy.StrategyID,
  194. FollowersLow: strategy.FollowersLow,
  195. FollowersUp: strategy.FollowersUp,
  196. RecruitNumber: strategy.RecruitNumber,
  197. ProjectID: project.ProjectId,
  198. StrategyType: 1,
  199. ServiceRate: project.ServiceChargeRate,
  200. }
  201. totalRecruitNum += strategy.RecruitNumber
  202. if strategy.FeeForm == 2 {
  203. recruitStrategy.Offer = strategy.Offer
  204. recruitStrategy.ServiceCharge = strategy.Offer * projectUpdateParam.ServiceChargeRate * 0.01
  205. recruitStrategy.TOffer = strategy.Offer * (1 - projectUpdateParam.ServiceChargeRate*0.01)
  206. }
  207. recruits = append(recruits, recruitStrategy)
  208. }
  209. err = dao.RecruitStrategyDao{}.CreateRecruitStrategy(recruits)
  210. if err != nil {
  211. return nil, err
  212. }
  213. }
  214. }
  215. // 2. 数据准备
  216. // a) 查找关联商品信息
  217. var productInfoToString string
  218. var productPhotosToString string
  219. if projectUpdateParam.ProductId != 0 {
  220. product, err := dao.ProductDAO{}.GetProductByID(projectUpdateParam.ProductId)
  221. if err != nil {
  222. return nil, err
  223. }
  224. if product == nil {
  225. return nil, errors.New("未找到关联商品")
  226. }
  227. productMainPhoto, _ := dao.ProductPhotoDAO{}.GetMainProductPhotoInfoByProductID(projectUpdateParam.ProductId)
  228. productInfoToJson, _ := json.Marshal(product)
  229. productInfoToString = string(productInfoToJson)
  230. productPhotosToJson, _ := json.Marshal(productMainPhoto)
  231. productPhotosToString = string(productPhotosToJson)
  232. }
  233. // d) 任务截止时间
  234. //// f) 更新选品状态
  235. //if projectUpdateParam.ProjectStatus != 2 && projectUpdateParam.ProjectStatus != 8 {
  236. // projectUpdateParam.ProjectStatus = 1
  237. //}
  238. t := time.Now()
  239. updateProject := entity.Project{
  240. //ProjectStatus: projectUpdateParam.ProjectStatus,
  241. ServiceChargeRate: projectUpdateParam.ServiceChargeRate,
  242. ProjectName: projectUpdateParam.ProjectName,
  243. ProductID: projectUpdateParam.ProductId,
  244. TalentType: projectUpdateParam.TalentType,
  245. RecruitDdl: recruitDdl,
  246. ProductSnap: productInfoToString,
  247. ProductPhotoSnap: productPhotosToString,
  248. UpdatedAt: t,
  249. ProjectForm: projectUpdateParam.ProjectForm,
  250. ContentType: projectUpdateParam.ContentType,
  251. ProjectDetail: projectUpdateParam.ProjectDetail,
  252. EstimatedCost: estimatedCost,
  253. TotalRecruitNum: totalRecruitNum,
  254. }
  255. //if projectUpdateParam.ProjectStatus == 2 {
  256. // updateProject.SubmitAt = t
  257. //}
  258. // 合并传入参数和数据表中原记录,若传入参数字段值为空,则将字段赋值为原记录中值
  259. result := util.MergeStructValue(&updateProject, project)
  260. // 利用反射机制将interface类型转换为结构体类型
  261. v := reflect.ValueOf(&result).Elem()
  262. if v.Kind() == reflect.Struct {
  263. updateProject = v.Interface().(entity.Project)
  264. //fmt.Println(p)
  265. }
  266. // c) 计算预估成本(如果有)
  267. /*
  268. var estimatedCost float64
  269. if conv.MustInt(updateSelection.TaskMode, 0) == 1 {
  270. estimatedCost = conv.MustFloat64(updateSelection.TaskReward, 0) * conv.MustFloat64(updateSelection.SampleNum, 0)
  271. }
  272. estimatedCostToString, _ := conv.String(estimatedCost)
  273. updateSelection.EstimatedCost = estimatedCostToString
  274. */
  275. // 3. 更新选品
  276. err = dao.ProjectDAO{}.UpdateProject(updateProject)
  277. if err != nil {
  278. return nil, err
  279. }
  280. // 4. 更新选品brief和示例(种草任务补充信息)
  281. if projectUpdateParam.ProjectBrief != nil {
  282. // 删除已有brief
  283. err = dao.ProjectBriefDao{}.DeleteSecBriefBySelectionId(project.ProjectId)
  284. if err != nil {
  285. return nil, err
  286. }
  287. // 插入新的brief
  288. for _, v := range projectUpdateParam.ProjectBrief {
  289. brief := entity.ProjectBrief{
  290. ProjectID: project.ProjectId,
  291. FileUid: v.FileUid,
  292. FileName: v.Name,
  293. FileUrl: v.FileUrl,
  294. CreatedAt: time.Now(),
  295. Type: v.Type,
  296. }
  297. err = dao.ProjectBriefDao{}.CreateProjectBrief(brief)
  298. if err != nil {
  299. return nil, err
  300. }
  301. }
  302. }
  303. if projectUpdateParam.ProjectMaterial != nil {
  304. // 删除已有示例
  305. err = dao.ProjectMaterialDao{}.DeleteProjectMaterialByProjectId(project.ProjectId)
  306. if err != nil {
  307. return nil, err
  308. }
  309. // 插入新的示例
  310. for _, v := range projectUpdateParam.ProjectMaterial {
  311. projectMaterial := entity.ProjectMaterial{
  312. ProjectID: project.ProjectId,
  313. FileUid: v.FileUid,
  314. FileName: v.Name,
  315. FileUrl: v.FileUrl,
  316. CreatedAt: time.Now(),
  317. Type: v.Type,
  318. }
  319. err = dao.ProjectMaterialDao{}.CreateProjectMaterial(projectMaterial)
  320. if err != nil {
  321. return nil, err
  322. }
  323. }
  324. }
  325. return &updateProject.ProjectId, nil
  326. }
  327. // 更新定向种草任务(招募要求、执行要求)
  328. func (s ProjectService) UpdateProjectTarget(projectUpdateParam *vo.ProjectUpdateParam) (*string, error) {
  329. // 1. 检查该项目id有无种草任务
  330. projectID := projectUpdateParam.ProjectID
  331. project, err := dao.ProjectDAO{}.GetProjectById(projectID)
  332. if err != nil {
  333. return nil, err
  334. }
  335. if project == nil {
  336. return nil, errors.New("种草项目不存在")
  337. }
  338. println("更新定向种草任务的招募策略")
  339. // 更新定向种草任务的招募策略
  340. var totalRecruitNum int64
  341. var estimatedCost float64
  342. if projectUpdateParam.RecruitStrategys != nil {
  343. // 1. 删除已有的招募策略
  344. err = dao.RecruitStrategyDao{}.DeleteRecruitStrategyByProjectID(projectUpdateParam.ProjectID)
  345. if err != nil {
  346. return nil, err
  347. }
  348. // 2. 接收并创建新的招募策略
  349. if len(projectUpdateParam.RecruitStrategys) != 0 {
  350. var recruits []entity.RecruitStrategy
  351. for _, strategy := range projectUpdateParam.RecruitStrategys {
  352. if strategy.FeeForm == 2 {
  353. estimatedCost += float64(strategy.RecruitNumber) * strategy.Offer
  354. }
  355. recruitStrategy := entity.RecruitStrategy{
  356. FeeForm: strategy.FeeForm,
  357. StrategyID: strategy.StrategyID,
  358. FollowersLow: strategy.FollowersLow,
  359. FollowersUp: strategy.FollowersUp,
  360. RecruitNumber: strategy.RecruitNumber,
  361. ProjectID: project.ProjectId,
  362. StrategyType: 1,
  363. ServiceRate: project.ServiceChargeRate,
  364. }
  365. totalRecruitNum += strategy.RecruitNumber
  366. if strategy.FeeForm == 2 {
  367. recruitStrategy.Offer = strategy.Offer // 报价
  368. }
  369. recruits = append(recruits, recruitStrategy)
  370. }
  371. err = dao.RecruitStrategyDao{}.CreateRecruitStrategy(recruits)
  372. if err != nil {
  373. return nil, err
  374. }
  375. }
  376. }
  377. // 2. 数据准备
  378. // a) 查找关联商品信息
  379. var productInfoToString string
  380. var productPhotosToString string
  381. if projectUpdateParam.ProductId != 0 {
  382. product, err := dao.ProductDAO{}.GetProductByID(projectUpdateParam.ProductId)
  383. if err != nil {
  384. return nil, err
  385. }
  386. if product == nil {
  387. return nil, errors.New("未找到关联商品")
  388. }
  389. productMainPhoto, _ := dao.ProductPhotoDAO{}.GetMainProductPhotoInfoByProductID(projectUpdateParam.ProductId)
  390. productInfoToJson, _ := json.Marshal(product)
  391. productInfoToString = string(productInfoToJson)
  392. productPhotosToJson, _ := json.Marshal(productMainPhoto)
  393. productPhotosToString = string(productPhotosToJson)
  394. }
  395. // d) 任务截止时间
  396. recruitDdl := time.Time{} //赋零值
  397. recruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", projectUpdateParam.RecruitDdl, time.Local)
  398. //// f) 更新选品状态
  399. //if projectUpdateParam.ProjectStatus != 2 && projectUpdateParam.ProjectStatus != 8 {
  400. // projectUpdateParam.ProjectStatus = 1
  401. //}
  402. t := time.Now()
  403. updateProject := entity.Project{
  404. //ProjectStatus: projectUpdateParam.ProjectStatus,
  405. ProjectName: projectUpdateParam.ProjectName,
  406. ProductID: projectUpdateParam.ProductId,
  407. TalentType: projectUpdateParam.TalentType,
  408. RecruitDdl: recruitDdl,
  409. ProductSnap: productInfoToString,
  410. ProductPhotoSnap: productPhotosToString,
  411. CreatedAt: project.CreatedAt,
  412. UpdatedAt: t,
  413. ProjectForm: projectUpdateParam.ProjectForm,
  414. ContentType: projectUpdateParam.ContentType,
  415. ProjectDetail: projectUpdateParam.ProjectDetail,
  416. Tools: projectUpdateParam.Tools,
  417. EstimatedCost: estimatedCost,
  418. TotalRecruitNum: totalRecruitNum,
  419. }
  420. //if projectUpdateParam.ProjectStatus == 2 {
  421. // updateProject.SubmitAt = t
  422. //}
  423. // 合并传入参数和数据表中原记录,若传入参数字段值为空,则将字段赋值为原记录中值
  424. result := util.MergeStructValue(&updateProject, project)
  425. // 利用反射机制将interface类型转换为结构体类型
  426. v := reflect.ValueOf(&result).Elem()
  427. if v.Kind() == reflect.Struct {
  428. updateProject = v.Interface().(entity.Project)
  429. //fmt.Println(p)
  430. }
  431. // c) 计算预估成本(如果有)
  432. /*
  433. var estimatedCost float64
  434. if conv.MustInt(updateSelection.TaskMode, 0) == 1 {
  435. estimatedCost = conv.MustFloat64(updateSelection.TaskReward, 0) * conv.MustFloat64(updateSelection.SampleNum, 0)
  436. }
  437. estimatedCostToString, _ := conv.String(estimatedCost)
  438. updateSelection.EstimatedCost = estimatedCostToString
  439. */
  440. // 3. 更新选品
  441. err = dao.ProjectDAO{}.UpdateProject(updateProject)
  442. if err != nil {
  443. return nil, err
  444. }
  445. // 4. 更新选品brief和示例(种草任务补充信息)
  446. if projectUpdateParam.ProjectBrief != nil {
  447. // 删除已有brief
  448. err = dao.ProjectBriefDao{}.DeleteSecBriefBySelectionId(project.ProjectId)
  449. if err != nil {
  450. return nil, err
  451. }
  452. // 插入新的brief
  453. for _, v := range projectUpdateParam.ProjectBrief {
  454. brief := entity.ProjectBrief{
  455. ProjectID: project.ProjectId,
  456. FileUid: v.FileUid,
  457. FileName: v.Name,
  458. FileUrl: v.FileUrl,
  459. CreatedAt: time.Now(),
  460. Type: v.Type,
  461. }
  462. err = dao.ProjectBriefDao{}.CreateProjectBrief(brief)
  463. if err != nil {
  464. return nil, err
  465. }
  466. }
  467. }
  468. if projectUpdateParam.ProjectMaterial != nil {
  469. // 删除已有示例
  470. err = dao.ProjectMaterialDao{}.DeleteProjectMaterialByProjectId(project.ProjectId)
  471. if err != nil {
  472. return nil, err
  473. }
  474. // 插入新的示例
  475. for _, v := range projectUpdateParam.ProjectMaterial {
  476. projectMaterial := entity.ProjectMaterial{
  477. ProjectID: project.ProjectId,
  478. FileUid: v.FileUid,
  479. FileName: v.Name,
  480. FileUrl: v.FileUrl,
  481. CreatedAt: time.Now(),
  482. Type: v.Type,
  483. }
  484. err = dao.ProjectMaterialDao{}.CreateProjectMaterial(projectMaterial)
  485. if err != nil {
  486. return nil, err
  487. }
  488. }
  489. }
  490. return &updateProject.ProjectId, nil
  491. }
  492. // 种草任务预览
  493. func (s ProjectService) GetProjectDetail(projectId string) (*vo.ReProjectDetail, error) {
  494. reProjectDetail := vo.ReProjectDetail{}
  495. project, err := dao.ProjectDAO{}.GetProjectById(projectId)
  496. if err != nil {
  497. logrus.Errorf("[projectDB service] call GetProject error,err:%+v", err)
  498. return nil, err
  499. }
  500. if project == nil {
  501. return nil, errors.New("数据不存在")
  502. }
  503. reProjectDetail.ProjectName = project.ProjectName
  504. // 系统信息
  505. reProjectDetail.ProjectId = projectId
  506. reProjectDetail.ProjectStatus = project.ProjectStatus
  507. reProjectDetail.ProjectPlatform = project.ProjectPlatform
  508. reProjectDetail.CreatedAt = project.CreatedAt.Format("2006-01-02 15:04:05")
  509. reProjectDetail.SubmitAt = project.SubmitAt.Format("2006-01-02 15:04:05")
  510. reProjectDetail.PassAt = project.PassAt.Format("2006-01-02 15:04:05")
  511. reProjectDetail.AutoFailAt = project.AutoFailAt.Format("2006-01-02 15:04:05")
  512. reProjectDetail.StartAt = project.PayAt.Format("2006-01-02 15:04:05")
  513. reProjectDetail.FinishAt = project.FinishAt.Format("2006-01-02 15:04:05")
  514. reProjectDetail.FailAt = project.FailAt.Format("2006-01-02 15:04:05")
  515. if project.ProjectStatus < 6 {
  516. reProjectDetail.EstimatedCost = project.EstimatedCost
  517. } else {
  518. reProjectDetail.EstimatedCost = project.NeedPay
  519. }
  520. reProjectDetail.ServiceChargeRate = project.ServiceChargeRate
  521. var creatorName, phone string
  522. if project.SubAccountId == 0 {
  523. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(project.EnterpriseID)
  524. if err == nil && enterprise != nil {
  525. creatorName = enterprise.BusinessName
  526. phone, err = dao.UserDao{}.GetPhoneByUserId(enterprise.UserId)
  527. }
  528. } else {
  529. subAccount, err := dao.SubAccountDao{}.GetSubAccount(project.SubAccountId)
  530. if err == nil && subAccount != nil {
  531. creatorName = subAccount.SubAccountName
  532. phone, err = dao.UserDao{}.GetPhoneByUserId(subAccount.UserId)
  533. }
  534. }
  535. reProjectDetail.CreatorName = creatorName
  536. reProjectDetail.Phone = phone
  537. // 关联商品
  538. var reProduct vo.ReProductPreview
  539. var product entity.Product
  540. var productMainPhoto entity.ProductPhoto
  541. err1 := json.Unmarshal([]byte(project.ProductSnap), &product)
  542. err2 := json.Unmarshal([]byte(project.ProductPhotoSnap), &productMainPhoto)
  543. if err1 == nil && err2 == nil {
  544. reProduct = vo.ReProductPreview{
  545. ProductID: product.ProductID,
  546. ProductName: product.ProductName,
  547. ProductType: product.ProductType,
  548. ProductCategory: product.ProductCategory,
  549. ProductPrice: product.ProductPrice,
  550. ProductDetail: product.ProductDetail,
  551. CreatedAt: product.CreatedAt.Format("2006-01-02 15:04:05"),
  552. PhotoUrl: productMainPhoto.PhotoUrl,
  553. }
  554. }
  555. reProjectDetail.ProductInfo = &reProduct
  556. // 招募要求
  557. reProjectDetail.TalentType = project.TalentType
  558. reProjectDetail.RecruitDdl = project.RecruitDdl.Format("2006-01-02 15:04:05")
  559. reProjectDetail.ProjectForm = project.ProjectForm
  560. reProjectDetail.ContentType = project.ContentType
  561. reProjectDetail.ProjectDetail = project.ProjectDetail
  562. var recruitStrategysPreviews []*vo.RecruitStrategyPreview
  563. recruitStrategys, err := dao.RecruitStrategyDao{}.GetRecruitStrategyByProjectId(projectId)
  564. if err != nil {
  565. logrus.Errorf("[projectDB service] call GetRecruitStrategy error,err:%+v", err)
  566. return nil, err
  567. }
  568. for _, recruitStrategy := range recruitStrategys {
  569. recruitStrategysPreview := &vo.RecruitStrategyPreview{
  570. StrategyId: recruitStrategy.StrategyID,
  571. FeeForm: recruitStrategy.FeeForm,
  572. FollowersLow: recruitStrategy.FollowersLow,
  573. FollowersUp: recruitStrategy.FollowersUp,
  574. RecruitNumber: recruitStrategy.RecruitNumber,
  575. Offer: recruitStrategy.Offer,
  576. TOffer: recruitStrategy.TOffer,
  577. ServiceCharge: recruitStrategy.ServiceCharge,
  578. SelectedNumber: recruitStrategy.SelectedNumber,
  579. TotalOffer: recruitStrategy.TotalOffer,
  580. }
  581. recruitStrategysPreviews = append(recruitStrategysPreviews, recruitStrategysPreview)
  582. }
  583. reProjectDetail.RecruitStrategys = recruitStrategysPreviews
  584. // 执行要求
  585. projectBriefInfos, err := dao.ProjectBriefDao{}.GetProjectBriefInfo(projectId)
  586. if err != nil {
  587. logrus.Errorf("[projectDB service] call GetProjectBriefInfo error,err:%+v", err)
  588. return nil, err
  589. }
  590. projectMaterials, err := dao.ProjectMaterialDao{}.GetProjectMaterialInfo(projectId)
  591. if err != nil {
  592. logrus.Errorf("[projectDB service] call GetprojectMaterialInfo error,err:%+v", err)
  593. return nil, err
  594. }
  595. reProjectDetail.ProjectBriefs = projectBriefInfos
  596. reProjectDetail.ProjectMaterials = projectMaterials
  597. reProjectDetail.Tools = project.Tools
  598. return &reProjectDetail, nil
  599. }
  600. // 复制种草任务
  601. func (s ProjectService) CopyProject(param *vo.ProjectSearchParam) (*string, error) {
  602. projectOrigin, err := dao.ProjectDAO{}.GetProjectById(param.ProjectId)
  603. if err != nil {
  604. logrus.Errorf("[projectDB service] call GetProject error,err:%+v", err)
  605. return nil, err
  606. }
  607. if projectOrigin == nil {
  608. return nil, errors.New("任务不存在")
  609. }
  610. projectIdOrigin := projectOrigin.ProjectId
  611. projectIdNew := strings.ReplaceAll(util.GenerateUUID(11), "-", "")
  612. t := time.Now()
  613. // 获取定时任务配置id
  614. infoAutoTask := entity.InfoAutoTask{}
  615. infoAutoTask = dao.InfoAutoTaskDao{}.GetAutoTaskLast(projectOrigin.EnterpriseID)
  616. infoAutoDefault := entity.InfoAutoDefault{}
  617. infoAutoDefault = dao.InfoAutoDefaultDao{}.GetAutoDefaultLast(projectOrigin.EnterpriseID)
  618. // 复制任务
  619. projectNew := entity.Project{
  620. ProjectStatus: 1,
  621. ProjectType: projectOrigin.ProjectType,
  622. ProjectId: projectIdNew,
  623. ProductID: projectOrigin.ProductID,
  624. ProductCategory: projectOrigin.ProductCategory,
  625. EnterpriseID: projectOrigin.EnterpriseID,
  626. SubAccountId: projectOrigin.SubAccountId,
  627. ProjectPlatform: projectOrigin.ProjectPlatform,
  628. OperatorType: projectOrigin.OperatorType,
  629. ProductSnap: projectOrigin.ProductSnap,
  630. ProductPhotoSnap: projectOrigin.ProductPhotoSnap,
  631. CreatedAt: t,
  632. AutoTaskID: infoAutoTask.AutoTaskID,
  633. AutoDefaultID: infoAutoDefault.AutoDefaultID,
  634. ProjectName: projectOrigin.ProjectName,
  635. TalentType: projectOrigin.TalentType,
  636. RecruitDdl: projectOrigin.RecruitDdl,
  637. ProjectForm: projectOrigin.ProjectForm,
  638. ContentType: projectOrigin.ContentType,
  639. ProjectDetail: projectOrigin.ProjectDetail,
  640. Tools: projectOrigin.Tools,
  641. ServiceChargeRate: projectOrigin.ServiceChargeRate,
  642. EstimatedCost: projectOrigin.EstimatedCost,
  643. }
  644. err = dao.ProjectDAO{}.CreateProject(projectNew)
  645. if err != nil {
  646. return nil, err
  647. }
  648. // 更新选品brief和示例(种草任务补充信息)
  649. projectBriefInfos, err := dao.ProjectBriefDao{}.GetProjectBriefInfo(projectIdOrigin)
  650. if err != nil {
  651. logrus.Errorf("[projectDB service] call GetProjectBriefInfo error,err:%+v", err)
  652. return nil, err
  653. }
  654. if projectBriefInfos != nil {
  655. for _, v := range projectBriefInfos {
  656. brief := entity.ProjectBrief{
  657. ProjectID: projectIdNew,
  658. FileUid: v.FileUid,
  659. FileName: v.FileName,
  660. FileUrl: v.FileUrl,
  661. CreatedAt: time.Now(),
  662. Type: v.Type,
  663. }
  664. err = dao.ProjectBriefDao{}.CreateProjectBrief(brief)
  665. if err != nil {
  666. return nil, err
  667. }
  668. }
  669. }
  670. projectMaterials, err := dao.ProjectMaterialDao{}.GetProjectMaterialInfo(projectIdOrigin)
  671. if err != nil {
  672. logrus.Errorf("[projectDB service] call GetprojectMaterialInfo error,err:%+v", err)
  673. return nil, err
  674. }
  675. if projectMaterials != nil {
  676. // 插入新的示例
  677. for _, v := range projectMaterials {
  678. projectMaterial := entity.ProjectMaterial{
  679. ProjectID: projectIdNew,
  680. FileUid: v.FileUid,
  681. FileName: v.FileName,
  682. FileUrl: v.FileUrl,
  683. CreatedAt: time.Now(),
  684. Type: v.Type,
  685. }
  686. err = dao.ProjectMaterialDao{}.CreateProjectMaterial(projectMaterial)
  687. if err != nil {
  688. return nil, err
  689. }
  690. }
  691. }
  692. // 更新种草任务的招募策略
  693. recruitStrategys, err := dao.RecruitStrategyDao{}.GetRecruitStrategyByProjectId(projectIdOrigin)
  694. if err != nil {
  695. logrus.Errorf("[projectDB service] call GetRecruitStrategy error,err:%+v", err)
  696. return nil, err
  697. }
  698. var totalRecruitNum int64
  699. var estimatedCost float64
  700. if recruitStrategys != nil {
  701. // 2. 接收并创建新的招募策略
  702. if len(recruitStrategys) != 0 {
  703. var recruits []entity.RecruitStrategy
  704. for _, strategy := range recruitStrategys {
  705. if strategy.FeeForm == 2 {
  706. estimatedCost += float64(strategy.RecruitNumber) * strategy.Offer
  707. }
  708. recruitStrategy := entity.RecruitStrategy{
  709. FeeForm: strategy.FeeForm,
  710. StrategyID: strategy.StrategyID,
  711. FollowersLow: strategy.FollowersLow,
  712. FollowersUp: strategy.FollowersUp,
  713. RecruitNumber: strategy.RecruitNumber,
  714. ProjectID: projectIdNew,
  715. StrategyType: strategy.StrategyType,
  716. ServiceRate: strategy.ServiceRate,
  717. Offer: strategy.Offer,
  718. ServiceCharge: strategy.ServiceCharge,
  719. TOffer: strategy.TOffer,
  720. }
  721. totalRecruitNum += strategy.RecruitNumber
  722. recruits = append(recruits, recruitStrategy)
  723. }
  724. err = dao.RecruitStrategyDao{}.CreateRecruitStrategy(recruits)
  725. if err != nil {
  726. return nil, err
  727. }
  728. }
  729. }
  730. return &projectIdNew, nil
  731. }
  732. // 种草提交审核
  733. func (s ProjectService) ProjectToReview(projectUpdateParam *vo.ProjectUpdateParam) (*string, error) {
  734. projectId := projectUpdateParam.ProjectID
  735. project, err := dao.ProjectDAO{}.GetProjectById(projectId)
  736. if err != nil {
  737. logrus.Errorf("[projectInfoDB service] call GetProject error,err:%+v", err)
  738. return nil, err
  739. }
  740. projectName := project.ProjectName // 任务标题
  741. projectDetail := project.ProjectDetail // 任务详情
  742. product, err := dao.ProductDAO{}.GetProductByID(project.ProductID)
  743. if err != nil {
  744. return nil, err
  745. }
  746. productName := product.ProductName // 商品标题
  747. productDetail := product.ProductDetail // 卖点总结
  748. mainPhoto, err1 := dao.ProductPhotoDAO{}.GetMainPhotoByProductID(project.ProductID)
  749. if err1 != nil {
  750. return nil, err1
  751. }
  752. var images []string
  753. var videos []string
  754. var videoJobIds []string
  755. var documents []string
  756. var documentJobIds []string
  757. reviewService := review_service.GetConfig()
  758. productPhotos, err2 := dao.ProductPhotoDAO{}.GetProductPhotoByProductID(project.ProductID)
  759. if err2 != nil {
  760. return nil, err2
  761. }
  762. for _, productPhoto := range productPhotos {
  763. if productPhoto.Symbol == 2 || productPhoto.Symbol == 4 {
  764. images = append(images, productPhoto.PhotoUrl)
  765. } else if productPhoto.Symbol == 3 || productPhoto.Symbol == 5 {
  766. var videoJobId *string
  767. var reviewErr error
  768. i := 10
  769. for {
  770. videoJobId, reviewErr = reviewService.CheckVideo(productPhoto.PhotoUrl)
  771. if reviewErr == nil || i == 0 {
  772. break
  773. }
  774. i -= 1
  775. }
  776. if reviewErr != nil {
  777. return nil, reviewErr
  778. }
  779. videos = append(videos, productPhoto.PhotoUrl)
  780. videoJobIds = append(videoJobIds, *videoJobId)
  781. }
  782. }
  783. projectBriefInfos, err := dao.ProjectBriefDao{}.GetProjectBriefInfo(projectId)
  784. if err != nil {
  785. return nil, err
  786. }
  787. for _, projectBriefInfo := range projectBriefInfos {
  788. if projectBriefInfo.Type == 1 {
  789. images = append(images, projectBriefInfo.FileUrl)
  790. } else if projectBriefInfo.Type == 2 {
  791. var documentJobId *string
  792. var reviewErr error
  793. i := 10
  794. fileType := "pdf"
  795. parts := strings.Split(projectBriefInfo.FileName, ".")
  796. if len(parts) > 1 {
  797. fileType = parts[len(parts)-1]
  798. }
  799. for {
  800. documentJobId, reviewErr = reviewService.CheckDocument(projectBriefInfo.FileUrl, fileType)
  801. if reviewErr == nil || i == 0 {
  802. break
  803. }
  804. i -= 1
  805. }
  806. if reviewErr != nil {
  807. return nil, reviewErr
  808. }
  809. documents = append(documents, projectBriefInfo.FileUrl)
  810. documentJobIds = append(documentJobIds, *documentJobId)
  811. }
  812. }
  813. projectMaterials, err := dao.ProjectMaterialDao{}.GetProjectMaterialInfo(projectId)
  814. if err != nil {
  815. return nil, err
  816. }
  817. for _, projectMaterial := range projectMaterials {
  818. if projectMaterial.Type == 1 {
  819. images = append(images, projectMaterial.FileUrl)
  820. } else if projectMaterial.Type == 2 {
  821. var videoJobId *string
  822. var reviewErr error
  823. i := 10
  824. for {
  825. videoJobId, reviewErr = reviewService.CheckVideo(projectMaterial.FileUrl)
  826. if reviewErr == nil || i == 0 {
  827. break
  828. }
  829. i -= 1
  830. }
  831. if reviewErr != nil {
  832. return nil, reviewErr
  833. }
  834. videos = append(videos, projectMaterial.FileUrl)
  835. videoJobIds = append(videoJobIds, *videoJobId)
  836. }
  837. }
  838. newReviewProject := &entity.ReviewProject{
  839. ProjectID: projectId,
  840. TaskName: projectName,
  841. TaskDetail: projectDetail,
  842. ProductName: productName,
  843. ProductDetail: productDetail,
  844. MainPhoto: mainPhoto,
  845. Images: strings.Join(images, ","),
  846. Videos: strings.Join(videos, ","),
  847. Documents: strings.Join(documents, ","),
  848. VideoJobIds: strings.Join(videoJobIds, ","),
  849. DocumentJobIds: strings.Join(documentJobIds, ","),
  850. Status: 1,
  851. }
  852. err5 := dao.ProjectReviewDao{}.Create(newReviewProject)
  853. if err5 != nil {
  854. return nil, err5
  855. }
  856. t := time.Now()
  857. updateProject := entity.Project{
  858. ProjectId: projectId,
  859. ProjectStatus: 2,
  860. SubmitAt: t,
  861. UpdatedAt: t,
  862. }
  863. err6 := dao.ProjectDAO{}.UpdateProject(updateProject)
  864. if err6 != nil {
  865. return nil, err
  866. }
  867. return &projectId, nil
  868. }
  869. // 种草任务列表
  870. func (s ProjectService) GetProjectTaskList(param *vo.ProjectSearchParam) (vo.ResultVO, error) {
  871. if param.Page == 0 {
  872. param.Page = 1
  873. }
  874. if param.PageSize == 0 {
  875. param.PageSize = 10
  876. }
  877. var result vo.ResultVO
  878. reProjectTaskPreviews, total, err := (&dao.ProjectDAO{}).GetProjectPreviews(param)
  879. if err != nil {
  880. return result, err
  881. }
  882. for i := range reProjectTaskPreviews {
  883. var creatorName string
  884. var productName string
  885. var productPrice float64
  886. var mainImage string
  887. if reProjectTaskPreviews[i].SubAccountId == 0 {
  888. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reProjectTaskPreviews[i].EnterpriseId)
  889. if err == nil && enterprise != nil {
  890. creatorName = enterprise.BusinessName
  891. }
  892. } else {
  893. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reProjectTaskPreviews[i].SubAccountId)
  894. if err == nil && subAccount != nil {
  895. creatorName = subAccount.SubAccountName
  896. }
  897. }
  898. product, err := dao.ProductDAO{}.GetProductByID(reProjectTaskPreviews[i].ProductId)
  899. if err == nil && product != nil {
  900. productName = product.ProductName
  901. productPrice = product.ProductPrice
  902. }
  903. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reProjectTaskPreviews[i].ProductId)
  904. reProjectTaskPreviews[i].CreatorName = creatorName
  905. reProjectTaskPreviews[i].ProductName = productName
  906. reProjectTaskPreviews[i].ProductPrice = productPrice
  907. reProjectTaskPreviews[i].MainImage = mainImage
  908. }
  909. result = vo.ResultVO{
  910. Page: param.Page,
  911. PageSize: param.PageSize,
  912. Total: total,
  913. Data: reProjectTaskPreviews,
  914. }
  915. return result, nil
  916. }
  917. // 删除种草任务
  918. func (s ProjectService) DeleteProject(projectId string) (*string, error) {
  919. res, err := dao.ProjectDAO{}.DeleteProject(projectId)
  920. if err != nil {
  921. logrus.Errorf("[projectDB service] call DeleteProject error,err:%+v", err)
  922. return res, err
  923. }
  924. return res, nil
  925. }
  926. // 结束种草任务
  927. func (s ProjectService) CloseProject(projectId string) (string, error) {
  928. // 任务待办:待审核、待支付、达人未处理、初稿待审、链接待审、待结算 待发货、待签收 未传初稿、未发作品、未传数据
  929. // 合作待办:可邀约、邀约中、合作中
  930. project, err := dao.ProjectDAO{}.GetProjectById(projectId)
  931. if err != nil {
  932. return "0", err
  933. }
  934. if project == nil {
  935. return "0", errors.New("任务不存在")
  936. }
  937. var needProcess int64
  938. if project.ProjectStatus == 4 || project.ProjectStatus == 8 {
  939. // 达人未处理 or 物流待办 or 初稿待审、链接待审、待结算
  940. _ = dao.Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? and (task_status = ? or task_stage < ?)", projectId, 1, 15).Count(&needProcess).Error // task_status=1待选
  941. }
  942. if project.ProjectStatus == 2 || project.ProjectStatus == 4 || needProcess > 0 {
  943. // 存在待办不可结束
  944. return "1", nil
  945. } else {
  946. err := dao.ProjectDAO{}.UpdateProject(entity.Project{
  947. ProjectId: projectId,
  948. ProjectStatus: 10,
  949. UpdatedAt: time.Now(),
  950. })
  951. return "0", err
  952. }
  953. }
  954. // 草稿箱——品牌种草
  955. func (s ProjectService) GetProjectDraftList(param *vo.ProjectDraftParam) (vo.ResultVO, error) {
  956. if param.Page == 0 {
  957. param.Page = 1
  958. }
  959. if param.PageSize == 0 {
  960. param.PageSize = 10
  961. }
  962. var result vo.ResultVO
  963. reProjectTaskPreviews, total, err := (&dao.ProjectDAO{}).GetProjectDraftList(param)
  964. if err != nil {
  965. return result, err
  966. }
  967. for i := range reProjectTaskPreviews {
  968. var creatorName string
  969. var productName string
  970. var productPrice float64
  971. var mainImage string
  972. if reProjectTaskPreviews[i].SubAccountId == 0 {
  973. enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reProjectTaskPreviews[i].EnterpriseId)
  974. if err == nil && enterprise != nil {
  975. creatorName = enterprise.BusinessName
  976. }
  977. } else {
  978. subAccount, err := dao.SubAccountDao{}.GetSubAccount(reProjectTaskPreviews[i].SubAccountId)
  979. if err == nil && subAccount != nil {
  980. creatorName = subAccount.SubAccountName
  981. }
  982. }
  983. product, err := dao.ProductDAO{}.GetProductByID(reProjectTaskPreviews[i].ProductId)
  984. if err == nil && product != nil {
  985. productName = product.ProductName
  986. productPrice = product.ProductPrice
  987. }
  988. mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reProjectTaskPreviews[i].ProductId)
  989. reProjectTaskPreviews[i].CreatorName = creatorName
  990. reProjectTaskPreviews[i].ProductName = productName
  991. reProjectTaskPreviews[i].ProductPrice = productPrice
  992. reProjectTaskPreviews[i].MainImage = mainImage
  993. }
  994. result = vo.ResultVO{
  995. Page: param.Page,
  996. PageSize: param.PageSize,
  997. Total: total,
  998. Data: reProjectTaskPreviews,
  999. }
  1000. return result, nil
  1001. }
  1002. // 达人内容类型
  1003. func (p ProjectService) GetTalentCategory() ([]vo.ReTalentCategory, error) {
  1004. var reTalentCategories []vo.ReTalentCategory
  1005. talentCategory, err := dao.TalentInfoDao{}.GetTalentCategory()
  1006. if err != nil {
  1007. return nil, err
  1008. }
  1009. for _, category := range talentCategory {
  1010. reTalentCategory := vo.ReTalentCategory{
  1011. ID: category.ID,
  1012. Category: category.Category,
  1013. }
  1014. reTalentCategories = append(reTalentCategories, reTalentCategory)
  1015. }
  1016. return reTalentCategories, nil
  1017. }
  1018. // 种草任务待办
  1019. func (p ProjectService) GetTaskToDo(enterpriseId string, subAccountId int64, taskType int64) (map[string]map[string]int64, error) {
  1020. res := make(map[string]map[string]int64)
  1021. redbook, err1 := dao.ProjectDAO{}.GetProjectToDo(enterpriseId, subAccountId, 1, taskType)
  1022. if err1 != nil {
  1023. logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err1)
  1024. return res, err1
  1025. }
  1026. douyin, err2 := dao.ProjectDAO{}.GetProjectToDo(enterpriseId, subAccountId, 2, taskType)
  1027. if err2 != nil {
  1028. logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err2)
  1029. return res, err2
  1030. }
  1031. kuaishou, err3 := dao.ProjectDAO{}.GetProjectToDo(enterpriseId, subAccountId, 4, taskType)
  1032. if err3 != nil {
  1033. logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err3)
  1034. return res, err3
  1035. }
  1036. weibo, err4 := dao.ProjectDAO{}.GetProjectToDo(enterpriseId, subAccountId, 3, taskType)
  1037. if err4 != nil {
  1038. logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err4)
  1039. return res, err4
  1040. }
  1041. bilibili, err5 := dao.ProjectDAO{}.GetProjectToDo(enterpriseId, subAccountId, 5, taskType)
  1042. if err5 != nil {
  1043. logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err5)
  1044. return res, err5
  1045. }
  1046. all := make(map[string]int64)
  1047. all["needReview"] = redbook["needReview"] + douyin["needReview"] + kuaishou["needReview"] + weibo["needReview"] + bilibili["needReview"]
  1048. all["needPay"] = redbook["needPay"] + douyin["needPay"] + kuaishou["needPay"] + weibo["needPay"] + bilibili["needPay"]
  1049. all["needProcess"] = redbook["needProcess"] + douyin["needProcess"] + kuaishou["needProcess"] + weibo["needProcess"] + bilibili["needProcess"]
  1050. all["needCheck"] = redbook["needCheck"] + douyin["needCheck"] + kuaishou["needCheck"] + weibo["needCheck"] + bilibili["needCheck"]
  1051. all["needQuality"] = redbook["needQuality"] + douyin["needQuality"] + kuaishou["needQuality"] + weibo["needQuality"] + bilibili["needQuality"]
  1052. all["needCalculate"] = redbook["needCalculate"] + douyin["needCalculate"] + kuaishou["needCalculate"] + weibo["needCalculate"] + bilibili["needCalculate"]
  1053. res["redbook"] = redbook
  1054. res["douyin"] = douyin
  1055. res["kuaishou"] = kuaishou
  1056. res["weibo"] = weibo
  1057. res["bilibili"] = bilibili
  1058. res["all"] = all
  1059. return res, nil
  1060. }
  1061. // 寄样物流任务待办
  1062. func (p ProjectService) GetLogisticsToDo(enterpriseId string, subAccountId int64) (map[string]map[string]int64, error) {
  1063. res := make(map[string]map[string]int64)
  1064. redbook, err1 := dao.ProjectDAO{}.GetLogisticsToDo(enterpriseId, subAccountId, 1)
  1065. if err1 != nil {
  1066. logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err1)
  1067. return res, err1
  1068. }
  1069. douyin, err2 := dao.ProjectDAO{}.GetLogisticsToDo(enterpriseId, subAccountId, 2)
  1070. if err2 != nil {
  1071. logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err2)
  1072. return res, err2
  1073. }
  1074. kuaishou, err3 := dao.ProjectDAO{}.GetLogisticsToDo(enterpriseId, subAccountId, 4)
  1075. if err3 != nil {
  1076. logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err3)
  1077. return res, err3
  1078. }
  1079. weibo, err4 := dao.ProjectDAO{}.GetLogisticsToDo(enterpriseId, subAccountId, 3)
  1080. if err4 != nil {
  1081. logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err4)
  1082. return res, err4
  1083. }
  1084. bilibili, err5 := dao.ProjectDAO{}.GetLogisticsToDo(enterpriseId, subAccountId, 5)
  1085. if err5 != nil {
  1086. logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err5)
  1087. return res, err5
  1088. }
  1089. all := make(map[string]int64)
  1090. all["needDelivery"] = redbook["needDelivery"] + douyin["needDelivery"] + kuaishou["needDelivery"] + weibo["needDelivery"] + bilibili["needDelivery"]
  1091. all["needReceive"] = redbook["needReceive"] + douyin["needReceive"] + kuaishou["needReceive"] + weibo["needReceive"] + bilibili["needReceive"]
  1092. res["redbook"] = redbook
  1093. res["douyin"] = douyin
  1094. res["kuaishou"] = kuaishou
  1095. res["weibo"] = weibo
  1096. res["bilibili"] = bilibili
  1097. res["all"] = all
  1098. return res, nil
  1099. }
  1100. // 违约管理任务待办
  1101. func (p ProjectService) GetDefaultToDo(enterpriseId string, subAccountId int64, taskType int64) (map[string]map[string]int64, error) {
  1102. res := make(map[string]map[string]int64)
  1103. redbook, err1 := dao.ProjectDAO{}.GetDefaultToDo(enterpriseId, subAccountId, 1, taskType)
  1104. if err1 != nil {
  1105. logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err1)
  1106. return res, err1
  1107. }
  1108. douyin, err2 := dao.ProjectDAO{}.GetDefaultToDo(enterpriseId, subAccountId, 2, taskType)
  1109. if err2 != nil {
  1110. logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err2)
  1111. return res, err2
  1112. }
  1113. kuaishou, err3 := dao.ProjectDAO{}.GetDefaultToDo(enterpriseId, subAccountId, 4, taskType)
  1114. if err3 != nil {
  1115. logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err3)
  1116. return res, err3
  1117. }
  1118. weibo, err4 := dao.ProjectDAO{}.GetDefaultToDo(enterpriseId, subAccountId, 3, taskType)
  1119. if err4 != nil {
  1120. logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err4)
  1121. return res, err4
  1122. }
  1123. bilibili, err5 := dao.ProjectDAO{}.GetDefaultToDo(enterpriseId, subAccountId, 5, taskType)
  1124. if err5 != nil {
  1125. logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err5)
  1126. return res, err5
  1127. }
  1128. all := make(map[string]int64)
  1129. all["noSketch"] = redbook["noSketch"] + douyin["noSketch"] + kuaishou["noSketch"] + weibo["noSketch"] + bilibili["noSketch"]
  1130. all["noWork"] = redbook["noWork"] + douyin["noWork"] + kuaishou["noWork"] + weibo["noWork"] + bilibili["noWork"]
  1131. all["noData"] = redbook["noData"] + douyin["noData"] + kuaishou["noData"] + weibo["noData"] + bilibili["noData"]
  1132. all["cooperateOver"] = redbook["cooperateOver"] + douyin["cooperateOver"] + kuaishou["cooperateOver"] + weibo["cooperateOver"] + bilibili["cooperateOver"]
  1133. res["redbook"] = redbook
  1134. res["douyin"] = douyin
  1135. res["kuaishou"] = kuaishou
  1136. res["weibo"] = weibo
  1137. res["bilibili"] = bilibili
  1138. res["all"] = all
  1139. return res, nil
  1140. }
  1141. // 合作待办-任务邀约
  1142. func (p ProjectService) GetTaskInviteToDo(enterpriseId string, subAccountId int64) (map[string]map[string]int64, error) {
  1143. res := make(map[string]map[string]int64)
  1144. redbook, err1 := dao.ProjectDAO{}.GetTaskInviteToDo(enterpriseId, subAccountId, 1)
  1145. if err1 != nil {
  1146. logrus.Errorf("[GetTaskInviteToDo service] call GetTaskInviteToDo error,err:%+v", err1)
  1147. return res, err1
  1148. }
  1149. douyin, err2 := dao.ProjectDAO{}.GetTaskInviteToDo(enterpriseId, subAccountId, 2)
  1150. if err2 != nil {
  1151. logrus.Errorf("[GetTaskInviteToDo service] call GetTaskInviteToDo error,err:%+v", err2)
  1152. return res, err2
  1153. }
  1154. kuaishou, err3 := dao.ProjectDAO{}.GetTaskInviteToDo(enterpriseId, subAccountId, 4)
  1155. if err3 != nil {
  1156. logrus.Errorf("[GetTaskInviteToDo service] call GetTaskInviteToDo error,err:%+v", err3)
  1157. return res, err3
  1158. }
  1159. weibo, err4 := dao.ProjectDAO{}.GetTaskInviteToDo(enterpriseId, subAccountId, 3)
  1160. if err4 != nil {
  1161. logrus.Errorf("[GetTaskInviteToDo service] call GetTaskInviteToDo error,err:%+v", err4)
  1162. return res, err4
  1163. }
  1164. bilibili, err5 := dao.ProjectDAO{}.GetTaskInviteToDo(enterpriseId, subAccountId, 5)
  1165. if err5 != nil {
  1166. logrus.Errorf("[GetTaskInviteToDo service] call GetTaskInviteToDo error,err:%+v", err5)
  1167. return res, err5
  1168. }
  1169. all := make(map[string]int64)
  1170. all["availInvitationNum"] = redbook["availInvitationNum"] + douyin["availInvitationNum"] + kuaishou["availInvitationNum"] + weibo["availInvitationNum"] + bilibili["availInvitationNum"]
  1171. all["invitingNum"] = redbook["invitingNum"] + douyin["invitingNum"] + kuaishou["invitingNum"] + weibo["invitingNum"] + bilibili["invitingNum"]
  1172. all["cooperatingNum"] = redbook["cooperatingNum"] + douyin["cooperatingNum"] + kuaishou["cooperatingNum"] + weibo["cooperatingNum"] + bilibili["cooperatingNum"]
  1173. res["redbook"] = redbook
  1174. res["douyin"] = douyin
  1175. res["kuaishou"] = kuaishou
  1176. res["weibo"] = weibo
  1177. res["bilibili"] = bilibili
  1178. res["all"] = all
  1179. return res, nil
  1180. }