//echo $jsonStores; $rootElements = json_decode($jsonStores, true); $stores = $rootElements['searchItems']; //print_r($stores); //return; echo 'Start import stores with file :' . $file . ' Count:' . count($stores) . '<br>'; foreach ($stores as $store) { //print_r($store); //return; $storeRefID = '7009-' . $store['Id']; $storeName = $store['Name']; $checkExisted = $objStore->getStoreByRefID($storeRefID); //print_r($checkExisted); ; if (!$checkExisted) { $cityName = $store['City']; $city = $objCity->getCityByName($cityName); //print_r($city); if ($city) { $cityID = $city[global_mapping::CityID]; } else { $cityID = $objCity->insert($cityName); } $districtName = $store['District']; $district = $objDistrict->getDistrictByName($districtName); //print_r($district); if ($district) { $districtID = $district[global_mapping::DistrictID]; } else { $districtID = $objDistrict->insert($districtName, $cityID); } echo 'DistricID:' . $districtID . '<br>';
/** * 增加城市 */ public function addAction() { if ($this->_request->isPost()) { //修改密码验证 $aCookie = Util_Cookie::get(Yaf_G::getConf('authkey', 'cookie')); $iAdminID = $aCookie['iAdminID']; $aUser = Model_Admin::getDetail($iAdminID); $pwd = $this->getParam('pwd'); if (!isset($pwd) || $pwd == '') { return $this->showMsg('修改密码不可以为空', false); } if ($aUser['sEditPassword'] != md5($pwd)) { return $this->showMsg('修改密码不正确', false); } $aCity = $this->_checkData('add'); if (empty($aCity)) { return null; } if (Model_City::getCityByName($aCity['sCityName'])) { return $this->showMsg('城市已经存在!', false); } if (Model_City::addData($aCity) > 0) { return $this->showMsg('城市增加成功!', true); } else { return $this->showMsg('城市增加失败!', false); } } }