国内站点更新程序

mobile-first
赵鹏 6 years ago
parent 95ef6c66ee
commit d246571e1b

@ -0,0 +1,174 @@
<?php
/*
* @Author: your name
* @Date: 2020-01-14 11:19:04
* @LastEditTime : 2020-01-14 11:30:24
* @LastEditors : Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \information-system\application\third_party\updatetrain\controllers\updatestation.php
*/
defined('BASEPATH') or exit('No direct script access allowed');
ini_set('memory_limit', '128M');
class updatestation extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model("station_model");
}
public function index()
{
//
$this->load->view('bootstrap3/header');
$this->load->view('updatestation');
$this->load->view('bootstrap3/footer');
}
/**
* @description: 从12306抓取数据对比翰特数据库
* @param {type}
* @return:
*/
public function getstatioBy12306()
{
$stationUrl = "https://kyfw.12306.cn/otn/resources/js/framework/station_name.js";
$StationData = $this->get_data($stationUrl);
// echo $StationData;
$arr_Station = explode("@", str_replace("';", "", str_replace("var station_names ='", "", $StationData)));
//print_r($arr_Station);
$NewStation = "";
for ($i = 0; $i < count($arr_Station); $i++) {
if ($arr_Station[$i] != null) {
$arr_StationDetail = explode("|", $arr_Station[$i]);
// print_r($arr_StationDetail);
//对比数据库,如果是新的就保存
$isNew = $this->station_model->GetStationCount($arr_StationDetail[2], $arr_StationDetail[1]);
if ($isNew) {
$NewStation .= $arr_Station[$i]."@";
}
}
}
echo $NewStation;
}
/**
* @description: 对比12306与目前的站点文件
* @param {type}
* @return:
*/
public function getNewStationByFile()
{
$stationUrl = "https://kyfw.12306.cn/otn/resources/js/framework/station_name.js";
$StationData = $this->get_data($stationUrl);
$StationFileUrl = "https://biz.chinahighlights.com/china-trains/js/train/StationInfo.js";
$StationFileData = $this->get_data($StationFileUrl);
// echo $StationData;
$arr_Station = explode("@", str_replace("';", "", str_replace("var station_names ='", "", $StationData)));
$arr_StationFile = explode("@", str_replace("\";", "", str_replace("var station_names =\"", "", $StationFileData)));
//print_r($arr_Station);
$NewStation = "";
for ($i = 0; $i < count($arr_Station); $i++) {
$isNew = true;
$arr_StationDetail = explode("|", $arr_Station[$i]);
for ($j = 0; $j < count($arr_StationFile); $j++) {
if ($arr_Station[$i] != null) {
$arr_StationFileDetail = explode("|", $arr_StationFile[$j]);
//对比目前的站点文件,如果是新的就保存
if ($arr_StationDetail[2] == $arr_StationFileDetail[1] && $arr_StationDetail[1] == $arr_StationFileDetail[3]) {
//break;
$isNew = false;
break;
// continue 2;
}
}
}
if ($isNew) {
$NewStation .= $arr_Station[$i]."@";
}
}
echo $NewStation;
}
/**
* @description: 目前站点文件与翰特数据对比
* @param {type}
* @return:
*/
function CheckFileAndHT(){
$StationFileUrl = "https://biz.chinahighlights.com/china-trains/js/train/StationInfo.js";
$StationFileData = $this->get_data($StationFileUrl);
$arr_StationFile = explode("@", str_replace("\";", "", str_replace("var station_names =\"", "", $StationFileData)));
$NewStation = "";
for ($i=0;$i<count($arr_StationFile);$i++){
$arr_StationFileDetail = explode("|", $arr_StationFile[$i]);
//对比数据库,如果是新的就保存
$isNew = $this->station_model->GetStationCount($arr_StationFileDetail[1], $arr_StationFileDetail[3]);
if ($isNew) {
$NewStation .= $arr_StationFile[$i]."@";
//保存到数据库
$data["StationCN"] = $arr_StationFileDetail[3];
$data["Station"] = $arr_StationFileDetail[2];
$data["Code"] = $arr_StationFileDetail[1];
$this->station_model->AddStation($data);
}
}
echo $NewStation;
}
/**
* @description: 从HT获取最新的站点信息
* @param {type}
* @return:
*/
function GetNewStationFromHT(){
//先获取当前使用的站点文件
$StationFileUrl = "https://biz.chinahighlights.com/china-trains/js/train/StationInfo.js";
$StationFileData = $this->get_data($StationFileUrl);
$arr_StationFile = explode("@", str_replace("\";", "", str_replace("var station_names =\"", "", $StationFileData)));
$NewStation = "";
//循环HT站点表对比
$StationList = $this->station_model->GetStationList();
foreach($StationList as $Item){
$isNew = true;
for ($i=0;$i<count($arr_StationFile);$i++){
$arr_StationFileDetail = explode("|", $arr_StationFile[$i]);
//对比数据库,如果是新的就保存
$TRS_StationCN = $Item->TRS_StationCN;
$TRS_Station = $Item->TRS_Station;
$TRS_Code = $Item->TRS_Code;
if ($TRS_StationCN==$arr_StationFileDetail[3] && $TRS_Code==$arr_StationFileDetail[1]){
$isNew = false;
break;
}
}
if ($isNew) {
$NewStation .= $arr_StationFile[$i]."@";
}
}
echo $NewStation;
}
function get_data($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证https证书
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
}
/* End of file updatestation.php */

