/commonshell/liuzhumei/modules/front/controllers/CityController.php
PHP | 182 lines | 112 code | 14 blank | 56 comment | 6 complexity | f70eec24db0e585f431cf7c63c40cca5 MD5 | raw file
- <?php
-
- class CityController extends Front_Controller_Action_Abstract
- {
- protected $db;
-
- public function init()/*{{{*/
- {
- try {
- $this->_db = Mongo_Database::instance(Zend_Registry::get('config')->mongo->dbconfig,
- array('server' => Zend_Registry::get('config')->mongo->server,
- 'database' => Zend_Registry::get('config')->mongo->db));
- parent::init();
- } catch (Exception $e) {
- echo 'Caught exception: ', $e->getMessage(), "\n";
- return ;
- }
- }/*}}}*/
-
- public function indexAction()/*{{{*/
- {
- //?????????
- $doc = new Front_Model_City();
- $city = $doc->collection()->reset()->find(array('parent'=>$this->_getParam('pro')))->load();
- $cursor = $city->cursor();
- $tmp = array();
- while($item = $cursor->getNext()) {
- $tmp[$item['cid']] = array('name'=>$item['name'], 'mall'=>$item['mall']);
- }
-
- if ($this->_request->isXmlHttpRequest() || isset($_GET['ajax']))
- {
- $this->_helper->viewRenderer->setNoRender();
- echo json_encode($tmp);
- return ;
- }
- } /*}}}*/
-
- public function mallAction()
- {
- //????ID??????
- $this->_helper->viewRenderer->setNoRender();
- $doc = new Front_Model_City();
- $city = $doc->collection()->reset()->find(array('cid'=>$this->_getParam('cid','')))->load();
- $cursor = $city->cursor();
- $tmp = array();
- while($item = $cursor->getNext()) {
- $tmp = $item['mall'];
- }
-
- if ($this->_request->isXmlHttpRequest() || isset($_GET['ajax']))
- {
- $this->_helper->viewRenderer->setNoRender();
- echo json_encode($tmp);
- return ;
- }
-
- /*/*{{{*/
- $this->_helper->viewRenderer->setNoRender();
- try {
- //???????????
- $doc = new Front_Model_City();
- $updoc = new Front_Model_City();
- $malldoc = new Front_Model_Mall();
-
- $city = $doc->collection()->reset()->find(array('parent'=>array('$ne'=>'')))->load();
- $cursor = $city->cursor();
- $tmp = array();
- while($item = $cursor->getNext()) {
- //find mall by city name
- $city_name = mb_substr($item['name'], 0, 9);
- $match_mall = $malldoc->collection()->reset()->find(array('desc'=>new MongoRegex("/{$city_name}/i")))->load();
- $m_cursor = $match_mall->cursor();
- while($match_item = $m_cursor->getNext()) {
- $updoc->load(array('_id'=>$item['_id']));
- $updoc->addToSet('mall', array("{$match_item['mid']}"=>"{$match_item['name']}"));
- $updoc->save();
- $updoc->clear();
- }
- }
- } catch (Exception $e) {
- echo 'Caught exception: ', $e->getMessage(), "\n";
- return ;
- }
- *//*}}}*/
- }
-
- public function proAction()
- {
- //???????
- $doc = new Front_Model_City();
- $city = $doc->collection()->reset()->find(array('parent'=>''))->load();
- $cursor = $city->cursor();
- $tmp = array();
- while($item = $cursor->getNext()) {
- $tmp[$item['cid']] = $item['name'];
- }
-
- if ($this->_request->isXmlHttpRequest() || isset($_GET['ajax']))
- {
- $this->_helper->viewRenderer->setNoRender();
- echo json_encode($tmp);
- return ;
- }
-
- /*/*{{{*/
- $this->_helper->viewRenderer->setNoRender();
- $doc = new Front_Model_City();
- $city = $doc->collection()->find(array('co'=>'china'))->load();
- $cursor = $city->cursor();
- $tmp = array();
- while($item = $cursor->getNext()) {
- //print_r($item);
- $tmp[$item['name']] = $item['cid'];
- }
-
- $city = $doc->collection()->reset()->find(array('co'=>array('$ne'=>'china')))->load();
- $upcursor = $city->cursor();
- $updoc = new Front_Model_City();
- while($item = $upcursor->getNext()) {
- $updoc->load(array('_id'=>$item['_id']));
- $updoc->set('parent', $tmp[$item['pro']]);
- $updoc->save();
- $updoc->clear();
- }
- echo "update success";
- */
-
- /*
- $doc = new Front_Model_City();
- $pro = $this->_db->db()->command(array("distinct"=>"city","key"=>"pro"));
- //var_dump($pro);exit;
- foreach($pro['values'] as $k=>$v) {
- $doc->co = 'china';
- $doc->mall = '';
- $doc->name = $v;
- $doc->pro = $v;
- $doc->parent = '';
- $doc->save();
- $doc->clear();
- }
- *//*}}}*/
- }
-
- public function importAction()/*{{{*/
- {
- /*
- $this->_helper->viewRenderer->setNoRender();
- $cmodel = new Front_Model_Db_Mycity();
- $clist = $cmodel->getCity();
- foreach($clist as $k=>$v) {
- $tmp[intval($v['id'])] = $v;
- }
-
- foreach($tmp as $k=>$v) {
- $head = substr($v['id'], 0, 2);
- $tail = substr($v['id'], -2);
- if(($tail == '00') && !in_array($v['name'],array("?", "???"))){
- $pro = $tmp[intval("{$head}0000")]['name'];
- if(($pro != $v['name']) && substr($v['name'],-1) != "?")
- $datas[] = array( 'name' => $v['name'], 'pro' => $pro, 'co' => '??');
- }
- }
-
- try {
- $this->db = Mongo_Database::instance(Zend_Registry::get('config')->mongo->dbconfig,
- array('server' => Zend_Registry::get('config')->mongo->server,
- 'database' => Zend_Registry::get('config')->mongo->db));
- $this->db->createCollection('city');
- $doc = new Front_Model_City();
- foreach($datas as $data) {
- $doc->load_values($data)->save();
- $doc->clear();
- }
- } catch (Exception $e) {
- echo 'Caught exception: ', $e->getMessage(), "\n";
- return ;
- }
- echo "import success";
- */
- }/*}}}*/
- }