diff --git a/webht/third_party/trippestOrderSync/controllers/order_finance.php b/webht/third_party/trippestOrderSync/controllers/order_finance.php index 25207e9f..6bc6cb55 100644 --- a/webht/third_party/trippestOrderSync/controllers/order_finance.php +++ b/webht/third_party/trippestOrderSync/controllers/order_finance.php @@ -52,6 +52,7 @@ class Order_finance extends CI_Controller { // HT单团财务表页面调用, 先刷新一次成本 public function single_order_report_refresh($coli_sn=0, $debug=false) { + ignore_user_abort(true); // 刷新成本 $controller_name = "TulanduoApi"; require_once($controller_name . '.php'); diff --git a/webht/third_party/trippestOrderSync/controllers/vendor_money.php b/webht/third_party/trippestOrderSync/controllers/vendor_money.php index 878a1fd8..a93d39e9 100644 --- a/webht/third_party/trippestOrderSync/controllers/vendor_money.php +++ b/webht/third_party/trippestOrderSync/controllers/vendor_money.php @@ -300,9 +300,8 @@ class Vendor_money extends CI_Controller { $ret['not_found'] = $this->money_model->get_order_not_found_gci($start_date, $end_date, implode(',' ,$vendors)); // cost $HT_combine_cost = $this->money_model->get_combine_cost($start_date, $end_date, implode(',' ,$vendors)); - $cost_error = array(); - $ht_no_match = array(); - $xls_no_match = array(); + $xls_ht_diff = array(); + $xls_data = array(); // $config['upload_path'] = FCPATH.'download_statement\temp_files'; $config['upload_path'] = 'download_statement/temp_files'; // $config['file_name'] = "1.xls"; @@ -321,71 +320,117 @@ class Vendor_money extends CI_Controller { { $upload_data = array('upload_data' => $this->upload->data()); $read_path = $upload_data['upload_data']['full_path']; - $xls_data=array(); - $this->load->library('PHPExcel'); - $PHPExcel = new PHPExcel(); - /**默认用excel2007读取excel,若格式不对,则用之前的版本进行读取*/ - $PHPReader = new PHPExcel_Reader_Excel2007(); - if(!$PHPReader->canRead($read_path)){ - $PHPReader = new PHPExcel_Reader_Excel5(); - if(!$PHPReader->canRead($read_path)){ - echo 'no Excel'; - return ; - } - } - $PHPExcel = $PHPReader->load($read_path); - /**读取excel文件中的第一个工作表*/ - $currentSheet = $PHPExcel->getSheet(0); - /**取得最大的列号*/ - // $allColumn = $currentSheet->getHighestColumn(); - $allColumn = 'B'; - /**取得一共有多少行*/ - $allRow = $currentSheet->getHighestRow(); - $col_titles = array('A' => 'group_name', 'B' => 'group_cost'); - /**从第3行开始输出,因为excel表中第一行为列名*/ - for($currentRow = 3;$currentRow <= $allRow;$currentRow++){ - $row_tmp = array(); - /**从第A列开始输出*/ - for($currentColumn= 'A';$currentColumn<= $allColumn; $currentColumn++){ - /**ord()将字符转为十进制数*/ - $val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65,$currentRow)->getValue(); - $col_mean = $col_titles[$currentColumn]; - $row_tmp[$col_mean] = $val; - } - if (isset($row_tmp['group_name']) && !empty($row_tmp['group_name'])) { - $row_tmp['group_name'] = trim_str(trim($row_tmp['group_name'])); - $xls_data[] = $row_tmp; - } - } - $all_xls_group_name = array_column($xls_data, 'group_name'); - $all_ht_group_no = array_column($HT_combine_cost, 'GCI_combineNo'); - $not_in_ht = array_diff($all_xls_group_name, $all_ht_group_no); - $not_in_xls = array_diff($all_ht_group_no, $all_xls_group_name); - foreach ($HT_combine_cost as $kht => $ht_cost) { - if (in_array($ht_cost['GCI_combineNo'], $not_in_xls) - && !in_array(strtolower($ht_cost['GCI_combineNo']),array('cancel', 'forbidden')) + $xls_data = $this->read_excel($read_path); + unlink($upload_data['upload_data']['full_path']); + $xls_ht_diff = $this->diff_xls_ht_cost($xls_data, $HT_combine_cost); + foreach ($xls_ht_diff['cost_error'] as $kc => $cost_error) { + $colis = $this->get_gci_coli($cost_error['GCI_combineNo'], false); + if (array_sum(array_column($colis['data'], 'no_fresh')) > 0 + || array_sum(array_column($colis['data'], 'cgi_check')) > 0 ) { - $ht_no_match[] = $ht_cost; + continue; } - foreach ($xls_data as $kxls => $xls_cost) { - if ($xls_cost['group_name'] == $ht_cost['GCI_combineNo'] - && strval($ht_cost['cost']) != strval($xls_cost['group_cost']) - ) { - $cost_error[] = array_merge($ht_cost, $xls_cost); - } + foreach ($colis['data'] as $kco => $coli) { + async_curl("https://www.mycht.cn/webht.php/apps/trippestOrderSync/order_finance/single_order_report_refresh/" . $coli['COLI_SN'], 2); } } + } + if ( ! empty($xls_data)) { + // 批量`重新生成账单`之后, 在对比一次 + $HT_combine_cost = $this->money_model->get_combine_cost($start_date, $end_date, implode(',' ,$vendors)); + $xls_ht_diff = $this->diff_xls_ht_cost($xls_data, $HT_combine_cost); + } + $ret = array_merge($ret, $xls_ht_diff); + + return $this->load->view('order_report_precheck', $ret); + } + + private function diff_xls_ht_cost($xls_data, $HT_combine_cost) + { + $cost_error = array(); + $ht_no_match = array(); + $xls_no_match = array(); + $all_xls_group_name = array_column($xls_data, 'group_name'); + $all_ht_group_no = array_column($HT_combine_cost, 'GCI_combineNo'); + $not_in_ht = array_diff($all_xls_group_name, $all_ht_group_no); + $not_in_xls = array_diff($all_ht_group_no, $all_xls_group_name); + foreach ($HT_combine_cost as $kht => $ht_cost) { + if (in_array($ht_cost['GCI_combineNo'], $not_in_xls) + && !in_array(strtolower($ht_cost['GCI_combineNo']),array('cancel', 'forbidden')) + ) { + $ht_no_match[] = $ht_cost; + } foreach ($xls_data as $kxls => $xls_cost) { - if (in_array($xls_cost['group_name'], $not_in_ht)) { - $xls_no_match[] = $xls_cost; + if ($xls_cost['group_name'] == $ht_cost['GCI_combineNo'] + && strval($ht_cost['cost']) != strval($xls_cost['group_cost']) + ) { + $cost_error[] = array_merge($ht_cost, $xls_cost); } } - unlink($upload_data['upload_data']['full_path']); + } + foreach ($xls_data as $kxls => $xls_cost) { + if (in_array($xls_cost['group_name'], $not_in_ht)) { + $xls_no_match[] = $xls_cost; + } } $ret['cost_error'] = $cost_error; $ret['ht_no_match'] = $ht_no_match; $ret['xls_no_match'] = $xls_no_match; - return $this->load->view('order_report_precheck', $ret); + return $ret; + } + + private function read_excel($read_path) + { + $xls_data=array(); + $this->load->library('PHPExcel'); + $PHPExcel = new PHPExcel(); + /**默认用excel2007读取excel,若格式不对,则用之前的版本进行读取*/ + $PHPReader = new PHPExcel_Reader_Excel2007(); + if(!$PHPReader->canRead($read_path)){ + $PHPReader = new PHPExcel_Reader_Excel5(); + if(!$PHPReader->canRead($read_path)){ + echo 'no Excel'; + return ; + } + } + $PHPExcel = $PHPReader->load($read_path); + /**读取excel文件中的第一个工作表*/ + $currentSheet = $PHPExcel->getSheet(0); + /**取得最大的列号*/ + // $allColumn = $currentSheet->getHighestColumn(); + $allColumn = 'B'; + /**取得一共有多少行*/ + $allRow = $currentSheet->getHighestRow(); + $col_titles = array('A' => 'group_name', 'B' => 'group_cost'); + /**从第3行开始输出,因为excel表中第一行为列名*/ + for($currentRow = 3;$currentRow <= $allRow;$currentRow++){ + $row_tmp = array(); + /**从第A列开始输出*/ + for($currentColumn= 'A';$currentColumn<= $allColumn; $currentColumn++){ + /**ord()将字符转为十进制数*/ + $val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65,$currentRow)->getValue(); + $col_mean = $col_titles[$currentColumn]; + $row_tmp[$col_mean] = $val; + } + if (isset($row_tmp['group_name']) && !empty($row_tmp['group_name'])) { + $row_tmp['group_name'] = trim_str(trim($row_tmp['group_name'])); + $xls_data[] = $row_tmp; + } + } + return $xls_data; + } + + public function get_gci_coli($gci=null, $output=true) + { + $gci = $gci===null ? $this->input->get_post('gci') : $gci; + if ( ! $gci ) { + return $output===true ? $this->output->set_content_type('application/json')->set_output(json_encode([])) : []; + } + $result['data'] = $this->money_model->get_gci_coli($gci); + if (array_sum(array_column($result['data'], 'no_fresh')) == 0) { + $result['msg'] = '拼团中的订单含有其他地接社预订, 请到HT中查看和操作, 以免覆盖数据.'; + } + return $output===true ? $this->output->set_content_type('application/json')->set_output(json_encode($result)) : $result; } } diff --git a/webht/third_party/trippestOrderSync/helpers/array_helper.php b/webht/third_party/trippestOrderSync/helpers/array_helper.php index 5d8c874a..2c286fa7 100644 --- a/webht/third_party/trippestOrderSync/helpers/array_helper.php +++ b/webht/third_party/trippestOrderSync/helpers/array_helper.php @@ -174,3 +174,43 @@ function real_phone_number($phone, $nation_code) $cut_nation = str_replace($nation_str, "", $phone); return mb_ereg_replace('[\D]', '', $cut_nation); } + +/*! + * @Author: LYT + * @Date: 2019-06-27 10:32:11 + * @Desc: 异步的curl,1秒超时,被请求的地址需要设置: ignore_user_abort(true); + */ +function async_curl($url, $second = 1) +{ + log_message('error','Webht Async Call: '. $url); + $ch = curl_init(); + $curlVersion = curl_version(); + $ua = "Webht (".PHP_OS.") PHP/".PHP_VERSION." CURL/".$curlVersion['version']." " . "AsyncJob"; + //设置超时 + curl_setopt($ch, CURLOPT_TIMEOUT, $second); + curl_setopt($ch,CURLOPT_URL, $url); + if(stripos($url,"https://")!==FALSE){ + // curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); + } else { + // curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,TRUE); + // curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2);//严格校验 + } + curl_setopt($ch,CURLOPT_USERAGENT, $ua); + //设置header + curl_setopt($ch, CURLOPT_HEADER, FALSE); + //要求结果为字符串且输出到屏幕上 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + + //运行curl + $data = curl_exec($ch); + if (curl_errno($ch) && !in_array(curl_errno($ch),array(0,28)) ) { + log_message('error',"Webht Async Curl Call 出错,错误码:" . curl_errno($ch) . ": " . curl_error($ch) . ", url: " . $url); + } + if (!in_array(curl_getinfo($ch, CURLINFO_HTTP_CODE),array(0,200)) ) { + log_message('error', "Webht Async Curl Call Request html Status Code: ".curl_getinfo($ch, CURLINFO_HTTP_CODE)."; curl url: ".$url); + } + curl_close($ch); + return $data; +} diff --git a/webht/third_party/trippestOrderSync/models/vendor_money_model.php b/webht/third_party/trippestOrderSync/models/vendor_money_model.php index b8d5fa64..5ed9d2e3 100644 --- a/webht/third_party/trippestOrderSync/models/vendor_money_model.php +++ b/webht/third_party/trippestOrderSync/models/vendor_money_model.php @@ -616,8 +616,22 @@ class Vendor_money_model extends CI_Model { AND tourBZ LIKE '%'+REPLACE(gci_no,'[','[[]')+'%' AND ( RPT_Total<>to_be_diff.report_total_cost0 OR RPT_Total<>to_be_diff.total_cost ) ) AS diff_report_total_cost0 + ,case isnull(to_be_diff.no_fresh, 0) when 0 then 1 else 0 end to_fresh FROM - (SELECT * , + (SELECT + (select top 1 1 + from BIZ_ConfirmLineInfo + inner join GroupCombineInfo cc on cc.GCI_GRI_SN=COLI_GRI_SN + and GCI_combineNo=all_gci_no.gci_no + where + exists ( + select 1 from BIZ_ConfirmLineDetail + where COLD_COLI_SN=COLI_SN + and DeleteFlag=0 + and COLD_PlanVEI_SN not in ($all_vendor) + ) + ) as no_fresh + , * , (SELECT isnull(SUM(CONVERT(float,gcod.GCOD_sumMoney)),0) FROM GroupCombineOperationDetail gcod WHERE GCOD_GCI_combineNo=all_gci_no.gci_no @@ -627,8 +641,10 @@ FROM (SELECT isnull(round(SUM(isnull(tourcost,0)),2),0) FROM report_tour WHERE 1=1 - AND tourProvide=gci_vei_name - AND tourBZ LIKE '%'+REPLACE(gci_no,'[','[[]')+'%' + AND ( tourProvide=gci_vei_name OR tourProvide='' ) + -- AND ( tourProvide=gci_vei_name ) + -- AND tourBZ LIKE '%'+REPLACE(gci_no,'[','[[]')+'%' + and CHARINDEX(gci_no, tourBZ) > 0 ) AS report_cost , (SELECT top 1 RPT_Total FROM report_tour @@ -663,6 +679,26 @@ ORDER BY to_be_diff.GCI_VEI_SN return $query->result_array(); } + public function get_gci_coli($gci) + { + $sql = "SELECT COLI_SN, COLI_ID, COLI_GroupCode + ,( + select COUNT(COLD_SN) from BIZ_ConfirmLineDetail + where COLD_COLI_SN=COLI_SN + and DeleteFlag=0 + and COLD_PlanVEI_SN not in (1343,29188,30548) + ) as no_fresh + ,( + select COUNT(CGI_SN) from CK_GroupInfo k + where k.CGI_GRI_SN=GCI_GRI_SN and CGI_Checked=1 + ) as cgi_check + from BIZ_ConfirmLineInfo + inner join GroupCombineInfo cc on cc.GCI_GRI_SN=COLI_GRI_SN + and GCI_combineNo=?"; + $query = $this->HT->query($sql, array($gci)); + return $query->result_array(); + } + } /* End of file vendor_money.php */ diff --git a/webht/third_party/trippestOrderSync/views/order_report_precheck.php b/webht/third_party/trippestOrderSync/views/order_report_precheck.php index 21ea2e19..49a91639 100644 --- a/webht/third_party/trippestOrderSync/views/order_report_precheck.php +++ b/webht/third_party/trippestOrderSync/views/order_report_precheck.php @@ -101,6 +101,9 @@ ul { padding-left: 1em; } + .fade.in{ + background-color: rgba(0,0,0,.5); + } @@ -331,7 +334,9 @@ $ec) { ?>