123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- /**
- * 地区数据(中国)
- * Created by PhpStorm.
- * User: QianNiao-C
- * Date: 2019/10/26
- * Time: 9:57
- */
- namespace Jindouyun\Controller\Common;
- use Mall\Framework\Core\ErrorCode;
- use JinDouYun\Cache\SysAreaChinaCache;
- use Jindouyun\Controller\BaseController;
- use JinDouYun\Model\SysAreaChina\MSysAreaChina;
- class SysAreaChina extends BaseController
- {
- private $objMSysAreaChina;
- private $objSysAreaChinaCache;
- public function __construct($isCheckAcl = false, $isMustLogin = false)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->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)]);
- }
- }
|