project.go 27 KB

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