TravelController.php
7.7 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
/**
* 商旅服务
* Author : xiaojie
* DateTime: 2018/12/06 11:46
*/
namespace app\portal\controller;
use app\portal\model\PageModel;
use app\portal\model\PortalCategoryModel;
use app\portal\model\CarWxModel;
use app\portal\model\ShowModel;
use cmf\controller\HomeBaseController;
class TravelController extends HomeBaseController
{
private $appkey = 'a31656a82e1147b189246f88ddac2adf';
private $url = 'http://v.juhe.cn/xianxing/index';
/**
* 交通信息
* portal/travel/traffic
*/
public function traffic()
{
$cate_id = 42;
$pageModel = new PageModel();
$info = $pageModel->where('cate_id',$cate_id)->find();
//所在位置
$location = [
[
'location' => '商旅服务',
'url' => 'javascript:;'
],
[
'location' => '交通信息',
'url' => url('portal/travel/traffic')
]
];
$this->assign('info',$info);
$this->assign('location',$location);
return $this->fetch();
}
/**
* 酒店住宿,周边美食,天津旅游(43,44,45)
* portal/travel/news
*/
public function news()
{
$cate_id = $this->request->param('cate_id');
$showModel = new ShowModel();
$list = $showModel->getList($cate_id);
if($cate_id == 43){
$location = '酒店住宿';
$menu_id = '49';
}elseif ($cate_id == 44){
$location = '周边美食';
$menu_id = '50';
}elseif ($cate_id == 45){
$location = '天津旅游';
$menu_id = '51';
}else{
return false;
}
//分页样式
$page = $this->getPageStyle($list);
//所在位置
$location = [
[
'location' => '商旅服务',
'url' => 'javascript:;'
],
[
'location' => $location,
'url' => url('portal/travel/news',array('cate_id'=>$cate_id))
]
];
$this->assign('list',$list);
$this->assign('location',$location);
$this->assign('page',$page);
$this->assign('menu_id',$menu_id);
return $this->fetch(':list');
}
//移动端交通信息
public function trafficMobile(){
//交通信息数据
$cateId = 42;
$pageModel = new PageModel();
$info = $pageModel->where('cate_id',$cateId)->find();
$this->assign('info',$info);
return $this->fetch();
}
//移动端酒店住宿
public function hotelMobile(){
return $this->fetch();
}
//移动度周边美食
public function foodMobile(){
return $this->fetch();
}
//移动端商旅服务列表数据
public function get_list(){
$cate_id = $this->request->param('cate_id');
$page = $this->request->param('page');
$data = $this->dataList($cate_id,$page);
$week = ['日','一','二','三','四','五','六'];
foreach($data['list'] as &$value){
$value['menu_id'] = $data['menu_id'];
$value['thumb'] = cmf_get_image_url($value['thumb']);
$value['m'] = date('m',$value['update_time']);
$value['d'] = date('d',$value['update_time']);
$value['w'] = $week[date('w',$value['update_time'])];
}
echo json_encode($data['list']);
}
//移动端天津旅游
public function travelMobile(){
return $this->fetch();
}
//移动端商旅服务数据
public function dataList($cate_id,$page){
$showModel = new ShowModel();
$list = $showModel->getMobileList($cate_id,$page);
if($cate_id == 43){
$menu_id = '49';
}elseif ($cate_id == 44){
$menu_id = '50';
}elseif ($cate_id == 45){
$menu_id = '51';
}elseif ($cate_id == 36){
$menu_id = '42';
}else{
return false;
}
//分页样式
$data = [];
$data['list'] = $list;
$data['menu_id'] = $menu_id;
return $data;
}
//商旅服务详情页
public function detail(){
$id = $this->request->param('id','','intval');
$showModel = new ShowModel();
$info = $showModel->getDetail($id);
$this->setShowNum($info['id']);
$info['thumb'] = cmf_get_image_url($info['thumb']);
$this->assign('info',$info);
return $this->fetch();
}
//车辆限号
public function carWx(){
$carModel = new CarWxModel();
$info = $carModel->select();
echo json_encode($info);
}
//移动端限号数据
public function limitRow(){
$url = $this->url;
$params = array(
"key" => $this->appkey,//应用APPKEY(应用详细页查询)
"dtype" => "",//返回数据的格式,xml或json,默认json
"city" => "tianjin",//城市代码,在城市列表接口获取
"type" => "6",//类型,1:今日 2:明天 3:后天 4:第4天 5:第5天 6:第6天 默认1
);
$paramstring = http_build_query($params);
$content = $this->http($url,$paramstring);
$res_decode = json_decode($content,true);
if($res_decode){
if($res_decode['error_code']=='0'){
$date = strtotime($res_decode['result']['date']);
$week = $res_decode['result']['week'];
if($res_decode['result']['xxweihao']){
$number = $res_decode['result']['xxweihao'][0].'/'.$res_decode['result']['xxweihao'][1];
}else{
$number = '不限行';
}
$result['date'] = date('n',$date).'月'.date('j',$date).'日';
$result['week'] = '周'.mb_substr($week,2,1,"UTF-8");
$result['number'] = $number;
$result['create_time'] = time();
$wxModel = new CarWxModel();
$wxModel->get(1)->delete();
$wxModel::create($result);
echo '请求成功';
}else{
echo $res_decode['error_code'].":".$res_decode['reason'];
}
}else{
echo "请求失败";
}
}
/**
* 请求接口返回内容
* @param string $url [请求的URL地址]
* @param string $params [请求的参数]
* @param int $ipost [是否采用POST形式]
* @return string
*/
private function http($url,$params=false,$ispost=0){
$httpInfo = array();
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if( $ispost )
{
curl_setopt( $ch , CURLOPT_POST , true );
curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
curl_setopt( $ch , CURLOPT_URL , $url );
}
else
{
if($params){
curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
}else{
curl_setopt( $ch , CURLOPT_URL , $url);
}
}
$response = curl_exec( $ch );
if ($response === FALSE) {
//echo "cURL Error: " . curl_error($ch);
return false;
}
$httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
$httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
curl_close( $ch );
return $response;
}
}