* @version LV1.0 */ namespace Common\Model; use Think\Model; //[1.7.90] /** * Class CitysModel * @package Common\Model */ class CitysModel extends BaseModel { protected $tableName = 'citys'; protected $fields = array( 0 => 'id', // int(11) NOT NULL AUTO_INCREMENT COMMENT '主键', 1 => 'cityid', // int(11) NOT NULL COMMENT '城市ID', 2 => 'parentid', // int(11) NOT NULL DEFAULT '0' COMMENT '父节点ID', 3 => 'city_name', // varchar(50) NOT NULL COMMENT '城市名称', 4 => 'state', // tinyint(1) NOT NULL DEFAULT '0' COMMENT '状态 0:正常 1:删除', ); public function getListBase($map, $order) { $list = $this->where($map)->order($order)->select(); return $list; } public function getList($map, $page, $order) { $list = $this->where($map)->order($order)->page($page)->select(); return $list; } public function getCount($map, $order) { $list = $this->where($map)->order($order)->count(); return $list; } /** * 根据ID获取地区信息 * * @return array 根据ID获取地区信息 */ public function getCityById($id) { $map ['id'] = $id; $Citys = $this->where($map)->find(); return $Citys; } /** * 添加地区信息 * * @return 添加地区信息 */ public function AddCity($City) { $ret = $this->data($City)->add(); return $ret; } /** * 修改地区信息 * * @return 修改地区信息 */ public function updateCity($City) { $ret = $this->where('id=' . $City ['id'])->save($City); return $ret; } /** * 修改地区信息 * * @return 修改地区信息 */ public function updateCityEx($where, $City) { $ret = $this->where($where)->save($City); return $ret; } /** * 删除地区信息 * * @return 删除地区信息 */ public function deleteCity($where) { $ret = $this->where($where)->delete(); return $ret; } /** * 根据区域ID,获取城市信息 * @param $temDistributionAreaCom 区域ID总 ","拼接 * @return mixed */ public function distributionAreaCityInfo($temDistributionAreaCom) { $cityData = $this->field('id,cityid,parentid,city_name') ->where("state = 0") ->where(array('cityid' => array('in', $temDistributionAreaCom))) ->select(); return $cityData; } /** * 根据父节点,查询当前城市的上一级信息 * @param $parentId 父节点ID * @return mixed */ public function getAreaCityInfoByParentId($parentId) { $cityData = $this->field('id,cityid,parentid,city_name') ->where("state = 0") ->where(array('cityid' => $parentId)) ->find(); return $cityData; } /** * 查询省市区对应的区域信息 * @param $province 省 * @param $city 市 * @param $area 区 * @return mixed */ public function getCityDataByCityName($province, $city, $area) { $cityData = $this->field('id,cityid,parentid,city_name') ->where(array('city_name' => array('in', $province . ',' . $city . ',' . $area))) ->select(); return $cityData; } }