Kaynağa Gözat

bug002andbug003

XingYuXian 1 yıl önce
ebeveyn
işleme
d8c5a7cf5f

+ 71 - 5
db/operate.go

@@ -279,6 +279,8 @@ func UpdateAutoTaskTime(ctx context.Context, time int32, num int32) error {
 		autoTaskInfo.LinkBreach = time
 	case 12:
 		autoTaskInfo.CaseCloseDefault = time
+	case 13:
+		autoTaskInfo.SelectionInvalid = time
 	}
 	autoTaskInfo.AutoTaskID += 1
 	err = db.Model(gorm_model.InfoAutoTask{}).Create(&autoTaskInfo).Error
@@ -943,18 +945,25 @@ func GetAutoCaseCloseTask() error {
 
 // GetAutoInvalidTask 全流程项目失效自动处理
 func GetAutoInvalidTask() error {
+	// 获取数据库链接
 	db := GetReadDB(context.Background())
+	// 指针类型数组 *gorm_model.ProjectInfo类型
 	var projectInfos []*gorm_model.ProjectInfo
+	// 查出来全部待支付状态的全流程项目
 	err := db.Model(gorm_model.ProjectInfo{}).Where("project_type = ? AND project_status = ? ", 1, 6).Find(&projectInfos).Error
 	if err != nil {
 		return err
 	}
+	// string型数组projectIds
 	var projectIds []string
+	// 空map "项目1":1
 	projectIdToAutoTaskIdMap := map[string]int{}
+	// 获取所有未支付的全流程项目ID与map{项目id:自动处理id}
 	for _, projectInfo := range projectInfos {
 		projectIds = append(projectIds, projectInfo.ProjectID)
 		projectIdToAutoTaskIdMap[projectInfo.ProjectID] = int(projectInfo.AutoTaskID)
 	}
+	// 对于所有的未支付的全流程项目
 	for _, projectId := range projectIds {
 		// 获取 autoTaskId 及其对应的限制时间
 		autoTaskId := projectIdToAutoTaskIdMap[projectId]
@@ -980,16 +989,18 @@ func GetAutoInvalidTask() error {
 		if project.AutoFailAt == nil || project.AutoFailAt.IsZero() {
 			db3 := GetReadDB(context.Background())
 			db3.Model(gorm_model.ProjectInfo{}).Where("project_id = ?", projectId).Updates(&gorm_model.ProjectInfo{AutoFailAt: &t})
-			fmt.Println("已添加失效自动处理时间")
+			fmt.Println("已添加全流程项目失效自动处理时间")
 		}
 
 		projectNeedMod := gorm_model.ProjectInfo{}
 		db2 := GetReadDB(context.Background())
 		db2 = db2.Where("project_id = ?", projectId).First(&projectNeedMod)
-		fmt.Println("失效自动处理时间为:", projectNeedMod.AutoFailAt)
+		fmt.Println("全流程项目失效自动处理时间为:", projectNeedMod.AutoFailAt)
+		// 失效自动处理的时间不为空
 		if !projectNeedMod.AutoFailAt.IsZero() || projectNeedMod.AutoFailAt != nil {
-			fmt.Printf("项目 %v 失效自动处理时间不为空\n", projectNeedMod.ProjectID)
-			fmt.Println("距离失效自动处理时间还有:,项目当前状态为", projectNeedMod.AutoFailAt.Sub(time.Now()), projectNeedMod.ProjectStatus)
+			fmt.Printf("全流程项目 %v 失效自动处理时间不为空\n", projectNeedMod.ProjectID)
+			fmt.Println("距离失效自动处理时间还有:,全流程项目当前状态为", projectNeedMod.AutoFailAt.Sub(time.Now()), projectNeedMod.ProjectStatus)
+			// 已经过了失效自动处理的时间 ProjectStatus == 8代表失效
 			if projectNeedMod.AutoFailAt.Sub(time.Now()) <= 0 && projectNeedMod.ProjectStatus < 8 {
 				db4 := GetReadDB(context.Background())
 				t := time.Now()
@@ -997,7 +1008,7 @@ func GetAutoInvalidTask() error {
 				if err1 != nil {
 					return err1
 				}
-				fmt.Println("已更新项目状态为超时未支付的失效状态")
+				fmt.Println("已更新全流程项目状态为超时未支付的失效状态")
 				dbT := GetReadDB(context.TODO())
 				dbT.Model(gorm_model.YoungeeTaskInfo{}).Where("project_id = ?", projectId).Updates(gorm_model.YoungeeTaskInfo{TaskStage: 3, CompleteStatus: 3, CompleteDate: time.Now()})
 			}
@@ -1006,6 +1017,61 @@ func GetAutoInvalidTask() error {
 	return nil
 }
 
+// GetAutoSelectionInvalidTask 选品项目的失效自动处理
+func GetAutoSelectionInvalidTask() error {
+	println("GetAutoSelectionInvalidTask is running ====-=-0=-0=-0=-0=--------=")
+	db := GetReadDB(context.Background())
+	var selectioninfos []*gorm_model.YounggeeSelectionInfo
+	err := db.Model(gorm_model.YounggeeSelectionInfo{}).Where("selection_status= ? AND task_mode = ? ", 4, 1).Find(&selectioninfos).Error
+	if err != nil {
+		return err
+	}
+	var selectionIds []string
+	selectionIdToAutoTaskIdMap := map[string]int{}
+	for _, selectionInfo := range selectioninfos {
+		selectionIds = append(selectionIds, selectionInfo.SelectionID)
+		selectionIdToAutoTaskIdMap[selectionInfo.SelectionID] = int(selectionInfo.AutoTaskID)
+	}
+	for _, selectionId := range selectionIds {
+		autoTaskId := selectionIdToAutoTaskIdMap[selectionId]
+		dbStart := GetReadDB(context.Background())
+		var SelectionInvalid int32
+		dbStart.Model(gorm_model.InfoAutoTask{}).Select("selectioninvalid").Where("auto_task_id = ?", autoTaskId).First(&SelectionInvalid)
+		db1 := GetReadDB(context.Background())
+		selection := gorm_model.YounggeeSelectionInfo{}
+		db1.Model(gorm_model.YounggeeSelectionInfo{}).Where("selection_id = ?", selectionId).First(&selection)
+		dd, _ := time.ParseDuration(conv.MustString(SelectionInvalid, "") + "h")
+		selection.PassAt.Add(dd)
+		t := selection.PassAt.Add(dd)
+		if selection.AutoFailAt == nil || selection.AutoFailAt.IsZero() {
+			db3 := GetReadDB(context.Background())
+			db3.Model(gorm_model.YounggeeSelectionInfo{}).Where("selection_id = ?", selectionId).Updates(&gorm_model.YounggeeSelectionInfo{AutoFailAt: &t})
+			fmt.Println("已添加选品任务失效自动处理时间")
+		}
+		selectionNeedMod := gorm_model.YounggeeSelectionInfo{}
+		db2 := GetReadDB(context.Background())
+		db2 = db2.Where("selection_id = ? ", selectionIds).First(&selectionNeedMod)
+		fmt.Println("选品项目失效自动处理时间为:", selectionNeedMod.AutoFailAt)
+
+		if !selectionNeedMod.AutoFailAt.IsZero() || selectionNeedMod.AutoFailAt != nil {
+			fmt.Printf("选品项目 %v 失效自动处理时间不为空\n", selectionNeedMod.SelectionID)
+			fmt.Println("距离失效自动处理时间还有:,选品项目当前状态为", selectionNeedMod.AutoFailAt.Sub(time.Now()), selectionNeedMod.SelectionStatus)
+			if selectionNeedMod.AutoFailAt.Sub(time.Now()) <= 0 && selectionNeedMod.SelectionStatus < 5 {
+				db4 := GetReadDB(context.Background())
+				t := time.Now()
+				err1 := db4.Model(gorm_model.YounggeeSelectionInfo{}).Where("selection_id = ?", selectionId).Updates(&gorm_model.YounggeeSelectionInfo{SelectionStatus: 7, FinishAt: &t, FailReason: 1}).Error
+				if err1 != nil {
+					return err
+				}
+				fmt.Println("已更新选品项目状态为超时未支付的失效状态")
+				dbT := GetReadDB(context.TODO())
+				dbT.Model(gorm_model.YounggeeSecTaskInfo{}).Where("selection_id = ? ", selectionIds).Updates(gorm_model.YounggeeSecTaskInfo{TaskStage: 3, CompleteStatus: 3, CompleteDate: time.Now()})
+			}
+		}
+	}
+	return nil
+}
+
 // GetAutoDraftDefaultInPicTask 图文-初稿超时违约判断
 func GetAutoDraftDefaultInPicTask() error {
 	db := GetReadDB(context.Background())

+ 1 - 1
handler/operate/SelectionInvalid.go

@@ -36,7 +36,7 @@ func (i selectioninvalidHandler) getRequest() interface{} {
 func (i selectioninvalidHandler) run() {
 	println("selectioninvalid===============")
 	time := i.req.Time
-	err := db.UpdateAutoTaskTime(i.ctx, time, 7)
+	err := db.UpdateAutoTaskTime(i.ctx, time, 13)
 	if err != nil {
 		logrus.WithContext(i.ctx).Errorf("[invalidHandler] error invalid, err:%+v", err)
 		util.HandlerPackErrorResp(i.resp, consts.ErrorInternal, consts.DefaultToast)

+ 24 - 23
model/gorm_model/auto_task.go

@@ -1,23 +1,24 @@
-package gorm_model
-
-// Code generated by sql2gorm. DO NOT EDIT.
-
-type InfoAutoTask struct {
-	AutoTaskID        int32 `gorm:"column:auto_task_id;primary_key;AUTO_INCREMENT"` // 自动处理规则id
-	SignInOffline     int32 `gorm:"column:sign_in_offline"`                         // 线下探店自动签收时间
-	SignInVirtual     int32 `gorm:"column:sign_in_virtual"`                         // 虚拟产品测评自动签收时间
-	ReviewInMv        int32 `gorm:"column:review_in_mv"`                            // 视频形式的审稿处理
-	ReviewUnlimited   int32 `gorm:"column:review_unlimited"`                        // 不限形式的审稿处理
-	Postreview        int32 `gorm:"column:postreview"`                              // 发布审核自动处理
-	CaseClose         int32 `gorm:"column:case_close"`                              // 结案自动处理
-	Invalid           int32 `gorm:"column:invalid"`                                 // 失效自动处理
-	DraftDefaultInPic int32 `gorm:"column:draft_default_in_pic"`                    // 图片初稿违约自动处理
-	DraftDefaultInMv  int32 `gorm:"column:draft_default_in_mv"`                     // 视频初稿违约自动处理
-	ScriptDefault     int32 `gorm:"column:script_default"`                          // 脚本违约自动处理
-	LinkBreach        int32 `gorm:"column:link_breach"`                             // 链接违约自动处理
-	CaseCloseDefault  int32 `gorm:"column:case_close_default"`                      // 结案违约自动处理
-}
-
-func (m *InfoAutoTask) TableName() string {
-	return "info_auto_task"
-}
+package gorm_model
+
+// Code generated by sql2gorm. DO NOT EDIT.
+
+type InfoAutoTask struct {
+	AutoTaskID        int32 `gorm:"column:auto_task_id;primary_key;AUTO_INCREMENT"` // 自动处理规则id
+	SignInOffline     int32 `gorm:"column:sign_in_offline"`                         // 线下探店自动签收时间
+	SignInVirtual     int32 `gorm:"column:sign_in_virtual"`                         // 虚拟产品测评自动签收时间
+	ReviewInMv        int32 `gorm:"column:review_in_mv"`                            // 视频形式的审稿处理
+	ReviewUnlimited   int32 `gorm:"column:review_unlimited"`                        // 不限形式的审稿处理
+	Postreview        int32 `gorm:"column:postreview"`                              // 发布审核自动处理
+	CaseClose         int32 `gorm:"column:case_close"`                              // 结案自动处理
+	Invalid           int32 `gorm:"column:invalid"`                                 // 全流程项目失效自动处理
+	DraftDefaultInPic int32 `gorm:"column:draft_default_in_pic"`                    // 图片初稿违约自动处理
+	DraftDefaultInMv  int32 `gorm:"column:draft_default_in_mv"`                     // 视频初稿违约自动处理
+	ScriptDefault     int32 `gorm:"column:script_default"`                          // 脚本违约自动处理
+	LinkBreach        int32 `gorm:"column:link_breach"`                             // 链接违约自动处理
+	CaseCloseDefault  int32 `gorm:"column:case_close_default"`                      // 结案违约自动处理
+	SelectionInvalid  int32 `gorm:"column:selectioninvalid"`                        // 选品项目失效自动处理
+}
+
+func (m *InfoAutoTask) TableName() string {
+	return "info_auto_task"
+}

+ 44 - 42
model/gorm_model/selection_info.go

@@ -1,42 +1,44 @@
-package gorm_model
-
-import (
-	"time"
-)
-
-type YounggeeSelectionInfo struct {
-	SelectionID      string    `gorm:"column:selection_id;primary_key"` // 选品项目id
-	SelectionName    string    `gorm:"column:selection_name"`           // 选品项目名称
-	EnterpriseID     string    `gorm:"column:enterprise_id"`            // 所属企业id
-	ProductID        int       `gorm:"column:product_id"`               // 关联商品id
-	ContentType      int       `gorm:"column:content_type"`             // 内容形式,1代表图文,2代表视频
-	SelectionStatus  int       `gorm:"column:selection_status"`         // 选品项目状态,1-8分别代表创建中、待审核、审核通过、待支付、已支付、执行中、失效、已结案
-	TaskMode         int       `gorm:"column:task_mode"`                // 任务形式,1、2分别表示悬赏任务、纯佣带货
-	Platform         int       `gorm:"column:platform"`                 // 项目平台,1-7分别代表小红书、抖音、微博、快手、b站、大众点评、知乎
-	SampleMode       int       `gorm:"column:sample_mode"`              // 领样形式,1、2分别表示免费领样、垫付领样
-	ProductUrl       string    `gorm:"column:product_url"`              // 带货链接
-	SampleNum        int       `gorm:"column:sample_num"`               // 样品数量
-	RemainNum        int       `gorm:"column:remain_num"`               // 剩余数量
-	CommissionRate   int       `gorm:"column:commission_rate"`          // 佣金比例
-	EstimatedCost    string    `gorm:"column:estimated_cost"`           // 预估成本
-	TaskReward       string    `gorm:"column:task_reward"`              // 任务悬赏
-	SampleCondition  string    `gorm:"column:sample_condition"`         // 领样条件
-	RewardCondition  string    `gorm:"column:reward_condition"`         // 返现悬赏条件
-	SettlementAmount string    `gorm:"column:settlement_amount"`        // 结算金额
-	TaskDdl          *time.Time `gorm:"column:task_ddl"`                 // 招募截止时间
-	Detail           string    `gorm:"column:detail"`                   // 卖点总结
-	ProductSnap      string    `gorm:"column:product_snap"`             // 商品信息快照
-	ProductPhotoSnap string    `gorm:"column:product_photo_snap"`       // 商品图片快照
-	CreatedAt        *time.Time `gorm:"column:created_at"`               // 创建时间
-	UpdatedAt        *time.Time `gorm:"column:updated_at"`               // 修改时间
-	SubmitAt         *time.Time `gorm:"column:submit_at"`                // 提交审核时间
-	PassAt           *time.Time `gorm:"column:pass_at"`                  // 审核通过时间
-	FailReason       int       `gorm:"column:fail_reason"`              // 失效原因,1、2分别表示逾期未支付、项目存在风险
-	PayAt            *time.Time `gorm:"column:pay_at"`                   // 支付时间
-	FinishAt         *time.Time `gorm:"column:finish_at"`                // 结案时间
-	IsRead           int       `gorm:"column:is_read"`                  // 是否已读
-}
-
-func (m *YounggeeSelectionInfo) TableName() string {
-	return "younggee_selection_info"
-}
+package gorm_model
+
+import (
+	"time"
+)
+
+type YounggeeSelectionInfo struct {
+	SelectionID      string     `gorm:"column:selection_id;primary_key"` // 选品项目id
+	SelectionName    string     `gorm:"column:selection_name"`           // 选品项目名称
+	EnterpriseID     string     `gorm:"column:enterprise_id"`            // 所属企业id
+	ProductID        int        `gorm:"column:product_id"`               // 关联商品id
+	ContentType      int        `gorm:"column:content_type"`             // 内容形式,1代表图文,2代表视频
+	SelectionStatus  int        `gorm:"column:selection_status"`         // 选品项目状态,1-8分别代表创建中、待审核、审核通过、待支付、已支付、执行中、失效、已结案
+	TaskMode         int        `gorm:"column:task_mode"`                // 任务形式,1、2分别表示悬赏任务、纯佣带货
+	Platform         int        `gorm:"column:platform"`                 // 项目平台,1-7分别代表小红书、抖音、微博、快手、b站、大众点评、知乎
+	SampleMode       int        `gorm:"column:sample_mode"`              // 领样形式,1、2分别表示免费领样、垫付领样
+	ProductUrl       string     `gorm:"column:product_url"`              // 带货链接
+	SampleNum        int        `gorm:"column:sample_num"`               // 样品数量
+	RemainNum        int        `gorm:"column:remain_num"`               // 剩余数量
+	CommissionRate   int        `gorm:"column:commission_rate"`          // 佣金比例
+	EstimatedCost    string     `gorm:"column:estimated_cost"`           // 预估成本
+	TaskReward       string     `gorm:"column:task_reward"`              // 任务悬赏
+	SampleCondition  string     `gorm:"column:sample_condition"`         // 领样条件
+	RewardCondition  string     `gorm:"column:reward_condition"`         // 返现悬赏条件
+	SettlementAmount string     `gorm:"column:settlement_amount"`        // 结算金额
+	TaskDdl          *time.Time `gorm:"column:task_ddl"`                 // 招募截止时间
+	Detail           string     `gorm:"column:detail"`                   // 卖点总结
+	ProductSnap      string     `gorm:"column:product_snap"`             // 商品信息快照
+	ProductPhotoSnap string     `gorm:"column:product_photo_snap"`       // 商品图片快照
+	CreatedAt        *time.Time `gorm:"column:created_at"`               // 创建时间
+	UpdatedAt        *time.Time `gorm:"column:updated_at"`               // 修改时间
+	SubmitAt         *time.Time `gorm:"column:submit_at"`                // 提交审核时间
+	PassAt           *time.Time `gorm:"column:pass_at"`                  // 审核通过时间
+	FailReason       int        `gorm:"column:fail_reason"`              // 失效原因,1、2分别表示逾期未支付、项目存在风险
+	PayAt            *time.Time `gorm:"column:pay_at"`                   // 支付时间
+	FinishAt         *time.Time `gorm:"column:finish_at"`                // 结案时间
+	IsRead           int        `gorm:"column:is_read"`                  // 是否已读
+	AutoTaskID       int        `gorm:"column:auto_task_id"`             // 定时任务id
+	AutoFailAt       *time.Time `gorm:"column:auto_fail_at"`             // 失效自动处理时间
+}
+
+func (m *YounggeeSelectionInfo) TableName() string {
+	return "younggee_selection_info"
+}

+ 21 - 2
service/auto_task.go

@@ -203,10 +203,25 @@ func AutoTask() error {
 		}
 		log.Println("GetAutoCaseCloseDefaultTask is running ,Time :", time.Now())
 	}
+	//定时任务13. 选品项目失效自动处理
+	task13 := func() {
+		println("AWdawdawdawdawd")
+		DB := db.GetReadDB(context.Background())
+		autoTaskTime := gorm_model.InfoAutoTask{}
+		DB.Model(gorm_model.InfoAutoTask{}).Last(&autoTaskTime)
+		if autoTaskTime.SelectionInvalid != 0 {
+			err := db.GetAutoSelectionInvalidTask()
+			if err != nil {
+				logrus.Error("[GetAutoInvalidTask] in DB error %+v", err)
+				return
+			}
+		}
+		log.Println("GetAutoSelectionInvalidTask is running ,Time :", time.Now())
+	}
 	//定时任务
-	//spec := "*/30 * * * * ?" //cron表达式,每30秒一次
+	spec := "*/30 * * * * ?" //cron表达式,每30秒一次
 	//spec := "0 */1 * * * ?" //cron表达式,每一分钟执行一次
-	spec := "0 0 * * * *" //每小时执行
+	//spec := "0 0 * * * *" //每小时执行
 	// 添加定时任务,
 	_, err := crontab.AddFunc("0 0 * * * *", taskKDStatus) //每小时执行一次快递是否签收的查询
 	//_, err := crontab.AddFunc("*/30 * * * * ?", taskKDStatus)
@@ -261,6 +276,10 @@ func AutoTask() error {
 	if err12 != nil {
 		return err12
 	}
+	_, err13 := crontab.AddFunc(spec, task13)
+	if err13 != nil {
+		return err13
+	}
 	// 启动定时器
 	crontab.Start()
 	// 定时任务是另起协程执行的,这里使用 select 简单阻塞.需要根据实际情况进行控制

+ 685 - 684
service/project.go

@@ -1,684 +1,685 @@
-package service
-
-import (
-	"context"
-	"encoding/json"
-	"fmt"
-	"math/rand"
-	"strconv"
-	"strings"
-	"time"
-	"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"
-	"youngee_m_api/util"
-
-	"github.com/caixw/lib.go/conv"
-	"github.com/gin-gonic/gin"
-	"github.com/sirupsen/logrus"
-)
-
-var Project *project
-
-type project struct {
-}
-
-func (*project) GetFullProjectList(ctx context.Context, pageSize, pageNum int32, condition *common_model.ProjectCondition, projectType string) (*http_model.FullProjectListData, error) {
-	fullProjects, total, err := db.GetFullProjectList(ctx, pageSize, pageNum, condition, projectType)
-	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) GetProjectDetail(ctx context.Context, projectID string) (*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)
-	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
-	}
-	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, ""),
-		AvailableBalance: conv.MustString(enterprise.AvailableBalance, ""),
-		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:       util.GetTimePointer(project.AutoFailAt),
-		SubmitAt:         util.GetTimePointer(project.SubmitAt),
-	}
-	Strategys, err := db.GetRecruitStrategys(ctx, projectID)
-	if err != nil {
-		logrus.WithContext(ctx).Error()
-		return nil, err
-	}
-	for _, strategy := range Strategys {
-		RecruitStrategy := http_model.ShowRecruitStrategy{
-			RecruitStrategyID: conv.MustString(strategy.RecruitStrategyID, ""),
-			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, ""),
-			ServiceCharge:     conv.MustString(strategy.ServiceCharge, ""),
-			SelectedNumber:    strategy.SelectedNumber,
-			WaitingNumber:     strategy.WaitingNumber,
-			DeliveredNumber:   strategy.DeliveredNumber,
-			SignedNumber:      strategy.SignedNumber,
-		}
-		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,
-			FileName: Photo.FileName,
-		}
-		ProjectDetail.ProjectPhotos = append(ProjectDetail.ProjectPhotos, ProjectPhoto)
-	}
-	return &ProjectDetail, 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
-}
-
-func (*project) GetAllProject(ctx context.Context, pageSize, pageNum int32) (*http_model.GetAllProjectData, error) {
-	allProjectPreviews, total, err := db.GetAllProject(ctx, pageSize, pageNum)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[project service] call GetAllProject error,err:%+v", err)
-		return nil, err
-	}
-	allProjects := new(http_model.GetAllProjectData)
-	allProjects.AllProjectPreview = pack.MGormAllProjectToHttpAllProjectPreview(allProjectPreviews)
-	allProjects.Total = conv.MustString(total, "")
-	return allProjects, nil
-}
-
-func (*project) GetProjectTaskList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TaskConditions) (*http_model.ProjectTaskListData, error) {
-	projectTasks, total, err := db.GetProjectTaskList(ctx, projectID, pageSize, pageNum, conditions)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[project service] call GetProjectTaskList error,err:%+v", err)
-		return nil, err
-	}
-	projectTaskListData := new(http_model.ProjectTaskListData)
-	projectTaskListData.ProjectTaskPreview = pack.MGormProjectTaskToHttpProjectTaskPreview(projectTasks)
-	projectTaskListData.Total = conv.MustString(total, "")
-	return projectTaskListData, nil
-}
-
-func (*project) Create(ctx context.Context, newProject http_model.CreateProjectRequest, enterpriseID string) (*http_model.CreateProjectData, error) {
-	fmt.Printf("newProject:%+v\n", newProject)
-	fmt.Println("newProject.RecruitDdl:", newProject.RecruitDdl)
-	RecruitDdl := time.Time{} //赋零值
-	if newProject.RecruitDdl != "" {
-		RecruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
-	}
-	// 查询关联商品信息
-	product, err := db.GetProductByID(ctx, newProject.ProductID)
-	if err != nil {
-		return nil, err
-	}
-	fmt.Println("product:", product)
-	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
-	var feeFrom []string
-	for _, strategy := range newProject.RecruitStrategys {
-		feeFrom = append(feeFrom, strconv.FormatInt(strategy.FeeForm, 10))
-	}
-	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
-		}
-	}
-	feeForms := strings.Join(feeFrom, ",")
-	projectInfo := gorm_model.ProjectInfo{}
-	rand.Seed(time.Now().UnixNano())
-	td := conv.MustString(time.Now().Day(), "")
-	for {
-		if len(td) == 3 {
-			break
-		}
-		td = "0" + td
-	}
-	fmt.Printf("RecruitDdl:%+v\n", RecruitDdl)
-	if newProject.ProjectType == int64(1) {
-		if newProject.RecruitDdl == "" {
-			projectInfo = gorm_model.ProjectInfo{
-				ProjectID:        conv.MustString(time.Now().Year(), "")[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000, ""),
-				ProjectName:      projectName,
-				ProjectStatus:    1,
-				ProjectType:      newProject.ProjectType,
-				TalentType:       newProject.TalentType,
-				ProjectPlatform:  newProject.ProjectPlatform,
-				ProjectForm:      newProject.ProjectForm,
-				ProjectDetail:    newProject.ProjectDetail,
-				ContentType:      newProject.ContentType,
-				EnterpriseID:     enterpriseID,
-				ProductID:        newProject.ProductID,
-				FeeForm:          feeForms,
-				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{
-				ProjectID:        conv.MustString(time.Now().Year(), "")[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000, ""),
-				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:          feeForms,
-				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{
-			ProjectID:        conv.MustString(time.Now().Year(), "")[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000, ""),
-			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:          feeForms,
-			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)
-	if err != nil {
-		return nil, err
-	}
-	if len(newProject.ProjectPhotos) != 0 {
-		var projectPhotos []gorm_model.ProjectPhoto
-		for _, photo := range newProject.ProjectPhotos {
-			projectPhoto := gorm_model.ProjectPhoto{
-				PhotoUrl:  photo.PhotoUrl,
-				PhotoUid:  photo.PhotoUid,
-				ProjectID: projectID,
-			}
-			projectPhotos = append(projectPhotos, projectPhoto)
-		}
-		// db create ProjectPhoto
-		err = db.CreateProjectPhoto(ctx, projectPhotos)
-		if err != nil {
-			return nil, err
-		}
-	}
-	// build
-	if newProject.ProjectType == int64(1) && newProject.RecruitStrategys != nil {
-		var 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
-		}
-	}
-	res := &http_model.CreateProjectData{
-		ProjectID: projectID,
-	}
-	return res, nil
-}
-
-func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectRequest, enterpriseID string) (*http_model.UpdateProjectData, error) {
-	//RecruitDdl, _ := time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
-	RecruitDdl := time.Time{} //赋零值
-	if newProject.RecruitDdl != "" {
-		RecruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
-	}
-	oldProject, err3 := db.GetProjectDetail(ctx, newProject.ProjectID)
-	if err3 != nil {
-		return nil, err3
-	}
-	var feeFrom []string
-	for _, strategy := range newProject.RecruitStrategys {
-		feeFrom = append(feeFrom, strconv.FormatInt(strategy.FeeForm, 10))
-	}
-	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
-		}
-	}
-	feeForms := strings.Join(feeFrom, ",")
-	t := time.Now()
-	project := gorm_model.ProjectInfo{}
-	if newProject.RecruitDdl == "" {
-		project = gorm_model.ProjectInfo{
-			ProjectType:   newProject.ProjectType,
-			ProjectID:     newProject.ProjectID,
-			TalentType:    newProject.TalentType,
-			ContentType:   conv.MustInt64(newProject.ContentType, 0),
-			ProjectDetail: newProject.ProjectDetail,
-			ProjectForm:   conv.MustInt64(newProject.ProjectForm, 0),
-			EnterpriseID:  enterpriseID,
-			ProjectStatus: newProject.ProjectStatus,
-			FeeForm:       feeForms,
-			EstimatedCost: ECost,
-			SubmitAt:      &t,
-		}
-	} else {
-		project = gorm_model.ProjectInfo{
-			ProjectType:   newProject.ProjectType,
-			ProjectID:     newProject.ProjectID,
-			RecruitDdl:    &RecruitDdl,
-			TalentType:    newProject.TalentType,
-			ContentType:   conv.MustInt64(newProject.ContentType, 0),
-			ProjectDetail: newProject.ProjectDetail,
-			ProjectForm:   conv.MustInt64(newProject.ProjectForm, 0),
-			EnterpriseID:  enterpriseID,
-			ProjectStatus: newProject.ProjectStatus,
-			FeeForm:       feeForms,
-			EstimatedCost: ECost,
-			SubmitAt:      &t,
-		}
-	}
-	projectID, err := db.UpdateProject(ctx, project)
-	if err != nil {
-		return nil, err
-	}
-	// 删除该项目之前的所有图片
-	err = db.DeleteProjectPhotoByProjectID(ctx, *projectID)
-	if err != nil {
-		return nil, err
-	}
-	fmt.Printf("照片:\t %+v\n", newProject.ProjectPhotos)
-	if len(newProject.ProjectPhotos) != 0 {
-		// 新增图片
-		var projectPhotos []gorm_model.ProjectPhoto
-		for _, photo := range newProject.ProjectPhotos {
-			projectPhoto := gorm_model.ProjectPhoto{
-				ProjectID: project.ProjectID,
-				PhotoUrl:  photo.PhotoUrl,
-				PhotoUid:  photo.PhotoUid,
-				FileName:  photo.FileName,
-			}
-			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("招募策略:%+v \n", newProject.RecruitStrategys)
-	if len(newProject.RecruitStrategys) != 0 && newProject.ProjectType == 1 {
-		// 新增策略
-		var 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:       Strategy.FeeForm,
-				StrategyID:    Strategy.StrategyID,
-				FollowersLow:  Strategy.FollowersLow,
-				FollowersUp:   Strategy.FollowersUp,
-				RecruitNumber: Strategy.RecruitNumber,
-				Offer:         Strategy.Offer,
-				TOffer:        Strategy.TOffer,
-				ServiceCharge: Strategy.ServiceCharge,
-				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) GetPorjectDetail(ctx context.Context, projectID string) (*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
-	}
-	ProjectDetail := http_model.ShowProjectData{
-		ProjectID:       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),
-	}
-	Strategys, err := db.GetRecruitStrategys(ctx, projectID)
-	fmt.Println("招募策略:", Strategys)
-	if err != nil {
-		logrus.WithContext(ctx).Error()
-		return nil, err
-	}
-	for _, strategy := range Strategys {
-		RecruitStrategy := http_model.ShowRecruitStrategy{
-			RecruitStrategyID: conv.MustString(strategy.RecruitStrategyID, ""),
-			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, ""),
-			ServiceCharge:     conv.MustString(strategy.ServiceCharge, ""),
-			SelectedNumber:    strategy.SelectedNumber,
-			WaitingNumber:     strategy.WaitingNumber,
-			DeliveredNumber:   strategy.DeliveredNumber,
-			SignedNumber:      strategy.SignedNumber,
-		}
-		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) GetTaskLogisticsList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskLogisticsListData, error) {
-	TaskLogisticss, total, err := db.GetTaskLogisticsList(ctx, projectID, pageSize, pageNum, conditions)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[project service] call GetTaskLogisticsList error,err:%+v", err)
-		return nil, err
-	}
-	TaskLogisticsListData := new(http_model.TaskLogisticsListData)
-	TaskLogisticsListData.TaskLogisticsPreview = pack.MGormTaskLogisticsInfoListToHttpTaskLogisticsPreviewList(TaskLogisticss)
-	TaskLogisticsListData.Total = conv.MustString(total, "")
-	return TaskLogisticsListData, nil
-}
-
-func (*project) GetSpecialProjectTaskList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.SpecialTaskLogisticsListData, error) {
-	SpecialTaskLogisticsListDatas, total, err := db.GetSpecialTaskLogisticsList(ctx, projectID, pageSize, pageNum, conditions)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[project service] call GetSpecialProjectTaskList error,err:%+v", err)
-		return nil, err
-	}
-	TaskLogisticsListData := new(http_model.SpecialTaskLogisticsListData)
-	TaskLogisticsListData.SpecialTaskLogisticsPreview = pack.MGormSpecialTaskLogisticsInfoListToHttpTaskLogisticsPreviewList(SpecialTaskLogisticsListDatas)
-	TaskLogisticsListData.Total = conv.MustString(total, "")
-	return TaskLogisticsListData, nil
-}
-
-func (*project) ChangeTaskStatus(ctx *gin.Context, data http_model.ProjectChangeTaskStatusRequest) interface{} {
-	fmt.Println("taskIds :", data.TaskIds)
-	fmt.Println("task_status :", data.TaskStatus)
-	RecruitStrategyIDs, err := db.ChangeTaskStatus(ctx, data.TaskIds, data.TaskStatus)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
-		return err
-	}
-	if data.TaskStatus == "2" {
-		for _, RecruitStrategyID := range RecruitStrategyIDs {
-			err = db.CalculateSelectedNumberByRecruitStrategyID(ctx, RecruitStrategyID, 1)
-			if err != nil {
-				logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
-				return err
-			}
-		}
-	} else if data.TaskStatus == "3" && data.ClickIndex != "0" {
-		for _, RecruitStrategyID := range RecruitStrategyIDs {
-			err = db.CalculateSelectedNumberByRecruitStrategyID(ctx, RecruitStrategyID, -1)
-			if err != nil {
-				logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
-				return err
-			}
-		}
-	}
-	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
-	}
-	for _, taskId := range data.TaskIds {
-		err = db.CreateMessageByTaskId(ctx, 7, 2, taskId)
-		if err != nil {
-			logrus.WithContext(ctx).Errorf("[project service] call CreateMessageByTaskId error,err:%+v", err)
-			return err
-		}
-	}
-	err = db.SetSpecialProjectFinish(ctx, data.ProjectId)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[project service] call CreateMessageByTaskId 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 {
-		logrus.WithContext(ctx).Errorf("[project service] call GetTaskScriptList error,err:%+v", err)
-		return nil, err
-	}
-	TaskScriptListData := new(http_model.TaskScriptListData)
-	TaskScriptListData.TaskScriptPreview = pack.MGormTaskScriptInfoListToHttpTaskScriptPreviewList(TaskScripts)
-	TaskScriptListData.Total = conv.MustString(total, "")
-	return TaskScriptListData, nil
-}
-
-func (p *project) GetTaskSketchList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskSketchListData, error) {
-	TaskSketchs, total, err := db.GetTaskSketchList(ctx, projectID, pageSize, pageNum, conditions)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[project service] call GetTaskSketchList error,err:%+v", err)
-		return nil, err
-	}
-	TaskSketchListData := new(http_model.TaskSketchListData)
-	TaskSketchListData.TaskSketchPreview = pack.MGormTaskSketchInfoListToHttpTaskSketchPreviewList(TaskSketchs)
-	TaskSketchListData.Total = conv.MustString(total, "")
-	return TaskSketchListData, nil
-}
-
-func (p *project) GetTaskLinkList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskLinkListData, error) {
-	TaskLinks, total, err := db.GetTaskLinkList(ctx, projectID, pageSize, pageNum, conditions)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[project service] call GetTaskLinkList error,err:%+v", err)
-		return nil, err
-	}
-	TaskLinkListData := new(http_model.TaskLinkListData)
-	TaskLinkListData.TaskLinkPreview = pack.MGormTaskLinkInfoListToHttpTaskLinkPreviewList(TaskLinks)
-	TaskLinkListData.Total = conv.MustString(total, "")
-	return TaskLinkListData, nil
-}
-
-func (p *project) GetTaskDataList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskDataListData, error) {
-	TaskDatas, total, err := db.GetTaskDataList(ctx, projectID, pageSize, pageNum, conditions)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[project service] call GetTaskDataList error,err:%+v", err)
-		return nil, err
-	}
-	TaskDataListData := new(http_model.TaskDataListData)
-	TaskDataListData.TaskDataPreview = pack.MGormTaskDataInfoListToHttpTaskDataPreviewList(TaskDatas)
-	TaskDataListData.Total = conv.MustString(total, "")
-	return TaskDataListData, nil
-}
-
-func (p *project) GetTaskFinishList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskFinishListData, error) {
-	TaskFinishs, total, err := db.GetTaskFinishList(ctx, pageSize, pageNum, conditions)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[project service] call GetTaskFinishList error,err:%+v", err)
-		return nil, err
-	}
-	TaskFinishListData := new(http_model.TaskFinishListData)
-	TaskFinishListData.TaskFinishPreview = pack.MGormTaskFinishInfoListToHttpTaskFinishPreviewList(TaskFinishs)
-	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
-}
+package service
+
+import (
+	"context"
+	"encoding/json"
+	"fmt"
+	"math/rand"
+	"strconv"
+	"strings"
+	"time"
+	"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"
+	"youngee_m_api/util"
+
+	"github.com/caixw/lib.go/conv"
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+)
+
+var Project *project
+
+type project struct {
+}
+
+func (*project) GetFullProjectList(ctx context.Context, pageSize, pageNum int32, condition *common_model.ProjectCondition, projectType string) (*http_model.FullProjectListData, error) {
+	fullProjects, total, err := db.GetFullProjectList(ctx, pageSize, pageNum, condition, projectType)
+	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) GetProjectDetail(ctx context.Context, projectID string) (*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)
+	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
+	}
+	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, ""),
+		AvailableBalance: conv.MustString(enterprise.AvailableBalance, ""),
+		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:       util.GetTimePointer(project.AutoFailAt),
+		SubmitAt:         util.GetTimePointer(project.SubmitAt),
+	}
+	Strategys, err := db.GetRecruitStrategys(ctx, projectID)
+	if err != nil {
+		logrus.WithContext(ctx).Error()
+		return nil, err
+	}
+	for _, strategy := range Strategys {
+		RecruitStrategy := http_model.ShowRecruitStrategy{
+			RecruitStrategyID: conv.MustString(strategy.RecruitStrategyID, ""),
+			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, ""),
+			ServiceCharge:     conv.MustString(strategy.ServiceCharge, ""),
+			SelectedNumber:    strategy.SelectedNumber,
+			WaitingNumber:     strategy.WaitingNumber,
+			DeliveredNumber:   strategy.DeliveredNumber,
+			SignedNumber:      strategy.SignedNumber,
+		}
+		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,
+			FileName: Photo.FileName,
+		}
+		ProjectDetail.ProjectPhotos = append(ProjectDetail.ProjectPhotos, ProjectPhoto)
+	}
+	return &ProjectDetail, 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
+}
+
+func (*project) GetAllProject(ctx context.Context, pageSize, pageNum int32) (*http_model.GetAllProjectData, error) {
+	allProjectPreviews, total, err := db.GetAllProject(ctx, pageSize, pageNum)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[project service] call GetAllProject error,err:%+v", err)
+		return nil, err
+	}
+	allProjects := new(http_model.GetAllProjectData)
+	allProjects.AllProjectPreview = pack.MGormAllProjectToHttpAllProjectPreview(allProjectPreviews)
+	allProjects.Total = conv.MustString(total, "")
+	return allProjects, nil
+}
+
+func (*project) GetProjectTaskList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TaskConditions) (*http_model.ProjectTaskListData, error) {
+	projectTasks, total, err := db.GetProjectTaskList(ctx, projectID, pageSize, pageNum, conditions)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[project service] call GetProjectTaskList error,err:%+v", err)
+		return nil, err
+	}
+	projectTaskListData := new(http_model.ProjectTaskListData)
+	projectTaskListData.ProjectTaskPreview = pack.MGormProjectTaskToHttpProjectTaskPreview(projectTasks)
+	projectTaskListData.Total = conv.MustString(total, "")
+	return projectTaskListData, nil
+}
+
+func (*project) Create(ctx context.Context, newProject http_model.CreateProjectRequest, enterpriseID string) (*http_model.CreateProjectData, error) {
+	fmt.Printf("newProject:%+v\n", newProject)
+	fmt.Println("newProject.RecruitDdl:", newProject.RecruitDdl)
+	RecruitDdl := time.Time{} //赋零值
+	if newProject.RecruitDdl != "" {
+		RecruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
+	}
+	// 查询关联商品信息
+	product, err := db.GetProductByID(ctx, newProject.ProductID)
+	if err != nil {
+		return nil, err
+	}
+	fmt.Println("product:", product)
+	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
+	var feeFrom []string
+	for _, strategy := range newProject.RecruitStrategys {
+		feeFrom = append(feeFrom, strconv.FormatInt(strategy.FeeForm, 10))
+	}
+	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
+		}
+	}
+	feeForms := strings.Join(feeFrom, ",")
+	projectInfo := gorm_model.ProjectInfo{}
+	rand.Seed(time.Now().UnixNano())
+	td := conv.MustString(time.Now().Day(), "")
+	for {
+		if len(td) == 3 {
+			break
+		}
+		td = "0" + td
+	}
+	fmt.Printf("RecruitDdl:%+v\n", RecruitDdl)
+	// 全流程项目
+	if newProject.ProjectType == int64(1) {
+		if newProject.RecruitDdl == "" { // 招募截止时间为空
+			projectInfo = gorm_model.ProjectInfo{
+				ProjectID:        conv.MustString(time.Now().Year(), "")[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000, ""),
+				ProjectName:      projectName,
+				ProjectStatus:    1,
+				ProjectType:      newProject.ProjectType,
+				TalentType:       newProject.TalentType,
+				ProjectPlatform:  newProject.ProjectPlatform,
+				ProjectForm:      newProject.ProjectForm,
+				ProjectDetail:    newProject.ProjectDetail,
+				ContentType:      newProject.ContentType,
+				EnterpriseID:     enterpriseID,
+				ProductID:        newProject.ProductID,
+				FeeForm:          feeForms,
+				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{
+				ProjectID:        conv.MustString(time.Now().Year(), "")[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000, ""),
+				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:          feeForms,
+				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{
+			ProjectID:        conv.MustString(time.Now().Year(), "")[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000, ""),
+			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:          feeForms,
+			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)
+	if err != nil {
+		return nil, err
+	}
+	if len(newProject.ProjectPhotos) != 0 {
+		var projectPhotos []gorm_model.ProjectPhoto
+		for _, photo := range newProject.ProjectPhotos {
+			projectPhoto := gorm_model.ProjectPhoto{
+				PhotoUrl:  photo.PhotoUrl,
+				PhotoUid:  photo.PhotoUid,
+				ProjectID: projectID,
+			}
+			projectPhotos = append(projectPhotos, projectPhoto)
+		}
+		// db create ProjectPhoto
+		err = db.CreateProjectPhoto(ctx, projectPhotos)
+		if err != nil {
+			return nil, err
+		}
+	}
+	// build
+	if newProject.ProjectType == int64(1) && newProject.RecruitStrategys != nil {
+		var 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
+		}
+	}
+	res := &http_model.CreateProjectData{
+		ProjectID: projectID,
+	}
+	return res, nil
+}
+
+func (*project) Update(ctx context.Context, newProject http_model.UpdateProjectRequest, enterpriseID string) (*http_model.UpdateProjectData, error) {
+	//RecruitDdl, _ := time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
+	RecruitDdl := time.Time{} //赋零值
+	if newProject.RecruitDdl != "" {
+		RecruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", newProject.RecruitDdl, time.Local)
+	}
+	oldProject, err3 := db.GetProjectDetail(ctx, newProject.ProjectID)
+	if err3 != nil {
+		return nil, err3
+	}
+	var feeFrom []string
+	for _, strategy := range newProject.RecruitStrategys {
+		feeFrom = append(feeFrom, strconv.FormatInt(strategy.FeeForm, 10))
+	}
+	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
+		}
+	}
+	feeForms := strings.Join(feeFrom, ",")
+	t := time.Now()
+	project := gorm_model.ProjectInfo{}
+	if newProject.RecruitDdl == "" {
+		project = gorm_model.ProjectInfo{
+			ProjectType:   newProject.ProjectType,
+			ProjectID:     newProject.ProjectID,
+			TalentType:    newProject.TalentType,
+			ContentType:   conv.MustInt64(newProject.ContentType, 0),
+			ProjectDetail: newProject.ProjectDetail,
+			ProjectForm:   conv.MustInt64(newProject.ProjectForm, 0),
+			EnterpriseID:  enterpriseID,
+			ProjectStatus: newProject.ProjectStatus,
+			FeeForm:       feeForms,
+			EstimatedCost: ECost,
+			SubmitAt:      &t,
+		}
+	} else {
+		project = gorm_model.ProjectInfo{
+			ProjectType:   newProject.ProjectType,
+			ProjectID:     newProject.ProjectID,
+			RecruitDdl:    &RecruitDdl,
+			TalentType:    newProject.TalentType,
+			ContentType:   conv.MustInt64(newProject.ContentType, 0),
+			ProjectDetail: newProject.ProjectDetail,
+			ProjectForm:   conv.MustInt64(newProject.ProjectForm, 0),
+			EnterpriseID:  enterpriseID,
+			ProjectStatus: newProject.ProjectStatus,
+			FeeForm:       feeForms,
+			EstimatedCost: ECost,
+			SubmitAt:      &t,
+		}
+	}
+	projectID, err := db.UpdateProject(ctx, project)
+	if err != nil {
+		return nil, err
+	}
+	// 删除该项目之前的所有图片
+	err = db.DeleteProjectPhotoByProjectID(ctx, *projectID)
+	if err != nil {
+		return nil, err
+	}
+	fmt.Printf("照片:\t %+v\n", newProject.ProjectPhotos)
+	if len(newProject.ProjectPhotos) != 0 {
+		// 新增图片
+		var projectPhotos []gorm_model.ProjectPhoto
+		for _, photo := range newProject.ProjectPhotos {
+			projectPhoto := gorm_model.ProjectPhoto{
+				ProjectID: project.ProjectID,
+				PhotoUrl:  photo.PhotoUrl,
+				PhotoUid:  photo.PhotoUid,
+				FileName:  photo.FileName,
+			}
+			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("招募策略:%+v \n", newProject.RecruitStrategys)
+	if len(newProject.RecruitStrategys) != 0 && newProject.ProjectType == 1 {
+		// 新增策略
+		var 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:       Strategy.FeeForm,
+				StrategyID:    Strategy.StrategyID,
+				FollowersLow:  Strategy.FollowersLow,
+				FollowersUp:   Strategy.FollowersUp,
+				RecruitNumber: Strategy.RecruitNumber,
+				Offer:         Strategy.Offer,
+				TOffer:        Strategy.TOffer,
+				ServiceCharge: Strategy.ServiceCharge,
+				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) GetPorjectDetail(ctx context.Context, projectID string) (*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
+	}
+	ProjectDetail := http_model.ShowProjectData{
+		ProjectID:       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),
+	}
+	Strategys, err := db.GetRecruitStrategys(ctx, projectID)
+	fmt.Println("招募策略:", Strategys)
+	if err != nil {
+		logrus.WithContext(ctx).Error()
+		return nil, err
+	}
+	for _, strategy := range Strategys {
+		RecruitStrategy := http_model.ShowRecruitStrategy{
+			RecruitStrategyID: conv.MustString(strategy.RecruitStrategyID, ""),
+			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, ""),
+			ServiceCharge:     conv.MustString(strategy.ServiceCharge, ""),
+			SelectedNumber:    strategy.SelectedNumber,
+			WaitingNumber:     strategy.WaitingNumber,
+			DeliveredNumber:   strategy.DeliveredNumber,
+			SignedNumber:      strategy.SignedNumber,
+		}
+		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) GetTaskLogisticsList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskLogisticsListData, error) {
+	TaskLogisticss, total, err := db.GetTaskLogisticsList(ctx, projectID, pageSize, pageNum, conditions)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[project service] call GetTaskLogisticsList error,err:%+v", err)
+		return nil, err
+	}
+	TaskLogisticsListData := new(http_model.TaskLogisticsListData)
+	TaskLogisticsListData.TaskLogisticsPreview = pack.MGormTaskLogisticsInfoListToHttpTaskLogisticsPreviewList(TaskLogisticss)
+	TaskLogisticsListData.Total = conv.MustString(total, "")
+	return TaskLogisticsListData, nil
+}
+
+func (*project) GetSpecialProjectTaskList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.SpecialTaskLogisticsListData, error) {
+	SpecialTaskLogisticsListDatas, total, err := db.GetSpecialTaskLogisticsList(ctx, projectID, pageSize, pageNum, conditions)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[project service] call GetSpecialProjectTaskList error,err:%+v", err)
+		return nil, err
+	}
+	TaskLogisticsListData := new(http_model.SpecialTaskLogisticsListData)
+	TaskLogisticsListData.SpecialTaskLogisticsPreview = pack.MGormSpecialTaskLogisticsInfoListToHttpTaskLogisticsPreviewList(SpecialTaskLogisticsListDatas)
+	TaskLogisticsListData.Total = conv.MustString(total, "")
+	return TaskLogisticsListData, nil
+}
+
+func (*project) ChangeTaskStatus(ctx *gin.Context, data http_model.ProjectChangeTaskStatusRequest) interface{} {
+	fmt.Println("taskIds :", data.TaskIds)
+	fmt.Println("task_status :", data.TaskStatus)
+	RecruitStrategyIDs, err := db.ChangeTaskStatus(ctx, data.TaskIds, data.TaskStatus)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
+		return err
+	}
+	if data.TaskStatus == "2" {
+		for _, RecruitStrategyID := range RecruitStrategyIDs {
+			err = db.CalculateSelectedNumberByRecruitStrategyID(ctx, RecruitStrategyID, 1)
+			if err != nil {
+				logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
+				return err
+			}
+		}
+	} else if data.TaskStatus == "3" && data.ClickIndex != "0" {
+		for _, RecruitStrategyID := range RecruitStrategyIDs {
+			err = db.CalculateSelectedNumberByRecruitStrategyID(ctx, RecruitStrategyID, -1)
+			if err != nil {
+				logrus.WithContext(ctx).Errorf("[project service] call ChangeTaskStatus error,err:%+v", err)
+				return err
+			}
+		}
+	}
+	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
+	}
+	for _, taskId := range data.TaskIds {
+		err = db.CreateMessageByTaskId(ctx, 7, 2, taskId)
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[project service] call CreateMessageByTaskId error,err:%+v", err)
+			return err
+		}
+	}
+	err = db.SetSpecialProjectFinish(ctx, data.ProjectId)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[project service] call CreateMessageByTaskId 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 {
+		logrus.WithContext(ctx).Errorf("[project service] call GetTaskScriptList error,err:%+v", err)
+		return nil, err
+	}
+	TaskScriptListData := new(http_model.TaskScriptListData)
+	TaskScriptListData.TaskScriptPreview = pack.MGormTaskScriptInfoListToHttpTaskScriptPreviewList(TaskScripts)
+	TaskScriptListData.Total = conv.MustString(total, "")
+	return TaskScriptListData, nil
+}
+
+func (p *project) GetTaskSketchList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskSketchListData, error) {
+	TaskSketchs, total, err := db.GetTaskSketchList(ctx, projectID, pageSize, pageNum, conditions)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[project service] call GetTaskSketchList error,err:%+v", err)
+		return nil, err
+	}
+	TaskSketchListData := new(http_model.TaskSketchListData)
+	TaskSketchListData.TaskSketchPreview = pack.MGormTaskSketchInfoListToHttpTaskSketchPreviewList(TaskSketchs)
+	TaskSketchListData.Total = conv.MustString(total, "")
+	return TaskSketchListData, nil
+}
+
+func (p *project) GetTaskLinkList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskLinkListData, error) {
+	TaskLinks, total, err := db.GetTaskLinkList(ctx, projectID, pageSize, pageNum, conditions)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[project service] call GetTaskLinkList error,err:%+v", err)
+		return nil, err
+	}
+	TaskLinkListData := new(http_model.TaskLinkListData)
+	TaskLinkListData.TaskLinkPreview = pack.MGormTaskLinkInfoListToHttpTaskLinkPreviewList(TaskLinks)
+	TaskLinkListData.Total = conv.MustString(total, "")
+	return TaskLinkListData, nil
+}
+
+func (p *project) GetTaskDataList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskDataListData, error) {
+	TaskDatas, total, err := db.GetTaskDataList(ctx, projectID, pageSize, pageNum, conditions)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[project service] call GetTaskDataList error,err:%+v", err)
+		return nil, err
+	}
+	TaskDataListData := new(http_model.TaskDataListData)
+	TaskDataListData.TaskDataPreview = pack.MGormTaskDataInfoListToHttpTaskDataPreviewList(TaskDatas)
+	TaskDataListData.Total = conv.MustString(total, "")
+	return TaskDataListData, nil
+}
+
+func (p *project) GetTaskFinishList(ctx *gin.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) (*http_model.TaskFinishListData, error) {
+	TaskFinishs, total, err := db.GetTaskFinishList(ctx, pageSize, pageNum, conditions)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[project service] call GetTaskFinishList error,err:%+v", err)
+		return nil, err
+	}
+	TaskFinishListData := new(http_model.TaskFinishListData)
+	TaskFinishListData.TaskFinishPreview = pack.MGormTaskFinishInfoListToHttpTaskFinishPreviewList(TaskFinishs)
+	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
+}

