123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- package service
- import (
- "context"
- "fmt"
- "github.com/caixw/lib.go/conv"
- "github.com/gin-gonic/gin"
- "github.com/sirupsen/logrus"
- "youngee_m_api/db"
- "youngee_m_api/model/common_model"
- "youngee_m_api/model/gorm_model"
- "youngee_m_api/model/http_model"
- "youngee_m_api/pack"
- )
- var Project *project
- type project struct {
- }
- func (*project) GetFullProjectList(ctx context.Context , pageSize, pageNum int32, condition *common_model.ProjectCondition) (*http_model.FullProjectListData, error) {
- fullProjects, total, err := db.GetFullProjectList(ctx , pageSize, pageNum, condition)
- if err != nil {
- logrus.WithContext(ctx).Errorf("[project service] call GetFullProjectList error,err:%+v", err)
- return nil, err
- }
- fullProjectListData := new(http_model.FullProjectListData)
- fullProjectListData.FullProjectPreview = pack.MGormFullProjectToHttpFullProjectPreview(fullProjects)
- fullProjectListData.Total = conv.MustString(total,"")
- return fullProjectListData, nil
- }
- func (*project) GetPorjectDetail(ctx context.Context,EnterpriseID string, projectID int64) (*http_model.ShowProjectData, error) {
- project, err := db.GetProjectDetail(ctx, projectID)
- if err != nil {
- logrus.WithContext(ctx).Errorf("[project service] call GetPorjectDetail error,err:%+v", err)
- return nil, err
- }
- enterprise, err := db.GetEnterpriseByEnterpriseID(ctx, project.EnterpriseID)
- fmt.Println("%+v", enterprise.UserID)
- if err != nil {
- logrus.WithContext(ctx).Errorf("[project service] call GetEnterpriseByEnterpriseID error,err:%+v", err)
- return nil, err
- }
- user, err := db.GetUserByID(ctx, enterprise.UserID)
- if err != nil {
- logrus.WithContext(ctx).Errorf("[project service] call GetUserByID error,err:%+v", err)
- return nil, err
- }
- fmt.Println("%+v", user.Phone)
- //var RecruitStrategys []http_model.ShowRecruitStrategy
- ProjectDetail := http_model.ShowProjectData{
- ProjectID: conv.MustString(project.ProjectID,""),
- ProjectName: conv.MustString(project.ProjectName,""),
- ProjectStatus: conv.MustString(project.ProjectStatus,""),
- ProjectType: conv.MustString(project.ProjectType,""),
- ProjectPlatform: conv.MustString(project.ProjectPlatform,""),
- ProjectForm: conv.MustString(project.ProjectForm,""),
- TalentType: conv.MustString(project.TalentType,""),
- RecruitDdl: project.RecruitDdl,
- ContentType: conv.MustString(project.ContentType,""),
- ProjectDetail: conv.MustString(project.ProjectDetail,""),
- ProductID: conv.MustString(project.ProductID,""),
- EnterpriseID: conv.MustString(project.EnterpriseID,""),
- Balance: conv.MustString(enterprise.Balance,""),
- CreateAt: project.CreatedAt,
- UpdateAt: project.UpdatedAt,
- Phone: user.Phone,
- }
- Strategys, err := db.GetRecruitStrategys(ctx, projectID)
- if err != nil {
- logrus.WithContext(ctx).Error()
- return nil, err
- }
- for _, strategy := range Strategys {
- RecruitStrategy := http_model.ShowRecruitStrategy{
- FeeForm: conv.MustString(strategy.FeeForm,""),
- StrategyID: conv.MustString(strategy.StrategyID,""),
- FollowersLow: conv.MustString(strategy.FollowersLow,""),
- FollowersUp: conv.MustString(strategy.FollowersUp,""),
- RecruitNumber: conv.MustString(strategy.RecruitNumber,""),
- Offer: conv.MustString(strategy.Offer,""),
- }
- ProjectDetail.RecruitStrategys = append(ProjectDetail.RecruitStrategys, RecruitStrategy)
- }
- Photos, err := db.GetProjectPhoto(ctx, projectID)
- if err != nil {
- logrus.WithContext(ctx).Error()
- return nil, err
- }
- for _, Photo := range Photos {
- ProjectPhoto := http_model.ShowProjectPhoto{
- PhotoUrl: Photo.PhotoUrl,
- PhotoUid: Photo.PhotoUid,
- }
- ProjectDetail.ProjectPhotos = append(ProjectDetail.ProjectPhotos, ProjectPhoto)
- }
- return &ProjectDetail, nil
- }
- func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectRequest, enterpriseID string) (*http_model.UpdateProjectData, error) {
- fmt.Println("newproject:", newProject)
- project := gorm_model.ProjectInfo{
- ProjectID: conv.MustInt64(newProject.ProjectID,0),
- RecruitDdl: newProject.RecruitDdl,
- TalentType: newProject.TalentType,
- ContentType: conv.MustInt64(newProject.ContentType,0),
- ProjectDetail: newProject.ProjectDetail,
- ProjectForm: conv.MustInt64(newProject.ProjectForm,0),
- EnterpriseID: conv.MustInt64(enterpriseID,0),
- ProjectStatus: 4,
- }
- projectID, err := db.UpdateProject(ctx, project)
- if err != nil {
- return nil, err
- }
- // 删除该项目之前的所有图片
- err = db.DeleteProjectPhotoByProjecttID(ctx, *projectID)
- if err != nil {
- return nil, err
- }
- fmt.Printf("照片:\t %+v", newProject.ProjectPhotos)
- if newProject.ProjectPhotos != nil {
- // 新增图片
- projectPhotos := []gorm_model.ProjectPhoto{}
- for _, photo := range newProject.ProjectPhotos {
- projectPhoto := gorm_model.ProjectPhoto{
- ProjectID: project.ProjectID,
- PhotoUrl: photo.PhotoUrl,
- PhotoUid: photo.PhotoUid,
- }
- projectPhotos = append(projectPhotos, projectPhoto)
- }
- err = db.CreateProjectPhoto(ctx, projectPhotos)
- if err != nil {
- return nil, err
- }
- }
- // 删除该项目之前的所有策略
- err = db.DeleteRecruitStrategyByProjectID(ctx, *projectID)
- if err != nil {
- return nil, err
- }
- fmt.Printf("策略:\t %+v", newProject.RecruitStrategys)
- if newProject.RecruitStrategys != nil {
- // 新增策略
- RecruitStrategys := []gorm_model.RecruitStrategy{}
- for _, Strategy := range newProject.RecruitStrategys {
- RecruitStrategy := gorm_model.RecruitStrategy{
- FeeForm: conv.MustInt64(Strategy.FeeForm,0),
- StrategyID: conv.MustInt64(Strategy.StrategyID,0),
- FollowersLow: conv.MustInt64(Strategy.FollowersLow,0),
- FollowersUp: conv.MustInt64(Strategy.FollowersUp,0),
- RecruitNumber: conv.MustInt64(Strategy.RecruitNumber,0),
- Offer: conv.MustInt64(Strategy.Offer,0),
- ProjectID: project.ProjectID,
- }
- fmt.Printf("Offer:\t %+v", Strategy.Offer)
- RecruitStrategys = append(RecruitStrategys, RecruitStrategy)
- }
- err = db.CreateRecruitStrategy(ctx, RecruitStrategys)
- if err != nil {
- return nil, err
- }
- }
- res := &http_model.UpdateProjectData{
- ProjectID: *projectID,
- }
- return res, nil
- }
- func (*project) ApproveProject(ctx *gin.Context, data http_model.ApproveProjectRequest) (error, string) {
- fmt.Println("data.IsApprove:",data.IsApprove)
- err,message := db.ApproveProject(ctx, data.ProjectId ,data.IsApprove)
- if err != nil {
- logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
- return err,""
- }
- return nil,message
- }
|