Files
liche/common/models/Area_model.php
T
2021-08-19 10:42:49 +08:00

79 lines
2.0 KiB
PHP
Executable File

<?php
/**
* Created by PhpStorm.
* User: linfan
* Date: 2018/11/5
* Time: 13:47
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class Area_model extends HD_Model
{
private $table_name = 'lc_area';
public function __construct()
{
parent::__construct($this->table_name, 'default');
}
public function province()
{
$result = array();
$list = $this->select(null, null, null, null, 'distinct(province_id), province_name');
if($list)
{
foreach ($list as $v)
{
$result[$v['province_id']] = array(
'id' => $v['province_id'],
'name' => $v['province_name'],
);
}
}
return $result;
}
public function city($province_id = '',$type = 0)
{
$result = array();
$list = $this->select(array('province_id' => $province_id), null, null, null, 'distinct(city_id), city_name, firstchar');
$type == 0 && $result[] = array('name'=>'城市','id'=>'');
if($list)
{
foreach ($list as $v)
{
$item = array(
'id' => $v['city_id'],
'name' => $v['city_name'],
);
2 == $type && $item['firstchar'] = $v['firstchar'];
$result[$v['city_id']] = $item;
}
}
return $result;
}
public function county($city_id = '')
{
$result = array();
$list = $this->select(array('city_id' => $city_id), null, null, null, 'distinct(county_id), county_name');
$result[] = array('name'=>'行政区','id'=>'');
if($list)
{
foreach ($list as $v)
{
$result[$v['county_id']] = array(
'id' => $v['county_id'],
'name' => $v['county_name'],
);
}
}
return $result;
}
}