project.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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. project := gorm_model.ProjectInfo{
  206. ProjectID: newProject.ProjectID,
  207. RecruitDdl: &RecruitDdl,
  208. TalentType: newProject.TalentType,
  209. ContentType: conv.MustInt64(newProject.ContentType),
  210. ProjectDetail: newProject.ProjectDetail,
  211. ProjectForm: conv.MustInt64(newProject.ProjectForm),
  212. EnterpriseID: enterpriseID,
  213. ProjectStatus: conv.MustInt64(newProject.ProjectStatus),
  214. FeeForm: feeFroms,
  215. EstimatedCost: ECost,
  216. }
  217. projectID, err := db.UpdateProject(ctx, project)
  218. if err != nil {
  219. return nil, err
  220. }
  221. // 删除该项目之前的所有图片
  222. err = db.DeleteProjectPhotoByProjecttID(ctx, *projectID)
  223. if err != nil {
  224. return nil, err
  225. }
  226. //fmt.Printf("照片:\t %+v", newProject.ProjectPhotos)
  227. if len(newProject.ProjectPhotos) != 0 {
  228. // 新增图片
  229. projectPhotos := []gorm_model.ProjectPhoto{}
  230. for _, photo := range newProject.ProjectPhotos {
  231. projectPhoto := gorm_model.ProjectPhoto{
  232. ProjectID: project.ProjectID,
  233. PhotoUrl: photo.PhotoUrl,
  234. PhotoUid: photo.PhotoUid,
  235. }
  236. projectPhotos = append(projectPhotos, projectPhoto)
  237. }
  238. err = db.CreateProjectPhoto(ctx, projectPhotos)
  239. if err != nil {
  240. return nil, err
  241. }
  242. }
  243. // 删除该项目之前的所有策略
  244. err = db.DeleteRecruitStrategyByProjectID(ctx, *projectID)
  245. if err != nil {
  246. return nil, err
  247. }
  248. fmt.Printf("策略:\t %+v", newProject.RecruitStrategys)
  249. if newProject.RecruitStrategys != nil && newProject.ProjectType == int64(1) {
  250. // 新增策略
  251. RecruitStrategys := []gorm_model.RecruitStrategy{}
  252. for _, Strategy := range newProject.RecruitStrategys {
  253. // 查询对应定价策略
  254. pricingStrategy, err := db.GetPricingStrategy(ctx, Strategy.FollowersLow, Strategy.FollowersUp, Strategy.FeeForm, oldProject.ProjectPlatform)
  255. if err != nil {
  256. return nil, err
  257. }
  258. // 根据定价策略计算达人所见报价
  259. if Strategy.FeeForm == 2 {
  260. Strategy.TOffer = Strategy.Offer * (1 - conv.MustFloat64(pricingStrategy.ServiceRate)/1000)
  261. }
  262. RecruitStrategy := gorm_model.RecruitStrategy{
  263. FeeForm: conv.MustInt64(Strategy.FeeForm),
  264. StrategyID: conv.MustInt64(Strategy.StrategyID),
  265. FollowersLow: conv.MustInt64(Strategy.FollowersLow),
  266. FollowersUp: conv.MustInt64(Strategy.FollowersUp),
  267. RecruitNumber: conv.MustInt64(Strategy.RecruitNumber),
  268. ServiceCharge: Strategy.ServiceCharge,
  269. Offer: Strategy.Offer,
  270. TOffer: Strategy.TOffer,
  271. ProjectID: project.ProjectID,
  272. }
  273. //fmt.Printf("Offer:\t %+v", Strategy.Offer)
  274. RecruitStrategys = append(RecruitStrategys, RecruitStrategy)
  275. }
  276. err = db.CreateRecruitStrategy(ctx, RecruitStrategys)
  277. if err != nil {
  278. return nil, err
  279. }
  280. }
  281. res := &http_model.UpdateProjectData{
  282. ProjectID: *projectID,
  283. }
  284. return res, nil
  285. }
  286. func (*project) Delete(ctx context.Context, projectID string) (*http_model.DeleteProjectData, error) {
  287. // 删除该项目之前的所有图片
  288. err := db.DeleteProjectPhotoByProjecttID(ctx, projectID)
  289. if err != nil {
  290. return nil, err
  291. }
  292. // 删除该项目之前的所有策略
  293. err = db.DeleteRecruitStrategyByProjectID(ctx, projectID)
  294. if err != nil {
  295. return nil, err
  296. }
  297. //删除项目
  298. NewProjectID, err1 := db.DeleteProject(ctx, projectID)
  299. if err1 != nil {
  300. return nil, err1
  301. }
  302. res := &http_model.DeleteProjectData{
  303. ProjectID: *NewProjectID,
  304. }
  305. return res, nil
  306. }
  307. func (*project) GetFullProjectList(ctx context.Context, enterpriseID string, pageSize, pageNum int32, condition *common_model.ProjectCondition) (*http_model.FullProjectListData, error) {
  308. fullProjects, total, err := db.GetFullProjectList(ctx, enterpriseID, pageSize, pageNum, condition)
  309. if err != nil {
  310. logrus.WithContext(ctx).Errorf("[project service] call GetFullProjectList error,err:%+v", err)
  311. return nil, err
  312. }
  313. fullProjectListData := new(http_model.FullProjectListData)
  314. fullProjectListData.FullProjectPreview = pack.MGormFullProjectToHttpFullProjectPreview(fullProjects)
  315. fullProjectListData.Total = conv.MustString(total)
  316. return fullProjectListData, nil
  317. }
  318. func (*project) GetProjectDraftList(ctx context.Context, enterpriseID string, pageSize, pageNum int32, condition *common_model.ProjectCondition) (*http_model.ProjectDraftListData, error) {
  319. ProjectDrafts, total, err := db.GetProjectDraftList(ctx, enterpriseID, pageSize, pageNum, condition)
  320. if err != nil {
  321. logrus.WithContext(ctx).Errorf("[project service] call GetProjectDraftList error,err:%+v", err)
  322. return nil, err
  323. }
  324. ProjectDraftListData := new(http_model.ProjectDraftListData)
  325. ProjectDraftListData.ProjectDraftPreview = pack.MGormProjectDraftToHttpProjectDraftPreview(ProjectDrafts)
  326. ProjectDraftListData.Total = conv.MustString(total)
  327. return ProjectDraftListData, nil
  328. }
  329. func (*project) GetProjectTaskList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TaskConditions) (*http_model.ProjectTaskListData, error) {
  330. projectTasks, total, err := db.GetProjectTaskList(ctx, projectID, pageSize, pageNum, conditions)
  331. if err != nil {
  332. logrus.WithContext(ctx).Errorf("[project service] call GetProjectTaskList error,err:%+v", err)
  333. return nil, err
  334. }
  335. projectTaskListData := new(http_model.ProjectTaskListData)
  336. projectTaskListData.ProjectTaskPreview = pack.MGormProjectTaskToHttpProjectTaskPreview(projectTasks)
  337. projectTaskListData.Total = conv.MustString(total)
  338. return projectTaskListData, nil
  339. }
  340. func (*project) GetPorjectDetail(ctx context.Context, projectID string) (*http_model.ShowProjectData, error) {
  341. project, err := db.GetProjectDetail(ctx, projectID)
  342. if err != nil {
  343. logrus.WithContext(ctx).Errorf("[project service] call GetPorjectDetail error,err:%+v", err)
  344. return nil, err
  345. }
  346. enterprise, err := db.GetEnterpriseByEnterpriseID(ctx, project.EnterpriseID)
  347. if err != nil {
  348. logrus.WithContext(ctx).Errorf("[project service] call GetEnterpriseByEnterpriseID error,err:%+v", err)
  349. return nil, err
  350. }
  351. user, err := db.GetUserByID(ctx, enterprise.UserID)
  352. if err != nil {
  353. logrus.WithContext(ctx).Errorf("[project service] call GetUserByID error,err:%+v", err)
  354. return nil, err
  355. }
  356. ProjectDetail := http_model.ShowProjectData{
  357. ProjectID: conv.MustString(project.ProjectID),
  358. ProjectName: conv.MustString(project.ProjectName),
  359. ProjectStatus: conv.MustString(project.ProjectStatus),
  360. ProjectType: conv.MustString(project.ProjectType),
  361. ProjectPlatform: conv.MustString(project.ProjectPlatform),
  362. ProjectForm: conv.MustString(project.ProjectForm),
  363. TalentType: conv.MustString(project.TalentType),
  364. RecruitDdl: util.GetTimePoionter(project.RecruitDdl),
  365. ContentType: conv.MustString(project.ContentType),
  366. ProjectDetail: conv.MustString(project.ProjectDetail),
  367. ProductID: conv.MustString(project.ProductID),
  368. EnterpriseID: conv.MustString(project.EnterpriseID),
  369. Balance: conv.MustString(enterprise.Balance),
  370. EstimatedCost: conv.MustString(project.EstimatedCost),
  371. FailReason: conv.MustString(project.FailReason),
  372. CreateAt: util.GetTimePoionter(project.CreatedAt),
  373. UpdateAt: util.GetTimePoionter(project.UpdatedAt),
  374. Phone: user.Phone,
  375. FinishAt: util.GetTimePoionter(project.FinishAt),
  376. PassAt: util.GetTimePoionter(project.PassAt),
  377. PayAt: util.GetTimePoionter(project.PayAt),
  378. ProductInfo: conv.MustString(project.ProductSnap),
  379. ProductPhotoInfo: conv.MustString(project.ProductPhotoSnap),
  380. AutoFailAt: util.GetTimePoionter(project.AutoFailAt),
  381. }
  382. Strategys, err := db.GetRecruitStrategys(ctx, projectID)
  383. //fmt.Println("招募策略:", Strategys)
  384. if err != nil {
  385. logrus.WithContext(ctx).Error()
  386. return nil, err
  387. }
  388. for _, strategy := range Strategys {
  389. RecruitStrategy := http_model.ShowRecruitStrategy{
  390. RecruitStrategyID: conv.MustString(strategy.RecruitStrategyID),
  391. FeeForm: conv.MustString(strategy.FeeForm),
  392. StrategyID: conv.MustString(strategy.StrategyID),
  393. FollowersLow: conv.MustString(strategy.FollowersLow),
  394. FollowersUp: conv.MustString(strategy.FollowersUp),
  395. RecruitNumber: conv.MustString(strategy.RecruitNumber),
  396. Offer: conv.MustString(strategy.Offer),
  397. ServiceCharge: conv.MustString(strategy.ServiceCharge),
  398. SelectedNumber: strategy.SelectedNumber,
  399. WaitingNumber: strategy.WaitingNumber,
  400. DeliveredNumber: strategy.DeliveredNumber,
  401. SignedNumber: strategy.SignedNumber,
  402. }
  403. ProjectDetail.RecruitStrategys = append(ProjectDetail.RecruitStrategys, RecruitStrategy)
  404. }
  405. Photos, err := db.GetProjectPhoto(ctx, projectID)
  406. if err != nil {
  407. logrus.WithContext(ctx).Error()
  408. return nil, err
  409. }
  410. for _, Photo := range Photos {
  411. ProjectPhoto := http_model.ShowProjectPhoto{
  412. PhotoUrl: Photo.PhotoUrl,
  413. PhotoUid: Photo.PhotoUid,
  414. }
  415. ProjectDetail.ProjectPhotos = append(ProjectDetail.ProjectPhotos, ProjectPhoto)
  416. }
  417. return &ProjectDetail, nil
  418. }
  419. func (*project) GetTaskLogisticsList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskLogisticsListData, error) {
  420. TaskLogisticss, total, err := db.GetTaskLogisticsList(ctx, projectID, pageSize, pageNum, conditions)
  421. if err != nil {
  422. logrus.WithContext(ctx).Errorf("[project service] call GetTaskLogisticsList error,err:%+v", err)
  423. return nil, err
  424. }
  425. TaskLogisticsListData := new(http_model.TaskLogisticsListData)
  426. TaskLogisticsListData.TaskLogisticsPreview = pack.MGormTaskLogisticsInfoListToHttpTaskLogisticsPreviewList(TaskLogisticss)
  427. TaskLogisticsListData.Total = conv.MustString(total)
  428. return TaskLogisticsListData, nil
  429. }
  430. func (*project) ChangeTaskStatus(ctx *gin.Context, data http_model.ProjectChangeTaskStatusRequest) interface{} {
  431. RecruitStrategyIDs, err := db.ChangeTaskStatus(ctx, data.TaskIds, data.TaskStatus)
  432. if err != nil {
  433. logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  434. return err
  435. }
  436. if data.TaskStatus == "2" {
  437. err = db.CalculateSelectedNumberByRecruitStrategyID(ctx, RecruitStrategyIDs, 1)
  438. if err != nil {
  439. logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  440. return err
  441. }
  442. } else {
  443. err = db.CalculateSelectedNumberByRecruitStrategyID(ctx, RecruitStrategyIDs, -1)
  444. if err != nil {
  445. logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  446. return err
  447. }
  448. }
  449. return nil
  450. }
  451. func (*project) ChangeSpecialTaskStatus(ctx *gin.Context, data http_model.ProjectChangeTaskStatusRequest) interface{} {
  452. err := db.ChangeSpecialTaskStatus(ctx, data.TaskIds, data.TaskStatus, data.TaskStage)
  453. if err != nil {
  454. logrus.WithContext(ctx).Errorf("[project service] call ChangeSpecialTaskStatus error,err:%+v", err)
  455. return err
  456. }
  457. return nil
  458. }
  459. func (p *project) GetTaskScriptList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskScriptListData, error) {
  460. TaskScripts, total, err := db.GetTaskScriptList(ctx, projectID, pageSize, pageNum, conditions)
  461. if err != nil {
  462. logrus.WithContext(ctx).Errorf("[project service] call GetTaskScriptList error,err:%+v", err)
  463. return nil, err
  464. }
  465. TaskScriptListData := new(http_model.TaskScriptListData)
  466. TaskScriptListData.TaskScriptPreview = pack.MGormTaskScriptInfoListToHttpTaskScriptPreviewList(TaskScripts)
  467. TaskScriptListData.Total = conv.MustString(total)
  468. return TaskScriptListData, nil
  469. }
  470. func (p *project) GetTaskSketchList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskSketchListData, error) {
  471. TaskSketchs, total, err := db.GetTaskSketchList(ctx, projectID, pageSize, pageNum, conditions)
  472. if err != nil {
  473. logrus.WithContext(ctx).Errorf("[project service] call GetTaskSketchList error,err:%+v", err)
  474. return nil, err
  475. }
  476. TaskSketchListData := new(http_model.TaskSketchListData)
  477. TaskSketchListData.TaskSketchPreview = pack.MGormTaskSketchInfoListToHttpTaskSketchPreviewList(TaskSketchs)
  478. TaskSketchListData.Total = conv.MustString(total)
  479. return TaskSketchListData, nil
  480. }
  481. func (p *project) GetTaskLinkList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskLinkListData, error) {
  482. TaskLinks, total, err := db.GetTaskLinkList(ctx, projectID, pageSize, pageNum, conditions)
  483. if err != nil {
  484. logrus.WithContext(ctx).Errorf("[project service] call GetTaskLinkList error,err:%+v", err)
  485. return nil, err
  486. }
  487. TaskLinkListData := new(http_model.TaskLinkListData)
  488. TaskLinkListData.TaskLinkPreview = pack.MGormTaskLinkInfoListToHttpTaskLinkPreviewList(TaskLinks)
  489. TaskLinkListData.Total = conv.MustString(total)
  490. return TaskLinkListData, nil
  491. }
  492. func (p *project) GetTaskDataList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskDataListData, error) {
  493. TaskDatas, total, err := db.GetTaskDataList(ctx, projectID, pageSize, pageNum, conditions)
  494. if err != nil {
  495. logrus.WithContext(ctx).Errorf("[project service] call GetTaskDataList error,err:%+v", err)
  496. return nil, err
  497. }
  498. TaskDataListData := new(http_model.TaskDataListData)
  499. TaskDataListData.TaskDataPreview = pack.MGormTaskDataInfoListToHttpTaskDataPreviewList(TaskDatas)
  500. TaskDataListData.Total = conv.MustString(total)
  501. return TaskDataListData, nil
  502. }
  503. func (p *project) GetTaskFinishList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskFinishListData, error) {
  504. TaskFinishs, total, err := db.GetTaskFinishList(ctx, pageSize, pageNum, conditions)
  505. if err != nil {
  506. logrus.WithContext(ctx).Errorf("[project service] call GetTaskFinishList error,err:%+v", err)
  507. return nil, err
  508. }
  509. TaskFinishListData := new(http_model.TaskFinishListData)
  510. TaskFinishListData.TaskFinishPreview = pack.MGormTaskFinishInfoListToHttpTaskFinishPreviewList(TaskFinishs)
  511. TaskFinishListData.Total = conv.MustString(total)
  512. return TaskFinishListData, nil
  513. }
  514. func (p *project) GetServiceCharge(ctx *gin.Context, data http_model.GetServiceChargeRequest) (*http_model.ServiceChargeData, error) {
  515. pricingStrategy, err := db.GetPricingStrategy(ctx, data.FollowersLow, data.FollowersUp, data.FeeForm, data.Platform)
  516. if err != nil {
  517. return nil, err
  518. }
  519. serviceFee := http_model.ServiceChargeData{
  520. ServiceCharge: pricingStrategy.ServiceCharge,
  521. }
  522. return &serviceFee, nil
  523. }