feat: 在线支付记录合并; 汇总统计;

feature/pay
lyt 5 years ago
parent 798cfd14b6
commit d868b371c3

@ -1,4 +1,5 @@
<?php
$config["method_code"] = 15015;
$config['app_id'] = "2017092108849921";
$config['seller_id'] = "2088221900308281";
$config['notify_url'] = "http://www.mycht.cn/webht.php/apps/pay/alipaytradeservice/alipay_notice";

@ -12,6 +12,8 @@ class PaymentService extends CI_Controller {
$this->config->load('wxpay', true);
$this->config->load('paypal', true);
$this->load->library('ipaylinks_call');
$this->load->library('wxpay_call');
$this->load->library('alipay_call');
$this->load->model('Online_payment_note_model', 'note_model');
$this->load->model('Online_payment_account_model', 'account_model');
}
@ -21,7 +23,7 @@ class PaymentService extends CI_Controller {
"15010" => "PayPal",
"15015" => "Alipay",
"15016" => "WeChat",
"15018" => "Credit Card",
"15018" => "Credit Card-iPaylinks",
);
public function index()
@ -663,5 +665,167 @@ class PaymentService extends CI_Controller {
return;
}
public function wechat_settlement($year, $month)
{
set_time_limit(0);
ignore_user_abort(true);
$target_folder = "wechat-" . $year;
$target_file = $year . "." . $month;
// $target_file .= ($day===null) ? null : ("-" . $day);
$statement_folder = FCPATH.'download_statement\settlement_files\\' . $target_folder;
if ( ! is_dir($statement_folder)) {
echo "read folder failed";
return;
}
$files = array_values(array_diff(scandir($statement_folder), array('.', '..')));
if (empty($files)) {
echo "none excel.";
return;
}
$file_path_output = "";
foreach ($files as $k => $fe) {
if ( ! in_array(strrchr($fe, '.'), array(".xlsx", ".xls"))) {
continue;
}
if (stripos($fe, $target_file)===false) {
continue;
}
$file_path = $statement_folder . '\\' . $fe;
if ( ! file_exists($file_path)) {
continue;
}
$settlement_record = $this->wxpay_call->read_settlement_excel($file_path);
$update_cnt = $this->wxpay_call->save_settlement_excel($settlement_record);
// log_message('error','0' . PHP_EOL . var_export($settlement_record[0], 1));
// $update_cnt = 0;
$file_path_output .= "\r\n" . $file_path;
if ($k > 0) {
break;
}
}
$result = "Store $update_cnt records;" . $file_path_output;
log_message('error', $result);
echo $result;
return;
}
public function alipay_settlement($year, $month)
{
set_time_limit(0);
ignore_user_abort(true);
$target_folder = "alipay-" . $year;
$target_file = $year . "." . $month;
// $target_file .= ($day===null) ? null : ("-" . $day);
$statement_folder = FCPATH.'download_statement\settlement_files\\' . $target_folder;
if ( ! is_dir($statement_folder)) {
echo "read folder failed";
return;
}
$files = array_values(array_diff(scandir($statement_folder), array('.', '..')));
if (empty($files)) {
echo "none excel.";
return;
}
$file_path_output = "";
foreach ($files as $k => $fe) {
if ( ! in_array(strrchr($fe, '.'), array(".xlsx", ".xls"))) {
continue;
}
if (stripos($fe, $target_file)===false) {
continue;
}
$file_path = $statement_folder . '\\' . $fe;
if ( ! file_exists($file_path)) {
continue;
}
$settlement_record = $this->alipay_call->read_settlement_excel($file_path);
$update_cnt = $this->alipay_call->save_settlement_excel($settlement_record);
// log_message('error','0' . PHP_EOL . var_export($settlement_record[0], 1));
// $update_cnt = 0;
$file_path_output .= "\r\n" . $file_path;
if ($k > 0) {
break;
}
}
$result = "Store $update_cnt records;" . $file_path_output;
log_message('error', $result);
echo $result;
return;
}
public function income_statistics()
{
$this->permission->is_admin(true);
$date_range = $this->input->post("date_range");
preg_match_all('/\d{4}\-\d{2}\-\d{2}/', $date_range, $date_range_arr);
if (empty($date_range_arr[0])) {
// $data['from_date'] = date("Y-m-d", strtotime("-8 days"));
// $data['to_date'] = date("Y-m-d", strtotime("-1 days"));
$data['from_date'] = date("Y-m-01", strtotime("-1 month"));
$data['to_date'] = date("Y-m-01");
} else {
$data['from_date'] = $date_range_arr[0][0];
$data['to_date'] =$date_range_arr[0][1] . " 23:59:59";
if ($data['to_date'] == null) {
$data['to_date'] = date("Y-m-d H:i:s", strtotime("+1 month", strtotime($data['from_date']))-1);
}
}
$data['at_year'] = date('Y-01-01', strtotime($data['to_date']));
$data['day_cnt'] = calc_day_cnt($data['from_date'], $data['to_date']);
$data['from_date_quarter'] = date('Y-m-d', strtotime("-" . $data['day_cnt'] . " days ", strtotime($data['from_date'])));
$data['to_date_quarter'] = date('Y-m-d', strtotime("-" . $data['day_cnt'] . " days ", strtotime($data['to_date'])));
$data['from_date_year'] = date('Y-m-d', strtotime("-1 year ", strtotime($data['from_date'])));
$data['to_date_year'] = date('Y-m-d', strtotime("-1 year ", strtotime($data['to_date'])));
$data['data']['pay'] = $this->note_model->total_by_method('pay',
$data['from_date'], $data['to_date'],
$data['from_date_quarter'], $data['to_date_quarter'],
$data['from_date_year'], $data['to_date_year'],
$data['at_year']
);
array_walk($data['data']['pay'], 'PaymentService::set_brandname');
$data['data']['refund'] = $this->note_model->total_by_method('refund',
$data['from_date'], $data['to_date'],
$data['from_date_quarter'], $data['to_date_quarter'],
$data['from_date_year'], $data['to_date_year'],
$data['at_year']
);
array_walk($data['data']['refund'], 'PaymentService::set_brandname');
$data['data']['income'] = array();
bcscale(4);
foreach ($data['data']['pay'] as $key => $pay) {
$income_tmp = new stdClass();
foreach ($data['data']['refund'] as $key => $refund) {
if ($pay->OPN_accountMethod === $refund->OPN_accountMethod) {
$income_tmp->OPN_accountMethod = $pay->OPN_accountMethod;
$income_tmp->brand_name = $pay->brand_name;
$income_tmp->method_total_income = bcadd($pay->method_total_income, $refund->method_total_income);
$income_tmp->method_total_income_cmp = bcadd($pay->method_total_income_cmp, $refund->method_total_income_cmp);
$income_tmp->year_method_total_income = bcadd($pay->year_method_total_income, $refund->year_method_total_income);
$income_tmp->this_year_method_total_income = bcadd($pay->this_year_method_total_income, $refund->this_year_method_total_income);
$income_tmp->quarter_rate = $income_tmp->method_total_income_cmp==0 ? 0 :
bcdiv(
bcsub($income_tmp->method_total_income, $income_tmp->method_total_income_cmp),
($income_tmp->method_total_income_cmp)
)*100;
$income_tmp->year_rate = $income_tmp->year_method_total_income==0 ? 0 :
bcdiv(
bcsub($income_tmp->method_total_income, $income_tmp->year_method_total_income),
($income_tmp->year_method_total_income)
)*100;
$data['data']['income'][] = $income_tmp;
}
}
}
$this->load->view('income', $data, FALSE);
return;
}
}

