测试退款的财务通知

feature/pay
lyt 7 years ago
parent 1d40a0d2a4
commit bad9e43339

@ -387,5 +387,84 @@ log_message('error','send_notify begin ----');
return;
}
/*!
* 发送状态是send-to-finance的记录
* refund-imported
* @date 2019-05-15
*/
public function refund_finance_notify()
{
$all_list = $this->account_model->get_refund_imported();
if (empty($all_list)) {
echo "No refund record.";
return false;
}
$this->load->library('PHPExcel');
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
//set width
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15); // 部门
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30); // 团号
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15); // 金额
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15); // 币种
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15); // 人民币
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20); // 付款人
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30); // 邮箱
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(20); // 交易号
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(20); // 时间
// 对齐
$objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyle('F')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
// 表标题行
$objPHPExcel->getActiveSheet()
->SetCellValue('A1', '#')
->SetCellValue('B1', '部门')
->SetCellValue('C1', '团号')
->SetCellValue('D1', '金额')
->SetCellValue('E1', '币种')
->SetCellValue('F1', '人民币')
->SetCellValue('G1', '付款人')
->SetCellValue('H1', '邮箱')
->SetCellValue('I1', '交易号')
->SetCellValue('J1', '时间');
$currency_sum = array();
bcscale(2);
$rowCount = 2;
foreach ($all_list as $key => $row) {
$objPHPExcel->getActiveSheet()
->SetCellValue('A'.$rowCount, ($rowCount-1))
->SetCellValue('B'.$rowCount, $row['department'])
->setCellValueExplicit('C'.$rowCount, $row['gri_name'], PHPExcel_Cell_DataType::TYPE_STRING)
->setCellValueExplicit('D'.$rowCount, number_format($row['amount'], 2, ".", ""),PHPExcel_Cell_DataType::TYPE_STRING)
->SetCellValue('E'.$rowCount, trim($row['currency']))
->setCellValueExplicit('F'.$rowCount, $row['amount_CNY'], PHPExcel_Cell_DataType::TYPE_STRING)
->SetCellValue('G'.$rowCount, $row['payer'])
->SetCellValue('H'.$rowCount, $row['payer_email'])
->setCellValueExplicit('I'.$rowCount, $row['transaction_id'], PHPExcel_Cell_DataType::TYPE_STRING)
->SetCellValue('J'.$rowCount, $row['payment_date']);
$rowCount++;
}
$filename = "refund_imported_" . date('Y-m-d_H_i_s');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save(FCPATH . "download_statement/refund/" . $filename . ".xls");
if (file_exists(FCPATH . "download_statement/refund/" . $filename . ".xls")) {
// 保存成功:更新标记,邮件
foreach ($all_list as $ka => $va) {
// $this->account_model->update_send_fiance($va['note_sn'], $va['payment_type']);
}
$fromName = 'refund imported';
$fromEmail = '';
$toName = 'lyt';
$toEmail = 'lyt@hainatravel.com';
$subject = $filename;
$body = "https://www.mycht.cn/download_statement/refund/" . $filename . ".xls";
$M_AddTime = date('Y-m-d_H_i_s');
$M_State = 0;
$this->account_model->save_automail($fromName, $fromEmail, $toName, $toEmail, $subject, $body, 0, $M_State, $M_AddTime, 'refund imported', 'refund imported');
}
return false;
}
}

@ -341,5 +341,70 @@ class Online_payment_account_model extends CI_Model {
return $this->HT->query($sql, $gri_sn)->num_rows() > 0;
}
/*!
* 查询标记为需要发送财务的退款记录send-to-finance
* TODO 异步通知合并
* @date 2019-05-15
*/
public function get_refund_imported()
{
$ret = array();
$paypal_sql = "SELECT 'paypal' as 'payment_type', pn_sn note_sn, pn_txn_id transaction_id,
(select DEI_DepartmentName from OperatorInfo inner join DepartmentInfo on OPI_DEI_SN=DEI_SN
where OPI_SN=ISNULL(coli.COLI_OPI_ID, bcoli.COLI_OPI_ID)) as department,
(select GRI_Name from GRoupInfo where gri_sn=ISNULL(coli.COLI_GRI_SN,bcoli.COLI_GRI_SN)) as gri_name,
pn.pn_payment_date payment_date,
pn.pn_mc_gross amount,pn_mc_currency currency,
isnull(gai.GAI_SSJE,bgai.GAI_SSJE) amount_CNY,
pn_payer payer,pn_payer_email payer_email
from paypal_note pn
left join GroupAccountInfo gai on gai.GAI_AccreditNo=pn.pn_txn_id
left join ConfirmLineInfo coli on coli.COLI_SN=gai.GAI_COLI_SN
left join BIZ_GroupAccountInfo bgai on bgai.GAI_AccreditNo=pn.pn_txn_id
left join BIZ_ConfirmLineInfo bcoli on bcoli.COLI_SN=bgai.GAI_COLI_SN
where pn_send='send-to-finance' ";
$ret = $paypal_list = $this->HT->query($paypal_sql)->result_array();
$ipaylinks_sql = "SELECT 'ipaylinks' as 'payment_type', IPL_sn note_sn,IPL_dealId transaction_id,
(select DEI_DepartmentName from OperatorInfo inner join DepartmentInfo on OPI_DEI_SN=DEI_SN
where OPI_SN=ISNULL(coli.COLI_OPI_ID, bcoli.COLI_OPI_ID)) as department,
(select GRI_Name from GRoupInfo where gri_sn=ISNULL(coli.COLI_GRI_SN,bcoli.COLI_GRI_SN)) as gri_name,
pn.IPL_completeTime payment_date,
pn.IPL_orderAmount amount,
isnull(IPL_currencyCode,isnull(gai.GAI_SQJECurrency,bgai.GAI_SQJECurrency)) currency,
isnull(gai.GAI_SSJE,bgai.GAI_SSJE) amount_CNY,
isnull(IPL_payerName,isnull(gai.GAI_CusName,bgai.GAI_CusName)) payer,
isnull(IPL_payerEmail,ISNULL(gai.gai_cusEmail,bgai.gai_cusemail)) payer_email
from InfoManager.dbo.IPayLinksLog pn
left join GroupAccountInfo gai on gai.GAI_AccreditNo=pn.IPL_dealId
left join ConfirmLineInfo coli on coli.COLI_SN=gai.GAI_COLI_SN
left join BIZ_GroupAccountInfo bgai on bgai.GAI_AccreditNo=pn.IPL_dealId
left join BIZ_ConfirmLineInfo bcoli on bcoli.COLI_SN=bgai.GAI_COLI_SN
where IPL_sent='send-to-finance' ";
$ipaylinks_list = $this->HT->query($ipaylinks_sql)->result_array();
if ( ! empty($ipaylinks_list)) {
$ret = array_merge($paypal_list, $ipaylinks_list);
}
return $ret;
}
public function update_send_fiance($note_sn, $payment_type)
{
$sql = "";
switch ($payment_type) {
case 'paypal':
$sql = " UPDATE Tourmanager.dbo.paypal_note SET pn_send = 'send-finance' WHERE pn_sn = ? ";
break;
case 'ipaylinks':
$sql = " UPDATE InfoManager.dbo.IPayLinksLog SET IPL_sent = 'send-finance' WHERE IPL_sn = ? ";
break;
default:
# code...
break;
}
if ($sql==="") {return false;}
return $this->HT->query($sql, $note_sn);
}
}

Loading…
Cancel
Save