Procházet zdrojové kódy

修改选品更新接口

Ohio-HYF před 1 rokem
rodič
revize
a782a767b8

+ 42 - 0
db/selection.go

@@ -189,3 +189,45 @@ func PaySelection(ctx context.Context, enterpriseId string, payMoney float64, se
 	}
 	return nil
 }
+
+func CreateSecBrief(ctx context.Context, briefInfo gorm_model.YounggeeSecBrief) error {
+	db := GetWriteDB(ctx)
+	err := db.Create(&briefInfo).Error
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+func DeleteSecBriefBySelectionId(ctx context.Context, selectionId string) error {
+	db := GetWriteDB(ctx)
+	deleteCondition := gorm_model.YounggeeSecBrief{
+		SelectionID: selectionId,
+	}
+	err := db.Where(deleteCondition).Delete(gorm_model.YounggeeSecBrief{}).Error
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+func CreateSecExample(ctx context.Context, ExampleInfo gorm_model.YounggeeSecExample) error {
+	db := GetWriteDB(ctx)
+	err := db.Create(&ExampleInfo).Error
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+func DeleteSecExampleBySelectionId(ctx context.Context, selectionId string) error {
+	db := GetWriteDB(ctx)
+	deleteCondition := gorm_model.YounggeeSecExample{
+		SelectionID: selectionId,
+	}
+	err := db.Where(deleteCondition).Delete(gorm_model.YounggeeSecExample{}).Error
+	if err != nil {
+		return err
+	}
+	return nil
+}

+ 1 - 1
handler/UpdateSelection.go

@@ -45,7 +45,7 @@ func (c UpdateSelection) run() {
 		logrus.Info("UpdateSelection fail,req:%+v", c.req)
 		return
 	}
-	c.resp.Message = "成功创建选品"
+	c.resp.Message = "选品更新成功"
 	c.resp.Data = res
 }
 

+ 7 - 6
model/http_model/UpdateSelection.go

@@ -2,6 +2,7 @@ package http_model
 
 type UpdateSelectionRequest struct {
 	SelectionID      string            `json:"selection_id"` // 选品项目id
+	SelectionStatus  int               `json:"selection_status"`
 	Platform         string            `json:"platform"`
 	ProductId        int               `json:"product_id"`
 	ContentType      int               `json:"content_type"`
@@ -22,15 +23,15 @@ type UpdateSelectionRequest struct {
 }
 
 type SecBriefInfo struct {
-	FileUrl  string `json:"file_url"`
-	FileUid  string `json:"file_uid"`
-	FileName string `json:"file_name"`
+	PhotoUrl string `json:"photo_url"`
+	PhotoUid string `json:"photo_uid"`
+	Name     string `json:"name"`
 }
 
 type SecExampleInfo struct {
-	FileUrl  string `json:"file_url"`
-	FileUid  string `json:"file_uid"`
-	FileName string `json:"file_name"`
+	PhotoUrl string `json:"photo_url"`
+	PhotoUid string `json:"photo_uid"`
+	Name     string `json:"name"`
 }
 
 type UpdateSelectionData struct {

+ 53 - 5
service/selection_service/selection.go

@@ -82,8 +82,8 @@ 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))
+	// 1. 检查该选品是否存在
+	selectionInfo, err := db.GetSelectionById(ctx, request.SelectionID)
 	if err != nil {
 		return nil, err
 	}
@@ -110,16 +110,19 @@ func (*selection) Update(ctx context.Context, request http_model.UpdateSelection
 	estimatedCostToString, _ := conv.String(estimatedCost)
 	// d) 任务截止时间
 	taskDdl := time.Time{} //赋零值
-
 	taskDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", request.TaskDdl, time.Local)
+	// f) 更新选品状态
+	if request.SelectionStatus != 2 {
+		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:  1,
 		TaskMode:         conv.MustInt(request.TaskMode, 0),
 		Platform:         conv.MustInt(request.Platform, 0),
 		SampleMode:       conv.MustInt(request.SampleMode, 0),
@@ -138,7 +141,7 @@ func (*selection) Update(ctx context.Context, request http_model.UpdateSelection
 		ProductPhotoSnap: string(productPhotosToJson),
 		CreatedAt:        selectionInfo.CreatedAt,
 		UpdatedAt:        time.Now(),
-		SubmitAt:         time.Now(),
+		//SubmitAt:         time.Now(),
 	}
 	// 合并传入参数和数据表中原记录,若传入参数字段值为空,则将字段赋值为原记录中值
 	//fmt.Printf("MergeTest %+v %+v", updateSelection, selectionInfo)
@@ -156,6 +159,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
+		}
+		// 插入新的biref
+		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,
 	}