+ 369 - 356
service/selection.go

@@ -1,356 +1,369 @@
-package service
-
-import (
-	"context"
-	"encoding/json"
-	"errors"
-	"fmt"
-	"reflect"
-	"time"
-	"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"
-	"youngee_m_api/util"
-
-	"github.com/gin-gonic/gin"
-	"github.com/sirupsen/logrus"
-
-	"github.com/caixw/lib.go/conv"
-)
-
-var Selection *selection
-
-type selection struct {
-}
-
-func (*selection) Create(ctx context.Context, request http_model.CreateSelectionRequest) (*http_model.CreateSelectionData, error) {
-	enterpriseId := request.EnterpriseId
-	// 1. 检查该企业id和商品id有无选品
-	//selectionInfo, err := db.GetSelectionByEnterpiseIdAndProductId(ctx, enterpriseId, conv.MustInt(request.ProductId, 0))
-	//if err != nil {
-	//	return nil, err
-	//}
-	//if selectionInfo != nil {
-	//	return nil, errors.New("该商品下选品已存在")
-	//}
-
-	// 2. 数据准备
-	// a) 生成选品id
-	selectionId := util.GetSelectionID()
-	// b) 查找关联商品信息
-	product, err := db.GetProductByID(ctx, conv.MustInt64(request.ProductId, 0))
-	if err != nil {
-		return nil, err
-	}
-	productPhotos, err := db.GetProductPhotoByProductID(ctx, conv.MustInt64(request.ProductId, 0))
-	productInfoToJson, _ := json.Marshal(product)
-	productPhotosToJson, _ := json.Marshal(productPhotos)
-	// c) 选品名称
-	selectionName := product.BrandName + "-" + product.ProductName
-
-	// 3. 创建选品
-	//taskDdl := time.Time{} //赋零值
-	//taskDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", "2026-01-01 08:00:00", time.Local)
-	t := time.Now()
-	newSelection := gorm_model.YounggeeSelectionInfo{
-		SelectionStatus:  1,
-		SelectionID:      selectionId,
-		SelectionName:    selectionName,
-		ProductID:        conv.MustInt(request.ProductId, 0),
-		EnterpriseID:     enterpriseId,
-		Platform:         conv.MustInt(request.Platform, 0),
-		ProductSnap:      string(productInfoToJson),
-		ProductPhotoSnap: string(productPhotosToJson),
-		CreatedAt:        &t,
-		UpdatedAt:        &t,
-		EstimatedCost:    "0",
-		TaskReward:       "0",
-		SettlementAmount: "0",
-	}
-	//Selection := gorm_model.YounggeeSelectionInfo{}
-	err = db.CreateSelection(ctx, newSelection)
-	if err != nil {
-		return nil, err
-	}
-
-	res := &http_model.CreateSelectionData{
-		SelectionId: selectionId,
-	}
-	return res, nil
-}
-
-func (*selection) Update(ctx context.Context, request http_model.UpdateSelectionRequest, enterpriseId string) (*http_model.UpdateSelectionData, error) {
-	// 1. 检查该企业id和商品id有无选品
-	selectionInfo, err := db.GetSelectionById(ctx, request.SelectionID)
-	if err != nil {
-		return nil, err
-	}
-	if selectionInfo == nil {
-		return nil, errors.New("选品不存在")
-	}
-
-	// 2. 数据准备
-	// a) 查找关联商品信息
-	product, err := db.GetProductByID(ctx, conv.MustInt64(request.ProductId, 0))
-	if err != nil {
-		return nil, err
-	}
-	productPhotos, err := db.GetProductPhotoByProductID(ctx, conv.MustInt64(request.ProductId, 0))
-	productInfoToJson, _ := json.Marshal(product)
-	productPhotosToJson, _ := json.Marshal(productPhotos)
-	// b) 选品名称
-	selectionName := product.BrandName + "-" + product.ProductName
-	// d) 任务截止时间
-	fmt.Println("taskDdl:", request.TaskDdl)
-	taskDdl := time.Time{} //赋零值
-	taskDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", request.TaskDdl, time.Local)
-	// f) 更新选品状态
-	if request.SelectionStatus != 2 && request.SelectionStatus != 7 {
-		request.SelectionStatus = 1
-	}
-	t := time.Now()
-	updateSelection := gorm_model.YounggeeSelectionInfo{
-		SelectionID:      request.SelectionID,
-		SelectionStatus:  request.SelectionStatus,
-		SelectionName:    selectionName,
-		EnterpriseID:     enterpriseId,
-		ProductID:        conv.MustInt(request.ProductId, 0),
-		ContentType:      conv.MustInt(request.ContentType, 0),
-		TaskMode:         conv.MustInt(request.TaskMode, 0),
-		Platform:         conv.MustInt(request.Platform, 0),
-		SampleMode:       conv.MustInt(request.SampleMode, 0),
-		ProductUrl:       request.ProductUrl,
-		SampleNum:        conv.MustInt(request.SampleNum, 0),
-		RemainNum:        conv.MustInt(request.SampleNum, 0),
-		CommissionRate:   conv.MustInt(request.CommissionRate, 0),
-		TaskReward:       conv.MustString(request.TaskReward, "0"),
-		SettlementAmount: conv.MustString(request.SettlementAmount, "0"),
-		EstimatedCost:    selectionInfo.EstimatedCost,
-		SampleCondition:  request.SampleCondition,
-		RewardCondition:  request.RewardCondition,
-		TaskDdl:          &taskDdl,
-		Detail:           request.Detail,
-		ProductSnap:      string(productInfoToJson),
-		ProductPhotoSnap: string(productPhotosToJson),
-		CreatedAt:        selectionInfo.CreatedAt,
-		UpdatedAt:        &t,
-	}
-	if request.SelectionStatus == 2 {
-		updateSelection.SubmitAt = &t
-	}
-	// 合并传入参数和数据表中原记录,若传入参数字段值为空,则将字段赋值为原记录中值
-	result := util.MergeStructValue(&updateSelection, selectionInfo)
-	// 利用反射机制将interface类型转换为结构体类型
-	v := reflect.ValueOf(&result).Elem()
-	if v.Kind() == reflect.Struct {
-		updateSelection = v.Interface().(gorm_model.YounggeeSelectionInfo)
-		//fmt.Println(p)
-	}
-	// c) 计算预估成本(如果有)
-	var estimatedCost float64
-	if conv.MustInt(updateSelection.TaskMode, 0) == 1 {
-		estimatedCost = conv.MustFloat64(updateSelection.TaskReward, 0) * conv.MustFloat64(updateSelection.SampleNum, 0)
-	}
-	estimatedCostToString, _ := conv.String(estimatedCost)
-	updateSelection.EstimatedCost = estimatedCostToString
-
-	// 3. 更新选品
-	err = db.UpdateSelection(ctx, updateSelection)
-	if err != nil {
-		return nil, err
-	}
-
-	// 4. 更新选品brief和示例
-	if request.SecBrief != nil {
-		// 删除已有brief
-		err = db.DeleteSecBriefBySelectionId(ctx, selectionInfo.SelectionID)
-		if err != nil {
-			return nil, err
-		}
-		// 插入新的brief
-		for _, v := range request.SecBrief {
-			brief := gorm_model.YounggeeSecBrief{
-				SelectionID: selectionInfo.SelectionID,
-				FileUid:     v.PhotoUid,
-				FileName:    v.Name,
-				FileUrl:     v.PhotoUrl,
-				CreatedAt:   time.Now(),
-			}
-			err = db.CreateSecBrief(ctx, brief)
-			if err != nil {
-				return nil, err
-			}
-		}
-	}
-
-	if request.SecExample != nil {
-		// 删除已有示例
-		err = db.DeleteSecExampleBySelectionId(ctx, selectionInfo.SelectionID)
-		if err != nil {
-			return nil, err
-		}
-		// 插入新的示例
-		for _, v := range request.SecExample {
-			Example := gorm_model.YounggeeSecExample{
-				SelectionID: selectionInfo.SelectionID,
-				FileUid:     v.PhotoUid,
-				FileName:    v.Name,
-				FileUrl:     v.PhotoUrl,
-				CreatedAt:   time.Now(),
-			}
-			err = db.CreateSecExample(ctx, Example)
-			if err != nil {
-				return nil, err
-			}
-		}
-	}
-
-	res := &http_model.UpdateSelectionData{
-		SelectionId: updateSelection.SelectionID,
-	}
-	return res, nil
-}
-
-func (*selection) Pay(ctx context.Context, request http_model.PaySelectionRequest, enterpriseId string) (*http_model.PaySelectionData, error) {
-	// 校验
-	// 1. 账户余额是否足够
-	enterprise, err := db.GetEnterpriseByEnterpriseID(ctx, enterpriseId)
-	if err != nil {
-		return nil, err
-	}
-	if enterprise.AvailableBalance < request.PayMoney {
-		return nil, errors.New("账户余额不足")
-	}
-	// 2. 选品项目状态是否正确
-	selectionInfo, err := db.GetSelectionById(ctx, request.SelectionId)
-	if err != nil {
-		return nil, err
-	}
-	if selectionInfo == nil {
-		return nil, errors.New("选品不存在")
-	}
-	if selectionInfo.SelectionStatus != 4 {
-		return nil, errors.New("选品状态有误")
-	}
-
-	// 支付
-	err = db.PaySelection(ctx, enterpriseId, request.PayMoney, request.SelectionId)
-	if err != nil {
-		return nil, err
-	}
-
-	res := &http_model.PaySelectionData{
-		SelectionId: request.SelectionId,
-	}
-	return res, nil
-}
-
-func (*selection) Submit(ctx context.Context, request http_model.SubmitSelectionRequest) (*http_model.SubmitSelectionData, error) {
-	t := time.Now()
-	updateSelection := gorm_model.YounggeeSelectionInfo{
-		SelectionID:     request.SelectionId,
-		SelectionStatus: request.SelectionStatus,
-		SubmitAt:        &t,
-	}
-
-	err := db.UpdateSelection(ctx, updateSelection)
-	if err != nil {
-		return nil, err
-	}
-
-	res := &http_model.SubmitSelectionData{}
-	return res, nil
-}
-
-func (s *selection) GetAllSelection(ctx context.Context, enterpriseID string, pageSize, pageNum int64, conditions *common_model.SelectionConditions) (*http_model.SelectionData, error) {
-	SelectionList, total, err := db.GetSelectionList(ctx, enterpriseID, pageSize, pageNum, conditions)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetAllSelection error,err:%+v", err)
-		return nil, err
-	}
-	SelectionListData := new(http_model.SelectionData)
-	SelectionListData.SelectionInfo = pack.MGormSelectionToHttpSelectionPreview(SelectionList)
-	SelectionListData.Total = conv.MustString(total, "")
-	return SelectionListData, nil
-}
-
-func (s *selection) GetSelectionDetail(ctx *gin.Context, selectionId string, enterpriseId string) (*http_model.SelectionDetail, error) {
-	selectionDetail := http_model.SelectionDetail{}
-	selectionInfo, err := db.GetSelectionById(ctx, selectionId)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetSelectionInfo error,err:%+v", err)
-		return nil, err
-	}
-	selectionBriefInfo, err := db.GetSelectionBriefInfo(ctx, selectionId)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetSelectionBriefInfo error,err:%+v", err)
-		return nil, err
-	}
-	selectionExampleInfo, err := db.GetSelectionExampleInfo(ctx, selectionId)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetSelectionExampleInfo error,err:%+v", err)
-		return nil, err
-	}
-	productInfo, err := db.GetProductInfoBySelectionId(ctx, selectionId)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetProductInfo error,err:%+v", err)
-		return nil, err
-	}
-	productPhotoInfo, err := db.GetProductPhotoInfoBySelectionId(ctx, selectionId)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetProductPhotoInfo error,err:%+v", err)
-		return nil, err
-	}
-	selectionDetail.SelectionBrief = selectionBriefInfo
-	selectionDetail.SelectionInfo = selectionInfo
-	selectionDetail.SelectionExample = selectionExampleInfo
-	selectionDetail.ProductInfo = productInfo
-	selectionDetail.ProductPhotoInfo = productPhotoInfo
-	return &selectionDetail, nil
-}
-
-func (*selection) Review(ctx context.Context, request http_model.ReviewSelectionRequest) (*http_model.ReviewSelectionData, error) {
-	// 根据选品id查询选品信息
-	selectionInfo, err := db.GetSelectionById(ctx, request.SelectionId)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetSelectionById error,err:%+v", err)
-		return nil, err
-	}
-
-	// 计算预估成本
-	var estimatedCost float64 = 0.0
-	var estimatedCostToString string = ""
-	if conv.MustInt(selectionInfo.TaskMode, 0) == 1 {
-		estimatedCost = conv.MustFloat64(selectionInfo.TaskReward, 0) * conv.MustFloat64(selectionInfo.SampleNum, 0)
-		estimatedCostToString, _ = conv.String(estimatedCost)
-	}
-
-	// 若审核通过则更新选品阶段为待支付,否则更新为失效并赋值失效原因
-	t := time.Now()
-	updateSelection := gorm_model.YounggeeSelectionInfo{}
-	if request.IsPass == 1 {
-		updateSelection = gorm_model.YounggeeSelectionInfo{
-			SelectionID:     request.SelectionId,
-			SelectionStatus: 4,
-			PassAt:          &t,
-			EstimatedCost:   estimatedCostToString,
-		}
-	} else {
-		updateSelection = gorm_model.YounggeeSelectionInfo{
-			SelectionID:     request.SelectionId,
-			SelectionStatus: 7,
-			FailReason:      2,
-			FinishAt:        &t,
-			EstimatedCost:   estimatedCostToString,
-		}
-	}
-	err = db.UpdateSelection(ctx, updateSelection)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[selectionDB service] call UpdateSelection error,err:%+v", err)
-		return nil, err
-	}
-	res := &http_model.ReviewSelectionData{}
-	return res, nil
-}
+package service
+
+import (
+	"context"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"reflect"
+	"time"
+	"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"
+	"youngee_m_api/util"
+
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+
+	"github.com/caixw/lib.go/conv"
+)
+
+var Selection *selection
+
+type selection struct {
+}
+
+func (*selection) Create(ctx context.Context, request http_model.CreateSelectionRequest) (*http_model.CreateSelectionData, error) {
+	enterpriseId := request.EnterpriseId
+	// 1. 检查该企业id和商品id有无选品
+	//selectionInfo, err := db.GetSelectionByEnterpiseIdAndProductId(ctx, enterpriseId, conv.MustInt(request.ProductId, 0))
+	//if err != nil {
+	//	return nil, err
+	//}
+	//if selectionInfo != nil {
+	//	return nil, errors.New("该商品下选品已存在")
+	//}
+
+	// 2. 数据准备
+	// a) 生成选品id
+	selectionId := util.GetSelectionID()
+	// b) 查找关联商品信息
+	product, err := db.GetProductByID(ctx, conv.MustInt64(request.ProductId, 0))
+	if err != nil {
+		return nil, err
+	}
+	productPhotos, err := db.GetProductPhotoByProductID(ctx, conv.MustInt64(request.ProductId, 0))
+	productInfoToJson, _ := json.Marshal(product)
+	productPhotosToJson, _ := json.Marshal(productPhotos)
+	// c) 选品名称
+	selectionName := product.BrandName + "-" + product.ProductName
+
+	// 3. 创建选品
+	//taskDdl := time.Time{} //赋零值
+	//taskDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", "2026-01-01 08:00:00", time.Local)
+	t := time.Now()
+	newSelection := gorm_model.YounggeeSelectionInfo{
+		SelectionStatus:  1,
+		SelectionID:      selectionId,
+		SelectionName:    selectionName,
+		ProductID:        conv.MustInt(request.ProductId, 0),
+		EnterpriseID:     enterpriseId,
+		Platform:         conv.MustInt(request.Platform, 0),
+		ProductSnap:      string(productInfoToJson),
+		ProductPhotoSnap: string(productPhotosToJson),
+		CreatedAt:        &t,
+		UpdatedAt:        &t,
+		EstimatedCost:    "0",
+		TaskReward:       "0",
+		SettlementAmount: "0",
+	}
+	//Selection := gorm_model.YounggeeSelectionInfo{}
+	err = db.CreateSelection(ctx, newSelection)
+	if err != nil {
+		return nil, err
+	}
+
+	res := &http_model.CreateSelectionData{
+		SelectionId: selectionId,
+	}
+	return res, nil
+}
+
+func (*selection) Update(ctx context.Context, request http_model.UpdateSelectionRequest, enterpriseId string) (*http_model.UpdateSelectionData, error) {
+	// 1. 检查该企业id和商品id有无选品
+	selectionInfo, err := db.GetSelectionById(ctx, request.SelectionID)
+	if err != nil {
+		return nil, err
+	}
+	if selectionInfo == nil {
+		return nil, errors.New("选品不存在")
+	}
+
+	// 2. 数据准备
+	// a) 查找关联商品信息
+	product, err := db.GetProductByID(ctx, conv.MustInt64(request.ProductId, 0))
+	if err != nil {
+		return nil, err
+	}
+	productPhotos, err := db.GetProductPhotoByProductID(ctx, conv.MustInt64(request.ProductId, 0))
+	productInfoToJson, _ := json.Marshal(product)
+	productPhotosToJson, _ := json.Marshal(productPhotos)
+	// b) 选品名称
+	selectionName := product.BrandName + "-" + product.ProductName
+	// d) 任务截止时间
+	fmt.Println("taskDdl:", request.TaskDdl)
+	taskDdl := time.Time{} //赋零值
+	taskDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", request.TaskDdl, time.Local)
+	// f) 更新选品状态
+	if request.SelectionStatus != 2 && request.SelectionStatus != 7 {
+		request.SelectionStatus = 1
+	}
+	t := time.Now()
+	updateSelection := gorm_model.YounggeeSelectionInfo{
+		SelectionID:      request.SelectionID,
+		SelectionStatus:  request.SelectionStatus,
+		SelectionName:    selectionName,
+		EnterpriseID:     enterpriseId,
+		ProductID:        conv.MustInt(request.ProductId, 0),
+		ContentType:      conv.MustInt(request.ContentType, 0),
+		TaskMode:         conv.MustInt(request.TaskMode, 0),
+		Platform:         conv.MustInt(request.Platform, 0),
+		SampleMode:       conv.MustInt(request.SampleMode, 0),
+		ProductUrl:       request.ProductUrl,
+		SampleNum:        conv.MustInt(request.SampleNum, 0),
+		RemainNum:        conv.MustInt(request.SampleNum, 0),
+		CommissionRate:   conv.MustInt(request.CommissionRate, 0),
+		TaskReward:       conv.MustString(request.TaskReward, "0"),
+		SettlementAmount: conv.MustString(request.SettlementAmount, "0"),
+		EstimatedCost:    selectionInfo.EstimatedCost,
+		SampleCondition:  request.SampleCondition,
+		RewardCondition:  request.RewardCondition,
+		TaskDdl:          &taskDdl,
+		Detail:           request.Detail,
+		ProductSnap:      string(productInfoToJson),
+		ProductPhotoSnap: string(productPhotosToJson),
+		CreatedAt:        selectionInfo.CreatedAt,
+		UpdatedAt:        &t,
+	}
+	if request.SelectionStatus == 2 {
+		updateSelection.SubmitAt = &t
+	}
+	// 合并传入参数和数据表中原记录,若传入参数字段值为空,则将字段赋值为原记录中值
+	result := util.MergeStructValue(&updateSelection, selectionInfo)
+	// 利用反射机制将interface类型转换为结构体类型
+	v := reflect.ValueOf(&result).Elem()
+	if v.Kind() == reflect.Struct {
+		updateSelection = v.Interface().(gorm_model.YounggeeSelectionInfo)
+		//fmt.Println(p)
+	}
+	// c) 计算预估成本(如果有)
+	var estimatedCost float64
+	if conv.MustInt(updateSelection.TaskMode, 0) == 1 {
+		estimatedCost = conv.MustFloat64(updateSelection.TaskReward, 0) * conv.MustFloat64(updateSelection.SampleNum, 0)
+	}
+	estimatedCostToString, _ := conv.String(estimatedCost)
+	updateSelection.EstimatedCost = estimatedCostToString
+
+	// 3. 更新选品
+	err = db.UpdateSelection(ctx, updateSelection)
+	if err != nil {
+		return nil, err
+	}
+
+	// 4. 更新选品brief和示例
+	if request.SecBrief != nil {
+		// 删除已有brief
+		err = db.DeleteSecBriefBySelectionId(ctx, selectionInfo.SelectionID)
+		if err != nil {
+			return nil, err
+		}
+		// 插入新的brief
+		for _, v := range request.SecBrief {
+			brief := gorm_model.YounggeeSecBrief{
+				SelectionID: selectionInfo.SelectionID,
+				FileUid:     v.PhotoUid,
+				FileName:    v.Name,
+				FileUrl:     v.PhotoUrl,
+				CreatedAt:   time.Now(),
+			}
+			err = db.CreateSecBrief(ctx, brief)
+			if err != nil {
+				return nil, err
+			}
+		}
+	}
+
+	if request.SecExample != nil {
+		// 删除已有示例
+		err = db.DeleteSecExampleBySelectionId(ctx, selectionInfo.SelectionID)
+		if err != nil {
+			return nil, err
+		}
+		// 插入新的示例
+		for _, v := range request.SecExample {
+			Example := gorm_model.YounggeeSecExample{
+				SelectionID: selectionInfo.SelectionID,
+				FileUid:     v.PhotoUid,
+				FileName:    v.Name,
+				FileUrl:     v.PhotoUrl,
+				CreatedAt:   time.Now(),
+			}
+			err = db.CreateSecExample(ctx, Example)
+			if err != nil {
+				return nil, err
+			}
+		}
+	}
+
+	res := &http_model.UpdateSelectionData{
+		SelectionId: updateSelection.SelectionID,
+	}
+	return res, nil
+}
+
+func (*selection) Pay(ctx context.Context, request http_model.PaySelectionRequest, enterpriseId string) (*http_model.PaySelectionData, error) {
+	// 校验
+	// 1. 账户余额是否足够
+	enterprise, err := db.GetEnterpriseByEnterpriseID(ctx, enterpriseId)
+	if err != nil {
+		return nil, err
+	}
+	if enterprise.AvailableBalance < request.PayMoney {
+		return nil, errors.New("账户余额不足")
+	}
+	// 2. 选品项目状态是否正确
+	selectionInfo, err := db.GetSelectionById(ctx, request.SelectionId)
+	if err != nil {
+		return nil, err
+	}
+	if selectionInfo == nil {
+		return nil, errors.New("选品不存在")
+	}
+	if selectionInfo.SelectionStatus != 4 {
+		return nil, errors.New("选品状态有误")
+	}
+
+	// 支付
+	err = db.PaySelection(ctx, enterpriseId, request.PayMoney, request.SelectionId)
+	if err != nil {
+		return nil, err
+	}
+
+	res := &http_model.PaySelectionData{
+		SelectionId: request.SelectionId,
+	}
+	return res, nil
+}
+
+func (*selection) Submit(ctx context.Context, request http_model.SubmitSelectionRequest) (*http_model.SubmitSelectionData, error) {
+	t := time.Now()
+	updateSelection := gorm_model.YounggeeSelectionInfo{
+		SelectionID:     request.SelectionId,
+		SelectionStatus: request.SelectionStatus,
+		SubmitAt:        &t,
+	}
+
+	err := db.UpdateSelection(ctx, updateSelection)
+	if err != nil {
+		return nil, err
+	}
+
+	res := &http_model.SubmitSelectionData{}
+	return res, nil
+}
+
+func (s *selection) GetAllSelection(ctx context.Context, enterpriseID string, pageSize, pageNum int64, conditions *common_model.SelectionConditions) (*http_model.SelectionData, error) {
+	SelectionList, total, err := db.GetSelectionList(ctx, enterpriseID, pageSize, pageNum, conditions)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetAllSelection error,err:%+v", err)
+		return nil, err
+	}
+	SelectionListData := new(http_model.SelectionData)
+	SelectionListData.SelectionInfo = pack.MGormSelectionToHttpSelectionPreview(SelectionList)
+	SelectionListData.Total = conv.MustString(total, "")
+	return SelectionListData, nil
+}
+
+func (s *selection) GetSelectionDetail(ctx *gin.Context, selectionId string, enterpriseId string) (*http_model.SelectionDetail, error) {
+	selectionDetail := http_model.SelectionDetail{}
+	selectionInfo, err := db.GetSelectionById(ctx, selectionId)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetSelectionInfo error,err:%+v", err)
+		return nil, err
+	}
+	selectionBriefInfo, err := db.GetSelectionBriefInfo(ctx, selectionId)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetSelectionBriefInfo error,err:%+v", err)
+		return nil, err
+	}
+	selectionExampleInfo, err := db.GetSelectionExampleInfo(ctx, selectionId)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetSelectionExampleInfo error,err:%+v", err)
+		return nil, err
+	}
+	productInfo, err := db.GetProductInfoBySelectionId(ctx, selectionId)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetProductInfo error,err:%+v", err)
+		return nil, err
+	}
+	productPhotoInfo, err := db.GetProductPhotoInfoBySelectionId(ctx, selectionId)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetProductPhotoInfo error,err:%+v", err)
+		return nil, err
+	}
+	selectionDetail.SelectionBrief = selectionBriefInfo
+	selectionDetail.SelectionInfo = selectionInfo
+	selectionDetail.SelectionExample = selectionExampleInfo
+	selectionDetail.ProductInfo = productInfo
+	selectionDetail.ProductPhotoInfo = productPhotoInfo
+	return &selectionDetail, nil
+}
+
+func (*selection) Review(ctx context.Context, request http_model.ReviewSelectionRequest) (*http_model.ReviewSelectionData, error) {
+	// 根据选品id查询选品信息
+	selectionInfo, err := db.GetSelectionById(ctx, request.SelectionId)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetSelectionById error,err:%+v", err)
+		return nil, err
+	}
+
+	// 计算预估成本
+	var estimatedCost float64 = 0.0
+	var estimatedCostToString string = ""
+	if conv.MustInt(selectionInfo.TaskMode, 0) == 1 {
+		estimatedCost = conv.MustFloat64(selectionInfo.TaskReward, 0) * conv.MustFloat64(selectionInfo.SampleNum, 0)
+		estimatedCostToString, _ = conv.String(estimatedCost)
+	}
+
+	// 若审核通过则更新选品阶段为待支付,否则更新为失效并赋值失效原因
+	t := time.Now()
+	AutoTaskID, err := db.GetLastAutoTaskID()
+	updateSelection := gorm_model.YounggeeSelectionInfo{}
+	if request.IsPass == 1 {
+		if conv.MustInt(selectionInfo.TaskMode, 0) == 1 {
+			//悬赏任务
+			updateSelection = gorm_model.YounggeeSelectionInfo{
+				SelectionID:     request.SelectionId,
+				SelectionStatus: 4,
+				PassAt:          &t,
+				EstimatedCost:   estimatedCostToString,
+				AutoTaskID:      int(AutoTaskID),
+			}
+		} else {
+			// 纯佣带货
+			updateSelection = gorm_model.YounggeeSelectionInfo{
+				SelectionID:     request.SelectionId,
+				SelectionStatus: 6,
+				PassAt:          &t,
+				EstimatedCost:   estimatedCostToString,
+			}
+		}
+	} else {
+		updateSelection = gorm_model.YounggeeSelectionInfo{
+			SelectionID:     request.SelectionId,
+			SelectionStatus: 7,
+			FailReason:      2,
+			FinishAt:        &t,
+			EstimatedCost:   estimatedCostToString,
+		}
+	}
+	err = db.UpdateSelection(ctx, updateSelection)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[selectionDB service] call UpdateSelection error,err:%+v", err)
+		return nil, err
+	}
+	res := &http_model.ReviewSelectionData{}
+	return res, nil
+}