//检查两个多维数组 是否一直 public function foo($arr, &$rt , $key=‘‘ ,$i=0) { if (is_array($arr)) { foreach ($arr as $k=>$v) { if (is_array($v)) { $this->foo($v ,$rt ,$k ,$i); } else { $rt[$key.‘->‘.$k.$i] = $v; } $i++; } } return $rt; } /** * 商品信息缓存一致性检查 * @param $productId * @return bool */ public function checkProductAttach($productId) { $getAttach = $this->productService->getAttach($productId); $getProductAttach = $this->productService->getProductAttach($productId); if($getProductAttach == false){ Yii::$app->dataCache->getRedis()->del([‘PRODUCT_ATTACH‘, $productId]); return true; } $isSame = $this->isSame($getAttach ,$getProductAttach ); $arr = []; $arrCache = $this->foo($getAttach,$arr); $arrService = $this->foo($getProductAttach,$arr); $result = [‘isSame‘=>$isSame,‘diff‘=>array_diff($arrService, $arrCache)]; if($isSame==false){ Yii::getLogger()->log([‘errorkey‘ => ‘RedisCheckError:‘.$productId , ‘errorvalue‘ => json_encode($result[‘diff‘])], Logger::LEVEL_ERROR); } return $result; }
时间: 2024-12-28 14:30:21