Files
liche/common/models/Area_model.php
dengbw 50bab18192 channel_1117
channel_1117_2

channel_1117_3
2021-11-17 15:20:44 +08:00

96 lines
2.5 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 = '', $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;
}
}