feat: good
This commit is contained in:
@@ -60,8 +60,55 @@ class SpuService extends BaseService
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$cycleId = (int)$this->request->input('cycle_id');
|
||||
$kitchenId = (int)$this->request->input('search_kitchen_id');
|
||||
$cityId = (int)$this->request->input('search_city_id');
|
||||
|
||||
$list = $this->spuModel->where('cycle_id',$cycleId)->where('city_id',$this->cityId)->paginate($limit)->toArray();
|
||||
$list = $this->spuModel
|
||||
->where('cycle_id',$cycleId)
|
||||
->where('city_id',$cityId)
|
||||
->where('kitchen_id',$kitchenId)
|
||||
->where('is_del',GoodCode::SPU_IS_NO_DEL)
|
||||
->paginate($limit)
|
||||
->toArray();
|
||||
|
||||
if (empty($list['data'])) return $this->return->success('success', ['list' => $list]);
|
||||
|
||||
$spuIds = array_column($list['data'], 'id');
|
||||
|
||||
$skuList = $this->skuModel
|
||||
->whereIn('spu_id',$spuIds)
|
||||
->where('is_del',GoodCode::SKU_IS_NO_DEL)
|
||||
->get();
|
||||
|
||||
if (empty($skuList)) return $this->return->success('success', ['list' => $list]);
|
||||
$skuList = $skuList->toArray();
|
||||
|
||||
$imageIdArr = array_column($skuList,'image_ids');
|
||||
$imageIds = array_unique(explode(',',implode(',',$imageIdArr)));
|
||||
$imageList = $this->getOssObjects($imageIds);
|
||||
|
||||
$skuListArr = [];
|
||||
foreach ($skuList as $sku) {
|
||||
$imageOneArr = [];
|
||||
foreach (explode(',',$sku['image_ids']) as $imageId) {
|
||||
$imageOneArr[] = [
|
||||
'id' => $imageId,
|
||||
'url' => $imageList[$imageId]['url']
|
||||
];
|
||||
}
|
||||
|
||||
$sku['image_list'] = $imageOneArr;
|
||||
|
||||
if (empty($skuListArr[$sku['spu_id']])) {
|
||||
$skuListArr[$sku['spu_id']] = [];
|
||||
}
|
||||
|
||||
$skuListArr[$sku['spu_id']][] = $sku;
|
||||
}
|
||||
|
||||
foreach ($list['data'] as &$item) {
|
||||
$item['sku_list'] = $skuListArr[$item['id']];
|
||||
}
|
||||
|
||||
return $this->return->success('success', ['list' => $list]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user