|
@@ -5,6 +5,7 @@ import (
|
|
|
"fmt"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
+ "time"
|
|
|
"youngee_m_api/db"
|
|
|
"youngee_m_api/model/common_model"
|
|
|
"youngee_m_api/model/gorm_model"
|
|
@@ -148,7 +149,7 @@ func (*project) GetProjectTaskList(ctx context.Context, projectID string, pageSi
|
|
|
}
|
|
|
|
|
|
func (*project) Create(ctx context.Context, newProject http_model.CreateProjectRequest, enterpriseID int64) (*http_model.CreateProjectData, error) {
|
|
|
- // build gorm_model.ProjectInfo
|
|
|
+ RecruitDdl, _ := time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
|
|
|
// 查询关联商品信息
|
|
|
product, err := db.GetProductByID(ctx, newProject.ProductID)
|
|
|
if err != nil {
|
|
@@ -159,12 +160,22 @@ 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, ",")
|
|
|
-
|
|
|
projectInfo := gorm_model.ProjectInfo{
|
|
|
ProjectName: projectName,
|
|
|
ProjectStatus: 1,
|
|
@@ -172,12 +183,14 @@ 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,
|
|
|
ProductID: newProject.ProductID,
|
|
|
FeeForm: feeFroms,
|
|
|
+ EstimatedCost: ECost,
|
|
|
+ IsRead: 0,
|
|
|
}
|
|
|
// db create ProjectInfo
|
|
|
projectID, err := db.CreateProject(ctx, projectInfo)
|
|
@@ -203,7 +216,15 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
|
|
|
}
|
|
|
// build
|
|
|
recruitStrategys := []gorm_model.RecruitStrategy{}
|
|
|
- for _, strategy := range newProject.RecruitStrategys {
|
|
|
+ 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,
|
|
@@ -229,15 +250,42 @@ func (*project) Create(ctx context.Context, newProject http_model.CreateProjectR
|
|
|
|
|
|
func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectRequest, enterpriseID int64) (*http_model.UpdateProjectData, error) {
|
|
|
//fmt.Println("newproject:", newProject)
|
|
|
+ RecruitDdl, _ := time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
|
|
|
+ oldProject, err3 := db.GetProjectDetail(ctx, conv.MustInt64(newProject.ProjectID, 0))
|
|
|
+ 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, 0),
|
|
|
- RecruitDdl: &newProject.RecruitDdl,
|
|
|
+ RecruitDdl: &RecruitDdl,
|
|
|
TalentType: newProject.TalentType,
|
|
|
ContentType: conv.MustInt64(newProject.ContentType, 0),
|
|
|
ProjectDetail: newProject.ProjectDetail,
|
|
|
ProjectForm: conv.MustInt64(newProject.ProjectForm, 0),
|
|
|
EnterpriseID: enterpriseID,
|
|
|
ProjectStatus: int64(newProject.ProjectStatus),
|
|
|
+ FeeForm: feeFroms,
|
|
|
+ EstimatedCost: ECost,
|
|
|
}
|
|
|
projectID, err := db.UpdateProject(ctx, project)
|
|
|
if err != nil {
|
|
@@ -275,6 +323,15 @@ 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, 0)/1000)
|
|
|
+ }
|
|
|
RecruitStrategy := gorm_model.RecruitStrategy{
|
|
|
FeeForm: conv.MustInt64(Strategy.FeeForm, 0),
|
|
|
StrategyID: conv.MustInt64(Strategy.StrategyID, 0),
|
|
@@ -471,3 +528,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
|
|
|
+}
|