Files
spacestation/api/controllers/wxapp/app/City.php
T
lin fan 7d22016c69 1
2024-11-21 15:02:41 +08:00

149 lines
5.4 KiB
PHP

<?php
defined('WXAPP_APP') or exit('No direct script access allowed');
/**
* Created by vim
* User: lcc
* Desc: 城市
* Date: 2021/07/27
* Time: 10:22
*/
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
class City extends Wxapp
{
private $province_lists = [350000, 430000]; //开放省份 湖南 福建
function __construct($inputs, $app_key)
{
parent::__construct($inputs, $app_key);
$this->login_white = array('get');//登录白名单
$this->check_status = array();//用户状态校验
$this->check_mobile = array();//需要手机号
$this->check_headimg = array();//授权微信信息
$this->load->model("sys/sys_city_model");
$this->load->model("sys/sys_area_model");
$this->load->model("biz/biz_model");
$this->load->model('area_model', 'mdArea');
$this->biz_id = $this->get_biz_id();
}
protected function get()
{
$page = $this->input_param('page');
$size = $this->input_param('size');
!$page && $page = 1;
!$size && $size = 20;
$default_city = $this->session['city_id'] ? $this->session['city_id'] : 350200;
$where = [
'status' => 1
];
if ($this->app_id == 2 && $this->session['group_id'] == 4) {
$biz_id_arr = explode(',', $this->session['biz_id']);
$biz_where = ['city_id>' => 0, 'status' => 1, 'type<>' => 4];
if ($this->session['biz_id'] && $biz_id_arr) {
$biz_ids = implode(',', $biz_id_arr);
$biz_where["id in ({$biz_ids})"] = null;
}
$biz_rows = $this->biz_model->select_groupby('city_id', $biz_where, '', '', '', 'id,city_id');
$city_ids = implode(',', array_column($biz_rows, 'city_id'));
$city_ids && $where["city_id in ($city_ids)"] = null;
}
$count = $this->sys_city_model->count($where);
$lists = [];
if ($count) {
$rows = $this->sys_city_model->select($where, 'id desc', $page, $size, 'id,city_id,name');
$city_id_arr = array_column($rows, 'city_id');
$default_city = in_array($default_city, $city_id_arr) ? $default_city : $city_id_arr[0];
foreach ($rows as $key => $val) {
$lists = $val;
}
$lists = $rows;
}
$data = [
'list' => $lists,
'total' => $count,
'default' => $default_city
];
return $data;
}
protected function get_lists()
{
if ($this->session['province_id']) {
$province_lists[] = $this->session['province_id'];
} else {
$province_lists = $this->province_lists; //开发城省份 湖南 福建
}
$lists = [];
foreach ($province_lists as $item) {
$where['province_id'] = $item;
$rows = $this->mdArea->select_groupby('city_id', $where, '', 0, 100, 'city_id,city_name,id,province_name');
$children = [];
foreach ($rows as $k => $item2) {
if (!$k) {
$children[] = ['city_id' => 0, 'name' => '全省'];
}
$children[] = ['city_id' => $item2['city_id'], 'name' => $item2['city_name']];
}
$lists[] = ['name' => $rows[0]['province_name'], 'province_id' => $item, 'children' => $children];
}
$data = [
'area_list' => $lists,
'default_area_id' => [$province_lists[0], 0]
];
return $data;
}
/**
* Notes:获取省/市/区/街道
* Created on: 2022/7/1 11:17
* Created by: dengbw
* @return mixed
*/
public function get_area()
{
$type = $this->input->get('type');
$pid = intval($this->input->get('pid'));
$lists = [];
switch ($type) {
case 'city':
if(!$pid && $this->biz_id){
$biz = $this->biz_model->get(['id' => $this->biz_id]);
$biz['province_id'] && $pid = $biz['province_id'];
}
$res = $this->mdArea->select(['province_id' => $pid], null, null, null, 'distinct(city_id), city_name');
foreach ($res as $v) {
$lists[] = ['id' => $v['city_id'], 'name' => $v['city_name']];
}
break;
case 'county':
$res = $this->mdArea->select(['city_id' => $pid], null, null, null, 'distinct(county_id), county_name');
foreach ($res as $v) {
$lists[] = ['id' => $v['county_id'], 'name' => $v['county_name']];
}
break;
case 'street':
$this->load->model('sys/sys_street_model', 'mdStreet');
$res = $this->mdStreet->select(['county_id' => $pid], 'id ASC', 0, 0, 'street_id,street_name');
foreach ($res as $v) {
$lists[] = ['id' => $v['street_id'], 'name' => $v['street_name']];
}
break;
default:
$res = $this->mdArea->select([], null, null, null, 'distinct(province_id), province_name');
foreach ($res as $v) {
$lists[] = ['id' => $v['province_id'], 'name' => $v['province_name']];
}
break;
}
$data = [
'list' => $lists,
];
return $data;
}
}