project.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "math/rand"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "youngee_b_api/db"
  11. "youngee_b_api/model/common_model"
  12. "youngee_b_api/model/gorm_model"
  13. "youngee_b_api/model/http_model"
  14. "youngee_b_api/pack"
  15. "youngee_b_api/util"
  16. "github.com/gin-gonic/gin"
  17. "github.com/issue9/conv"
  18. "github.com/sirupsen/logrus"
  19. )
  20. var Project *project
  21. type project struct {
  22. }
  23. func (*project) Create(ctx context.Context, newProject http_model.CreateProjectRequest, enterpriseID string) (*http_model.CreateProjectData, error) {
  24. // build gorm_model.ProjectInfo
  25. // 查询关联商品信息
  26. product, err := db.GetProductByID(ctx, newProject.ProductID)
  27. if err != nil {
  28. return nil, err
  29. }
  30. productPhotos, err := db.GetProductPhotoByProductID(ctx, newProject.ProductID)
  31. productInfoToJson, _ := json.Marshal(product)
  32. productPhotosToJson, _ := json.Marshal(productPhotos)
  33. //fmt.Println("productPhotosToJson:", productPhotosToJson)
  34. AutoTaskID, err := db.GetLastAutoTaskID()
  35. if err != nil {
  36. return nil, err
  37. }
  38. AutoDefaultID, err := db.GetLastAutoDefaultID()
  39. if err != nil {
  40. return nil, err
  41. }
  42. // 按照品牌名-商品名对项目进行命名
  43. projectName := product.BrandName + "-" + product.ProductName
  44. //feeForm := fmt.Sprintf("[")
  45. feeFrom := []string{}
  46. for _, strategy := range newProject.RecruitStrategys {
  47. feeFrom = append(feeFrom, strconv.FormatInt(strategy.FeeForm, 10))
  48. }
  49. var ECost float64 = 0
  50. if newProject.ProjectType == int64(1) {
  51. for _, strategy := range newProject.RecruitStrategys {
  52. // 计算预估成本
  53. var tmpCost float64 = 0
  54. if strategy.FeeForm == 1 {
  55. tmpCost = strategy.ServiceCharge * float64(strategy.RecruitNumber)
  56. } else if strategy.FeeForm == 2 {
  57. tmpCost = strategy.Offer * float64(strategy.RecruitNumber)
  58. }
  59. ECost += tmpCost
  60. }
  61. }
  62. feeFroms := strings.Join(feeFrom, ",")
  63. //fmt.Printf("创建项目new %+v", newProject)
  64. RecruitDdl, _ := time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
  65. fmt.Println("Create RecruitDdl:", newProject.RecruitDdl, RecruitDdl)
  66. projectInfo := gorm_model.ProjectInfo{}
  67. rand.Seed(time.Now().UnixNano())
  68. td := conv.MustString(time.Now().Day())
  69. for {
  70. if len(td) == 3 {
  71. break
  72. }
  73. td = "0" + td
  74. }
  75. if newProject.ProjectType == int64(1) {
  76. projectInfo = gorm_model.ProjectInfo{
  77. ProjectID: conv.MustString(time.Now().Year())[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000),
  78. ProjectName: projectName,
  79. ProjectStatus: 1,
  80. ProjectType: newProject.ProjectType,
  81. TalentType: newProject.TalentType,
  82. ProjectPlatform: newProject.ProjectPlatform,
  83. ProjectForm: newProject.ProjectForm,
  84. RecruitDdl: &RecruitDdl,
  85. ProjectDetail: newProject.ProjectDetail,
  86. ContentType: newProject.ContentType,
  87. EnterpriseID: enterpriseID,
  88. ProductID: newProject.ProductID,
  89. FeeForm: feeFroms,
  90. AutoTaskID: conv.MustInt64(AutoTaskID),
  91. AutoDefaultID: conv.MustInt64(AutoDefaultID),
  92. EstimatedCost: ECost,
  93. IsRead: 0,
  94. ProductSnap: string(productInfoToJson),
  95. ProductPhotoSnap: string(productPhotosToJson),
  96. }
  97. } else {
  98. projectInfo = gorm_model.ProjectInfo{
  99. ProjectID: conv.MustString(time.Now().Year())[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000),
  100. ProjectName: projectName,
  101. ProjectStatus: 1,
  102. ProjectType: newProject.ProjectType,
  103. TalentType: "[]",
  104. ProjectPlatform: newProject.ProjectPlatform,
  105. ProjectForm: newProject.ProjectForm,
  106. //RecruitDdl: &RecruitDdl,
  107. ProjectDetail: newProject.ProjectDetail,
  108. ContentType: newProject.ContentType,
  109. EnterpriseID: enterpriseID,
  110. ProductID: newProject.ProductID,
  111. FeeForm: feeFroms,
  112. AutoTaskID: conv.MustInt64(AutoTaskID),
  113. AutoDefaultID: conv.MustInt64(AutoDefaultID),
  114. EstimatedCost: ECost,
  115. ProductSnap: string(productInfoToJson),
  116. ProductPhotoSnap: string(productPhotosToJson),
  117. }
  118. }
  119. // db create ProjectInfo
  120. projectID, err := db.CreateProject(ctx, projectInfo)
  121. if err != nil {
  122. return nil, err
  123. }
  124. if len(newProject.ProjectPhotos) != 0 {
  125. // build []gorm_model.ProjectPhoto
  126. projectPhotos := []gorm_model.ProjectPhoto{}
  127. for _, photo := range newProject.ProjectPhotos {
  128. projectPhoto := gorm_model.ProjectPhoto{
  129. PhotoUrl: photo.PhotoUrl,
  130. PhotoUid: photo.PhotoUid,
  131. ProjectID: *projectID,
  132. }
  133. projectPhotos = append(projectPhotos, projectPhoto)
  134. }
  135. // db create ProjectPhoto
  136. err = db.CreateProjectPhoto(ctx, projectPhotos)
  137. if err != nil {
  138. return nil, err
  139. }
  140. }
  141. // build
  142. if newProject.ProjectType == int64(1) {
  143. recruitStrategys := []gorm_model.RecruitStrategy{}
  144. for _, strategy := range newProject.RecruitStrategys {
  145. // 查询对应定价策略
  146. pricingStrategy, err := db.GetPricingStrategy(ctx, strategy.FollowersLow, strategy.FollowersUp, strategy.FeeForm, newProject.ProjectPlatform)
  147. if err != nil {
  148. return nil, err
  149. }
  150. // 根据定价策略计算达人所见报价
  151. if strategy.FeeForm == 2 {
  152. strategy.TOffer = strategy.Offer * (1 - conv.MustFloat64(pricingStrategy.ServiceRate)/1000)
  153. }
  154. recruitStrategy := gorm_model.RecruitStrategy{
  155. FeeForm: strategy.FeeForm,
  156. StrategyID: strategy.StrategyID,
  157. FollowersLow: strategy.FollowersLow,
  158. FollowersUp: strategy.FollowersUp,
  159. RecruitNumber: strategy.RecruitNumber,
  160. ServiceCharge: strategy.ServiceCharge,
  161. Offer: strategy.Offer,
  162. TOffer: strategy.TOffer,
  163. ProjectID: *projectID,
  164. }
  165. recruitStrategys = append(recruitStrategys, recruitStrategy)
  166. }
  167. err = db.CreateRecruitStrategy(ctx, recruitStrategys)
  168. if err != nil {
  169. return nil, err
  170. }
  171. }
  172. res := &http_model.CreateProjectData{
  173. ProjectID: *projectID,
  174. }
  175. //fmt.Printf("%+v", res)
  176. return res, nil
  177. }
  178. func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectRequest, enterpriseID string) (*http_model.UpdateProjectData, error) {
  179. RecruitDdl, _ := time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
  180. fmt.Println("Update RecruitDdl:", newProject.RecruitDdl, RecruitDdl)
  181. oldProject, err3 := db.GetProjectDetail(ctx, newProject.ProjectID)
  182. if err3 != nil {
  183. return nil, err3
  184. }
  185. feeFrom := []string{}
  186. for _, strategy := range newProject.RecruitStrategys {
  187. //if strategy.StrategyID
  188. feeFrom = append(feeFrom, strconv.FormatInt(strategy.FeeForm, 10))
  189. //feeForm += string(strategy.StrategyID)
  190. }
  191. var ECost float64 = 0
  192. if newProject.ProjectType == int64(1) {
  193. for _, strategy := range newProject.RecruitStrategys {
  194. // 计算预估成本
  195. var tmpCost float64 = 0
  196. if strategy.FeeForm == 1 {
  197. tmpCost = strategy.ServiceCharge * float64(strategy.RecruitNumber)
  198. } else if strategy.FeeForm == 2 {
  199. tmpCost = strategy.Offer * float64(strategy.RecruitNumber)
  200. }
  201. ECost += tmpCost
  202. }
  203. }
  204. feeFroms := strings.Join(feeFrom, ",")
  205. t := time.Now()
  206. project := gorm_model.ProjectInfo{
  207. ProjectID: newProject.ProjectID,
  208. RecruitDdl: &RecruitDdl,
  209. TalentType: newProject.TalentType,
  210. ContentType: conv.MustInt64(newProject.ContentType),
  211. ProjectDetail: newProject.ProjectDetail,
  212. ProjectForm: conv.MustInt64(newProject.ProjectForm),
  213. EnterpriseID: enterpriseID,
  214. ProjectStatus: conv.MustInt64(newProject.ProjectStatus),
  215. FeeForm: feeFroms,
  216. EstimatedCost: ECost,
  217. SubmitAt: &t,
  218. }
  219. projectID, err := db.UpdateProject(ctx, project)
  220. if err != nil {
  221. return nil, err
  222. }
  223. // 删除该项目之前的所有图片
  224. err = db.DeleteProjectPhotoByProjecttID(ctx, *projectID)
  225. if err != nil {
  226. return nil, err
  227. }
  228. //fmt.Printf("照片:\t %+v", newProject.ProjectPhotos)
  229. if len(newProject.ProjectPhotos) != 0 {
  230. // 新增图片
  231. projectPhotos := []gorm_model.ProjectPhoto{}
  232. for _, photo := range newProject.ProjectPhotos {
  233. projectPhoto := gorm_model.ProjectPhoto{
  234. ProjectID: project.ProjectID,
  235. PhotoUrl: photo.PhotoUrl,
  236. PhotoUid: photo.PhotoUid,
  237. }
  238. projectPhotos = append(projectPhotos, projectPhoto)
  239. }
  240. err = db.CreateProjectPhoto(ctx, projectPhotos)
  241. if err != nil {
  242. return nil, err
  243. }
  244. }
  245. // 删除该项目之前的所有策略
  246. err = db.DeleteRecruitStrategyByProjectID(ctx, *projectID)
  247. if err != nil {
  248. return nil, err
  249. }
  250. fmt.Printf("策略:\t %+v", newProject.RecruitStrategys)
  251. if newProject.RecruitStrategys != nil && newProject.ProjectType == int64(1) {
  252. // 新增策略
  253. RecruitStrategys := []gorm_model.RecruitStrategy{}
  254. for _, Strategy := range newProject.RecruitStrategys {
  255. // 查询对应定价策略
  256. pricingStrategy, err := db.GetPricingStrategy(ctx, Strategy.FollowersLow, Strategy.FollowersUp, Strategy.FeeForm, oldProject.ProjectPlatform)
  257. if err != nil {
  258. return nil, err
  259. }
  260. // 根据定价策略计算达人所见报价
  261. if Strategy.FeeForm == 2 {
  262. Strategy.TOffer = Strategy.Offer * (1 - conv.MustFloat64(pricingStrategy.ServiceRate)/1000)
  263. }
  264. RecruitStrategy := gorm_model.RecruitStrategy{
  265. FeeForm: conv.MustInt64(Strategy.FeeForm),
  266. StrategyID: conv.MustInt64(Strategy.StrategyID),
  267. FollowersLow: conv.MustInt64(Strategy.FollowersLow),
  268. FollowersUp: conv.MustInt64(Strategy.FollowersUp),
  269. RecruitNumber: conv.MustInt64(Strategy.RecruitNumber),
  270. ServiceCharge: Strategy.ServiceCharge,
  271. Offer: Strategy.Offer,
  272. TOffer: Strategy.TOffer,
  273. ProjectID: project.ProjectID,
  274. }
  275. //fmt.Printf("Offer:\t %+v", Strategy.Offer)
  276. RecruitStrategys = append(RecruitStrategys, RecruitStrategy)
  277. }
  278. err = db.CreateRecruitStrategy(ctx, RecruitStrategys)
  279. if err != nil {
  280. return nil, err
  281. }
  282. }
  283. res := &http_model.UpdateProjectData{
  284. ProjectID: *projectID,
  285. }
  286. return res, nil
  287. }
  288. func (*project) Delete(ctx context.Context, projectID string) (*http_model.DeleteProjectData, error) {
  289. // 删除该项目之前的所有图片
  290. err := db.DeleteProjectPhotoByProjecttID(ctx, projectID)
  291. if err != nil {
  292. return nil, err
  293. }
  294. // 删除该项目之前的所有策略
  295. err = db.DeleteRecruitStrategyByProjectID(ctx, projectID)
  296. if err != nil {
  297. return nil, err
  298. }
  299. //删除项目
  300. NewProjectID, err1 := db.DeleteProject(ctx, projectID)
  301. if err1 != nil {
  302. return nil, err1
  303. }
  304. res := &http_model.DeleteProjectData{
  305. ProjectID: *NewProjectID,
  306. }
  307. return res, nil
  308. }
  309. func (*project) GetFullProjectList(ctx context.Context, enterpriseID string, pageSize, pageNum int32, condition *common_model.ProjectCondition) (*http_model.FullProjectListData, error) {
  310. fullProjects, total, err := db.GetFullProjectList(ctx, enterpriseID, pageSize, pageNum, condition)
  311. if err != nil {
  312. logrus.WithContext(ctx).Errorf("[project service] call GetFullProjectList error,err:%+v", err)
  313. return nil, err
  314. }
  315. fullProjectListData := new(http_model.FullProjectListData)
  316. fullProjectListData.FullProjectPreview = pack.MGormFullProjectToHttpFullProjectPreview(fullProjects)
  317. fullProjectListData.Total = conv.MustString(total)
  318. return fullProjectListData, nil
  319. }
  320. func (*project) GetProjectDraftList(ctx context.Context, enterpriseID string, pageSize, pageNum int32, condition *common_model.ProjectCondition) (*http_model.ProjectDraftListData, error) {
  321. ProjectDrafts, total, err := db.GetProjectDraftList(ctx, enterpriseID, pageSize, pageNum, condition)
  322. if err != nil {
  323. logrus.WithContext(ctx).Errorf("[project service] call GetProjectDraftList error,err:%+v", err)
  324. return nil, err
  325. }
  326. ProjectDraftListData := new(http_model.ProjectDraftListData)
  327. ProjectDraftListData.ProjectDraftPreview = pack.MGormProjectDraftToHttpProjectDraftPreview(ProjectDrafts)
  328. ProjectDraftListData.Total = conv.MustString(total)
  329. return ProjectDraftListData, nil
  330. }
  331. func (*project) GetProjectTaskList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TaskConditions) (*http_model.ProjectTaskListData, error) {
  332. projectTasks, total, err := db.GetProjectTaskList(ctx, projectID, pageSize, pageNum, conditions)
  333. if err != nil {
  334. logrus.WithContext(ctx).Errorf("[project service] call GetProjectTaskList error,err:%+v", err)
  335. return nil, err
  336. }
  337. projectTaskListData := new(http_model.ProjectTaskListData)
  338. projectTaskListData.ProjectTaskPreview = pack.MGormProjectTaskToHttpProjectTaskPreview(projectTasks)
  339. projectTaskListData.Total = conv.MustString(total)
  340. return projectTaskListData, nil
  341. }
  342. func (*project) GetPorjectDetail(ctx context.Context, projectID string) (*http_model.ShowProjectData, error) {
  343. project, err := db.GetProjectDetail(ctx, projectID)
  344. if err != nil {
  345. logrus.WithContext(ctx).Errorf("[project service] call GetPorjectDetail error,err:%+v", err)
  346. return nil, err
  347. }
  348. enterprise, err := db.GetEnterpriseByEnterpriseID(ctx, project.EnterpriseID)
  349. if err != nil {
  350. logrus.WithContext(ctx).Errorf("[project service] call GetEnterpriseByEnterpriseID error,err:%+v", err)
  351. return nil, err
  352. }
  353. user, err := db.GetUserByID(ctx, enterprise.UserID)
  354. if err != nil {
  355. logrus.WithContext(ctx).Errorf("[project service] call GetUserByID error,err:%+v", err)
  356. return nil, err
  357. }
  358. ProjectDetail := http_model.ShowProjectData{
  359. ProjectID: conv.MustString(project.ProjectID),
  360. ProjectName: conv.MustString(project.ProjectName),
  361. ProjectStatus: conv.MustString(project.ProjectStatus),
  362. ProjectType: conv.MustString(project.ProjectType),
  363. ProjectPlatform: conv.MustString(project.ProjectPlatform),
  364. ProjectForm: conv.MustString(project.ProjectForm),
  365. TalentType: conv.MustString(project.TalentType),
  366. RecruitDdl: util.GetTimePoionter(project.RecruitDdl),
  367. ContentType: conv.MustString(project.ContentType),
  368. ProjectDetail: conv.MustString(project.ProjectDetail),
  369. ProductID: conv.MustString(project.ProductID),
  370. EnterpriseID: conv.MustString(project.EnterpriseID),
  371. Balance: conv.MustString(enterprise.Balance),
  372. AvailableBalance: conv.MustString(enterprise.AvailableBalance),
  373. EstimatedCost: conv.MustString(project.EstimatedCost),
  374. FailReason: conv.MustString(project.FailReason),
  375. CreateAt: util.GetTimePoionter(project.CreatedAt),
  376. UpdateAt: util.GetTimePoionter(project.UpdatedAt),
  377. Phone: user.Phone,
  378. FinishAt: util.GetTimePoionter(project.FinishAt),
  379. PassAt: util.GetTimePoionter(project.PassAt),
  380. SubmitAt: util.GetTimePoionter(project.SubmitAt),
  381. PayAt: util.GetTimePoionter(project.PayAt),
  382. ProductInfo: conv.MustString(project.ProductSnap),
  383. ProductPhotoInfo: conv.MustString(project.ProductPhotoSnap),
  384. AutoFailAt: util.GetTimePoionter(project.AutoFailAt),
  385. }
  386. Strategys, err := db.GetRecruitStrategys(ctx, projectID)
  387. //fmt.Println("招募策略:", Strategys)
  388. if err != nil {
  389. logrus.WithContext(ctx).Error()
  390. return nil, err
  391. }
  392. for _, strategy := range Strategys {
  393. RecruitStrategy := http_model.ShowRecruitStrategy{
  394. RecruitStrategyID: conv.MustString(strategy.RecruitStrategyID),
  395. FeeForm: conv.MustString(strategy.FeeForm),
  396. StrategyID: conv.MustString(strategy.StrategyID),
  397. FollowersLow: conv.MustString(strategy.FollowersLow),
  398. FollowersUp: conv.MustString(strategy.FollowersUp),
  399. RecruitNumber: conv.MustString(strategy.RecruitNumber),
  400. Offer: conv.MustString(strategy.Offer),
  401. ServiceCharge: conv.MustString(strategy.ServiceCharge),
  402. SelectedNumber: strategy.SelectedNumber,
  403. WaitingNumber: strategy.WaitingNumber,
  404. DeliveredNumber: strategy.DeliveredNumber,
  405. SignedNumber: strategy.SignedNumber,
  406. }
  407. ProjectDetail.RecruitStrategys = append(ProjectDetail.RecruitStrategys, RecruitStrategy)
  408. }
  409. Photos, err := db.GetProjectPhoto(ctx, projectID)
  410. if err != nil {
  411. logrus.WithContext(ctx).Error()
  412. return nil, err
  413. }
  414. for _, Photo := range Photos {
  415. ProjectPhoto := http_model.ShowProjectPhoto{
  416. PhotoUrl: Photo.PhotoUrl,
  417. PhotoUid: Photo.PhotoUid,
  418. }
  419. ProjectDetail.ProjectPhotos = append(ProjectDetail.ProjectPhotos, ProjectPhoto)
  420. }
  421. return &ProjectDetail, nil
  422. }
  423. func (*project) GetTaskLogisticsList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskLogisticsListData, error) {
  424. TaskLogisticss, total, err := db.GetTaskLogisticsList(ctx, projectID, pageSize, pageNum, conditions)
  425. if err != nil {
  426. logrus.WithContext(ctx).Errorf("[project service] call GetTaskLogisticsList error,err:%+v", err)
  427. return nil, err
  428. }
  429. TaskLogisticsListData := new(http_model.TaskLogisticsListData)
  430. TaskLogisticsListData.TaskLogisticsPreview = pack.MGormTaskLogisticsInfoListToHttpTaskLogisticsPreviewList(TaskLogisticss)
  431. TaskLogisticsListData.Total = conv.MustString(total)
  432. return TaskLogisticsListData, nil
  433. }
  434. func (*project) ChangeTaskStatus(ctx *gin.Context, data http_model.ProjectChangeTaskStatusRequest) interface{} {
  435. RecruitStrategyIDs, err := db.ChangeTaskStatus(ctx, data.TaskIds, data.TaskStatus)
  436. if err != nil {
  437. logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  438. return err
  439. }
  440. if data.TaskStatus == "2" {
  441. err = db.CalculateSelectedNumberByRecruitStrategyID(ctx, RecruitStrategyIDs, 1)
  442. if err != nil {
  443. logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  444. return err
  445. }
  446. } else {
  447. err = db.CalculateSelectedNumberByRecruitStrategyID(ctx, RecruitStrategyIDs, -1)
  448. if err != nil {
  449. logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  450. return err
  451. }
  452. }
  453. return nil
  454. }
  455. func (*project) ChangeSpecialTaskStatus(ctx *gin.Context, data http_model.ProjectChangeTaskStatusRequest) interface{} {
  456. err := db.ChangeSpecialTaskStatus(ctx, data.TaskIds, data.TaskStatus, data.TaskStage)
  457. if err != nil {
  458. logrus.WithContext(ctx).Errorf("[project service] call ChangeSpecialTaskStatus error,err:%+v", err)
  459. return err
  460. }
  461. for _, taskId := range data.TaskIds {
  462. err = db.CreateMessageByTaskId(ctx, 7, 2, taskId)
  463. if err != nil {
  464. logrus.WithContext(ctx).Errorf("[project service] call CreateMessageByTaskId error,err:%+v", err)
  465. return err
  466. }
  467. }
  468. return nil
  469. }
  470. func (p *project) GetTaskScriptList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskScriptListData, error) {
  471. TaskScripts, total, err := db.GetTaskScriptList(ctx, projectID, pageSize, pageNum, conditions)
  472. if err != nil {
  473. logrus.WithContext(ctx).Errorf("[project service] call GetTaskScriptList error,err:%+v", err)
  474. return nil, err
  475. }
  476. TaskScriptListData := new(http_model.TaskScriptListData)
  477. TaskScriptListData.TaskScriptPreview = pack.MGormTaskScriptInfoListToHttpTaskScriptPreviewList(TaskScripts)
  478. TaskScriptListData.Total = conv.MustString(total)
  479. return TaskScriptListData, nil
  480. }
  481. func (p *project) GetTaskSketchList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskSketchListData, error) {
  482. TaskSketchs, total, err := db.GetTaskSketchList(ctx, projectID, pageSize, pageNum, conditions)
  483. if err != nil {
  484. logrus.WithContext(ctx).Errorf("[project service] call GetTaskSketchList error,err:%+v", err)
  485. return nil, err
  486. }
  487. TaskSketchListData := new(http_model.TaskSketchListData)
  488. TaskSketchListData.TaskSketchPreview = pack.MGormTaskSketchInfoListToHttpTaskSketchPreviewList(TaskSketchs)
  489. TaskSketchListData.Total = conv.MustString(total)
  490. return TaskSketchListData, nil
  491. }
  492. func (p *project) GetTaskLinkList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskLinkListData, error) {
  493. TaskLinks, total, err := db.GetTaskLinkList(ctx, projectID, pageSize, pageNum, conditions)
  494. if err != nil {
  495. logrus.WithContext(ctx).Errorf("[project service] call GetTaskLinkList error,err:%+v", err)
  496. return nil, err
  497. }
  498. TaskLinkListData := new(http_model.TaskLinkListData)
  499. TaskLinkListData.TaskLinkPreview = pack.MGormTaskLinkInfoListToHttpTaskLinkPreviewList(TaskLinks)
  500. TaskLinkListData.Total = conv.MustString(total)
  501. return TaskLinkListData, nil
  502. }
  503. func (p *project) GetTaskDataList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskDataListData, error) {
  504. TaskDatas, total, err := db.GetTaskDataList(ctx, projectID, pageSize, pageNum, conditions)
  505. if err != nil {
  506. logrus.WithContext(ctx).Errorf("[project service] call GetTaskDataList error,err:%+v", err)
  507. return nil, err
  508. }
  509. TaskDataListData := new(http_model.TaskDataListData)
  510. TaskDataListData.TaskDataPreview = pack.MGormTaskDataInfoListToHttpTaskDataPreviewList(TaskDatas)
  511. TaskDataListData.Total = conv.MustString(total)
  512. return TaskDataListData, nil
  513. }
  514. func (p *project) GetTaskFinishList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskFinishListData, error) {
  515. TaskFinishs, total, err := db.GetTaskFinishList(ctx, pageSize, pageNum, conditions)
  516. if err != nil {
  517. logrus.WithContext(ctx).Errorf("[project service] call GetTaskFinishList error,err:%+v", err)
  518. return nil, err
  519. }
  520. TaskFinishListData := new(http_model.TaskFinishListData)
  521. TaskFinishListData.TaskFinishPreview = pack.MGormTaskFinishInfoListToHttpTaskFinishPreviewList(TaskFinishs)
  522. TaskFinishListData.Total = conv.MustString(total)
  523. return TaskFinishListData, nil
  524. }
  525. func (p *project) GetServiceCharge(ctx *gin.Context, data http_model.GetServiceChargeRequest) (*http_model.ServiceChargeData, error) {
  526. pricingStrategy, err := db.GetPricingStrategy(ctx, data.FollowersLow, data.FollowersUp, data.FeeForm, data.Platform)
  527. if err != nil {
  528. return nil, err
  529. }
  530. serviceFee := http_model.ServiceChargeData{
  531. ServiceCharge: pricingStrategy.ServiceCharge,
  532. }
  533. return &serviceFee, nil
  534. }