feat: Trippest账单,自动更新

feature/trippest
lyt 6 years ago
parent 7f690b7dfe
commit ec1abbac48

@ -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');

@ -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,115 @@ 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;
$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) {
continue;
}
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;
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);
}
}
$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 ($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);
}
}
}
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;
}
}

@ -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;
}

@ -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,22 @@ 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
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 */

@ -101,6 +101,9 @@
ul {
padding-left: 1em;
}
.fade.in{
background-color: rgba(0,0,0,.5);
}
</style>
</head>
@ -331,7 +334,9 @@
<?php if (!empty($cost_error)) {
foreach ($cost_error as $ko => $ec) { ?>
<tr>
<td><?php echo $ec['GCI_combineNo']; ?></td>
<td><?php echo $ec['GCI_combineNo']; ?>&nbsp;&nbsp;
<!-- <a onclick="refresh_report('<?php echo $ec['GCI_combineNo'] ?>')" class="cell-right">重新生成账单&nbsp;&circlearrowleft;</a> -->
</td>
<td><?php echo $ec['cost']; ?></td>
<td><?php echo $ec['group_cost']; ?></td>
</tr>
@ -369,6 +374,24 @@
</table>
</div>
<div class="modal fade" tabindex="-1" role="dialog" id="gci_coli">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">拼团号: <span id="gci_no"></span> </h4>
</div>
<div class="modal-body" id="gci_coli_id">
<p>One fine body&hellip;</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
<script src="/js/jquery.min.js" type="text/javascript"></script>
<script src="/js/bootstrap.min.js" type="text/javascript"></script>
@ -391,6 +414,33 @@
document.querySelector('#request_form').submit();
document.request_form.action = "/webht.php/apps/trippestordersync/vendor_money/index";
}
function refresh_report(gci) {
const formData = new FormData();
formData.append('gci', gci);
fetch('/webht.php/apps/trippestordersync/vendor_money/get_gci_coli',{
method: 'POST',
body: formData
})
.then (function (data) {
return data.json();
})
.then(function (response) {
$('#gci_no').html(gci);
if (response.msg) {
$('#gci_coli_id').html(response.msg);
$('#gci_coli').modal('show')
return false;
}
var content_html='';
for (let i = 0; i < response.data.length; i++) {
const element = response.data[i];
content_html += "<p>" + (i+1) + ". " + element.COLI_ID + " : " + element.COLI_GroupCode + "</p>";
}
$('#gci_coli_id').html(content_html);
$('#gci_coli').modal('show')
})
}
</script>
</html>

@ -86,6 +86,9 @@
.info-primary{
color: #337ab7;
}
.fade.in{
background-color: rgba(0,0,0,.5);
}
</style>
</head>
@ -360,9 +363,9 @@
<th class="text-left">
<p class="text-center"> 财务表计算总成本</p>
<!-- <ol class="info-primary">
<li> 数据为空: 虚拟订单没有团号, 无法计算. 如:
<li> 与左列值不相等
<ul>
<li> TA导游奖励计入成本的虚拟订单. 人工检查金额正确之后, 此处可忽略该团. </li>
<li> 拼团下个别订单需要重新生成账单. </li>
</ul>
</li>
</ol> -->
@ -372,7 +375,11 @@
<tbody>
<?php foreach ($diff_cost as $kdc => $diff) { ?>
<tr>
<td><?php echo $diff['gci_no'] ?></td>
<td><?php echo $diff['gci_no'] ?>&nbsp;&nbsp;
<?php //if($diff['to_fresh']===1) { ?>
<!-- <a onclick="refresh_report('<?php echo $diff['gci_no'] ?>')" class="cell-right">重新生成账单&nbsp;&circlearrowleft;</a> -->
<?php //} ?>
</td>
<td><?php echo $diff['total_cost'] ?></td>
<td><?php echo $diff['report_total_cost0'] ?></td>
<td><?php echo $diff['report_cost'] ?></td>
@ -382,6 +389,23 @@
</table>
<?php } ?>
</div>
<div class="modal fade" tabindex="-1" role="dialog" id="gci_coli">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">group number: </h4>
</div>
<div class="modal-body" id="gci_coli_id">
<p>One fine body&hellip;</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
<script src="/js/jquery.min.js" type="text/javascript"></script>
<script src="/js/bootstrap.min.js" type="text/javascript"></script>
@ -402,6 +426,27 @@
document.querySelector('#request_form').submit();
document.request_form.action = "/webht.php/apps/trippestordersync/vendor_money/index";
}
function refresh_report(gci) {
const formData = new FormData();
formData.append('gci', gci);
fetch('/webht.php/apps/trippestordersync/vendor_money/get_gci_coli',{
method: 'POST',
body: formData
})
.then (function (data) {
return data.json();
})
.then(function (response) {
var content_html='';
for (let i = 0; i < response.data.length; i++) {
const element = response.data[i];
content_html += "<p>" + element.COLI_ID + " : " + element.COLI_GroupCode + "</p>";
}
$('#gci_coli_id').html(content_html);
$('#gci_coli').modal('show')
})
}
</script>
</html>

Loading…
Cancel
Save