api接口里面:
public function getCity() {
if(request()->isGet()) {
$data = input('get.');
$res = model('Area')->getCityInfo($data);
$d = [
'data' => $res,
'code' => 1,
'msg' => "success"
];
$res = json_encode($d);
return json($d);
} else {
$this->result('',0,'请求出错');
}
}
Model里面:
public function getCityInfo($data) {
$validate = validate('Area')->check($data);
if($validate) {
$type = $data['type'];
switch ($type){
case "1":
$this->field('id1 id,title')->where('id2',0)->where('id3',0);
break;
case "2":
$this->field('id2 id,title')
->where('id2','>','0')
->where('id3',0)
->where('id1',$data['id1']);
break;
case "3":
$this->field('id3 id,title')
->where('id3','>','0')
->where('id2',$data['id2'])
->where('id1',$data['id1']);
break;
}
$order = [
'px' => 'desc',
'id' => 'asc'
];
$this->where('flag',1)->order($order);
return $this->select()->toArray();
}
}