100 lines
2.8 KiB
PHP
100 lines
2.8 KiB
PHP
<?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($show_limit = false)
|
|
{
|
|
$result = array();
|
|
$where = [];
|
|
if($show_limit){
|
|
$where["province_id in (430000,350000)"] = null;
|
|
}
|
|
$list = $this->select($where, 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 = '', $type = 0)
|
|
{
|
|
$result = array();
|
|
$list = $this->select(array('city_id' => $city_id), null, null, null, 'distinct(county_id), county_name');
|
|
$type == 0 && $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;
|
|
}
|
|
|
|
/**
|
|
* Notes:根据county_id获取数据
|
|
* Created on: 2021/11/16 14:18
|
|
* Created by: dengbw
|
|
* @param $ids
|
|
* @param string $fileds
|
|
* @param string $map_key
|
|
* @return array
|
|
*/
|
|
public function get_map_by_county_ids($ids, $fileds = '', $map_key = 'id')
|
|
{
|
|
$rows = [];
|
|
$ids = array_filter($ids);
|
|
if ($ids) {
|
|
$cf_ids = implode(',', $ids);
|
|
$where = [
|
|
"county_id in ($cf_ids)" => null
|
|
];
|
|
$rows = $this->map($map_key, '', $where, '', '', '', $fileds);
|
|
}
|
|
return $rows;
|
|
}
|
|
}
|