@ -302,3 +302,17 @@ function set_url_param($param_arr=array())
$param_arr = $current_param===null ? $param_arr : array_merge($current_param, $param_arr);
return strstr($_SERVER['REQUEST_URI'],'?', true) . "?" . http_build_query($param_arr);
}
function calc_day_cnt($from, $to)
{
$now = new DateTime($to);
$start = new DateTime(($from));
$date_d = $now->diff($start);
$d_t = ($date_d->format("%a"));
return $d_t;
}
function zero_to_one($value)
{
return $value==0 ? 1 : $value;
}

@ -0,0 +1,154 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Alipay_call
{
protected $ci;
public function __construct()
{
$this->ci =& get_instance();
$this->ci->load->helper('payment');
$this->ci->config->load('alipay', true);
$this->ci->load->model('Online_payment_note_model', 'note_model');
$this->ci->load->model('Online_payment_account_model', 'account_model');
}
/**
*/
public function read_settlement_excel($filePath, $sheetIndex=0)
{
$tarr1=array();
$this->ci->load->library('PHPExcel');
$PHPExcel = new PHPExcel();
/**默认用excel2007读取excel若格式不对则用之前的版本进行读取*/
$PHPReader = new PHPExcel_Reader_Excel2007();
if(!$PHPReader->canRead($filePath)){
$PHPReader = new PHPExcel_Reader_Excel5();
if(!$PHPReader->canRead($filePath)){
echo 'no Excel';
return ;
}
}
$PHPExcel = $PHPReader->load($filePath);
/**读取excel文件中的第一个工作表*/
$currentSheet = $PHPExcel->getSheet($sheetIndex);
/**取得最大的列号*/
$allColumn = $currentSheet->getHighestColumn();
/**取得一共有多少行*/
$allRow = $currentSheet->getHighestRow();
log_message('error','total row' . PHP_EOL . var_export($allRow, 1));
$col_titles = $this->settlement_excel_title();
/**从第二行开始输出因为excel表中第一行为列名*/
for($currentRow = 2;$currentRow <= $allRow;$currentRow++){
$row_tmp = array();
/**从第A列开始输出*/
$columnNum = 0;
// for($currentColumn= 'A';$currentColumn<= "AD"; $currentColumn++){
// 列标题Z之后的不能直接用逻辑运算
for($currentColumn= 'A';str_pad($currentColumn, 2, "0", STR_PAD_LEFT)<= $allColumn; $currentColumn++){
/**ord()将字符转为十进制数*/
// $val = trim($currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65,$currentRow)->getValue());
// 列标题Z之后不能直接用ord计算ASCII码,因ord仅返回第一个字符的结果导致列AA的值读取到列A
$val = trim($currentSheet->getCellByColumnAndRow($columnNum,$currentRow)->getValue());
if ( ! isset($col_titles[$currentColumn])) {
continue;
}
if ($currentColumn==='D' && !in_array(trim($val), array('交易', '交易退款'))) {
$row_tmp = array();
break;
}
$col_mean = $col_titles[$currentColumn];
$row_tmp[$col_mean] = trim($val)==='-' ? '' : str_replace('`','',$val);
$columnNum++;
}
if ( ! empty($row_tmp)) {
$tarr1[] = $row_tmp;
}
}
return $tarr1;
}
public function save_settlement_excel($excel_data)
{
$settle_cnt = 0;
foreach ($excel_data as $settle) {
$save_column = array();
$save_column['OPN_accountMethod'] = $this->ci->config->item('method_code', 'alipay');
$save_column['OPN_noticeType'] = trim($settle['trade_type']) === '交易' ? 'pay' : 'refund';
$save_column['OPN_fundSource'] = 'cht';
$save_column['OPN_transactionId'] = $settle['transaction_id'];
// $save_column['OPN_relatedId'] = str_ireplace("-", '', $settle['related_id']);
$save_column['OPN_orderAmount'] = bcsub(floatval($settle['trade_amount']),floatval($settle['refund_amount']));
$save_column['OPN_orderId'] = $settle['orderid'];
$note_exists = $this->ci->note_model->if_note_exists($settle['transaction_id']);
// test:
if (true === $note_exists) {
continue;
}
// test: 月账单太长
if ($settle_cnt > 999) {
break;
}
$order_info = $this->ci->account_model
->get_gai(
$save_column['OPN_transactionId'],
$save_column['OPN_orderId'],
$save_column['OPN_orderAmount'],
$save_column['OPN_accountMethod']
);
if ($order_info['data'] !== null) {
$save_column['OPN_orderId'] = $order_info['data']->orderId;
$save_column['OPN_accountType'] = $order_info['type'];
$save_column['OPN_accountStatus'] = 'recorded';
}
$save_column['OPN_subject'] = $settle['item_name'];
$save_column['OPN_payAmount'] = $save_column['OPN_orderAmount'];
$save_column['OPN_noticeSendStatus'] = 'closed';
$save_column['OPN_transactionResult'] = 'completed';
$save_column['OPN_rawOrderId'] = $settle['orderid'];
$save_column['OPN_invoiceId'] = $settle['orderid'];
$save_column['OPN_currency'] = 'CNY'; // $settle['trade_currency'];
$save_column['OPN_acquiringTime'] = $settle['complete_date'];
$save_column['OPN_completeTime'] = $settle['complete_date'];
$save_column['OPN_remark'] = $settle['remark'];
$save_column['OPN_rawContent'] = json_encode($settle, JSON_UNESCAPED_UNICODE);
$save_column['OPN_noticeTime'] = date('Y-m-d H:i:s');
$note_exists = $this->ci->note_model->if_note_exists($settle['transaction_id'], $settle['orderid']);
if (true === $note_exists) {
// update
$update_where = " OPN_transactionId='" . $settle['transaction_id'] . "' AND OPN_rawOrderId='" . $settle['orderid'] . "' ";
$this->ci->note_model->update_note($update_where, $save_column) ;
$settle_cnt++;
} elseif (false === $note_exists) {
// insert
$this->ci->note_model->insert_note($save_column) ;
$settle_cnt++;
}
}
return $settle_cnt;
}
/**
* 入账时间 支付宝交易号 商户订单号 账务类型 收入(+元) 支出(-元) 商品名称 备注
*/
private function settlement_excel_title()
{
return array(
"A" => "complete_date",
"B" => "transaction_id",
"C" => "orderid",
"D" => "trade_type",
"E" => "trade_amount",
"F" => "refund_amount",
"G" => "item_name",
"H" => "remark"
);
}
}
/* End of file Alipay_call.php */

