功能完成

mobile-first
赵鹏 6 years ago
parent 73ea8f4d01
commit 3a74df4cd3

@ -30,6 +30,16 @@ class updatestation extends CI_Controller
$this->load->view('bootstrap3/footer');
}
public function test(){
$results="";
for($i=1; $i<=90000; $i++){
$results.='"'.$i.'"';
}
$len = strlen($results);
header("Content-Length: $len");
echo $results;
}
/**
* @description: 从12306抓取数据对比翰特数据库
* @param {type}
@ -43,18 +53,48 @@ class updatestation extends CI_Controller
$arr_Station = explode("@", str_replace("';", "", str_replace("var station_names ='", "", $StationData)));
//print_r($arr_Station);
$NewStation = "";
$UpdateStaion="";
for ($i = 0; $i < count($arr_Station); $i++) {
if ($arr_Station[$i] != null) {
$arr_StationDetail = explode("|", $arr_Station[$i]);
$TRS_Code = $arr_StationDetail[2];
$TRS_StationCN = $arr_StationDetail[1];
$TRS_Station = $arr_StationDetail[3];
// print_r($arr_StationDetail);
//对比数据库,如果是新的就保存
$isNew = $this->station_model->GetStationCount($arr_StationDetail[2], $arr_StationDetail[1]);
if ($isNew) {
$NewStation .= $arr_Station[$i]."@";
$isNew = $this->station_model->CompareStation($TRS_Code, $TRS_StationCN);
if ($isNew == 1) {
//更新
$strStation = "@-1|" . $TRS_Code . "|" . $TRS_Station . "|" . $TRS_StationCN . "|2|";
$UpdateStaion .= $strStation;
//表操作
// $this->station_model->UpdateStation($TRS_Code, $TRS_StationCN);
} else if ($isNew == 2) {
//新增
$strStation = "@9999|" . $TRS_Code . "|" . $TRS_Station . "|" . $TRS_StationCN . "|2|";
$NewStation .= $strStation;
//表增加操作
$data["StationCN"] = $TRS_StationCN;
$data["Station"] = $TRS_Station;
$data["Code"] = $TRS_Code;
//$this->station_model->AddStation($data);
}
}
}
echo $NewStation;
$NewStationList = $UpdateStaion.$NewStation;
//发送邮件
$this->station_model->SendMail(
"UpdateStationSystem",
"noreplay@email.com",
'zhaopeng',
'zhaopeng@hainatravel.com',
'New Station(by12306):' . date("Y-m-d"),
$NewStationList
);
$len = strlen($NewStationList);//count( explode("@",$NewStationList))-1;
header("Content-Length: $len");
echo $NewStationList;
}
/**
@ -76,50 +116,60 @@ class updatestation extends CI_Controller
for ($i = 0; $i < count($arr_Station); $i++) {
$isNew = true;
$arr_StationDetail = explode("|", $arr_Station[$i]);
for ($j = 0; $j < count($arr_StationFile); $j++) {
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;
break;
}
}
}
if ($isNew) {
$NewStation .= $arr_Station[$i]."@";
$NewStation .= $arr_Station[$i] . "@";
}
}
echo $NewStation;
}
/**
* @description: 目前站点文件与翰特数据对比
* @description: 目前站点文件与翰特数据对比,导入HT没有的数据
* @param {type}
* @return:
*/
function CheckFileAndHT(){
public 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++){
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);
}
//对比数据库,如果是新的就保存
$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;
//发送邮件
$this->station_model->SendMail(
"UpdateStationSystem",
"noreplay@email.com",
'zhaopeng',
'zhaopeng@hainatravel.com',
'站点文件导入HT:' . date("Y-m-d"),
$NewStation
);
}
@ -128,7 +178,8 @@ class updatestation extends CI_Controller
* @param {type}
* @return:
*/
function GetNewStationFromHT(){
public function GetNewStationFromHT()
{
//先获取当前使用的站点文件
$StationFileUrl = "https://biz.chinahighlights.com/china-trains/js/train/StationInfo.js";
$StationFileData = $this->get_data($StationFileUrl);
@ -137,24 +188,36 @@ class updatestation extends CI_Controller
//循环HT站点表对比
$StationList = $this->station_model->GetStationList();
foreach($StationList as $Item){
foreach ($StationList as $Item) {
$isNew = true;
for ($i=0;$i<count($arr_StationFile);$i++){
$TRS_ID = $Item->TRS_ID;
$TRS_StationCN = $Item->TRS_StationCN;
$TRS_Station = $Item->TRS_Station;
$TRS_Code = $Item->TRS_Code;
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]){
//对比数据库,如果是新的就保存
if ($TRS_StationCN == $arr_StationFileDetail[3] && $TRS_Code == $arr_StationFileDetail[1]) {
$isNew = false;
break;
}
}
}
if ($isNew) {
$NewStation .= $arr_StationFile[$i]."@";
$strStation = "@" . $TRS_ID . "|" . $TRS_Code . "|" . $TRS_Station . "|" . $TRS_StationCN . "|2|";
$NewStation .= $strStation;
}
}
echo $NewStation;
// echo $NewStation;
//发送邮件
$this->station_model->SendMail(
"UpdateStationSystem",
"noreplay@email.com",
'zhaopeng',
'zhaopeng@hainatravel.com',
'New Station:' . date("Y-m-d"),
$NewStation
);
}

