diff --git a/webht/third_party/trippestOrderSync/controllers/TulanduoApi.php b/webht/third_party/trippestOrderSync/controllers/TulanduoApi.php index 95502145..1015f5ab 100644 --- a/webht/third_party/trippestOrderSync/controllers/TulanduoApi.php +++ b/webht/third_party/trippestOrderSync/controllers/TulanduoApi.php @@ -692,20 +692,31 @@ class TulanduoApi extends CI_Controller public function order_complement() { - // $start_date = $this->input->get_post("start_date"); - // $end_date = $this->input->get_post("end_date"); + $start_date = NULL; $end_date = NULL; $group_code = $this->input->get_post("group_code"); /** * 解析输入字段, 可能为拼团号或原始团号 * * 拼团号: 直接解析为发团时间, 按发团时间查询列表 * * 原始团号: 按团号查询 */ - $start_date = NULL; $end_date = NULL; + preg_match_all('/\d{4}\-\d{1,2}\-\d{2}/i', $group_code, $matchs_arr); + if ( ! empty($matchs_arr[0])) { + $start_date = $matchs_arr[0][0]; + $end_date = $matchs_arr[0][0]; + $group_code = NULL; + } $order_list = $this->new_order_to_ht("travel", $start_date, $end_date, $group_code); + if ( ! empty($order_list['data'])) { + foreach ($order_list['data'] as $key => $order) { + $this->insert_HT_order_operation(NULL, $order); + } + } + return $this->output->set_content_type('application/json')->set_output(json_encode($order_list)); } public function new_order_to_ht($date_type="travel", $start_date=NULL, $end_date=NULL, $group_code=NULL) { + $this->load->model('Tulanduo_sync_model', 'sync_model'); $ret = array(); $ret['data'] = array(); $ret['msg'] = ""; @@ -731,8 +742,9 @@ class TulanduoApi extends CI_Controller $ret['msg'] = "failed"; return $ret; } + // return $this->tld_order->getBizContent(); if ($resp_arr["responseData"]["totalRows"] == 0) { - $ret['msg'] = "total0"; + $ret['msg'] = "notFound"; return $ret; } $all_list = $resp_arr["responseData"]["orders"]; @@ -754,9 +766,52 @@ class TulanduoApi extends CI_Controller $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)) { - $ret['msg'] = "empty"; + $ret['msg'] = "synced"; + } + foreach ($all_list as $k => $vo) { + if ( ! in_array($vo['orderId'], $to_insert)) { + continue; + } + // paypal 手续费订单没有团号 + $vo['agcOrderNo'] = (isset($vo['agcOrderNo'])&&$vo['agcOrderNo']!="") ? $vo['agcOrderNo'] : $vo['groupOrderNo']; + $vo['agcOrderNo'] = (trim_str($vo['agcOrderNo'])); // 去掉中文的全角空格 + + $this->Orders_model->BIZ_COLI_SN = null; + $this->Orders_model->GRI_SN = null; + $this->Orders_model->GCI_SN = null; + $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) { + $real_groupCode_info = analysis_groupCode($vo['agcOrderNo']); + $real_groupCode = $real_groupCode_info["cut"]; + // set BIZ_COLI_SN, GRI_SN at Orders_model + $group_info = $this->Orders_model->get_SN_by_groupCode($real_groupCode, $vo['orderId']); + if (empty($group_info)) { + $real_groupCode = $real_groupCode_info["all"]; + $group_info = $this->Orders_model->get_SN_by_groupCode($real_groupCode, $vo['orderId']); + } + } + if ($this->Orders_model->GRI_SN === null) { + /** GRoupInfo */ + $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->insert_coli($vo); + /** BIZ_ConfirmLineDetail*/ + $this->insert_cold($vo); + } + if ($this->Orders_model->GCI_SN === null) { + /*biz_groupcombineinfo*/ + $this->insert_gci($vo); + } } - $ret['data'] = $to_insert; + $ret['data'] = array_values($to_insert); return $ret; }