Files
2023-03-10 17:23:52 +08:00

131 lines
4.6 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
{
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");
}
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;
}
$typeAry = $this->biz_model->type_ary();
$type_ids = implode(',',array_keys($typeAry));
$type_ids && $biz_where["type in ($type_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;
}
//上牌城市
public function get_oncard()
{
$where = [
'province_id' => 350,
'status' => 1
];
$lists = $this->sys_area_model->select_groupby('city_id', $where, '', '', '', 'city_id,city_name as name');
$data = [
'list' => $lists,
];
return $data;
}
/**
* Notes:获取省/市/区/街道
* Created on: 2022/7/1 11:17
* Created by: dengbw
* @return mixed
*/
public function get_area()
{
$this->load->model('area_model', 'mdArea');
$type = $this->input->get('type');
$pid = intval($this->input->get('pid'));
$lists = [];
switch ($type) {
case 'city':
!$pid && $pid = 350;//默认福建
$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, 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;
}
}