Parcourir la source

addNameInKuaishouProduct

Xingyu Xian il y a 4 mois
Parent
commit
851af92ff6
2 fichiers modifiés avec 28 ajouts et 2 suppressions
  1. 3 2
      model/http_model/product_find.go
  2. 25 0
      service/product.go

+ 3 - 2
model/http_model/product_find.go

@@ -6,8 +6,9 @@ type FindProductRequest struct {
 
 type ProductPhoto struct {
 	PhotoUrl string `json:"photo_url"` // 图片或视频url
-	PhotoUid string `json:"photo_uid"`
-	Symbol   int64  `json:"symbol"` // 图片为主图或详情图标志位
+	PhotoUid string `json:"photo_uid"` // 图片Uid
+	Symbol   int64  `json:"symbol"`    // 图片为主图或详情图标志位
+	Name     string `json:"name"`      // 图片名称
 }
 
 type FindProductData struct {

+ 25 - 0
service/product.go

@@ -6,6 +6,7 @@ import (
 	"github.com/lin-jim-leon/kuaishou"
 	"math/rand"
 	"strconv"
+	"strings"
 	"time"
 	"youngee_b_api/consts"
 	"youngee_b_api/db"
@@ -216,8 +217,16 @@ func (*product) QueryKuaishouProduct(ctx context.Context, newKuaishouProduct htt
 	// 5.1. 主图
 	var currProductMainPhoto *http_model.ProductPhoto
 	rand.Seed(time.Now().UnixNano())
+	currLastIndex := strings.LastIndex(findKuaishouProductData.KuaishouMainPhoto, "/")
+	var currDesiredFileName string
+	if currLastIndex != -1 {
+		currDesiredFileName = findKuaishouProductData.KuaishouMainPhoto[currLastIndex+1:]
+	} else {
+		currDesiredFileName = "FileNotFound"
+	}
 	currProductMainPhoto = &http_model.ProductPhoto{
 		PhotoUrl: findKuaishouProductData.KuaishouMainPhoto,
+		Name:     currDesiredFileName,
 		PhotoUid: generateRandomString(10),
 		Symbol:   1,
 	}
@@ -227,8 +236,16 @@ func (*product) QueryKuaishouProduct(ctx context.Context, newKuaishouProduct htt
 	for _, url := range findKuaishouProductData.KuaishouCarousePhotoList {
 		var currProductPhoto *http_model.ProductPhoto
 		rand.Seed(time.Now().UnixNano())
+		lastIndex := strings.LastIndex(url, "/")
+		var desiredFileName string
+		if lastIndex != -1 {
+			desiredFileName = url[lastIndex+1:]
+		} else {
+			desiredFileName = "FileNotFound"
+		}
 		currProductPhoto = &http_model.ProductPhoto{
 			PhotoUrl: url,
+			Name:     desiredFileName,
 			PhotoUid: generateRandomString(10),
 			Symbol:   2,
 		}
@@ -239,8 +256,16 @@ func (*product) QueryKuaishouProduct(ctx context.Context, newKuaishouProduct htt
 	for _, url := range findKuaishouProductData.KuaishouDetailPhotoList {
 		var currProductPhoto *http_model.ProductPhoto
 		rand.Seed(time.Now().UnixNano())
+		lastIndex := strings.LastIndex(url, "/")
+		var desiredFileName string
+		if lastIndex != -1 {
+			desiredFileName = url[lastIndex+1:]
+		} else {
+			desiredFileName = "FileNotFound"
+		}
 		currProductPhoto = &http_model.ProductPhoto{
 			PhotoUrl: url,
+			Name:     desiredFileName,
 			PhotoUid: generateRandomString(10),
 			Symbol:   4,
 		}