From d868b371c3896fa2fcd328dda748d41a140ceccd Mon Sep 17 00:00:00 2001 From: lyt Date: Mon, 23 Mar 2020 17:04:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=E7=BA=BF=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=90=88=E5=B9=B6;=20=E6=B1=87=E6=80=BB?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webht/third_party/pay/config/alipay.php | 1 + .../pay/controllers/PaymentService.php | 166 ++++++++++++- .../pay/helpers/payment_helper.php | 14 ++ .../third_party/pay/libraries/alipay_call.php | 154 ++++++++++++ .../pay/libraries/ipaylinks_call.php | 8 +- .../third_party/pay/libraries/wxpay_call.php | 134 +++++++++++ .../pay/models/Online_payment_note_model.php | 220 ++++++++++++++++++ webht/third_party/pay/views/income.php | 180 ++++++++++++++ webht/third_party/pay/views/payment_list.php | 5 +- .../third_party/paypal/models/note_model.php | 2 +- 10 files changed, 877 insertions(+), 7 deletions(-) create mode 100644 webht/third_party/pay/libraries/alipay_call.php create mode 100644 webht/third_party/pay/views/income.php diff --git a/webht/third_party/pay/config/alipay.php b/webht/third_party/pay/config/alipay.php index ff795035..1c846214 100644 --- a/webht/third_party/pay/config/alipay.php +++ b/webht/third_party/pay/config/alipay.php @@ -1,4 +1,5 @@ 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; + } + } diff --git a/webht/third_party/pay/helpers/payment_helper.php b/webht/third_party/pay/helpers/payment_helper.php index 3be012cd..815fa3c8 100644 --- a/webht/third_party/pay/helpers/payment_helper.php +++ b/webht/third_party/pay/helpers/payment_helper.php @@ -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; +} diff --git a/webht/third_party/pay/libraries/alipay_call.php b/webht/third_party/pay/libraries/alipay_call.php new file mode 100644 index 00000000..277fc588 --- /dev/null +++ b/webht/third_party/pay/libraries/alipay_call.php @@ -0,0 +1,154 @@ +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 */ diff --git a/webht/third_party/pay/libraries/ipaylinks_call.php b/webht/third_party/pay/libraries/ipaylinks_call.php index 649e795e..cbe841dd 100644 --- a/webht/third_party/pay/libraries/ipaylinks_call.php +++ b/webht/third_party/pay/libraries/ipaylinks_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']; diff --git a/webht/third_party/pay/libraries/wxpay_call.php b/webht/third_party/pay/libraries/wxpay_call.php index 85f29fdd..42aff5a4 100644 --- a/webht/third_party/pay/libraries/wxpay_call.php +++ b/webht/third_party/pay/libraries/wxpay_call.php @@ -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 */ diff --git a/webht/third_party/pay/models/Online_payment_note_model.php b/webht/third_party/pay/models/Online_payment_note_model.php index 6ccbed7f..0c4b0d2f 100644 --- a/webht/third_party/pay/models/Online_payment_note_model.php +++ b/webht/third_party/pay/models/Online_payment_note_model.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; + } + } diff --git a/webht/third_party/pay/views/income.php b/webht/third_party/pay/views/income.php new file mode 100644 index 00000000..adbb039b --- /dev/null +++ b/webht/third_party/pay/views/income.php @@ -0,0 +1,180 @@ + + + + + + 在线支付统计 + + + + + + + + + + + + + + + +
+

+
+
+ +
+ +
+
+ + +
+
+
+

+ $table) { ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + $method) { ?> + + + + + + + + + + + +
付款 +
退款 +
收入 +
付款方式金额 + 上期 ( 前 天 )
+ +
环比上年同期
+ +
同比当年截止
+ +
brand_name ?>method_total_income, 2, '.', ',') ?>method_total_income_cmp, 2, '.', ',') ?>quarter_rate, 2, '.', ',') . '%' ?>year_method_total_income, 2, '.', ',') ?>year_rate, 2, '.', ',') . '%' ?>this_year_method_total_income, 2, '.', ',') ?>
+ + + + + + + + + diff --git a/webht/third_party/pay/views/payment_list.php b/webht/third_party/pay/views/payment_list.php index 04aefaed..ce6a6117 100644 --- a/webht/third_party/pay/views/payment_list.php +++ b/webht/third_party/pay/views/payment_list.php @@ -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);}