@ -20,10 +20,10 @@ class Ipaylinks_call
$settle_cnt = 0;
foreach ($excel_data as $key => $settle) {
// test:
// $note_exists = $this->ci->note_model->if_note_exists($settle['transaction_id'], $settle['orderid']);
// if (true === $note_exists) {
// continue;
// }
$note_exists = $this->ci->note_model->if_note_exists($settle['transaction_id'], $settle['orderid']);
if (true === $note_exists) {
continue;
}
$save_column = array();
$save_column['OPN_accountMethod'] = $this->ci->config->item('method_code', 'ipaylinks');
$save_column['OPN_invoiceId'] = $settle['orderid'];

@ -278,6 +278,140 @@ class Wxpay_call
return $reponse;
}
public function read_settlement_excel($filePath, $sheetIndex=0)
{
$tarr1=array();
$this->ci->load->library('PHPExcel');
$PHPExcel = new PHPExcel();
/**默认用excel2007读取excel若格式不对则用之前的版本进行读取*/
$PHPReader = new PHPExcel_Reader_Excel2007();
if(!$PHPReader->canRead($filePath)){
$PHPReader = new PHPExcel_Reader_Excel5();
if(!$PHPReader->canRead($filePath)){
echo 'no Excel';
return ;
}
}
$PHPExcel = $PHPReader->load($filePath);
/**读取excel文件中的第一个工作表*/
$currentSheet = $PHPExcel->getSheet($sheetIndex);
/**取得最大的列号*/
$allColumn = $currentSheet->getHighestColumn();
/**取得一共有多少行*/
$allRow = $currentSheet->getHighestRow();
$col_titles = $this->settlement_excel_title();
/**从第二行开始输出因为excel表中第一行为列名*/
for($currentRow = 2;$currentRow <= $allRow;$currentRow++){
$row_tmp = array();
/**从第A列开始输出*/
$columnNum = 0;
// for($currentColumn= 'A';$currentColumn<= "AD"; $currentColumn++){
// 列标题Z之后的不能直接用逻辑运算
for($currentColumn= 'A';str_pad($currentColumn, 2, "0", STR_PAD_LEFT)<= $allColumn; $currentColumn++){
/**ord()将字符转为十进制数*/
// $val = trim($currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65,$currentRow)->getValue());
// 列标题Z之后不能直接用ord计算ASCII码,因ord仅返回第一个字符的结果导致列AA的值读取到列A
$val = trim($currentSheet->getCellByColumnAndRow($columnNum,$currentRow)->getValue());
if ( ! isset($col_titles[$currentColumn])) {
continue;
}
if ($currentColumn==='A' && trim($val)=='') {
break;
}
$col_mean = $col_titles[$currentColumn];
$row_tmp[$col_mean] = trim($val)==='-' ? '' : str_replace('`','',$val);
$columnNum++;
}
if ( ! empty($row_tmp)) {
$tarr1[] = $row_tmp;
}
}
return $tarr1;
}
public function save_settlement_excel($excel_data)
{
$settle_cnt = 0;
foreach ($excel_data as $settle) {
$save_column = array();
$save_column['OPN_accountMethod'] = $this->ci->config->item('method_code', 'wxpay');
$save_column['OPN_noticeType'] = trim($settle['trade_type']) === 'SUCCESS' ? 'pay' : 'refund';
$save_column['OPN_fundSource'] = 'cht';
$save_column['OPN_transactionId'] = $settle['transaction_id'];
// $save_column['OPN_relatedId'] = str_ireplace("-", '', $settle['related_id']);
$save_column['OPN_orderAmount'] = bcsub($settle['trade_amount'],$settle['refund_amount']);
$save_column['OPN_orderId'] = $settle['orderid'];
$note_exists = $this->ci->note_model->if_note_exists($settle['transaction_id']);
// test:
if (true === $note_exists) {
continue;
}
// test: 月账单太长
if ($settle_cnt > 999) {
break;
}
$order_info = $this->ci->account_model
->get_gai(
$save_column['OPN_transactionId'],
$save_column['OPN_orderId'],
$save_column['OPN_orderAmount'],
$save_column['OPN_accountMethod']
);
if ($order_info['data'] !== null) {
$save_column['OPN_orderId'] = $order_info['data']->orderId;
$save_column['OPN_accountType'] = $order_info['type'];
$save_column['OPN_accountStatus'] = 'recorded';
}
$save_column['OPN_subject'] = $settle['orderid'];
$save_column['OPN_payAmount'] = $save_column['OPN_orderAmount'];
$save_column['OPN_noticeSendStatus'] = 'closed';
$save_column['OPN_transactionResult'] = 'completed';
$save_column['OPN_rawOrderId'] = $settle['orderid'];
$save_column['OPN_invoiceId'] = $settle['orderid'];
$save_column['OPN_currency'] = $settle['trade_currency'];
$save_column['OPN_acquiringTime'] = $settle['complete_date'];
$save_column['OPN_completeTime'] = $settle['complete_date'];
$save_column['OPN_remark'] = $settle['fund_source'];
$save_column['OPN_rawContent'] = json_encode($settle, JSON_UNESCAPED_UNICODE);
$save_column['OPN_noticeTime'] = date('Y-m-d H:i:s');
$note_exists = $this->ci->note_model->if_note_exists($settle['transaction_id'], $settle['orderid']);
if (true === $note_exists) {
// update
$update_where = " OPN_transactionId='" . $settle['transaction_id'] . "' AND OPN_rawOrderId='" . $settle['orderid'] . "' ";
$this->ci->note_model->update_note($update_where, $save_column) ;
$settle_cnt++;
} elseif (false === $note_exists) {
// insert
$this->ci->note_model->insert_note($save_column) ;
$settle_cnt++;
}
}
return $settle_cnt;
}
/**
* 交易时间 商户号 微信订单号 商户订单号 交易状态 付款银行 货币种类 应结订单金额 退款金额 手续费 费率 结算金额
*/
private function settlement_excel_title()
{
return array(
"A" => "complete_date",
"B" => "mch_id",
"C" => "transaction_id",
"D" => "orderid",
"E" => "trade_source",
"F" => "trade_type",
"G" => "fund_source",
"H" => "trade_currency",
"I" => "trade_amount",
"J" => "refund_amount",
"K" => "trade_fee",
"L" => "fee_rate",
"M" => "settlement_amount"
);
}
}
/* End of file Wxpay_call.php */

