Sundry.php
2.8 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/4/29
* Time: 17:43
*/
namespace app\index\controller;
use app\common\controller\Frontend;
use app\index\model\Area;
use app\index\model\Consult;
use app\index\model\Province;
use fast\Http;
/**
* 杂项
* Class Sundry
* @package app\index\controller
*/
class Sundry extends Frontend
{
protected $noNeedLogin = ['get_address','get_province_id','get_area'];
protected $noNeedRight = ['*'];
/**
* 关键字输入提示
*/
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);
}
public function consult(){
$user_id = $this->auth->id;
$goods_id = $this->request->param('goods_id',0,'intval');
if(empty($goods_id)){
$this->error('缺少必要参数');
}
$arr['user_id'] = $user_id;
$arr['goods_id'] = $goods_id;
$arr['status'] = '1';
$arr['createtime'] = time();
$consultModel = new Consult();
$data = $consultModel->findData(['user_id'=>$user_id,'goods_id'=>$goods_id,'status'=>'1']);
if(!empty($data)){
$result = $consultModel->updateData(['id'=>$data['id']],$arr);
}else{
$result = $consultModel->insertData($arr);
}
if(empty($result)){
$this->error('sql执行失败');
}
$this->success('SUCCESS');
}
}