From 52c765e874581227bb10c3a1e747cdf3f40a1e71 Mon Sep 17 00:00:00 2001 From: cyc Date: Thu, 8 Jun 2017 13:12:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=87=BA=E7=A5=A8=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../third_party/train/controllers/auto.php | 163 +++++++++--------- .../train/models/BIZ_train_model.php | 24 ++- .../train/models/sendmail_model.php | 80 +++++++++ 3 files changed, 185 insertions(+), 82 deletions(-) create mode 100644 application/third_party/train/models/sendmail_model.php diff --git a/application/third_party/train/controllers/auto.php b/application/third_party/train/controllers/auto.php index 8baf7700..0a11ea14 100644 --- a/application/third_party/train/controllers/auto.php +++ b/application/third_party/train/controllers/auto.php @@ -37,84 +37,85 @@ class Auto extends CI_Controller{ $this->load->model("BIZ_train_model");//加载模型 } - - public function auto_check_ticket(){ - $ticket_info = $this->BIZ_train_model->auto_check_ticket(); - print_r($ticket_info); - foreach($ticket_info as $value){ - if(strlen($value->GUT_Passport) < 18){ - $this->auto_pay_ticket($value->COLI_SN); - } - } - } - //用于自动出票,接收COLI_SN - public function auto_pay_ticket($coli_sn=false){ + //用于自动出票 + public function auto_pay_ticket(){ date_default_timezone_set('Asia/Shanghai'); - // $coli_sn="473013018"; - //$coli_sn = $this->input->post("coli_sn"); - $list=new StdClass; - $back_data = 1; - - if(!empty($coli_sn)){ - $cold_sn=$this->BIZ_train_model->get_cold_sn($coli_sn); - $coli_id = $this->BIZ_train_model->coli_sn_get_coli_id($coli_sn); - $i = 0; - $list->info=array(); - foreach ($cold_sn as $v) { - //print_r(empty($this->BIZ_train_model->auto_check_pullticket($v->COLD_SN))); - //是否已经出过票 - if(empty($this->BIZ_train_model->auto_check_pullticket($v->COLD_SN))){ - $back_data = 1; - break; + $list=new StdClass; + $ticket_info = $this->BIZ_train_model->auto_check_ticket(); + //print_r($ticket_info); + foreach($ticket_info as $item){ + $back_data = 1; + $coli_sn = $item->COLI_SN; + if(!empty($coli_sn)){ + $cold_sn = $this->BIZ_train_model->get_cold_sn($coli_sn); + $coli_id = $this->BIZ_train_model->coli_sn_get_coli_id($coli_sn); + $i = 0; + $list->info=array(); + foreach ($cold_sn as $v) { + //是否已经出过票(通过查询聚合数据判断此订单是否已经请求过聚合) + if(empty($this->BIZ_train_model->get_biz_jol($v->COLD_SN))){ + //邮寄的不自动出票 + if($v->COLD_SPFS > 1){ + //寄送票 + $back_data = 0; + break; + } + $list->info[$i]=new StdClass; + $list->info[$i]->people=$this->BIZ_train_model->biz_people($v->COLD_SN); + $list->info[$i]->train=$this->BIZ_train_model->get_biz_foi($v->COLD_SN); + //print_r($list->info[$i]->people); + //print_r($list->info[$i]->train); + + //护照位数大于18位则不自动出票 + if(strlen($list->info[$i]->people[$i]->BPE_Passport) >= 18){ + $back_data = 0; + break; + } + + //乘客人数大于5人不出票 + if(count($list->info[$i]->people) > 5){ + $back_data = 0; + break; + }; + + //3小时以内或者大于29天的不出票 + if((strtotime($list->info[$i]->train[0]->DepartureTime) - time())/3600 < 3 or (strtotime($list->info[$i]->train[0]->DepartureTime) - time())/24/3600 >29){ + $back_data = 0; + break; + } + + //金额不能大于1000人民币 + if($list->info[$i]->train[0]->adultcost > 1000){ + $back_data = 0; + break; + } + $i++; + } } - if($v->COLD_SPFS > 1){ - //寄送票 - $back_data = 0; - break; - } - $list->info[$i]=new StdClass; - $list->info[$i]->people=$this->BIZ_train_model->biz_people($v->COLD_SN); - $list->info[$i]->train=$this->BIZ_train_model->get_biz_foi($v->COLD_SN); - $list->info[$i]->status=$this->BIZ_train_model->get_biz_jol($v->COLD_SN); -//乘客人数大于5人不出票 - if(count($list->info[$i]->people) > 5){ - $back_data = 0; - break; - }; - //3小时以内或者大于29天的不出票 - if((strtotime($list->info[$i]->train[0]->DepartureTime) - time())/3600 < 3 or (strtotime($list->info[$i]->train[0]->DepartureTime) - time())/24/3600 >29){ - $back_data = 0; - break; - } - //金额不能大于1000人民币 - if($list->info[$i]->train[0]->adultcost > 1000){ - $back_data = 0; - break; - } - $i++; - } - if($back_data == 0){ - echo 0; - return false; - }else{ - foreach ($cold_sn as $v) { - $reback = $this->submit_juhe_order($v->COLD_SN,$coli_id[0]->COLI_ID); - if($reback["status"] && !empty($reback["order"])){ - $back_data .= ",".$reback["order"]; - } - } - } - $back_data = substr($back_data, 2); - if($back_data){ //这里 $back_data 还有可能没数据,所以判断一下 - echo $back_data; - }else{ - echo 0; - } - return false; - } - + + if($back_data == 0){ + echo 0; + return false; + }else{ + foreach ($cold_sn as $v) { + $reback = $this->submit_juhe_order($v->COLD_SN,$coli_id[0]->COLI_ID); + if($reback["status"] && !empty($reback["order"])){ + $back_data .= ",".$reback["order"]; + } + } + } + $back_data = substr($back_data, 2); + if($back_data){ //这里 $back_data 还有可能没数据,所以判断一下 + echo $back_data; + }else{ + echo 0; + } + return false; + } + } } + //根据汉特订单明细表SN来获取车次,乘客信息,拼接成聚合提交订单的url public function submit_juhe_order($cold_sn,$coli_id) { // $cold_sn=$this->input->get("order"); @@ -146,6 +147,7 @@ class Auto extends CI_Controller{ echo json_encode($reback); return false; } + //前面做过判断,为什么还要再判断一次 if (count($data['people_list']) > 5) { //显示错误,用户超过五个 $reback["mes"]="乘客不能超过五个"; @@ -201,7 +203,7 @@ class Auto extends CI_Controller{ print_r($url); print_r($post_data); die(); - // $bakc_json=$this->post_data($url,$post_data); + //$bakc_json=$this->post_data($url,$post_data); $bakc=json_decode($bakc_json);//json=>obj $add_data=new StdClass(); @@ -221,17 +223,21 @@ class Auto extends CI_Controller{ $reback["status"]=1; $reback["order"]=$bakc->result->orderid; $reback["mes"]="订单提交成功,等待回调"; - $this->send_mail_to_wl("订单:{$coli_id} 提交成功","翰特订单号:{$coli_id} ;聚合订单号:{$bakc->result->orderid}"); + $this->send_mail_to_wl("订单:{$coli_id} 提交成功","翰特订单号:{$coli_id} ;聚合订单号:{$bakc->result->orderid}"); + //聚合返回成功信息后,将处理过的订单标记为付款已出票(61) + $this->BIZ_train_model->update_ticket_state($coli_id); }else{ $add_data->JOL_JuheOrder=null; $reback["mes"]= $bakc_json; $add_data->JOL_Status="e"; $this->send_mail_to_wl("订单:{$coli_id} 提交失败","翰特订单号:{$coli_id}"); } + //聚合返回数据之后记录到聚合订单表 $add_back_data=$this->BIZ_train_model->add_biz_jol($add_data); return $reback; } + public function ticket_status($coli_sn="",$jh_id=""){ if(empty($coli_sn)){ $coli_sn = $this->input->get("sn"); @@ -266,6 +272,7 @@ class Auto extends CI_Controller{ $list->cols_id = $cols_id[0]->COLI_ID; $this->load->view("ticket_status",$list); } + //发邮件给外联 public function send_mail_to_wl($subject,$body){ $this->load->model("Sendmail_model"); @@ -273,7 +280,7 @@ class Auto extends CI_Controller{ $fromEmail = "csk@hainatravel.com"; $toName = "ethel"; $toEmail = "ethel@chinahighlights.com"; - $this->Sendmail_model->SendGuest($fromName,$fromEmail,$toName,$toEmail,$subject,$body); + $this->Sendmail_model->SendMailToTable($fromName,$fromEmail,$toName,$toEmail,$subject,$body); } //发邮件给客人 public function send_mail_to_guest($coli_id,$jh_order){ @@ -285,7 +292,7 @@ class Auto extends CI_Controller{ $toEmail = $guest[0]->GUT_Email; $subject = "auto pay test $jh_order"; $body = "csk test train ticket $jh_order"; - $this->Sendmail_model->SendGuest($fromName,$fromEmail,$toName,$toEmail,$subject,$body); + $this->Sendmail_model->SendMailToTable($fromName,$fromEmail,$toName,$toEmail,$subject,$body); } // public function sub_callback(){ diff --git a/application/third_party/train/models/BIZ_train_model.php b/application/third_party/train/models/BIZ_train_model.php index 0c8bf4f3..d63a33f2 100644 --- a/application/third_party/train/models/BIZ_train_model.php +++ b/application/third_party/train/models/BIZ_train_model.php @@ -7,16 +7,32 @@ class BIZ_train_model extends CI_Model { $this->HT = $this->load->database('HT', TRUE); } + //自动获取符合自动出票要求的订单的coli_sn function auto_check_ticket($topnum=5){ - $sql = "select top $topnum * from BIZ_ConfirmLineInfo bcli left join BIZ_Guest bg on bcli.COLI_GUT_SN = bg.GUT_SN where COLI_ServiceType = '2' and COLI_State ='62' AND bcli.COLI_WebCode='CHT' ORDER BY bcli.COLI_SN DESC"; + $sql = "SELECT + top $topnum COLI_SN + FROM + BIZ_ConfirmLineInfo + WHERE + COLI_ServiceType = '2' + AND COLI_State ='62' + AND COLI_WebCode='CHT' + ORDER BY + COLI_SN DESC"; $query = $this->HT->query($sql); return $query->result(); } - function auto_check_pullticket($coli_sn){ - $sql = "SELECT * FROM BIZ_JuheOrderList where JOL_COLD_SN = '$coli_sn'"; + //自动出票成功后更新订单的状态 + function update_ticket_state($coli_id){ + $sql = "UPDATE + BIZ_ConfirmLineInfo + SET + COLI_State = '61' + WHERE + COLI_ID = '$coli_id'"; $query = $this->HT->query($sql); - return $query->row(); + return $query; } function biz_order_detail($cold_sn) { diff --git a/application/third_party/train/models/sendmail_model.php b/application/third_party/train/models/sendmail_model.php new file mode 100644 index 00000000..824f98ee --- /dev/null +++ b/application/third_party/train/models/sendmail_model.php @@ -0,0 +1,80 @@ +HT = $this->load->database('HT', TRUE); + } + + function SendMailToTable($fromName,$fromEmail,$toName,$toEmail,$subject,$body) + { + if($this->validEmail($toEmail)) + { + $data = array( + "M_ReplyToName" => $fromName, //回复人 + "M_ReplyToEmail" => $fromEmail, //回复地址 + "M_ToName" => $toName, //收件人名 + "M_ToEmail" => $toEmail, //收件邮件地址 + "M_Title" => $subject, //主题 + "M_Body" => $body, //邮件正文 + "M_Web" => "CHT", //所属站点 + "M_FromName" => "Chinahighlights.com", //站点名称 + "M_State" => 0, + ); + $this->HT->insert('Email_AutomaticSend',$data); + return TRUE; + }else{ + return FALSE; + } + } + + + public function validEmail($email){ + $isValid = true; + $atIndex = strrpos($email, "@"); + if (is_bool($atIndex) && !$atIndex){ + $isValid = false; + }else{ + $domain = substr($email, $atIndex+1); + $local = substr($email, 0, $atIndex); + $localLen = strlen($local); + $domainLen = strlen($domain); + if ($localLen < 1 || $localLen > 64){ + // local part length exceeded + $isValid = false; + }else if ($domainLen < 1 || $domainLen > 255){ + // domain part length exceeded + $isValid = false; + }else if ($local[0] == '.' || $local[$localLen-1] == '.'){ + // local part starts or ends with '.' + $isValid = false; + }else if (preg_match('/\\.\\./', $local)){ + // local part has two consecutive dots + $isValid = false; + }else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)){ + // character not valid in domain part + $isValid = false; + }else if (preg_match('/\\.\\./', $domain)){ + // domain part has two consecutive dots + $isValid = false; + }else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',str_replace("\\\\","",$local))){ + // character not valid in local part unless + // local part is quoted + if (!preg_match('/^"(\\\\"|[^"])+"$/',str_replace("\\\\","",$local))){ + $isValid = false; + } + } + /* + 不检查是否有DNS解析 + if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))){ + // domain not found in DNS + $isValid = false; + } + */ + } + return $isValid; + } + +} \ No newline at end of file