补充日志:
增加获取历史数据[列表已获取完毕]; 增加同步历史数据的订单详情; 修改同步时间的规则, 每次仅同步一条; 补充缺少的产品编号; 完善tracking链接数据; 财务表计算:增加非常规拼团的计算;解决一个产品拼多个团问题;增加已下架产品计算; 增加短信通知;短信发送记录查询;feature/trippest
parent
f0cade4838
commit
439de39731
@ -0,0 +1,174 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Send_operation extends CI_Controller {
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
mb_regex_encoding("UTF-8");
|
||||
bcscale(4);
|
||||
$this->load->helper('array');
|
||||
$this->load->model('Send_operation_model', 'send_model');
|
||||
$this->send_url = 'https://www.mycht.cn/webht.php/apps/messagecenter/index/send_message/';
|
||||
header('Access-Control-Allow-Origin:*');
|
||||
header('Access-Control-Allow-Methods:POST, GET');
|
||||
header('Access-Control-Max-Age:0');
|
||||
header('Access-Control-Allow-Headers:x-requested-with, Content-Type');
|
||||
header('Access-Control-Allow-Credentials:true');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->sms_log();
|
||||
return;
|
||||
}
|
||||
|
||||
public function sms_log()
|
||||
{
|
||||
$date = $this->input->get_post("date");
|
||||
$date = $date ? $date : date('Y-m-d', strtotime("+1 day"));
|
||||
$ready_order["date"] = $date;
|
||||
$COLI_ID = $this->input->get_post("order_id");
|
||||
$ready_order["order_id"] = $COLI_ID;
|
||||
$ready_order["list"] = $this->send_model->daytour_order_ready_for_send(trim($COLI_ID), $date, "no_send_state");
|
||||
$this->load->view('sms_log', $ready_order);
|
||||
return;
|
||||
}
|
||||
|
||||
public function order_sms_list($COLI_SN)
|
||||
{
|
||||
$data['list'] = $this->send_model->order_sms_list($COLI_SN);
|
||||
$list_table = $this->load->view('order_sms_list', $data, true);
|
||||
$this->output->set_content_type('application/json')->set_output(json_encode($list_table));
|
||||
return;
|
||||
}
|
||||
|
||||
/*!
|
||||
* 通过短信发送导游信息给预定了Day Tour的客人
|
||||
* * 每天9:00, 16:00 尝试发送
|
||||
* * 第二次发送之后仍然发送失败或没有调度信息, 反馈到Alex邮箱
|
||||
* * 这里只是Day Tour 订单, 不含单接送, 因此每个订单仅发送一次
|
||||
* @date 2018-09-25
|
||||
*/
|
||||
public function daytour($COLI_ID="")
|
||||
{
|
||||
$now_h = date("H");
|
||||
$time_flag = "";
|
||||
if ($now_h < 9 || $now_h > 19) {
|
||||
echo "Break time.";
|
||||
return false;
|
||||
} else if ($now_h >= 9 && $now_h < 16) {
|
||||
$time_flag = "try1";
|
||||
} else {
|
||||
$time_flag = "try2";
|
||||
}
|
||||
$date = date('Y-m-d', strtotime("+1 day"));
|
||||
if (trim($COLI_ID) !== "") {
|
||||
$date = null;
|
||||
$time_flag = "handle";
|
||||
}
|
||||
$ready_order = $this->send_model->daytour_order_ready_for_send(trim($COLI_ID), $date, $time_flag);
|
||||
if (empty($ready_order)) {
|
||||
echo "Empty. ";
|
||||
return false;
|
||||
}
|
||||
$order = $ready_order[0];
|
||||
if (strtotime($order->GCI_travelDate) < strtotime(date('Y-m-d')) ) {
|
||||
echo "已过期";
|
||||
return;
|
||||
}
|
||||
$send_body = array(
|
||||
"one" => trim($order->GUT_FirstName . " " . $order->GUT_LastName)
|
||||
,"two" => substr($order->GCI_travelDate, 0, 10)
|
||||
,"three" => $order->GCOD_dutyName
|
||||
,"four" => "+86 " . $order->GCOD_dutyTel
|
||||
,"phone" => real_phone_number($order->GUT_TEL, $order->GUT_POST)
|
||||
,"nation_code" => $order->GUT_POST
|
||||
);
|
||||
$cb_db = array(
|
||||
"TPSL_COLI_SN" => $order->COLI_SN
|
||||
,"TPSL_nationCode" => $send_body['nation_code']
|
||||
,"TPSL_mobile" => $send_body['phone']
|
||||
,"TPSL_msgType" => 'guide'
|
||||
,"TPSL_sendState" => 0
|
||||
);
|
||||
$ht_id = $this->send_model->insert_trippest_sms_log($cb_db);
|
||||
$error_msg = "";
|
||||
$send_time = date("Y-m-d H:i:s");
|
||||
if ($order->GCOD_dutyName !== null) {
|
||||
$send_cb = $this->excute_curl($this->send_url, $send_body);
|
||||
$send_cb_obj = json_decode($send_cb);
|
||||
$update_cb_db["TPSL_sendTime"] = $send_time;
|
||||
$update_cb_db["TPSL_sendContent"] = json_encode($send_body);
|
||||
$update_cb_db['TPSL_sendState'] = $send_cb_obj->result===0 ? 1 : 0;
|
||||
$update_cb_db['TPSL_callbackJson'] = $send_cb;
|
||||
$update_cb_db['TPSL_callbackTime'] = date("Y-m-d H:i:s");
|
||||
$update_where = " TPSL_SN=" . $ht_id;
|
||||
$ht_id = $this->send_model->update_trippest_sms_log($update_where, $update_cb_db);
|
||||
$send_cb_obj->errmsg!=="OK" ? $error_msg=$send_cb_obj->errmsg : null;
|
||||
}
|
||||
if ($time_flag === "try1") {
|
||||
return;
|
||||
}
|
||||
if ($order->GCOD_dutyName === null || $error_msg !== "") {
|
||||
// 没有调度或发送失败
|
||||
// to Alex
|
||||
$operator_mailbody = "<p> Dear Alex: </p>" .
|
||||
"<p>导游信息发送客人失败:<br /></p>" .
|
||||
"<p>订单号:" . $order->COLI_ID ."</p>" .
|
||||
"<p>发团时间:" . substr($order->GCI_travelDate, 0, 10) ."</p>" .
|
||||
"<p>导游信息:" . $order->GCOD_dutyName . "(" . $order->GCOD_dutyTel . ")" ."</p>" .
|
||||
"<p>导游更新时间:" . $order->GCI_createTime . " " . $order->GCOD_creatTime ."</p>" .
|
||||
"<p>发送时间:" . $send_time ."</p>";
|
||||
if ($error_msg !== "") {
|
||||
$operator_mailbody .= "<p>发送失败信息:" . $error_msg . "</p>";
|
||||
}
|
||||
$operator_mailbody .= "<p><a href='https://www.trippest.com/track-your-trip/'>Tracking Link</a>.</p>";
|
||||
$operator_mailbody .= "<p> 此邮件由系统自动发送, 请勿回复.</p>";
|
||||
$this->send_model->SendMail(
|
||||
"chinahighlights",
|
||||
"webform@chinahighlights.net",
|
||||
"YSL",
|
||||
"alex@chinahighlights.net", // ysl email alex@chinahighlights.net
|
||||
'#SMS send fail# ' . $order->COLI_ID,
|
||||
$operator_mailbody);
|
||||
}
|
||||
echo "已发送";
|
||||
return;
|
||||
}
|
||||
|
||||
protected function excute_curl($url, $postBody) {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_FAILONERROR, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
"Accept: application/json"
|
||||
));
|
||||
|
||||
if (empty($postBody)) {
|
||||
return false;
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postBody);
|
||||
|
||||
$reponse = curl_exec($ch);
|
||||
// $eval_resp = json_decode($reponse);
|
||||
|
||||
if (curl_errno($ch)) {
|
||||
log_message('error', "curl error : ".curl_error($ch) . "; curl postBodyString: ".json_encode($postBody));
|
||||
} else {
|
||||
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if (200 !== $httpStatusCode) {
|
||||
log_message('error', "curl response Status Code: ".$httpStatusCode."; curl postBodyString: ".json_encode($postBody));
|
||||
}
|
||||
}
|
||||
curl_close($ch);
|
||||
return $reponse;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* End of file send_operation.php */
|
||||
/* Location: ./webht/third_party/trippestOrderSync/controllers/send_operation.php */
|
||||
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Send_operation_model extends CI_Model {
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->HT = $this->load->database('HT', TRUE);
|
||||
$this->info = $this->load->database('INFO', TRUE);
|
||||
}
|
||||
|
||||
public function daytour_order_ready_for_send($COLI_ID="", $date, $time_flag="no_send_state")
|
||||
{
|
||||
$today = date('Y-m-d 16:00:00');
|
||||
switch ($time_flag) {
|
||||
case 'try1':
|
||||
$send_state = " ";
|
||||
break;
|
||||
case 'try2':
|
||||
$send_state = " and (TPSL_sendState=1 OR TPSL_logTime > '$today') ";
|
||||
break;
|
||||
case 'handle':
|
||||
$send_state = " and (TPSL_sendState=1) ";
|
||||
break;
|
||||
|
||||
case '':
|
||||
default:
|
||||
$send_state = "";
|
||||
break;
|
||||
}
|
||||
$send_state_sql = " and not exists (
|
||||
select TPSL_SN from InfoManager.dbo.trippest_sms_log
|
||||
where TPSL_COLI_SN=coli.COLI_SN
|
||||
$send_state
|
||||
) ";
|
||||
$top = " TOP 1 ";
|
||||
$sms_state = "";
|
||||
if ($time_flag == "no_send_state") {
|
||||
$send_state_sql = "";
|
||||
$top = "";
|
||||
$sms_state = " ,(select top 1 TPSL_sendState from InfoManager.dbo.trippest_sms_log
|
||||
where TPSL_COLI_SN=coli.COLI_SN and TPSL_sendContent like '%'+GCOD_startDate+'%'
|
||||
order by TPSL_sendState desc
|
||||
) as send_state";
|
||||
}
|
||||
$search_sql = " AND GCI_travelDate ='$date' ";
|
||||
if ($COLI_ID !== "") {
|
||||
$search_sql = " AND COLI_ID='" . $COLI_ID . "'";
|
||||
}
|
||||
$sql = "SELECT $top GroupCombineOperationDetail.GCOD_SN,COLI_SN,COLI_ID,COLI_groupCode
|
||||
,GUT_POST,GUT_TEL
|
||||
,PAG_ExtendType,PAG_Code
|
||||
,g.GUT_FirstName,g.GUT_LastName
|
||||
,gci.*
|
||||
,GCOD_startDate,GCOD_operationType,GCOD_dutyName,GCOD_dutyTel,GCOD_creatTime
|
||||
$sms_state
|
||||
FROM BIZ_ConfirmLineInfo coli
|
||||
INNER JOIN BIZ_ConfirmLineDetail cold ON COLD_COLI_SN=COLI_SN
|
||||
INNER JOIN BIZ_GUEST g ON g.GUT_SN=COLI_GUT_SN
|
||||
and GUT_TEL is not null and GUT_TEL<>'' and GUT_POST<>''
|
||||
INNER JOIN BIZ_PackageInfo pag ON pag.PAG_SN=COLD_ServiceSN
|
||||
LEFT JOIN GroupCombineInfo gci ON COLI_GRI_SN=GCI_GRI_SN
|
||||
LEFT JOIN GroupCombineOperationDetail ON GCOD_GCI_combineNo=GCI_combineNo
|
||||
AND GCOD_operationType='guiderOperations'
|
||||
WHERE 1=1
|
||||
$search_sql
|
||||
AND GCI_combineNo not IN ('cancel','forbidden')
|
||||
AND '39009'<>PAG_ExtendType
|
||||
$send_state_sql
|
||||
ORDER BY GCI_travelDate, COLI_SN
|
||||
";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function insert_trippest_sms_log($column)
|
||||
{
|
||||
$this->info->insert("trippest_sms_log", $column);
|
||||
return $this->info->insert_id();
|
||||
}
|
||||
|
||||
public function update_trippest_sms_log($where, $column)
|
||||
{
|
||||
if ($where == "" || empty($column)) {
|
||||
return false;
|
||||
}
|
||||
$update_str = $this->info->update_string('trippest_sms_log', $column, $where);
|
||||
$update_exc = $this->info->query($update_str);
|
||||
return $update_exc;
|
||||
}
|
||||
|
||||
/** 暂时不用了 */
|
||||
public function if_order_sent($COLI_SN, $msgType='guide')
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM [infomanager].[dbo].[trippest_sms_log]
|
||||
where [TPSL_COLI_SN]=$COLI_SN
|
||||
and [TPSL_sendState]=1
|
||||
and TPSL_msgType='$msgType'
|
||||
";
|
||||
return $this->info->query($sql)->row();
|
||||
}
|
||||
|
||||
/*
|
||||
* 发送邮件
|
||||
*/
|
||||
function SendMail($fromName, $fromEmail, $toName, $toEmail, $subject, $body) {
|
||||
$sql = "INSERT INTO tourmanager.dbo.Email_AutomaticSend \n"
|
||||
. " ( \n"
|
||||
. " M_ReplyToName, M_ReplyToEmail, M_ToName, M_ToEmail, M_Title, M_Body, M_Web, \n"
|
||||
. " M_FromName, M_State \n"
|
||||
. " ) \n"
|
||||
. "VALUES \n"
|
||||
. " ( \n"
|
||||
. " ?, ?, ?, ?, ?, N?, ?, ?, 0 \n"
|
||||
. " ) ";
|
||||
$query = $this->info->query($sql,
|
||||
array(substr($fromName, 0, 127), $fromEmail, substr($toName, 0, 127), $toEmail, $subject, $body, 'trippest SMS send fail', 'chinahighlighgts')
|
||||
);
|
||||
return $query;
|
||||
}
|
||||
|
||||
function order_sms_list($COLI_SN=0)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM [infomanager].[dbo].[trippest_sms_log]
|
||||
where [TPSL_COLI_SN]=$COLI_SN
|
||||
order by TPSL_logTime ";
|
||||
return $this->HT->query($sql)->result();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* End of file send_operation_model.php */
|
||||
/* Location: ./webht/third_party/trippestOrderSync/models/send_operation_model.php */
|
||||
@ -0,0 +1,25 @@
|
||||
<table class="table table-bordered table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>发送时间</th>
|
||||
<th>失败原因</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($list as $key => $value) {
|
||||
$tmp_msg = null;
|
||||
if ($value->TPSL_callbackJson == null) {
|
||||
$tmp_msg = "无导游安排";
|
||||
} else {
|
||||
$tmp_msg = json_decode($value->TPSL_callbackJson);
|
||||
$tmp_msg = $tmp_msg->errmsg;
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td> <?php echo $value->TPSL_logTime; ?> </td>
|
||||
<td> <?php echo $tmp_msg; ?> </td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue