Sundry.php
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/4/29
* Time: 17:43
*/
namespace app\index\controller;
use app\common\controller\HomeBase;
use app\index\model\Area;
use app\index\model\Province;
use fast\Http;
/**
* 杂项
* Class Sundry
* @package app\index\controller
*/
class Sundry extends HomeBase
{
/**
* 关键字输入提示
*/
public function get_address(){
$keyword = $this->request->param('keyword');
if(empty($keyword)){
$this->error('缺少必要参数');
}
$url = "https://apis.map.qq.com/ws/place/v1/suggestion/?keyword=$keyword&key=M4ABZ-MM7W3-WH43F-YXSKV-XYCBT-2NB2J";
$result = Http::get($url);
$result = json_decode($result,true);
if($result['status'] != 0){
$this->error($result['message']);
}
$data['count'] = $result['count'];
$data['list'] = $result['data'];
$this->success('SUCCESS','',$data);
}
/**
* 省份名称转换id
*/
public function get_province_id(){
$province_name = $this->request->param('province_name');
if(empty($province_name)){
$this->error('缺少必要参数');
}
$provinceModel = new Province();
$province_id = $provinceModel->where(['name'=>$province_name])->value('id');
$this->success('SUCCESS','',['province_id'=>$province_id]);
}
/**
* 省市区三级联动
*/
public function get_area(){
$pid = $this->request->param('pid',0,'intval');
$level = $this->request->param('level',0,'intval');
if(empty($level)){
$this->error('缺少必要参数');
}
$where['pid'] = ['eq',$pid];
$where['level'] = ['eq',$level];
$areaModel = new Area();
$data = $areaModel->selectData($where);
$this->success('SUCCESS','',$data);
}
}