project.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/caixw/lib.go/conv"
  6. "github.com/gin-gonic/gin"
  7. "github.com/sirupsen/logrus"
  8. "youngee_m_api/db"
  9. "youngee_m_api/model/common_model"
  10. "youngee_m_api/model/gorm_model"
  11. "youngee_m_api/model/http_model"
  12. "youngee_m_api/pack"
  13. )
  14. var Project *project
  15. type project struct {
  16. }
  17. func (*project) GetFullProjectList(ctx context.Context , pageSize, pageNum int32, condition *common_model.ProjectCondition) (*http_model.FullProjectListData, error) {
  18. fullProjects, total, err := db.GetFullProjectList(ctx , pageSize, pageNum, condition)
  19. if err != nil {
  20. logrus.WithContext(ctx).Errorf("[project service] call GetFullProjectList error,err:%+v", err)
  21. return nil, err
  22. }
  23. fullProjectListData := new(http_model.FullProjectListData)
  24. fullProjectListData.FullProjectPreview = pack.MGormFullProjectToHttpFullProjectPreview(fullProjects)
  25. fullProjectListData.Total = conv.MustString(total,"")
  26. return fullProjectListData, nil
  27. }
  28. func (*project) GetPorjectDetail(ctx context.Context,EnterpriseID string, projectID int64) (*http_model.ShowProjectData, error) {
  29. project, err := db.GetProjectDetail(ctx, projectID)
  30. if err != nil {
  31. logrus.WithContext(ctx).Errorf("[project service] call GetPorjectDetail error,err:%+v", err)
  32. return nil, err
  33. }
  34. enterprise, err := db.GetEnterpriseByEnterpriseID(ctx, project.EnterpriseID)
  35. fmt.Println("%+v", enterprise.UserID)
  36. if err != nil {
  37. logrus.WithContext(ctx).Errorf("[project service] call GetEnterpriseByEnterpriseID error,err:%+v", err)
  38. return nil, err
  39. }
  40. user, err := db.GetUserByID(ctx, enterprise.UserID)
  41. if err != nil {
  42. logrus.WithContext(ctx).Errorf("[project service] call GetUserByID error,err:%+v", err)
  43. return nil, err
  44. }
  45. fmt.Println("%+v", user.Phone)
  46. //var RecruitStrategys []http_model.ShowRecruitStrategy
  47. ProjectDetail := http_model.ShowProjectData{
  48. ProjectID: conv.MustString(project.ProjectID,""),
  49. ProjectName: conv.MustString(project.ProjectName,""),
  50. ProjectStatus: conv.MustString(project.ProjectStatus,""),
  51. ProjectType: conv.MustString(project.ProjectType,""),
  52. ProjectPlatform: conv.MustString(project.ProjectPlatform,""),
  53. ProjectForm: conv.MustString(project.ProjectForm,""),
  54. TalentType: conv.MustString(project.TalentType,""),
  55. RecruitDdl: project.RecruitDdl,
  56. ContentType: conv.MustString(project.ContentType,""),
  57. ProjectDetail: conv.MustString(project.ProjectDetail,""),
  58. ProductID: conv.MustString(project.ProductID,""),
  59. EnterpriseID: conv.MustString(project.EnterpriseID,""),
  60. Balance: conv.MustString(enterprise.Balance,""),
  61. CreateAt: project.CreatedAt,
  62. UpdateAt: project.UpdatedAt,
  63. Phone: user.Phone,
  64. }
  65. Strategys, err := db.GetRecruitStrategys(ctx, projectID)
  66. if err != nil {
  67. logrus.WithContext(ctx).Error()
  68. return nil, err
  69. }
  70. for _, strategy := range Strategys {
  71. RecruitStrategy := http_model.ShowRecruitStrategy{
  72. FeeForm: conv.MustString(strategy.FeeForm,""),
  73. StrategyID: conv.MustString(strategy.StrategyID,""),
  74. FollowersLow: conv.MustString(strategy.FollowersLow,""),
  75. FollowersUp: conv.MustString(strategy.FollowersUp,""),
  76. RecruitNumber: conv.MustString(strategy.RecruitNumber,""),
  77. Offer: conv.MustString(strategy.Offer,""),
  78. }
  79. ProjectDetail.RecruitStrategys = append(ProjectDetail.RecruitStrategys, RecruitStrategy)
  80. }
  81. Photos, err := db.GetProjectPhoto(ctx, projectID)
  82. if err != nil {
  83. logrus.WithContext(ctx).Error()
  84. return nil, err
  85. }
  86. for _, Photo := range Photos {
  87. ProjectPhoto := http_model.ShowProjectPhoto{
  88. PhotoUrl: Photo.PhotoUrl,
  89. PhotoUid: Photo.PhotoUid,
  90. }
  91. ProjectDetail.ProjectPhotos = append(ProjectDetail.ProjectPhotos, ProjectPhoto)
  92. }
  93. return &ProjectDetail, nil
  94. }
  95. func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectRequest, enterpriseID string) (*http_model.UpdateProjectData, error) {
  96. fmt.Println("newproject:", newProject)
  97. project := gorm_model.ProjectInfo{
  98. ProjectID: conv.MustInt64(newProject.ProjectID,0),
  99. RecruitDdl: newProject.RecruitDdl,
  100. TalentType: newProject.TalentType,
  101. ContentType: conv.MustInt64(newProject.ContentType,0),
  102. ProjectDetail: newProject.ProjectDetail,
  103. ProjectForm: conv.MustInt64(newProject.ProjectForm,0),
  104. EnterpriseID: conv.MustInt64(enterpriseID,0),
  105. ProjectStatus: 4,
  106. }
  107. projectID, err := db.UpdateProject(ctx, project)
  108. if err != nil {
  109. return nil, err
  110. }
  111. // 删除该项目之前的所有图片
  112. err = db.DeleteProjectPhotoByProjecttID(ctx, *projectID)
  113. if err != nil {
  114. return nil, err
  115. }
  116. fmt.Printf("照片:\t %+v", newProject.ProjectPhotos)
  117. if newProject.ProjectPhotos != nil {
  118. // 新增图片
  119. projectPhotos := []gorm_model.ProjectPhoto{}
  120. for _, photo := range newProject.ProjectPhotos {
  121. projectPhoto := gorm_model.ProjectPhoto{
  122. ProjectID: project.ProjectID,
  123. PhotoUrl: photo.PhotoUrl,
  124. PhotoUid: photo.PhotoUid,
  125. }
  126. projectPhotos = append(projectPhotos, projectPhoto)
  127. }
  128. err = db.CreateProjectPhoto(ctx, projectPhotos)
  129. if err != nil {
  130. return nil, err
  131. }
  132. }
  133. // 删除该项目之前的所有策略
  134. err = db.DeleteRecruitStrategyByProjectID(ctx, *projectID)
  135. if err != nil {
  136. return nil, err
  137. }
  138. fmt.Printf("策略:\t %+v", newProject.RecruitStrategys)
  139. if newProject.RecruitStrategys != nil {
  140. // 新增策略
  141. RecruitStrategys := []gorm_model.RecruitStrategy{}
  142. for _, Strategy := range newProject.RecruitStrategys {
  143. RecruitStrategy := gorm_model.RecruitStrategy{
  144. FeeForm: conv.MustInt64(Strategy.FeeForm,0),
  145. StrategyID: conv.MustInt64(Strategy.StrategyID,0),
  146. FollowersLow: conv.MustInt64(Strategy.FollowersLow,0),
  147. FollowersUp: conv.MustInt64(Strategy.FollowersUp,0),
  148. RecruitNumber: conv.MustInt64(Strategy.RecruitNumber,0),
  149. Offer: conv.MustInt64(Strategy.Offer,0),
  150. ProjectID: project.ProjectID,
  151. }
  152. fmt.Printf("Offer:\t %+v", Strategy.Offer)
  153. RecruitStrategys = append(RecruitStrategys, RecruitStrategy)
  154. }
  155. err = db.CreateRecruitStrategy(ctx, RecruitStrategys)
  156. if err != nil {
  157. return nil, err
  158. }
  159. }
  160. res := &http_model.UpdateProjectData{
  161. ProjectID: *projectID,
  162. }
  163. return res, nil
  164. }
  165. func (*project) ApproveProject(ctx *gin.Context, data http_model.ApproveProjectRequest) (error, string) {
  166. fmt.Println("data.IsApprove:",data.IsApprove)
  167. err,message := db.ApproveProject(ctx, data.ProjectId ,data.IsApprove)
  168. if err != nil {
  169. logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
  170. return err,""
  171. }
  172. return nil,message
  173. }