From 02bc546e78d07ef5e22297676a61f1e9c43cb826 Mon Sep 17 00:00:00 2001 From: lyt Date: Fri, 24 Aug 2018 15:39:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=86=99=E5=90=8C?= =?UTF-8?q?=E6=AD=A5,=E6=9C=AA=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/TulanduoApi.php | 197 ++++++++++++++++-- .../trippestOrderSync/controllers/api.php | 2 +- .../trippestOrderSync/models/order_update.php | 14 ++ .../trippestOrderSync/models/orders_model.php | 44 ++-- 4 files changed, 224 insertions(+), 33 deletions(-) diff --git a/webht/third_party/trippestOrderSync/controllers/TulanduoApi.php b/webht/third_party/trippestOrderSync/controllers/TulanduoApi.php index b2370792..1320495c 100644 --- a/webht/third_party/trippestOrderSync/controllers/TulanduoApi.php +++ b/webht/third_party/trippestOrderSync/controllers/TulanduoApi.php @@ -169,7 +169,8 @@ class TulanduoApi extends CI_Controller $tmpv = $this->city_info[$vo['operationDep']]['PlanVEI_SN'] ? $this->city_info[$vo['operationDep']]['PlanVEI_SN'] : 1343; // set GCI_SN $this->Orders_model->get_SN_by_vendorOrderId($vo['orderId'], $tmpv); // 查询订单是否已经录入过 - if ($this->Orders_model->BIZ_COLI_SN === null && in_array($vo['agcName'], array("D目的地桂林组", "Trippest"))) { + // if ($this->Orders_model->BIZ_COLI_SN===null && in_array($vo['agcName'], array("D目的地桂林组", "Trippest"))) { + if ($this->Orders_model->BIZ_COLI_SN === null) { $real_groupCode = analysis_groupCode($vo['agcOrderNo']); // set BIZ_COLI_SN, GRI_SN at Orders_model $this->Orders_model->get_SN_by_groupCode($real_groupCode, $vo['orderId']); @@ -263,9 +264,6 @@ class TulanduoApi extends CI_Controller */ public function insert_HT_order_operation($coli_sn=null,$get_vendorID=null) { - // if ($coli_sn == null) { - // return null; - // } log_message('error','get_order_operation From TuLanDuo '); $this->load->model('Order_update'); if ($coli_sn !== null && $coli_sn != 0) { @@ -303,6 +301,7 @@ class TulanduoApi extends CI_Controller } continue; } + $detail_jsonResp->orderDetail->agcOrderNo = mb_ereg_replace('( )', '', trim($detail_jsonResp->orderDetail->agcOrderNo)); // 去掉中文的全角空格 // 目的地的团已经主动取消, 只有其他渠道的团需要更新状态 if (mb_strstr($detail_jsonResp->orderDetail->agcOrderNo, "取消") !== false) { $this->plan_cancel($order->GCI_VendorOrderId); @@ -330,17 +329,120 @@ class TulanduoApi extends CI_Controller } } /** HT 开始 */ - /** UPDATE */ $cnt++; $vei_SN = $this->city_info[$detail_jsonResp->orderDetail->operationDep]['PlanVEI_SN'] ? $this->city_info[$detail_jsonResp->orderDetail->operationDep]['PlanVEI_SN'] : $order->COLD_PlanVEI_SN; $getInfo_byGroupCode = null; - if (in_array($order->GCI_FromAgc, array("D目的地桂林组", "Trippest"))) { - $real_groupCode = analysis_groupCode($detail_jsonResp->orderDetail->agcOrderNo); - $getInfo_byGroupCode = $this->Orders_model->get_SN_by_groupCode($real_groupCode, $detail_jsonResp->orderDetail->orderId); + $real_groupCode = analysis_groupCode($detail_jsonResp->orderDetail->agcOrderNo); + if (intval($order->COLI_OPI_ID) === 435 ) { + $getInfo_byGroupCodeArr = $this->Orders_model->get_order_by_groupcode($real_groupCode); + if ( empty($getInfo_byGroupCodeArr) ){ + $getInfo_byGroupCode = null; // 没有该团号的团信息 + } elseif (strval($getInfo_byGroupCodeArr[0]->COLI_OPI_ID) !== '435') { // 避免intval(null)=0 + $getInfo_byGroupCode = $getInfo_byGroupCodeArr[0]; // 渠道和目的地有重复操作的团 + } else { + foreach ($getInfo_byGroupCodeArr as $kg => $vg) { + if (mb_substr($vg->GRI_No, 0, 49) === $detail_jsonResp->orderDetail->agcOrderNo) { + // 地接拆分的团号,需要全部匹配; 否则为没有团信息 + $getInfo_byGroupCode = $vg; + break; + } + } + } + if ($getInfo_byGroupCode === null) { + $PAG_Code = $pag_sub = null; + preg_match('/[a-zA-Z]+\-[0-9\-]+/', characet($detail_jsonResp->orderDetail->routeName, "UTF-8"), $temp_array); + if (empty($temp_array) && isset($pag_no_tmp[$detail_jsonResp->orderDetail->routeName])) { + $PAG_Code = $pag_no_tmp[$detail_jsonResp->orderDetail->routeName]; + $split_code = explode("-", $PAG_Code); + $PAG_Code = $split_code[0] . "-" . $split_code[1]; + isset($split_code[2]) ? $pag_sub=$split_code[2] : null; + } else if ( ! empty($temp_array)) { + $PAG_Code = $pag_sub = null; + $split_code = explode("-", $temp_array[0]); + $PAG_Code = $split_code[0] . "-" . $split_code[1]; + isset($split_code[2]) ? $pag_sub=$split_code[2] : null; + } else { + log_message('error',"未识别的线路名称 $PAG_Code " . $detail_jsonResp->orderDetail->orderId . " " . $detail_jsonResp->orderDetail->routeName . var_export($temp_array, 1)); + } + $PAG_Code = in_array($PAG_Code, array("SHALC-6","SHALC-7","SHALC-8","SHALC-9")) ? "SHSIC-45" : $PAG_Code; + $serviceSN = $this->Orders_model->get_packageSN($PAG_Code); + $COLD_MemoText = raw_json_encode(array("Pick up"=>$detail_jsonResp->orderDetail->toTraffic, "Drop off"=>$detail_jsonResp->orderDetail->backTraffic)); + /** INSERT GRoupInfo */ + $travelDate = new DateTime($detail_jsonResp->orderDetail->travelDate); + $leaveDate = new DateTime($detail_jsonResp->orderDetail->leaveDate); + $date_diff = $travelDate->diff($leaveDate); + $this->Orders_model->GRI_No = mb_substr($detail_jsonResp->orderDetail->agcOrderNo, 0, 49); + $this->Orders_model->GRI_OrderType = 227002; // 商务 + $this->Orders_model->GRI_Name = mb_substr($detail_jsonResp->orderDetail->agcName . $detail_jsonResp->orderDetail->agcOrderNo, 0, 49); + $this->Orders_model->GRI_PersonNum = $detail_jsonResp->orderDetail->adultNum+$detail_jsonResp->orderDetail->childNum; + $this->Orders_model->GRI_Days = intval($date_diff->format('%R%a')+1); + $this->Orders_model->GRI_IsCancel = 0; + $this->Orders_model->DeleteFlag = 0; + $this->Orders_model->GRI_OPI_ID = 435; + $this->Orders_model->GRI_operator = 435; + $this->Orders_model->GRI_Creator = 435; + $groupSN = $this->Orders_model->groupinfo_save(); + /** BIZ_Guest */ + $this->Orders_model->GUT_LastName = $detail_jsonResp->orderDetail->customers[0]->name; + $this->Orders_model->biz_guest_save(); + /** BIZ_ConfirmLineInfo*/ + $this->Orders_model->BIZ_COLI_GRI_SN = $groupSN; + $this->Orders_model->BIZ_COLI_GroupCode = $this->Orders_model->GRI_No; + $this->Orders_model->BIZ_GUT_SN = $this->Orders_model->GUT_SN; + $this->Orders_model->BIZ_COLI_ID = $this->Orders_model->biz_make_order_number(); + $this->Orders_model->BIZ_COLI_ApplyDate = $detail_jsonResp->orderDetail->orderTime; + $this->Orders_model->BIZ_COLI_sourcetype = empty($this->city_info[$detail_jsonResp->orderDetail->operationDep]) ? 32090 : $this->city_info[$detail_jsonResp->orderDetail->operationDep]['COLI_sourcetype']; + $this->Orders_model->BIZ_COLI_State = 9; + $this->Orders_model->BIZ_COLI_servicetype = 'D'; + $this->Orders_model->BIZ_COLI_ConfirmType = 52001; + $this->Orders_model->BIZ_COLI_Memo = ""; + $this->Orders_model->BIZ_COLI_OrderDetailText = "来自图兰朵系统同步" . $detail_jsonResp->orderDetail->orderId . ";线路:" . $detail_jsonResp->orderDetail->routeName . "; 团名: " . $detail_jsonResp->orderDetail->agcOrderNo; + $this->Orders_model->BIZ_COLI_GUT_SN = $this->Orders_model->BIZ_GUT_SN ? $this->Orders_model->BIZ_GUT_SN : null; + $this->Orders_model->BIZ_COLI_OPI_ID = 435; + $this->Orders_model->BIZ_COLI_PayManner = 15006; + $coli_sn = $this->Orders_model->biz_confirm_save(); + $coli_id = $this->Orders_model->BIZ_COLI_ID; + /**BIZ_ConfirmLineDetail*/ + $this->Orders_model->COLD_COLI_SN = $this->Orders_model->BIZ_COLI_SN; + $this->Orders_model->COLD_ServiceType = "D"; + $this->Orders_model->COLD_ServiceSN = $serviceSN->PAG2_PAG_SN; + $this->Orders_model->COLD_ServiceSN2 = $pag_sub; + $this->Orders_model->COLD_ServiceCity = $serviceSN->PAG_CII_SN; + $this->Orders_model->COLD_StartDate = $detail_jsonResp->orderDetail->travelDate; + $this->Orders_model->COLD_EndDate = $detail_jsonResp->orderDetail->leaveDate; + $this->Orders_model->COLD_PersonNum = $detail_jsonResp->orderDetail->adultNum; + $this->Orders_model->COLD_ChildNum = $detail_jsonResp->orderDetail->childNum; + $this->Orders_model->cold_state = 9 + $this->Orders_model->DeleteFlag = 0; + $this->Orders_model->COLD_PlanVEI_SN = $this->city_info[$detail_jsonResp->orderDetail->operationDep]['PlanVEI_SN'] ? $this->city_info[$detail_jsonResp->orderDetail->operationDep]['PlanVEI_SN'] : 1343; + $this->Orders_model->COLD_MemoText = $COLD_MemoText; + $cold_sn = $this->Orders_model->biz_confirm_detail_save(); + } + $groupSN = $groupSN ? $groupSN : $getInfo_byGroupCode->GRI_SN; + $coli_sn = $coli_sn ? $coli_sn : $getInfo_byGroupCode->COLI_SN; + $coli_id = $coli_id ? $coli_id : $getInfo_byGroupCode->COLI_ID; + $coli_memo = ($getInfo_byGroupCode!==null) ? $getInfo_byGroupCode->COLI_Memo : ""; + $coli_orderdetailtext = ($getInfo_byGroupCode!==null) ? $getInfo_byGroupCode->COLI_OrderDetailText : ""; + $coli_state = ($getInfo_byGroupCode!==null) ? $getInfo_byGroupCode->COLI_State : 9; + $cold_sn = $cold_sn ? $cold_sn : $getInfo_byGroupCode->COLD_SN; + } else { + // $getInfo_byGroupCode = null; + $getInfo_byGroupCode = $getInfo_byGroupCode[0]; + $groupSN = $order->COLI_GRI_SN; + $coli_sn = $order->COLI_SN; + $coli_id = $order->COLI_ID; + $coli_memo = $order->COLI_Memo; + $coli_orderdetailtext = $order->COLI_OrderDetailText; + $coli_state = $order->COLI_State; + $cold_sn = $order->COLD_SN; } - $groupSN = $getInfo_byGroupCode!==null ? $getInfo_byGroupCode->GRI_SN : $order->COLI_GRI_SN; - $coli_sn = isset($getInfo_byGroupCode->COLI_SN) ? $getInfo_byGroupCode->COLI_SN : $order->COLI_SN; - $coli_id = isset($getInfo_byGroupCode->COLI_SN) ? $getInfo_byGroupCode->COLI_ID : $order->COLI_ID; + // if (in_array($order->GCI_FromAgc, array("D目的地桂林组", "Trippest"))) { + // $getInfo_byGroupCode = $this->Orders_model->get_SN_by_groupCode($real_groupCode, $detail_jsonResp->orderDetail->orderId); + // } + /** UPDATE */ + $groupSN = $groupSN ? $groupSN : $order->COLI_GRI_SN; + $coli_sn = $coli_sn ? $coli_sn : $order->COLI_SN; + $coli_id = $coli_id ? $coli_id : $order->COLI_ID; $coli_memo = isset($getInfo_byGroupCode->COLI_SN) ? $getInfo_byGroupCode->COLI_Memo : $order->COLI_Memo; $coli_orderdetailtext = isset($getInfo_byGroupCode->COLI_SN) ? $getInfo_byGroupCode->COLI_OrderDetailText : $order->COLI_OrderDetailText; $coli_state = isset($getInfo_byGroupCode->COLI_SN) ? @@ -349,12 +451,10 @@ class TulanduoApi extends CI_Controller $cold_sn = isset($getInfo_byGroupCode->COLI_SN) ? $getInfo_byGroupCode->COLD_SN : $order->COLD_SN; // HT 订单有重复时, 以图兰朵的团号为正确的订单, 原本已录入的设为无效 if ($getInfo_byGroupCode === null) { - } elseif ($getInfo_byGroupCode->GRI_SN != $order->COLI_GRI_SN && in_array($order->GCI_FromAgc, array("D目的地桂林组", "Trippest"))) { + } elseif ($getInfo_byGroupCode->GRI_SN != $order->COLI_GRI_SN && intval($order->COLI_OPI_ID)===435) { if ( $order->COLI_ID && $order->COLI_ID != $getInfo_byGroupCode->COLI_ID) { $allDetails_to_HT .= "\r\n疑似重复,请更新订单状态:" . $order->COLI_ID; - if (intval($order->COLI_OPI_ID) === 435 ) { - $this->order_cancel($order->COLI_ID); - } + $this->order_cancel($order->COLI_ID); } } /** groupcombineinfo */ @@ -369,6 +469,15 @@ class TulanduoApi extends CI_Controller ,"GCI_createTime" => date('Y-m-d H:i:s') ); $this->Order_update->biz_groupcombineinfo_update($gci_update_column); + /** GRoupInfo */ + if (intval($order->COLI_OPI_ID) === 435 ) { + $gri_update_column = array( + "GRI_No" => $detail_jsonResp->orderDetail->agcOrderNo + ,"GRI_Name" => $detail_jsonResp->orderDetail->agcOrderNo + ); + $this->Order_update->gri_where_update = " GRI_SN=" . $groupSN; + $this->Order_update->biz_groupinfo_update($gci_update_column); + } /** BIZ_ConfirmLineInfo */ $this->Order_update->coli_where_update = " COLI_SN=" . $coli_sn; $old_memo = mb_strstr($coli_memo, " orderRemark", true)!==false ? mb_strstr($coli_memo, " orderRemark", true) : $coli_memo; @@ -396,9 +505,18 @@ class TulanduoApi extends CI_Controller ,"COLI_State" => $coli_state ,"COLI_Price" => $travel_fee ,"COLI_CUrrency" => $travel_fee_currency + ,"COLI_GroupCode" => $detail_jsonResp->orderDetail->agcOrderNo ); $this->Order_update->biz_confirmlineinfo_update($coli_update_column); /** BIZ_ConfirmLineDetail */ + if (intval($order->COLI_OPI_ID) === 435) { + $cold_update_column = array( + "COLD_PersonNum" => $detail_jsonResp->orderDetail->adultNum + ,"COLD_ChildNum" => $detail_jsonResp->orderDetail->childNum + ); + $this->Order_update->cold_where_update = " COLD_SN=" . $getInfo_byGroupCode->COLD_SN; + $this->Order_update->biz_confirmlinedetail_update($cold_update_column); + } /** INSERT */ /*BIZ_BookPeople*/ if ($this->Orders_model->bookpeople_exist($cold_sn) === array()) { @@ -652,6 +770,7 @@ class TulanduoApi extends CI_Controller */ public function get_history_order_list($oldest_date=null) { + $this->load->model('Tulanduo_sync_model', 'sync_model'); // $oldest_date===null ? $oldest_date = $this->Orders_model->get_oldest_offset() : null; $oldest_date===null ? $oldest_date = '2018-05-10' : null; // test $startTravelDate = date('Y-m-d', strtotime("-1 day", strtotime($oldest_date))); @@ -677,7 +796,7 @@ class TulanduoApi extends CI_Controller if ($resp_arr["responseData"]["totalRows"] == 0) { log_message('error','TulanduoApi get_orderlist history 0. '); // 继续往前滚日期 - $this->get_history_order_list($startTravelDate); + return $this->get_history_order_list($startTravelDate); } $all_list = $resp_arr["responseData"]["orders"]; for($pi=2; $pi <= $resp_arr['responseData']['pageCount']; $pi++) { @@ -695,10 +814,52 @@ class TulanduoApi extends CI_Controller $exists_ht = $this->Orders_model->get_exists_vendorOrderId($all_vendor_order_id_str); $exists_ht_order_id = array_map(function($ele){ return intval($ele->GCI_VendorOrderId);}, $exists_ht); $to_insert = array_diff($all_vendor_order_id, $exists_ht_order_id); - var_export($to_insert); if (empty($to_insert) || count($to_insert)==1) { // 继续往前滚日期 - $this->get_history_order_list($startTravelDate); + return $this->get_history_order_list($startTravelDate); + } + foreach ($all_list as $k => $vo) { + if ( ! in_array($value['orderId'], $to_insert)) { + continue; + } + $vo['agcOrderNo'] = mb_ereg_replace('( )', '', trim($vo['agcOrderNo'])); // 去掉中文的全角空格 + // 解析产品编号 + $PAG_Code = $pag_sub = null; + preg_match('/[a-zA-Z]+\-[0-9\-]+/', $this->characet($vo['routeName'], "UTF-8"), $temp_array); + if (empty($temp_array) && isset($pag_no_tmp[$vo['routeName']])) { + $PAG_Code = $pag_no_tmp[$vo['routeName']]; + $split_code = explode("-", $PAG_Code); + $PAG_Code = $split_code[0] . "-" . $split_code[1]; + isset($split_code[2]) ? $pag_sub=$split_code[2] : null; + } else if ( ! empty($temp_array)) { + $PAG_Code = $pag_sub = null; + $split_code = explode("-", $temp_array[0]); + $PAG_Code = $split_code[0] . "-" . $split_code[1]; + isset($split_code[2]) ? $pag_sub=$split_code[2] : null; + } else { + log_message('error',"未识别的线路名称 $PAG_Code " . $vo['orderId'] . " " . $vo['routeName'] . var_export($temp_array, 1)); + } + $PAG_Code = in_array($PAG_Code, array("SHALC-6","SHALC-7","SHALC-8","SHALC-9")) ? "SHSIC-45" : $PAG_Code; + $serviceSN = $this->Orders_model->get_packageSN($PAG_Code); + $COLD_MemoText = raw_json_encode(array("Pick up"=>$vo['toTraffic'], "Drop off"=>$vo['backTraffic'])); + $tmpv = $this->city_info[$vo['operationDep']]['PlanVEI_SN'] ? $this->city_info[$vo['operationDep']]['PlanVEI_SN'] : 1343; + // if (in_array($vo['agcName'], array("D目的地桂林组", "Trippest"))) { + $real_groupCode = analysis_groupCode($vo['agcOrderNo']); + // check BIZ_COLI_SN,GRI_SN + $this->Orders_model->get_SN_by_groupCode($real_groupCode, $vo['orderId']); + // } + /** INSERT */ + /** biz_groupcombineinfo*/ + $this->Orders_model->GCI_combineNo = isset($vo['groupOrderNo']) ? $vo['groupOrderNo'] : ''; + $this->Orders_model->GCI_GRI_SN = $this->sync_model->GRI_SN; + $this->Orders_model->GCI_VEI_SN = $this->city_info[$vo['operationDep']]['PlanVEI_SN'] ? $this->city_info[$vo['operationDep']]['PlanVEI_SN'] : 1343; + $this->Orders_model->GCI_VendorOrderId = $vo['orderId']; + $this->Orders_model->GCI_FromAgc = $vo['agcName']; + $this->Orders_model->GCI_groupType = $vo['orderType']; + $this->Orders_model->GCI_travelDate = $vo['travelDate']; + $this->Orders_model->GCI_leaveDate = $vo['leaveDate']; + $this->Orders_model->GCI_createTime = date('Y-m-d H:i:s'); + $this->Orders_model->biz_groupcombineinfo_save(); } exit(); } diff --git a/webht/third_party/trippestOrderSync/controllers/api.php b/webht/third_party/trippestOrderSync/controllers/api.php index fa89eb5d..1562f36b 100644 --- a/webht/third_party/trippestOrderSync/controllers/api.php +++ b/webht/third_party/trippestOrderSync/controllers/api.php @@ -39,7 +39,7 @@ class Api extends CI_Controller { { return $ele->GCI_combineNo; }, $order_project)); - $ret['operation'] = null; + $ret['operation'] = array(); $operation = $this->Orders_model->get_operation($all_combine_no); // 司机, 导游 if ( ! empty($operation)) { diff --git a/webht/third_party/trippestOrderSync/models/order_update.php b/webht/third_party/trippestOrderSync/models/order_update.php index 7c2b17f0..bff88fd2 100644 --- a/webht/third_party/trippestOrderSync/models/order_update.php +++ b/webht/third_party/trippestOrderSync/models/order_update.php @@ -56,6 +56,20 @@ class Order_update extends CI_Model { return $update_exc; } + /*! + * 更新团信息 + */ + public $gri_where_update = ""; // where 条件 + public function biz_groupinfo_update($column_data) + { + if ($this->gri_where_update == "" || empty($column_data)) { + return false; + } + $update_str = $this->HT->update_string('GroupInfo', $column_data, $this->gri_where_update); + $update_exc = $this->HT->query($update_str); + return $update_exc; + } + /*! * 地接计划状态变更 * @param [type] $vas_sn [description] diff --git a/webht/third_party/trippestOrderSync/models/orders_model.php b/webht/third_party/trippestOrderSync/models/orders_model.php index 43ecc465..ae96731a 100644 --- a/webht/third_party/trippestOrderSync/models/orders_model.php +++ b/webht/third_party/trippestOrderSync/models/orders_model.php @@ -122,18 +122,7 @@ class Orders_model extends CI_Model { } return NULL; } - public function get_exists_vendorOrderId($vendorOrderIds="") - { - $sql = "SELECT GCI_VendorOrderId FROM GroupCombineInfo - WHERE GCI_VendorOrderId IN ($vendorOrderIds) "; - return $this->HT->query($sql)->result(); - } - public function get_oldest_offset() - { - $sql = "SELECT top 1 CAST(GCI_travelDate as DATE) old_date from GroupCombineInfo - order by GCI_travelDate asc"; - return $this->HT->query($sql)->row()->old_date; - } + /*! * 需要更新调度信息的订单 -- 商务表 * @param integer $coli_sn [description] @@ -145,7 +134,7 @@ class Orders_model extends CI_Model { $sql = "SELECT top 10 coli.COLI_ID, coli.COLI_SN, coli.COLI_GRI_SN, cold.COLD_SN, coli.COLI_OrderDetailText, coli.COLI_Memo,coli.COLI_State,coli.COLI_OPI_ID, cold.COLD_PlanVEI_SN, gci.* FROM GroupCombineInfo gci - LEFT JOIN BIZ_ConfirmLineInfo coli ON coli.COLI_GRI_SN=gci.GCI_GRI_SN and coli.COLI_State NOT IN ('30','40','50') + LEFT JOIN BIZ_ConfirmLineInfo coli ON coli.COLI_GRI_SN=gci.GCI_GRI_SN --and coli.COLI_State NOT IN ('30','40','50') LEFT JOIN BIZ_ConfirmLineDetail cold ON cold.COLD_COLI_SN=coli.COLI_SN WHERE 1=1 "; if ($coli_sn !== 0) { @@ -524,13 +513,19 @@ class Orders_model extends CI_Model { return NULL; } + /*! + * 1. 获取列表时: 按团号查询团是否已存在, 避免渠道和目的地组同时操作 + * @param [type] $code [description] + * @param [type] $vendorOrderId [description] + */ public function get_SN_by_groupCode($code, $vendorOrderId=NULL) { $sql = "SELECT top 1 COLI_SN,gri.GRI_SN,cold.COLD_PlanVEI_SN,cold.COLD_SN,coli.COLI_ID,coli.COLI_Memo,coli.COLI_OrderDetailText,coli.COLI_State,coli.COLI_OPI_ID,coli.COLI_Price,coli.COLI_CUrrency ,GRI_OPI_ID,GRI_operator,GRI_No,GRI_Name FROM BIZ_ConfirmLineInfo coli - inner join BIZ_ConfirmLineDetail cold on cold.COLD_COLI_SN=COLI_SN and COLI_State not in (30,40,50) + inner join BIZ_ConfirmLineDetail cold on cold.COLD_COLI_SN=COLI_SN --and COLI_State not in (30,40,50) LEFT JOIN GRoupInfo gri ON coli.COLI_GRI_SN=gri.GRI_SN and GRI_OrderType=227002 + and gri.GRI_operator<>435 and gri.GRI_operator is not null WHERE gri.GRI_No LIKE '%$code%' order by COLI_SN desc"; // and gri.GRI_Name like '%$NoName%' $query = $this->HT->query($sql); @@ -545,6 +540,27 @@ class Orders_model extends CI_Model { return NULL; } + /*! + * 更新时: + * @date 2018-08-23 + * @param [type] $code [description] + */ + public function get_order_by_groupcode($code) + { + $sql = "SELECT COLI_SN,gri.GRI_SN,cold.COLD_PlanVEI_SN,cold.COLD_SN,coli.COLI_ID, + coli.COLI_OrderDetailText, + coli.COLI_State,coli.COLI_OPI_ID,coli.COLI_Price,coli.COLI_CUrrency + GRI_OPI_ID,GRI_operator,GRI_No,GRI_Name, + coli.COLI_Memo + FROM BIZ_ConfirmLineInfo coli + inner join BIZ_ConfirmLineDetail cold on cold.COLD_COLI_SN=COLI_SN + left JOIN GRoupInfo gri ON coli.COLI_GRI_SN=gri.GRI_SN and GRI_OrderType=227002 + WHERE gri.GRI_No LIKE '%$code%' + order by case COLI_OPI_ID when 435 then 1 else 0 end asc,COLI_SN desc"; + $query = $this->HT->query($sql); + return $query->result(); + } + /*! * 获取地接社接受计划的人员信息 * @param $vendorID 地接社ID From 3f20da44085dabb188744da16ae22cc5d64ed7de Mon Sep 17 00:00:00 2001 From: lyt Date: Fri, 7 Sep 2018 11:36:00 +0800 Subject: [PATCH 2/2] =?UTF-8?q?trippest=E8=8E=B7=E5=8F=96=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E8=AE=A2=E5=8D=95;=20=E6=8E=92=E9=99=A4=E5=95=86?= =?UTF-8?q?=E6=97=85=E7=BB=84=E5=9B=A2=E5=8F=B7;=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=9C=AA=E8=AF=86=E5=88=AB=E4=BA=A7=E5=93=81;=E6=8B=86?= =?UTF-8?q?=E5=88=86=E5=9B=A2=E4=BF=AE=E6=94=B9=E5=9B=A2=E5=8F=B7=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/TulanduoApi.php | 1093 ++++++++--------- .../helpers/array_helper.php | 9 +- .../trippestOrderSync/models/orders_model.php | 8 +- .../models/tulanduo_sync_model.php | 59 + 4 files changed, 590 insertions(+), 579 deletions(-) create mode 100644 webht/third_party/trippestOrderSync/models/tulanduo_sync_model.php diff --git a/webht/third_party/trippestOrderSync/controllers/TulanduoApi.php b/webht/third_party/trippestOrderSync/controllers/TulanduoApi.php index 1320495c..938d1a7b 100644 --- a/webht/third_party/trippestOrderSync/controllers/TulanduoApi.php +++ b/webht/third_party/trippestOrderSync/controllers/TulanduoApi.php @@ -21,6 +21,11 @@ class TulanduoApi extends CI_Controller ,"COLI_sourcetype" => 32090 ,"routeType" => "北京目的地线路" ), + "总部" => array( + "PlanVEI_SN" => 1343 + ,"COLI_sourcetype" => 32090 + ,"routeType" => "北京目的地线路" + ), "西安分公司" => array( "PlanVEI_SN" => 30548 ,"COLI_sourcetype" => 32116 @@ -32,6 +37,7 @@ class TulanduoApi extends CI_Controller ,"routeType" => "上海目的地线路" ) ); + public $vendor_ids = array(1343,30548,29188); // userId key // 1343 2e47c3721e3ff6e816fe6b928d7acc7d @@ -75,7 +81,6 @@ class TulanduoApi extends CI_Controller */ public function get_orderlist($order_number=null) { - // $order_number = $this->input->get_post("orderNo"); $startOrderDate = date('Y-m-d', strtotime("-2 days")); $endOrderDate = date('Y-m-d'); $startTravelDate = date('Y-m-d'); @@ -89,11 +94,11 @@ class TulanduoApi extends CI_Controller } else { $get_type = rand(0, 1); // 需要按预定时间和出发时间, 避免有漏的 if ($get_type === 0) { - log_message('error','get_orderlist From TuLanDuo By travel Date' ); + log_message('error','Got order list From TuLanDuo By travel Date' ); $this->tld_order->setStartTravelDate($startTravelDate) ->setEndTravelDate($endTravelDate) ; } else { - log_message('error','get_orderlist From TuLanDuo By order Date' ); + log_message('error','Got order list From TuLanDuo By order Date' ); $this->tld_order->setStartOrderDate($startOrderDate) ->setEndOrderDate($endOrderDate) ; } @@ -101,35 +106,21 @@ class TulanduoApi extends CI_Controller $resp = $this->excute_curl($this->list_url, $this->tld_order); $resp_arr = json_decode($resp, true); if ($resp_arr['status'] !== 1) { - log_message('error','TulanduoApi get_orderlist failed. Msg:' . $resp_arr['errMsg'] . "; Request: " . ($this->tld_order->getBizContent())); + log_message('error','TulanduoApi Got order list failed. Msg:' . $resp_arr['errMsg'] . "; Request: " . ($this->tld_order->getBizContent())); return; } if ($resp_arr["responseData"]["totalRows"] == 0) { - log_message('error','TulanduoApi get_orderlist 0. '); return; } $all_list = $resp_arr["responseData"]["orders"]; - $order_to_HT = array_map( - function($ele){ - if ( ! in_array($ele['agcName'], array("D目的地桂林组", "Trippest")) ) { - return $ele; - } - },$resp_arr["responseData"]["orders"]); for($pi=2; $pi <= $resp_arr['responseData']['pageCount']; $pi++) { $this->tld_order->setPageIndex($pi); $f_resp = $this->excute_curl($this->list_url, $this->tld_order); $f_resp_arr = json_decode($f_resp, true); if ($resp_arr['status'] !== 1) { - log_message('error','TulanduoApi get_orderlist failed. Msg:' . $f_resp_arr['errMsg'] . "; Request: " . ($this->tld_order->getBizContent())); + log_message('error','TulanduoApi Got order list failed. Msg:' . $f_resp_arr['errMsg'] . "; Request: " . ($this->tld_order->getBizContent())); continue; } - $f_order_to_HT = array_map( - function($ele){ - if ( ! in_array($ele['agcName'], array("D目的地桂林组", "Trippest")) ) { - return $ele; - } - },$f_resp_arr["responseData"]["orders"]); - $order_to_HT = array_filter(array_merge($order_to_HT, $f_order_to_HT)); $all_list = array_merge($all_list, $f_resp_arr["responseData"]["orders"]); } $cnt = 0; @@ -141,27 +132,9 @@ class TulanduoApi extends CI_Controller continue; } $unique_order[] = $vo['orderId']; - $this->Orders_model->BIZ_COLI_SN = null; - $this->Orders_model->GRI_SN = null; - $vo['agcOrderNo'] = mb_ereg_replace('( )', '', trim($vo['agcOrderNo'])); // 去掉中文的全角空格 - $PAG_Code = $pag_sub = null; - preg_match('/[a-zA-Z]+\-[0-9\-]+/', $this->characet($vo['routeName'], "UTF-8"), $temp_array); - if (empty($temp_array) && isset($pag_no_tmp[$vo['routeName']])) { - $PAG_Code = $pag_no_tmp[$vo['routeName']]; - $split_code = explode("-", $PAG_Code); - $PAG_Code = $split_code[0] . "-" . $split_code[1]; - isset($split_code[2]) ? $pag_sub=$split_code[2] : null; - } else if ( ! empty($temp_array)) { - $PAG_Code = $pag_sub = null; - $split_code = explode("-", $temp_array[0]); - $PAG_Code = $split_code[0] . "-" . $split_code[1]; - isset($split_code[2]) ? $pag_sub=$split_code[2] : null; - } else { - log_message('error',"未识别的线路名称 $PAG_Code " . $vo['orderId'] . " " . $vo['routeName'] . var_export($temp_array, 1)); - } - $PAG_Code = in_array($PAG_Code, array("SHALC-6","SHALC-7","SHALC-8","SHALC-9")) ? "SHSIC-45" : $PAG_Code; - $serviceSN = $this->Orders_model->get_packageSN($PAG_Code); - $COLD_MemoText = raw_json_encode(array("Pick up"=>$vo['toTraffic'], "Drop off"=>$vo['backTraffic'])); + // paypal 手续费订单没有团号 + $vo['agcOrderNo'] = isset($vo['agcOrderNo']) ? $vo['agcOrderNo'] : $vo['groupOrderNo']; + $vo['agcOrderNo'] = trim_groupCode(trim($vo['agcOrderNo'])); // 去掉中文的全角空格 $this->Orders_model->BIZ_COLI_SN = null; $this->Orders_model->GRI_SN = null; @@ -169,7 +142,6 @@ class TulanduoApi extends CI_Controller $tmpv = $this->city_info[$vo['operationDep']]['PlanVEI_SN'] ? $this->city_info[$vo['operationDep']]['PlanVEI_SN'] : 1343; // set GCI_SN $this->Orders_model->get_SN_by_vendorOrderId($vo['orderId'], $tmpv); // 查询订单是否已经录入过 - // if ($this->Orders_model->BIZ_COLI_SN===null && in_array($vo['agcName'], array("D目的地桂林组", "Trippest"))) { if ($this->Orders_model->BIZ_COLI_SN === null) { $real_groupCode = analysis_groupCode($vo['agcOrderNo']); // set BIZ_COLI_SN, GRI_SN at Orders_model @@ -177,94 +149,40 @@ class TulanduoApi extends CI_Controller } if ($this->Orders_model->GRI_SN === null) { /** GRoupInfo */ - $travelDate = new DateTime($vo['travelDate']); - $leaveDate = new DateTime($vo['leaveDate']); - $date_diff = $travelDate->diff($leaveDate); - $this->Orders_model->GRI_No = mb_substr($vo['agcOrderNo'], 0, 49); - $this->Orders_model->GRI_OrderType = 227002; // 商务 - $this->Orders_model->GRI_Name = mb_substr($vo["agcName"] . $vo['agcOrderNo'], 0, 49); - $this->Orders_model->GRI_PersonNum = $vo['adultNum']+$vo['childNum']; - $this->Orders_model->GRI_Days = intval($date_diff->format('%R%a')+1); - $this->Orders_model->GRI_IsCancel = 0; - $this->Orders_model->DeleteFlag = 0; - $this->Orders_model->GRI_OPI_ID = 435; - $this->Orders_model->GRI_operator = 435; - $this->Orders_model->GRI_Creator = 435; - $this->Orders_model->groupinfo_save(); + $this->insert_gri($vo); } /** insert HT */ if ($this->Orders_model->BIZ_COLI_SN === null) { /** BIZ_Guest */ $this->Orders_model->GUT_LastName = $vo['customerName']; $this->Orders_model->biz_guest_save(); - /**BIZ_ConfirmLineInfo*/ - $this->Orders_model->BIZ_COLI_GRI_SN = $this->Orders_model->GRI_SN ? $this->Orders_model->GRI_SN : null; - $this->Orders_model->BIZ_COLI_GroupCode = $this->Orders_model->GRI_SN ? $this->Orders_model->GRI_No : ""; - $this->Orders_model->BIZ_GUT_SN = $this->Orders_model->GUT_SN; - $this->Orders_model->BIZ_COLI_ID = $this->Orders_model->biz_make_order_number(); - $this->Orders_model->BIZ_COLI_ApplyDate = $vo['orderDate']; - $this->Orders_model->BIZ_COLI_sourcetype = empty($this->city_info[$vo['operationDep']]) ? 32090 : $this->city_info[$vo['operationDep']]['COLI_sourcetype']; - $this->Orders_model->BIZ_COLI_State = 9; - $this->Orders_model->BIZ_COLI_servicetype = 'D'; - $this->Orders_model->BIZ_COLI_ConfirmType = 52001; - $this->Orders_model->BIZ_COLI_Memo = ""; - $this->Orders_model->BIZ_COLI_OrderDetailText = "来自图兰朵系统同步" . $vo["orderId"] . ";线路:" . $vo['routeName'] . "; 团名: " . $vo['agcOrderNo']; - $this->Orders_model->BIZ_COLI_GUT_SN = $this->Orders_model->BIZ_GUT_SN ? $this->Orders_model->BIZ_GUT_SN : null; - $this->Orders_model->BIZ_COLI_OPI_ID = 435; - $this->Orders_model->BIZ_COLI_PayManner = 15006; - $coli_sn[] = $this->Orders_model->biz_confirm_save(); - /**BIZ_ConfirmLineDetail*/ - $this->Orders_model->COLD_COLI_SN = $this->Orders_model->BIZ_COLI_SN; - $this->Orders_model->COLD_ServiceType = "D"; - $this->Orders_model->COLD_ServiceSN = $serviceSN->PAG2_PAG_SN; - $this->Orders_model->COLD_ServiceSN2 = $pag_sub; - $this->Orders_model->COLD_ServiceCity = $serviceSN->PAG_CII_SN; - $this->Orders_model->COLD_StartDate = $vo['travelDate']; - $this->Orders_model->COLD_EndDate = $vo['leaveDate']; - $this->Orders_model->COLD_PersonNum = $vo['adultNum']; - $this->Orders_model->COLD_ChildNum = $vo['childNum']; - $this->Orders_model->cold_state = $vo['orderStatus']==1 ? 9 : 104; // 9订妥 // 104联络地接中 - $this->Orders_model->DeleteFlag = 0; - $this->Orders_model->COLD_PlanVEI_SN = $this->city_info[$vo['operationDep']]['PlanVEI_SN'] ? $this->city_info[$vo['operationDep']]['PlanVEI_SN'] : 1343; - $this->Orders_model->COLD_MemoText = $COLD_MemoText; - $this->Orders_model->biz_confirm_detail_save(); - /** SP_BIZ_Arrange - * 这里是其他社的订单, 不写这个操作 - */ - // if ($this->Orders_model->GRI_SN) { - // $this->Orders_model->sp_biz_arrange(); - // } + /** BIZ_ConfirmLineInfo*/ + $this->insert_coli($vo); + /** BIZ_ConfirmLineDetail*/ + $this->insert_cold($vo); $cnt++; } if ($this->Orders_model->GCI_SN === null) { /*biz_groupcombineinfo*/ - $this->Orders_model->GCI_combineNo = isset($vo['groupOrderNo']) ? $vo['groupOrderNo'] : ''; - $this->Orders_model->GCI_GRI_SN = $this->Orders_model->GRI_SN; - $this->Orders_model->GCI_VEI_SN = $this->city_info[$vo['operationDep']]['PlanVEI_SN'] ? $this->city_info[$vo['operationDep']]['PlanVEI_SN'] : 1343; - $this->Orders_model->GCI_VendorOrderId = $vo['orderId']; - $this->Orders_model->GCI_FromAgc = $vo['agcName']; - $this->Orders_model->GCI_groupType = $vo['orderType']; - $this->Orders_model->GCI_travelDate = $vo['travelDate']; - $this->Orders_model->GCI_leaveDate = $vo['leaveDate']; - $this->Orders_model->GCI_createTime = date('Y-m-d H:i:s'); - $this->Orders_model->biz_groupcombineinfo_save(); + $this->insert_gci($vo); } } - log_message('error',"Got order list from TuLanDuo. count: " . $resp_arr["responseData"]["totalRows"] . " Insert COLI : " . $cnt); - echo "Got order list from TuLanDuo. count: " . $resp_arr["responseData"]["totalRows"] . "\r\n"; - echo "Insert COLI : " . $cnt . "\r\n"; + $output_text = "Got order list from TuLanDuo. count: " . $resp_arr["responseData"]["totalRows"] . ". Insert COLI : " . $cnt; + log_message('error', $output_text); + echo $output_text; return; } /*! * 更新订单的详情;[客人列表, 团费, 调度信息] + * * 定时执行, 约5分钟一次, 每次更新一个订单 * @date 2018-05-02 * @param [type] $coli_sn HT系统的订单key */ public function insert_HT_order_operation($coli_sn=null,$get_vendorID=null) { - log_message('error','get_order_operation From TuLanDuo '); + // log_message('error','get_order_operation From TuLanDuo '); $this->load->model('Order_update'); if ($coli_sn !== null && $coli_sn != 0) { $to_update_list = $this->Orders_model->get_groupCombineInfo($coli_sn); @@ -277,246 +195,182 @@ class TulanduoApi extends CI_Controller $endDate = date('Y-m-d', strtotime("+2 days")); $to_update_list = $this->Orders_model->get_groupCombineInfo(0, null, $startDate, $endDate); } - $unique_orderGroupCombine = array(); - $unique_order = array(); - $cnt = 0; - foreach ($to_update_list as $key => $order) { - if (in_array($order->GCI_VendorOrderId, $unique_order)) { - continue; - } - $unique_order[] = $order->GCI_VendorOrderId; - $this->tld_order->setOrderId($order->GCI_VendorOrderId) - ->setUserId($this->userId) - ->setKey($this->key); - $detail_resp = $this->excute_curl($this->detail_url, $this->tld_order); - $detail_jsonResp = json_decode($detail_resp); - // 判断取消 - if ($detail_jsonResp->status !== 1) { - log_message('error','TulanduoApi get_orderdetail failed. Msg:' . $detail_jsonResp->errMsg . "; Request: " . $this->tld_order->getBizContent()); - if ( $detail_jsonResp->errMsg == "未查询到对应的订单") { - $this->plan_cancel($order->GCI_VendorOrderId); - if (intval($order->COLI_OPI_ID) === 435) { - $this->order_cancel($order->COLI_ID); - } - } - continue; - } - $detail_jsonResp->orderDetail->agcOrderNo = mb_ereg_replace('( )', '', trim($detail_jsonResp->orderDetail->agcOrderNo)); // 去掉中文的全角空格 - // 目的地的团已经主动取消, 只有其他渠道的团需要更新状态 - if (mb_strstr($detail_jsonResp->orderDetail->agcOrderNo, "取消") !== false) { + $unique_orderGroupCombine = array(); // 录入拼团调度时,避免重复 + $order = $to_update_list[0]; + $this->tld_order->setOrderId($order->GCI_VendorOrderId) + ->setUserId($this->userId) + ->setKey($this->key); + $detail_resp = $this->excute_curl($this->detail_url, $this->tld_order); + $detail_jsonResp = json_decode($detail_resp); + // 判断取消 + if ($detail_jsonResp->status !== 1) { + log_message('error','TulanduoApi get_orderdetail failed. Msg:' . $detail_jsonResp->errMsg . "; Request: " . $this->tld_order->getBizContent()); + if ( $detail_jsonResp->errMsg == "未查询到对应的订单") { $this->plan_cancel($order->GCI_VendorOrderId); if (intval($order->COLI_OPI_ID) === 435) { $this->order_cancel($order->COLI_ID); } - continue; } - $allDetails_to_HT = ""; - $allDetails_to_HT .= "\r\n日程: "; - foreach ($detail_jsonResp->orderDetail->scheduleDetails as $vsd) { - $allDetails_to_HT .= $vsd->travelDate .": ". $vsd->title . "; "; + if ($detail_jsonResp->errMsg == "您没有查看本订单的权限!") { + $this->plan_cancel($order->GCI_VendorOrderId, "forbidden"); } - if (isset($detail_jsonResp->orderDetail->operationDetails->guiderOperations) ) { - $allDetails_to_HT .= "\r\n导游: "; - foreach ($detail_jsonResp->orderDetail->operationDetails->guiderOperations as $vg) { - $allDetails_to_HT .= $vg->name ." (". $vg->mobelPhone . "); "; - } + return; + } + $detail_jsonResp->orderDetail->agcOrderNo = trim_groupCode(trim($detail_jsonResp->orderDetail->agcOrderNo)); // 去掉中文的全角空格 + // 目的地的团已经主动取消, 只有其他渠道的团需要更新状态 + if (mb_strstr($detail_jsonResp->orderDetail->agcOrderNo, "取消") !== false) { + $this->plan_cancel($order->GCI_VendorOrderId); + if (intval($order->COLI_OPI_ID) === 435) { + $this->order_cancel($order->COLI_ID); } - if (isset($detail_jsonResp->orderDetail->operationDetails->touristCarOperations) ) { - $allDetails_to_HT .= "\r\n用车: "; - foreach ($detail_jsonResp->orderDetail->operationDetails->touristCarOperations as $vtc) { - $allDetails_to_HT .= $vtc->name .": " . $vtc->driver." (". $vtc->driverTel . ") "; - $allDetails_to_HT .= "[". $vtc->remark . "]; "; - } + return; + } + $allDetails_to_HT = ""; + $allDetails_to_HT .= "\r\n日程: "; + foreach ($detail_jsonResp->orderDetail->scheduleDetails as $vsd) { + $allDetails_to_HT .= $vsd->travelDate .": ". $vsd->title . "; "; + } + if (isset($detail_jsonResp->orderDetail->operationDetails->guiderOperations) ) { + $allDetails_to_HT .= "\r\n导游: "; + foreach ($detail_jsonResp->orderDetail->operationDetails->guiderOperations as $vg) { + $allDetails_to_HT .= $vg->name ." (". $vg->mobelPhone . "); "; } - /** HT 开始 */ - $cnt++; - $vei_SN = $this->city_info[$detail_jsonResp->orderDetail->operationDep]['PlanVEI_SN'] ? $this->city_info[$detail_jsonResp->orderDetail->operationDep]['PlanVEI_SN'] : $order->COLD_PlanVEI_SN; - $getInfo_byGroupCode = null; - $real_groupCode = analysis_groupCode($detail_jsonResp->orderDetail->agcOrderNo); - if (intval($order->COLI_OPI_ID) === 435 ) { - $getInfo_byGroupCodeArr = $this->Orders_model->get_order_by_groupcode($real_groupCode); - if ( empty($getInfo_byGroupCodeArr) ){ - $getInfo_byGroupCode = null; // 没有该团号的团信息 - } elseif (strval($getInfo_byGroupCodeArr[0]->COLI_OPI_ID) !== '435') { // 避免intval(null)=0 - $getInfo_byGroupCode = $getInfo_byGroupCodeArr[0]; // 渠道和目的地有重复操作的团 - } else { - foreach ($getInfo_byGroupCodeArr as $kg => $vg) { - if (mb_substr($vg->GRI_No, 0, 49) === $detail_jsonResp->orderDetail->agcOrderNo) { - // 地接拆分的团号,需要全部匹配; 否则为没有团信息 - $getInfo_byGroupCode = $vg; - break; - } - } - } - if ($getInfo_byGroupCode === null) { - $PAG_Code = $pag_sub = null; - preg_match('/[a-zA-Z]+\-[0-9\-]+/', characet($detail_jsonResp->orderDetail->routeName, "UTF-8"), $temp_array); - if (empty($temp_array) && isset($pag_no_tmp[$detail_jsonResp->orderDetail->routeName])) { - $PAG_Code = $pag_no_tmp[$detail_jsonResp->orderDetail->routeName]; - $split_code = explode("-", $PAG_Code); - $PAG_Code = $split_code[0] . "-" . $split_code[1]; - isset($split_code[2]) ? $pag_sub=$split_code[2] : null; - } else if ( ! empty($temp_array)) { - $PAG_Code = $pag_sub = null; - $split_code = explode("-", $temp_array[0]); - $PAG_Code = $split_code[0] . "-" . $split_code[1]; - isset($split_code[2]) ? $pag_sub=$split_code[2] : null; - } else { - log_message('error',"未识别的线路名称 $PAG_Code " . $detail_jsonResp->orderDetail->orderId . " " . $detail_jsonResp->orderDetail->routeName . var_export($temp_array, 1)); + } + if (isset($detail_jsonResp->orderDetail->operationDetails->touristCarOperations) ) { + $allDetails_to_HT .= "\r\n用车: "; + foreach ($detail_jsonResp->orderDetail->operationDetails->touristCarOperations as $vtc) { + $allDetails_to_HT .= $vtc->name .": " . $vtc->driver." (". $vtc->driverTel . ") "; + $allDetails_to_HT .= "[". $vtc->remark . "]; "; + } + } + /** HT 开始 */ + $vei_SN = $this->city_info[$detail_jsonResp->orderDetail->operationDep]['PlanVEI_SN'] ? $this->city_info[$detail_jsonResp->orderDetail->operationDep]['PlanVEI_SN'] : 1343; + $getInfo_byGroupCode = null; + $real_groupCode = analysis_groupCode($detail_jsonResp->orderDetail->agcOrderNo); + $getInfo_byGroupCodeArr = $this->Orders_model->get_order_by_groupcode($real_groupCode); + $duplicate = false; + // 由同步新增的订单 或 未找到团号关联 + if (intval($order->COLI_OPI_ID) === 435 || $order->COLI_ID === null) { + if ( empty($getInfo_byGroupCodeArr)){ + $getInfo_byGroupCode = null; // 没有该团号的团信息 + } elseif (strval($getInfo_byGroupCodeArr[0]->COLI_OPI_ID) !== '435') { // 避免intval(null)=0 + $getInfo_byGroupCode = $getInfo_byGroupCodeArr[0]; // 渠道和目的地有重复操作的团 + $duplicate = true; + } else { + foreach ($getInfo_byGroupCodeArr as $kg => $vg) { + if ($vg->GRI_No === mb_substr($detail_jsonResp->orderDetail->agcOrderNo, 0, 49)) { + // 地接拆分的团号,需要全部匹配; 否则为没有团信息 + $getInfo_byGroupCode = $vg; + break; } - $PAG_Code = in_array($PAG_Code, array("SHALC-6","SHALC-7","SHALC-8","SHALC-9")) ? "SHSIC-45" : $PAG_Code; - $serviceSN = $this->Orders_model->get_packageSN($PAG_Code); - $COLD_MemoText = raw_json_encode(array("Pick up"=>$detail_jsonResp->orderDetail->toTraffic, "Drop off"=>$detail_jsonResp->orderDetail->backTraffic)); - /** INSERT GRoupInfo */ - $travelDate = new DateTime($detail_jsonResp->orderDetail->travelDate); - $leaveDate = new DateTime($detail_jsonResp->orderDetail->leaveDate); - $date_diff = $travelDate->diff($leaveDate); - $this->Orders_model->GRI_No = mb_substr($detail_jsonResp->orderDetail->agcOrderNo, 0, 49); - $this->Orders_model->GRI_OrderType = 227002; // 商务 - $this->Orders_model->GRI_Name = mb_substr($detail_jsonResp->orderDetail->agcName . $detail_jsonResp->orderDetail->agcOrderNo, 0, 49); - $this->Orders_model->GRI_PersonNum = $detail_jsonResp->orderDetail->adultNum+$detail_jsonResp->orderDetail->childNum; - $this->Orders_model->GRI_Days = intval($date_diff->format('%R%a')+1); - $this->Orders_model->GRI_IsCancel = 0; - $this->Orders_model->DeleteFlag = 0; - $this->Orders_model->GRI_OPI_ID = 435; - $this->Orders_model->GRI_operator = 435; - $this->Orders_model->GRI_Creator = 435; - $groupSN = $this->Orders_model->groupinfo_save(); - /** BIZ_Guest */ - $this->Orders_model->GUT_LastName = $detail_jsonResp->orderDetail->customers[0]->name; - $this->Orders_model->biz_guest_save(); - /** BIZ_ConfirmLineInfo*/ - $this->Orders_model->BIZ_COLI_GRI_SN = $groupSN; - $this->Orders_model->BIZ_COLI_GroupCode = $this->Orders_model->GRI_No; - $this->Orders_model->BIZ_GUT_SN = $this->Orders_model->GUT_SN; - $this->Orders_model->BIZ_COLI_ID = $this->Orders_model->biz_make_order_number(); - $this->Orders_model->BIZ_COLI_ApplyDate = $detail_jsonResp->orderDetail->orderTime; - $this->Orders_model->BIZ_COLI_sourcetype = empty($this->city_info[$detail_jsonResp->orderDetail->operationDep]) ? 32090 : $this->city_info[$detail_jsonResp->orderDetail->operationDep]['COLI_sourcetype']; - $this->Orders_model->BIZ_COLI_State = 9; - $this->Orders_model->BIZ_COLI_servicetype = 'D'; - $this->Orders_model->BIZ_COLI_ConfirmType = 52001; - $this->Orders_model->BIZ_COLI_Memo = ""; - $this->Orders_model->BIZ_COLI_OrderDetailText = "来自图兰朵系统同步" . $detail_jsonResp->orderDetail->orderId . ";线路:" . $detail_jsonResp->orderDetail->routeName . "; 团名: " . $detail_jsonResp->orderDetail->agcOrderNo; - $this->Orders_model->BIZ_COLI_GUT_SN = $this->Orders_model->BIZ_GUT_SN ? $this->Orders_model->BIZ_GUT_SN : null; - $this->Orders_model->BIZ_COLI_OPI_ID = 435; - $this->Orders_model->BIZ_COLI_PayManner = 15006; - $coli_sn = $this->Orders_model->biz_confirm_save(); - $coli_id = $this->Orders_model->BIZ_COLI_ID; - /**BIZ_ConfirmLineDetail*/ - $this->Orders_model->COLD_COLI_SN = $this->Orders_model->BIZ_COLI_SN; - $this->Orders_model->COLD_ServiceType = "D"; - $this->Orders_model->COLD_ServiceSN = $serviceSN->PAG2_PAG_SN; - $this->Orders_model->COLD_ServiceSN2 = $pag_sub; - $this->Orders_model->COLD_ServiceCity = $serviceSN->PAG_CII_SN; - $this->Orders_model->COLD_StartDate = $detail_jsonResp->orderDetail->travelDate; - $this->Orders_model->COLD_EndDate = $detail_jsonResp->orderDetail->leaveDate; - $this->Orders_model->COLD_PersonNum = $detail_jsonResp->orderDetail->adultNum; - $this->Orders_model->COLD_ChildNum = $detail_jsonResp->orderDetail->childNum; - $this->Orders_model->cold_state = 9 - $this->Orders_model->DeleteFlag = 0; - $this->Orders_model->COLD_PlanVEI_SN = $this->city_info[$detail_jsonResp->orderDetail->operationDep]['PlanVEI_SN'] ? $this->city_info[$detail_jsonResp->orderDetail->operationDep]['PlanVEI_SN'] : 1343; - $this->Orders_model->COLD_MemoText = $COLD_MemoText; - $cold_sn = $this->Orders_model->biz_confirm_detail_save(); } - $groupSN = $groupSN ? $groupSN : $getInfo_byGroupCode->GRI_SN; - $coli_sn = $coli_sn ? $coli_sn : $getInfo_byGroupCode->COLI_SN; - $coli_id = $coli_id ? $coli_id : $getInfo_byGroupCode->COLI_ID; - $coli_memo = ($getInfo_byGroupCode!==null) ? $getInfo_byGroupCode->COLI_Memo : ""; - $coli_orderdetailtext = ($getInfo_byGroupCode!==null) ? $getInfo_byGroupCode->COLI_OrderDetailText : ""; - $coli_state = ($getInfo_byGroupCode!==null) ? $getInfo_byGroupCode->COLI_State : 9; - $cold_sn = $cold_sn ? $cold_sn : $getInfo_byGroupCode->COLD_SN; - } else { - // $getInfo_byGroupCode = null; - $getInfo_byGroupCode = $getInfo_byGroupCode[0]; - $groupSN = $order->COLI_GRI_SN; - $coli_sn = $order->COLI_SN; - $coli_id = $order->COLI_ID; - $coli_memo = $order->COLI_Memo; - $coli_orderdetailtext = $order->COLI_OrderDetailText; - $coli_state = $order->COLI_State; - $cold_sn = $order->COLD_SN; } - // if (in_array($order->GCI_FromAgc, array("D目的地桂林组", "Trippest"))) { - // $getInfo_byGroupCode = $this->Orders_model->get_SN_by_groupCode($real_groupCode, $detail_jsonResp->orderDetail->orderId); - // } - /** UPDATE */ - $groupSN = $groupSN ? $groupSN : $order->COLI_GRI_SN; - $coli_sn = $coli_sn ? $coli_sn : $order->COLI_SN; - $coli_id = $coli_id ? $coli_id : $order->COLI_ID; - $coli_memo = isset($getInfo_byGroupCode->COLI_SN) ? $getInfo_byGroupCode->COLI_Memo : $order->COLI_Memo; - $coli_orderdetailtext = isset($getInfo_byGroupCode->COLI_SN) ? $getInfo_byGroupCode->COLI_OrderDetailText : $order->COLI_OrderDetailText; - $coli_state = isset($getInfo_byGroupCode->COLI_SN) ? - (intval($getInfo_byGroupCode->COLI_OPI_ID)===435 ? 9 : $getInfo_byGroupCode->COLI_State) - : 9; - $cold_sn = isset($getInfo_byGroupCode->COLI_SN) ? $getInfo_byGroupCode->COLD_SN : $order->COLD_SN; - // HT 订单有重复时, 以图兰朵的团号为正确的订单, 原本已录入的设为无效 if ($getInfo_byGroupCode === null) { - } elseif ($getInfo_byGroupCode->GRI_SN != $order->COLI_GRI_SN && intval($order->COLI_OPI_ID)===435) { - if ( $order->COLI_ID && $order->COLI_ID != $getInfo_byGroupCode->COLI_ID) { - $allDetails_to_HT .= "\r\n疑似重复,请更新订单状态:" . $order->COLI_ID; - $this->order_cancel($order->COLI_ID); - } - } - /** groupcombineinfo */ - // $this->Order_update->gci_where_update = " GCI_VEI_SN=$vei_SN and GCI_VendorOrderId='" . $detail_jsonResp->orderDetail->orderId . "'"; - $this->Order_update->gci_where_update = " GCI_VendorOrderId='" . $detail_jsonResp->orderDetail->orderId . "'"; - $gci_update_column = array( - "GCI_combineNo" => isset($detail_jsonResp->orderDetail->groupOrderNo) ? $detail_jsonResp->orderDetail->groupOrderNo : null - ,"GCI_VEI_SN" => $vei_SN - ,"GCI_GRI_SN" => $groupSN - ,"GCI_travelDate" => $detail_jsonResp->orderDetail->travelDate - ,"GCI_leaveDate" => $detail_jsonResp->orderDetail->leaveDate - ,"GCI_createTime" => date('Y-m-d H:i:s') - ); - $this->Order_update->biz_groupcombineinfo_update($gci_update_column); - /** GRoupInfo */ - if (intval($order->COLI_OPI_ID) === 435 ) { - $gri_update_column = array( - "GRI_No" => $detail_jsonResp->orderDetail->agcOrderNo - ,"GRI_Name" => $detail_jsonResp->orderDetail->agcOrderNo - ); - $this->Order_update->gri_where_update = " GRI_SN=" . $groupSN; - $this->Order_update->biz_groupinfo_update($gci_update_column); + /** INSERT */ + $order_detail_arr = (array)$detail_jsonResp->orderDetail; + /** GRoupInfo */ + $groupSN = $this->insert_gri($order_detail_arr); + /** BIZ_Guest */ + $this->Orders_model->GUT_LastName = $detail_jsonResp->orderDetail->customers[0]->name; + $this->Orders_model->biz_guest_save(); + /** BIZ_ConfirmLineInfo*/ + $order_detail_arr['orderDate'] = $order_detail_arr['orderTime']; + $coli_sn = $this->insert_coli($order_detail_arr); + $coli_id = $this->Orders_model->BIZ_COLI_ID; + /**BIZ_ConfirmLineDetail*/ + $cold_sn = $this->insert_cold($order_detail_arr); } - /** BIZ_ConfirmLineInfo */ - $this->Order_update->coli_where_update = " COLI_SN=" . $coli_sn; - $old_memo = mb_strstr($coli_memo, " orderRemark", true)!==false ? mb_strstr($coli_memo, " orderRemark", true) : $coli_memo; - $new_memo = trim($detail_jsonResp->orderDetail->orderRemark)=="" ? $old_memo : $old_memo . " orderRemark\r\n" . $detail_jsonResp->orderDetail->orderRemark . "\r\n"; - $old_detail = mb_strstr($coli_orderdetailtext, " operations", true)!==false ? mb_strstr($coli_orderdetailtext, " operations", true) : $coli_orderdetailtext; - $new_detail = trim($allDetails_to_HT)=="" ? $old_detail : $old_detail . " operations\r\n" . $allDetails_to_HT . "\r\n"; - // 团款总金额 美元币种 - $travel_fee = 0; - $travel_fee_currency = 'RMB'; - if (isset($detail_jsonResp->orderDetail->travelFees) ) { - foreach ($detail_jsonResp->orderDetail->travelFees as $ktf => $vtf) { - $travel_fee = bcadd($travel_fee, $vtf->sumMoney); - } - unset($vtf); + $groupSN = isset($groupSN) ? $groupSN : $getInfo_byGroupCode->GRI_SN; + $coli_sn = isset($coli_sn) ? $coli_sn : $getInfo_byGroupCode->COLI_SN; + $coli_id = isset($coli_id) ? $coli_id : $getInfo_byGroupCode->COLI_ID; + $cold_sn = isset($cold_sn) ? $cold_sn : $getInfo_byGroupCode->COLD_SN; + $coli_opi_id = 435; + $coli_memo = ($getInfo_byGroupCode !== null) ? $getInfo_byGroupCode->COLI_Memo : ""; + $coli_state = ($getInfo_byGroupCode !== null) ? $getInfo_byGroupCode->COLI_State : 9; + $coli_orderdetailtext = ($getInfo_byGroupCode !== null) ? $getInfo_byGroupCode->COLI_OrderDetailText : ""; + } else { + // 已找到的目的地发的计划 + // $getInfo_byGroupCode = $order; + $getInfo_byGroupCode = $getInfo_byGroupCode[0]; + $groupSN = $order->COLI_GRI_SN; + $coli_sn = $order->COLI_SN; + $coli_id = $order->COLI_ID; + $coli_memo = $order->COLI_Memo; + $coli_state = $order->COLI_State; + $cold_sn = $order->COLD_SN; // ???多个子订单 !!!仅用于435创建的订单的更新, 因此仅一个 + $coli_opi_id = $order->COLI_OPI_ID; + $coli_orderdetailtext = $order->COLI_OrderDetailText; + } + /** UPDATE */ + // HT 订单有重复时, 以图兰朵的团号为正确的订单, 原本已录入的设为无效 + if ($duplicate === true) { + if ( $order->COLI_ID && $order->COLI_ID != $getInfo_byGroupCode->COLI_ID) { + $allDetails_to_HT .= "\r\n疑似重复,请更新订单状态:" . $order->COLI_ID; + $this->order_cancel($order->COLI_ID); } - $travel_fee = isset($getInfo_byGroupCode->COLI_SN) ? - (intval($getInfo_byGroupCode->COLI_OPI_ID)===435 ? $travel_fee : $getInfo_byGroupCode->COLI_Price) - : $travel_fee; - $travel_fee_currency = isset($getInfo_byGroupCode->COLI_SN) ? - (intval($getInfo_byGroupCode->COLI_OPI_ID)===435 ? $travel_fee_currency : $getInfo_byGroupCode->COLI_CUrrency) - : $travel_fee_currency; - $coli_update_column = array( - "COLI_Memo" => substr($new_memo, 0, 400) - ,"COLI_OrderDetailText" => $new_detail - ,"COLI_State" => $coli_state - ,"COLI_Price" => $travel_fee - ,"COLI_CUrrency" => $travel_fee_currency - ,"COLI_GroupCode" => $detail_jsonResp->orderDetail->agcOrderNo + } + /** groupcombineinfo */ + $this->Order_update->gci_where_update = " GCI_VendorOrderId='" . $detail_jsonResp->orderDetail->orderId . "' and GCI_VEI_SN in (" . implode(',', $this->vendor_ids) . ")"; // 不明确指定供应商id,出现过不对应的情况 + $gci_update_column = array( + "GCI_combineNo" => isset($detail_jsonResp->orderDetail->groupOrderNo) ? $detail_jsonResp->orderDetail->groupOrderNo : null + ,"GCI_VEI_SN" => $vei_SN + ,"GCI_GRI_SN" => $groupSN + ,"GCI_travelDate" => $detail_jsonResp->orderDetail->travelDate + ,"GCI_leaveDate" => $detail_jsonResp->orderDetail->leaveDate + ,"GCI_createTime" => date('Y-m-d H:i:s') + ); + $this->Order_update->biz_groupcombineinfo_update($gci_update_column); + /** GRoupInfo */ + if (intval($order->COLI_OPI_ID) === 435 ) { + $gri_update_column = array( + "GRI_No" => $detail_jsonResp->orderDetail->agcOrderNo + ,"GRI_Name" => $detail_jsonResp->orderDetail->agcOrderNo ); - $this->Order_update->biz_confirmlineinfo_update($coli_update_column); - /** BIZ_ConfirmLineDetail */ - if (intval($order->COLI_OPI_ID) === 435) { - $cold_update_column = array( - "COLD_PersonNum" => $detail_jsonResp->orderDetail->adultNum - ,"COLD_ChildNum" => $detail_jsonResp->orderDetail->childNum - ); - $this->Order_update->cold_where_update = " COLD_SN=" . $getInfo_byGroupCode->COLD_SN; - $this->Order_update->biz_confirmlinedetail_update($cold_update_column); + $this->Order_update->gri_where_update = " GRI_SN=" . $groupSN; + $this->Order_update->biz_groupinfo_update($gri_update_column); + } + /** BIZ_ConfirmLineInfo */ + $this->Order_update->coli_where_update = " COLI_SN=" . $coli_sn; + $old_memo = mb_strstr($coli_memo, " orderRemark", true)!==false ? mb_strstr($coli_memo, " orderRemark", true) : $coli_memo; + $new_memo = trim($detail_jsonResp->orderDetail->orderRemark)=="" ? $old_memo : $old_memo . " orderRemark\r\n" . $detail_jsonResp->orderDetail->orderRemark . "\r\n"; + $old_detail = mb_strstr($coli_orderdetailtext, " operations", true)!==false ? mb_strstr($coli_orderdetailtext, " operations", true) : $coli_orderdetailtext; + $new_detail = trim($allDetails_to_HT)=="" ? $old_detail : $old_detail . " operations\r\n" . $allDetails_to_HT . "\r\n"; + // 团款总金额 + $travel_fee = 0; + $travel_fee_currency = 'RMB'; + if (isset($detail_jsonResp->orderDetail->travelFees) ) { + foreach ($detail_jsonResp->orderDetail->travelFees as $ktf => $vtf) { + $travel_fee = bcadd($travel_fee, $vtf->sumMoney); } + unset($vtf); + } + $travel_fee = intval($coli_opi_id)===435 ? $travel_fee : $getInfo_byGroupCode->COLI_Price; + $travel_fee_currency = intval($coli_opi_id)===435 ? $travel_fee_currency : $getInfo_byGroupCode->COLI_CUrrency; + $coli_update_column = array( + "COLI_Memo" => substr($new_memo, 0, 400) + ,"COLI_OrderDetailText" => $new_detail + ,"COLI_State" => $coli_state + ,"COLI_Price" => $travel_fee + ,"COLI_CUrrency" => $travel_fee_currency + ,"COLI_GroupCode" => mb_substr($detail_jsonResp->orderDetail->agcOrderNo, 0, 49) + ); + $this->Order_update->biz_confirmlineinfo_update($coli_update_column); + /** + * update BIZ_ConfirmLineDetail + * insert BIZ_BookPeople,BIZ_PackageOrderInfo + */ + if (intval($coli_opi_id) === 435) { + /** BIZ_ConfirmLineDetail */ + $pag_info = $this->analysis_productcode($detail_jsonResp->orderDetail->routeName, $detail_jsonResp->orderDetail->orderId); + $cold_update_column = array( + "COLD_PersonNum" => $detail_jsonResp->orderDetail->adultNum + ,"COLD_ChildNum" => $detail_jsonResp->orderDetail->childNum + ,"COLD_ServiceSN" => $pag_info->serviceinfo->PAG2_PAG_SN + ,"COLD_ServiceSN2" => $pag_info->pag_sub + ,"COLD_ServiceCity" => $pag_info->serviceinfo->PAG_CII_SN + ); + $this->Order_update->cold_where_update = " COLD_SN=" . $cold_sn; + $this->Order_update->biz_confirmlinedetail_update($cold_update_column); /** INSERT */ /*BIZ_BookPeople*/ if ($this->Orders_model->bookpeople_exist($cold_sn) === array()) { @@ -540,227 +394,185 @@ class TulanduoApi extends CI_Controller $this->Orders_model->POI_EndTime = $detail_jsonResp->orderDetail->leaveDate; $this->Orders_model->POI_QuotationType = 1; // 1 报价 2 网络支付价 3 促销价 $this->Orders_model->biz_packageorder_save(); - /** BIZ_GroupAccountInfo */ - // 团款, 只有其他社的订单, 目的地项目组的团款已经直接收入海纳账户 - $paytype = 15006; // 地接代收 - $pay_currency = 'RMB'; - $auto_text = "dataAutoEnter "; - // query latest order detail - $latest_order_detail = $this->Orders_model->get_orderinfo_detail($coli_id); - // 删除旧的录入 - $this->Orders_model->biz_groupaccountinfo_cut($coli_sn, $paytype); - if (isset($detail_jsonResp->orderDetail->travelFees) && intval($latest_order_detail[0]->COLI_OPI_ID===435) ) { + } + // query latest order detail + $latest_order_detail = $this->Orders_model->get_orderinfo_detail($coli_id); + /** BIZ_GroupAccountInfo */ + // 团款, 只有其他社的订单, 目的地项目组的团款已经直接收入海纳账户 + $paytype = 15006; // 地接代收 + $pay_currency = 'RMB'; + $auto_text = "dataAutoEnter "; + // 删除旧的录入 + $this->Orders_model->biz_groupaccountinfo_cut($coli_sn, $paytype); + if (intval($latest_order_detail[0]->COLI_OPI_ID)===435) { + // 团款 + if (isset($detail_jsonResp->orderDetail->travelFees) ) { foreach ($detail_jsonResp->orderDetail->travelFees as $ktf => $vtf) { - // if ($vtf->reviewStatus == 0) { // 未审核的 - // continue; - // } - $this->Orders_model->GAI_Operator = 435; - $this->Orders_model->GAI_COLI_SN = $coli_sn; - $this->Orders_model->GAI_GRI_SN = $groupSN; - $this->Orders_model->GAI_COLI_ID = $coli_id; - $this->Orders_model->GAI_Type = $paytype; - $this->Orders_model->GAI_SQJE = $vtf->sumMoney; - $this->Orders_model->GAI_SQJECurrency = $pay_currency; - $this->Orders_model->GAI_SSJE = $vtf->sumMoney; - $this->Orders_model->GAI_SSDate = date("Y-m-d H:i:s"); - $this->Orders_model->GAI_Memo = $auto_text . "团款" . $vtf->type . ", " . $vtf->remark; - $this->Orders_model->biz_groupaccountinfo_save(); + $this->insert_gai($coli_sn, $groupSN, $coli_id, $paytype, $pay_currency, $vtf->sumMoney, $vtf->sumMoney, $auto_text . "代收" . $vtf->type . ", " . $vtf->remark); } } - // 目的地项目组的订单为了避免重复录入, 外联会沟通录入, 这里不写入. todo + // 目的地项目组的订单为了避免重复录入, 外联会沟通录入, 这里不写入. // 代收 - if (isset($detail_jsonResp->orderDetail->replaceCollections) && intval($latest_order_detail[0]->COLI_OPI_ID===435) ) { + if (isset($detail_jsonResp->orderDetail->replaceCollections) ) { foreach ($detail_jsonResp->orderDetail->replaceCollections as $krc => $vrc) { - // if ($vrc->reviewStatus == 0) { - // continue; - // } - $this->Orders_model->GAI_Operator = 435; - $this->Orders_model->GAI_COLI_SN = $coli_sn; - $this->Orders_model->GAI_GRI_SN = $groupSN; - $this->Orders_model->GAI_COLI_ID = $coli_id; - $this->Orders_model->GAI_Type = $paytype; - $this->Orders_model->GAI_SQJE = $vrc->money; - $this->Orders_model->GAI_SQJECurrency = $pay_currency; - $this->Orders_model->GAI_SSJE = $vrc->money; - $this->Orders_model->GAI_SSDate = date("Y-m-d H:i:s"); - $this->Orders_model->GAI_Memo = $auto_text . "代收" . $vrc->type . ", " . $vrc->remark; - $this->Orders_model->biz_groupaccountinfo_save(); + $this->insert_gai($coli_sn, $groupSN, $coli_id, $paytype, $pay_currency, $vrc->money, $vrc->money, $auto_text . "代收" . $vrc->type . ", " . $vrc->remark); } } - if (isset($detail_jsonResp->orderDetail->operationDetails->otherReceives) && intval($latest_order_detail[0]->COLI_OPI_ID===435) ) { + if (isset($detail_jsonResp->orderDetail->operationDetails->otherReceives) ) { foreach ($detail_jsonResp->orderDetail->operationDetails->otherReceives as $koor => $voor) { - $this->Orders_model->GAI_Operator = 435; - $this->Orders_model->GAI_COLI_SN = $coli_sn; - $this->Orders_model->GAI_GRI_SN = $groupSN; - $this->Orders_model->GAI_COLI_ID = $coli_id; - $this->Orders_model->GAI_Type = $paytype; - $this->Orders_model->GAI_SQJE = $voor->sumMoney; - $this->Orders_model->GAI_SQJECurrency = $pay_currency; - $this->Orders_model->GAI_SSJE = $voor->sumMoney; - $this->Orders_model->GAI_SSDate = date("Y-m-d H:i:s"); - $this->Orders_model->GAI_Memo = $auto_text . "代收" . $voor->type . ", " . $voor->remark; - $this->Orders_model->biz_groupaccountinfo_save(); + $this->insert_gai($coli_sn, $groupSN, $coli_id, $paytype, $pay_currency, $voor->sumMoney, $voor->sumMoney, $auto_text . "代收" . $voor->type . ", " . $voor->remark); } } // 代付 - if (isset($detail_jsonResp->orderDetail->replacePays) && intval($latest_order_detail[0]->COLI_OPI_ID===435) ) { + if (isset($detail_jsonResp->orderDetail->replacePays) ) { foreach ($detail_jsonResp->orderDetail->replacePays as $krp => $vrp) { - // if ($vrp->reviewStatus == 0) { - // continue; - // } - $this->Orders_model->GAI_Operator = 435; - $this->Orders_model->GAI_COLI_SN = $coli_sn; - $this->Orders_model->GAI_GRI_SN = $groupSN; - $this->Orders_model->GAI_COLI_ID = $coli_id; - $this->Orders_model->GAI_Type = $paytype; - $this->Orders_model->GAI_SQJE = "-" . $vrp->money; - $this->Orders_model->GAI_SQJECurrency = $pay_currency; - $this->Orders_model->GAI_SSJE = $vrp->money; - $this->Orders_model->GAI_SSDate = date("Y-m-d H:i:s"); - $this->Orders_model->GAI_Memo = $auto_text . $vrp->type . ", " . $vrp->remark; - $this->Orders_model->biz_groupaccountinfo_save(); + $GAI_SQJE = "-" . $vrp->money; + $GAI_SSJE = "-" . $vrp->money; + $GAI_Memo = $auto_text . $vrp->type . ", " . $vrp->remark; + $this->insert_gai($coli_sn, $groupSN, $coli_id, $paytype, $pay_currency, $GAI_SQJE, $GAI_SSJE, $GAI_Memo); } } - /*BIZ_GroupCombineOperationDetail*/ - if ( ! isset($detail_jsonResp->orderDetail->groupOrderNo)) { // 没有拼团团号 - continue; - } - if (in_array($detail_jsonResp->orderDetail->groupOrderNo, $unique_orderGroupCombine)) { - continue; - } - $unique_orderGroupCombine[] = $detail_jsonResp->orderDetail->groupOrderNo; - // 删除旧的录入 - $this->Orders_model->biz_groupcombineoperationdetail_cut($detail_jsonResp->orderDetail->groupOrderNo); - // 门票 - if (isset($detail_jsonResp->orderDetail->operationDetails->sceneryOperations)) { - foreach ($detail_jsonResp->orderDetail->operationDetails->sceneryOperations as $ks => $vso) { - $this->Orders_model->GCOD_GCI_combineNo = $detail_jsonResp->orderDetail->groupOrderNo; - $this->Orders_model->GCOD_VEI_SN = $vei_SN; - $this->Orders_model->GCOD_operationType = "sceneryOperations"; - $this->Orders_model->GCOD_subType = $vso->type; - $this->Orders_model->GCOD_title = $vso->name; - $this->Orders_model->GCOD_startDate = $vso->useDate; - $this->Orders_model->GCOD_endDate = $vso->useDate; - $this->Orders_model->GCOD_useNum = $vso->useNum; - $this->Orders_model->GCOD_sumMoney = $vso->sumMoney; - $this->Orders_model->GCOD_remark = $vso->remark; - $this->Orders_model->GCOD_dutyName = ""; - $this->Orders_model->GCOD_dutyTel = null; - $this->Orders_model->GCOD_dutyPhoto = null; - $this->Orders_model->GCOD_standard = ""; - $this->Orders_model->GCOD_carLicense = ""; - $this->Orders_model->biz_groupcombineoperationdetail_save(); - } + } + /*BIZ_GroupCombineOperationDetail*/ + if ( ! isset($detail_jsonResp->orderDetail->groupOrderNo)) { // 没有拼团团号 + continue; + } + if (in_array($detail_jsonResp->orderDetail->groupOrderNo, $unique_orderGroupCombine)) { + continue; + } + $unique_orderGroupCombine[] = $detail_jsonResp->orderDetail->groupOrderNo; + // 删除旧的录入 + $this->Orders_model->biz_groupcombineoperationdetail_cut($detail_jsonResp->orderDetail->groupOrderNo); + // 门票 + if (isset($detail_jsonResp->orderDetail->operationDetails->sceneryOperations)) { + foreach ($detail_jsonResp->orderDetail->operationDetails->sceneryOperations as $ks => $vso) { + $this->Orders_model->GCOD_GCI_combineNo = $detail_jsonResp->orderDetail->groupOrderNo; + $this->Orders_model->GCOD_VEI_SN = $vei_SN; + $this->Orders_model->GCOD_operationType = "sceneryOperations"; + $this->Orders_model->GCOD_subType = $vso->type; + $this->Orders_model->GCOD_title = $vso->name; + $this->Orders_model->GCOD_startDate = $vso->useDate; + $this->Orders_model->GCOD_endDate = $vso->useDate; + $this->Orders_model->GCOD_useNum = $vso->useNum; + $this->Orders_model->GCOD_sumMoney = $vso->sumMoney; + $this->Orders_model->GCOD_remark = $vso->remark; + $this->Orders_model->GCOD_dutyName = ""; + $this->Orders_model->GCOD_dutyTel = null; + $this->Orders_model->GCOD_dutyPhoto = null; + $this->Orders_model->GCOD_standard = ""; + $this->Orders_model->GCOD_carLicense = ""; + $this->Orders_model->biz_groupcombineoperationdetail_save(); } - // 用房 ... - // 用餐 - if (isset($detail_jsonResp->orderDetail->operationDetails->restraurantOperations) ) { - foreach ($detail_jsonResp->orderDetail->operationDetails->restraurantOperations as $vro) { - $this->Orders_model->GCOD_GCI_combineNo = $detail_jsonResp->orderDetail->groupOrderNo ; - $this->Orders_model->GCOD_VEI_SN = $vei_SN; - $this->Orders_model->GCOD_operationType = "restraurantOperations"; - $this->Orders_model->GCOD_subType = $vro->type; - $this->Orders_model->GCOD_title = $vro->name; - $this->Orders_model->GCOD_startDate = $vro->useDate; - $this->Orders_model->GCOD_endDate = $vro->useDate; - $this->Orders_model->GCOD_useNum = $vro->useNum; - $this->Orders_model->GCOD_sumMoney = $vro->sumMoney; - $this->Orders_model->GCOD_standard = $vro->standard; - $this->Orders_model->GCOD_remark = $vro->remark; - $this->Orders_model->GCOD_dutyName = ""; - $this->Orders_model->GCOD_dutyTel = null; - $this->Orders_model->GCOD_dutyPhoto = null; - $this->Orders_model->GCOD_carLicense = ""; - $this->Orders_model->biz_groupcombineoperationdetail_save(); - } + } + // 用房 ... + // 用餐 + if (isset($detail_jsonResp->orderDetail->operationDetails->restraurantOperations) ) { + foreach ($detail_jsonResp->orderDetail->operationDetails->restraurantOperations as $vro) { + $this->Orders_model->GCOD_GCI_combineNo = $detail_jsonResp->orderDetail->groupOrderNo ; + $this->Orders_model->GCOD_VEI_SN = $vei_SN; + $this->Orders_model->GCOD_operationType = "restraurantOperations"; + $this->Orders_model->GCOD_subType = $vro->type; + $this->Orders_model->GCOD_title = $vro->name; + $this->Orders_model->GCOD_startDate = $vro->useDate; + $this->Orders_model->GCOD_endDate = $vro->useDate; + $this->Orders_model->GCOD_useNum = $vro->useNum; + $this->Orders_model->GCOD_sumMoney = $vro->sumMoney; + $this->Orders_model->GCOD_standard = $vro->standard; + $this->Orders_model->GCOD_remark = $vro->remark; + $this->Orders_model->GCOD_dutyName = ""; + $this->Orders_model->GCOD_dutyTel = null; + $this->Orders_model->GCOD_dutyPhoto = null; + $this->Orders_model->GCOD_carLicense = ""; + $this->Orders_model->biz_groupcombineoperationdetail_save(); } - // 用车 - if (isset($detail_jsonResp->orderDetail->operationDetails->touristCarOperations)) { - foreach ($detail_jsonResp->orderDetail->operationDetails->touristCarOperations as $vco) { - $this->Orders_model->GCOD_GCI_combineNo = $detail_jsonResp->orderDetail->groupOrderNo ; - $this->Orders_model->GCOD_VEI_SN = $vei_SN; - $this->Orders_model->GCOD_operationType = "touristCarOperations"; - $this->Orders_model->GCOD_subType = $vco->type; - $this->Orders_model->GCOD_title = $vco->name; - $this->Orders_model->GCOD_dutyName = $vco->driver; - $this->Orders_model->GCOD_dutyTel = $vco->driverTel; - $this->Orders_model->GCOD_startDate = $vco->startDate; - $this->Orders_model->GCOD_endDate = $vco->endDate; - $this->Orders_model->GCOD_sumMoney = $vco->sumMoney; - $this->Orders_model->GCOD_carLicense = $vco->carLicense; - $this->Orders_model->GCOD_useNum = 1; - $this->Orders_model->GCOD_standard = ""; - $this->Orders_model->GCOD_dutyPhoto = null; - $this->Orders_model->GCOD_remark = $vco->remark; - $this->Orders_model->biz_groupcombineoperationdetail_save(); - } + } + // 用车 + if (isset($detail_jsonResp->orderDetail->operationDetails->touristCarOperations)) { + foreach ($detail_jsonResp->orderDetail->operationDetails->touristCarOperations as $vco) { + $this->Orders_model->GCOD_GCI_combineNo = $detail_jsonResp->orderDetail->groupOrderNo ; + $this->Orders_model->GCOD_VEI_SN = $vei_SN; + $this->Orders_model->GCOD_operationType = "touristCarOperations"; + $this->Orders_model->GCOD_subType = $vco->type; + $this->Orders_model->GCOD_title = $vco->name; + $this->Orders_model->GCOD_dutyName = $vco->driver; + $this->Orders_model->GCOD_dutyTel = $vco->driverTel; + $this->Orders_model->GCOD_startDate = $vco->startDate; + $this->Orders_model->GCOD_endDate = $vco->endDate; + $this->Orders_model->GCOD_sumMoney = $vco->sumMoney; + $this->Orders_model->GCOD_carLicense = $vco->carLicense; + $this->Orders_model->GCOD_useNum = 1; + $this->Orders_model->GCOD_standard = ""; + $this->Orders_model->GCOD_dutyPhoto = null; + $this->Orders_model->GCOD_remark = $vco->remark; + $this->Orders_model->biz_groupcombineoperationdetail_save(); } - // 导游服务 - if (isset($detail_jsonResp->orderDetail->operationDetails->guiderOperations) ) { - foreach ($detail_jsonResp->orderDetail->operationDetails->guiderOperations as $vgo) { - $this->Orders_model->GCOD_GCI_combineNo = $detail_jsonResp->orderDetail->groupOrderNo ; - $this->Orders_model->GCOD_VEI_SN = $vei_SN; - $this->Orders_model->GCOD_operationType = "guiderOperations"; - $this->Orders_model->GCOD_subType = ""; - $this->Orders_model->GCOD_title = ""; - $this->Orders_model->GCOD_dutyName = $vgo->name; - $this->Orders_model->GCOD_dutyTel = $vgo->mobelPhone; - $this->Orders_model->GCOD_dutyPhoto = isset($vgo->guiderPhoto) ? $vgo->guiderPhoto : ''; - $this->Orders_model->GCOD_startDate = $vgo->startDate; - $this->Orders_model->GCOD_endDate = $vgo->endDate; - $this->Orders_model->GCOD_sumMoney = $vgo->sumMoney; - $this->Orders_model->GCOD_carLicense = ""; - $this->Orders_model->GCOD_standard = ""; - $this->Orders_model->GCOD_remark = $vgo->remark; - $this->Orders_model->GCOD_useNum = 1; - $this->Orders_model->biz_groupcombineoperationdetail_save(); - } + } + // 导游服务 + if (isset($detail_jsonResp->orderDetail->operationDetails->guiderOperations) ) { + foreach ($detail_jsonResp->orderDetail->operationDetails->guiderOperations as $vgo) { + $this->Orders_model->GCOD_GCI_combineNo = $detail_jsonResp->orderDetail->groupOrderNo ; + $this->Orders_model->GCOD_VEI_SN = $vei_SN; + $this->Orders_model->GCOD_operationType = "guiderOperations"; + $this->Orders_model->GCOD_subType = ""; + $this->Orders_model->GCOD_title = ""; + $this->Orders_model->GCOD_dutyName = $vgo->name; + $this->Orders_model->GCOD_dutyTel = $vgo->mobelPhone; + $this->Orders_model->GCOD_dutyPhoto = isset($vgo->guiderPhoto) ? $vgo->guiderPhoto : ''; + $this->Orders_model->GCOD_startDate = $vgo->startDate; + $this->Orders_model->GCOD_endDate = $vgo->endDate; + $this->Orders_model->GCOD_sumMoney = $vgo->sumMoney; + $this->Orders_model->GCOD_carLicense = ""; + $this->Orders_model->GCOD_standard = ""; + $this->Orders_model->GCOD_remark = $vgo->remark; + $this->Orders_model->GCOD_useNum = 1; + $this->Orders_model->biz_groupcombineoperationdetail_save(); } - // 其他支出 - if (isset($detail_jsonResp->orderDetail->operationDetails->otherCosts) ) { - foreach ($detail_jsonResp->orderDetail->operationDetails->otherCosts as $voc) { - $this->Orders_model->GCOD_GCI_combineNo = $detail_jsonResp->orderDetail->groupOrderNo ; - $this->Orders_model->GCOD_VEI_SN = $vei_SN; - $this->Orders_model->GCOD_operationType = "otherCosts"; - $this->Orders_model->GCOD_subType = $voc->type; - $this->Orders_model->GCOD_title = ""; - $this->Orders_model->GCOD_dutyName = ""; - $this->Orders_model->GCOD_dutyTel = ""; - $this->Orders_model->GCOD_dutyPhoto = ''; - $this->Orders_model->GCOD_startDate = ""; - $this->Orders_model->GCOD_endDate = ""; - $this->Orders_model->GCOD_sumMoney = $voc->sumMoney; - $this->Orders_model->GCOD_carLicense = ""; - $this->Orders_model->GCOD_standard = ""; - $this->Orders_model->GCOD_remark = $voc->remark; - $this->Orders_model->GCOD_useNum = $voc->useNum; - $this->Orders_model->biz_groupcombineoperationdetail_save(); - } + } + // 其他支出 + if (isset($detail_jsonResp->orderDetail->operationDetails->otherCosts) ) { + foreach ($detail_jsonResp->orderDetail->operationDetails->otherCosts as $voc) { + $this->Orders_model->GCOD_GCI_combineNo = $detail_jsonResp->orderDetail->groupOrderNo ; + $this->Orders_model->GCOD_VEI_SN = $vei_SN; + $this->Orders_model->GCOD_operationType = "otherCosts"; + $this->Orders_model->GCOD_subType = $voc->type; + $this->Orders_model->GCOD_title = ""; + $this->Orders_model->GCOD_dutyName = ""; + $this->Orders_model->GCOD_dutyTel = ""; + $this->Orders_model->GCOD_dutyPhoto = ''; + $this->Orders_model->GCOD_startDate = ""; + $this->Orders_model->GCOD_endDate = ""; + $this->Orders_model->GCOD_sumMoney = $voc->sumMoney; + $this->Orders_model->GCOD_carLicense = ""; + $this->Orders_model->GCOD_standard = ""; + $this->Orders_model->GCOD_remark = $voc->remark; + $this->Orders_model->GCOD_useNum = $voc->useNum; + $this->Orders_model->biz_groupcombineoperationdetail_save(); } - // 其他收入 - if (isset($detail_jsonResp->orderDetail->operationDetails->otherReceives) ) { - foreach ($detail_jsonResp->orderDetail->operationDetails->otherReceives as $vor) { - $this->Orders_model->GCOD_GCI_combineNo = $detail_jsonResp->orderDetail->groupOrderNo ; - $this->Orders_model->GCOD_VEI_SN = $vei_SN; - $this->Orders_model->GCOD_operationType = "otherReceives"; - $this->Orders_model->GCOD_subType = $vor->type; - $this->Orders_model->GCOD_title = ""; - $this->Orders_model->GCOD_dutyName = ""; - $this->Orders_model->GCOD_dutyTel = ""; - $this->Orders_model->GCOD_dutyPhoto = ''; - $this->Orders_model->GCOD_startDate = ""; - $this->Orders_model->GCOD_endDate = ""; - $this->Orders_model->GCOD_sumMoney = $vor->sumMoney; - $this->Orders_model->GCOD_carLicense = ""; - $this->Orders_model->GCOD_standard = ""; - $this->Orders_model->GCOD_remark = $vor->remark; - $this->Orders_model->GCOD_useNum = $vor->useNum; - $this->Orders_model->biz_groupcombineoperationdetail_save(); - } + } + // 其他收入 + if (isset($detail_jsonResp->orderDetail->operationDetails->otherReceives) ) { + foreach ($detail_jsonResp->orderDetail->operationDetails->otherReceives as $vor) { + $this->Orders_model->GCOD_GCI_combineNo = $detail_jsonResp->orderDetail->groupOrderNo ; + $this->Orders_model->GCOD_VEI_SN = $vei_SN; + $this->Orders_model->GCOD_operationType = "otherReceives"; + $this->Orders_model->GCOD_subType = $vor->type; + $this->Orders_model->GCOD_title = ""; + $this->Orders_model->GCOD_dutyName = ""; + $this->Orders_model->GCOD_dutyTel = ""; + $this->Orders_model->GCOD_dutyPhoto = ''; + $this->Orders_model->GCOD_startDate = ""; + $this->Orders_model->GCOD_endDate = ""; + $this->Orders_model->GCOD_sumMoney = $vor->sumMoney; + $this->Orders_model->GCOD_carLicense = ""; + $this->Orders_model->GCOD_standard = ""; + $this->Orders_model->GCOD_remark = $vor->remark; + $this->Orders_model->GCOD_useNum = $vor->useNum; + $this->Orders_model->biz_groupcombineoperationdetail_save(); } - } // end foreach order - log_message('error',"Got order operations from TuLanDuo, count: " . count($cnt)); - echo "Got order operations from TuLanDuo, count: " . count($cnt); + } + $output_text = "Got order operations from TuLanDuo:" . $detail_jsonResp->orderDetail->orderId . ". " . $coli_id; + log_message('error', $output_text); + echo $output_text; return; } @@ -768,11 +580,19 @@ class TulanduoApi extends CI_Controller * 往前获取历史数据 * @date 2018-08-21 */ + public $date_roll = 0; public function get_history_order_list($oldest_date=null) { + // 避免执行超时, 滚动3次之后结束 + if ($this->date_roll > 2) { + log_message('error', "Got order list from TuLanDuo. Roll end. " . $oldest_date); + return false; + } + $this->date_roll ++; $this->load->model('Tulanduo_sync_model', 'sync_model'); - // $oldest_date===null ? $oldest_date = $this->Orders_model->get_oldest_offset() : null; - $oldest_date===null ? $oldest_date = '2018-05-10' : null; // test + $oldest_date===null ? $oldest_date = $this->sync_model->get_oldest_offset() : null; + // $oldest_date===null ? $oldest_date = '2018-05-10' : null; // test + // $oldest_date===null ? $oldest_date = '2018-04-28' : null; // test $startTravelDate = date('Y-m-d', strtotime("-1 day", strtotime($oldest_date))); $endTravelDate = $oldest_date; $start_date = $this->input->get_post("start"); @@ -785,8 +605,6 @@ class TulanduoApi extends CI_Controller ->setPageIndex(1) ->setStartTravelDate($startTravelDate) ->setEndTravelDate($endTravelDate) ; - var_export($startTravelDate); - var_export($endTravelDate); $resp = $this->excute_curl($this->list_url, $this->tld_order); $resp_arr = json_decode($resp, true); if (intval($resp_arr['status']) !== 1) { @@ -811,57 +629,169 @@ class TulanduoApi extends CI_Controller } $all_vendor_order_id = array_column($all_list, 'orderId'); $all_vendor_order_id_str = implode(',', $all_vendor_order_id); - $exists_ht = $this->Orders_model->get_exists_vendorOrderId($all_vendor_order_id_str); + $exists_ht = $this->sync_model->get_exists_vendorOrderId($all_vendor_order_id_str); $exists_ht_order_id = array_map(function($ele){ return intval($ele->GCI_VendorOrderId);}, $exists_ht); $to_insert = array_diff($all_vendor_order_id, $exists_ht_order_id); - if (empty($to_insert) || count($to_insert)==1) { + // if (empty($to_insert)) { + if (empty($to_insert) || count($to_insert)==1) { // test // 继续往前滚日期 return $this->get_history_order_list($startTravelDate); } + $cnt = 0; foreach ($all_list as $k => $vo) { - if ( ! in_array($value['orderId'], $to_insert)) { + if ( ! in_array($vo['orderId'], $to_insert)) { continue; } - $vo['agcOrderNo'] = mb_ereg_replace('( )', '', trim($vo['agcOrderNo'])); // 去掉中文的全角空格 - // 解析产品编号 - $PAG_Code = $pag_sub = null; - preg_match('/[a-zA-Z]+\-[0-9\-]+/', $this->characet($vo['routeName'], "UTF-8"), $temp_array); - if (empty($temp_array) && isset($pag_no_tmp[$vo['routeName']])) { - $PAG_Code = $pag_no_tmp[$vo['routeName']]; - $split_code = explode("-", $PAG_Code); - $PAG_Code = $split_code[0] . "-" . $split_code[1]; - isset($split_code[2]) ? $pag_sub=$split_code[2] : null; - } else if ( ! empty($temp_array)) { - $PAG_Code = $pag_sub = null; - $split_code = explode("-", $temp_array[0]); - $PAG_Code = $split_code[0] . "-" . $split_code[1]; - isset($split_code[2]) ? $pag_sub=$split_code[2] : null; - } else { - log_message('error',"未识别的线路名称 $PAG_Code " . $vo['orderId'] . " " . $vo['routeName'] . var_export($temp_array, 1)); - } - $PAG_Code = in_array($PAG_Code, array("SHALC-6","SHALC-7","SHALC-8","SHALC-9")) ? "SHSIC-45" : $PAG_Code; - $serviceSN = $this->Orders_model->get_packageSN($PAG_Code); - $COLD_MemoText = raw_json_encode(array("Pick up"=>$vo['toTraffic'], "Drop off"=>$vo['backTraffic'])); + $vo['agcOrderNo'] = trim_groupCode(trim($vo['agcOrderNo'])); // 去掉中文的全角空格 $tmpv = $this->city_info[$vo['operationDep']]['PlanVEI_SN'] ? $this->city_info[$vo['operationDep']]['PlanVEI_SN'] : 1343; + $this->Orders_model->BIZ_COLI_SN = null; + $this->Orders_model->GRI_SN = null; // if (in_array($vo['agcName'], array("D目的地桂林组", "Trippest"))) { $real_groupCode = analysis_groupCode($vo['agcOrderNo']); // check BIZ_COLI_SN,GRI_SN $this->Orders_model->get_SN_by_groupCode($real_groupCode, $vo['orderId']); // } /** INSERT */ - /** biz_groupcombineinfo*/ - $this->Orders_model->GCI_combineNo = isset($vo['groupOrderNo']) ? $vo['groupOrderNo'] : ''; - $this->Orders_model->GCI_GRI_SN = $this->sync_model->GRI_SN; - $this->Orders_model->GCI_VEI_SN = $this->city_info[$vo['operationDep']]['PlanVEI_SN'] ? $this->city_info[$vo['operationDep']]['PlanVEI_SN'] : 1343; - $this->Orders_model->GCI_VendorOrderId = $vo['orderId']; - $this->Orders_model->GCI_FromAgc = $vo['agcName']; - $this->Orders_model->GCI_groupType = $vo['orderType']; - $this->Orders_model->GCI_travelDate = $vo['travelDate']; - $this->Orders_model->GCI_leaveDate = $vo['leaveDate']; - $this->Orders_model->GCI_createTime = date('Y-m-d H:i:s'); - $this->Orders_model->biz_groupcombineinfo_save(); + /** GRoupInfo */ + if ($this->Orders_model->GRI_SN === null) { + $this->insert_gri($vo); + } + if ($this->Orders_model->BIZ_COLI_SN === null) { + /** BIZ_Guest */ + $this->Orders_model->GUT_LastName = $vo['customerName']; + $this->Orders_model->biz_guest_save(); + /** BIZ_ConfirmLineInfo */ + $this->insert_coli($vo); + /** BIZ_ConfirmLineDetail */ + $this->insert_cold($vo); + $cnt++; + } + /** biz_groupcombineinfo */ + $this->insert_gci($vo); } - exit(); + $output_text = "Got order list from TuLanDuo (" . $startTravelDate . " ~ " . $endTravelDate . "). count: " . $resp_arr["responseData"]["totalRows"] . ". Insert COLI : " . $cnt; + log_message('error',$output_text); + echo $output_text; + return; + } + + public function insert_gai($coli_sn, $gri_sn, $coli_id, $paytype, $currency, $sqje, $ssje, $memo="") + { + $this->Orders_model->GAI_Operator = 435; + $this->Orders_model->GAI_COLI_SN = $coli_sn; + $this->Orders_model->GAI_GRI_SN = $gri_sn; + $this->Orders_model->GAI_COLI_ID = $coli_id; + $this->Orders_model->GAI_Type = $paytype; + $this->Orders_model->GAI_SQJE = $sqje; + $this->Orders_model->GAI_SQJECurrency = $currency; + $this->Orders_model->GAI_SSJE = $ssje; + $this->Orders_model->GAI_SSDate = date("Y-m-d H:i:s"); + $this->Orders_model->GAI_Memo = $memo; + return $this->Orders_model->biz_groupaccountinfo_save(); + } + + public function insert_cold($list_ele) + { + $COLD_MemoText = raw_json_encode(array("Pick up"=>$list_ele['toTraffic'], "Drop off"=>$list_ele['backTraffic'])); + $pag_info = $this->analysis_productcode($list_ele['routeName'], $list_ele['orderId']); + $this->Orders_model->COLD_COLI_SN = $this->Orders_model->BIZ_COLI_SN; + $this->Orders_model->COLD_ServiceType = "D"; + $this->Orders_model->COLD_ServiceSN = $pag_info->serviceinfo->PAG2_PAG_SN; + $this->Orders_model->COLD_ServiceSN2 = $pag_info->pag_sub; + $this->Orders_model->COLD_ServiceCity = $pag_info->serviceinfo->PAG_CII_SN; + $this->Orders_model->COLD_StartDate = $list_ele['travelDate']; + $this->Orders_model->COLD_EndDate = $list_ele['leaveDate']; + $this->Orders_model->COLD_PersonNum = $list_ele['adultNum']; + $this->Orders_model->COLD_ChildNum = $list_ele['childNum']; + $this->Orders_model->cold_state = $list_ele['orderStatus']==1 ? 9 : 104; // 9订妥 // 104联络地接中 + $this->Orders_model->DeleteFlag = 0; + $this->Orders_model->COLD_PlanVEI_SN = $this->city_info[$list_ele['operationDep']]['PlanVEI_SN'] ? $this->city_info[$list_ele['operationDep']]['PlanVEI_SN'] : 1343; + $this->Orders_model->COLD_MemoText = $COLD_MemoText; + return $this->Orders_model->biz_confirm_detail_save(); + } + + public function insert_coli($list_ele) + { + $this->Orders_model->BIZ_COLI_GRI_SN = $this->Orders_model->GRI_SN ; + $this->Orders_model->BIZ_COLI_GroupCode = $this->Orders_model->GRI_No ; + $this->Orders_model->BIZ_GUT_SN = $this->Orders_model->GUT_SN; + $this->Orders_model->BIZ_COLI_ID = $this->Orders_model->biz_make_order_number(); + $this->Orders_model->BIZ_COLI_ApplyDate = $list_ele['orderDate']; + $this->Orders_model->BIZ_COLI_sourcetype = empty($this->city_info[$list_ele['operationDep']]) ? 32090 : $this->city_info[$list_ele['operationDep']]['COLI_sourcetype']; + $this->Orders_model->BIZ_COLI_State = 9; + $this->Orders_model->BIZ_COLI_servicetype = 'D'; + $this->Orders_model->BIZ_COLI_ConfirmType = 52001; + $this->Orders_model->BIZ_COLI_Memo = ""; + $this->Orders_model->BIZ_COLI_OrderDetailText = "来自图兰朵系统同步" . $list_ele["orderId"] . ";线路:" . $list_ele['routeName'] . "; 团名: " . $list_ele['agcOrderNo']; + $this->Orders_model->BIZ_COLI_GUT_SN = $this->Orders_model->BIZ_GUT_SN ? $this->Orders_model->BIZ_GUT_SN : null; + $this->Orders_model->BIZ_COLI_OPI_ID = 435; + $this->Orders_model->BIZ_COLI_PayManner = 15006; + return $this->Orders_model->biz_confirm_save(); + } + + public function insert_gri($list_ele) + { + $travelDate = new DateTime($list_ele['travelDate']); + $leaveDate = new DateTime($list_ele['leaveDate']); + $date_diff = $travelDate->diff($leaveDate); + $this->Orders_model->GRI_No = mb_substr($list_ele['agcOrderNo'], 0, 49); + $this->Orders_model->GRI_OrderType = 227002; // 商务 + $this->Orders_model->GRI_Name = mb_substr($list_ele['agcOrderNo'], 0, 49); + $this->Orders_model->GRI_PersonNum = $list_ele['adultNum']+$list_ele['childNum']; + $this->Orders_model->GRI_Days = intval($date_diff->format('%R%a')+1); + $this->Orders_model->GRI_IsCancel = 0; + $this->Orders_model->DeleteFlag = 0; + $this->Orders_model->GRI_OPI_ID = 435; + $this->Orders_model->GRI_operator = 435; + $this->Orders_model->GRI_Creator = 435; + return $this->Orders_model->groupinfo_save(); + } + + public function insert_gci($list_ele) + { + $this->Orders_model->GCI_combineNo = isset($list_ele['groupOrderNo']) ? $list_ele['groupOrderNo'] : ''; + $this->Orders_model->GCI_GRI_SN = $this->Orders_model->GRI_SN; + $this->Orders_model->GCI_VEI_SN = $this->city_info[$list_ele['operationDep']]['PlanVEI_SN'] ? $this->city_info[$list_ele['operationDep']]['PlanVEI_SN'] : 1343; + $this->Orders_model->GCI_VendorOrderId = $list_ele['orderId']; + $this->Orders_model->GCI_FromAgc = $list_ele['agcName']; + $this->Orders_model->GCI_groupType = $list_ele['orderType']; + $this->Orders_model->GCI_travelDate = $list_ele['travelDate']; + $this->Orders_model->GCI_leaveDate = $list_ele['leaveDate']; + $this->Orders_model->GCI_createTime = date('Y-m-d H:i:s'); + return $this->Orders_model->biz_groupcombineinfo_save(); + } + + // 解析产品编号 + public function analysis_productcode($route_name, $vendor_orderid) + { + $ret = new stdClass(); + $ret->PAG_Code = null; + $ret->pag_sub = null; + $ret->serviceinfo = new stdClass(); + $pag_no_tmp = $this->pag_no_tmp(); + preg_match('/[a-zA-Z]+\-[0-9\-]+/', characet($route_name, "UTF-8"), $temp_array); + if (empty($temp_array) && isset($pag_no_tmp[$route_name])) { + $ret->PAG_Code = $pag_no_tmp[$route_name]; + $split_code = explode("-", $ret->PAG_Code); + $ret->PAG_Code = $split_code[0] . "-" . $split_code[1]; + isset($split_code[2]) ? $ret->pag_sub=$split_code[2] : null; + } else if ( ! empty($temp_array)) { + $ret->PAG_Code = null; + $ret->pag_sub = null; + $split_code = explode("-", $temp_array[0]); + $ret->PAG_Code = $split_code[0] . "-" . $split_code[1]; + isset($split_code[2]) ? $ret->pag_sub=$split_code[2] : null; + } else { + log_message('error',"UnKnown route name " . $ret->PAG_Code . " " . $vendor_orderid . " " . $route_name . var_export($temp_array, 1)); + $ret->serviceinfo->PAG2_SN = null; + $ret->serviceinfo->PAG_CII_SN = null; + $ret->serviceinfo->PAG2_PAG_SN = null; + } + $ret->PAG_Code = in_array($ret->PAG_Code, array("SHALC-6","SHALC-7","SHALC-8","SHALC-9")) ? "SHSIC-45" : $ret->PAG_Code; + if ($ret->PAG_Code) { + $ret->serviceinfo = $this->Orders_model->get_packageSN($ret->PAG_Code); + } + return $ret; } /*! @@ -874,7 +804,7 @@ class TulanduoApi extends CI_Controller if ($COLI_ID == '') { return false; } - log_message('error','修改为不成行 order_cancel ' . $COLI_ID); + log_message('error','update order_cancel ' . $COLI_ID); /** UPDATE HT */ /** BIZ_ConfirmLineInfo */ $this->Order_update->coli_where_update = " COLI_ID='" . $COLI_ID . "'"; @@ -883,12 +813,27 @@ class TulanduoApi extends CI_Controller ); return $this->Order_update->biz_confirmlineinfo_update($coli_update_column); } - public function plan_cancel($vendorID=0) + public function groupinfo_delete($gri_sn=0) + { + if ($gri_sn === 0) { + return false; + } + /** GRoupInfo */ + $this->Order_update->gri_where_update = " GRI_SN='" . $gri_sn . "'"; + $gri_update_column = array( + "DeleteFlag" => 1 + ); + return $this->Order_update->biz_groupinfo_update($gri_update_column); + } + public function plan_cancel($vendorID=0, $state="cancel") { + if ($vendorID === 0) { + return false; + } /** groupcombineinfo */ $this->Order_update->gci_where_update = " GCI_VendorOrderId='" . $vendorID . "'"; $gci_update_column = array( - "GCI_combineNo" => 'cancel' + "GCI_combineNo" => $state ,"GCI_createTime" => date('Y-m-d H:i:s') ); $this->Order_update->biz_groupcombineinfo_update($gci_update_column); @@ -1124,6 +1069,7 @@ log_message('error','in GCI ' . json_decode($resp)->responseData->orderId); ,"司马台西-金山岭徒步一日游(PVT)(目的地)" => "BJSIC-46" ,"司马台西-金山岭长城徒步拼团(目的地)" => "BJSIC-46" ,"慕田峪半日游拼团(目的地)" => "BJSIC-47" + ,"慕田峪半日游PVT(目的地)" => "BJSIC-47" ,"古北口长城徒步一日游(目的地)" => "BJSIC-48" ,"半日游广场故宫拼团(目的地)" => "BJSIC-41" // ,=> @@ -1133,6 +1079,7 @@ log_message('error','in GCI ' . json_decode($resp)->responseData->orderId); ,"西安单租车接送服务(目的地)" => "XASIC-17" ,"西安兵马俑精品一日游(目的地)" => "XASIC-41" ,"西安兵马俑精品半日游(目的地)" => "XASIC-15" + ,"西安兵马俑精品半日游PVT(目的地)" => "XASIC-15" ,"西安汉阳陵市内精品一日游(目的地)" => "XASIC-42" // ,=> ,"上海精品一日游(目的地)" => "SHSIC-41" diff --git a/webht/third_party/trippestOrderSync/helpers/array_helper.php b/webht/third_party/trippestOrderSync/helpers/array_helper.php index b1cf03e2..8880682f 100644 --- a/webht/third_party/trippestOrderSync/helpers/array_helper.php +++ b/webht/third_party/trippestOrderSync/helpers/array_helper.php @@ -117,8 +117,9 @@ function raw_json_encode($input, $flags = 0) { function analysis_groupCode($groupCode) { mb_regex_encoding("UTF-8"); + $groupCode = trim_groupCode(trim($groupCode)); preg_match('/[\w\s\-]+/', characet($groupCode, "UTF-8"), $temp_array); - $temp_array[0] = strrchr($temp_array[0], " ") ? mb_strstr($temp_array[0], " ",true) : $temp_array[0]; + // $temp_array[0] = strrchr($temp_array[0], " ") ? mb_strstr($temp_array[0], " ",true) : $temp_array[0]; $tmp_groupCode = explode("-", trim($temp_array[0])); $real_groupCode = $tmp_groupCode[0]; if (isset($tmp_groupCode[1])) { @@ -131,9 +132,13 @@ function analysis_groupCode($groupCode) $real_groupCode .= mb_strstr($tmp_groupCode[$i], "(", true)!==false ? mb_strstr($tmp_groupCode[$i], "(", true) : $tmp_groupCode[$i]; } } - $real_groupCode = mb_ereg_replace('( )', '', trim($real_groupCode)); + $real_groupCode = trim_groupCode(trim($real_groupCode)); return $real_groupCode; } +function trim_groupCode($groupCode) +{ + return mb_ereg_replace('( | | )', '', $groupCode); +} /*! * 转换字符集编码 * @param $data diff --git a/webht/third_party/trippestOrderSync/models/orders_model.php b/webht/third_party/trippestOrderSync/models/orders_model.php index ae96731a..9871d2be 100644 --- a/webht/third_party/trippestOrderSync/models/orders_model.php +++ b/webht/third_party/trippestOrderSync/models/orders_model.php @@ -131,7 +131,7 @@ class Orders_model extends CI_Model { */ public function get_groupCombineInfo($coli_sn=0, $get_vendorID=null, $startDate=null, $endDate=NULL) { - $sql = "SELECT top 10 coli.COLI_ID, coli.COLI_SN, coli.COLI_GRI_SN, cold.COLD_SN, coli.COLI_OrderDetailText, coli.COLI_Memo,coli.COLI_State,coli.COLI_OPI_ID, + $sql = "SELECT top 1 coli.COLI_ID, coli.COLI_SN, coli.COLI_GRI_SN, cold.COLD_SN, coli.COLI_OrderDetailText, coli.COLI_Memo,coli.COLI_State,coli.COLI_OPI_ID, cold.COLD_PlanVEI_SN, gci.* FROM GroupCombineInfo gci LEFT JOIN BIZ_ConfirmLineInfo coli ON coli.COLI_GRI_SN=gci.GCI_GRI_SN --and coli.COLI_State NOT IN ('30','40','50') @@ -267,7 +267,7 @@ class Orders_model extends CI_Model { $this->GRI_Creator, $this->GRI_OrderType )); - $this->GRI_SN = $this->HT->query("select MAX(GRI_SN) as insert_id FROM GRoupInfo WHERE GRI_No='" . $this->GRI_No . "'")->row('insert_id'); + $this->GRI_SN = $this->HT->query("select MAX(GRI_SN) as insert_id FROM GRoupInfo WHERE GRI_operator=435 AND GRI_No='" . $this->GRI_No . "'")->row('insert_id'); return $this->GRI_SN; } @@ -526,7 +526,7 @@ class Orders_model extends CI_Model { inner join BIZ_ConfirmLineDetail cold on cold.COLD_COLI_SN=COLI_SN --and COLI_State not in (30,40,50) LEFT JOIN GRoupInfo gri ON coli.COLI_GRI_SN=gri.GRI_SN and GRI_OrderType=227002 and gri.GRI_operator<>435 and gri.GRI_operator is not null - WHERE gri.GRI_No LIKE '%$code%' + WHERE coli.COLI_Department=30 and gri.GRI_No LIKE '%$code%' order by COLI_SN desc"; // and gri.GRI_Name like '%$NoName%' $query = $this->HT->query($sql); if ($query->num_rows() > 0) { @@ -555,7 +555,7 @@ class Orders_model extends CI_Model { FROM BIZ_ConfirmLineInfo coli inner join BIZ_ConfirmLineDetail cold on cold.COLD_COLI_SN=COLI_SN left JOIN GRoupInfo gri ON coli.COLI_GRI_SN=gri.GRI_SN and GRI_OrderType=227002 - WHERE gri.GRI_No LIKE '%$code%' + WHERE coli.COLI_Department=30 and gri.GRI_No LIKE '%$code%' order by case COLI_OPI_ID when 435 then 1 else 0 end asc,COLI_SN desc"; $query = $this->HT->query($sql); return $query->result(); diff --git a/webht/third_party/trippestOrderSync/models/tulanduo_sync_model.php b/webht/third_party/trippestOrderSync/models/tulanduo_sync_model.php new file mode 100644 index 00000000..abcfb29a --- /dev/null +++ b/webht/third_party/trippestOrderSync/models/tulanduo_sync_model.php @@ -0,0 +1,59 @@ +HT = $this->load->database('HT', TRUE); + } + + /*! + * 查询图兰朵订单id是否已存在 + * @param string $vendorOrderIds [description] + */ + public function get_exists_vendorOrderId($vendorOrderIds="") + { + $sql = "SELECT GCI_VendorOrderId FROM GroupCombineInfo + WHERE GCI_VendorOrderId IN ($vendorOrderIds) "; + return $this->HT->query($sql)->result(); + } + /*! + * 从图兰朵同步历史数据的日期偏移 + * 获取HT内图兰朵订单的最老出发日期 + * * 由于获取列表时根据发团日期或得到更早时间的发团日期 + * * 因此这里取最早的10个, 找出不连续的为滚动日期的开始 + */ + public function get_oldest_offset() + { + $sql = "SELECT DISTINCT TOP 10 CAST(GCI_travelDate as DATE) old_date from GroupCombineInfo + order by old_date asc"; + $all_date = $this->HT->query($sql)->result(); + $all_date_arr = array_map(function($ele) + { + return $ele->old_date; + }, $all_date); + for ($i=count($all_date_arr)-1; $i > 0; $i--) { + $d1 = new DateTime($all_date_arr[$i]); + $d2 = new DateTime($all_date_arr[$i-1]); + $date_diff = $d2->diff($d1); + if (intval($date_diff->format('%R%a')) > 1) { + return $all_date_arr[$i]; + } + } + return $all_date_arr[0]; + } + /*! + * 图兰朵订单在HT内的信息 + * @param [type] $code [description] + * @param [type] $vendorOrderId [description] + */ + public function get_vendorOrder_HTinfo($code, $vendorOrderId=NULL) + { + # code... + } + +} + +/* End of file tulanduo_sync_model.php */ +/* Location: ./webht/third_party/trippestOrderSync/models/tulanduo_sync_model.php */