project.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  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. FileName: photo.FileName,
  284. }
  285. projectPhotos = append(projectPhotos, projectPhoto)
  286. }
  287. err = db.CreateProjectPhoto(ctx, projectPhotos)
  288. if err != nil {
  289. return nil, err
  290. }
  291. }
  292. // 删除该项目之前的所有策略
  293. err = db.DeleteRecruitStrategyByProjectID(ctx, *projectID)
  294. if err != nil {
  295. return nil, err
  296. }
  297. fmt.Printf("策略:\t %+v,%+v", newProject.RecruitStrategys, len(newProject.RecruitStrategys) == 0)
  298. if len(newProject.RecruitStrategys) != 0 && newProject.ProjectType == int64(1) {
  299. // 新增策略
  300. RecruitStrategys := []gorm_model.RecruitStrategy{}
  301. for _, Strategy := range newProject.RecruitStrategys {
  302. // 查询对应定价策略
  303. pricingStrategy, err := db.GetPricingStrategy(ctx, Strategy.FollowersLow, Strategy.FollowersUp, Strategy.FeeForm, oldProject.ProjectPlatform)
  304. if err != nil {
  305. return nil, err
  306. }
  307. // 根据定价策略计算达人所见报价
  308. if Strategy.FeeForm == 2 {
  309. Strategy.TOffer = Strategy.Offer * (1 - conv.MustFloat64(pricingStrategy.ServiceRate)/1000)
  310. }
  311. RecruitStrategy := gorm_model.RecruitStrategy{
  312. FeeForm: conv.MustInt64(Strategy.FeeForm),
  313. StrategyID: conv.MustInt64(Strategy.StrategyID),
  314. FollowersLow: conv.MustInt64(Strategy.FollowersLow),
  315. FollowersUp: conv.MustInt64(Strategy.FollowersUp),
  316. RecruitNumber: conv.MustInt64(Strategy.RecruitNumber),
  317. ServiceCharge: Strategy.ServiceCharge,
  318. Offer: Strategy.Offer,
  319. TOffer: Strategy.TOffer,
  320. ProjectID: project.ProjectID,
  321. }
  322. //fmt.Printf("Offer:\t %+v", Strategy.Offer)
  323. RecruitStrategys = append(RecruitStrategys, RecruitStrategy)
  324. }
  325. err = db.CreateRecruitStrategy(ctx, RecruitStrategys)
  326. if err != nil {
  327. return nil, err
  328. }
  329. }
  330. res := &http_model.UpdateProjectData{
  331. ProjectID: *projectID,
  332. }
  333. return res, nil
  334. }
  335. func (*project) Delete(ctx context.Context, projectID string) (*http_model.DeleteProjectData, error) {
  336. // 删除该项目之前的所有图片
  337. err := db.DeleteProjectPhotoByProjecttID(ctx, projectID)
  338. if err != nil {
  339. return nil, err
  340. }
  341. // 删除该项目之前的所有策略
  342. err = db.DeleteRecruitStrategyByProjectID(ctx, projectID)
  343. if err != nil {
  344. return nil, err
  345. }
  346. //删除项目
  347. NewProjectID, err1 := db.DeleteProject(ctx, projectID)
  348. if err1 != nil {
  349. return nil, err1
  350. }
  351. res := &http_model.DeleteProjectData{
  352. ProjectID: *NewProjectID,
  353. }
  354. return res, nil
  355. }
  356. func (*project) GetFullProjectList(ctx context.Context, pageSize, pageNum int32, supplierId int, condition *common_model.ProjectCondition) (*http_model.FullProjectListData, error) {
  357. // 1. 查询种草任务基本信息
  358. fullProjects, total, err := db.GetFullProjectList(ctx, pageSize, pageNum, condition)
  359. if err != nil {
  360. logrus.WithContext(ctx).Errorf("[project service] call GetFullProjectList error,err:%+v", err)
  361. return nil, err
  362. }
  363. fullProjectListData := new(http_model.FullProjectListData)
  364. fullProjectListData.FullProjectPreview = pack.MGormFullProjectToHttpFullProjectPreview(fullProjects)
  365. fullProjectListData.Total = conv.MustString(total)
  366. // 2. 查询种草任务补充信息:商品信息,招募策略
  367. for _, project := range fullProjectListData.FullProjectPreview {
  368. // 2.1. 商品信息
  369. productInfo, productErr := db.GetProductByID(ctx, project.ProductId)
  370. if productErr != nil {
  371. return nil, productErr
  372. }
  373. if productInfo != nil {
  374. project.ProductId = productInfo.ProductID
  375. project.ProductPrice = productInfo.ProductPrice
  376. project.ProductName = productInfo.ProductName
  377. }
  378. // 2.2. 商品图片信息
  379. productPhotoInfo, productPhotoErr := db.GetProductPhotoByProductID(ctx, project.ProductId)
  380. if productPhotoErr != nil {
  381. return nil, productPhotoErr
  382. }
  383. if productPhotoInfo != nil {
  384. for _, photo := range productPhotoInfo {
  385. fmt.Println(photo)
  386. if photo.Symbol == 1 {
  387. project.ProductPhotoSymbol = 1
  388. project.ProductPhotoUrl = photo.PhotoUrl
  389. project.ProductPhotoUid = photo.PhotoUid
  390. }
  391. }
  392. }
  393. // 2.3. 招募策略信息
  394. recruitStrategyInfo, recruitErr := db.GetRecruitStrategyByProjectId(ctx, project.ProjectId)
  395. if recruitErr != nil {
  396. return nil, recruitErr
  397. }
  398. if recruitStrategyInfo != nil {
  399. for _, strategy := range recruitStrategyInfo {
  400. var recruitStrategy *http_model.EasyRecruitStrategy
  401. recruitStrategy = &http_model.EasyRecruitStrategy{}
  402. recruitStrategy.StrategyId = strategy.StrategyID
  403. recruitStrategy.FeeForm = strategy.FeeForm
  404. recruitStrategy.RecruitNumber = strategy.RecruitNumber
  405. project.RecruitStrategy = append(project.RecruitStrategy, recruitStrategy)
  406. }
  407. }
  408. // 2.4. 判断是否加入商单
  409. sProjectCount, sProjectErr := db.UpdateSProjectByProjectIdAndSupplierId(ctx, project.ProjectId, supplierId)
  410. if sProjectErr != nil {
  411. return nil, sProjectErr
  412. }
  413. if sProjectCount > 0 {
  414. project.AddToListStatus = 1
  415. } else {
  416. project.AddToListStatus = 2
  417. }
  418. }
  419. return fullProjectListData, nil
  420. }
  421. func (*project) GetProjectDraftList(ctx context.Context, enterpriseID string, pageSize, pageNum int32, condition *common_model.ProjectCondition) (*http_model.ProjectDraftListData, error) {
  422. ProjectDrafts, total, err := db.GetProjectDraftList(ctx, enterpriseID, pageSize, pageNum, condition)
  423. if err != nil {
  424. logrus.WithContext(ctx).Errorf("[project service] call GetProjectDraftList error,err:%+v", err)
  425. return nil, err
  426. }
  427. ProjectDraftListData := new(http_model.ProjectDraftListData)
  428. ProjectDraftListData.ProjectDraftPreview = pack.MGormProjectDraftToHttpProjectDraftPreview(ProjectDrafts)
  429. ProjectDraftListData.Total = conv.MustString(total)
  430. return ProjectDraftListData, nil
  431. }
  432. func (*project) GetProjectTaskList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TaskConditions) (*http_model.ProjectTaskListData, error) {
  433. projectTasks, total, err := db.GetProjectTaskList(ctx, projectID, pageSize, pageNum, conditions)
  434. if err != nil {
  435. logrus.WithContext(ctx).Errorf("[project service] call GetProjectTaskList error,err:%+v", err)
  436. return nil, err
  437. }
  438. projectTaskListData := new(http_model.ProjectTaskListData)
  439. projectTaskListData.ProjectTaskPreview = pack.MGormProjectTaskToHttpProjectTaskPreview(projectTasks)
  440. projectTaskListData.Total = conv.MustString(total)
  441. return projectTaskListData, nil
  442. }
  443. func (*project) GetPorjectDetail(ctx context.Context, projectID string) (*http_model.ShowProjectData, error) {
  444. project, err := db.GetProjectDetail(ctx, projectID)
  445. if err != nil {
  446. logrus.WithContext(ctx).Errorf("[project service] call GetPorjectDetail error,err:%+v", err)
  447. return nil, err
  448. }
  449. enterprise, err := db.GetEnterpriseByEnterpriseID(ctx, project.EnterpriseID)
  450. if err != nil {
  451. logrus.WithContext(ctx).Errorf("[project service] call GetEnterpriseByEnterpriseID error,err:%+v", err)
  452. return nil, err
  453. }
  454. user, err := db.GetUserByID(ctx, enterprise.UserID)
  455. if err != nil {
  456. logrus.WithContext(ctx).Errorf("[project service] call GetUserByID error,err:%+v", err)
  457. return nil, err
  458. }
  459. ProjectDetail := http_model.ShowProjectData{
  460. ProjectID: conv.MustString(project.ProjectID),
  461. ProjectName: conv.MustString(project.ProjectName),
  462. ProjectStatus: conv.MustString(project.ProjectStatus),
  463. ProjectType: conv.MustString(project.ProjectType),
  464. ProjectPlatform: conv.MustString(project.ProjectPlatform),
  465. ProjectForm: conv.MustString(project.ProjectForm),
  466. TalentType: conv.MustString(project.TalentType),
  467. RecruitDdl: util.GetTimePoionter(project.RecruitDdl),
  468. ContentType: conv.MustString(project.ContentType),
  469. ProjectDetail: conv.MustString(project.ProjectDetail),
  470. ProductID: conv.MustString(project.ProductID),
  471. EnterpriseID: conv.MustString(project.EnterpriseID),
  472. Balance: conv.MustString(enterprise.Balance),
  473. AvailableBalance: conv.MustString(enterprise.AvailableBalance),
  474. EstimatedCost: conv.MustString(project.EstimatedCost),
  475. FailReason: conv.MustString(project.FailReason),
  476. CreateAt: util.GetTimePoionter(project.CreatedAt),
  477. UpdateAt: util.GetTimePoionter(project.UpdatedAt),
  478. Phone: user.Phone,
  479. FinishAt: util.GetTimePoionter(project.FinishAt),
  480. PassAt: util.GetTimePoionter(project.PassAt),
  481. SubmitAt: util.GetTimePoionter(project.SubmitAt),
  482. PayAt: util.GetTimePoionter(project.PayAt),
  483. ProductInfo: conv.MustString(project.ProductSnap),
  484. ProductPhotoInfo: conv.MustString(project.ProductPhotoSnap),
  485. AutoFailAt: util.GetTimePoionter(project.AutoFailAt),
  486. }
  487. Strategys, err := db.GetRecruitStrategys(ctx, projectID)
  488. if err != nil {
  489. logrus.WithContext(ctx).Error()
  490. return nil, err
  491. }
  492. for _, strategy := range Strategys {
  493. RecruitStrategy := http_model.ShowRecruitStrategy{
  494. RecruitStrategyID: conv.MustString(strategy.RecruitStrategyID),
  495. FeeForm: conv.MustString(strategy.FeeForm),
  496. StrategyID: conv.MustString(strategy.StrategyID),
  497. FollowersLow: conv.MustString(strategy.FollowersLow),
  498. FollowersUp: conv.MustString(strategy.FollowersUp),
  499. RecruitNumber: conv.MustString(strategy.RecruitNumber),
  500. Offer: conv.MustString(strategy.Offer),
  501. ServiceCharge: conv.MustString(strategy.ServiceCharge),
  502. SelectedNumber: strategy.SelectedNumber,
  503. WaitingNumber: strategy.WaitingNumber,
  504. DeliveredNumber: strategy.DeliveredNumber,
  505. SignedNumber: strategy.SignedNumber,
  506. }
  507. ProjectDetail.RecruitStrategys = append(ProjectDetail.RecruitStrategys, RecruitStrategy)
  508. }
  509. Photos, err := db.GetProjectPhoto(ctx, projectID)
  510. if err != nil {
  511. logrus.WithContext(ctx).Error()
  512. return nil, err
  513. }
  514. for _, Photo := range Photos {
  515. ProjectPhoto := http_model.ShowProjectPhoto{
  516. PhotoUrl: Photo.PhotoUrl,
  517. PhotoUid: Photo.PhotoUid,
  518. FileName: Photo.FileName,
  519. }
  520. ProjectDetail.ProjectPhotos = append(ProjectDetail.ProjectPhotos, ProjectPhoto)
  521. }
  522. return &ProjectDetail, nil
  523. }
  524. func (*project) GetTaskLogisticsList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskLogisticsListData, error) {
  525. TaskLogisticss, total, err := db.GetTaskLogisticsList(ctx, projectID, pageSize, pageNum, conditions)
  526. if err != nil {
  527. logrus.WithContext(ctx).Errorf("[project service] call GetTaskLogisticsList error,err:%+v", err)
  528. return nil, err
  529. }
  530. TaskLogisticsListData := new(http_model.TaskLogisticsListData)
  531. TaskLogisticsListData.TaskLogisticsPreview = pack.MGormTaskLogisticsInfoListToHttpTaskLogisticsPreviewList(TaskLogisticss)
  532. TaskLogisticsListData.Total = conv.MustString(total)
  533. return TaskLogisticsListData, nil
  534. }
  535. // ChangeTaskStatus 提报达人或拒绝提报达人
  536. func (*project) ChangeTaskStatus(ctx *gin.Context, data http_model.ProjectChangeTaskStatusRequest) interface{} {
  537. RecruitStrategyIDs, err := db.ChangeTaskStatus(ctx, data.TaskIds, data.SupplierStatus)
  538. if err != nil {
  539. logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  540. return err
  541. }
  542. fmt.Println(RecruitStrategyIDs)
  543. // 已选数量
  544. //if data.SupplierStatus == 2 {
  545. // for _, RecruitStrategyID := range RecruitStrategyIDs {
  546. // err = db.CalculateSelectedNumberByRecruitStrategyID(ctx, RecruitStrategyID, 0)
  547. // if err != nil {
  548. // logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  549. // return err
  550. // }
  551. // }
  552. //} else if data.SupplierStatus == 3 {
  553. // for _, RecruitStrategyID := range RecruitStrategyIDs {
  554. // err = db.CalculateSelectedNumberByRecruitStrategyID(ctx, RecruitStrategyID, 0)
  555. // if err != nil {
  556. // logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  557. // return err
  558. // }
  559. // }
  560. //}
  561. return nil
  562. }
  563. // ChangeSpecialTaskStatus 定向种草任务 提报达人,拒绝提报
  564. func (*project) ChangeSpecialTaskStatus(ctx *gin.Context, data http_model.ProjectChangeTaskStatusRequest) interface{} {
  565. err := db.ChangeSpecialTaskStatus(ctx, data.TaskIds, data.SupplierStatus)
  566. if err != nil {
  567. logrus.WithContext(ctx).Errorf("[project service] call ChangeSpecialTaskStatus error,err:%+v", err)
  568. return err
  569. }
  570. return nil
  571. }
  572. func (p *project) GetTaskScriptList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskScriptListData, error) {
  573. TaskScripts, total, err := db.GetTaskScriptList(ctx, projectID, pageSize, pageNum, conditions)
  574. if err != nil {
  575. logrus.WithContext(ctx).Errorf("[project service] call GetTaskScriptList error,err:%+v", err)
  576. return nil, err
  577. }
  578. TaskScriptListData := new(http_model.TaskScriptListData)
  579. TaskScriptListData.TaskScriptPreview = pack.MGormTaskScriptInfoListToHttpTaskScriptPreviewList(TaskScripts)
  580. TaskScriptListData.Total = conv.MustString(total)
  581. return TaskScriptListData, nil
  582. }
  583. func (p *project) GetTaskSketchList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskSketchListData, error) {
  584. TaskSketchs, total, err := db.GetTaskSketchList(ctx, projectID, pageSize, pageNum, conditions)
  585. if err != nil {
  586. logrus.WithContext(ctx).Errorf("[project service] call GetTaskSketchList error,err:%+v", err)
  587. return nil, err
  588. }
  589. TaskSketchListData := new(http_model.TaskSketchListData)
  590. TaskSketchListData.TaskSketchPreview = pack.MGormTaskSketchInfoListToHttpTaskSketchPreviewList(TaskSketchs)
  591. TaskSketchListData.Total = conv.MustString(total)
  592. return TaskSketchListData, nil
  593. }
  594. func (p *project) GetTaskLinkList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskLinkListData, error) {
  595. TaskLinks, total, err := db.GetTaskLinkList(ctx, projectID, pageSize, pageNum, conditions)
  596. if err != nil {
  597. logrus.WithContext(ctx).Errorf("[project service] call GetTaskLinkList error,err:%+v", err)
  598. return nil, err
  599. }
  600. TaskLinkListData := new(http_model.TaskLinkListData)
  601. TaskLinkListData.TaskLinkPreview = pack.MGormTaskLinkInfoListToHttpTaskLinkPreviewList(TaskLinks)
  602. TaskLinkListData.Total = conv.MustString(total)
  603. return TaskLinkListData, nil
  604. }
  605. func (p *project) GetTaskDataList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskDataListData, error) {
  606. TaskDatas, total, err := db.GetTaskDataList(ctx, projectID, pageSize, pageNum, conditions)
  607. if err != nil {
  608. logrus.WithContext(ctx).Errorf("[project service] call GetTaskDataList error,err:%+v", err)
  609. return nil, err
  610. }
  611. TaskDataListData := new(http_model.TaskDataListData)
  612. TaskDataListData.TaskDataPreview = pack.MGormTaskDataInfoListToHttpTaskDataPreviewList(TaskDatas)
  613. TaskDataListData.Total = conv.MustString(total)
  614. return TaskDataListData, nil
  615. }
  616. func (p *project) GetTaskFinishList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskFinishListData, error) {
  617. TaskFinishs, total, err := db.GetTaskFinishList(ctx, pageSize, pageNum, conditions)
  618. if err != nil {
  619. logrus.WithContext(ctx).Errorf("[project service] call GetTaskFinishList error,err:%+v", err)
  620. return nil, err
  621. }
  622. TaskFinishListData := new(http_model.TaskFinishListData)
  623. TaskFinishListData.TaskFinishPreview = pack.MGormTaskFinishInfoListToHttpTaskFinishPreviewList(TaskFinishs)
  624. TaskFinishListData.Total = conv.MustString(total)
  625. return TaskFinishListData, nil
  626. }
  627. func (p *project) GetServiceCharge(ctx *gin.Context, data http_model.GetServiceChargeRequest) (*http_model.ServiceChargeData, error) {
  628. pricingStrategy, err := db.GetPricingStrategy(ctx, data.FollowersLow, data.FollowersUp, data.FeeForm, data.Platform)
  629. if err != nil {
  630. return nil, err
  631. }
  632. serviceFee := http_model.ServiceChargeData{
  633. ServiceCharge: pricingStrategy.ServiceCharge,
  634. }
  635. return &serviceFee, nil
  636. }
  637. func (*project) GetSpecialProjectTaskList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.SpecialTaskLogisticsListData, error) {
  638. SpecialTaskLogisticsListDatas, total, err := db.GetSpecialTaskLogisticsList(ctx, projectID, pageSize, pageNum, conditions)
  639. if err != nil {
  640. logrus.WithContext(ctx).Errorf("[project service] call GetSpecialProjectTaskList error,err:%+v", err)
  641. return nil, err
  642. }
  643. TaskLogisticsListData := new(http_model.SpecialTaskLogisticsListData)
  644. TaskLogisticsListData.SpecialTaskLogisticsPreview = pack.MGormSpecialTaskLogisticsInfoListToHttpTaskLogisticsPreviewList(SpecialTaskLogisticsListDatas)
  645. TaskLogisticsListData.Total = conv.MustString(total, "")
  646. return TaskLogisticsListData, nil
  647. }
  648. // ShowTaskProgress ToDo
  649. // ShowTaskProgress 展示种草子任务进度
  650. func (p *project) ShowTaskProgress(ctx *gin.Context, data http_model.ShowTaskProgressRequest) (*http_model.ShowTaskProgressData, error) {
  651. // 1. 初始化返回数据结构体
  652. var taskProgressData *http_model.ShowTaskProgressData
  653. taskProgressData = &http_model.ShowTaskProgressData{}
  654. // 2. 根据task_id筛选出对应的子任务基础信息
  655. taskInfo, taskErr := db.GetTaskByTaskId(ctx, data.TaskId)
  656. if taskErr != nil {
  657. return nil, taskErr
  658. }
  659. if taskInfo != nil {
  660. taskProgressData.TaskId = data.TaskId
  661. taskProgressData.CreateData = taskInfo.CreateDate
  662. taskProgressData.SelectDate = taskInfo.SelectDate
  663. taskProgressData.DeliveryDate = taskInfo.DeliveryDate
  664. taskProgressData.SignedTime = taskInfo.SignedTime
  665. taskProgressData.ServiceCharge = taskInfo.ServiceCharge
  666. taskProgressData.DraftFee = taskInfo.DraftFee
  667. }
  668. // 3. 筛选出上传初稿时间和初稿状态
  669. taskSketchs, taskSketchErr := db.FindSketchInfoByTaskId(ctx, data.TaskId)
  670. if taskSketchErr != nil {
  671. return nil, taskSketchErr
  672. }
  673. if taskSketchs != nil {
  674. taskProgressData.SketchInfo = taskSketchs
  675. }
  676. // 4. 筛选作品链接上传时间和状态
  677. taskLinks, taskLinksErr := db.GetLinkByTaskId(ctx, data.TaskId)
  678. if taskLinksErr != nil {
  679. return nil, taskLinksErr
  680. }
  681. if taskLinks != nil {
  682. taskProgressData.LinkInfo = taskLinks
  683. }
  684. // 5. 若有违约,筛选出违约情况
  685. if taskInfo != nil {
  686. taskProgressData.TerminateTime = taskInfo.TerminateTime
  687. taskProgressData.TerminateReason = taskInfo.TerminateReason
  688. taskProgressData.CancelTime = taskInfo.CancelTime
  689. taskProgressData.CancelReason = taskInfo.CancelReason
  690. }
  691. return taskProgressData, nil
  692. }
  693. func (p *project) GetProjectStrategys(ctx *gin.Context, projectId string) ([]gorm_model.RecruitStrategy, error) {
  694. recruitStrategys, getProjectStrategysErr := db.GetRecruitStrategyByProjectId(ctx, projectId)
  695. if getProjectStrategysErr != nil {
  696. return nil, getProjectStrategysErr
  697. }
  698. return recruitStrategys, nil
  699. }