|
@@ -84,7 +84,7 @@ func (*selection) Create(ctx context.Context, request http_model.CreateSelection
|
|
|
|
|
|
func (*selection) Update(ctx context.Context, request http_model.UpdateSelectionRequest, enterpriseId string) (*http_model.UpdateSelectionData, error) {
|
|
|
// 1. 检查该企业id和商品id有无选品
|
|
|
- selectionInfo, err := db.GetSelectionByEnterpiseIdAndProductId(ctx, enterpriseId, conv.MustInt(request.ProductId, 0))
|
|
|
+ selectionInfo, err := db.GetSelectionById(ctx, request.SelectionID)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -106,18 +106,18 @@ func (*selection) Update(ctx context.Context, request http_model.UpdateSelection
|
|
|
// d) 任务截止时间
|
|
|
taskDdl := time.Time{} //赋零值
|
|
|
taskDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", request.TaskDdl, time.Local)
|
|
|
-
|
|
|
- if request.SelectionStatus != "2" && request.SelectionStatus != "7" {
|
|
|
- request.SelectionStatus = "1"
|
|
|
+ // f) 更新选品状态
|
|
|
+ if request.SelectionStatus != 2 && request.SelectionStatus != 7 {
|
|
|
+ request.SelectionStatus = 1
|
|
|
}
|
|
|
|
|
|
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),
|
|
|
- SelectionStatus: selectionInfo.SelectionStatus,
|
|
|
TaskMode: conv.MustInt(request.TaskMode, 0),
|
|
|
Platform: conv.MustInt(request.Platform, 0),
|
|
|
SampleMode: conv.MustInt(request.SampleMode, 0),
|
|
@@ -148,8 +148,8 @@ func (*selection) Update(ctx context.Context, request http_model.UpdateSelection
|
|
|
}
|
|
|
// c) 计算预估成本(如果有)
|
|
|
var estimatedCost float64
|
|
|
- if conv.MustInt(request.TaskMode, 0) == 1 {
|
|
|
- estimatedCost = conv.MustFloat64(request.TaskReward, 0) * conv.MustFloat64(request.SampleNum, 0)
|
|
|
+ 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
|
|
@@ -160,6 +160,51 @@ func (*selection) Update(ctx context.Context, request http_model.UpdateSelection
|
|
|
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,
|
|
|
}
|