From 6319ba64b82c53b132ba70fbbb4bd17fb908b66a Mon Sep 17 00:00:00 2001 From: howell <2827207845@qq.com> Date: Thu, 27 Jan 2022 11:27:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=A8=E9=87=8F-=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=95=86=E8=AF=A62?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/v2/logic/manage/goods/notice.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/internal/v2/logic/manage/goods/notice.go b/internal/v2/logic/manage/goods/notice.go index 15170f4..e5226af 100644 --- a/internal/v2/logic/manage/goods/notice.go +++ b/internal/v2/logic/manage/goods/notice.go @@ -223,18 +223,16 @@ func (n *noticeLogic) Add(title string, img []string, noticeType int, vendorId u start := 0 total := len(noticeGoods) temp := make([][]goods.RecookGoodsNoticeGoodsModel, 0) + for { - if start > total { + if start >= total { break } - if total < step { - temp = append(temp, noticeGoods[start:]) - break - } else { - temp = append(temp, noticeGoods[start:step]) - start += step + if total-start < step { + step = total - start } - + temp = append(temp, noticeGoods[start:start+step]) + start = start + step } for _, v := range temp { if err := tx.Create(&v).Error; err != nil {