Merge branch 'feature/new-merge-payment'

mobile-first
lyt 5 years ago
commit 4a6b8bcecb

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

@ -1,4 +1,5 @@
<?php
$config['method_code'] = "15018";
$config['version'] = "1.1";
$config['partnerId'] = "10000004000";
$config['siteId'] = "www.chinahighlights.com";

@ -8,12 +8,24 @@ class PaymentService extends CI_Controller {
bcscale(2);
mb_regex_encoding("UTF-8");
$this->load->helper('payment');
$this->config->load('ipaylinks', true);
$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');
}
private $code_brandname = array(
"15002" => "PayPal",
"15010" => "PayPal",
"15015" => "Alipay",
"15016" => "WeChat",
"15018" => "Credit Card-iPaylinks",
);
public function index()
{
}
@ -22,15 +34,25 @@ class PaymentService extends CI_Controller {
{
$this->permission->is_admin(true);
$data = array();
$method = $this->input->get_post("method");
$method = $method===false ? null : $method;
$data['method_code'] = '';
// $data["paytext"] = $this->payment_status();
$data["method_name"] = $this->input->get_post("method_name");
if (isset($this->code_brandname[$method])) {
$data['method_code'] = $method;
$data["method_name"] = $this->code_brandname[$method];
}
$data["keywords"] = $this->input->get_post("keywords");
$data["date"] = $this->input->get_post("date");
empty($data['date']) ? $data['date'] = date('Y-m-d') : false;
if (!empty($data['keywords'])) {
$data['notelist'] = $this->note_model->search_key($data['keywords']);
} else {
$data['notelist'] = $this->note_model->search_date($data['date']);
$search_date = $this->note_model->search_date($data['date'], $method);
$unsend = $this->note_model->unsend_note(false, $method);
$sendfail = $this->note_model->sendfail_note(false, $method);
$closed = $this->note_model->closed_note($data['date'], 300, $method);
$data['notelist'] = array_merge(array_merge($unsend, $sendfail), array_merge($search_date, $closed));
}
array_walk($data["notelist"], 'PaymentService::set_brandname');
@ -49,7 +71,7 @@ class PaymentService extends CI_Controller {
$this->permission->is_admin(true);
$data = array();
$data['date'] = date('Y-m-d');
$data['notelist'] = $this->note_model->failnote(100);
$data['notelist'] = $this->note_model->sendfail_note(false);
array_walk($data["notelist"], 'PaymentService::set_brandname');
$this->load->view("payment_list",$data);
return;
@ -58,22 +80,8 @@ class PaymentService extends CI_Controller {
public function set_brandname(&$ele)
{
$ele->brand_name = "none";
switch ($ele->OPN_accountMethod) {
case '15016':
$ele->brand_name = "WeChat";
break;
case '15010':
case '15002':
$ele->brand_name = "PayPal";
break;
case '15018':
$ele->brand_name = "Credit Card";
break;
case '15015':
$ele->brand_name = "Alipay";
break;
default:
break;
if ($this->code_brandname[$ele->OPN_accountMethod]) {
$ele->brand_name = $this->code_brandname[$ele->OPN_accountMethod];
}
}
@ -602,5 +610,222 @@ class PaymentService extends CI_Controller {
return false;
}
public function ipalinks_settlement($year, $month, $day="01")
{
set_time_limit(0);
ignore_user_abort(true);
$fun_version = $this->input->get_post('fun');
$target_folder = "ipaylinks-" . $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;
}
if ($target_file==='2019-09') { // 2019.09.10 切换清算账单, 此处特殊处理
$settlement_record = $this->ipaylinks_call->read_excel_old($file_path);
$update_cnt = $this->ipaylinks_call->save_excel_old($settlement_record);
$settlement_record2 = $this->ipaylinks_call->read_excel_new($file_path,1);
$update_cnt2 = $this->ipaylinks_call->save_excel_new($settlement_record2);
$update_cnt += $update_cnt2;
} else if ($fun_version==='old') {
$settlement_record = $this->ipaylinks_call->read_excel_old($file_path);
$update_cnt = $this->ipaylinks_call->save_excel_old($settlement_record);
} else {
$settlement_record = $this->ipaylinks_call->read_excel_new($file_path);
$update_cnt = $this->ipaylinks_call->save_excel_new($settlement_record);
}
$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 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;
}
}

@ -151,7 +151,7 @@ function analysis_orderid($note_invoice_string) {
} elseif (isset($note_invoice_string[0]) && $note_invoice_string[0] !== "China Train Booking") {
$note_invoice_string = trim($note_invoice_string[0]);
}
return json_encode(array('orderid' => $note_invoice_string, 'ordertype' => 'A')); //APP订单不需要处理交易记录和通知
return json_encode(array('orderid' => $note_invoice_string, 'ordertype' => 'A', 'table' => 'biz')); //APP订单不需要处理交易记录和通知
}
//订单号例子 160420021_B--9608
@ -170,21 +170,27 @@ function analysis_orderid($note_invoice_string) {
//订单类型识别
$ordertype = 'N';
$table = null;
if (isset($note_invoice_string[1])) {
$ordertype_temp = trim($note_invoice_string[1]);
if (substr($ordertype_temp, 0, 2) == 'TP') {
$ordertype = 'TP';
$table = 'biz';
} elseif (substr($ordertype_temp, 0, 1) == 'T') {
$ordertype = 'T';
$table = 'tour';
} elseif (substr($ordertype_temp, 0, 1) == 'B') {
$ordertype = 'B';
$table = 'biz';
} elseif (substr($ordertype_temp, 0, 1) == 'A') {
$ordertype = 'A';
$table = 'biz';
}
}
// 2018.05.28 for Trippest, tourMaster的订单号是01开头
if (substr($note_invoice_string[0], 0, 2) == '01') {
$ordertype = 'TP';
$table = 'biz';
}
//手机订单、机票订单都没有加标示,在这里帮加上,暂时的,今后还是要在网前设置好
@ -192,6 +198,7 @@ function analysis_orderid($note_invoice_string) {
$orderid_temp = $note_invoice_string[0];
if (strlen($orderid_temp) == 9 && substr($orderid_temp, 0, 2) == '16') {
$ordertype = 'B';
$table = 'biz';
}
}
@ -201,6 +208,7 @@ function analysis_orderid($note_invoice_string) {
$orderid_temp = $note_invoice_string[0];
if (strlen($orderid_temp) == 8 && substr($orderid_temp, 0, 2) == '45') {
$ordertype = 'M';
$table = null;
}
}
//新的订单号14733661876255
@ -208,6 +216,7 @@ function analysis_orderid($note_invoice_string) {
$orderid_temp = $note_invoice_string[0];
if (strlen($orderid_temp) == 14 && substr($orderid_temp, 0, 2) == '14') {
$ordertype = 'M';
$table = null;
}
}
@ -228,7 +237,7 @@ function analysis_orderid($note_invoice_string) {
if (empty($pm_orderid) || strlen($pm_orderid) < 8) {
return false;
}
return json_encode(array('orderid' => $pm_orderid, 'ordertype' => $ordertype));
return json_encode(array('orderid' => $pm_orderid, 'ordertype' => $ordertype, 'table' => $table));
}
/**
* 输出xml字符
@ -286,3 +295,24 @@ function characet($data, $targetCharset) {
}
return $data;
}
function set_url_param($param_arr=array())
{
parse_str(parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY), $current_param);
$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 */

@ -0,0 +1,344 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Ipaylinks_call
{
protected $ci;
public function __construct()
{
$this->ci = &get_instance();
$this->ci->load->helper('payment');
$this->ci->config->load('ipaylinks', true);
$this->ci->load->model('Online_payment_note_model', 'note_model');
$this->ci->load->model('Online_payment_account_model', 'account_model');
}
public function save_excel_old($excel_data)
{
$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;
}
$save_column = array();
$save_column['OPN_accountMethod'] = $this->ci->config->item('method_code', 'ipaylinks');
$save_column['OPN_invoiceId'] = $settle['orderid'];
$save_column['OPN_orderId'] = $settle['orderid'];
$save_column['OPN_orderAmount'] = $settle['order_amount'];
if ($settle['data_type'] == '已清算退款' || $settle['data_type'] == '未清算退款') {
// 退款
// $ssje = $this->account_model->get_ssje($row['settlement_refund_fee'], str_replace("CNY", "RMB", strtoupper($row['currency_type'])), $save_column['OPN_accountMethod']);
// $save_column['OPN_resultCode'] = $row['refund_status'];
// $save_column['OPN_resultMsg'] = $row['refund_status'];
// $save_column['OPN_entryAmountCNY'] = floatval("-" . $ssje);
$save_column['OPN_noticeType'] = 'refund';
$save_column['OPN_relatedId'] = $settle['transaction_id'];
$save_column['OPN_transactionId'] = '';
if (true === $this->ci->note_model->if_refund_exists($settle['orderid'])) {
continue;
}
$query_from_ipalinkslog = $this->ci->note_model->query_ipalinkslog_memo($settle['orderid']);
if ( ! empty($query_from_ipalinkslog)) {
$save_column['OPN_transactionId'] = $query_from_ipalinkslog->IPL_dealId;
$save_column['OPN_invoiceId'] = $query_from_ipalinkslog->IPL_orderId;
$save_column['OPN_orderId'] = $query_from_ipalinkslog->IPL_orderId;
}
$related = $this->ci->note_model->query_related($save_column['OPN_relatedId']);
if ( ! empty($related)) {
$save_column['OPN_orderId'] = $related[0]->OPN_orderId;
$save_column['OPN_accountType'] = $related[0]->OPN_accountType;
}
} elseif ($settle['data_type'] == '清算') {
// 收款
$save_column['OPN_noticeType'] = 'pay';
$save_column['OPN_transactionId'] = $settle['transaction_id'];
$note_exists = $this->ci->note_model->if_note_exists($settle['transaction_id'], $settle['orderid']);
if (true === $note_exists) {
continue; // test:
}
} else {
continue;
}
if ($save_column['OPN_transactionId']==='') {
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_payAmount'] = $settle['order_amount'];
$save_column['OPN_noticeSendStatus'] = 'closed';
$save_column['OPN_transactionResult'] = 'completed';
$save_column['OPN_rawOrderId'] = $settle['orderid'];
$save_column['OPN_currency'] = $settle['currency'];
$save_column['OPN_acquiringTime'] = date('Y-m-d H:i:s',strtotime($settle['complete_date']));
$save_column['OPN_completeTime'] = date('Y-m-d H:i:s',strtotime($settle['complete_date']));
$save_column['OPN_remark'] = $settle['mark_memo'];
$save_column['OPN_fundSource'] = 'cht';
$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) {
continue; // test:
// 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;
}
public function read_excel_old($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','all row ' . $allRow);
$realRow = 0;
$col_titles = $this->excel_title_old();
/**从第二行开始输出因为excel表中第一行为列名*/
for($currentRow = 2;$currentRow <= $allRow;$currentRow++){
$row_tmp = array();
/**从第A列开始输出*/
for($currentColumn= 'A';$currentColumn<= "N"; $currentColumn++){
/**ord()将字符转为十进制数*/
$val = trim($currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65,$currentRow)->getValue());
$col_mean = $col_titles[$currentColumn];
if($col_mean == 'data_type' && in_array($val, $this->no_store_deal_type()) )
{
break;
}
if ($col_mean == 'orderid' && strcasecmp('-', $val) === 0) {
break;
}
$row_tmp[$col_mean] = $val;
}
if (isset($row_tmp['settlement_amount'])) {
$tarr1[] = $row_tmp;
$realRow++;
}
}
log_message('error','real row ' . $realRow);
return $tarr1;
}
private function no_store_deal_type()
{
return array(
"归还保证金"
// ,"记账"
,"冻结"
,"解冻"
,"提现"
,"提现手续费"
,"单笔处理费"
,"退款手续费"
);
}
private function excel_title_old()
{
return array(
"A" => "complete_date",
"B" => "transaction_id",
"C" => "orderid",
"D" => "data_type",
"E" => "currency",
"F" => "order_amount",
"G" => "settlement_rate",
"H" => "settlement_amount",
"I" => "service_fee",
"J" => "transaction_fee",
"K" => "mark_memo",
"L" => "entry_currency",
"M" => "entry_security",
"N" => "entry_basic"
);
}
public function save_excel_new($excel_data)
{
$settle_cnt = 0;
foreach ($excel_data as $settle) {
$save_column = array();
$save_column['OPN_accountMethod'] = $this->ci->config->item('method_code', 'ipaylinks');
$save_column['OPN_noticeType'] = trim($settle['trade_type']) === '消费' ? 'pay' : 'refund';
$save_column['OPN_fundSource'] = trim($settle['site_id']) === 'www.chinahighlights.com' ? 'cht' : 'app';
$save_column['OPN_transactionId'] = $settle['transaction_id'];
$save_column['OPN_relatedId'] = str_ireplace("-", '', $settle['related_id']);
$save_column['OPN_orderAmount'] = $settle['trade_amount'];
$save_column['OPN_orderId'] = $settle['orderid'];
$note_exists = $this->ci->note_model->if_note_exists($settle['transaction_id'], $settle['orderid']);
if (true === $note_exists) {
continue; // test:
}
// 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_payAmount'] = $settle['trade_amount'];
$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'] = date('Y-m-d H:i:s',strtotime($settle['complete_date']));
$save_column['OPN_completeTime'] = date('Y-m-d H:i:s',strtotime($settle['complete_date']));
$save_column['OPN_remark'] = str_ireplace("-", '', $settle['apply_pay_type']) . "_" . str_ireplace("-", '', $settle['trade_region']) . "_" . str_ireplace("-", '', $settle['card_issuers']) . "_" . str_ireplace("-", '', $settle['card_bin_country']) . "_" . str_ireplace("-", '', $settle['card_type']);
$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;
}
public function read_excel_new($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','all row ' . $allRow);
$col_titles = $this->excel_title_new();
/**从第二行开始输出因为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;
}
$col_mean = $col_titles[$currentColumn];
$row_tmp[$col_mean] = trim($val)==='-' ? '' : $val;
$columnNum++;
}
$tarr1[] = $row_tmp;
}
return $tarr1;
}
private function excel_title_new()
{
return array(
"A" => "complete_date",
"B" => "transaction_id",
"C" => "related_id",
"D" => "orderid",
"E" => "site_id",
"F" => "local_channel",
"G" => "apply_pay_type",
"H" => "trade_region",
"I" => "card_issuers",
"J" => "card_bin_country",
"K" => "card_type",
"L" => "trade_type",
"M" => "trade_currency",
"N" => "trade_amount",
"O" => "settlement_currency",
"P" => "settlement_amount",
"Q" => "service_fee",
"R" => "trade_fee",
"S" => "chargeback_fee",
"T" => "security_amount",
"U" => "system_fee",
"V" => "refund_fee",
"W" => "3d_fee",
"X" => "extra_info1",
"Y" => "extra_info2",
"Z" => "extra_info3",
"AA" => "extra_info4",
"AB" => "extra_info5",
"AC" => "basic_account_entry_amount",
"AD" => "security_account_entry_amount"
);
}
}
/* End of file Ipaylinks_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 */

@ -164,24 +164,50 @@ class Online_payment_account_model extends CI_Model {
return $query;
}
public function get_gai($t_id, $order=null, $amount=null, $type=null)
{
$ret = array("type"=> null, "data"=>null);
$result_t = $this->get_money_t($t_id);
$result_b = $this->get_money_b($t_id, $order, $amount, $type);
if ( ! empty($result_t)) {
$ret['type'] = 'T';
$ret['data'] = $result_t[0];
} else if ( ! empty($result_b)) {
$ret['type'] = 'B';
$ret['data'] = $result_b[0];
}
return $ret;
}
//根据交易号获取收款记录(传统订单)
public function get_money_t($pn_invoice) {
$sql = "SELECT GroupAccountInfo.*
from GroupAccountInfo
where DeleteFlag=0 and GAI_AccreditNo=?
$sql = "SELECT COLI_ID orderId, g.*
from GroupAccountInfo g
inner join Tourmanager.dbo.ConfirmLineInfo on g.GAI_COLI_SN=COLI_SN
where g.DeleteFlag=0 and g.GAI_AccreditNo=?
";
$query = $this->HT->query($sql, array($pn_invoice));
$result = $query->result();
return $result;
}
//根据交易号获取收款记录(商务订单)
public function get_money_b($pn_invoice) {
$sql = "SELECT BIZ_GroupAccountInfo.*
from BIZ_GroupAccountInfo
where DeleteFlag=0 and GAI_AccreditNo=?
public function get_money_b($t_id, $raw_order=null, $amount=null, $payment_type=null) {
$sql = "SELECT COLI_ID orderId, g.*
from BIZ_GroupAccountInfo g
inner join Tourmanager.dbo.BIZ_ConfirmLineInfo on g.GAI_COLI_SN=COLI_SN
where g.DeleteFlag=0 and g.GAI_AccreditNo=?
";
$query = $this->HT->query($sql, array($pn_invoice));
$query = $this->HT->query($sql, array($t_id));
$result = $query->result();
if (empty($result)) {
$raw_order_sql = "SELECT COLI_ID orderId, g.*
from BIZ_GroupAccountInfo g
inner join Tourmanager.dbo.BIZ_ConfirmLineInfo on g.GAI_COLI_SN=COLI_SN
where g.DeleteFlag=0 and COLI_ID=? and g.GAI_SQJE=? and g.GAI_Type=?
";
$query = $this->HT->query($raw_order_sql, array($raw_order, $amount, $payment_type));
$result = $query->result();
}
return $result;
}
/** 删除收款记录 */

@ -8,6 +8,25 @@ class Online_payment_note_model extends CI_Model {
$this->info = $this->load->database('INFO', TRUE);
}
public function if_note_exists($transaction_id, $raw_id=null)
{
if ($transaction_id === null) {
return null;
}
$order_sql = $raw_id===null ? " " : " AND OPN_rawOrderId='" . $raw_id . "'";
$ret = "SELECT TOP 1 * FROM OnlinePaymentNote WHERE OPN_transactionId=? $order_sql ORDER BY OPN_SN DESC ";
return $this->info->query($ret, array($transaction_id))->num_rows() > 0;
}
public function if_refund_exists($refund_id)
{
if ($refund_id === null) {
return null;
}
$ret = "SELECT TOP 1 * FROM OnlinePaymentNote WHERE OPN_rawOrderId=? ORDER BY OPN_SN DESC ";
return $this->info->query($ret, array($refund_id))->num_rows() > 0;
}
public function insert_note($column)
{
if ($column === null) {
@ -40,18 +59,32 @@ class Online_payment_note_model extends CI_Model {
return $this->update_note($where, $column);
}
public function unsend_note($num=2)
public function unsend_note($num=2, $method=null)
{
$this->init_query();
$this->topnum = $num;
// $this->send = " AND (OPN_noticeSendStatus='unsend' OR OPN_noticeSendStatus='' OR OPN_noticeSendStatus IS NULL) ";
$this->search = $method===null ? "" : " AND OPN_accountMethod=$method ";
$this->send = " AND ISNULL(OPN_noticeSendStatus,'') in ('', 'unsend') ";
return $this->query_note();
}
public function closed_note($date, $num=2, $method=null)
{
$this->init_query();
$this->topnum = $num;
$this->send = " AND (OPN_noticeSendStatus='unsend' OR OPN_noticeSendStatus='' OR OPN_noticeSendStatus IS NULL) ";
$this->send = " AND (OPN_noticeSendStatus) = 'closed' ";
$this->search = $method===null ? "" : " AND OPN_accountMethod=$method ";
$this->search .= " AND OPN_noticeTime BETWEEN '$date 00:00:00' AND '$date 23:59:59' ";
return $this->query_note();
}
public function sendfail_note($num=2)
public function sendfail_note($num=2, $method=null)
{
$this->init_query();
$this->topnum = $num;
$this->search = $method===null ? "" : " AND OPN_accountMethod=$method ";
$this->send = " AND OPN_noticeSendStatus='sendfail' ";
return $this->query_note();
}
@ -88,6 +121,9 @@ class Online_payment_note_model extends CI_Model {
$this->search ? $sql.=$this->search : false;
$this->transactionId ? $sql.=$this->transactionId : false;
$this->orderby ? $sql.=$this->orderby : false;
// log_message('error', PHP_EOL . $sql);
$query = $this->info->query($sql);
return $query->result();
}
@ -115,17 +151,12 @@ class Online_payment_note_model extends CI_Model {
return $this->query_note();
}
public function search_date($date)
public function search_date($date, $method=null)
{
$this->init_query();
$this->search = " AND OPN_noticeTime BETWEEN '$date 00:00:00' AND '$date 23:59:59' ";
return $this->query_note();
}
public function failnote($topnum = 2) {
$this->init_query();
$this->topnum = $topnum;
$this->send = " AND OPN_noticeSendStatus='sendfail' ";
$this->search = $method===null ? "" : " AND OPN_accountMethod=$method ";
$this->search .= " AND OPN_noticeTime BETWEEN '$date 00:00:00' AND '$date 23:59:59' ";
$this->send = " AND isnull(OPN_noticeSendStatus,'') NOT IN ('', 'sendfail', 'unsend', 'closed' )";
return $this->query_note();
}
@ -138,13 +169,256 @@ class Online_payment_note_model extends CI_Model {
{
$search_sql = $sn===0 ? "" : " and TEL_SN=$sn ";
$sql = "SELECT TOP 10 *
FROM [InfoManager].[dbo].[Transaction_Export_Log]
WHERE 1=1
$search_sql
order by TEL_SN desc";
FROM [InfoManager].[dbo].[Transaction_Export_Log]
WHERE 1=1
$search_sql
order by TEL_SN desc";
return $this->info->query($sql)->result();
}
public function query_ipalinkslog_memo($memo)
{
$sql = "SELECT *
from IPayLinksLog
where CHARINDEX(?,IPL_memo)>0";
return $this->info->query($sql, array($memo))->row();
}
public function query_ipalinkslog_dealid($id)
{
$sql = "SELECT *
from IPayLinksLog
where IPL_dealId=?";
return $this->info->query($sql, array($id))->row();
}
public function query_related($related_id)
{
$this->init_query();
$this->search = " AND OPN_transactionId='$related_id' and OPN_accountType is not null ";
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)">
@ -125,14 +125,24 @@
<img width="150" style="height:40px;" src="/css/nav/img/6000.png">
</a>
<h1>Payment List</h1>
<a class="text-muted" href="#">微信</a>
<a <?php if($method_code==='') { ?> class="text-muted"<?php } ?>
href="/webht.php/apps/pay/paymentservice/note_list">ALL</a>
&NonBreakingSpace;&boxv;&NonBreakingSpace;
<a <?php if($method_code==='15016') { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('method'=>15016)) ?>">微信&raquo;</a>
&NonBreakingSpace;
<a href="http://www.mycht.cn/webht.php/apps/paypal/index/note_list">PayPal&raquo;</a>
<a <?php if($method_code==='15002') { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('method'=>15002)) ?>">PayPal&raquo;</a>
&NonBreakingSpace;
<a href="https://www.mycht.cn/webht.php/apps/pay/ipaylinksservice/note_list">信用卡&raquo;</a>
<a <?php if($method_code==='15018') { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('method'=>15018)) ?>">信用卡&raquo;</a>
&NonBreakingSpace;
<a href="https://www.mycht.cn/webht.php/apps/pay/AlipayTradeService/index">支付宝&raquo;</a>
<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>
@ -279,7 +289,7 @@ jQuery.browser = {};
dateFormat: "Y-m-d",
defaultDate: "<?php echo $date; ?>",
onChange: function (selectedDates, dateStr, instance) {
window.location.href = '/webht.php/apps/pay/paymentservice/note_list?date=' + dateStr;
window.location.href = '/webht.php/apps/pay/paymentservice/note_list?date=' + dateStr;
}
});
})

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