request->get(); $product_dict = Cache::store('redis')->get('product_class_'.$id["id"]); if ($product_dict){ return $this->JsonSucess($product_dict); } try { $productDict = ProductClassService::getProductClassById($id["id"]); } catch (DataNotFoundException|DbException $e) { return $this->JsonError($e->getData()); } $dict =$this->getArray("0".$id["id"],$productDict->toArray()); Cache::store('redis')->set('product_class_'.$id["id"],$dict); return $this->JsonSucess($dict); } function getArray($parentCode,$data): array { $arr = array(); foreach($data as $k => $v){ if($v["parent_id"]==$parentCode){ unset($data[$k]); $c=$this->getArray($v["product_code"],$data); if($c){ $v["children"]=$c; } $arr[]=$v; } } return $arr; } /** * @Apidoc\Title("通过分类id查找产品分类") * @Apidoc\Tag("产品字典") * @Apidoc\Method ("GET") * @Apidoc\Author ("yang") * @Route("getProductClass",method="GET") * @Middleware({"jwt"}) */ public function getProductClass(){ return $this->JsonSucess(ProductClassService::getProductClass()); } }