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; /** * @return array */ public function skuList(): array { $spuList = $this->spuModel ->leftjoin('sku','spu.id','=','sku.spu_id') ->where('spu.caterer_id',$this->adminId) ->where('spu.cycle_id',$this->cycleId) ->select(['spu.title','spu.sub_title','spu.id','sku.id as sku_id','sku.title as sku_title']) ->get(); if ($spuList->isEmpty()) return $this->return->success('success',['list' => []]); $spuList = $spuList->toArray(); return $this->return->success('success',['list' => $spuList]); } }