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 {