@ -0,0 +1,74 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class station_model extends CI_Model {
function __construct() {
parent::__construct();
$this->HT = $this->load->database('HT', TRUE);
}
/**
* @description: 判断数据库里面是否有该站点的信息
* @param {type}$code 三字码,$name 车站名
* @return: bool
*/
function GetStationCount($code,$name){
$sql = " select top 1 * from TrainStation
where TRS_Code=? and TRS_StationCN='".$name."'";
$name = iconv ( "utf-8", "gb2312//IGNORE", $name );
$query = $this->HT->query($sql,array($code));
if ($query->result()){
return false;
}else{
return true;
}
}
/**
* @description: 获取HT里面的站点信息列表
* @param {type}
* @return:
*/
function GetStationList(){
$sql = "select TRS_StationCN,TRS_Station,TRS_Code FROM TrainStation where TRS_Use=1";
$query = $this->HT->query($sql);
return $query->result();
}
/**
* @description: 增加新站点
* @param {type}
* @return:
*/
function AddStation($data){
//TrainStation表
$sql = "
insert into TrainStation (TRS_StationCN,TRS_Station,LastEditTime,TRS_Code,TRS_Use,TRS_IsNew)
values(?,?,getdate(),?,1,1)
";
$param = array($data["StationCN"],$data["Station"],$data["Code"]);
$query = $this->HT->query($sql,$param);
$TRS_ID = $this->HT->insert_id();
//语种表TrainStation2,中英文都得添加
$sql2=" insert into TrainStation2 (TS2_Name,TS2_LGC,TS2_TRSID,LastEditTime)
values(?,1,?,GETDATE())";
$param = array($data["Station"],$TRS_ID);
$query = $this->HT->query($sql2,$param);
$sql2=" insert into TrainStation2 (TS2_Name,TS2_LGC,TS2_TRSID,LastEditTime)
values(?,2,?,GETDATE())";
$param = array($data["StationCN"],$TRS_ID);
$query = $this->HT->query($sql2,$param);
}
}
/* End of file station_model.php */

@ -0,0 +1,34 @@
<div class="col-sm-5 well">
</div>
<div class="col-sm-18">
<div class="panel panel-default">
<div class="panel-heading">更新国内火车站点信息</div>
<div class="panel-body">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table table-striped">
<tr>
<td width="120">&nbsp;</td>
<td width="300">
<div class="form_submit">
<button type="button" class="btn btn-success" onclick="UpdateStation()">开始更新</button>
</div>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td id="msg_1">请等待:当前进度:<span>0%</span></td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="3" id="msg_1a"></td>
</tr>
</table>
</div>
</div>
</div>
<script type="text/javascript">
function UpdateStation() {
}
</script>
Loading…
Cancel
Save