diff --git a/app/Service/Api/Good/OptionalListService.php b/app/Service/Api/Good/OptionalListService.php index d065dd0..def95e0 100644 --- a/app/Service/Api/Good/OptionalListService.php +++ b/app/Service/Api/Good/OptionalListService.php @@ -114,9 +114,11 @@ class OptionalListService extends BaseService $favorable = []; $skuList = []; foreach ($data as &$item) { - foreach ($item['sku_list'] as &$v) { - $v['surplus_stock'] = $this->redisCache->zScore($stockKey,$v['id']) ?? 0; - $v['category_id'] = $item['category_id']; + if (!empty($item['sku_list'])) { + foreach ($item['sku_list'] as &$v) { + $v['surplus_stock'] = $this->redisCache->zScore($stockKey,$v['id']) ?? 0; + $v['category_id'] = $item['category_id']; + } } if ($item['favorable'] == GoodCode::IS_FAVORABLE) { @@ -136,10 +138,10 @@ class OptionalListService extends BaseService } $res[$item['category_id']]['spu_list'][] = $item; - $skuList = array_merge($skuList, $item['sku_list']); + $skuList = array_merge($skuList, $item['sku_list'] ?? []); } - if (empty($skuList)) throw new ErrException('数据错误'); + if (empty($skuList)) return array_values($res); $skuList = array_column($skuList,null,'id'); if (!empty($purchaseData)) {