feat : spu
This commit is contained in:
@@ -77,18 +77,21 @@ class CycleListService extends CateringBaseService
|
|||||||
#[Inject]
|
#[Inject]
|
||||||
protected Spu $spuModel;
|
protected Spu $spuModel;
|
||||||
|
|
||||||
public function skuList()
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function skuList(): array
|
||||||
{
|
{
|
||||||
$spuList = $this->spuModel->where('caterer_id',$this->adminId)->select(['title','sub_title','id'])->get();
|
$spuList = $this->spuModel
|
||||||
if (empty($spuList)) return $this->return->success('success',['list' => []]);
|
->join('sku','spu.id','=','sku.spu_id')
|
||||||
|
->where('spu.caterer_id',$this->adminId)
|
||||||
|
->select(['spu.title','sku.sub_title','spu.id'])
|
||||||
|
->selectRaw('sku.id as sku_id')
|
||||||
|
->selectRaw('sku.title as sku_title')
|
||||||
|
->get();
|
||||||
|
if ($spuList->isEmpty()) return $this->return->success('success',['list' => []]);
|
||||||
$spuList = $spuList->toArray();
|
$spuList = $spuList->toArray();
|
||||||
|
|
||||||
$skuList = $this->skuModel->whereIn('spu_id',array_column($spuList,'id'))->pluck('id','spu_id');
|
|
||||||
|
|
||||||
foreach ($spuList as &$v) {
|
|
||||||
$v['sku_id'] = $skuList[$v['id']] ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->return->success('success',['list' => $spuList]);
|
return $this->return->success('success',['list' => $spuList]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user