Files
liche/api/controllers/wxapp/app/City.php
T
2021-09-18 11:54:58 +08:00

64 lines
2.1 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("biz/biz_model");
}
protected function get(){
$page = $this->input_param('page');
$size = $this->input_param('size');
!$page && $page = 1;
!$size && $size = 20;
$default_city = 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];
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($city_id_arr,$default_city) ? $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;
}
}