diff --git a/app/Service/Api/Good/OptionalListService.php b/app/Service/Api/Good/OptionalListService.php index 51da944..8b3494c 100644 --- a/app/Service/Api/Good/OptionalListService.php +++ b/app/Service/Api/Good/OptionalListService.php @@ -100,7 +100,8 @@ class OptionalListService extends BaseService $res = []; $stockKey = ApiRedisKey::goodStockKey($this->goodCache->cycleId, $this->goodCache->kitchenId); $favorable = []; - foreach ($data as $key => &$item) { + $skuList = []; + foreach ($data as &$item) { foreach ($item['sku_list'] as &$v) { $v['surplus_stock'] = $this->redisCache->zScore($stockKey,$v['id']) ?? 0; } @@ -121,6 +122,7 @@ class OptionalListService extends BaseService } $res[$item['category_id']]['spu_list'][] = $item; + $skuList[] = $item['sku_list']; } if (!empty($purchaseData)) { @@ -133,6 +135,12 @@ class OptionalListService extends BaseService } if (!empty($favorable)) { + if (empty($skuList)) throw new ErrException('数据错误'); + $skuList = array_column($skuList,null,'id'); + foreach ($favorable['sku_list'] as &$v) { + $v['origin_spu_id'] = $skuList[$v['id']]['spu_id'] ?? 0; + } + array_unshift($res,[ 'category_name' => $this->configCache->getConfigValueByKey(ConfigCode::SPECIALS_CATEGORY_NAME), 'category_image' => $this->configCache->getConfigValueByKey(ConfigCode::SPECIALS_CATEGORY_IMAGE),