@ -199,6 +199,226 @@ class Online_payment_note_model extends CI_Model {
return $this->query_note();
}
/**
*
* @param [type] $pay_method
*
* 选择日期:
* @param [type] $from_date
* @param [type] $to_date
*
* 环比日期:
* @param [type] $from_date_fomer
* @param [type] $to_date_former
*
* 上年同期:
* @param [type] $from_date_year
* @param [type] $to_date_year
*
* 本年度开始日期: {Year}-01-01
* @param [type] $at_year
*/
public function total_by_method($pay_method,
$from_date, $to_date,
$from_date_fomer, $to_date_former,
$from_date_year, $to_date_year,
$at_year
)
{
$sql = " SET NOCOUNT ON;
DECLARE @type varchar(10)='$pay_method'
declare @this_year date='$at_year'
declare @from_date date='$from_date'
declare @to_date date='$to_date'
declare @from_date_former date='$from_date_fomer'
declare @to_date_former date='$to_date_former'
declare @from_date_last_year date='$from_date_year'
declare @to_date_last_year date='$to_date_year'
declare @unique_opn table (
id bigint IDENTITY(1,1) primary key,
--opn_sn bigint,
OPN_transactionId varchar(512),
OPN_accountMethod varchar(100),
OPN_noticeType varchar(100),
OPN_currency varchar(100),
OPN_orderAmount varchar(512),
OPN_entryAmountCNY varchar(512),
OPN_completeTime date
)
insert into @unique_opn (
--opn_sn ,
OPN_transactionId ,
OPN_accountMethod ,
OPN_noticeType ,
OPN_currency ,
OPN_orderAmount ,
OPN_entryAmountCNY ,
OPN_completeTime
)
select
--opn_sn ,
OPN_transactionId ,
OPN_accountMethod ,
OPN_noticeType ,
OPN_currency ,
OPN_orderAmount ,
OPN_entryAmountCNY ,
OPN_completeTime
from InfoManager.dbo.OnlinePaymentNote
where OPN_completeTime>@from_date_last_year
group by
--opn_sn ,
OPN_transactionId ,
OPN_accountMethod ,
OPN_noticeType ,
OPN_currency ,
OPN_orderAmount ,
OPN_entryAmountCNY ,
OPN_completeTime
SELECT OPN_accountMethod
,method_total_income,method_total_income_cmp
,isnull(year_method_total_income,0) year_method_total_income
,this_year_method_total_income
--,REPLACE(CONVERT(VARCHAR, CONVERT(MONEY, method_total_income), 1), '.00', '') method_total_income
--,REPLACE(CONVERT(VARCHAR, CONVERT(MONEY, method_total_income_cmp), 1), '.00', '') method_total_income_cmp
,CONVERT(decimal(10,2),
round( (method_total_income-method_total_income_cmp)/method_total_income_cmp*100 ,2 )
) AS quarter_rate
--,REPLACE(CONVERT(VARCHAR, CONVERT(MONEY, isnull(year_method_total_income,0)), 1), '.00', '') year_method_total_income
,CONVERT(decimal(10,2),
round( (method_total_income-year_method_total_income)/year_method_total_income*100 ,2 )
) AS year_rate
--,REPLACE(CONVERT(VARCHAR, CONVERT(MONEY, this_year_method_total_income), 1), '.00', '') this_year_method_total_income
FROM
(
SELECT *
FROM
(
SELECT OPN_accountMethod
,SUM(
ISNULL( CONVERT(decimal(10,2),OPN_entryAmountCNY),
Tourmanager.dbo.GetSSJEFromSQJE(
OPN_accountMethod,
REPLACE(OPN_currency, 'CNY', 'RMB'),
CONVERT(decimal(10,2),OPN_orderAmount)
)
)
) AS method_total_income
FROM @unique_opn
WHERE OPN_completeTime BETWEEN @from_date AND @to_date
and OPN_noticeType=@type
GROUP BY OPN_accountMethod
) AS method
INNER JOIN
(
SELECT SUM(
[Tourmanager].[dbo].ZeroToOne(
ISNULL( CONVERT(decimal(10,2),OPN_entryAmountCNY),
Tourmanager.dbo.GetSSJEFromSQJE(
OPN_accountMethod,
REPLACE(OPN_currency, 'CNY', 'RMB'),
CONVERT(decimal(10,2),OPN_orderAmount)
)
)
)
) AS total_income
FROM @unique_opn
WHERE OPN_completeTime BETWEEN @from_date AND @to_date
and OPN_noticeType=@type
) AS total ON 1=1
inner join (
SELECT OPN_accountMethod last_method
,SUM(
[Tourmanager].[dbo].ZeroToOne(
ISNULL( CONVERT(decimal(10,2),OPN_entryAmountCNY),
Tourmanager.dbo.GetSSJEFromSQJE(
OPN_accountMethod,
REPLACE(OPN_currency, 'CNY', 'RMB'),
CONVERT(decimal(10,2),OPN_orderAmount)
)
)
)
) AS method_total_income_cmp
FROM @unique_opn
WHERE OPN_completeTime BETWEEN @from_date_former AND @to_date_former
and OPN_noticeType=@type
GROUP BY OPN_accountMethod
) as cmp on method.OPN_accountMethod=cmp.last_method
left join (
SELECT OPN_accountMethod year_method
,SUM(
[Tourmanager].[dbo].ZeroToOne(
ISNULL( CONVERT(decimal(10,2),OPN_entryAmountCNY),
Tourmanager.dbo.GetSSJEFromSQJE(
OPN_accountMethod,
REPLACE(OPN_currency, 'CNY', 'RMB'),
CONVERT(decimal(10,2),OPN_orderAmount)
)
)
)
) AS year_method_total_income
FROM @unique_opn
WHERE OPN_completeTime BETWEEN @from_date_last_year AND @to_date_last_year
and OPN_noticeType=@type
GROUP BY OPN_accountMethod
) as year_cmp on method.OPN_accountMethod=year_cmp.year_method
left join (
SELECT OPN_accountMethod this_year_method
,SUM(
[Tourmanager].[dbo].ZeroToOne(
ISNULL( CONVERT(decimal(10,2),OPN_entryAmountCNY),
Tourmanager.dbo.GetSSJEFromSQJE(
OPN_accountMethod,
REPLACE(OPN_currency, 'CNY', 'RMB'),
CONVERT(decimal(10,2),OPN_orderAmount)
)
)
)
) AS this_year_method_total_income
FROM @unique_opn
WHERE OPN_completeTime BETWEEN @this_year AND @to_date
and OPN_noticeType=@type
GROUP BY OPN_accountMethod
) as this_year_cmp on method.OPN_accountMethod=this_year_cmp.this_year_method
) AS cal
";
// var_dump($this->info->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);
//每一个select都会产生一个结果集取某个结果集就需要从第一个移动到需要的那个结果集
//如果结果集为空就移到下一个
while (sqlsrv_has_rows($stmt) !== TRUE) {
sqlsrv_next_result($stmt);
}
$result_object = array();
while ($row = sqlsrv_fetch_object($stmt)) {
$result_object[] = $row;
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
return $result_object;
}
}

