|
@@ -2,6 +2,7 @@ package service
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
+ "encoding/json"
|
|
|
"fmt"
|
|
|
"strconv"
|
|
|
"strings"
|
|
@@ -42,7 +43,6 @@ func (*project) GetProjectDetail(ctx context.Context, projectID int64) (*http_mo
|
|
|
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
|
|
@@ -52,32 +52,34 @@ func (*project) GetProjectDetail(ctx context.Context, projectID int64) (*http_mo
|
|
|
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: util.GetTimePointer(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, ""),
|
|
|
- FailReason: conv.MustString(project.FailReason, ""),
|
|
|
- CreateAt: util.GetTimePointer(project.CreatedAt),
|
|
|
- UpdateAt: util.GetTimePointer(project.UpdatedAt),
|
|
|
- Phone: user.Phone,
|
|
|
- FinishAt: util.GetTimePointer(project.FinishAt),
|
|
|
- PassAt: util.GetTimePointer(project.PassAt),
|
|
|
- PayAt: util.GetTimePointer(project.PayAt),
|
|
|
+ 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: util.GetTimePointer(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, ""),
|
|
|
+ EstimatedCost: conv.MustString(project.EstimatedCost, ""),
|
|
|
+ FailReason: conv.MustString(project.FailReason, ""),
|
|
|
+ CreateAt: util.GetTimePointer(project.CreatedAt),
|
|
|
+ UpdateAt: util.GetTimePointer(project.UpdatedAt),
|
|
|
+ Phone: user.Phone,
|
|
|
+ FinishAt: util.GetTimePointer(project.FinishAt),
|
|
|
+ PassAt: util.GetTimePointer(project.PassAt),
|
|
|
+ PayAt: util.GetTimePointer(project.PayAt),
|
|
|
+ ProductInfo: conv.MustString(project.ProductSnap, ""),
|
|
|
+ ProductPhotoInfo: conv.MustString(project.ProductPhotoSnap, ""),
|
|
|
+ AutoFailAt: conv.MustString(project.AutoFailAt, ""),
|
|
|
}
|
|
|
Strategys, err := db.GetRecruitStrategys(ctx, projectID)
|
|
|
- fmt.Println("招募策略:", Strategys)
|
|
|
+ //fmt.Println("招募策略:", Strategys)
|
|
|
if err != nil {
|
|
|
logrus.WithContext(ctx).Error()
|
|
|
return nil, err
|
|
@@ -155,7 +157,18 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
+ productPhotos, err := db.GetProductPhotoByProductID(ctx, newProject.ProductID)
|
|
|
+ productInfoToJson, _ := json.Marshal(product)
|
|
|
+ productPhotosToJson, _ := json.Marshal(productPhotos)
|
|
|
// 按照品牌名-商品名对项目进行命名
|
|
|
+ AutoTaskID, err := db.GetLastAutoTaskID()
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ AutoDefaultID, err := db.GetLastAutoDefaultID()
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
projectName := product.BrandName + "-" + product.ProductName
|
|
|
//feeForm := fmt.Sprintf("[")
|
|
|
feeFrom := []string{}
|
|
@@ -176,21 +189,47 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
|
|
|
}
|
|
|
}
|
|
|
feeFroms := strings.Join(feeFrom, ",")
|
|
|
- projectInfo := gorm_model.ProjectInfo{
|
|
|
- ProjectName: projectName,
|
|
|
- ProjectStatus: 1,
|
|
|
- ProjectType: newProject.ProjectType,
|
|
|
- TalentType: newProject.TalentType,
|
|
|
- ProjectPlatform: newProject.ProjectPlatform,
|
|
|
- ProjectForm: newProject.ProjectForm,
|
|
|
- RecruitDdl: &RecruitDdl,
|
|
|
- ProjectDetail: newProject.ProjectDetail,
|
|
|
- ContentType: newProject.ContentType,
|
|
|
- EnterpriseID: enterpriseID,
|
|
|
- ProductID: newProject.ProductID,
|
|
|
- FeeForm: feeFroms,
|
|
|
- EstimatedCost: ECost,
|
|
|
- IsRead: 0,
|
|
|
+ projectInfo := gorm_model.ProjectInfo{}
|
|
|
+ if newProject.ProjectType == int64(1) {
|
|
|
+ projectInfo = gorm_model.ProjectInfo{
|
|
|
+ ProjectName: projectName,
|
|
|
+ ProjectStatus: 1,
|
|
|
+ ProjectType: newProject.ProjectType,
|
|
|
+ TalentType: newProject.TalentType,
|
|
|
+ ProjectPlatform: newProject.ProjectPlatform,
|
|
|
+ ProjectForm: newProject.ProjectForm,
|
|
|
+ RecruitDdl: &RecruitDdl,
|
|
|
+ ProjectDetail: newProject.ProjectDetail,
|
|
|
+ ContentType: newProject.ContentType,
|
|
|
+ EnterpriseID: enterpriseID,
|
|
|
+ ProductID: newProject.ProductID,
|
|
|
+ FeeForm: feeFroms,
|
|
|
+ AutoTaskID: conv.MustInt64(AutoTaskID, 0),
|
|
|
+ AutoDefaultID: conv.MustInt64(AutoDefaultID, 0),
|
|
|
+ EstimatedCost: ECost,
|
|
|
+ IsRead: 0,
|
|
|
+ ProductSnap: string(productInfoToJson),
|
|
|
+ ProductPhotoSnap: string(productPhotosToJson),
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ projectInfo = gorm_model.ProjectInfo{
|
|
|
+ ProjectName: projectName,
|
|
|
+ ProjectStatus: 1,
|
|
|
+ ProjectType: newProject.ProjectType,
|
|
|
+ TalentType: "[]",
|
|
|
+ ProjectPlatform: newProject.ProjectPlatform,
|
|
|
+ ProjectForm: newProject.ProjectForm,
|
|
|
+ ProjectDetail: newProject.ProjectDetail,
|
|
|
+ ContentType: newProject.ContentType,
|
|
|
+ EnterpriseID: enterpriseID,
|
|
|
+ ProductID: newProject.ProductID,
|
|
|
+ FeeForm: feeFroms,
|
|
|
+ AutoTaskID: conv.MustInt64(AutoTaskID, 0),
|
|
|
+ AutoDefaultID: conv.MustInt64(AutoDefaultID, 0),
|
|
|
+ EstimatedCost: ECost,
|
|
|
+ ProductSnap: string(productInfoToJson),
|
|
|
+ ProductPhotoSnap: string(productPhotosToJson),
|
|
|
+ }
|
|
|
}
|
|
|
// db create ProjectInfo
|
|
|
projectID, err := db.CreateProject(ctx, projectInfo)
|
|
@@ -215,36 +254,40 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
|
|
|
}
|
|
|
}
|
|
|
// build
|
|
|
- recruitStrategys := []gorm_model.RecruitStrategy{}
|
|
|
- for _, strategy := range newProject.RecruitStrategys { // 查询对应定价策略
|
|
|
- pricingStrategy, err := db.GetPricingStrategy(ctx, strategy.FollowersLow, strategy.FollowersUp, strategy.FeeForm, newProject.ProjectPlatform)
|
|
|
+ if newProject.ProjectType == int64(1) {
|
|
|
+ recruitStrategys := []gorm_model.RecruitStrategy{}
|
|
|
+ for _, strategy := range newProject.RecruitStrategys {
|
|
|
+ // 查询对应定价策略
|
|
|
+ pricingStrategy, err := db.GetPricingStrategy(ctx, strategy.FollowersLow, strategy.FollowersUp, strategy.FeeForm, newProject.ProjectPlatform)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ // 根据定价策略计算达人所见报价
|
|
|
+ if strategy.FeeForm == 2 {
|
|
|
+ strategy.TOffer = strategy.Offer * (1 - conv.MustFloat64(pricingStrategy.ServiceRate, 0)/1000)
|
|
|
+ }
|
|
|
+ recruitStrategy := gorm_model.RecruitStrategy{
|
|
|
+ FeeForm: strategy.FeeForm,
|
|
|
+ StrategyID: strategy.StrategyID,
|
|
|
+ FollowersLow: strategy.FollowersLow,
|
|
|
+ FollowersUp: strategy.FollowersUp,
|
|
|
+ RecruitNumber: strategy.RecruitNumber,
|
|
|
+ ServiceCharge: strategy.ServiceCharge,
|
|
|
+ Offer: strategy.Offer,
|
|
|
+ TOffer: strategy.TOffer,
|
|
|
+ ProjectID: *projectID,
|
|
|
+ }
|
|
|
+ recruitStrategys = append(recruitStrategys, recruitStrategy)
|
|
|
+ }
|
|
|
+ err = db.CreateRecruitStrategy(ctx, recruitStrategys)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
- // 根据定价策略计算达人所见报价
|
|
|
- if strategy.FeeForm == 2 {
|
|
|
- strategy.TOffer = strategy.Offer * (1 - conv.MustFloat64(pricingStrategy.ServiceRate, 0)/1000)
|
|
|
- }
|
|
|
- recruitStrategy := gorm_model.RecruitStrategy{
|
|
|
- FeeForm: strategy.FeeForm,
|
|
|
- StrategyID: strategy.StrategyID,
|
|
|
- FollowersLow: strategy.FollowersLow,
|
|
|
- FollowersUp: strategy.FollowersUp,
|
|
|
- RecruitNumber: strategy.RecruitNumber,
|
|
|
- Offer: strategy.Offer,
|
|
|
- TOffer: strategy.TOffer,
|
|
|
- ProjectID: *projectID,
|
|
|
- }
|
|
|
- recruitStrategys = append(recruitStrategys, recruitStrategy)
|
|
|
- }
|
|
|
- err = db.CreateRecruitStrategy(ctx, recruitStrategys)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
}
|
|
|
res := &http_model.CreateProjectData{
|
|
|
ProjectID: *projectID,
|
|
|
}
|
|
|
- fmt.Printf("%+v", res)
|
|
|
+ //fmt.Printf("%+v", res)
|
|
|
return res, nil
|
|
|
}
|
|
|
|