<?php
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_index_restriction extends discuz_table
{
public function __construct()
{
parent::__construct();
$this->_pk = 'id';
$this->_table = 'plugin_lingke_license_restriction';
}
var $city = array(
'Beijing'=>'北京',
'Tianjin'=>'天津',
'Shijiazhuang'=>'石家庄',
'Xingtai'=>'邢台',
'Handan'=>'邯郸',
'Baoding'=>'保定',
'Cangzhou'=>'沧州',
'Langfang'=>'廊坊',
'Tangshan'=>'唐山',
'Qinhuangdao'=>'秦皇岛',
'Zhengzhou'=>'郑州',
'Hangzhou'=>'杭州',
'Nanchang'=>'南昌',
'Guiyang'=>'贵阳',
'Chengdu'=>'成都',
'Xian'=>'西安',
'Lanzhou'=>'兰州',
);
/**
* 一周记录
*
* @access public
* @param string, int, int, string
* @return array
*/
public function restriction_week_list($city, $monday)
{
$min_time = $monday;
$max_time = $min_time + 86400 * 6;
$sql = 'SELECT * FROM %t WHERE city=%s AND day>=%d AND day<=%d ORDER BY id ASC';
return DB::fetch_all($sql, array($this->_table, $city, $min_time, $max_time));
}
public function city_key_get($city)
{
$city_key = '';
if(! $city){
return $city_key;
}
foreach($this->city as $key =>$value){
if(strpos($city, $value) !== FALSE){
$city_key = $key;
break;
}
}
return $city_key;
}
public function traffic_restriction_get($city, $date)
{
$date = date('Ymd', $date);
$where = '{"Date":"'.$date.'"}';
$url = 'https://9y7h7igs.api.lncld.net/1.1/classes/'.$city.'?where='.$where;
$headers = array(
'X-LC-Id: ',
'X-LC-Key: ',
'Content-Type:application/json',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
$errno = curl_errno($ch);
curl_close($ch);
if($errno) {
return lib_base::back_array('网络错误');
}
$result = json_decode($result, true);
if(! $result['results'][0]){
return lib_base::back_array('网络错误');
}
$data = array(
'date'=>$result['results'][0]['Date'],
'number'=>($result['results'][0]['TailNumber'] && $result['results'][0]['TailNumber'] != 'none') ? $result['results'][0]['TailNumber'] : '',
);
return lib_base::back_array($data, 0);
}
}