/** * 从接口中获取数据并做缓存 */ protected function _getApiData() { //组合可以通过接口获取数据的数组 $tempApi = array(); foreach ($this->mApi as $key => $val) { $tempApi = array_merge($tempApi, $val['api']); } //获取接口数据 SPP_Util_Util::getMultiRemoteContent($tempApi); foreach ($tempApi as $ke => $vo) { $tempApi[$ke]['result'] = json_decode($vo['result'], true); } //获取索引数组 $tempSort = array_flip(array_keys($tempApi)); //取结果集 foreach ($this->mApi as $key => $val) { $this->mApi[$key]['api'] = array_slice($tempApi, $tempSort[$val['key']], $val['num']); } }
/** * 入口文件 */ function run() { /** * 以下是公共部分 */ //不变数据 $tApiUnchange = array('baikezx' => array('url' => $this->mApiUrl . 'NewsApi.php?action=wikiEntry&name=装修百科&limit=10'), 'baikejc' => array('url' => $this->mApiUrl . 'NewsApi.php?action=wikiEntry&name=建材百科&limit=10'), 'rightAds' => array('url' => $this->mApiUrl . 'IndexApi.php?action=getTopRightAds')); //根据关键词或者楼盘ID可变数据 $tApiChangeTag = array('ask' => array('url' => $this->mApiUrl . 'NewsApi.php?action=askTag&&limit=10&&tag=' . $this->mName), 'xiaoguotu' => array('url' => $this->mApiUrl . 'XiaoguotuApi.php?action=getXiaoguotuByTagName&limit=4&tagName=' . $this->mName), 'news' => array('url' => $this->mApiUrl . 'NewsApi.php?action=getNewsByTagName&limit=10&tagName=' . $this->mName)); //根据城市变化数据 $tApiChangeCity = array('ad' => array('url' => $this->mApiUrl . "NewsApi.php?action=adsList&positionId=112&limit=1®Id={$this->mCompanyId}")); //根据应用可变数据 $tApiChangePosition = array('qrcode' => array('url' => $this->mApiUrl . "NewsApi.php?action=cityQrcode&positionId={$this->mPositionId}")); //根据各自的条件可变数据 $tApiChangeId = array('loupan' => array('url' => $this->mApiUrl . "HouseApi.php?action=findHouseInfoById&id={$this->mId}"), 'new' => array('url' => $this->mApiUrl . "HouseApi.php?action=getNewsList&houseId={$this->mId}&pNumber=1&pSize=5"), 'huxingNum' => array('url' => $this->mApiUrl . "HouseApi.php?action=getLayoutCountByHouseId&id={$this->mId}"), 'huxing' => array('url' => $this->mApiUrl . "HouseApi.php?action=getLayoutListByHouseId&houseId={$this->mId}&pNumber=1&pSize=8"), 'photo' => array('url' => $this->mApiUrl . "HouseApi.php?action=getPhotoListByHouseId&houseId={$this->mId}&pNumber=1&pSize=8")); $tUnchangeKey = "Loupan:Unhange"; $tChangeTagKey = "Loupan:Change:Id:" . $this->mName; $tChangeCompanyKey = "Loupan:Change:Id:" . $this->mCompanyId; $tChangePositionKey = "Loupan:Change:Id:" . $this->mPositionId; $tChangeIdKey = "Loupan:Change:Id:" . $this->mId; //自己 $tApiUnchangeData = json_decode($this->redis->get($tUnchangeKey), true); //获取固定接口缓存数据 $tApiChangeTagData = json_decode($this->redis->get($tChangeTagKey), true); //获取固定接口缓存数据 $tApiChangeCityData = json_decode($this->redis->get($tChangeCompanyKey), true); $tApiChangePositionData = json_decode($this->redis->get($tChangePositionKey), true); $tApiChangeIdData = json_decode($this->redis->get($tChangeIdKey), true); //获取固定接口缓存数据 //自己 $tApi = array(); if (empty($tApiUnchangeData)) { $tApi = array_merge($tApi, $tApiUnchange); } if (empty($tApiChangeTagData)) { $tApi = array_merge($tApi, $tApiChangeTag); } if (empty($tApiChangeCityData)) { $tApi = array_merge($tApi, $tApiChangeCity); } if (empty($tApiChangePositionData)) { $tApi = array_merge($tApi, $tApiChangePosition); } if (empty($tApiChangeIdData)) { $tApi = array_merge($tApi, $tApiChangeId); //自己 } SPP_Util_Util::getMultiRemoteContent($tApi); $tApiNum = array(); $i = 0; foreach ($tApi as $key => $val) { $tApiNum[$key] = $i; $i = $i + 1; } if (empty($tApiUnchangeData)) { $tApiUnchangeData = array_slice($tApi, 0, 3); $this->redis->setex($tUnchangeKey, self::CACHE_TIME_TYPE2, json_encode($tApiUnchangeData)); } if (empty($tApiChangeTagData)) { $tApiChangeTagData = array_slice($tApi, $tApiNum['ask'], 3); $this->redis->setex($tChangeTagKey, self::CACHE_TIME_TYPE2, json_encode($tApiChangeTagData)); } if (empty($tApiChangeCityData)) { $tApiChangeCityData = array_slice($tApi, $tApiNum['ad'], 1); $this->redis->setex($tChangeCompanyKey, self::CACHE_TIME_TYPE2, json_encode($tApiChangeCityData)); } if (empty($tApiChangePositionData)) { $tApiChangePositionData = array_slice($tApi, $tApiNum['qrcode'], 1); $this->redis->setex($tChangePositionKey, self::CACHE_TIME_TYPE2, json_encode($tApiChangePositionData)); } if (empty($tApiChangeIdData)) { $tApiChangeIdData = array_slice($tApi, $tApiNum['loupan'], 5); $this->redis->setex($tChangeIdKey, self::CACHE_TIME_TYPE2, json_encode($tApiChangeIdData)); //自己 } /** * 公共开始 */ $baikezx = json_decode($tApiUnchangeData['baikezx']['result'], true); $baikejc = json_decode($tApiUnchangeData['baikejc']['result'], true); $rightAds = json_decode($tApiUnchangeData['rightAds']['result'], true); $this->assign('baikezx', $baikezx['data']); //最热装修知识根据点击排序 $this->assign('baikejc', $baikejc['data']); //脚部文件 热门城市 $this->assign('rightAds', $rightAds['data']); //右侧广告 $ask = json_decode($tApiChangeTagData['ask']['result'], true); $xiaoguotu = json_decode($tApiChangeTagData['xiaoguotu']['result'], true); $news = json_decode($tApiChangeTagData['news']['result'], true); $this->assign('ask', $ask); //图库数据 $this->assign('xiaoguotu', $xiaoguotu['data']); //根据关键词调用资讯 $this->assign('news', $news['data']); //论坛数据 $topAds = json_decode($tApiChangeCityData['topAds']['result'], true); $this->assign('topAds', $topAds); //右侧广告 $qrcodeInfo = json_decode($tApiChangePositionData['qrcodeInfo']['result'], true); $this->assign('qrcodeInfo', $qrcodeInfo['data']); //右侧广告 /** * 公共结束 */ /** * 自己 */ $loupan = json_decode($tApiChangeIdData['loupan']['result'], true); $new = json_decode($tApiChangeIdData['new']['result'], true); $huxingNum = json_decode($tApiChangeIdData['huxingNum']['result'], true); $huxing = json_decode($tApiChangeIdData['huxing']['result'], true); $photo = json_decode($tApiChangeIdData['photo']['result'], true); $this->assign('topAds', $loupan['data']); $this->assign('new', $new['data']); $this->assign('huxingNum', $huxingNum['data']); $this->assign('huxing', $huxing['data']); $this->assign('photo', $photo['data']); $this->assign('companyName', $this->mCompanyName); //城市名称 $this->assign('jsVersion', $this->mJsVersion); //JS版本号 $this->assign('cssVersion', $this->mCssVersion); //css版本号 $this->assign('name', $this->mName); //name $this->assign('navType', $this->mNavType); //导航信息 $this->assign('title', $this->mTitle); //标题 $this->assign('keyword', $this->mKeyword); //关键字 $this->assign('description', $this->mDescription); //描述 }
/** * @param array $pApiOpts * @param $pCacheKey * @param $pCacheTime * @return array|mixed */ public function doApi(&$pApiOpts = array(), $pCacheKey, $pCacheTime) { $cacheData = $this->mRedis->get($pCacheKey); /* if (!empty($cacheData)) { $pApiOpts = json_decode($cacheData, true); return; } */ SPP_Util_Util::getMultiRemoteContent($pApiOpts); foreach ($pApiOpts as $key => &$val) { $val['result'] = json_decode($val['result'], true); } // $this->mRedis->setex($pCacheKey, $pCacheTime, json_encode($pApiOpts)); }