| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- //城市
- class cityClassModel extends Model
- {
- //获取城市路径
- public $pathss;
- public function getpath($id)
- {
- $this->pathss = array();
- $this->getpaths($id);
- return $this->pathss;
- }
- private function getpaths($id)
- {
- $rs = $this->getone($id);
- if($rs && $rs['pid']!=$id){
- $this->getpaths($rs['pid']);
- $this->pathss[] = $rs;
- }
- }
-
-
- /**
- * 导入数据
- */
- public function daorudata()
- {
- $barr = c('xinhuapi')->getdata('base','city');
- if(!$barr['success'])return returnerror($barr['msg']);
- $data = $barr['data'];
- $shul = 0;
- foreach($data as $k=>$rs){
- $id = $rs['id'];
- if($this->rows($id)==0){
- $shul++;
- $this->insert($rs);
- }
- }
- return returnsuccess('成功导入'.$shul.'条数据');
- }
-
- /**
- * 籍贯/城市数据
- */
- public function citydata()
- {
- $rows = $this->db->getall('SELECT a.name,b.name as name1 FROM `[Q]city` a left join `[Q]city` b on a.`pid`=b.`id` where a.`type` in(2)');
- $barr = array();
- foreach($rows as $k=>$rs){
- $name = $rs['name'];
- if($name!=$rs['name1'])$name=$rs['name1'].$name;
- $barr[] = array(
- 'name' => $name,
- 'cityname' => $rs['name'],
- 'shengname' => $rs['name1'],
- );
- }
- return $barr;
- }
-
- /**
- * 省份数据
- */
- public function shengdata()
- {
- $rows = $this->db->getall('SELECT `name` FROM `[Q]city` where `pid`=1 order by `sort`');
- $barr = array();
- foreach($rows as $k=>$rs){
- $name = $rs['name'];
- $barr[] = array(
- 'name' => $name
- );
- }
- return $barr;
- }
-
- /**
- * 全部城市数据,3级
- */
- public function alldata()
- {
- $chche = c('cache');
- $cdata = $chche->get('cityalldata');
- if(!$cdata){
- $this->drowsa = $this->getall('1=1','*','`sort`');
- $this->datass = array();
- $this->alldatas($this->drowsa, '1', 0,'');
-
- $chche->set('cityalldata', $this->datass);
- return $this->datass;
- }else{
- return $cdata;
- }
- }
- private function alldatas($rows, $pid, $xu, $sub, $sheng='', $city='')
- {
- $keya = array('shengname','cityname','xianname');
- $zxij = 0;
- foreach($rows as $k=>$rs){
- if($rs['pid']==$pid){
- $zxij++;
- $sar = array(
- 'name' => $sub.$rs['name'],
- 'value' => $rs['name'],
- 'padding'=> 30*$xu,
- 'shengname' => $sheng,
- 'cityname' => $city,
- 'xianname' => '',
- );
- $keysas = $keya[$xu];
- $sar[$keysas] = $rs['name'];
- $this->datass[] = $sar;
-
- unset($this->drowsa[$k]);
- if($xu==0)$sheng = $rs['name'];
- if($xu==1)$city = $rs['name'];
- $xiji = $this->alldatas($this->drowsa, $rs['id'], $xu+1, $sub.$rs['name'], $sheng, $city);
- }
- }
- return $zxij;
- }
- }
|