diff --git a/application/third_party/trainsystem/controllers/addorders.php b/application/third_party/trainsystem/controllers/addorders.php
index 0c056c79..9f9429c6 100644
--- a/application/third_party/trainsystem/controllers/addorders.php
+++ b/application/third_party/trainsystem/controllers/addorders.php
@@ -39,7 +39,7 @@ class addorders extends CI_Controller{
}
}
- //自动出票
+ //自动出票,2024-1-30改用新方法
public function auto_pay_ticket(){
//log_message('error','auto ticket');
date_default_timezone_set('Asia/Shanghai');
@@ -165,6 +165,109 @@ class addorders extends CI_Controller{
}
print_r('
');
}
+
+ //自动出票2.0 2024-1-30 zp
+ public function auto_pay_ticket_2(){
+ date_default_timezone_set('Asia/Shanghai');
+
+ //筛选出能自动出票的订单
+ $auto_pool = $this->BIZ_train_model->auto_check_ticket_2();
+
+ //创建一个不允许自动出票的国际火车票数组
+ $nation_train = array('K19', 'K23', 'Z8701', 'Z8702', 'Z97', 'Z98', 'Z99', 'Z100', 'K9795','D87');
+
+ //创建黑名单
+ $black_list = $this->config->item('black_list');
+ $string = '';
+ foreach($auto_pool as $item){
+ $this->isauto = 1;
+ $bpe_sn = '';
+ $back_message = '';
+ $cold_sn = $item->COLD_SN;
+ $coli_id = $item->coli_id;
+ $auto_flag = 1;
+
+ $people_arr = $this->BIZ_train_model->biz_people($cold_sn);
+ $train_info = $this->BIZ_train_model->biz_order_detail($cold_sn);
+
+ //乘客人数大于10人不出票
+ if(count($people_arr) > 10){
+ $auto_flag = 0;
+ $back_message .= '-乘客人数大于10不自动出票';
+ }
+
+ //护照号如果在黑名单的就不自动出票
+ foreach($people_arr as $people_info){
+ if(in_array($people_info->BPE_Passport,$black_list)){
+ $auto_flag = 0;
+ $back_message .= '-此用户为黑名单用户,不自动出票';
+ }
+
+ if(strlen($people_info->BPE_Passport) >= 18){
+ $auto_flag = 0;
+ $back_message .= '-护照位数大于18不自动出票';
+ }
+
+ $bpe_sn .= $people_info->BPE_SN.',';
+ }
+ $bpe_sn = substr($bpe_sn,0,strlen($bpe_sn)-1);
+
+ //不是已付款状态的,票价高于5000不出票,以防意外
+ if($item->COLI_State != '8'){
+ if($train_info->adultcost > 5000){
+ $auto_flag = 0;
+ $back_message .= '-没支付单价大于5000不自动出票';
+ }
+ }
+
+ //如果为国际火车票就不出票
+ if(in_array($train_info->FlightsNo, $nation_train) || strlen($train_info->DepartAirport)>3 || strlen($train_info->ArrivalAirport)>3){
+ $auto_flag = 0;
+ $back_message .= '-国际火车票不自动出票';
+ }
+
+ //无座的订单不做出票
+ if($train_info->Aircraft == 'WZ'){
+ $auto_flag = 0;
+ $back_message .= '-无座不自动出票';
+ }
+
+
+ $DepartureDate = strtotime(date('Y-m-d',strtotime($train_info->DepartureDate))); //只取日期部分
+ $now = strtotime(date('Y-m-d'));
+ $depart_diff = ($DepartureDate - $now) / 86400;
+
+ //如果刚好是第15天的订单
+ if($depart_diff==15){
+ //$this->isauto = 1;
+ $time = strtotime(time());
+ $autolasttime = $item->ts_autolasttime;
+ if(($timestamp = strtotime($autolasttime)) !== false) {
+ $time_diff = ($time - strtotime($autolasttime)) / 3600;
+ if ($time_diff < 1){
+ $auto_flag = 0;
+ $back_message .= '-预售期每小时只能提交一次';
+ }
+ }
+ }else{ //不是预售期的,只能3次抢票
+ if ($item->ts_autotimes > 3){
+ $auto_flag = 0;
+ $back_message .= '-抢票次数已到3次';
+ }
+ }
+
+ if($auto_flag == 0){
+ $string .= '汉特订单号:'.$coli_id.'('.$cold_sn.')'.$back_message.' |
';
+ }else{
+ //单个订单提交
+ echo $cold_sn.'
';
+ $this->booktickets($cold_sn,$bpe_sn,'','ctrip');
+ //$string .= '汉特订单号:'.$coli_id.'('.$cold_sn.')可以自动出票 |
';
+ }
+ }
+ print_r('');
+
+ }
//创建一个方法用于接收所有的出票请求
public function booktickets($cold_sn=null,$bpe_sn=null,$selectseat=null,$type=null){
@@ -724,9 +827,15 @@ class addorders extends CI_Controller{
$add_data->runtime = (strtotime($data['train']->ArrivalTime) - strtotime($data['train']->DepartureTime)) / 60;
$add_data->channel = 'ctrip';
$add_data->isauto = $this->isauto;
+ //出票次数
+ $countAuto = $this->train_system_model->get_autotimes($cold_sn);
+ $add_data->ts_autotimes = $countAuto->countauto + 1; //出票次数+1
//存储到数据库
- $this->train_system_model->add_orders($add_data);
+ $this->train_system_model->add_orders($add_data);
+
+ // print_r(json_encode($PostData));
+ // die();
$ResponseJson = GetPost_http($url,json_encode($PostData,JSON_UNESCAPED_UNICODE),'json');
$ResponseData = json_decode($ResponseJson);
@@ -756,6 +865,8 @@ class addorders extends CI_Controller{
}else{
+ //log_message('error','下单失败提交数据记录:'.json_encode($PostData,JSON_UNESCAPED_UNICODE));
+
$reback["mes"] = $ResponseJson;
$add_data->status = "e";
@@ -765,6 +876,7 @@ class addorders extends CI_Controller{
$msgData->OrderStatus = "1";
$msgData->ErrorMsg = $ResponseData->returnMessage;
$msgData->ordernumber = $OrderNumber;
+ $msgData->addOrderData = json_encode($PostData,JSON_UNESCAPED_UNICODE); //失败了记录提交的订单数据
$this->train_system_model->update_orders_msg($msgData);
}
diff --git a/application/third_party/trainsystem/models/BIZ_train_model.php b/application/third_party/trainsystem/models/BIZ_train_model.php
index e24d4da0..774ad64c 100644
--- a/application/third_party/trainsystem/models/BIZ_train_model.php
+++ b/application/third_party/trainsystem/models/BIZ_train_model.php
@@ -323,6 +323,33 @@ class BIZ_train_model extends CI_Model {
$query = $this->HT->query($sql);
return $query->result();
}
+
+
+ //获取能够自动出票的订单列表2.0版本 20240130 zp
+ function auto_check_ticket_2(){
+ $sql = "SELECT distinct top 2 COLD_SN ,coli_id,COLD_SPFS,COLI_State,(SELECT TOP 1 GAI_Type FROM BIZ_GroupAccountInfo WHERE GAI_COLI_SN=bcli.COLI_SN AND ISNULL(DeleteFlag,0)=0) as GAI_Type
+ ,cold_startdate
+ ,isnull((select top 1 ts_autotimes from InfoManager.dbo.trainsystem where ts_cold_sn= bcld.cold_sn order by ts_id desc),0) as ts_autotimes
+ ,(select top 1 ts_autolasttime from InfoManager.dbo.trainsystem where ts_cold_sn= bcld.cold_sn order by ts_id desc) as ts_autolasttime
+ FROM BIZ_ConfirmLineInfo bcli
+ inner join BIZ_ConfirmLineDetail bcld on COLD_COLI_SN=COLI_SN
+ INNER JOIN dbo.OperatorInfo ON OPI_SN=COLI_OPI_ID and OPI_DEI_SN=10 AND ISNULL(dbo.OperatorInfo.DeleteFlag,0)=0
+ WHERE bcli.COLI_ServiceType = '2'
+ AND bcli.COLI_State in ('13','63')
+ AND EXISTS(SELECT GAI_SN FROM BIZ_GroupAccountInfo WHERE GAI_COLI_SN=bcli.COLI_SN AND (bcli.COLI_Price - GAI_SQJE) <= 20 AND (GAI_SQJE - bcli.COLI_Price) >= -20 AND isnull(DeleteFlag,0) = 0)
+ AND isnull(bcli.DeleteFlag,0) = 0
+ AND isnull(bcld.DeleteFlag,0) = 0
+ AND COLD_SPFS < 2
+ AND ( NOT EXISTS (
+ SELECT TOP 1 1
+ FROM InfoManager.dbo.trainsystem
+ WHERE ts_cold_sn = COLD_SN
+ ) or EXISTS(select Top 1 1 from InfoManager.dbo.trainsystem WHERE ts_cold_sn = COLD_SN and ts_status = '5' and ts_cold_sn not in (select ts_cold_sn from InfoManager.dbo.trainsystem where (ts_status='4' or ts_status='3') and ts_cold_sn = COLD_SN) ))
+ and (COLD_StartDate between GETDATE() and CONVERT(varchar(100),GETDATE()+15,23)+' 23:59')
+ ";
+ $query = $this->HT->query($sql);
+ return $query->result();
+ }
public function get_saletime($station){
$sql = 'select TST_saletime from TrainSaleTime where TST_station_cn = ?';
diff --git a/application/third_party/trainsystem/models/train_system_model.php b/application/third_party/trainsystem/models/train_system_model.php
index f32b5631..c52654b8 100644
--- a/application/third_party/trainsystem/models/train_system_model.php
+++ b/application/third_party/trainsystem/models/train_system_model.php
@@ -95,7 +95,9 @@ class train_system_model extends CI_Model {
ts_runtime,
ts_checi,
ts_channel,
- ts_isauto
+ ts_isauto,
+ ts_autotimes,
+ ts_autolasttime
)
VALUES(
'{$data->cold_sn}',
@@ -114,7 +116,9 @@ class train_system_model extends CI_Model {
'{$data->runtime}',
'{$data->checi}',
'{$data->channel}',
- '{$data->isauto}'
+ '{$data->isauto}',
+ '{$data->ts_autotimes}',
+ getdate()
)
";
//echo $sql;
@@ -233,6 +237,11 @@ class train_system_model extends CI_Model {
$where .= "ts_reschedulecallback = '{$data->reschedulecallback}',";
}
+ if (!empty($data->addOrderData)) {
+ //失败了保存提交的订单数据
+ $where .= " ts_addOrderData = '{$data->addOrderData}',";
+ }
+
$sql ="
update trainsystem
set
@@ -246,6 +255,7 @@ class train_system_model extends CI_Model {
$query = $this->INFO->query($sql);
}
+
//更新乘客表信息
public function update_passpager_info($data){
@@ -327,4 +337,11 @@ class train_system_model extends CI_Model {
return false;
}
}
+
+ //获取出票次数,不管是自动还是手动。
+ public function get_autotimes($cold_sn){
+ $sql = "select COUNT(*) as countauto from InfoManager.dbo.trainsystem where ts_cold_sn = ? and ts_status=5";
+ $query = $this->INFO->query($sql, $cold_sn);
+ return $query->row();
+ }
}
\ No newline at end of file