@ -0,0 +1,180 @@
<?php
/**
* 账单结算
*/
?>
<!DOCTYPE html>
<html>
<head>
<title>在线支付统计</title>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1.0, user-scalable=no" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta name="referrer" content="always">
<link href="http://www.mycht.cn/css/webht/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="http://www.mycht.cn/css/bootstrap-datetimepicker.min.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<!-- <?php // include 'flatpickr.css.php';
?> -->
<style type="text/css">
form {
border-bottom: 1px solid #ccc;
}
.navbar-header h1 {
display: inline-block;
margin-left: 30px;
margin-right: 30px;
}
label {
display: inline-block;
max-width: none;
margin-bottom: 5px;
font-weight: bold;
}
.form-check-label {
font-weight: normal;
margin-left: 5px;
}
thead th {
text-align: center;
}
tbody td {
text-align: right;
}
.bg-grey {
background-color: #f5f5f5;
}
.text-left {
text-align: left;
}
.text-right {
text-align: right;
}
.text-bold {
font-weight: bold;
}
</style>
</head>
<body>
<div id="wrapper" class="chkVisible print-none">
<div class="navbar-header" style="float:none;border-bottom: 1px solid #ccc;">
<a class="navbar-brand text-muted" style="height: 52px;padding-top: 7px;padding-left: 30px;" href="http://www.mycht.cn/webht.php/index/index">
<img width="150" style="height:40px;" src="/css/nav/img/6000.png">
</a>
<h1>在线支付统计</h1>
<ul class="nav navbar-nav navbar-right pull-right" style="margin:7.5px 0;">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><?php $userdata = $this->session->userdata('admin_chtcdn');
echo $userdata['OPI_Name']; ?> <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="<?php echo site_url('login/logout'); ?>">退出</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="container-fluid">
<p></p>
<form action="/webht.php/apps/pay/paymentservice/income_statistics" method="POST" role="form">
<div class="form-group row">
<label for="" class="col-md-2">交易日期</label>
<div class="col-md-6">
<input type="text" class="form-control" name="date_range" id="date_range" placeholder="选择日期范围" required>
</div>
<div class="col-md-3">
<!-- <input type="text" class="form-control" id="end_date" placeholder="结束日期"> -->
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
<p></p>
<?php foreach ($data as $key => $table) { ?>
<table class="table table-bordered table-hover">
<thead>
<?php switch ($key) {
case 'pay':
?>
<tr class="bg-info">
<th colspan="7"> 付款
</th>
</tr>
<?php break;
case 'refund': ?>
<tr class="bg-danger">
<th colspan="7"> 退款
</th>
</tr>
<?php break;
case 'income': ?>
<tr class="bg-success">
<th colspan="7"> 收入
</th>
</tr>
<?php
default:
break;
} ?>
<tr>
<th>付款方式</th>
<th>金额</th>
<th>
上期 ( 前 <?php echo $day_cnt ?> 天 )<br>
<?php echo $from_date_quarter ?><?php echo $to_date_quarter ?>
</th>
<th>环比</th>
<th>上年同期<br>
<?php echo $from_date_year ?><?php echo $to_date_year ?>
</th>
<th>同比</th>
<th>当年截止<br>
<?php echo $at_year ?><?php echo $to_date ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($table as $kt => $method) { ?>
<tr>
<td><?php echo $method->brand_name ?></td>
<td><?php echo number_format($method->method_total_income, 2, '.', ',') ?></td>
<td><?php echo number_format($method->method_total_income_cmp, 2, '.', ',') ?></td>
<td><?php echo number_format($method->quarter_rate, 2, '.', ',') . '%' ?></td>
<td><?php echo number_format($method->year_method_total_income, 2, '.', ',') ?></td>
<td><?php echo number_format($method->year_rate, 2, '.', ',') . '%' ?></td>
<td><?php echo number_format($method->this_year_method_total_income, 2, '.', ',') ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
</body>
<script src="/js/jquery.min.js" type="text/javascript"></script>
<script src="/js/bootstrap.min.js" type="text/javascript"></script>
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#date_range").flatpickr({
dateFormat: 'Y-m-d',
mode: 'range',
allowInput: true,
defaultDate: ['<?php echo $from_date ?>', '<?php echo $to_date ?>']
});
})
</script>
</html>

