|
@@ -5,6 +5,7 @@ import (
|
|
|
"fmt"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
+ "time"
|
|
|
"youngee_b_api/db"
|
|
|
"youngee_b_api/model/common_model"
|
|
|
"youngee_b_api/model/gorm_model"
|
|
@@ -43,12 +44,24 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
|
|
|
//feeForm := fmt.Sprintf("[")
|
|
|
feeFrom := []string{}
|
|
|
for _, strategy := range newProject.RecruitStrategys {
|
|
|
- //if strategy.StrategyID
|
|
|
feeFrom = append(feeFrom, strconv.FormatInt(strategy.FeeForm, 10))
|
|
|
- //feeForm += string(strategy.StrategyID)
|
|
|
+ }
|
|
|
+ var ECost float64 = 0
|
|
|
+ if newProject.ProjectType == int64(1) {
|
|
|
+ for _, strategy := range newProject.RecruitStrategys {
|
|
|
+ // 计算预估成本
|
|
|
+ var tmpCost float64 = 0
|
|
|
+ if strategy.FeeForm == 1 {
|
|
|
+ tmpCost = strategy.ServiceCharge * float64(strategy.RecruitNumber)
|
|
|
+ } else if strategy.FeeForm == 2 {
|
|
|
+ tmpCost = strategy.Offer * float64(strategy.RecruitNumber)
|
|
|
+ }
|
|
|
+ ECost += tmpCost
|
|
|
+ }
|
|
|
}
|
|
|
feeFroms := strings.Join(feeFrom, ",")
|
|
|
fmt.Printf("创建项目new %+v", newProject)
|
|
|
+ RecruitDdl, _ := time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
|
|
|
projectInfo := gorm_model.ProjectInfo{}
|
|
|
if newProject.ProjectType == int64(1) {
|
|
|
projectInfo = gorm_model.ProjectInfo{
|
|
@@ -58,7 +71,7 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
|
|
|
TalentType: newProject.TalentType,
|
|
|
ProjectPlatform: newProject.ProjectPlatform,
|
|
|
ProjectForm: newProject.ProjectForm,
|
|
|
- RecruitDdl: &newProject.RecruitDdl,
|
|
|
+ RecruitDdl: &RecruitDdl,
|
|
|
ProjectDetail: newProject.ProjectDetail,
|
|
|
ContentType: newProject.ContentType,
|
|
|
EnterpriseID: enterpriseID,
|
|
@@ -66,6 +79,7 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
|
|
|
FeeForm: feeFroms,
|
|
|
AutoTaskID: conv.MustInt64(AutoTaskID),
|
|
|
AutoDefaultID: conv.MustInt64(AutoDefaultID),
|
|
|
+ EstimatedCost: ECost,
|
|
|
}
|
|
|
} else {
|
|
|
projectInfo = gorm_model.ProjectInfo{
|
|
@@ -82,6 +96,7 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
|
|
|
FeeForm: feeFroms,
|
|
|
AutoTaskID: conv.MustInt64(AutoTaskID),
|
|
|
AutoDefaultID: conv.MustInt64(AutoDefaultID),
|
|
|
+ EstimatedCost: ECost,
|
|
|
}
|
|
|
}
|
|
|
// db create ProjectInfo
|
|
@@ -110,13 +125,24 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
|
|
|
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)/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)
|
|
@@ -133,16 +159,43 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
|
|
|
return res, nil
|
|
|
}
|
|
|
func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectRequest, enterpriseID int64) (*http_model.UpdateProjectData, error) {
|
|
|
- fmt.Println("newproject:", newProject)
|
|
|
+ fmt.Println("RecruitDdl:", newProject.RecruitDdl)
|
|
|
+ RecruitDdl, _ := time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
|
|
|
+ oldProject, err3 := db.GetProjectDetail(ctx, conv.MustInt64(newProject.ProjectID))
|
|
|
+ if err3 != nil {
|
|
|
+ return nil, err3
|
|
|
+ }
|
|
|
+ feeFrom := []string{}
|
|
|
+ for _, strategy := range newProject.RecruitStrategys {
|
|
|
+ //if strategy.StrategyID
|
|
|
+ feeFrom = append(feeFrom, strconv.FormatInt(strategy.FeeForm, 10))
|
|
|
+ //feeForm += string(strategy.StrategyID)
|
|
|
+ }
|
|
|
+ var ECost float64 = 0
|
|
|
+ if newProject.ProjectType == int64(1) {
|
|
|
+ for _, strategy := range newProject.RecruitStrategys {
|
|
|
+ // 计算预估成本
|
|
|
+ var tmpCost float64 = 0
|
|
|
+ if strategy.FeeForm == 1 {
|
|
|
+ tmpCost = strategy.ServiceCharge * float64(strategy.RecruitNumber)
|
|
|
+ } else if strategy.FeeForm == 2 {
|
|
|
+ tmpCost = strategy.Offer * float64(strategy.RecruitNumber)
|
|
|
+ }
|
|
|
+ ECost += tmpCost
|
|
|
+ }
|
|
|
+ }
|
|
|
+ feeFroms := strings.Join(feeFrom, ",")
|
|
|
project := gorm_model.ProjectInfo{
|
|
|
ProjectID: conv.MustInt64(newProject.ProjectID),
|
|
|
- RecruitDdl: &newProject.RecruitDdl,
|
|
|
+ RecruitDdl: &RecruitDdl,
|
|
|
TalentType: newProject.TalentType,
|
|
|
ContentType: conv.MustInt64(newProject.ContentType),
|
|
|
ProjectDetail: newProject.ProjectDetail,
|
|
|
ProjectForm: conv.MustInt64(newProject.ProjectForm),
|
|
|
EnterpriseID: enterpriseID,
|
|
|
ProjectStatus: conv.MustInt64(newProject.ProjectStatus),
|
|
|
+ FeeForm: feeFroms,
|
|
|
+ EstimatedCost: ECost,
|
|
|
}
|
|
|
projectID, err := db.UpdateProject(ctx, project)
|
|
|
if err != nil {
|
|
@@ -154,7 +207,7 @@ func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectR
|
|
|
return nil, err
|
|
|
}
|
|
|
fmt.Printf("照片:\t %+v", newProject.ProjectPhotos)
|
|
|
- if newProject.ProjectPhotos != nil {
|
|
|
+ if len(newProject.ProjectPhotos) != 0 {
|
|
|
// 新增图片
|
|
|
projectPhotos := []gorm_model.ProjectPhoto{}
|
|
|
for _, photo := range newProject.ProjectPhotos {
|
|
@@ -180,13 +233,25 @@ func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectR
|
|
|
// 新增策略
|
|
|
RecruitStrategys := []gorm_model.RecruitStrategy{}
|
|
|
for _, Strategy := range newProject.RecruitStrategys {
|
|
|
+ // 查询对应定价策略
|
|
|
+ pricingStrategy, err := db.GetPricingStrategy(ctx, Strategy.FollowersLow, Strategy.FollowersUp, Strategy.FeeForm, oldProject.ProjectPlatform)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ // 根据定价策略计算达人所见报价
|
|
|
+ if Strategy.FeeForm == 2 {
|
|
|
+ Strategy.TOffer = Strategy.Offer * (1 - conv.MustFloat64(pricingStrategy.ServiceRate)/1000)
|
|
|
+ }
|
|
|
+
|
|
|
RecruitStrategy := gorm_model.RecruitStrategy{
|
|
|
FeeForm: conv.MustInt64(Strategy.FeeForm),
|
|
|
StrategyID: conv.MustInt64(Strategy.StrategyID),
|
|
|
FollowersLow: conv.MustInt64(Strategy.FollowersLow),
|
|
|
FollowersUp: conv.MustInt64(Strategy.FollowersUp),
|
|
|
RecruitNumber: conv.MustInt64(Strategy.RecruitNumber),
|
|
|
- Offer: conv.MustInt64(Strategy.Offer),
|
|
|
+ ServiceCharge: Strategy.ServiceCharge,
|
|
|
+ Offer: Strategy.Offer,
|
|
|
+ TOffer: Strategy.TOffer,
|
|
|
ProjectID: project.ProjectID,
|
|
|
}
|
|
|
fmt.Printf("Offer:\t %+v", Strategy.Offer)
|
|
@@ -264,7 +329,6 @@ func (*project) GetProjectTaskList(ctx context.Context, projectID string, pageSi
|
|
|
}
|
|
|
|
|
|
func (*project) GetPorjectDetail(ctx context.Context, 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)
|
|
@@ -297,6 +361,7 @@ func (*project) GetPorjectDetail(ctx context.Context, projectID int64) (*http_mo
|
|
|
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.GetTimePoionter(project.CreatedAt),
|
|
|
UpdateAt: util.GetTimePoionter(project.UpdatedAt),
|
|
@@ -320,7 +385,7 @@ func (*project) GetPorjectDetail(ctx context.Context, projectID int64) (*http_mo
|
|
|
FollowersUp: conv.MustString(strategy.FollowersUp),
|
|
|
RecruitNumber: conv.MustString(strategy.RecruitNumber),
|
|
|
Offer: conv.MustString(strategy.Offer),
|
|
|
- ServiceCharge: strategy.ServiceCharge,
|
|
|
+ ServiceCharge: conv.MustString(strategy.ServiceCharge),
|
|
|
SelectedNumber: strategy.SelectedNumber,
|
|
|
WaitingNumber: strategy.WaitingNumber,
|
|
|
DeliveredNumber: strategy.DeliveredNumber,
|
|
@@ -377,6 +442,15 @@ func (*project) ChangeTaskStatus(ctx *gin.Context, data http_model.ProjectChange
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+func (*project) ChangeSpecialTaskStatus(ctx *gin.Context, data http_model.ProjectChangeTaskStatusRequest) interface{} {
|
|
|
+ err := db.ChangeSpecialTaskStatus(ctx, data.TaskIds, data.TaskStatus, data.TaskStage)
|
|
|
+ if err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[project service] call ChangeSpecialTaskStatus error,err:%+v", err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
func (p *project) GetTaskScriptList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskScriptListData, error) {
|
|
|
TaskScripts, total, err := db.GetTaskScriptList(ctx, projectID, pageSize, pageNum, conditions)
|
|
|
if err != nil {
|
|
@@ -436,3 +510,14 @@ func (p *project) GetTaskFinishList(ctx *gin.Context, projectID string, pageSize
|
|
|
TaskFinishListData.Total = conv.MustString(total)
|
|
|
return TaskFinishListData, nil
|
|
|
}
|
|
|
+
|
|
|
+func (p *project) GetServiceCharge(ctx *gin.Context, data http_model.GetServiceChargeRequest) (*http_model.ServiceChargeData, error) {
|
|
|
+ pricingStrategy, err := db.GetPricingStrategy(ctx, data.FollowersLow, data.FollowersUp, data.FeeForm, data.Platform)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ serviceFee := http_model.ServiceChargeData{
|
|
|
+ ServiceCharge: pricingStrategy.ServiceCharge,
|
|
|
+ }
|
|
|
+ return &serviceFee, nil
|
|
|
+}
|