project.go 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  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 = 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.FindSProjectByProjectIdAndSupplierId(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, pageSize, pageNum int64, orderBy []string, orderDesc []int, conditions *common_model.TaskConditions) (*http_model.ProjectTaskListData, error) {
  433. // 1. 根据SProject和condition查询所有Task
  434. projectTasks, total, err := db.GetProjectTaskList(ctx, pageSize, pageNum, orderBy, orderDesc, conditions)
  435. if err != nil {
  436. logrus.WithContext(ctx).Errorf("[project service] call GetProjectTaskList error,err:%+v", err)
  437. return nil, err
  438. }
  439. projectTaskListData := new(http_model.ProjectTaskListData)
  440. // fmt.Println(projectTasks)
  441. projectTaskListData.ProjectTaskPreview = pack.MGormProjectTaskToHttpProjectTaskPreview(projectTasks)
  442. // 2. 查找SProject中其他信息
  443. sProjectInfo, sProjectErr := db.GetSProjectDetail(ctx, conditions.SProjectId)
  444. if sProjectErr != nil {
  445. return nil, sProjectErr
  446. }
  447. if sProjectInfo != nil {
  448. projectTaskListData.SettleNum = sProjectInfo.SettleNum
  449. projectTaskListData.RecruitNum = sProjectInfo.RecruitNum
  450. projectTaskListData.QuitNum = sProjectInfo.QuitNum
  451. projectTaskListData.ServiceChargeSettle = sProjectInfo.ServiceChargeSettle
  452. projectTaskListData.ServiceChargeActual = sProjectInfo.ServiceChargeActual
  453. projectTaskListData.EstimateServiceCharge = sProjectInfo.ServiceChargeActual
  454. projectTaskListData.EstimateDraftFee = sProjectInfo.EstimateDraftFee
  455. projectTaskListData.EstimateSupportFee = sProjectInfo.EstimateSupportFee
  456. }
  457. projectTaskListData.Total = conv.MustString(total)
  458. return projectTaskListData, nil
  459. }
  460. func (*project) GetPorjectDetail(ctx context.Context, projectID string) (*http_model.ShowProjectData, error) {
  461. project, err := db.GetProjectDetail(ctx, projectID)
  462. if err != nil {
  463. logrus.WithContext(ctx).Errorf("[project service] call GetPorjectDetail error,err:%+v", err)
  464. return nil, err
  465. }
  466. enterprise, err := db.GetEnterpriseByEnterpriseID(ctx, project.EnterpriseID)
  467. if err != nil {
  468. logrus.WithContext(ctx).Errorf("[project service] call GetEnterpriseByEnterpriseID error,err:%+v", err)
  469. return nil, err
  470. }
  471. user, err := db.GetUserByID(ctx, enterprise.UserID)
  472. if err != nil {
  473. logrus.WithContext(ctx).Errorf("[project service] call GetUserByID error,err:%+v", err)
  474. return nil, err
  475. }
  476. ProjectDetail := http_model.ShowProjectData{
  477. ProjectID: conv.MustString(project.ProjectID),
  478. ProjectName: conv.MustString(project.ProjectName),
  479. ProjectStatus: conv.MustString(project.ProjectStatus),
  480. ProjectType: conv.MustString(project.ProjectType),
  481. ProjectPlatform: conv.MustString(project.ProjectPlatform),
  482. ProjectForm: conv.MustString(project.ProjectForm),
  483. TalentType: conv.MustString(project.TalentType),
  484. RecruitDdl: util.GetTimePoionter(project.RecruitDdl),
  485. ContentType: conv.MustString(project.ContentType),
  486. ProjectDetail: conv.MustString(project.ProjectDetail),
  487. ProductID: conv.MustString(project.ProductID),
  488. EnterpriseID: conv.MustString(project.EnterpriseID),
  489. Balance: conv.MustString(enterprise.Balance),
  490. AvailableBalance: conv.MustString(enterprise.AvailableBalance),
  491. EstimatedCost: conv.MustString(project.EstimatedCost),
  492. FailReason: conv.MustString(project.FailReason),
  493. CreateAt: util.GetTimePoionter(project.CreatedAt),
  494. UpdateAt: util.GetTimePoionter(project.UpdatedAt),
  495. Phone: user.Phone,
  496. FinishAt: util.GetTimePoionter(project.FinishAt),
  497. PassAt: util.GetTimePoionter(project.PassAt),
  498. SubmitAt: util.GetTimePoionter(project.SubmitAt),
  499. PayAt: util.GetTimePoionter(project.PayAt),
  500. ProductInfo: conv.MustString(project.ProductSnap),
  501. ProductPhotoInfo: conv.MustString(project.ProductPhotoSnap),
  502. AutoFailAt: util.GetTimePoionter(project.AutoFailAt),
  503. }
  504. Strategys, err := db.GetRecruitStrategys(ctx, projectID)
  505. if err != nil {
  506. logrus.WithContext(ctx).Error()
  507. return nil, err
  508. }
  509. for _, strategy := range Strategys {
  510. RecruitStrategy := http_model.ShowRecruitStrategy{
  511. RecruitStrategyID: conv.MustString(strategy.RecruitStrategyID),
  512. FeeForm: conv.MustString(strategy.FeeForm),
  513. StrategyID: conv.MustString(strategy.StrategyID),
  514. FollowersLow: conv.MustString(strategy.FollowersLow),
  515. FollowersUp: conv.MustString(strategy.FollowersUp),
  516. RecruitNumber: conv.MustString(strategy.RecruitNumber),
  517. Offer: conv.MustString(strategy.Offer),
  518. ServiceCharge: conv.MustString(strategy.ServiceCharge),
  519. SelectedNumber: strategy.SelectedNumber,
  520. WaitingNumber: strategy.WaitingNumber,
  521. DeliveredNumber: strategy.DeliveredNumber,
  522. SignedNumber: strategy.SignedNumber,
  523. }
  524. ProjectDetail.RecruitStrategys = append(ProjectDetail.RecruitStrategys, RecruitStrategy)
  525. }
  526. Photos, err := db.GetProjectPhoto(ctx, projectID)
  527. if err != nil {
  528. logrus.WithContext(ctx).Error()
  529. return nil, err
  530. }
  531. for _, Photo := range Photos {
  532. ProjectPhoto := http_model.ShowProjectPhoto{
  533. PhotoUrl: Photo.PhotoUrl,
  534. PhotoUid: Photo.PhotoUid,
  535. FileName: Photo.FileName,
  536. }
  537. ProjectDetail.ProjectPhotos = append(ProjectDetail.ProjectPhotos, ProjectPhoto)
  538. }
  539. return &ProjectDetail, nil
  540. }
  541. func (*project) GetTaskLogisticsList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskLogisticsListData, error) {
  542. TaskLogisticss, total, err := db.GetTaskLogisticsList(ctx, projectID, pageSize, pageNum, conditions)
  543. if err != nil {
  544. logrus.WithContext(ctx).Errorf("[project service] call GetTaskLogisticsList error,err:%+v", err)
  545. return nil, err
  546. }
  547. TaskLogisticsListData := new(http_model.TaskLogisticsListData)
  548. TaskLogisticsListData.TaskLogisticsPreview = pack.MGormTaskLogisticsInfoListToHttpTaskLogisticsPreviewList(TaskLogisticss)
  549. TaskLogisticsListData.Total = conv.MustString(total)
  550. return TaskLogisticsListData, nil
  551. }
  552. // ChangeTaskStatus 提报达人或拒绝提报达人
  553. func (*project) ChangeTaskStatus(ctx *gin.Context, data http_model.ProjectChangeTaskStatusRequest) interface{} {
  554. var sOperatorType int
  555. if data.SubAccountId == 0 {
  556. sOperatorType = 1
  557. } else {
  558. sOperatorType = 2
  559. }
  560. RecruitStrategyIDs, err := db.ChangeTaskStatus(ctx, data.TaskIds, data.SupplierStatus, data.SupplierId, data.SubAccountId, sOperatorType)
  561. if err != nil {
  562. logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  563. return err
  564. }
  565. fmt.Println(RecruitStrategyIDs)
  566. // 已选数量
  567. //if data.SupplierStatus == 2 {
  568. // for _, RecruitStrategyID := range RecruitStrategyIDs {
  569. // err = db.CalculateSelectedNumberByRecruitStrategyID(ctx, RecruitStrategyID, 1)
  570. // if err != nil {
  571. // logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  572. // return err
  573. // }
  574. // }
  575. //} else if data.SupplierStatus == 3 {
  576. // for _, RecruitStrategyID := range RecruitStrategyIDs {
  577. // err = db.CalculateSelectedNumberByRecruitStrategyID(ctx, RecruitStrategyID, 1)
  578. // if err != nil {
  579. // logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  580. // return err
  581. // }
  582. // }
  583. //}
  584. return nil
  585. }
  586. // ChangeSpecialTaskStatus 定向种草任务 提报达人,拒绝提报
  587. /*
  588. func (*project) ChangeSpecialTaskStatus(ctx *gin.Context, data http_model.ProjectChangeTaskStatusRequest) interface{} {
  589. err := db.ChangeSpecialTaskStatus(ctx, data.TaskIds, data.SupplierStatus, data.SupplierId, data.SubAccountId, data.SOperatorType)
  590. if err != nil {
  591. logrus.WithContext(ctx).Errorf("[project service] call ChangeSpecialTaskStatus error,err:%+v", err)
  592. return err
  593. }
  594. return nil
  595. }
  596. */
  597. func (p *project) GetTaskScriptList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskScriptListData, error) {
  598. TaskScripts, total, err := db.GetTaskScriptList(ctx, projectID, pageSize, pageNum, conditions)
  599. if err != nil {
  600. logrus.WithContext(ctx).Errorf("[project service] call GetTaskScriptList error,err:%+v", err)
  601. return nil, err
  602. }
  603. TaskScriptListData := new(http_model.TaskScriptListData)
  604. TaskScriptListData.TaskScriptPreview = pack.MGormTaskScriptInfoListToHttpTaskScriptPreviewList(TaskScripts)
  605. TaskScriptListData.Total = conv.MustString(total)
  606. return TaskScriptListData, nil
  607. }
  608. func (p *project) GetTaskSketchList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskSketchListData, error) {
  609. TaskSketchs, total, err := db.GetTaskSketchList(ctx, projectID, pageSize, pageNum, conditions)
  610. if err != nil {
  611. logrus.WithContext(ctx).Errorf("[project service] call GetTaskSketchList error,err:%+v", err)
  612. return nil, err
  613. }
  614. TaskSketchListData := new(http_model.TaskSketchListData)
  615. TaskSketchListData.TaskSketchPreview = pack.MGormTaskSketchInfoListToHttpTaskSketchPreviewList(TaskSketchs)
  616. TaskSketchListData.Total = conv.MustString(total)
  617. return TaskSketchListData, nil
  618. }
  619. func (p *project) GetTaskLinkList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskLinkListData, error) {
  620. TaskLinks, total, err := db.GetTaskLinkList(ctx, projectID, pageSize, pageNum, conditions)
  621. if err != nil {
  622. logrus.WithContext(ctx).Errorf("[project service] call GetTaskLinkList error,err:%+v", err)
  623. return nil, err
  624. }
  625. TaskLinkListData := new(http_model.TaskLinkListData)
  626. TaskLinkListData.TaskLinkPreview = pack.MGormTaskLinkInfoListToHttpTaskLinkPreviewList(TaskLinks)
  627. TaskLinkListData.Total = conv.MustString(total)
  628. return TaskLinkListData, nil
  629. }
  630. func (p *project) GetTaskDataList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskDataListData, error) {
  631. TaskDatas, total, err := db.GetTaskDataList(ctx, projectID, pageSize, pageNum, conditions)
  632. if err != nil {
  633. logrus.WithContext(ctx).Errorf("[project service] call GetTaskDataList error,err:%+v", err)
  634. return nil, err
  635. }
  636. TaskDataListData := new(http_model.TaskDataListData)
  637. TaskDataListData.TaskDataPreview = pack.MGormTaskDataInfoListToHttpTaskDataPreviewList(TaskDatas)
  638. TaskDataListData.Total = conv.MustString(total)
  639. return TaskDataListData, nil
  640. }
  641. func (p *project) GetTaskFinishList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskFinishListData, error) {
  642. TaskFinishs, total, err := db.GetTaskFinishList(ctx, pageSize, pageNum, conditions)
  643. if err != nil {
  644. logrus.WithContext(ctx).Errorf("[project service] call GetTaskFinishList error,err:%+v", err)
  645. return nil, err
  646. }
  647. TaskFinishListData := new(http_model.TaskFinishListData)
  648. TaskFinishListData.TaskFinishPreview = pack.MGormTaskFinishInfoListToHttpTaskFinishPreviewList(TaskFinishs)
  649. TaskFinishListData.Total = conv.MustString(total)
  650. return TaskFinishListData, nil
  651. }
  652. func (p *project) GetServiceCharge(ctx *gin.Context, data http_model.GetServiceChargeRequest) (*http_model.ServiceChargeData, error) {
  653. pricingStrategy, err := db.GetPricingStrategy(ctx, data.FollowersLow, data.FollowersUp, data.FeeForm, data.Platform)
  654. if err != nil {
  655. return nil, err
  656. }
  657. serviceFee := http_model.ServiceChargeData{
  658. ServiceCharge: pricingStrategy.ServiceCharge,
  659. }
  660. return &serviceFee, nil
  661. }
  662. func (*project) GetSpecialProjectTaskList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.SpecialTaskLogisticsListData, error) {
  663. SpecialTaskLogisticsListDatas, total, err := db.GetSpecialTaskLogisticsList(ctx, projectID, pageSize, pageNum, conditions)
  664. if err != nil {
  665. logrus.WithContext(ctx).Errorf("[project service] call GetSpecialProjectTaskList error,err:%+v", err)
  666. return nil, err
  667. }
  668. TaskLogisticsListData := new(http_model.SpecialTaskLogisticsListData)
  669. TaskLogisticsListData.SpecialTaskLogisticsPreview = pack.MGormSpecialTaskLogisticsInfoListToHttpTaskLogisticsPreviewList(SpecialTaskLogisticsListDatas)
  670. TaskLogisticsListData.Total = conv.MustString(total, "")
  671. return TaskLogisticsListData, nil
  672. }
  673. // ShowTaskProgress ToDo
  674. // ShowTaskProgress 展示种草子任务进度
  675. func (p *project) ShowTaskProgress(ctx *gin.Context, data http_model.ShowTaskProgressRequest) (*http_model.ShowTaskProgressData, error) {
  676. // 1. 初始化返回数据结构体
  677. var taskProgressData *http_model.ShowTaskProgressData
  678. taskProgressData = &http_model.ShowTaskProgressData{}
  679. // 2. 根据task_id筛选出对应的子任务基础信息
  680. taskInfo, taskErr := db.GetTaskByTaskId(ctx, data.TaskId)
  681. if taskErr != nil {
  682. return nil, taskErr
  683. }
  684. if taskInfo != nil {
  685. taskProgressData.TaskId = data.TaskId
  686. taskProgressData.CreateData = taskInfo.CreateDate
  687. taskProgressData.SelectDate = taskInfo.SelectDate
  688. taskProgressData.DeliveryDate = taskInfo.DeliveryDate
  689. taskProgressData.SignedTime = taskInfo.SignedTime
  690. taskProgressData.ServiceCharge = taskInfo.ServiceCharge
  691. taskProgressData.DraftFee = taskInfo.DraftFee
  692. }
  693. // 3. 筛选出上传初稿时间和初稿状态
  694. taskSketchs, taskSketchErr := db.FindSketchInfoByTaskId(ctx, data.TaskId)
  695. if taskSketchErr != nil {
  696. return nil, taskSketchErr
  697. }
  698. if taskSketchs != nil {
  699. taskProgressData.SketchInfo = taskSketchs
  700. }
  701. // 4. 筛选作品链接上传时间和状态
  702. taskLinks, taskLinksErr := db.GetLinkByTaskId(ctx, data.TaskId)
  703. if taskLinksErr != nil {
  704. return nil, taskLinksErr
  705. }
  706. if taskLinks != nil {
  707. taskProgressData.LinkInfo = taskLinks
  708. }
  709. // 5. 若有违约,筛选出违约情况
  710. if taskInfo != nil {
  711. taskProgressData.TerminateTime = taskInfo.TerminateTime
  712. taskProgressData.TerminateReason = taskInfo.TerminateReason
  713. taskProgressData.CancelTime = taskInfo.CancelTime
  714. taskProgressData.CancelReason = taskInfo.CancelReason
  715. }
  716. return taskProgressData, nil
  717. }
  718. func (p *project) GetProjectStrategys(ctx *gin.Context, projectId string) ([]gorm_model.RecruitStrategy, error) {
  719. recruitStrategys, getProjectStrategysErr := db.GetRecruitStrategyByProjectId(ctx, projectId)
  720. if getProjectStrategysErr != nil {
  721. return nil, getProjectStrategysErr
  722. }
  723. return recruitStrategys, nil
  724. }
  725. // GetProjectDetail 查找种草任务详情
  726. func (*project) GetProjectDetail(ctx context.Context, ProjectId string) (*http_model.ShowNewProjectData, error) {
  727. var sProjectData *http_model.ShowNewProjectData
  728. sProjectData = &http_model.ShowNewProjectData{}
  729. // 1. 取出种草表中的信息
  730. projectInfo, projectErr := db.GetProjectDetail(ctx, ProjectId)
  731. if projectErr != nil {
  732. return nil, projectErr
  733. }
  734. if projectInfo != nil {
  735. sProjectData.ProjectName = projectInfo.ProjectName
  736. sProjectData.ProjectID = projectInfo.ProjectID
  737. sProjectData.ProjectType = projectInfo.ProjectType
  738. sProjectData.ProjectPlatform = projectInfo.ProjectPlatform
  739. sProjectData.ProjectForm = projectInfo.ProjectForm
  740. sProjectData.ContentType = projectInfo.ContentType
  741. sProjectData.EnterpriseID = projectInfo.EnterpriseID
  742. sProjectData.TalentType = projectInfo.TalentType
  743. sProjectData.RecruitDdl = conv.MustString(projectInfo.RecruitDdl)[0:19]
  744. sProjectData.ProjectDetail = projectInfo.ProjectDetail
  745. sProjectData.EstimatedCost = projectInfo.EstimatedCost
  746. sProjectData.PassAt = conv.MustString(projectInfo.PassAt)[0:19]
  747. sProjectData.Tools = projectInfo.Tools
  748. // 3. 取出招募策略并聚合达人数量信息
  749. recruitStrategy, recruitErr := db.GetRecruitStrategyByProjectId(ctx, ProjectId)
  750. if recruitErr != nil {
  751. return nil, recruitErr
  752. }
  753. if recruitStrategy != nil {
  754. for _, strategy := range recruitStrategy {
  755. showStrategy := http_model.ShowNewRecruitStrategy{
  756. StrategyID: strategy.StrategyID,
  757. FeeForm: strategy.FeeForm,
  758. RecruitStrategyID: strategy.RecruitStrategyID,
  759. FollowersLow: strategy.FollowersLow,
  760. FollowersUp: strategy.FollowersUp,
  761. RecruitNumber: strategy.RecruitNumber,
  762. ServiceCharge: projectInfo.ServiceChargeRate,
  763. Offer: strategy.Offer,
  764. }
  765. sProjectData.SRecruitStrategys = append(sProjectData.SRecruitStrategys, showStrategy)
  766. }
  767. }
  768. // 4. 取出种草任务创建者用户信息
  769. if projectInfo.OperatorType == 1 {
  770. // fmt.Println("商家用户")
  771. enterpriseInfo, enterpriseErr := db.GetEnterpriseByEnterpriseID(ctx, projectInfo.EnterpriseID)
  772. if enterpriseErr != nil {
  773. return nil, enterpriseErr
  774. }
  775. sProjectData.CreatorName = enterpriseInfo.BusinessName
  776. sProjectData.CreatorCompany = enterpriseInfo.BusinessName
  777. sProjectData.CreatorType = 1
  778. sProjectData.Phone = enterpriseInfo.BusinessName
  779. } else if projectInfo.OperatorType == 2 {
  780. // fmt.Println("商家子账号")
  781. enterpriseInfo, enterpriseErr := db.GetEnterpriseByEnterpriseID(ctx, projectInfo.EnterpriseID)
  782. if enterpriseErr != nil {
  783. return nil, enterpriseErr
  784. }
  785. sProjectData.CreatorCompany = enterpriseInfo.BusinessName
  786. subAccountInfo, SubAccountErr := db.FindSubAccountById(ctx, projectInfo.SubAccountId)
  787. if SubAccountErr != nil {
  788. return nil, SubAccountErr
  789. }
  790. sProjectData.Phone = subAccountInfo.PhoneNumber
  791. jobInfo, jobErr := db.FindJobByJobId(ctx, subAccountInfo.JobId)
  792. if jobErr != nil {
  793. return nil, jobErr
  794. }
  795. sProjectData.CreatorType = 2
  796. sProjectData.CreatorName = jobInfo.JobName
  797. }
  798. // 5. 商品信息
  799. // 5.1. 取出商品信息并聚合
  800. productInfo, productErr := db.GetProductByID(ctx, projectInfo.ProductID)
  801. if productErr != nil {
  802. return nil, productErr
  803. }
  804. if productInfo != nil {
  805. sProjectData.ProductID = productInfo.ProductID
  806. sProjectData.ProductName = productInfo.ProductName
  807. sProjectData.ProductType = productInfo.ProductType
  808. sProjectData.ProductPrice = productInfo.ProductPrice
  809. sProjectData.ProductCategory = productInfo.ProductCategory
  810. }
  811. // 5.2. 聚合商品图片信息
  812. productPhotoInfo, productPhotoErr := db.GetProductPhotoByProductID(ctx, projectInfo.ProductID)
  813. if productPhotoErr != nil {
  814. return nil, productPhotoErr
  815. }
  816. if productPhotoInfo != nil {
  817. for _, p := range productPhotoInfo {
  818. if p.Symbol == 1 {
  819. sProjectData.ProductMainPhotoUrl = p.PhotoUrl
  820. sProjectData.ProductMainPhotoUid = p.PhotoUid
  821. sProjectData.Symbol = 1
  822. }
  823. }
  824. }
  825. // 6. 执行要求Brief和素材
  826. // 6.1. Brief
  827. projectBrief, briefErr := db.FindProjectBriefByProjectId(ctx, sProjectData.ProjectID)
  828. if briefErr != nil {
  829. return nil, briefErr
  830. }
  831. if projectBrief != nil {
  832. sProjectData.ProjectBriefInfo = projectBrief
  833. }
  834. // 6.2. 素材
  835. projectMaterial, materialErr := db.FindProjectMaterialByProjectId(ctx, sProjectData.ProjectID)
  836. if materialErr != nil {
  837. return nil, materialErr
  838. }
  839. if projectMaterial != nil {
  840. sProjectData.ProjectMaterial = projectMaterial
  841. }
  842. }
  843. return sProjectData, nil
  844. }
  845. // CountProjectTask 按照状态统计子任务数量
  846. func (*project) CountProjectTask(ctx context.Context, sProjectId int) (*http_model.ProjectTaskCountData, error) {
  847. var counter *http_model.ProjectTaskCountData
  848. counter = &http_model.ProjectTaskCountData{}
  849. // 1. Stage1
  850. stage1, stage1Err := db.CountTaskNumByTaskStage(ctx, 0, 1, sProjectId)
  851. if stage1Err != nil {
  852. return nil, stage1Err
  853. }
  854. counter.Stage1 = stage1
  855. // 2. Stage2
  856. stage2, stage2Err := db.CountTaskNumByTaskStage(ctx, 0, 2, sProjectId)
  857. if stage2Err != nil {
  858. return nil, stage2Err
  859. }
  860. counter.Stage2 = stage2
  861. // 3. Stage3
  862. stage3, stage3Err := db.CountTaskNumByTaskStage(ctx, 0, 3, sProjectId)
  863. if stage3Err != nil {
  864. return nil, stage3Err
  865. }
  866. counter.Stage3 = stage3
  867. // 4. Stage4
  868. stage4, stage4Err := db.CountTaskNumByTaskStage(ctx, 1, 2, sProjectId)
  869. if stage4Err != nil {
  870. return nil, stage4Err
  871. }
  872. counter.Stage4 = stage4
  873. // 5. Stage5
  874. stage5, stage5Err := db.CountTaskNumByTaskStage(ctx, 2, 2, sProjectId)
  875. if stage5Err != nil {
  876. return nil, stage5Err
  877. }
  878. counter.Stage5 = stage5
  879. // 6. Stage6
  880. stage6, stage6Err := db.CountTaskNumByTaskStage(ctx, 3, 2, sProjectId)
  881. if stage6Err != nil {
  882. return nil, stage6Err
  883. }
  884. counter.Stage6 = stage6
  885. // 7. Stage7
  886. stage7, stage7Err := db.CountTaskNumByTaskStage(ctx, 0, 0, sProjectId)
  887. if stage7Err != nil {
  888. return nil, stage7Err
  889. }
  890. counter.Stage7 = stage7
  891. return counter, nil
  892. }