@ -25,7 +25,7 @@
.wechat-color {background-color: #62B900;}
.paypal-color {background-color: #002D89;}
.alipay-color {background-color: #00AAEE;}
.ipaylinks-color,.creditcard-color {background-color: #A31022;}
.ipaylinks-color,.creditcard-color,.creditcard-ipaylinks-color {background-color: #A31022;}
.modal {background-color: rgba(0,0,0,0.075);}
</style>
<style type="text/css" media="screen and (max-width:767px)">
@ -140,6 +140,9 @@
<a <?php if($method_code==='15015') { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('method'=>15015)) ?>">支付宝&raquo;</a>
&NonBreakingSpace;
&boxv;&NonBreakingSpace;
<a target="_blank" href="/webht.php/apps/pay/paymentservice/income_statistics">汇总统计&raquo;</a>
<ul class="nav navbar-nav navbar-right pull-right" style="margin:7.5px 0;">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><?php $userdata=$this->session->userdata('admin_chtcdn'); echo $userdata['OPI_Name']; ?> <span class="caret"></span></a>

@ -153,7 +153,7 @@ class Note_model extends CI_Model {
UPDATE paypal_note
SET pn_invoice = ?
WHERE pn_txn_id = ?
";
";
return $this->HT->query($sql, array($pn_invoice, $pn_txn_id));
}

Loading…
Cancel
Save