objMSysAreaChina = new MSysAreaChina(); $this->objSysAreaChinaCache = new SysAreaChinaCache('mapping'); } /** * 获取所有省份 */ public function getAllProvince() { if($this->objSysAreaChinaCache->isHaveProvinceKey()) { $returnData = $this->objSysAreaChinaCache->getAllProvince();//获取缓存 }else{ $result = $this->objMSysAreaChina->getAllProvince(); if (!$result->isSuccess()) { parent::sendOutput($result->getData(), ErrorCode::$dberror); } $returnData = $result->getData(); if(!empty($returnData)){ $this->objSysAreaChinaCache->cacheAllProvince($returnData); } } parent::sendOutput($returnData, 0, ['pageTotal'=>count($returnData)]); } /** * 根据省份id获取所有城市 */ public function getAllCityByProvinceCode() { $code = $this->request->param('request_id'); if (empty($code)) { $this->sendOutput('请指定省份id', ErrorCode::$paramError); } if($this->objSysAreaChinaCache->isHaveCityKeyByProvinceCode($code)){ $returnData = $this->objSysAreaChinaCache->getCityByProvinceCode($code); }else{ $result = $this->objMSysAreaChina->getAllCityByProvinceCode(['pcode' => $code]); if (!$result->isSuccess()) { parent::sendOutput($result->getData(), ErrorCode::$dberror); } $returnData = $result->getData(); if(!empty($returnData)){ $this->objSysAreaChinaCache->cacheCityByCode($returnData, $code); } } parent::sendOutput($returnData, 0, ['pageTotal'=>count($returnData)]); } /** * 获取指定城市下的所有区 */ public function getAllAreaByCityCode() { $code = $this->request->param('request_id'); if (empty($code)) { $this->sendOutput('请指定城市id', ErrorCode::$paramError); } if($this->objSysAreaChinaCache->isHaveAreaKeyByCityCode($code)){ $returnData = $this->objSysAreaChinaCache->getAreaByCityCode($code); }else{ $result = $this->objMSysAreaChina->getAllAreaByCityCode(['pcode' => $code]); if (!$result->isSuccess()) { parent::sendOutput($result->getData(), ErrorCode::$dberror); } $returnData = $result->getData(); if(!empty($returnData)){ $this->objSysAreaChinaCache->cacheAreaByCode($returnData, $code); } } parent::sendOutput($returnData, 0, ['pageTotal'=>count($returnData)]); } }