project.go 23 KB

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