Browse Source

修改封面上传逻辑

kobe6258 4 months ago
parent
commit
125a677e1b
1 changed files with 10 additions and 6 deletions
  1. 10 6
      controllers/product.go

+ 10 - 6
controllers/product.go

@@ -185,9 +185,11 @@ func (this *ProductController) AddProduct() {
 				//br.ErrMsg = "默认套餐封面获取失败,请上传封面,Err:" + err.Error()
 				//return
 			} else {
-				var rnd = rand.New(rand.NewSource(time.Now().UnixNano()))
-				index := rnd.Intn(len(imageList))
-				product.CoverSrc = imageList[index].Id
+				if len(imageList) > 0 {
+					var rnd = rand.New(rand.NewSource(time.Now().UnixNano()))
+					index := rnd.Intn(len(imageList))
+					product.CoverSrc = imageList[index].Id
+				}
 			}
 		} else {
 			product.CoverUrl = req.CoverSrc
@@ -608,9 +610,11 @@ func (this *ProductController) EditProduct() {
 				//br.ErrMsg = "默认套餐封面获取失败,请上传封面,Err:" + err.Error()
 				//return
 			} else {
-				var rnd = rand.New(rand.NewSource(time.Now().UnixNano()))
-				index := rnd.Intn(len(imageList))
-				product.CoverSrc = imageList[index].Id
+				if len(imageList) > 0 {
+					var rnd = rand.New(rand.NewSource(time.Now().UnixNano()))
+					index := rnd.Intn(len(imageList))
+					product.CoverSrc = imageList[index].Id
+				}
 			}
 		} else {
 			product.CoverUrl = req.CoverSrc