@ -1,41 +1,77 @@
<?php
/*
* @Author: your name
* @Date: 2020-01-15 11:28:41
* @LastEditTime : 2020-01-17 11:00:42
* @LastEditors : Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \information-system\application\third_party\updatetrain\models\station_model.php
*/
defined('BASEPATH') OR exit('No direct script access allowed');
defined('BASEPATH') or exit('No direct script access allowed');
class station_model extends CI_Model {
class station_model extends CI_Model
{
function __construct() {
function __construct()
{
parent::__construct();
$this->HT = $this->load->database('HT', TRUE);
}
/**
* @description: 判断数据库里面是否有该站点的信息
* @param {type}$code 三字码,$name 车站名
* @return: bool
*/
function GetStationCount($code,$name){
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()){
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{
} else {
return true;
}
}
/**
* @description: 通过比较中文名三字码判断HT的站点信息是否存在或变动
* @param {type}
* @return: 0表示站点已存在 1表示站点存在但是更新2表示站点未存在
*/
function CompareStation($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 0;
} else {
$sql2 = " select top 1 * from TrainStation where TRS_StationCN='" . $name . "'";
$query2 = $this->HT->query($sql2);
if ($query2->result()) {
return 1;
} else {
return 2;
}
}
}
/**
* @description: 获取HT里面的站点信息列表
* @param {type}
* @return:
*/
function GetStationList(){
$sql = "select TRS_StationCN,TRS_Station,TRS_Code FROM TrainStation where TRS_Use=1";
function GetStationList()
{
$sql = "select TRS_ID,TRS_StationCN,TRS_Station,TRS_Code FROM TrainStation where TRS_Use=1";
$query = $this->HT->query($sql);
return $query->result();
}
@ -46,28 +82,60 @@ class station_model extends CI_Model {
* @param {type}
* @return:
*/
function AddStation($data){
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);
$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)
$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)
$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);
$param = array($data["StationCN"], $TRS_ID);
$query = $this->HT->query($sql2, $param);
}
/**
* @description: 更新已存在的站点名称的三字码
* @param {type}
* @return:
*/
function UpdateStation($code, $name)
{
$name = iconv("utf-8", "gb2312//IGNORE", $name);
$sql = "update TrainStation set TRS_Code=? where TRS_StationCN='".$name."'";
$param = array($code);
$query = $this->HT->query($sql, $param);
}
function SendMail($fromName, $fromEmail, $toName, $toEmail, $subject, $body)
{
$toName = str_replace("'", "''", $toName);
$body = str_replace("'", "''", $body);
$sql = "INSERT INTO Email_AutomaticSend
(
M_ReplyToName, M_ReplyToEmail, M_ToName, M_ToEmail, M_Title, M_Body, M_Web,
M_FromName, M_State
)
VALUES
(
?, ?, N'{$toName}', ?, N'{$subject}', N'{$body}', ?, ?, 0
) ";
$query = $this->HT->query($sql, array($fromName, $fromEmail, $toEmail, 'cht', 'information'));
echo $query;
//return $query;
}
}

@ -1,5 +1,4 @@
<div class="col-sm-5 well">
</div>
<div class="col-sm-18">
<div class="panel panel-default">
@ -9,8 +8,13 @@
<tr>
<td width="120">&nbsp;</td>
<td width="300">
<div class="progress">
<div id="pros" class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
</div>
</div>
<div class="form_submit">
<button type="button" class="btn btn-success" onclick="UpdateStation()">开始更新</button>
<button type="button" class="btn btn-success" id="trigger_ajax">开始更新(12306)</button>
</div>
</td>
<td>&nbsp;</td>
@ -28,7 +32,18 @@
</div>
</div>
<script type="text/javascript">
function UpdateStation() {
var trigger = document.getElementById("trigger_ajax");
trigger.onclick = function(){
var xhr = new XMLHttpRequest();
xhr.onprogress = function(event){
if(event.lengthComputable){
var loaded = parseInt(event.loaded/event.total*100)+"%";
$('#pros').width(loaded);
$('#pros').text(loaded);
}
}
xhr.open("post", "/info.php/thirdparty/updatetrain/updatestation/test/", true);
xhr.send(null);
}
</script>
Loading…
Cancel
Save