skuModel->getInfoById((int)$this->request->input('sku_id')); if (empty($skuInfo)) throw new ErrException('该套餐不存在,请刷新后重试'); $cycleCateringLogs = $this->orderMealCateringLogModel ->where('cycle_id',$this->cycleId) ->where('sku_id',$skuInfo->id) ->select(['site_id','quantity','status','id']) ->get(); $res = $this->buildResArr($cycleCateringLogs); if (empty($res)) return $this->return->success('success',['list' => []]); return $this->return->success('success',['list' => array_values($res)]); } /** * @return array */ public function remainCount(): array { $skuInfo = $this->skuModel->getInfoById((int)$this->request->input('sku_id')); if (empty($skuInfo)) throw new ErrException('该套餐不存在,请刷新后重试'); $count = $this->orderMealCateringLogModel ->where('cycle_id',$this->cycleId) ->where('sku_id',$skuInfo->id) ->sum('quantity') ?? 0; return $this->return->success('success',['count' => $count]); } /** * @var Spu */ #[Inject] protected Spu $spuModel; public function skuList() { $spuList = $this->spuModel->where('caterer_id',$this->adminId)->select(['title','sub_title','id as spu_id'])->get(); if (empty($skuList)) return $this->return->success('success',['list' => []]); $spuList = $spuList->toArray(); $skuList = $this->skuModel->where('spu_id',array_column($spuList,'spu_id'))->pluck('id','spu_id'); foreach ($spuList as &$v) { $v['sku_id'] = $skuList[$v['spu_id']] ?? 0; } return $this->return->success('success',['list' => $spuList]); } }