167 lines
3.3 KiB
PHP
167 lines
3.3 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class City_model extends CI_Model {
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->database();
|
|
}
|
|
|
|
/*
|
|
解析城市信息
|
|
*/
|
|
public function setCityMsg($row,$type = 1)
|
|
{
|
|
$data=array();
|
|
if ($type == 1)
|
|
{
|
|
$data=array(
|
|
'id' => $row->id,
|
|
'name' => $row->name,
|
|
'addtime' => $row->addtime,
|
|
'citydess' => $row->citydess
|
|
);
|
|
}else if ($type == 2)
|
|
{
|
|
$data=array(
|
|
'id' => $row->id,
|
|
'name' => $row->name,
|
|
'cityid' => $row->cityid,
|
|
'addtime' => $row->addtime,
|
|
'citydess' => $row->citydess
|
|
);
|
|
/*$where = array('id' => $row->cityid);
|
|
$infor = $this->Db_model->getSpecificData("city",$where);
|
|
|
|
if (count($infor) > 0)
|
|
{
|
|
$data=array(
|
|
'id' => $row->id,
|
|
'name' => $row->name,
|
|
'cityid' => $row->cityid,
|
|
'city' => $infor[0]->name,
|
|
'addtime' => $row->addtime
|
|
);
|
|
}else
|
|
{
|
|
$data=array(
|
|
'id' => "",
|
|
'name' => "",
|
|
'cityid' => "",
|
|
'city' => "",
|
|
'addtime' => ""
|
|
);
|
|
}*/
|
|
}else if ($type == 3)
|
|
{
|
|
$where = array('id' => $row->cityid);
|
|
$infor = $this->Db_model->getSpecificData("city",$where);
|
|
$city = "";
|
|
if (count($infor) > 0)
|
|
$city = $infor[0]->name;
|
|
|
|
$where = array('id' => $row->areaid);
|
|
$areainfor = $this->Db_model->getSpecificData("area",$where);
|
|
$area = "";
|
|
if (count($areainfor) > 0)
|
|
$area = $areainfor[0]->name;
|
|
$citydess= $infor[0]->citydess;
|
|
$data=array(
|
|
'id' => $row->id,
|
|
'name' => $row->name,
|
|
'cityid' => $row->cityid,
|
|
'city' => $city,
|
|
'cityd' => $citydess,
|
|
'areaid' => $row->areaid,
|
|
'area' => $area,
|
|
'img' => $row->img,
|
|
'addtime' => $row->addtime
|
|
);
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
/*
|
|
接收城市信息
|
|
*/
|
|
public function receiveCityMsg()
|
|
{
|
|
date_default_timezone_set("Asia/Shanghai");
|
|
$name = isset($_POST['cityname'])?$_POST['cityname']:"";
|
|
$cityd= isset($_POST['cityd'])?$_POST['cityd']:"";
|
|
|
|
$data = array(
|
|
'name' => $name,
|
|
'citydess' => $cityd,
|
|
'addtime' => date("m/d/Y")
|
|
);
|
|
return $data;
|
|
}
|
|
|
|
/*
|
|
获得城市
|
|
*/
|
|
public function getCity()
|
|
{
|
|
$infor = $this->Db_model->getAllData("city");
|
|
$data=array();
|
|
foreach($infor as $v){
|
|
$data[] = $this->setCityMsg($v,1);
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
/*
|
|
获得城区
|
|
*/
|
|
public function getArea($cityid)
|
|
{
|
|
if ($cityid != "")
|
|
$where = array('cityid' => $cityid);
|
|
else
|
|
$where = array();
|
|
$infor = $this->Db_model->getSpecificData("area",$where);
|
|
|
|
$data=array();
|
|
foreach($infor as $v){
|
|
$data[] = $this->setCityMsg($v,2);
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
/*
|
|
获得小区(城区下所有小区)
|
|
*/
|
|
public function getCommunity($areaid)
|
|
{
|
|
if ($areaid != "")
|
|
$where = array('areaid' => $areaid);
|
|
else
|
|
$where = array();
|
|
$infor = $this->Db_model->getSpecificData("community",$where);
|
|
|
|
$data=array();
|
|
foreach($infor as $v){
|
|
$data[] = $this->setCityMsg($v,3);
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
/*
|
|
小区信息
|
|
*/
|
|
public function communityInfor($communityid)
|
|
{
|
|
$where = array('id' => $communityid);
|
|
$infor = $this->Db_model->getSpecificData("community",$where);
|
|
|
|
if (count($infor) <= 0)
|
|
return ;
|
|
|
|
$data = $this->setCityMsg($infor[0],3);
|
|
return $data;
|
|
}
|
|
}
|