From 3acce1e1dea24955bbc1eb4c546971e8f5975aa0 Mon Sep 17 00:00:00 2001 From: lyt Date: Sat, 28 Apr 2018 13:41:30 +0800 Subject: [PATCH] =?UTF-8?q?trippest=20=E5=9B=A2=E6=AC=BE=E5=BD=95=E5=85=A5?= =?UTF-8?q?=E5=9C=B0=E6=8E=A5=E4=BB=A3=E6=94=B6,=E8=B0=83=E5=BA=A6?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=9B=B4=E6=96=B0,=E8=B0=83=E5=BA=A6?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=98=BE=E7=A4=BA=E5=88=B0=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/TulanduoApi.php | 144 ++++++++++++++---- .../trippestOrderSync/models/order_update.php | 17 --- .../trippestOrderSync/models/orders_model.php | 113 +++++++------- 3 files changed, 165 insertions(+), 109 deletions(-) diff --git a/webht/third_party/trippestOrderSync/controllers/TulanduoApi.php b/webht/third_party/trippestOrderSync/controllers/TulanduoApi.php index 600d616f..96220ea5 100644 --- a/webht/third_party/trippestOrderSync/controllers/TulanduoApi.php +++ b/webht/third_party/trippestOrderSync/controllers/TulanduoApi.php @@ -44,7 +44,6 @@ class TulanduoApi extends CI_Controller // public $neworder_url = "http://djb3c.ltsoftware.net:9921/action/api/addOrUpdateRouteOrder/"; // 发送到图兰朵系统接口的参数jsonParams - // public $params; public function __construct(){ parent::__construct(); @@ -54,7 +53,6 @@ class TulanduoApi extends CI_Controller // $this->output->enable_profiler(TRUE); - // $this->params = new stdClass(); /** test */ // $this->userId = "358"; // $this->key = "a08f26ddc5b1bd4c8e5eafcac28fc1ec"; @@ -65,6 +63,7 @@ class TulanduoApi extends CI_Controller // 桂林海纳国旅 // $this->userId = "18"; // $this->key = "d05c25e6e6c5d4898161e0aaf700d9c7"; + mb_regex_encoding("UTF-8"); } public function get_orderlist() @@ -73,8 +72,8 @@ class TulanduoApi extends CI_Controller ->setKey($this->key) ->setPageSize(20) ->setPageIndex(1) - ->setStartTravelDate("2018-04-20") // test - ->setEndTravelDate("2018-04-20") + ->setStartTravelDate("2018-04-21") // test + ->setEndTravelDate("2018-04-21") // ->setStartOrderDate("2018-04-13") // ->setEndOrderDate("2018-04-13") ; @@ -111,7 +110,12 @@ class TulanduoApi extends CI_Controller $cnt = 0; $pag_no_tmp = $this->pag_no_tmp(); mb_regex_encoding("UTF-8"); + $unique_order = array(); foreach ($all_list as $k => $vo) { + if (in_array($vo['orderId'], $unique_order)) { + continue; + } + $unique_order[] = $vo['orderId']; $vo['agcOrderNo'] = mb_ereg_replace('(\s| )', '', $vo['agcOrderNo']); // 去掉中文的全角空格 $PAG_Code = $pag_sub = null; preg_match('^[a-zA-Z]+\-[0-9\-]+^', $this->characet($vo['routeName'], "UTF-8"), $temp_array); @@ -181,7 +185,7 @@ log_message('error','new coli ' . $this->Orders_model->BIZ_COLI_ID); $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 ? 7 : 4; // 7已确认(已收款) // 4 下计划未确认(已收款) + $this->Orders_model->cold_state = $vo['orderStatus']==1 ? 7 : 4; // 7已确认 // 4 下计划未确认 $this->Orders_model->DeleteFlag = 0; $this->Orders_model->COLD_PlanVEI_SN = empty($this->city_info[$vo['operationDep']]) ? 1343 : $this->city_info[$vo['operationDep']]['PlanVEI_SN']; $this->Orders_model->COLD_MemoText = $COLD_MemoText; @@ -213,18 +217,25 @@ log_message('error','new coli ' . $this->Orders_model->BIZ_COLI_ID); return; } - public function update_HT_order_operation($coli_sn=null) + public function insert_HT_order_operation($coli_sn=null) { $this->load->model('Order_update'); if ($coli_sn !== null) { $to_update_list = $this->Orders_model->get_groupCombineInfo($coli_sn); } else { - $startDate = date('Y-m-d'); - $endDate = date('Y-m-d', strtotime("+1 days")); // test + $startDate = ('2018-04-21'); + $endDate = ('2018-04-22'); // test + // $startDate = date('Y-m-d'); // $endDate = date('Y-m-d', strtotime("+4 days")); $to_update_list = $this->Orders_model->get_groupCombineInfo(0, $startDate, $endDate); } + $unique_orderGroupCombine = array(); + $unique_order = array(); 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); @@ -234,22 +245,33 @@ log_message('error','new coli ' . $this->Orders_model->BIZ_COLI_ID); log_message('error','TulanduoApi get_orderdetail failed. Msg:' . $detail_jsonResp->errMsg . "; Request: " . $this->tld_order->getBizContent()); return; } - // $allDetails_to_HT = ""; - // $allDetails_to_HT .= "日程: "; - // foreach ($detail_jsonResp->orderDetail->scheduleDetails as $vsd) { - // $allDetails_to_HT .= $vsd->travelDate .": ". $vsd->title . "; "; - // } - // $allDetails_to_HT .= "导游: "; - // foreach ($detail_jsonResp->orderDetail->operationDetails->guiderOperations as $vg) { - // $allDetails_to_HT .= $vg->name ." (". $vg->mobelPhone . "); "; - // } + $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 . "); "; + } + } + 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 开始 */ /** UPDATE */ /** BIZ_ConfirmLineInfo */ - $this->Order_update->coli_where_update = " COLI_SN=" . $order->GCI_COLI_SN; + $this->Order_update->coli_where_update = " COLI_SN=" . $order->COLI_SN; + $old_memo = mb_strstr($order->COLI_Memo, "orderRemark", true) ? mb_strstr($order->COLI_Memo, "orderRemark", true) : $order->COLI_Memo; + $old_detail = mb_strstr($order->COLI_OrderDetailText, "operations", true) ? mb_strstr($order->COLI_OrderDetailText, "operations", true) : $order->COLI_OrderDetailText; $coli_update_column = array( - "COLI_Memo" => $order->COLI_Memo . "\r\n" . $detail_jsonResp->orderDetail->orderRemark . "\r\n" - // ,"COLI_OrderDetailText" => $order->COLI_OrderDetailText . "\r\n" . $allDetails_to_HT . "\r\n" + "COLI_Memo" => $old_memo . "orderRemark\r\n" . $detail_jsonResp->orderDetail->orderRemark . "\r\n" + ,"COLI_OrderDetailText" => $old_detail . "operations\r\n" . $allDetails_to_HT . "\r\n" ); $this->Order_update->biz_confirmlineinfo_update($coli_update_column); /** BIZ_ConfirmLineDetail */ // nothing to update @@ -282,12 +304,73 @@ log_message('error','new coli ' . $this->Orders_model->BIZ_COLI_ID); $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'; + // 删除旧的录入 + $this->Orders_model->biz_groupaccountinfo_cut($order->COLI_SN, $paytype); + if (isset($detail_jsonResp->orderDetail->travelFees) && $order->GCI_FromAgc != "D目的地桂林组") { + foreach ($detail_jsonResp->orderDetail->travelFees as $ktf => $vtf) { + if ($vtf->reviewStatus == 0) { // 未审核的 + continue; + } + $this->Orders_model->GAI_COLI_SN = $order->COLI_SN; + $this->Orders_model->GAI_GRI_SN = $order->COLI_GRI_SN; + $this->Orders_model->GAI_COLI_ID = $order->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_Memo = $vtf->type . ", " . $vtf->remark; + $this->Orders_model->biz_groupaccountinfo_save(); + } + } + // 代收 + if (isset($detail_jsonResp->orderDetail->replaceCollections)) { + foreach ($detail_jsonResp->orderDetail->replaceCollections as $krc => $vrc) { + if ($vrc->reviewStatus == 0) { + continue; + } + $this->Orders_model->GAI_COLI_SN = $order->COLI_SN; + $this->Orders_model->GAI_GRI_SN = $order->COLI_GRI_SN; + $this->Orders_model->GAI_COLI_ID = $order->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_Memo = $vrc->type . ", " . $vrc->remark; + $this->Orders_model->biz_groupaccountinfo_save(); + } + } + // 代付 + if (isset($detail_jsonResp->orderDetail->replacePays)) { + foreach ($detail_jsonResp->orderDetail->replacePays as $krp => $vrp) { + if ($vrp->reviewStatus == 0) { + continue; + } + $this->Orders_model->GAI_COLI_SN = $order->COLI_SN; + $this->Orders_model->GAI_GRI_SN = $order->COLI_GRI_SN; + $this->Orders_model->GAI_COLI_ID = $order->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_Memo = $vrp->type . ", " . $vrp->remark; + $this->Orders_model->biz_groupaccountinfo_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) && - ($this->Orders_model->combineoperation_exist($detail_jsonResp->orderDetail->groupOrderNo, "sceneryOperations")) === array() ) { + if (isset($detail_jsonResp->orderDetail->operationDetails->sceneryOperations)) { foreach ($detail_jsonResp->orderDetail->operationDetails->sceneryOperations as $ks => $vso) { - $this->Orders_model->GCOD_GCI_combineNo = isset($detail_jsonResp->orderDetail->groupOrderNo) ? $detail_jsonResp->orderDetail->groupOrderNo : ""; + $this->Orders_model->GCOD_GCI_combineNo = $detail_jsonResp->orderDetail->groupOrderNo; $this->Orders_model->GCOD_operationType = "sceneryOperations"; $this->Orders_model->GCOD_subType = $vso->type; $this->Orders_model->GCOD_title = $vso->name; @@ -306,10 +389,9 @@ log_message('error','new coli ' . $this->Orders_model->BIZ_COLI_ID); } // 用房 ... // 用餐 - if (isset($detail_jsonResp->orderDetail->operationDetails->restraurantOperations) && - ($this->Orders_model->combineoperation_exist($detail_jsonResp->orderDetail->groupOrderNo, "restraurantOperations")) === array() ) { + if (isset($detail_jsonResp->orderDetail->operationDetails->restraurantOperations) ) { foreach ($detail_jsonResp->orderDetail->operationDetails->restraurantOperations as $vro) { - $this->Orders_model->GCOD_GCI_combineNo = isset($detail_jsonResp->orderDetail->groupOrderNo) ? $detail_jsonResp->orderDetail->groupOrderNo : ""; + $this->Orders_model->GCOD_GCI_combineNo = $detail_jsonResp->orderDetail->groupOrderNo ; $this->Orders_model->GCOD_operationType = "restraurantOperations"; $this->Orders_model->GCOD_subType = $vro->type; $this->Orders_model->GCOD_title = $vro->name; @@ -327,10 +409,9 @@ log_message('error','new coli ' . $this->Orders_model->BIZ_COLI_ID); } } // 用车 - if (isset($detail_jsonResp->orderDetail->operationDetails->touristCarOperations) && - ($this->Orders_model->combineoperation_exist($detail_jsonResp->orderDetail->groupOrderNo, "touristCarOperations")) === array() ) { + if (isset($detail_jsonResp->orderDetail->operationDetails->touristCarOperations)) { foreach ($detail_jsonResp->orderDetail->operationDetails->touristCarOperations as $vco) { - $this->Orders_model->GCOD_GCI_combineNo = isset($detail_jsonResp->orderDetail->groupOrderNo) ? $detail_jsonResp->orderDetail->groupOrderNo : ""; + $this->Orders_model->GCOD_GCI_combineNo = $detail_jsonResp->orderDetail->groupOrderNo ; $this->Orders_model->GCOD_operationType = "touristCarOperations"; $this->Orders_model->GCOD_subType = $vco->type; $this->Orders_model->GCOD_title = $vco->name; @@ -348,10 +429,9 @@ log_message('error','new coli ' . $this->Orders_model->BIZ_COLI_ID); } } // 导游服务 - if (isset($detail_jsonResp->orderDetail->operationDetails->guiderOperations) && - ($this->Orders_model->combineoperation_exist($detail_jsonResp->orderDetail->groupOrderNo, "guiderOperations")) === array() ) { + if (isset($detail_jsonResp->orderDetail->operationDetails->guiderOperations) ) { foreach ($detail_jsonResp->orderDetail->operationDetails->guiderOperations as $vgo) { - $this->Orders_model->GCOD_GCI_combineNo = isset($detail_jsonResp->orderDetail->groupOrderNo) ? $detail_jsonResp->orderDetail->groupOrderNo : ""; + $this->Orders_model->GCOD_GCI_combineNo = $detail_jsonResp->orderDetail->groupOrderNo ; $this->Orders_model->GCOD_operationType = "guiderOperations"; $this->Orders_model->GCOD_subType = ""; $this->Orders_model->GCOD_title = ""; diff --git a/webht/third_party/trippestOrderSync/models/order_update.php b/webht/third_party/trippestOrderSync/models/order_update.php index 4e61eda7..8c4a307a 100644 --- a/webht/third_party/trippestOrderSync/models/order_update.php +++ b/webht/third_party/trippestOrderSync/models/order_update.php @@ -56,23 +56,6 @@ class Order_update extends CI_Model { return $update_exc; } - /*! - * 拼团的调度信息是否已存在 - * @param string $combineNo 拼团团号 - * @param string $operation 调度类型 - */ - public function combineoperation_exist($combineNo='', $operation="") - { - if( ! $combineNo) { return array(); } - $sql = "SELECT TOP 1 GCOD_GCI_combineNo - FROM BIZ_GroupCombineOperationDetail - WHERE GCOD_GCI_combineNo = N? and GCOD_operationType=?"; - $query = $this->HT->query($sql, array( - $combineNo,$operation - )); - return $query->result(); - } - /*! * 地接计划状态变更 * @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 15ea7c69..f3427470 100644 --- a/webht/third_party/trippestOrderSync/models/orders_model.php +++ b/webht/third_party/trippestOrderSync/models/orders_model.php @@ -126,7 +126,7 @@ class Orders_model extends CI_Model { */ public function get_groupCombineInfo($coli_sn=0, $startDate=null, $endDate=NULL) { - $sql = "SELECT top 1000 coli.COLI_GRI_SN, cold.COLD_SN, coli.COLI_OrderDetailText, coli.COLI_Memo, gci.* + $sql = "SELECT top 1000 coli.COLI_ID, coli.COLI_SN, coli.COLI_GRI_SN, cold.COLD_SN, coli.COLI_OrderDetailText, coli.COLI_Memo, gci.* FROM BIZ_GroupCombineInfo gci INNER JOIN BIZ_ConfirmLineInfo coli ON coli.COLI_GRI_SN=gci.GCI_GRI_SN INNER JOIN BIZ_ConfirmLineDetail cold ON cold.COLD_COLI_SN=coli.COLI_SN @@ -135,7 +135,7 @@ class Orders_model extends CI_Model { $sql .= " and coli.COLI_SN='$coli_sn' "; } if ($startDate !== NULL) { - // $sql .= " and gci.GCI_travelDate between '$startDate' and '$endDate' "; // test + $sql .= " and gci.GCI_travelDate between '$startDate' and '$endDate' "; // test } $query = $this->HT->query($sql); return $query->result(); @@ -270,6 +270,16 @@ class Orders_model extends CI_Model { $this->GCI_SN = $this->HT->query("select MAX(GCI_SN) as insert_id FROM BIZ_GroupCombineInfo WHERE GCI_combineNo='" . $this->GCI_combineNo . "'")->row('insert_id'); return $this->GCI_SN; } + + public function biz_groupcombineoperationdetail_cut($combineNo) + { + $sql = "DELETE + FROM BIZ_GroupCombineOperationDetail + WHERE GCOD_GCI_combineNo = N?"; + $query = $this->HT->query($sql, array($combineNo)); + return $query; + } + public function combineoperation_exist($combineNo='', $operation="") { if( ! $combineNo) { return array(); } @@ -945,6 +955,11 @@ class Orders_model extends CI_Model { return $this->FOI_SN; } + /*! + * 查询是否已经写入过客人列表 + * @date 2018-04-28 + * @param [type] $cold_sn 订单字表key + */ public function bookpeople_exist($cold_sn) { if( ! $cold_sn) { return array(); } @@ -1104,42 +1119,20 @@ class Orders_model extends CI_Model { } } - /** - * - * 更新订单状态(商务订单) - * - */ - public function update_biz_order($order_id, $pay_manager, $source_type, $state, $text = '') { - //更新订单 - $sql = "UPDATE BIZ_ConfirmLineInfo SET COLI_PayManner=?,COLI_sourcetype=?,COLI_State=?,COLI_OrderDetailText=COLI_OrderDetailText+? WHERE COLI_ID=?"; - $query = $this->HT->query($sql, array($pay_manager, $source_type, $state, $text, $order_id . '')); - $this->insert_acc_info($order_id); - return '是否执行:' . print_r($query, true) . ' sql:' . $sql . ' 参数:' . print_r(array($pay_manager, $source_type, $state, $text, $order_id . ''), true); - } - - /** - * - * 更新火车订单购票截图 - * + /*! + * 删除收款记录以更新 + * @date 2018-04-28 + * @param [type] $coli_sn 订单key + * @param [type] $paytype 付款方式 */ - public function update_train_order_pic($order_pic_id) { - //更新订单 - $sql = "exec dbo.SP_BIZ_GroupFinanceList_Insert '" . $order_pic_id . "'"; - //$query = $this->HT->query($sql); - - include('c:/database_conn.php'); - $connection = array( - 'UID' => $db['HT']['username'], - 'PWD' => $db['HT']['password'], - 'Database' => 'tourmanager', - 'ConnectionPooling' => 1, - 'CharacterSet' => 'utf-8', - 'ReturnDatesAsStrings' => 1 - ); - $conn = sqlsrv_connect($db['HT']['hostname'], $connection); - $stmt = sqlsrv_query($conn, $sql); - - return $stmt; + public function biz_groupaccountinfo_cut($coli_sn, $paytype) + { + $sql = "UPDATE BIZ_GroupAccountInfo + SET DeleteFlag=1 + WHERE GAI_COLI_SN=? + AND GAI_Type=?"; + $query = $this->HT->query($sql, array($coli_sn, $paytype)); + return $query; } /** @@ -1147,24 +1140,25 @@ class Orders_model extends CI_Model { * 插入收款记录 * */ - public function insert_acc_info($order_id) { - //获取订单 - $sql = "Select Top 1 COLI_SN,COLI_ID,COLI_PayManner,COLI_Price From BIZ_ConfirmLineInfo Where COLI_ID = ?"; - $query = $this->HT->query($sql, array($order_id)); - $order_info = $query->row(); - //插入记录 - $sql = "INSERT INTO BIZ_GroupAccountInfo \n" + public $GAI_COLI_SN; + public $GAI_GRI_SN; + public $GAI_COLI_ID; + public $GAI_Type; + public $GAI_SQJE; + public $GAI_SQDate; + public $GAI_SQJECurrency; + public $GAI_Memo=""; + public function biz_groupaccountinfo_save() + { + $sql = "INSERT INTO BIZ_GroupAccountInfo \n" . " ( \n" . " GAI_COLI_SN, \n" + . " GAI_GRI_SN, \n" . " GAI_COLI_ID, \n" . " GAI_Type, \n" . " GAI_SQJE, \n" . " GAI_SQDate, \n" - . " GAI_SSJE, \n" . " GAI_SQJECurrency, \n" - . " GAI_SSDate, \n" - . " GAI_CusName, \n" - . " GAI_CusEmail, \n" . " GAI_Memo \n" . " ) \n" . "VALUES \n" @@ -1176,20 +1170,19 @@ class Orders_model extends CI_Model { . " ?, \n" . " ?, \n" . " ?, \n" - . " ?, \n" - . " ?, \n" - . " ?, \n" . " ? \n" . " )"; - $query = $this->HT->query($sql, array($order_info->COLI_SN, - $order_info->COLI_ID, - $order_info->COLI_PayManner, - $order_info->COLI_Price, - date('Y-m-d H:i:s'), - $order_info->COLI_Price, - $this->config->item('Site_Currency'), - date('Y-m-d H:i:s'), - "", "", " ")); + $query = $this->HT->query($sql, array( + $this->GAI_COLI_SN + ,$this->GAI_GRI_SN + ,$this->GAI_COLI_ID + ,$this->GAI_Type + ,$this->GAI_SQJE + ,$this->GAI_SQDate + ,$this->GAI_SQJECurrency + ,$this->GAI_Memo + )); + return $query; } function GetNationalityID($nationalityName) {