Compare commits

...

68 Commits

Author SHA1 Message Date
Lei OT cc8d76a8db 集中Alipay 的记录到在线支付记录 3 months ago
Lei OT 098316794b wxpay: 记录 payment Source; 账单录入, 查询录入等 3 months ago
Lei OT 155c137a97 集中PayPal的webhook记录到在线支付记录 3 months ago
Lei OT 740f1aed0a perf: PayPal: APP组退款记录录入后补充记录: 录入`我的支付`; 执行HT任务`SP_AddToSystask`; ACDC付款忽略邮箱地址 3 months ago
Lei OT 102ce623d3 feat: 连连信用卡: 异步通知; 处理 3 months ago
Lei OT 51972536ad perf: APP组退款记录录入后补充记录: 录入`我的支付` 3 months ago
Lei OT b0f15b97fe perf: 支付中心: 录入记录后, 执行HT任务`SP_AddToSystask` 3 months ago
Lei OT 99c4d6743a perf: APP组退款记录录入后补充记录: 录入`我的支付` 3 months ago
Lei OT 3d4a2bdea4 perf: 收款通知邮件的公司名称 4 months ago
Lei OT 991d8d2e96 perf: 每月20号, 发送退款调账记录给财务; 修复PayPal重复 9 months ago
Lei OT f226619289 perf: PayPal退款: 优先处理IPN 9 months ago
Lei OT b6da466e81 perf: PayPal记录: 调整列表页面排序 9 months ago
Lei OT 028f48d069 perf: PayPal退款: 优先处理IPN 9 months ago
Lei OT 18bb1e1e84 fix: PayPal退款记录: 重复发邮件 9 months ago
Lei OT 370dfd42e2 fix: PayPal记录, Webhook数据中的手续费读取, pengding状态无数据; todo: 查询已完成的 9 months ago
Lei OT c064662783 perf: PayPal记录: 显示pending的原因 9 months ago
Lei OT dc01f8e59d fix: PayPal记录: 判断APP的是否已存在手动的记录 9 months ago
Lei OT 7e1140a6d6 fix: PayPal退款减去手续费 10 months ago
Lei OT ce7d7b7ce0 fix: PayPal wh记录手动录入 10 months ago
Lei OT 0c3d3be577 perf: `支付宝`退款处理: 金额明细已记录数据库 10 months ago
Lei OT 160d6e6621 perf: PayPal退款处理: 只有wh记录 10 months ago
Lei OT cfa8070b3b perf: PayPal DECLINED 保留记录, 自动忽略 10 months ago
Lei OT 9107425120 perf: PayPal记录 10 months ago
Lei OT 2a50bae00c perf: PayPal: wenhook , 记录被拒绝的 10 months ago
Lei OT 36a86c93d2 微信支付的send notify 11 months ago
Lei OT 1e2f088eb4 style: wxpay 11 months ago
Lei OT 56a546875f perf: PayPal退款处理: 从收款记录获取订单号 11 months ago
Lei OT d6363ef9ce sync: 网前的版本 11 months ago
Lei OT 9bbc6ad408 fix: Alipay退款账单的处理,不发送以前的邮件 11 months ago
Lei OT 1b4459a744 fix: PayPal detail logo 11 months ago
Lei OT 1f52e51106 fix: PayPal记录: 商户账户 12 months ago
Lei OT 5c731a3782 perf: PayPal记录: 查询交易关联的退款 12 months ago
Lei OT b421108b43 perf: PayPal字段: 更新时间 12 months ago
Lei OT f40d5ec7e6 # 12 months ago
Lei OT 0449fc0070 perf: PayPal收款记录: 增加账户等字段 12 months ago
Lei OT 00299e79d0 perf: PayPal记录: 显示webhook的账户 12 months ago
Lei OT a53984540c 记录通知的时间 12 months ago
Lei OT ac7a6fc57c perf: PayPal webhook处理 12 months ago
Lei OT a5ea8d1519 perf: PayPal webhook 处理. 解决部分交易没有IPN 12 months ago
Lei OT be664ebc9c perf: PayPal收款, 显示wb记录 12 months ago
Lei OT 6f91702704 perf: PayPal note modal 显示custom 12 months ago
Lei OT 2a56950e72 perf: PayPal 退款处理: 没有外联地址 1 year ago
Lei OT 60f3c62005 feat: PayPal API退款的custom_id 1 year ago
Lei OT 747b768ccb perf: PayPal收款处理: 多条订单匹配处理 1 year ago
Lei OT 70bb2695d3 feat: PayPal: 处理webhook, 把PayPal账户写入 GAI 表 1 year ago
Lei OT 3c0dcfa90c fix: PayPal 收款记录审核提示 1 year ago
Lei OT e1829d5685 feat: PayPal: 处理webhook, 把资源地址写入 GAI 表 1 year ago
Lei OT a1d4c4cce1 perf: PayPal 已录入订单但是外联没有设置邮箱, 忽略了 1 year ago
Lei OT 56db24fc56 . 1 year ago
Lei OT 90edc01a7a conf: https 1 year ago
Lei OT df56ba5f60 # 1 year ago
Lei OT 5c50297c72 perf: PayPal webhooks: custom_id 1 year ago
Lei OT 04eba4d8c6 fix: 字段检查 1 year ago
Lei OT 8afa987676 fix: Alipay: 解决多次退款时, 异步通知每次都返回已退的总金额, 直接录入导致金额累加了. 1 year ago
Lei OT 4a1a0fd6e1 fix: PayPal webhooks: 退款 currency 1 year ago
Lei OT babc652ce9 fix: PayPal webhooks: 退款 invoice number 1 year ago
Lei OT 857e318e03 perf: PayPal webhooks: 处理手续费 1 year ago
Lei OT d6e692a3ac feat: PayPal webhooks 接收V2 API 1 year ago
Lei OT 5798195e0f feat: PayPal收款: 实收金额计算, 使用实际扣的服务费 1 year ago
Lei OT 1c42250c8b perf: PayPal: 调账记录显示 2 years ago
Lei OT 03fbd1eb5d perf: PayPal: 支持搜索 退款的原纪录 2 years ago
Lei OT b75773205c perf: wxpay: 录入记录的时间; 2 years ago
Lei OT 94de68bcb8 perf: PayPal: 查询webhooks记录 2 years ago
Lei OT c5286fd666 fix: 资源文件错误 2 years ago
Lei OT af70b69cbf perf: PayPal: 失败的记录按时间 处理, 避免卡住 2 years ago
Lei OT aa2efe9f55 fix: PayPal: 退款的临时单号的处理 2 years ago
Lei OT 91616d70d4 perf: PayPal: 退款之后, 更新case 2 years ago
Lei OT a39ac52406 feat: wxpay: 请求微信查询收款/退款 2 years ago

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

@ -14,7 +14,7 @@
| path to your installation.
|
*/
$config['base_url'] = '';
$config['base_url'] = 'https://www.mycht.cn/';
/*
|--------------------------------------------------------------------------

@ -0,0 +1,4 @@
<?php
// require 'lianlian_cht.php';
require 'lianlian_test.php';

@ -0,0 +1,28 @@
<?php
/**
*
*/
$config['test']["method_code"] = 15035;
$config['test']['merchant_id'] = "202503100003060003";
$config['test']['sub_merchant_id'] = "1020250310968002";
$config['test']['return_url'] = "https://secure.chinahighlights.com/lianlian/thankyou";
$config['test']['notify_url'] = "https://www.mycht.cn/webht.php/apps/pay/lianlianservice/notify";
$config['test']['notify_refund_url'] = "https://www.mycht.cn/webht.php/apps/pay/lianlianservice/notify_refund";
$config['test']['charset'] = "UTF-8";
$config['test']['sign_type'] = "RSA";
$config['test']['gatewayUrl'] = "https://celer-api.lianlianpay-inc.com";
$config['test']['timeout_express'] = "1m";
$config['test']['app_public_key'] = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwD1I8x3rMfeMAD2+sgpNkq7G9z38LmZlWXMUF98IkEpufKl1mV9FwY6FwhAXLnAnGhFbHMhRy/LkJ4vGrJb9FLhYEPGUMaO46umK6k+PW/B8KYdQdlhmrevTTRoNkneGyZ94ffqmiHtTTScbu/IjaIs6UX/ObYJnKrJ637HcZy+HahuBQsiiP2QFKRZX02sgEiGWcirMSlP6e4KxMROawz6VSW5GgufgxYH5M65emqFMOo64/tbqMn63pu32k7jE23JevKgCUWoTGZzZZBgJjZOe4M5hH4BYVF6MXYjiD3yXkKSxDmENIy26F3Dc29vDGlXe1yv9norIiIBHD5+eewIDAQAB";
$config['test']['lianlian_public_key'] = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAo3Vy+gy/w6ygPREJb4gRWMtA/PfaPMqiTdcHngeSDoGuCAN/9PqufDIc83F1PE2s+6nNXtj0uJT8mRVjwWoh96eDpVcxAC0Y3NIB+2Z/sx3EsTB0kRyLxE+ZBcl2ms8jXGf/IQSUb8FrEBBvS6WWaDcKjfDYsEM5AJP3npnIZXW2h/wlslmEh8FJJqi0Ne2wR+Q0zzZKCERcxSrwSXKL2sRusc7MOZxUVE+1EcmTkwAl1lxY2s/DQAVAZBT/DXo5plODIwyzIFyW9aNGm2YIVofITnFtWxNoXL0BlFFnfGVncvohmRwA5zCPCxtIYmM3zdE+n9he7n/jnVWEGoXTDQIDAQAB";
// PKCS1 #
//
// PKCS8
$config['test']['merchant_private_key'] = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDAPUjzHesx94wAPb6yCk2Srsb3PfwuZmVZcxQX3wiQSm58qXWZX0XBjoXCEBcucCcaEVscyFHL8uQni8aslv0UuFgQ8ZQxo7jq6YrqT49b8Hwph1B2WGat69NNGg2Sd4bJn3h9+qaIe1NNJxu78iNoizpRf85tgmcqsnrfsdxnL4dqG4FCyKI/ZAUpFlfTayASIZZyKsxKU/p7grExE5rDPpVJbkaC5+DFgfkzrl6aoUw6jrj+1uoyfrem7faTuMTbcl68qAJRahMZnNlkGAmNk57gzmEfgFhUXoxdiOIPfJeQpLEOYQ0jLboXcNzb28MaVd7XK/2eisiIgEcPn557AgMBAAECggEAAqYVhjwITJTzmeE/6mYX8Yh0910kR2NjzBq40Sdij9JmuVMAas+UP3l+QFFGcH5dG4/XqIreDahYGm9jmmcuL4XmuL0LZK+z0ZDMODRGbmbe3xedNTQ8nfLc43gTbcw10DthRqMYflLsr+h1Cl7ou/0HHa5cIsgkMcNpzAFAXy+TS96aLLn06REFETm4p9vayaqh8TNE+Z29z3lBtCvRV36O/mWaf417hENNHoNHzle3W+Hbv9pK0Y07L//VMpMCAZ0kgvK621MFoSCX8I0Us3Hu0CVzMcEq0Ig1zikPOGFfGXeCOdan0M76gpP/FDb+LTerQVfnIE6yhYeFueVOIQKBgQD9y626XmNXM+m0foGcpxsYoFz32PZ9MFXCz0lwoI6bsTKMFRDljIWN2mFlYBqcdq21IT6SrUr+P54R4ACZnopnuO1ez9ykMacWcMGC7jorWix3dynidN1/knHZD0tYgLM3N2w7k1t20FvZQFzwouT3ycIvGnO03D27ZipS80pksQKBgQDB6LwCngzxvGa3OT27AjXDilA2UWtCF84vY+mJ3p4VGE/v/FiWyHZuxgpbLeZzJqNxynBKHxJkw4TeIMpv1jiwTrQGa3NBMRbqeSpqQ65zvUmYyj3Fe8GWOGuczdp89Yd37MBXnVvee/xQGP1XCru3IGz/HRCaWOOjUxXPa7Qw6wKBgC6BaRcyfo+XIqcBW2zCLjPoBsEfz6MG/WASLcnmkdszsCh9H7iAdGSW9Kvn3Vh4YsJDEj08ZfaK38M0wcdkhsYU2+I4wpyPwKdbCAqe7qfNAULu4gzuDzx2MEhvBgZ0puJiVIHiMatm6L25jo5FuyEwplWNSlCE3wb85JqInEQxAoGAIsfG6UVGFxnu5pBa1S85S4CEkKmb7nfsoK1wFy2Z9zisJeSCU1FThNz6wI4EFsVobaGc8H6QQwiazWjeRp8K/fyv57LgMmJGtPnUtMi9Ar+B8ujbmY9wEqy+CJsXxHAZw1XwzgZIkyh0Aj3pOvKO5vLm+f9Rmg21jvb5I4IzCM8CgYEA4WVlJPa7z68uzs8X9WnMc2Qs/PsvncFG0yk3Cj28qxnCpuhrqGWUBGMa+QvtUpdB+z7QIkU1yZznzvU157BYgHm3Vi+UQdM54d+q+1yY8BHdu04iirmRUllLyMekNhR8oh3sbBKwA72afGAB6u/ggNmCTVplpXyxNT3CPueZMrI=";

@ -54,6 +54,7 @@ class AlipayTradeService extends CI_Controller
$this->load->model('Group_model');
$this->load->helper('payment');
$this->load->model('Online_payment_account_model', 'payment_model');
$this->load->model('Online_payment_note_model', 'online_note');
$this->set_merchant('cht');
@ -98,6 +99,15 @@ class AlipayTradeService extends CI_Controller
}
}
private function get_fundsource($app_id)
{
$code_fundsource = array(
"2021004129643221" => "trippest",
"2017092108849921" => "cht", // "CHT",
);
return $app_id ? $code_fundsource[$app_id] : 'cht';
}
public function index()
{
$this->note_list();
@ -152,6 +162,13 @@ class AlipayTradeService extends CI_Controller
,$buyer
);
} else if ($notify_type == "refund") {
// 查询已退金额总计
$query_all_refunds = $this->Alipay_note_model->search_deal_refund_from_memo(
strval($asyns_resp->data->trade_no),
strval($asyns_resp->data->gmt_refund)
);
$asyns_resp->data->total_refund_fee = strval($asyns_resp->data->refund_fee);
$asyns_resp->data->refund_fee = ($asyns_resp->data->refund_fee)+($query_all_refunds->refunded_fee);
$this->Alipay_note_model->save_alipay(
strval($asyns_resp->data->out_biz_no)
,strval($asyns_resp->data->out_trade_no)
@ -180,6 +197,38 @@ class AlipayTradeService extends CI_Controller
// if (strcmp(strval($response->trade_status), "TRADE_SUCCESS") == 0) {
// $this->Alipay_note_model->update_query($response->trade_no,$response->buyer_logon_id);
// }
$fund_bill_list = json_decode($asyns_resp->data->fund_bill_list, true);
$to_online = [
'memo' => json_encode($asyns_resp->data,JSON_UNESCAPED_UNICODE),
'transaction_id' => strval($asyns_resp->data->trade_no),
'invoice_id' => strval($asyns_resp->data->out_trade_no),
'subject' => strval($asyns_resp->data->subject),
'remark' => strval($asyns_resp->data->body),
'buyer_id' => $buyer,
// 'custom_id' => $pn_custom,
'pay_amount' => strval($asyns_resp->data->total_amount),
'pay_currency' => 'CNY', // $pn_mc_currency,
'net_amount' => isset($asyns_resp->data->receipt_amount) ? strval($asyns_resp->data->receipt_amount) : null,
// 'pay_fee' => $post_data->mc_fee,
'transaction_status' => 'completed', // $transaction_status, // $pn_payment_status,
'payment_date' => strval($asyns_resp->data->gmt_create),
'complate_date' => strval($asyns_resp->data->gmt_payment),
'fund_source' => $this->get_fundsource($asyns_resp->data->app_id),
'fund_type' => $notify_type,
'event' => strval($asyns_resp->data->notify_type),
'event_result' => strval($asyns_resp->data->trade_status),
'payment_source' => isset($fund_bill_list[0]) ? $fund_bill_list[0]->fundChannel : null,
// 'referer_id' => isset($post_data->parent_txn_id) ? $post_data->parent_txn_id : '',
];
if ($notify_type == "refund") {
$to_online['transaction_id'] = strval($asyns_resp->data->out_biz_no);
$to_online['pay_amount'] = "-" . strval($asyns_resp->data->refund_fee);
$to_online['net_amount'] = $to_online['pay_amount'];
$to_online['payment_date'] = strval($asyns_resp->data->gmt_refund);
$to_online['complate_date'] = strval($asyns_resp->data->notify_time);
$to_online['referer_id'] = strval($asyns_resp->data->trade_no);
}
$this->online_note->add_note_alipay($to_online);
}
// 返回状态码200
echo "success";
@ -445,7 +494,7 @@ class AlipayTradeService extends CI_Controller
//CHTAPP订单添加记录前判断是否有记录以前的APP版本没有交易号只能拿金额来判断
if (substr($advisor_info->COLI_WebCode, 0, 6) == 'CHTAPP' && strstr($advisor_info->COLI_WebCode, "-") != '-biz') {
//只判断前6位字符CHTAPP-fr CHTAPP-jp等各语种都属于APP订单
$this->Alipay_model->add_account_info_forAPP(
$insertID = $this->Alipay_model->add_account_info_forAPP(
$GAI_COLI_SN,
$advisor_info->COLI_ID,
$item->ALI_orderAmount,
@ -469,7 +518,7 @@ class AlipayTradeService extends CI_Controller
$this->Alipay_model->update_biz_coli_state($GAI_COLI_SN, 13);
$this->Alipay_model->insert_biz_order_log($GAI_COLI_SN, 'BS13');
}
$this->Alipay_model->add_account_info(
$insertID = $this->Alipay_model->add_account_info(
$GAI_COLI_SN,
$advisor_info->COLI_ID,
$item->ALI_orderAmount,
@ -488,6 +537,8 @@ class AlipayTradeService extends CI_Controller
// 更新订单主表付款方式,防止没访问thankyou-train.asp
$this->Alipay_model->update_paymanner($GAI_COLI_SN);
}
// 添加HT任务
$this->payment_model->exec_addToTask($insertID, 227002);
}
//更新还没有填的客邮和交易号de收款记录传统订单
elseif (isset($advisor_info->order_type) && $advisor_info->order_type == 1) {
@ -510,7 +561,7 @@ class AlipayTradeService extends CI_Controller
//添加汉特的订单提醒
$this->Alipay_model->update_coli_introduction($GAI_COLI_SN, '已支付 ' . mb_strtoupper($item->ALI_currencyCode) . $item->ALI_orderAmount);
// 添加HT任务
$this->Alipay_model->exec_addToTask($gai_sn);
$this->payment_model->exec_addToTask($gai_sn, 227001);
}
}
@ -617,7 +668,7 @@ class AlipayTradeService extends CI_Controller
$GAI_COLI_SN = isset($advisor_info->COLI_SN) ? $advisor_info->COLI_SN : 0;
//CHTAPP订单添加记录前判断是否有记录以前的APP版本没有交易号只能拿金额来判断
if (substr($advisor_info->COLI_WebCode, 0, 6) == 'CHTAPP' && strstr($advisor_info->COLI_WebCode, "-") != '-biz') {//只判断前6位字符CHTAPP-fr CHTAPP-jp等各语种都属于APP订单
$this->Alipay_model->add_account_info_forAPP(
$insertID = $this->Alipay_model->add_account_info_forAPP(
$GAI_COLI_SN,
$advisor_info->COLI_ID,
$item->ALI_orderAmount,
@ -631,12 +682,17 @@ class AlipayTradeService extends CI_Controller
NULL,
$item->ALI_dealId,
$ht_memo);
if ($insertID) {
$this->Alipay_model->insert_biz_order_log($GAI_COLI_SN, 'Refunded');
$this->payment_model->exec_BIZ_TrainCostAdd($GAI_COLI_SN, $ssje);
}
} else {
if (false == $this->Alipay_model->if_biz_gai_exists($item->ALI_dealId) ) {
$this->Alipay_model->insert_biz_order_log($GAI_COLI_SN, 'Refunded');
}
$this->Alipay_model->add_account_info(
$insertID = $this->Alipay_model->add_account_info(
$GAI_COLI_SN,
$advisor_info->COLI_ID,
$item->ALI_orderAmount,
@ -652,6 +708,8 @@ class AlipayTradeService extends CI_Controller
$item->ALI_dealId,
$ht_memo);
}
// 添加HT任务
$this->payment_model->exec_addToTask($insertID, 227002);
}
//更新还没有填的客邮和交易号的收款记录(传统订单)
elseif (isset($advisor_info->order_type) && $advisor_info->order_type == 1) {
@ -673,6 +731,8 @@ class AlipayTradeService extends CI_Controller
$ht_memo);
//添加汉特的订单提醒
$this->Alipay_model->update_coli_introduction($GAI_COLI_SN, '已退款 ' . ($currencyCode) . $item->ALI_orderAmount);
// 添加HT任务
$this->payment_model->exec_addToTask($gai_sn, 227001);
}
}
@ -680,7 +740,11 @@ class AlipayTradeService extends CI_Controller
$opi_firstname = !empty($advisor_info->OPI_FirstName) ? $advisor_info->OPI_FirstName : !empty($advisor_info->OPI_Name) ? $advisor_info->OPI_Name : ''; //lussie
//没有外联信息表示订单未分配
if (empty($opi_email) || empty($opi_firstname)) {
// if (empty($opi_email) && !empty($opi_firstname)) {
// $this->Alipay_note_model->update_send($item->ALI_dealId, 'send');
// return false;
// }
if (empty($opi_email) && empty($opi_firstname)) {
$this->Alipay_note_model->update_send($item->ALI_dealId, 'sendfail');
return false;
}
@ -800,6 +864,8 @@ class AlipayTradeService extends CI_Controller
* @param [type] $dealId 必须, 退款请求号.out_biz_no, 或原始交易订单号
* @param [type] $trade_no 必须, 原收款交易号, 和order_id不能同时为空
* @param [type] $order_id 必须, 原收款订单号, 和trade_no不能同时为空
*
* @ignore 只能查询API发起的退款, 后台的退款查不到
*/
public function query_refund($dealId=NULL,$trade_no=NULL, $order_id=NULL)
{
@ -813,7 +879,8 @@ class AlipayTradeService extends CI_Controller
$response = $this->aopclientRequestExecute ($request);
// $response = $response->alipay_trade_fastpay_refund_query_response;
return $this->output->set_content_type('application/json')->set_output(json_encode($response));
return $response;
// return $this->output->set_content_type('application/json')->set_output(json_encode($response));
}
public function get_billfile($date=NULL)
@ -843,6 +910,10 @@ class AlipayTradeService extends CI_Controller
ignore_user_abort(true);
$request = new AlipayDataDataserviceBillDownloadurlQueryRequest();
$date = $date===NULL ? date("Y-m-d", strtotime("-1 day")) : $date;
$file_name = FCPATH.'download_statement\settlement_files\alipay\\' . $this->merchant_account . $date . ".zip";
if (file_exists($file_name)) {
// 已经下载, 直接读取
} else {
$request->setBizContent("{" .
"\"bill_type\":\"signcustomer\"," .
"\"bill_date\":\"$date\"" .
@ -858,9 +929,12 @@ class AlipayTradeService extends CI_Controller
$file_name = FCPATH.'download_statement\settlement_files\alipay\\' . $this->merchant_account . $date . ".zip";
$target = FCPATH.'download_statement\settlement_files\alipay\\' . $this->merchant_account . $date ;
file_put_contents($file_name, $file);
}
$biz_detail_table = array();
$biz_data_title = $this->bill_data_title();
$finance_data_title = $this->finance_data_title();
$biz_data_rows = [];
$finance_data_rows = [];
$zip = zip_open($file_name);
if ($zip) {
while ($zip_entry = zip_read($zip)) {
@ -870,8 +944,10 @@ class AlipayTradeService extends CI_Controller
$content_row = explode("\n", $content_convert);
if (stripos($content_row[0], "业务明细")) {
$data_title = $biz_data_title;
$this_rows = &$biz_data_rows;
} elseif (stripos($content_row[0], "账务明细")) {
$data_title = $finance_data_title;
$this_rows = &$finance_data_rows;
} else {
zip_entry_close($zip_entry);
continue;
@ -889,7 +965,8 @@ class AlipayTradeService extends CI_Controller
$row_arr[$title] = trim($row[$key]);
}
$row_arr['app_id'] = $this->appid;
$biz_detail_table[] = $row_arr;
// $biz_detail_table[] = $row_arr;
array_push($this_rows, $row_arr);
}
zip_entry_close($zip_entry);
@ -897,13 +974,15 @@ class AlipayTradeService extends CI_Controller
}
zip_close($zip);
}
$biz_detail_table = array_merge($biz_data_rows, $finance_data_rows);
if (empty($biz_detail_table)) {
return false;
}
$to_online_arr = array();
foreach ($biz_detail_table as $key => $row) {
$total_amount = 0;$trade_type='';$trade_no = '';$has_charge=null;
$total_amount = 0;$trade_type='';$trade_no = '';$has_charge=null;$net_amount = '';
if (isset($row['finance_id'])) {
if ($row['biz_type'] !== '其它' && $row['biz_type'] !== '在线支付') {
if ($row['biz_type'] !== '其它' && $row['biz_type'] !== '在线支付' && $row['biz_type'] !== '转账') {
continue;
}
$total_amount = floatval($row['income'])>0 ? $row['income'] : $row['expenditure'];
@ -915,6 +994,7 @@ class AlipayTradeService extends CI_Controller
$trade_no = $row['refund_id'];
} else {
$total_amount = ($row['total_amount']);
$net_amount = bcadd($row['total_amount'],$row['charge_fee']);
$trade_type = 'pay';
$trade_no = $row['trade_no'];
$has_charge = floatval($row['charge_fee'])==0 ? 1 : null;
@ -936,6 +1016,36 @@ class AlipayTradeService extends CI_Controller
,$row['buyer_user_name']
,null,true
);
$to_online = [
'memo' => json_encode($row, JSON_UNESCAPED_UNICODE),
'transaction_id' => strval($trade_no),
'invoice_id' => strval($row['out_trade_no']),
'subject' => strval($row['subject']),
'remark' => isset($row['body']) ? strval($row['body']) : $row['remark'],
'buyer_email' => $row['buyer_user_name'],
// 'buyer_id' => $buyer,
// 'custom_id' => $pn_custom,
'pay_amount' => strval($total_amount),
'pay_currency' => 'CNY', // $pn_mc_currency,
'net_amount' => $net_amount === '' ? strval($total_amount) : strval($net_amount),
'pay_fee' => isset($row['charge_fee']) ? bcsub(0, $row['charge_fee']) : null,
'transaction_status' => 'completed', // $transaction_status, // $pn_payment_status,
'payment_date' => $row['complete_time'],
'complate_date' => $row['complete_time'],
'fund_source' => $this->get_fundsource($row['app_id']),
'fund_type' => $trade_type,
'event' => isset($row['biz_type']) ? strval($row['biz_type']) : $row['trade_type'],
'event_result' => 'TRADE_SUCCESS',
'payment_source' => isset($row['trading_channel']) ? $row['trading_channel'] : null,
// 'referer_id' => isset($post_data->parent_txn_id) ? $post_data->parent_txn_id : '',
];
if ($trade_type == "refund") {
$to_online['referer_id'] = strval($row['trade_no']);
}
$to_online_arr[] = $to_online;
}
foreach ($to_online_arr as $key => $item) {
$this->online_note->add_note_alipay($item, true);
}
return;
}
@ -995,7 +1105,7 @@ class AlipayTradeService extends CI_Controller
* @return obj
*/
function check($arr){
$ret = new ArrayObject();
$ret = new stdClass();
$ret->check = false;
$ret->data = NULL;
@ -1003,7 +1113,7 @@ class AlipayTradeService extends CI_Controller
$aop = new AopClient();
$aop->alipayrsaPublicKey = $this->alipay_public_key;
$ret->check = $result = $aop->rsaCheckV1($arr, $this->alipay_public_key, $this->signtype);
$ret->check = $result = $aop->rsaCheckV2($arr, $this->alipay_public_key, $this->signtype);
if ($result === false) {
log_message('error','Alipay sign ERROR ! orderId:'.$arr_obj->out_trade_no.'; dealId:'.$arr_obj->trade_no . "; Original return:".json_encode($arr)."; ");
return $ret;

@ -0,0 +1,236 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class LianlianService extends CI_Controller
{
protected $merchant_config;
protected $private_key;
public function __construct()
{
parent::__construct();
bcscale(2);
$this->load->helper('payment');
$this->config->load('lianlian', true);
$this->load->model('Online_payment_note_model', 'note_model');
$this->load->model('Online_payment_account_model', 'account_model');
$this->merchant_config = $this->config->item('test', 'lianlian');
}
public function index() {}
public function query_status() {}
public function query_payment() {}
public function query_refund() {}
public function notify($site = 'cht')
{
// $this->merchant_config = $this->config->item($site, 'lianlian'); // test: 测试环境
error_reporting(0);
log_message('error', 'LianlianPay notify begin ----');
$response['code'] = 0;
$response['message'] = '';
$raw_post_data = file_get_contents('php://input');
if (empty($raw_post_data)) {
# 如果没有数据,直接返回失败
return $this->output->set_content_type('application/json')->set_output(json_encode($response));
}
log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . ' ' . PHP_EOL . var_export($raw_post_data, 1));
$signature = $this->input->server('HTTP_SIGNATURE');
$payment_result = json_decode($raw_post_data, true);
if ($this->check_sign($payment_result, $signature) !== true) {
$response['message'] = 'sign error';
// return $this->output->set_content_type('application/json')->set_output(json_encode($response));
}
$payment_data = $payment_result['payment_data'];
$payment_result['GAI_API'] = array(
'merchant' => $site,
'invoice' => $payment_result['merchant_transaction_id'],
'transaction_id' => $payment_result['ll_transaction_id'],
);
// todo: 计算手续费, 实收
$payment_fee = $payment_data['payment_amount'] - $payment_data['settlement_amount'];
$ssje = $this->account_model->get_ssje($payment_data['settlement_amount'], str_replace("CNY", "RMB", strtoupper($payment_data['settlement_currency_code'])), $this->merchant_config['method_code']);
$save_column = array();
$save_column['OPN_transactionId'] = $payment_result['ll_transaction_id'];
$save_column['OPN_orderId'] = $payment_result['merchant_transaction_id'];
$save_column['OPN_rawOrderId'] = $payment_result['merchant_transaction_id'];
$save_column['OPN_invoiceId'] = $payment_result['merchant_transaction_id'];
$save_column['OPN_subject'] = $payment_result['merchant_transaction_id'];
$save_column['OPN_currency'] = $payment_data['payment_currency_code'];
$save_column['OPN_orderAmount'] = $payment_data['payment_amount'];
$save_column['OPN_payAmount'] = $payment_data['payment_amount'];
// $save_column['OPN_payFee'] = $payment_fee; // todo: 计算手续费; 退款 1USD 原手续费不退
$save_column['OPN_netAmount'] = $payment_data['settlement_amount'];
$save_column['OPN_transactionResult'] = $payment_data['payment_status'] === 'PS' ? 'completed' : 'declined';
$save_column['OPN_resultCode'] = $payment_data['payment_status'];
// $save_column['OPN_resultMsg'] = isset($payment_result['return_msg']) ? $payment_result['return_msg'] : $payment_result['result_code'];
// $save_column['OPN_errCode'] = isset($payment_result['err_code']) ? $payment_result['err_code'] : NULL;
// $save_column['OPN_errMsg'] = isset($payment_result['err_code_des']) ? $payment_result['err_code_des'] : NULL;
$save_column['OPN_acquiringTime'] = date('Y-m-d H:i:s', strtotime($payment_data['payment_time']));
$save_column['OPN_completeTime'] = date('Y-m-d H:i:s', strtotime($payment_data['payment_time']));
// $save_column['OPN_remark'] = $payment_result['attach'] ? $payment_result['attach'] : $payment_result['out_trade_no'];
// $save_column['OPN_payerLogId'] = $payment_result['openid'];
// $save_column['OPN_payerStatus'] = $payment_result['is_subscribe']==='Y' ? "subscribed" : NULL;
$save_column['OPN_fundSource'] = $site;
$save_column['OPN_entryAmountCNY'] = floatval($ssje);
$save_column['OPN_rawContent'] = json_encode($payment_result);
$save_column['OPN_noticeTime'] = date('Y-m-d H:i:s');
// $save_column['OPN_noticeType'] = intval($payment_result['total_fee'])>0 ? 'pay' : 'refund';
$save_column['OPN_noticeType'] = 'pay';
$save_column['OPN_noticeSendStatus'] = $payment_data['payment_status'] === 'PS' ? 'unsend' : 'closed';
$save_column['OPN_noticeSendTime'] = NULL;
$save_column['OPN_accountMethod'] = $this->merchant_config['method_code'];
if ($this->note_model->insert_note($save_column)) {
$response['code'] = 200;
$response['message'] = 'success';
}
$this->output->set_content_type('application/json')->set_output(json_encode($response));
}
public function notify_refund($site = 'cht')
{
// $this->merchant_config = $this->config->item($site, 'lianlian'); // test: 测试环境
error_reporting(0);
log_message('error', 'LianlianPay notify refund begin ----');
$response['code'] = 0;
$response['message'] = '';
$raw_post_data = file_get_contents('php://input');
if (empty($raw_post_data)) {
# 如果没有数据,直接返回失败
return $this->output->set_content_type('application/json')->set_output(json_encode($response));
}
$signature = $this->input->server('HTTP_SIGNATURE');
$payment_result = json_decode($raw_post_data, true);
if ($this->check_sign($payment_result, $signature) !== true) {
log_message('error','debug: ' . __METHOD__ . ': ' . __LINE__ . ' signature' . PHP_EOL . var_export($signature, 1));
log_message('error','debug: ' . __METHOD__ . ': ' . __LINE__ . ' raw_post_data' . PHP_EOL . var_export($raw_post_data, 1));
$response['message'] = 'sign error';
// return $this->output->set_content_type('application/json')->set_output(json_encode($response)); // debug:
}
$payment_data = $payment_result['refund_data'];
$find_related = $this->note_model->get_note_where(['OPN_invoiceId' => ['=', $payment_result['original_transaction_id']], 'OPN_transactionResult' => ['=', 'completed']]);
// ! 退款手续费 1USD, 原交易手续费不退
// $payment_fee = $payment_data['payment_amount'] - $payment_data['settlement_amount'];
// $ssje = $this->account_model->get_ssje('-' . $payment_data['actual_refund_amount'], str_replace("CNY", "RMB", strtoupper($payment_data['actual_refund_currency_code'])), $this->merchant_config['method_code']);
$ssje = $this->account_model->get_ssje('-' . $payment_data['settlement_amount'], str_replace("CNY", "RMB", strtoupper($payment_data['settlement_currency_code'])), $this->merchant_config['method_code']);
$save_column = array();
$save_column['OPN_transactionId'] = $payment_result['ll_transaction_id'];
$save_column['OPN_orderId'] = $payment_result['original_transaction_id'];
$save_column['OPN_rawOrderId'] = $payment_result['merchant_transaction_id'];
$save_column['OPN_invoiceId'] = $payment_result['merchant_transaction_id'];
$save_column['OPN_relatedId'] = isset($find_related[0]->OPN_transactionId) ? $find_related[0]->OPN_transactionId : null;
$save_column['OPN_subject'] = $payment_result['merchant_transaction_id'] . ' ' . $payment_data['reason'];
$save_column['OPN_currency'] = $payment_data['refund_currency_code'];
$save_column['OPN_orderAmount'] = '-'.$payment_data['refund_amount'];
$save_column['OPN_payAmount'] = '-'.$payment_data['refund_amount'];
$save_column['OPN_payFee'] = null; // 1; // ! todo: 计算手续费; 退款 1 USD 原手续费不退
$save_column['OPN_netAmount'] = '-'.$payment_data['settlement_amount']; // todo:
$save_column['OPN_transactionResult'] = refund_status($payment_data['refund_status']);
$save_column['OPN_resultCode'] = $payment_data['refund_status'];
// $save_column['OPN_resultMsg'] = isset($payment_result['return_msg']) ? $payment_result['return_msg'] : $payment_result['result_code'];
// $save_column['OPN_errCode'] = isset($payment_result['err_code']) ? $payment_result['err_code'] : NULL;
// $save_column['OPN_errMsg'] = isset($payment_result['err_code_des']) ? $payment_result['err_code_des'] : NULL;
$save_column['OPN_acquiringTime'] = date('Y-m-d H:i:s', strtotime($payment_data['refund_time']));
$save_column['OPN_completeTime'] = date('Y-m-d H:i:s', strtotime($payment_data['refund_time']));
$save_column['OPN_remark'] = $payment_data['reason'] ? $payment_data['reason'] : '';
// $save_column['OPN_payerLogId'] = $payment_result['openid'];
// $save_column['OPN_payerStatus'] = $payment_result['is_subscribe']==='Y' ? "subscribed" : NULL;
$save_column['OPN_fundSource'] = $site;
$save_column['OPN_entryAmountCNY'] = floatval($ssje);
$save_column['OPN_rawContent'] = json_encode($payment_result);
$save_column['OPN_noticeTime'] = date('Y-m-d H:i:s');
$save_column['OPN_noticeType'] = 'refund';
$save_column['OPN_noticeSendStatus'] = refund_status_send($payment_data['refund_status']);
$save_column['OPN_noticeSendTime'] = NULL;
$save_column['OPN_accountMethod'] = $this->merchant_config['method_code'];
// log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . ' to in' . PHP_EOL . var_export($save_column, 1));
// die; // test:0
if ($this->note_model->insert_note($save_column)) {
$response['code'] = 200;
$response['message'] = 'success';
}
$this->output->set_content_type('application/json')->set_output(json_encode($response));
}
// protected function generateSignArray($params, $signType = "RSA")
// {
// return $this->sign(generateSignContent($params), $signType);
// }
// protected function sign($data, $signType = "RSA")
// {
// $this->private_key = $this->merchant_config['merchant_private_key'];
// $priKey = $this->private_key;
// $res = "-----BEGIN RSA PRIVATE KEY-----\n" .
// wordwrap($priKey, 64, "\n", true) .
// "\n-----END RSA PRIVATE KEY-----";
// ($res) or die('您使用的私钥格式错误请检查RSA私钥配置');
// if ("RSA2" == $signType) {
// openssl_sign($data, $sign, $res, OPENSSL_ALGO_SHA256);
// } else {
// openssl_sign($data, $sign, $res);
// }
// $sign = base64_encode($sign);
// return $sign;
// }
protected function check_sign($data, $signature)
{
if (empty($signature)) {
log_message('error', 'LianlianPay notify error: no sign.');
return false;
}
$verify_res = $this->verify_signature(generateSignContent($data), $signature);
if ( ! $verify_res) {
log_message('error', 'LianlianPay notify error: sign. ' . generateSignContent($data));
return false;
}
// return false; // test: 0
return true;
}
protected function verify_signature($data, $sign, $signType = "RSA")
{
// Load the public key
$pubKey = $this->merchant_config['lianlian_public_key'];
if (!$pubKey) {
return false; // Public key file not found or unreadable.
}
$res = "-----BEGIN PUBLIC KEY-----\n" .
wordwrap($pubKey, 64, "\n", true) .
"\n-----END PUBLIC KEY-----";
$res = openssl_get_publickey($res);
($res) or die('LianlianRSA公钥错误。请检查公钥文件格式是否正确');
//调用openssl内置方法验签返回bool值
if ("RSA2" == $signType) {
$result = (bool)openssl_verify($data, base64_decode($sign), $res, OPENSSL_ALGO_SHA256); // sha256 OPENSSL_ALGO_SHA256
} else {
$result = (bool)openssl_verify($data, base64_decode($sign), $res);
}
// log_message('error', 'test: ' . __METHOD__ . ': ' . __LINE__ . ' result' . PHP_EOL . var_export($result, 1));
//释放资源
openssl_free_key($res);
return $result;
}
}

@ -25,6 +25,7 @@ class PaymentService extends CI_Controller {
"15015" => "Alipay",
"15016" => "WeChat",
"15018" => "Credit Card-iPaylinks",
"15035" => "Credit Card-Lianlian",
);
public function index()
@ -36,8 +37,8 @@ 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'] = '';
$method = $method===false ? null : $method; // explode(',', $method);
$data['method_code'] = $method ? $method : '';
// $data["paytext"] = $this->payment_status();
if (isset($this->code_brandname[$method])) {
$data['method_code'] = $method;
@ -99,7 +100,7 @@ class PaymentService extends CI_Controller {
$wx_app = $wx_app!=='0' ? $wx_app : (isset($raw->appid) ? $raw->appid : '0');
$ele->app_name = "";
if ($this->wxpay_app[$wx_app]) {
if ($ele->OPN_accountMethod===15016 && $this->wxpay_app[$wx_app]) {
$ele->app_name = $this->wxpay_app[$wx_app];
}
}
@ -168,6 +169,11 @@ class PaymentService extends CI_Controller {
// continue;
}
$GAI_API = null;
$_memo = json_decode($item->OPN_rawContent);
$GAI_API = property_exists($_memo, 'GAI_API') ? $_memo->GAI_API : null;
$GAI_API = json_encode($GAI_API, JSON_UNESCAPED_SLASHES);
// 开始查找订单和录入
$handpick = empty($opn_id) ? false : true;
$advisor_info = $this->account_model->get_order($orderid_info->orderid, true, $orderid_info->ordertype, $handpick);
@ -202,7 +208,7 @@ class PaymentService extends CI_Controller {
// todo: 检测收/退款是否存在
if (substr($advisor_info->COLI_WebCode, 0, 6) == 'CHTAPP' && strstr($advisor_info->COLI_WebCode, "-") !== '-biz') {
/* APP */
$this->account_model->add_account_info_forAPP(
$insertID = $this->account_model->add_account_info_forAPP(
$COLI_SN,
$item->OPN_accountMethod,
$advisor_info->COLI_ID,
@ -216,14 +222,19 @@ class PaymentService extends CI_Controller {
$item->OPN_payerName,
$item->OPN_payerEmail,
$item->OPN_transactionId,
$ht_memo
$ht_memo, $GAI_API
);
if ($is_refund === true && $insertID) {
$this->account_model->exec_BIZ_TrainCostAdd($COLI_SN, $ssje);
}
if ($advisor_info->COLI_WebCode == 'CHTAPP' && $advisor_info->COLI_State == 11
&& false===$is_refund) {
//只修改APP组的订单状态并且订单进度是我的订单
$this->account_model->update_biz_coli_state($COLI_SN, 8); //把订单状态改为已付款
$this->account_model->insert_biz_order_log($COLI_SN, 'BS8');
}
// 添加HT任务
$this->account_model->exec_addToTask($insertID, 227002);
} else {
/* 其他商务订单 */
// 第一次录入收款记录时变更状态,记录日志
@ -232,10 +243,10 @@ class PaymentService extends CI_Controller {
) {
$this->account_model->update_biz_coli_state($COLI_SN, 13);
$this->account_model->insert_biz_order_log($COLI_SN, 'BS13');
} else {
} else if (false!==$is_refund) {
$this->account_model->insert_biz_order_log($COLI_SN, 'Refunded');
}
$this->account_model->add_account_info(
$insertID = $this->account_model->add_account_info(
$COLI_SN,
$item->OPN_accountMethod,
$advisor_info->COLI_ID,
@ -249,10 +260,12 @@ class PaymentService extends CI_Controller {
$item->OPN_payerName,
$item->OPN_payerEmail,
$item->OPN_transactionId,
$ht_memo
$ht_memo, $GAI_API
);
// 更新订单主表付款方式,防止没访问thankyou-train.asp
$this->account_model->update_paymanner($COLI_SN, $item->OPN_accountMethod);
// 添加HT任务
$this->account_model->exec_addToTask($insertID, 227002);
}
// 更新note
$update_note_column['OPN_accountType'] = 'B';
@ -273,16 +286,16 @@ class PaymentService extends CI_Controller {
$item->OPN_payerName,
$item->OPN_payerEmail,
$item->OPN_transactionId,
$ht_memo
$ht_memo, $GAI_API
);
if ($is_refund === false) {
//添加汉特的订单提醒
$this->account_model->update_coli_introduction($COLI_SN, '已支付 ' . $currencyCode . $item->OPN_orderAmount);
// 收款:添加HT任务
$this->account_model->exec_addToTask($gai_sn);
}
// 收款:添加HT任务
$this->account_model->exec_addToTask($gai_sn, 227001);
// 更新note
$update_note_column['OPN_accountType'] = 'B';
$update_note_column['OPN_accountType'] = 'T';
$update_note_column['OPN_accountStatus'] = 'recorded';
$update_note_column['OPN_accountTime'] = date('Y-m-d H:i:s');
}
@ -339,7 +352,7 @@ class PaymentService extends CI_Controller {
// todo:iPaylinks需要发收款, 退款发所有
// 3. 更新是否发送财务
if($is_refund === true ) {
$this->send_refund($send_email, $item, $orderid_info, $advisor_info);
$this->send_refund_email($send_email, $item, $orderid_info, $advisor_info);
}
//显示处理记录
@ -355,7 +368,7 @@ class PaymentService extends CI_Controller {
// return $this->output->set_content_type('application/json')->set_output(json_encode($data));
}
public function send_refund($send_email, $item, $orderid_info, $advisor_info)
public function send_refund_email($send_email, $item, $orderid_info, $advisor_info)
{
// 发送客人
if ($send_email===true

@ -24,7 +24,7 @@ class WxpayService extends CI_Controller {
public function notify($site='cht')
{
error_reporting(0);
// log_message('error','notify begin ----');
// log_message('error','wxpay notify begin ----');
$response['return_code'] = 'FAIL';
$response['return_msg'] = '';
$GLOBALS['__WX_SITE_NAME__'] = $site;
@ -54,7 +54,7 @@ class WxpayService extends CI_Controller {
$save_column['OPN_orderId'] = $xml_arr['out_trade_no'];
$save_column['OPN_rawOrderId'] = $xml_arr['out_trade_no'];
$save_column['OPN_invoiceId'] = $xml_arr['out_trade_no'];
$save_column['OPN_subject'] = $xml_arr['attach'];
$save_column['OPN_subject'] = $xml_arr['attach'] ? $xml_arr['attach'] : '';
$save_column['OPN_currency'] = $xml_arr['fee_type'];
$save_column['OPN_orderAmount'] = $xml_arr['total_fee'];
$save_column['OPN_payAmount'] = $xml_arr['total_fee'];
@ -65,7 +65,7 @@ class WxpayService extends CI_Controller {
$save_column['OPN_errMsg'] = isset($xml_arr['err_code_des']) ? $xml_arr['err_code_des'] : NULL;
$save_column['OPN_acquiringTime'] = date('Y-m-d H:i:s',strtotime($xml_arr['time_end']));
$save_column['OPN_completeTime'] = date('Y-m-d H:i:s',strtotime($xml_arr['time_end']));
$save_column['OPN_remark'] = $xml_arr['attach'];
$save_column['OPN_remark'] = $xml_arr['attach'] ? $xml_arr['attach'] : '';
$save_column['OPN_payerLogId'] = $xml_arr['openid'];
$save_column['OPN_payerStatus'] = $xml_arr['is_subscribe']==='Y' ? "subscribed" : NULL;
$save_column['OPN_fundSource'] = $site;
@ -77,12 +77,13 @@ class WxpayService extends CI_Controller {
$save_column['OPN_noticeSendStatus'] = 'unsend';
$save_column['OPN_noticeSendTime'] = NULL;
$save_column['OPN_accountMethod'] = $this->config->item('method_code', 'wxpay');
$save_column['OPN_paymentSource'] = $xml_arr['bank_type'];
if ( $this->note_model->insert_note($save_column) ) {
$response['return_code'] = 'SUCCESS';
$response['return_msg'] = 'OK';
}
}
async_curl($this->config->item('send_notify_url', 'wxpay'));
// async_curl($this->config->item('send_notify_url', 'wxpay'));
return $this->response_to_wx($response);
}
@ -92,7 +93,7 @@ class WxpayService extends CI_Controller {
foreach ($all_account as $account) {
$this->download_bill($account);
}
async_curl($this->config->item('send_notify_url', 'wxpay'));
// async_curl($this->config->item('send_notify_url', 'wxpay'));
async_curl('https://www.mycht.cn/webht.php/apps/pay/alipaytradeservice/get_billfile');
async_curl('https://www.mycht.cn/download_statement/download_files.php', 30); // iPaylinks日账单
/**
@ -129,6 +130,8 @@ class WxpayService extends CI_Controller {
$save_column['OPN_transactionId'] = $row['refund_id'];
$save_column['OPN_orderAmount'] = "-" . $row['settlement_refund_fee'];
$save_column['OPN_payAmount'] = "-" . $row['settlement_refund_fee'];
// $save_column['OPN_payFee'] = bcsub(0, $row['wxpay_fee']);
// $save_column['OPN_netAmount'] = "-" . bcadd($row['call_refund_fee'], $row['wxpay_fee']);
$save_column['OPN_resultCode'] = $row['refund_status'];
$save_column['OPN_resultMsg'] = $row['refund_status'];
$save_column['OPN_entryAmountCNY'] = floatval("-" . $ssje);
@ -136,7 +139,11 @@ class WxpayService extends CI_Controller {
$save_column['OPN_relatedId'] = $row['transaction_id'];
} else {
// 收款
$ssje = $this->account_model->get_ssje($row['settlement_total_fee'], str_replace("CNY", "RMB", strtoupper($row['currency_type'])), $save_column['OPN_accountMethod']);
$save_column['OPN_payFee'] = bcsub(0, $row['wxpay_fee']);
$save_column['OPN_netAmount'] = bcsub($row['settlement_total_fee'], $row['wxpay_fee']);
$ssje = $this->account_model->get_ssje_exclude_fee($save_column['OPN_netAmount'], str_replace("CNY", "RMB", strtoupper($row['currency_type'])), $save_column['OPN_accountMethod']);
$save_column['OPN_transactionId'] = $row['transaction_id'];
$save_column['OPN_orderAmount'] = $row['settlement_total_fee'];
$save_column['OPN_payAmount'] = $row['settlement_total_fee'];
@ -145,6 +152,7 @@ class WxpayService extends CI_Controller {
$save_column['OPN_entryAmountCNY'] = floatval($ssje);
$save_column['OPN_noticeType'] = 'pay';
$save_column['OPN_relatedId'] = '';
$save_column['OPN_paymentSource'] = $row['bank_type'];
}
$save_column['OPN_noticeSendStatus'] = 'unsend';
$save_column['OPN_transactionResult'] = 'completed';
@ -161,8 +169,45 @@ class WxpayService extends CI_Controller {
$save_column['OPN_rawContent'] = json_encode($row);
$save_column['OPN_noticeTime'] = date('Y-m-d H:i:s');
$this->note_model->insert_note($save_column) ;
$this->note_model->insert_note($save_column);
}
return;
}
public function query()
{
$all_account = explode(",", $this->config->item('all_account', 'wxpay'));
$GLOBALS['__WX_SITE_NAME__'] = $all_account[0];
$transaction_id = $this->input->get_post("keywords");
$this->load->model('WxpayQueryContentBuilder', 'query_builder');
$this->query_builder->set_transaction_id($transaction_id);
// $this->query_builder->set_out_trade_no($transaction_id);
$this->load->library('Wxpay_call');
foreach ($all_account as $account) {
// echo json_encode($this->query_builder);
// return;
$resultR = $this->wxpay_call->query_order_refund($this->query_builder, 0, $account);
$result = $this->wxpay_call->query_order_refund($this->query_builder, 1, $account);
if ($result['status'] === true) {
echo json_encode($result);
return;
$this->note_model->add_note_wxpay($result['data'], $account, 'pay');
}
if ($resultR['status'] === true) {
echo json_encode($result);
return;
$this->note_model->add_note_wxpay($resultR['data'], $account, 'refund');
}
// log_message('error',"query wxpay failed. $account $transaction_id");
}
$data['method_code'] = 15016;
$data["method_name"] = 'WeChat';
$data['date'] = date('Y-m-d');
$data['notelist'] = $this->note_model->search_key($transaction_id);
echo json_encode($data);
// $this->load->view("payment_list",$data);
return;
}

@ -316,3 +316,93 @@ function zero_to_one($value)
{
return $value==0 ? 1 : $value;
}
function to_json($arr, $options = 0)
{
if (version_compare(phpversion(), '5.4.0', '>=') === true) {
return json_encode($arr, $options | 64);
}
return str_replace('\\/', '/', json_encode($arr, $options)); // ~ php 5.3
}
/**
* 校验$value是否非空
* if not set ,return true;
* if is null , return true;
**/
function checkEmpty($value)
{
if (!isset($value))
return true;
if ($value === null)
return true;
if (trim($value) === "")
return true;
return false;
}
/**
* 连连支付
* @uses LianlianService
*/
/**
* 递归地将数组转为key=value形式, 仅拼接叶子节点
* @uses LianlianService
*/
function generateKeyValueParts($key, $value, &$parts) {
if (is_array($value)) {
ksort($value); // Sort inner array keys
foreach ($value as $innerKey => $innerValue) {
generateKeyValueParts($innerKey, $innerValue, $parts); //recursive call and build the key
}
} else {
$parts[] = $key . '=' . $value;
}
}
/**
* 生成待加签字符串
* @uses LianlianService
*/
function generateSignContent($data) {
ksort($data); // Sort keys alphabetically
$parts = [];
foreach ($data as $key => $value) {
generateKeyValueParts($key, $value, $parts);
}
return implode('&', $parts);
}
/**
* 连连
* 退款状态, 结果码
*/
function refund_status($code) {
$lianlian_refund_code = [
'PC' => 'pending',
'RS' => 'completed',
'RF' => 'failed',
];
return $code ? $lianlian_refund_code[$code] : '';
}
/**
* 连连
* 退款状态, 发送码
* @param string $code
*/
function refund_status_send($code) {
$lianlian_refund_code = [
'PC' => 'closed',
'RS' => 'unsend',
'RF' => 'closed',
];
return $code ? $lianlian_refund_code[$code] : '';
}
/**
* End 连连支付
*/

@ -7,22 +7,75 @@ class Wxpay_call
protected $ci;
private $api_info_arr = array();
private $merchant_account = '';
public function __construct()
public function __construct($account = '')
{
$this->ci =& get_instance();
$this->ci->load->helper('payment');
$this->ci->config->load('wxpay', true);
// $this->ci->load->model('WxpayQueryContentBuilder', 'query_builder');
$this->merchant_account = $account;
}
private function init_api()
private function init_api($account = '')
{
$this->wx_site_config = $this->ci->config->item($GLOBALS['__WX_SITE_NAME__'], 'wxpay');
$account = $account ? $account : ($this->merchant_account ? $this->merchant_account : $GLOBALS['__WX_SITE_NAME__']);
$this->wx_site_config = $this->ci->config->item($account, 'wxpay');
$this->api_info_arr['appid'] = $this->wx_site_config['app_id'];
$this->api_info_arr['mch_id'] = $this->wx_site_config['mch_id'];
$this->api_info_arr['key'] = $this->wx_site_config['key'];
$this->api_info_arr['app_secret'] = $this->wx_site_config['app_secret'];
// $this->api_info_arr['key'] = $this->wx_site_config['key'];
// $this->api_info_arr['app_secret'] = $this->wx_site_config['app_secret'];
}
public function query_order_refund($query_content, $query_refund=0, $account = '')
{
$ret = array('status'=>false, 'data'=>array());
$this->init_api($account);
// return false;
$url = $query_refund === 0 ? "https://api.mch.weixin.qq.com/pay/refundquery" : "https://api.mch.weixin.qq.com/pay/orderquery";
$query_content_input = $query_content->getBizContent(true);
//检测必填参数
if( ! $query_content_input['transaction_id']) {
throw new WxPayException("查询接口中,缺少必填参数 transaction_id ");
}
$this->api_info_arr['nonce_str'] = ($this->get_nonce_str());//随机字符串
$this->api_info_arr['sign'] = $this->make_sign(array_merge($this->api_info_arr, $query_content_input));//签名
$xml = to_xml(array_merge($this->api_info_arr, $query_content_input));
// log_message('error','test: ' . __CLASS__ . PHP_EOL . var_export(array_merge($this->api_info_arr, $query_content_input), 1));
$response = $this->post_xml_curl($this->api_info_arr, $xml, $url, 20);
$response_arr = from_xml($response);
$ret['status'] = $response_arr['return_code'] === 'SUCCESS' && $response_arr['result_code'] === 'SUCCESS';
if ($query_refund !== 0) {
$ret['data'] = [$response_arr];
return $ret;
}
if ($ret['status'] !== true) {
return $ret;
}
// log_message('error','test: response_arr ' .$query_refund . __CLASS__ . PHP_EOL . var_export($response_arr, 1));
$refund_times = strval($response_arr['refund_count']);
$order_keys = ( array_filter(array_keys($response_arr), function ($k) {
return stripos($k, 'refund') === false;
}));
$order_item = array_intersect_key($response_arr, array_flip($order_keys));
for ($i=0; $i < $refund_times; $i++) {
$filteredKeys = array_filter(array_keys($response_arr), function ($k) use ($i) {
return substr($k, -2) === '_' . $i;
});
$refund_item_raw = array_intersect_key($response_arr, array_flip($filteredKeys));
$suffix = '_' . $i;
$refund_item = array_combine(
array_map(function($key) use ($suffix) {
return substr($key, 0, -strlen($suffix));
}, array_keys($refund_item_raw)),
$refund_item_raw
);
$ret['data'][] = array_merge($order_item, $refund_item);
}
return $ret;
}
/**

@ -204,8 +204,16 @@ class Alipay_model extends CI_Model {
,DeleteFlag
) VALUES (?,?,15015,?,?,?,?,?,?,?,?,?,?,?,0,0)";
$query = $this->HT->query($sql, array($GAI_COLI_SN, $GAI_SQJE, $GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, substr($GAI_AccreditNo,0, 30), $GAI_Memo));
$insertid = $this->HT->last_id('BIZ_GroupAccountInfo');
return $query;
$insertid = ($query && $query->num_rows() > 0) ? $this->HT->last_id('BIZ_GroupAccountInfo') : false;
return $insertid;
// return $query;
// return $query->num_rows() > 0;
// affected_rows() doesn't work with the 'sqlsrv' driver in CI2
// The solution: Upgrade to the latest CodeIgniter 3.0.x version
// $ssql = "SELECT 1 as 'exist' from BIZ_GroupAccountInfo where GAI_AccreditNo=? ";
// $squery = $this->HT->query($ssql, array($GAI_AccreditNo));
// $ret = $squery->result();
// return !empty($ret);
}
//添加收款记录(商务订单)
@ -238,8 +246,8 @@ class Alipay_model extends CI_Model {
,DeleteFlag
) VALUES (?,?,15015,?,?,?,?,?,?,?,?,?,?,?,?,0,0)";
$query = $this->HT->query($sql, array(substr($GAI_AccreditNo,0, 30), $GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_Money, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, substr($GAI_AccreditNo,0, 30), $GAI_Memo));
$insertid = $this->HT->last_id('BIZ_GroupAccountInfo');
return $query;
$insertid = ($query && $query->num_rows() > 0) ? $this->HT->last_id('BIZ_GroupAccountInfo') : false;
return $insertid;
}
//添加收款记录(传统订单)
@ -272,7 +280,7 @@ class Alipay_model extends CI_Model {
ELSE
UPDATE GroupAccountInfo SET GAI_SSJE='$GAI_SSJE' WHERE GAI_AccreditNo='" . substr($GAI_AccreditNo,0, 30) ."' ";
$query = $this->HT->query($sql, array(substr($GAI_AccreditNo,0, 30), $GAI_COLI_SN, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, substr($GAI_AccreditNo,0, 30), $GAI_Memo));
$insertid = $this->HT->last_id('GroupAccountInfo');
$insertid = ($query && $query->num_rows() > 0) ? $this->HT->last_id('GroupAccountInfo') : false;
return $insertid;
}
@ -357,12 +365,12 @@ class Alipay_model extends CI_Model {
}
/** JJH: 添加订单收款记录之后执行 */
public function exec_addToTask($GAI_SN)
public function exec_addToTask($GAI_SN, $OrderSourceType = 227001)
{
$sql = " if not exists (
select top 1 1 from Sysautotask
where SAT_Type=1 and SAT_SourceSN=$GAI_SN
) exec SP_AddToSystask 1," . $GAI_SN;
) exec SP_AddToSystask 1," . $GAI_SN . ", ". $OrderSourceType;
$query = $this->HT->query($sql);
return $query;
}

@ -71,12 +71,42 @@ class Alipay_note_model extends CI_Model {
$search_key = trim($search_key);
if (!empty($search_key)) {
$search_sql.=" AND ( pn.ALI_dealId = '$search_key'
OR pn.ALI_orderId like '%$search_key%' )";
OR pn.ALI_orderId like '%$search_key%'
OR pn.ALI_memo like '%$search_key%'
)";
}
$this->search = $search_sql;
return $this->get_list();
}
/**
* 根据支付交易号查询已退款的总金额
*/
public function search_deal_refund_from_memo($search_key, $time = NULL)
{
$this->init();
$this->orderby = false;
$search_sql = '';
$search_key = trim($search_key);
if (!empty($search_key)) {
$search_sql .= " AND ( pn.ALI_memo like '%$search_key%' ) and pn.ALI_payType = 'refund' AND ALI_acquiringTime < '$time' ";
}
$this->search = $search_sql;
$sql = "SELECT SUM(CAST(pn.ALI_orderAmount AS FLOAT)) refunded_fee
FROM InfoManager.dbo.AlipayLog pn
WHERE 1=1 ";
$this->search ? $sql .= $this->search : false;
$this->orderby ? $sql .= $this->orderby : false;
// log_message('error', $sql);
$query = $this->INFO->query($sql);
if ($query->num_rows() > 0) {
$row = $query->row();
return $row;
} else {
return FALSE;
}
}
public function note_exists($dealId)
{
$this->init();
@ -98,6 +128,7 @@ class Alipay_note_model extends CI_Model {
WHERE ALI_dealId = '$ALI_dealId'
)
";
// AND ALI_orderAmount = '$ALI_orderAmount'
$sql .= "
INSERT INTO AlipayLog
(

@ -23,6 +23,16 @@ class Online_payment_account_model extends CI_Model {
}
return NULL;
}
public function get_ssje_exclude_fee($amount, $currency='USD', $pay_type='15002')
{
$sql = "SELECT dbo.ConvertToRMB(?, ?) as ssje";
$query = $this->HT->query($sql,array($currency, $amount));
$result = $query->result();
if ( ! empty($result)) {
return $result[0]->ssje;
}
return 0;
}
//根据订单号获取外联邮箱
public function get_order($COLI_ID, $orderinfo = false, $ordertype = 'N', $handpick=false) {
@ -248,7 +258,7 @@ class Online_payment_account_model extends CI_Model {
}
//添加收款记录(商务订单)
public function add_account_info($GAI_COLI_SN, $payment_method, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo) {
public function add_account_info($GAI_COLI_SN, $payment_method, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo, $GAI_API = null) {
//先判断是否有这条数据
$sql = "
@ -272,16 +282,18 @@ class Online_payment_account_model extends CI_Model {
,GAI_CusEmail
,GAI_AccreditNo
,GAI_Memo
,GAI_API
,GAI_State
,DeleteFlag
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0)";
$query = $this->HT->query($sql, array($GAI_AccreditNo, $GAI_COLI_SN, $GAI_COLI_ID, $payment_method, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo));
$insertid = $this->HT->last_id('BIZ_GroupAccountInfo');
return $query;
,DeleteFlag,LastEditTime
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE())";
$query = $this->HT->query($sql, array($GAI_AccreditNo, $GAI_COLI_SN, $GAI_COLI_ID, $payment_method, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo, $GAI_API));
$insertid = ($query && $query->num_rows() > 0) ? $this->HT->last_id('BIZ_GroupAccountInfo') : false;
return $insertid;
}
//添加收款记录(商务订单),APP会自动增加记录所以添加前根据金额来判断是否有重复记录
public function add_account_info_forAPP($GAI_COLI_SN, $payment_method, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo) {
public function add_account_info_forAPP($GAI_COLI_SN, $payment_method, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo, $GAI_API = null) {
//先判断是否有这条数据
$sql = "
IF NOT EXISTS(
@ -304,19 +316,26 @@ class Online_payment_account_model extends CI_Model {
,GAI_CusEmail
,GAI_AccreditNo
,GAI_Memo
,GAI_API
,GAI_State
,DeleteFlag
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0)";
$query = $this->HT->query($sql, array($GAI_COLI_SN, $GAI_SQJE, $payment_method, $GAI_COLI_SN, $GAI_COLI_ID, $payment_method, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo));
$insertid = $this->HT->last_id('BIZ_GroupAccountInfo');
return $query;
,DeleteFlag,LastEditTime
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE())";
$query = $this->HT->query($sql, array($GAI_COLI_SN, $GAI_SQJE, $payment_method, $GAI_COLI_SN, $GAI_COLI_ID, $payment_method, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo, $GAI_API));
$insertid = ($query && $query->num_rows() > 0) ? $this->HT->last_id('BIZ_GroupAccountInfo') : false;
return $insertid;
// return $query->num_rows() > 0;
// affected_rows() doesn't work with the 'sqlsrv' driver in CI2
// The solution: Upgrade to the latest CodeIgniter 3.0.x version
// $ssql = "SELECT 1 as 'exist' from BIZ_GroupAccountInfo where GAI_AccreditNo=? ";
// $squery = $this->HT->query($ssql, array($GAI_AccreditNo));
// $ret = $squery->result();
// return !empty($ret);
}
//添加收款记录(传统订单)
public function add_tour_account_info($GAI_COLI_SN, $payment_method, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo) {
public function add_tour_account_info($GAI_COLI_SN, $payment_method, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo, $GAI_API = null) {
//先判断是否有这条数据
$sql = "
IF NOT EXISTS(
SELECT TOP 1 1
FROM GroupAccountInfo
@ -336,11 +355,12 @@ class Online_payment_account_model extends CI_Model {
,GAI_CusEmail
,GAI_AccreditNo
,GAI_Memo
,GAI_API
,GAI_State
,DeleteFlag
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,0,0)";
$query = $this->HT->query($sql, array($GAI_AccreditNo, $GAI_COLI_SN, $payment_method, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo));
$insertid = $this->HT->last_id('GroupAccountInfo');
,DeleteFlag,LastEditTime
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE())";
$query = $this->HT->query($sql, array($GAI_AccreditNo, $GAI_COLI_SN, $payment_method, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo, $GAI_API));
$insertid = ($query && $query->num_rows() > 0) ? $this->HT->last_id('GroupAccountInfo') : false;
return $insertid;
}
@ -359,12 +379,24 @@ class Online_payment_account_model extends CI_Model {
}
/** JJH: 添加订单收款记录之后执行 */
public function exec_addToTask($GAI_SN)
public function exec_addToTask($GAI_SN, $OrderSourceType =227001)
{
if (empty($GAI_SN)) return false;
$sql = " if not exists (
select top 1 1 from Sysautotask
where SAT_Type=1 and SAT_SourceSN=$GAI_SN
) exec SP_AddToSystask 1," . $GAI_SN;
where SAT_Type=1 and SAT_SourceSN=$GAI_SN and SAT_OrderSourceType= $OrderSourceType
) exec SP_AddToSystask 1," . $GAI_SN . "," . $OrderSourceType;
$query = $this->HT->query($sql);
return $query;
}
/**
* QQS: APP组退款之后执行
* 插入数据到“我的支付”
**/
public function exec_BIZ_TrainCostAdd($COLI_SN, $ssje)
{
$sql = " EXEC dbo.SP_BIZ_TrainCostAdd $COLI_SN, $ssje; select 0; ";
$query = $this->HT->query($sql);
return $query;
}
@ -429,36 +461,67 @@ class Online_payment_account_model extends CI_Model {
{
$ret = array();
$send_flag = "send-to-finance";
$paypal_sql = "SELECT 'paypal' as payment_type,
pn_sn note_sn,pn_txn_id transaction_id,
(select DEI_DepartmentName from OperatorInfo inner join DepartmentInfo on OPI_DEI_SN=DEI_SN
where OPI_SN=ISNULL(table_t.COLI_OPI_ID, isnull(table_b.COLI_OPI_ID,table_app.COLI_OPI_ID))
) as department,
case when ISNULL(table_t.COLI_GRI_SN,table_b.COLI_GRI_SN) is null
then isnull(table_app.COLI_GroupCode,table_app.COLI_ID)
else (select GRI_Name from GRoupInfo
where gri_sn=ISNULL(table_t.COLI_GRI_SN,table_b.COLI_GRI_SN)
) end as gri_name,
pn.pn_payment_date payment_date,
pn.pn_mc_gross amount,pn_mc_currency currency,
isnull(table_t.GAI_SSJE,isnull(table_b.GAI_SSJE,table_app.GAI_SSJE)) amount_CNY,
pn_payer payer,pn_payer_email payer_email
from paypal_note pn
left join (
select gai.GAI_SSJE,gai.GAI_AccreditNo ,coli.COLI_GRI_SN,coli.COLI_OPI_ID,coli.COLI_SN
from GroupAccountInfo gai inner join ConfirmLineInfo coli on coli.COLI_SN=gai.GAI_COLI_SN
) as table_t on table_t.GAI_AccreditNo=pn.pn_txn_id
left join (
select bgai.GAI_AccreditNo,bgai.GAI_SSJE ,bcoli.COLI_GRI_SN,bcoli.COLI_OPI_ID,bcoli.COLI_SN
from BIZ_GroupAccountInfo bgai inner join BIZ_ConfirmLineInfo bcoli on bcoli.COLI_SN=bgai.GAI_COLI_SN
) as table_b on table_b.GAI_AccreditNo=pn.pn_txn_id
left join (
select bgai.GAI_AccreditNo,bgai.GAI_SSJE,bgai.GAI_SQJE,bgai.GAI_SQJECurrency ,bcoli.COLI_GRI_SN,bcoli.COLI_OPI_ID,bcoli.COLI_SN ,bcoli.COLI_id ,bcoli.COLI_GroupCode
from BIZ_GroupAccountInfo bgai inner join BIZ_ConfirmLineInfo bcoli on bcoli.COLI_SN=bgai.GAI_COLI_SN
) as table_app on table_app.COLI_ID=REPLACE ( pn_invoice , '_B' , '' )
and pn.pn_mc_gross=table_app.GAI_SQJE and pn.pn_mc_currency=table_app.GAI_SQJECurrency
where pn_send='$send_flag'
order by department ";
$paypal_sql = "WITH pn
AS (
SELECT pn_txn_id,pn_invoice,pn_mc_gross,pn_mc_currency,pn_payer_email,pn_payer,pn_payment_date,pn_datetime,pn_sn
,ROW_NUMBER() OVER (
PARTITION BY pn_txn_id ORDER BY pn_payer_email DESC
) AS rn
FROM paypal_note p1
WHERE p1.pn_send = '$send_flag'
)
SELECT 'paypal' AS payment_type,pn_sn note_sn,pn_txn_id transaction_id
,(
SELECT DEI_DepartmentName
FROM OperatorInfo
INNER JOIN DepartmentInfo ON OPI_DEI_SN = DEI_SN
WHERE OPI_SN = ISNULL(table_t.COLI_OPI_ID, table_b.COLI_OPI_ID)
) AS department
,CASE
WHEN ISNULL(table_t.COLI_GRI_SN, table_b.COLI_GRI_SN) IS NULL
THEN ''
ELSE (
SELECT GRI_Name
FROM GRoupInfo
WHERE gri_sn = ISNULL(table_t.COLI_GRI_SN, table_b.COLI_GRI_SN)
)
END AS gri_name
,pn.pn_payment_date payment_date
,pn.pn_mc_gross amount
,pn_mc_currency currency
,isnull(table_t.GAI_SSJE, table_b.GAI_SSJE) amount_CNY
,pn_payer payer
,pn_payer_email payer_email
FROM pn
LEFT JOIN (
SELECT SUM( gai.GAI_SSJE) GAI_SSJE
,gai.GAI_AccreditNo
,coli.COLI_GRI_SN
,coli.COLI_OPI_ID
,coli.COLI_SN
FROM GroupAccountInfo gai
INNER JOIN ConfirmLineInfo coli ON coli.COLI_SN = gai.GAI_COLI_SN
GROUP BY gai.GAI_AccreditNo
,coli.COLI_GRI_SN
,coli.COLI_OPI_ID
,coli.COLI_SN
) AS table_t ON table_t.GAI_AccreditNo = pn.pn_txn_id
LEFT JOIN (
SELECT bgai.GAI_AccreditNo
,sum(bgai.GAI_SSJE) GAI_SSJE
,bcoli.COLI_GRI_SN
,bcoli.COLI_OPI_ID
,bcoli.COLI_SN
FROM BIZ_GroupAccountInfo bgai
INNER JOIN BIZ_ConfirmLineInfo bcoli ON bcoli.COLI_SN = bgai.GAI_COLI_SN
GROUP BY bgai.GAI_AccreditNo
,bcoli.COLI_GRI_SN
,bcoli.COLI_OPI_ID
,bcoli.COLI_SN
) AS table_b ON table_b.GAI_AccreditNo = pn.pn_txn_id
WHERE pn.rn = 1
ORDER BY department ASC
,pn.payment_date DESC";
$ret = $paypal_list = $this->HT->query($paypal_sql)->result_array();
$ipaylinks_sql = "SELECT 'ipaylinks' as 'payment_type', IPL_sn note_sn,IPL_dealId transaction_id,
(select DEI_DepartmentName from OperatorInfo inner join DepartmentInfo on OPI_DEI_SN=DEI_SN

@ -27,11 +27,21 @@ class Online_payment_note_model extends CI_Model {
return $this->info->query($ret, array($refund_id))->num_rows() > 0;
}
public function insert_note($column)
public function insert_note($column, $check_exists = false)
{
if ($column === null) {
return false;
}
if ($check_exists === true) {
$sql = "SELECT TOP 1 1
FROM OnlinePaymentNote
WHERE OPN_accountMethod={$column['OPN_accountMethod']} AND OPN_transactionId = '{$column['OPN_transactionId']}'";
$query = $this->info->query($sql);
if ($query->num_rows() > 0) {
// todo: update pay_fee, CNY ssje
return false;
}
}
$this->info->insert('OnlinePaymentNote', $column);
$ret = "SELECT TOP 1 * FROM OnlinePaymentNote WHERE OPN_transactionId=? ORDER BY OPN_SN DESC ";
return $this->info->query($ret, array($column['OPN_transactionId']))->row();
@ -64,7 +74,7 @@ class Online_payment_note_model extends CI_Model {
$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->search = $method===null ? "" : " AND OPN_accountMethod IN ($method) ";
$this->send = " AND ISNULL(OPN_noticeSendStatus,'') in ('', 'unsend') ";
return $this->query_note();
@ -75,7 +85,7 @@ class Online_payment_note_model extends CI_Model {
$this->init_query();
$this->topnum = $num;
$this->send = " AND (OPN_noticeSendStatus) = 'closed' ";
$this->search = $method===null ? "" : " AND OPN_accountMethod=$method ";
$this->search = $method===null ? "" : " AND OPN_accountMethod IN ($method) ";
$this->search .= " AND OPN_noticeTime BETWEEN '$date 00:00:00' AND '$date 23:59:59' ";
return $this->query_note();
}
@ -84,7 +94,7 @@ class Online_payment_note_model extends CI_Model {
{
$this->init_query();
$this->topnum = $num;
$this->search = $method===null ? "" : " AND OPN_accountMethod=$method ";
$this->search = $method===null ? "" : " AND OPN_accountMethod IN ($method) ";
// 1小时前
$date = date("Y-m-d H:i:s", time() - 3600);
$this->search .= $num !== false ? " AND OPN_noticeSendTime < '$date' " : '';
@ -113,6 +123,38 @@ class Online_payment_note_model extends CI_Model {
$this->orderby = ' ORDER BY OPN_SN DESC ';
}
private $code_brandname = array(
"15002" => "PayPal",
"15010" => "PayPal",
"15015" => "Alipay",
"15016" => "WeChat",
"15018" => "Credit Card-iPaylinks",
"15035" => "Credit Card-Lianlian",
);
private $wxpay_app = array(
"wx749246dd935ca07b" => "APP",
"wx5d01021a6d515098" => "HLY", // "花梨鹰小程序", // 交行收款码
"wxd6c8dd69af5128cd" => "", // "NATIVE",
"wx7e605820faf98a05" => "Trippest-NATIVE",
"0" => "unknown",
);
public function set_brandname(&$ele)
{
$ele->brand_name = "none";
if ($this->code_brandname[$ele->OPN_accountMethod]) {
$ele->brand_name = $this->code_brandname[$ele->OPN_accountMethod];
}
$raw = json_decode($ele->OPN_rawContent);
$wx_app = isset($raw->app_id) ? $raw->app_id : '0';
$wx_app = $wx_app!=='0' ? $wx_app : (isset($raw->appid) ? $raw->appid : '0');
$ele->app_name = "";
if ($ele->OPN_accountMethod ===15016 && isset($this->wxpay_app[$wx_app])) {
$ele->app_name = $this->wxpay_app[$wx_app];
}
}
public function query_note()
{
$top_sql = $this->topnum ? (" TOP " . $this->topnum) : "";
@ -128,7 +170,9 @@ class Online_payment_note_model extends CI_Model {
// log_message('error', PHP_EOL . $sql);
$query = $this->info->query($sql);
return $query->result();
$result = $query->result();
array_walk($result, 'Online_payment_note_model::set_brandname');
return $result;
}
public function get_note($opn_id)
@ -139,6 +183,32 @@ class Online_payment_note_model extends CI_Model {
return $this->query_note();
}
/**
* @param mixed $where ['OPN_SN' => ['=', {val}] ]
*/
public function get_note_where($where) {
$this->init_query();
$this->topnum=1;
$this->search = '';
foreach ($where as $key => $value) {
$where_val = '';
switch (strtolower($value[0])) {
case '=':
$where_val = " = {$this->info->escape($value[1])}";
break;
case 'in':
$where_val = " IN ({$this->info->escape($value[1])})";
break;
default:
$where_val = " = {$this->info->escape($value[1])}";
break;
}
$this->search .= " AND {$key} {$where_val} ";
}
return $this->query_note();
}
public function search_key($keyword)
{
$this->init_query();
@ -147,6 +217,7 @@ class Online_payment_note_model extends CI_Model {
$search_sql = "";
if ( ! empty($keyword)) {
$search_sql.=" AND ( OPN_transactionId = '$keyword'
OR OPN_relatedId like '%$keyword%'
OR OPN_orderId like '%$keyword%'
OR OPN_rawOrderId like '%$keyword%' )";
}
@ -157,7 +228,7 @@ class Online_payment_note_model extends CI_Model {
public function search_date($date, $method=null)
{
$this->init_query();
$this->search = $method===null ? "" : " AND OPN_accountMethod=$method ";
$this->search = $method===null ? "" : " AND OPN_accountMethod IN ($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();
@ -404,6 +475,118 @@ class Online_payment_note_model extends CI_Model {
return $result_object;
}
/**
* @uses WxpayService::query
*/
public function add_note_wxpay($result_data, $target_account, $type='pay')
{
$this->load->model('Online_payment_account_model', 'account_model');
foreach ($result_data as $key => $row) {
$save_column = array();
$save_column['OPN_accountMethod'] = $this->config->item('method_code', 'wxpay');
$total_fee = bcdiv($row['total_fee'], $this->config->item('currency_unit', 'wxpay'));
$OPN_currency = isset($row['currency_type']) ? $row['currency_type'] : (isset($row['fee_type']) ? $row['fee_type'] : 'CNY');
if ($type != 'pay') {
// 退款
$refund_fee = bcdiv($row['refund_fee'], $this->config->item('currency_unit', 'wxpay'));
$ssje = $this->account_model->get_ssje($refund_fee, str_replace("CNY", "RMB", strtoupper($OPN_currency)), $save_column['OPN_accountMethod']);
$save_column['OPN_transactionId'] = $row['refund_id'];
$save_column['OPN_orderAmount'] = "-" . $refund_fee;
$save_column['OPN_payAmount'] = "-" . $refund_fee;
$save_column['OPN_resultCode'] = $row['refund_status'];
$save_column['OPN_resultMsg'] = $row['refund_status'];
$save_column['OPN_entryAmountCNY'] = floatval("-" . $ssje);
$save_column['OPN_noticeType'] = $type;
$save_column['OPN_relatedId'] = $row['transaction_id'];
$save_column['OPN_acquiringTime'] = date('Y-m-d H:i:s', strtotime($row['refund_success_time']));
$save_column['OPN_completeTime'] = date('Y-m-d H:i:s', strtotime($row['refund_success_time']));
} else {
// 收款
$total_fee = bcdiv($row['total_fee'], $this->config->item('currency_unit', 'wxpay'));
$ssje = $this->account_model->get_ssje($total_fee, str_replace("CNY", "RMB", strtoupper($OPN_currency)), $save_column['OPN_accountMethod']);
$save_column['OPN_transactionId'] = $row['transaction_id'];
$save_column['OPN_orderAmount'] = $total_fee;
$save_column['OPN_payAmount'] = $total_fee;
$save_column['OPN_resultCode'] = $row['trade_state'];
$save_column['OPN_resultMsg'] = $row['trade_state'];
$save_column['OPN_entryAmountCNY'] = floatval($ssje);
$save_column['OPN_noticeType'] = 'pay';
$save_column['OPN_relatedId'] = '';
$save_column['OPN_acquiringTime'] = date('Y-m-d H:i:s', strtotime($row['time_end']));
$save_column['OPN_completeTime'] = date('Y-m-d H:i:s', strtotime($row['time_end']));
}
$save_column['OPN_noticeSendStatus'] = 'unsend';
$save_column['OPN_transactionResult'] = 'completed';
$save_column['OPN_orderId'] = $row['out_trade_no'];
$save_column['OPN_rawOrderId'] = $row['out_trade_no'];
$save_column['OPN_invoiceId'] = $row['out_trade_no'];
$save_column['OPN_subject'] = isset($row['item_name']) ? $row['item_name'] : '';
$save_column['OPN_currency'] = $OPN_currency;
$save_column['OPN_remark'] = empty($row['attach']) ? '' : json_encode($row['attach']);
$save_column['OPN_payerLogId'] = isset( $row['openid']) ? $row['openid'] : '';
$save_column['OPN_fundSource'] = $target_account;
$save_column['OPN_rawContent'] = json_encode($row);
$save_column['OPN_noticeTime'] = date('Y-m-d H:i:s');
// $this->insert_note($save_column) ; // todo:
// log_message('error', 'test: ' . __CLASS__ . PHP_EOL . var_export($save_column, 1));
}
return;
}
/**
* @uses AlipayTradeService::alipay_notice
*/
public function add_note_alipay($result_data, $check_exists=false)
{
$this->load->model('Online_payment_account_model', 'account_model');
if ($check_exists === true) {
$sql = "SELECT TOP 1 1
FROM OnlinePaymentNote
WHERE OPN_accountMethod=15015 AND OPN_transactionId = '{$result_data['transaction_id']}'";
$query = $this->info->query($sql);
if ($query->num_rows() > 0) {
// todo: update pay_fee, CNY ssje
return false;
}
}
$ssje = $this->account_model->get_ssje_exclude_fee($result_data['net_amount'], str_replace("CNY", "RMB", strtoupper($result_data['pay_currency'])));
$payment_date = date('Y-m-d H:i:s', strtotime($result_data['payment_date']) + 3600 * 8);
$complate_date = date('Y-m-d H:i:s', strtotime($result_data['complate_date']) + 3600 * 8);
$save_column = array();
$save_column['OPN_transactionId'] = $result_data['transaction_id'];
$save_column['OPN_orderAmount'] = $result_data['pay_amount'];
$save_column['OPN_payAmount'] = $result_data['pay_amount'];
$save_column['OPN_payFee'] = isset($result_data['pay_fee']) ? bcsub(0,$result_data['pay_fee']) : null;
$save_column['OPN_netAmount'] = $result_data['net_amount'];
$save_column['OPN_resultCode'] = $result_data['event_result'];
$save_column['OPN_resultMsg'] = $result_data['event'];
$save_column['OPN_entryAmountCNY'] = floatval($ssje);
$save_column['OPN_noticeType'] = $result_data['fund_type'];
$save_column['OPN_relatedId'] = isset($result_data['referer_id']) ? $result_data['referer_id'] : null;
$save_column['OPN_acquiringTime'] = $result_data['payment_date'];
$save_column['OPN_completeTime'] = $result_data['complate_date'];
$save_column['OPN_accountMethod'] = 15015;
$save_column['OPN_noticeSendStatus'] = 'closed';
$save_column['OPN_transactionResult'] = $result_data['transaction_status'];
$save_column['OPN_orderId'] = $result_data['invoice_id'];
$save_column['OPN_rawOrderId'] = $result_data['invoice_id'];
$save_column['OPN_invoiceId'] = $result_data['invoice_id'];
$save_column['OPN_subject'] = isset($result_data['subject']) ? $result_data['subject'] : '';
$save_column['OPN_currency'] = $result_data['pay_currency'];
$save_column['OPN_remark'] = empty($result_data['remark']) ? '' : ($result_data['remark']);
$save_column['OPN_payerLogId'] = isset( $result_data['buyer_id']) ? $result_data['buyer_id'] : '';
$save_column['OPN_payerEmail'] = isset( $result_data['buyer_email']) ? $result_data['buyer_email'] : '';
$save_column['OPN_fundSource'] = $result_data['fund_source'];
$save_column['OPN_paymentSource'] = $result_data['payment_source'];
$save_column['OPN_rawContent'] = $result_data['memo'];
$save_column['OPN_noticeTime'] = date('Y-m-d H:i:s');
$this->insert_note($save_column) ;
return;
}
}

@ -49,6 +49,12 @@ class WxpayQueryContentBuilder extends CI_Model
$this->bizContentarr['tar_type'] = $tar_type;
}
public function set_transaction_id($v)
{
$this->transaction_id = $v;
$this->bizContentarr['transaction_id'] = $v;
}
}
/* End of file WxpayQueryContentBuilder.php */

@ -62,7 +62,12 @@
</form>
<div class="dl-horizontal">
<p><a href="javascript:void(0);" onclick="$('#note_original_data').toggle()" >原始数据</a></p>
<p> <span style="display: none;" id="note_original_data">
<?php echo str_replace('","', '"<br/>"', json_encode(json_decode($note->OPN_rawContent, true), JSON_UNESCAPED_UNICODE)); ?>
</span></p>
<p> <div style="display: none;" id="note_original_data">
<?php
$array = json_decode($note->OPN_rawContent, true);
$jsonPretty = json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
echo "<pre>$jsonPretty</pre>";
?>
<?php // echo str_replace('","', '"<br/>"', json_encode(json_decode($note->OPN_rawContent, true), JSON_UNESCAPED_UNICODE)); ?>
</div></p>
</div>

@ -8,7 +8,11 @@
<meta content="yes" name="apple-mobile-web-app-capable">
<meta name="referrer" content="always">
<title>Payment List - China Highlights</title>
<script src="http://www.mycht.cn/min?f=/js/jquery.min.js,/js/bootstrap.min.js,/js/navigation.js,/js/jquery.form.min.js"></script>
<!-- <script src="https://www.mycht.cn/min?f=/js/jquery.min.js,/js/bootstrap.min.js,/js/navigation.js,/js/jquery.form.min.js"></script> -->
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/js/navigation.js"></script>
<script type="text/javascript" src="/js/jquery.form.min.js"></script>
<link href="/css/webht/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="/css/webht/flatpicker.min.css">
<style type="text/css">
@ -25,18 +29,36 @@
.wechat-color {background-color: #62B900;}
.paypal-color {background-color: #002D89;}
.alipay-color {background-color: #00AAEE;}
.ipaylinks-color,.creditcard-color,.creditcard-ipaylinks-color {background-color: #A31022;}
.ipaylinks-color,.creditcard-color,.creditcard-ipaylinks-color {background-color: #AD1818;}
.creditcard-lianlian-color {background-color: #1985ff;}
.modal {background-color: rgba(0,0,0,0.075);}
.cht-color {background-color: #A31022;}
.cht-color {background-color: #AD1818;}
.trippest-color {background-color: #E83201;}
.app-color {background-color: #EC3A4F;}
.hly-color {background-color: #009fe9;}
.unknown-color{ background-color: #999999;}
.flex {display: flex;}
.items-center {align-items: center;}
.justify-center {justify-content: center;}
.ml-auto {margin-left: auto;}
</style>
<style type="text/css" media="screen and (max-width:767px)">
.navbar-header h1 {display: block; font-size: 20px;}
.navbar-header a { margin-left: 10px; }
</style>
<style>
.dayContainer{
max-width: 238px;
width: 238px;
min-width: unset;
}
.flatpickr-day{
max-width: 34px;
border-radius: 0;
}
</style>
</head>
<body>
<!-- Button trigger modal -->
@ -139,14 +161,14 @@
<a <?php if($method_code==='15002') { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('method'=>15002)) ?>">PayPal&raquo;</a>
&NonBreakingSpace;
<a <?php if($method_code==='15018') { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('method'=>15018)) ?>">信用卡&raquo;</a>
<a <?php if($method_code==='15018,15035') { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('method'=>'15018,15035')) ?>">信用卡&raquo;</a>
&NonBreakingSpace;
<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>
<!-- <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">
@ -165,6 +187,7 @@
<div class="col-md-4 col-xs-24 print-none">
<div class="row">
<form method="post" id="search_note_list" action="/webht.php/apps/pay/paymentservice/note_list/">
<!-- <form method="post" id="search_note_list" action="/webht.php/apps/pay/wxpayservice/query"> -->
<!-- <div class="input-group">
<label>
<input type="checkbox" name="" value="15016" checked readonly class="input-check"><span>微信</span>
@ -195,6 +218,9 @@
<p>3.sendfail 状态的需要手工设置正确的订单号</p>
<p>4.Pending 还未到账,需要人工检查,确认支付或者取消,需要手工关闭此通知</p>
<p>5.Denied 银行拒付,需要手工关闭此通知</p>
<p>6.closed 已经关闭此通知</p>
<h4>记录状态:</h4>
<p>1.recorded 表示已经录入HT订单收款</p>
</div>
</div>
<!-- left end -->
@ -202,13 +228,14 @@
<table class="table table-bordered table-hover">
<thead>
<tr>
<th >#</th>
<th >主题</th>
<th width="260" class="hidden-xs">subject</th>
<th width="20">#</th>
<th width="360">主题</th>
<th width="280" class="hidden-xs">subject</th>
<th width="280" class="hidden-xs">交易号</th>
<th width="150">收单时间</th>
<th width="150" class="hidden-xs">通知时间</th>
<th>状态[通知/记录]</th>
<!-- <th width="150" class="hidden-xs">通知时间</th> -->
<th width="150" class="hidden-xs">账单&nbsp;/&nbsp;录入</th>
<th width="150">状态[通知/记录]</th>
</tr>
</thead>
<tbody>
@ -218,7 +245,7 @@
<tr>
<td><?php echo $key+1; ?></td>
<td><span class="brand_text <?php echo strtolower(str_replace(" ","",$item->brand_name))."-color"; ?>"><?php echo $item->brand_name; ?></span>
<span class="brand_text <?php echo strtolower(str_replace(" ","",$item->OPN_fundSource))."-color"; ?>"><?php echo $item->OPN_fundSource; ?></span>
<span class="brand_text <?php echo strtolower(str_replace('cht', '',str_replace(" ","",$item->OPN_fundSource)))."-color"; ?>"><?php echo str_replace('cht', '', $item->OPN_fundSource); ?></span>
<?php echo $item->OPN_orderId . ' / ' . $item->OPN_orderAmount . $item->OPN_currency; ?></td>
<td class="hidden-xs">
@ -231,12 +258,19 @@
</td>
<td class="hidden-xs"><?php echo $item->OPN_transactionId; ?></td>
<td><?php echo $item->OPN_acquiringTime; ?></td>
<td class="hidden-xs"><?php echo $item->OPN_noticeTime; ?></td>
<!-- <td class="hidden-xs"><?php // echo $item->OPN_noticeTime; ?></td> -->
<td class="hidden-xs">
<div><?php echo $item->OPN_noticeTime ? $item->OPN_noticeTime : '--'; ?></div>
<div><?php echo $item->OPN_accountTime ? $item->OPN_accountTime : '--'; ?></div>
</td>
<td>
<?php
$send_text = '';$send_class='';
$recored_text = '';
if ($item->OPN_accountStatus !== 'recorded') {
$send_class = 'btn-danger';
} else {
$recored_text = '✅';// // ✅☑️✔️
}
if ($item->OPN_noticeSendStatus !== 'send' && substr($item->OPN_noticeSendStatus, 0, 5) !== 'send-') {
$send_class = 'btn-danger';
@ -245,12 +279,18 @@
$send_class = '';
}
?>
<?php if ($item->OPN_noticeType !== 'pay') {
<?php
if ($item->OPN_transactionResult !== 'completed') {
echo '<span class=text-muted >' . strtoupper($item->OPN_transactionResult) . '</span><br>';
} elseif ($item->OPN_noticeType !== 'pay') {
echo '<span class=text-danger >' . strtoupper($item->OPN_noticeType) . '</span><br>';
} ?>
<div class="flex items-center">
<a href="javascript:void(0);" class="btn btn-sm <?php echo $send_class; ?>" onclick="show_gai_modal('<?php echo $item->OPN_SN; ?>')">
<?php echo $item->OPN_noticeSendStatus .' / ' . $item->OPN_accountStatus; ?>
<?php echo $item->OPN_noticeSendStatus ; ?>
</a>
<span class="ml-auto"><?php echo ($recored_text); ?></span>
</div>
</td>
</tr>
<?php } ?>

@ -11,6 +11,8 @@ class Index extends CI_Controller {
$this->load->model('Paypal_model');
$this->load->model('Note_model');
$this->load->model('Group_model');
$this->load->model('Online_payment_note_model', 'online_note');
bcscale(2);
}
@ -583,7 +585,11 @@ class Index extends CI_Controller {
$pn_custom = $this->input->post('custom');
empty($pn_custom) ? $pn_custom = '' : false;
$pn_parent_txn_id = $this->input->post('parent_txn_id');
empty($pn_parent_txn_id) ? $pn_parent_txn_id = '' : false;
$pn_mc_gross = $this->input->post('mc_gross');
$pn_mc_fee = $this->input->post('mc_fee');
$pn_item_name = $this->input->post('item_name');
if (empty($pn_item_name)) {
@ -602,11 +608,15 @@ class Index extends CI_Controller {
$pn_payment_date = $this->input->post('payment_date');
$pn_payer = $this->input->post('first_name') . ' ' . $this->input->post('last_name');
$pn_payer_email = $this->input->post('payer_email');
$pn_memo = json_encode($_POST);
$pn_receiver_email = $this->input->post('business') ? $this->input->post('business') : $this->input->post('receiver_email');
$post_data = $_POST;
$post_data['ipn_time'] = date('Y-m-d H:i:s');
$post_data['notify_time'] = date('Y-m-d H:i:s');
$pn_memo = json_encode($post_data);
if (!empty($pn_txn_id)) {
//把PDT时间转成GMT时间
$pn_payment_date = gmdate('Y-m-d H:i:s', strtotime($pn_payment_date));
$this->Note_model->save_paypal_note($pn_txn_id, $pn_invoice, $pn_custom, $pn_mc_gross, $pn_item_name, $pn_item_number, $pn_mc_currency, $pn_payment_status, $pn_payer, $pn_payer_email, $pn_payment_date, $pn_memo);
$this->Note_model->save_paypal_note($pn_txn_id, $pn_invoice, $pn_custom, $pn_mc_gross, $pn_mc_fee, $pn_item_name, $pn_item_number, $pn_mc_currency, $pn_payment_status, $pn_payer, $pn_payer_email, $pn_payment_date, $pn_memo, $pn_receiver_email, $pn_parent_txn_id);
log_message('error','paypal-note-succeed ' . $pn_txn_id . ' # ' . $pn_invoice);
// echo 'ok';
} else {
@ -627,41 +637,149 @@ class Index extends CI_Controller {
{
$raw_post = file_get_contents('php://input');
if (empty($raw_post)) {
echo 'no';
return;
}
$post_data = json_decode($raw_post);
if ($post_data->event_type != 'PAYMENT.SALE.COMPLETED' && $post_data->event_type != 'PAYMENT.SALE.REFUNDED') {
log_message('error',"paypal_webhook" . var_export($raw_post, 1));
$post_data = json_decode($raw_post);
if (
strpos($post_data->event_type, 'COMPLETED') === false
&& strpos($post_data->event_type, 'REFUNDED') === false
&& strpos($post_data->event_type, 'PAYMENT.CAPTURE.DECLINED') === false
) {
return;
}
$pn_txn_id = $post_data->resource->id;
$pn_invoice = $post_data->resource->invoice_number;
// if ($post_data->event_type != 'PAYMENT.SALE.COMPLETED' && $post_data->event_type != 'PAYMENT.SALE.REFUNDED') {
// log_message('error',"paypal_webhook" . var_export($raw_post, 1));
// return;
// }
$pn_mc_gross = $post_data->resource->amount->total;
$default_payee = new stdClass();
$default_payee->email_address = "pays@chinahighlights.com";
$default_payee->merchant_id = "JE4VX9SSVGTVN";
$default_payee->merchant = "cht";
// $pn_item_name = $this->input->post('item_name');
// if (empty($pn_item_name)) {
// $pn_item_name = $this->input->post('item_name1'); //APP用SDK支付的话会是item_name1
// empty($pn_item_name) ? $pn_item_name = '' : false;
// }
$tp_payee = new stdClass();
$tp_payee->email_address = "pay@trippest.com";
$tp_payee->merchant_id = "5FUTQ9SU5P7CJ";
$tp_payee->merchant = "trippest";
// $pn_item_number = $this->input->post('item_number');
// if (empty($pn_item_number)) {
// $pn_item_number = $this->input->post('item_number1'); //APP用SDK支付的话会是item_number1
// empty($pn_item_number) ? $pn_item_number = '' : false;
// }
$pn_txn_id = $post_data->resource->id;
$pn_invoice = '';
$pn_custom = '';
$pn_mc_gross = '';
$pn_mc_currency = '';
$pn_mc_fee = '';
$GAI_API = new stdClass();
$pn_receiver_account = '';
$pn_receiver_account_name = '';
$fund_type = 'pay';
$net_amount = '';
$transaction_status = '';
switch ($post_data->event_type) {
case 'PAYMENT.SALE.COMPLETED':
$fund_type = 'pay';
$pn_invoice = $post_data->resource->invoice_number;
$pn_mc_gross = $post_data->resource->amount->total;
$pn_mc_currency = $post_data->resource->amount->currency;
$pn_payment_status = $post_data->resource->state;
if ($post_data->event_type == 'PAYMENT.SALE.REFUNDED') {
$transaction_status = 'completed';
$post_data->mc_fee = $post_data->resource->transaction_fee->value;
$net_amount = bcsub($pn_mc_gross, $post_data->mc_fee);
$GAI_API->payee = new stdClass();
if (stripos($post_data->resource->soft_descriptor, 'CHINAHIG') !== false) {
$GAI_API->payee = $default_payee;
}
if (stripos($post_data->resource->soft_descriptor, 'TRIPP') !== false) {
$GAI_API->payee = $tp_payee;
}
$GAI_API->res_links = $post_data->resource->links;
$post_data->GAI_API = $GAI_API;
$pn_receiver_account = $GAI_API->payee->email_address;
$pn_receiver_account_name = $GAI_API->payee->merchant;
break;
case 'PAYMENT.SALE.REFUNDED':
$pn_invoice = $post_data->resource->invoice_number;
$pn_mc_currency = $post_data->resource->amount->currency;
$fund_type = 'refund';
$pn_payment_status = 'Refunded';
$transaction_status = 'completed';
$pn_mc_gross = '-' . $post_data->resource->amount->total;
$post_data->parent_txn_id = $post_data->resource->sale_id;
$pn_mc_fee = bcsub(0, $post_data->resource->refund_from_transaction_fee->value);
$post_data->mc_fee = $pn_mc_fee;
$net_amount = isset($post_data->resource->seller_receivable_breakdown) ? '-'.$post_data->resource->seller_receivable_breakdown->refund_from_received_amount->value : $pn_mc_gross;
$GAI_API->payee = new stdClass();
$GAI_API->res_links = $post_data->resource->links;
$post_data->GAI_API = $GAI_API;
break;
case 'PAYMENT.CAPTURE.COMPLETED':
case 'PAYMENT.CAPTURE.DECLINED':
$fund_type = 'pay';
$pn_invoice = $post_data->resource->invoice_id;
$pn_custom = $post_data->resource->custom_id;
$pn_mc_gross = $post_data->resource->amount->value;
$pn_mc_currency = $post_data->resource->amount->currency_code;
$pn_payment_status = $post_data->resource->status;
$transaction_status = strtolower($post_data->resource->status);
$post_data->mc_fee = isset($post_data->resource->seller_receivable_breakdown) ? $post_data->resource->seller_receivable_breakdown->paypal_fee->value : 0;
$net_amount = isset($post_data->resource->seller_receivable_breakdown) ? $post_data->resource->seller_receivable_breakdown->net_amount->value : $pn_mc_gross;
$GAI_API->payee = $post_data->resource->payee;
$GAI_API->res_links = $post_data->resource->links;
$post_data->GAI_API = $GAI_API;
$pn_receiver_account = $GAI_API->payee->email_address;
$pn_receiver_account_name = $pn_receiver_account===$default_payee->email_address ? $default_payee->merchant : $tp_payee->merchant;
break;
case 'PAYMENT.CAPTURE.REFUNDED':
$fund_type = 'refund';
$pn_invoice = $post_data->resource->invoice_id;
$pn_custom = $post_data->resource->custom_id;
$pn_mc_currency = $post_data->resource->amount->currency_code;
$pn_mc_gross = '-' . $post_data->resource->amount->value;
$pn_payment_status = 'Refunded';
$transaction_status = 'completed';
// $post_data->parent_txn_id = $post_data->resource->sale_id;
$parent_link = $post_data->resource->links[1]->href;
$parent_path = parse_url($parent_link, PHP_URL_PATH); // Get the path from the URL
$post_data->parent_txn_id = basename($parent_path);
$pn_mc_fee = bcsub(0, $post_data->resource->seller_payable_breakdown->paypal_fee->value);
$post_data->mc_fee = $pn_mc_fee;
$net_amount = isset($post_data->resource->seller_payable_breakdown) ? '-'.$post_data->resource->seller_payable_breakdown->net_amount->value : $pn_mc_gross;
$GAI_API->payee = $post_data->resource->payer;
$GAI_API->res_links = $post_data->resource->links;
$post_data->GAI_API = $GAI_API;
$pn_receiver_account = $GAI_API->payee->email_address;
$pn_receiver_account_name = $pn_receiver_account===$default_payee->email_address ? $default_payee->merchant : $tp_payee->merchant;
break;
default: // capture COMPLETED
$pn_invoice = $post_data->resource->invoice_id;
$pn_custom = $post_data->resource->custom_id;
$pn_mc_gross = $post_data->resource->amount->value;
$pn_mc_currency = $post_data->resource->amount->currency_code;
$pn_payment_status = $post_data->resource->status;
break;
}
// if ($post_data->event_type == 'PAYMENT.SALE.REFUNDED') {
// $pn_payment_status = 'Refunded';
// $pn_mc_gross = '-' . $post_data->resource->amount->total;
// $post_data->parent_txn_id = $post_data->resource->sale_id;
// }
$pn_payment_date = $post_data->resource->update_time;
// $pn_payer = $post_data->resource->amount->currency;
// $pn_payer_email = $post_data->resource->amount->currency;
$post_data->notify_time = date('Y-m-d H:i:s');
$pn_memo = json_encode($post_data); // $raw_post;
if (!empty($pn_txn_id)) {
//把PDT时间转成GMT时间
@ -669,8 +787,9 @@ class Index extends CI_Controller {
$this->Note_model->save_paypal_note(
$pn_txn_id,
$pn_invoice,
"",
$pn_custom,
$pn_mc_gross,
$post_data->mc_fee,
"",
"",
$pn_mc_currency,
@ -678,15 +797,113 @@ class Index extends CI_Controller {
"",
"",
$pn_payment_date,
$pn_memo);
log_message('error','paypal-webhook-succeed ' . $pn_txn_id . ' # ' . $pn_invoice);
$pn_memo
,$pn_receiver_account
,isset($post_data->parent_txn_id) ? $post_data->parent_txn_id : ''
);
log_message('error','paypal-webhook-succeed ' . $pn_payment_status . ' ' . $pn_txn_id . ' # ' . $pn_invoice);
// echo 'ok';
$to_online = [
'memo' => $pn_memo,
'transaction_id' => $pn_txn_id,
'invoice_id' => $pn_invoice,
'custom_id' => $pn_custom,
'pay_amount' => $pn_mc_gross,
'pay_currency' => $pn_mc_currency,
'net_amount' => $net_amount,
'pay_fee' => $post_data->mc_fee,
'transaction_status' => $transaction_status, // $pn_payment_status,
'payment_date' => $pn_payment_date,
'fund_source' => $pn_receiver_account_name,
'fund_type' => $fund_type,
'event' => $post_data->event_type,
'event_result' => $pn_payment_status,
'referer_id' => isset($post_data->parent_txn_id) ? $post_data->parent_txn_id : '',
];
$this->online_note->add_note_paypal($to_online);
} else {
// echo 'no';
}
return;
}
/**
* 处理webhook
* * 把资源地址写入 GAI 表
* * * IPN先执行, 更新 GAI
* * * WB先执行, 需要等待IPN
*/
public function handle_webhook($item) {
$webhook_memo = json_decode($item->pn_memo);
$res_links = null;
$res_links = $webhook_memo->resource->links;
// $res_links = json_encode($res_links, JSON_UNESCAPED_SLASHES);
$default_payee = new stdClass();
$default_payee->email_address = "pays@chinahighlights.com";
$default_payee->merchant_id = "JE4VX9SSVGTVN";
$payee = isset($webhook_memo->resource->payee) ? $webhook_memo->resource->payee : $default_payee;
$payee = property_exists($webhook_memo, 'GAI_API') ? $webhook_memo->GAI_API->payee : $payee;
$API = new stdClass();
$API->payee = $payee;
$API->res_links = $res_links;
$API_str = json_encode($API, JSON_UNESCAPED_SLASHES);
$pn_txn_id = $item->pn_txn_id;
$pn_invoice = $item->pn_invoice;
$orderid_info = $this->analysis_orderid($pn_invoice);
if (empty($orderid_info)) {
$notes = $this->Note_model->search_note($pn_txn_id);
if (empty($notes)) {
return;
}
$IPN_note = $notes[0];
$pn_invoice = $IPN_note->pn_invoice;
$orderid_info = $this->analysis_orderid($pn_invoice);
}
$this->Note_model->update_send($item->pn_txn_id, 'sendfail', $item->pn_sn);
if (!empty($orderid_info)) {
$orderid_info = json_decode($orderid_info);
if ($orderid_info->ordertype === 'TP' || $orderid_info->ordertype === 'A') {
$orderid_info->ordertype = 'B';
}
$data_gai = null;
if ($orderid_info->ordertype === 'T') {
$data_gai = $this->Paypal_model->get_money_t($pn_txn_id);
if ( ! empty($data_gai)) {
$this->Paypal_model->update_money_api_t($pn_txn_id, $API_str);
$this->Note_model->update_send($item->pn_txn_id, 'send-wh-API', $item->pn_sn);
}
} elseif ($orderid_info->ordertype === 'B') {
$data_gai = $this->Paypal_model->get_money_b($pn_txn_id, false);
if ( ! empty($data_gai)) {
$this->Paypal_model->update_money_api_b($pn_txn_id, $API_str);
$this->Note_model->update_send($item->pn_txn_id, 'send-wh-API', $item->pn_sn);
}
}
}
return $API_str;
}
public function handle_webhook_batch() {
$data = array();
$data['notelist'] = $this->Note_model->notewebhooks(200, true);
$show_index = 0;
foreach ($data['notelist'] as $item) {
if ($item->pn_send === 'send-wh-API') {
continue;
}
echo ++$show_index . ' ' . $item->pn_txn_id . ' ' . $item->pn_payment_date . '<br/>';
// $webhook_memo = json_decode($item->pn_memo);
$this->handle_webhook($item);
}
}
//解析出订单号
public function analysis_orderid($note_invoice_string) {
$data = array();
@ -831,16 +1048,36 @@ class Index extends CI_Controller {
echo ++$show_index . ' ' . $item->pn_txn_id . '<br/>';
}
$GAI_API = null;
$payment_fee = 0;
// webhook的跳过
$webhook_memo = json_decode($item->pn_memo);
$is_webhook = false;
if (isset($webhook_memo->id) && substr($webhook_memo->id, 0, 2)==="WH") {
$is_webhook = true;
$payment_fee = property_exists($webhook_memo, 'mc_fee') ? $webhook_memo->mc_fee : $webhook_memo->resource->transaction_fee->value;
$GAI_API = property_exists($webhook_memo, 'GAI_API') ? $webhook_memo->GAI_API : null;
$GAI_API = json_encode($GAI_API, JSON_UNESCAPED_SLASHES);
} else {
$payment_fee = property_exists($webhook_memo, 'mc_fee') ? $webhook_memo->mc_fee : 0;
}
if (empty($pn_txn_id) && true === $is_webhook && strtolower($item->pn_payment_status) == 'completed') {
$this->handle_webhook($item);
// $this->Note_model->update_send($item->pn_txn_id, 'send-wh', $item->pn_sn);
continue;
}
if (empty($pn_txn_id) && true === $is_webhook) {
$this->Note_model->update_send($item->pn_txn_id, 'send-wh', $item->pn_sn);
$if48Hour = (time() - strtotime($item->pn_datetime)) >= 48*3600 ? true : false;
if (strtolower($item->pn_payment_status) == 'declined' && $if48Hour) {
$this->Note_model->update_send($item->pn_txn_id, 'closeRecord');
continue;
}
// if (strtolower($item->pn_payment_status) == 'pending') {
// $find_completed = $this->Note_model->note_completed($pn_txn_id);
// // $this->Note_model->update_send($item->pn_txn_id, 'closeRecord');
// continue;
// }
//退款状态默认为已经处理,陆燕在退款前手动通知外联了,系统跳过处理
if (strtolower($item->pn_payment_status) == 'refunded' ) {
@ -929,7 +1166,7 @@ class Index extends CI_Controller {
// for trippest tourMaster 2018.05.28
if ($orderid_info->ordertype == 'TP') {
$this->trippest_note($orderid_info, $item);
$this->trippest_note($orderid_info, $item, $webhook_memo);
continue;
}
@ -948,10 +1185,17 @@ class Index extends CI_Controller {
// continue;
// }
$pay_email = $item->pn_payer_email;
// PayPal ACDC生成的随机邮箱不记录付款信息
if (strpos($pay_email, 'paypal.com') !== false) {
$pay_email = '';
}
//添加支付信息入库
//没有分配订单之前先添加付款记录,这个过程可能会执行多次,必须在添加记录前查找是否有数据
if (!empty($orderid_info)) {
$ssje = $this->Paypal_model->get_ssje($item->pn_mc_gross, '15002', mb_strtoupper($item->pn_mc_currency));
// $ssje = $this->Paypal_model->get_ssje($item->pn_mc_gross, '15002', mb_strtoupper($item->pn_mc_currency));
$ssje = $this->Paypal_model->get_ssje_exclude_fee(bcsub($item->pn_mc_gross, $payment_fee), '15002', mb_strtoupper($item->pn_mc_currency));
$ssje = $old_ssje===NULL ? $ssje : $old_ssje;
$USD_amount = $this->Paypal_model->get_USD($item->pn_mc_gross, $item->pn_mc_currency);
$GAI_COLI_SN = isset($advisor_info->COLI_SN) ? $advisor_info->COLI_SN : 0;
@ -960,19 +1204,21 @@ class Index extends CI_Controller {
if (isset($advisor_info->order_type) && $advisor_info->order_type == 0) {
$ht_memo = '交易号(自动录入):' . $item->pn_txn_id;
//CHTAPP订单添加记录前判断是否有记录以前的APP版本没有交易号只能拿金额来判断
if (substr($advisor_info->COLI_WebCode, 0, 6) == 'CHTAPP' && strstr($advisor_info->COLI_WebCode, "-") !== '-biz') {//只判断前6位字符CHTAPP-fr CHTAPP-jp等各语种都属于APP订单
$this->Paypal_model->add_account_info_forAPP($GAI_COLI_SN, $advisor_info->COLI_ID, $item->pn_mc_gross, $item->pn_payment_date, mb_strtoupper($item->pn_mc_currency), $ssje, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payer, $item->pn_payer_email, $item->pn_txn_id, $ht_memo);
if (substr($advisor_info->COLI_WebCode, 0, 6) == 'CHTAPP' && strstr($advisor_info->COLI_WebCode, "-") !== '-biz') {
//只判断前6位字符CHTAPP-fr CHTAPP-jp等各语种都属于APP订单
$gai_sn = $this->Paypal_model->add_account_info_forAPP($GAI_COLI_SN, $advisor_info->COLI_ID, $item->pn_mc_gross, $item->pn_payment_date, mb_strtoupper($item->pn_mc_currency), $ssje, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payer, $pay_email, $item->pn_txn_id, $ht_memo, $GAI_API);
if ($advisor_info->COLI_WebCode == 'CHTAPP' && $advisor_info->COLI_State == 11) { //只修改APP组的订单状态并且订单进度是我的订单
$this->Paypal_model->update_biz_coli_state($GAI_COLI_SN, 8); //把订单状态改为已付款
$this->Paypal_model->insert_biz_order_log($GAI_COLI_SN, 'BS8');
}
} else {
// 商务订单, 除了APP
// 把订单状态设置为13-新订单已支付
if (false == $this->Paypal_model->if_biz_gai_exists($item->pn_txn_id) ) {
$this->Paypal_model->update_biz_coli_state($GAI_COLI_SN, 13);
$this->Paypal_model->insert_biz_order_log($GAI_COLI_SN, 'BS13');
}
$this->Paypal_model->add_account_info(
$gai_sn = $this->Paypal_model->add_account_info(
$GAI_COLI_SN,
$advisor_info->COLI_ID,
$item->pn_mc_gross,
@ -984,22 +1230,24 @@ class Index extends CI_Controller {
$item->pn_payment_date,
$item->pn_payment_date,
$item->pn_payer,
$item->pn_payer_email,
$pay_email,
$item->pn_txn_id,
$ht_memo);
$ht_memo, $GAI_API);
// 更新订单主表付款方式,防止没访问thankyou-train.asp
$this->Paypal_model->update_paymanner($GAI_COLI_SN, '15010');
}
// 添加HT任务
$this->Paypal_model->exec_addToTask($gai_sn, 227002);
}
//更新还没有填的客邮和交易号de收款记录传统订单
elseif (isset($advisor_info->order_type) && $advisor_info->order_type == 1) {
$ht_memo = '交易号(自动录入):' . $item->pn_txn_id;
$GAI_COLI_SN = isset($advisor_info->COLI_SN) ? $advisor_info->COLI_SN : 0;
$gai_sn = $this->Paypal_model->add_tour_account_info($GAI_COLI_SN, $item->pn_mc_gross, $item->pn_payment_date, mb_strtoupper($item->pn_mc_currency), $ssje, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payer, $item->pn_payer_email, $item->pn_txn_id, $ht_memo);
$gai_sn = $this->Paypal_model->add_tour_account_info($GAI_COLI_SN, $item->pn_mc_gross, $item->pn_payment_date, mb_strtoupper($item->pn_mc_currency), $ssje, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payer, $pay_email, $item->pn_txn_id, $ht_memo, $GAI_API);
//添加汉特的订单提醒
$this->Paypal_model->update_coli_introduction($GAI_COLI_SN, '已支付 ' . mb_strtoupper($item->pn_mc_currency) . $item->pn_mc_gross);
// 添加HT任务
$this->Paypal_model->exec_addToTask($gai_sn);
$this->Paypal_model->exec_addToTask($gai_sn, 227001);
}
}
@ -1013,6 +1261,10 @@ class Index extends CI_Controller {
$opi_firstname = 'contact@arachina.com';
}
//没有外联信息表示订单未分配
if (empty($opi_email) && !empty($opi_firstname)) {
$this->Note_model->update_send($item->pn_txn_id, 'send', $item->pn_sn);
continue;
}
if (empty($opi_email) || empty($opi_firstname)) {
$this->Note_model->update_send($item->pn_txn_id, 'sendfail', $item->pn_sn);
continue;
@ -1022,7 +1274,7 @@ class Index extends CI_Controller {
if ( ($item->pn_send !== 'send' && false===$is_webhook ) || true===$handpick) {
//给外联发送通知邮件
$fromName = !empty($item->pn_payer) ? $item->pn_payer : '';
$fromEmail = !empty($item->pn_payer_email) ? $item->pn_payer_email : '';
$fromEmail = !empty($pay_email) ? $pay_email : '';
$toName = !empty($opi_firstname) ? $opi_firstname : '';
$toEmail = !empty($opi_email) ? $opi_email : '';
$subject = $orderid_info->orderid . '_' . $orderid_info->ordertype . ' / ' . $item->pn_mc_gross . $item->pn_mc_currency . ' / ' . $fromName;
@ -1049,15 +1301,33 @@ class Index extends CI_Controller {
*/
public function send_refund($item, $handpick, $old_ssje=NULL)
{
$payment_memo = json_decode($item->pn_memo);
// 查询IPN通知, 优先按IPN处理
$notes = $this->Note_model->search_note($item->pn_txn_id);
if ( ! empty($notes) ) { // && strpos($notes[0]->pn_custom, 'GPA_') === false
$memo0 = json_decode($notes[0]->pn_memo);
if ( ! (isset($memo0->id) && substr($memo0->id, 0, 2)==="WH")) {
$IPN_note = $notes[0]; // 存在IPN, 本条WH忽略
if ((isset($payment_memo->id) && substr($payment_memo->id, 0, 2)==="WH")) {
$this->Note_model->update_send($item->pn_txn_id, 'send-', $item->pn_sn);
return false;
}
}
}
// 找到原始收款交易的订单
$parent_txn_id = json_decode($item->pn_memo)->parent_txn_id;
$parent_txn_id = $payment_memo->parent_txn_id;
$parent_note = $this->Note_model->note($parent_txn_id);
if (empty($parent_note)) {
$this->Note_model->update_send($item->pn_txn_id, 'sendfail');
$orderid_info = $this->analysis_orderid($item->pn_invoice);
if ( ! $handpick) {
return false;
}
} else {
//订单号
$orderid_info = $this->analysis_orderid($parent_note->pn_invoice);
$orderid_info = empty($orderid_info) ? $this->analysis_orderid($item->pn_invoice) : $orderid_info;
}
//找不到订单号,设置为发送失败标示
if (empty($orderid_info)) {
@ -1075,29 +1345,54 @@ class Index extends CI_Controller {
//根据订单号查找外联信息, 从临时表
$advisor_info_from_tmp = $this->Paypal_model->get_order($orderid_info->orderid, false, 'M', $handpick);
if (empty($advisor_info)) {
if ($orderid_info->ordertype === 'T') {
$parent_order_info = $this->Paypal_model->get_money_t($parent_txn_id);
} else {
$parent_order_info = $this->Paypal_model->get_money_B($parent_txn_id);
}
if ( ! empty($parent_order_info)) {
$advisor_info = $this->Paypal_model->get_order($parent_order_info[0]->COLI_ID, false, $orderid_info->ordertype, $handpick);
$orderid_info = $this->analysis_orderid("{$parent_order_info[0]->COLI_ID}_{$orderid_info->ordertype}");
$orderid_info = json_decode($orderid_info);
}
}
/**
* 传统订单, 网站支付
* @author LYT
*/
if (empty($advisor_info) && ! empty($advisor_info_from_tmp) && $orderid_info->ordertype == 'T') {
// $this->Note_model->update_send($item->pn_txn_id, 'closeRecord', $item->pn_sn);
$this->Note_model->set_invoice($item->pn_txn_id, $advisor_info_from_tmp->COLI_ID . '_' . $orderid_info->ordertype);
continue;
}
// return false;
} else if (empty($advisor_info)) {
//查不到订单信息
if (empty($advisor_info)) {
$this->Note_model->update_send($item->pn_txn_id, 'sendfail');
return false;
}
} else {
//更新正确的订单信息到记录中,以这个为主
$this->Note_model->set_invoice($item->pn_txn_id, $orderid_info->orderid . '_' . $orderid_info->ordertype);
}
$is_webhook = false;
$payment_fee = 0;
$refund_amount = 0;
if (isset($payment_memo->id) && substr($payment_memo->id, 0, 2)==="WH") {
$is_webhook = true;
$refund_amount = isset($payment_memo->refund_from_received_amount) ? $payment_memo->refund_from_received_amount : '-'.$payment_memo->resource->seller_payable_breakdown->net_amount->value;
// $payment_fee = $payment_memo->resource->refund_from_transaction_fee->value;
$payment_fee = property_exists($payment_memo, 'mc_fee') ? $payment_memo->mc_fee : $payment_memo->resource->refund_from_transaction_fee->value;
$refund_amount = bcsub($refund_amount, $payment_fee);
} else {
$refund_amount = bcsub($payment_memo->mc_gross, $payment_memo->mc_fee);
$payment_fee = $payment_memo->mc_fee;
}
$refund_amount = bcsub($item->pn_mc_gross, $item->pn_mc_fee);
//添加支付信息入库
//没有分配订单之前先添加付款记录,这个过程可能会执行多次,必须在添加记录前查找是否有数据
if (!empty($orderid_info)) {
$ssje = $this->Paypal_model->get_ssje($item->pn_mc_gross, '15002', mb_strtoupper($item->pn_mc_currency));
// $ssje = $this->Paypal_model->get_ssje($item->pn_mc_gross, '15002', mb_strtoupper($item->pn_mc_currency));
$ssje = $this->Paypal_model->get_ssje_exclude_fee($refund_amount, '15002', mb_strtoupper($item->pn_mc_currency));
$ssje = $old_ssje===NULL ? $ssje : $old_ssje;
$USD_amount = $this->Paypal_model->get_USD($item->pn_mc_gross, $item->pn_mc_currency);
//更新还没有填的客邮和交易号de收款记录商务订单
@ -1106,15 +1401,23 @@ class Index extends CI_Controller {
$ht_memo .= '原收款号:' . $parent_txn_id;
$GAI_COLI_SN = isset($advisor_info->COLI_SN) ? $advisor_info->COLI_SN : 0;
//CHTAPP订单添加记录前判断是否有记录以前的APP版本没有交易号只能拿金额来判断
if (substr($advisor_info->COLI_WebCode, 0, 6) == 'CHTAPP' && strstr($advisor_info->COLI_WebCode, "-") != '-biz') {//只判断前6位字符CHTAPP-fr CHTAPP-jp等各语种都属于APP订单
$this->Paypal_model->add_account_info_forAPP($GAI_COLI_SN, $advisor_info->COLI_ID, $item->pn_mc_gross, $item->pn_payment_date, mb_strtoupper($item->pn_mc_currency), $ssje, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payer, $item->pn_payer_email, $item->pn_txn_id, $ht_memo);
//只判断前6位字符CHTAPP-fr CHTAPP-jp等各语种都属于APP订单
if (substr($advisor_info->COLI_WebCode, 0, 6) == 'CHTAPP'
&& strstr($advisor_info->COLI_WebCode, "-") != '-biz'
) {
$insertedID = $this->Paypal_model->add_account_info_forAPP($GAI_COLI_SN, $advisor_info->COLI_ID, $item->pn_mc_gross, $item->pn_payment_date, mb_strtoupper($item->pn_mc_currency), $ssje, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payer, $item->pn_payer_email, $item->pn_txn_id, $ht_memo);
if ($insertedID) {
$this->Paypal_model->insert_biz_order_log($GAI_COLI_SN, 'Refunded');
$this->Paypal_model->exec_BIZ_TrainCostAdd($GAI_COLI_SN, $ssje);
}
} else {
if (false == $this->Paypal_model->if_biz_gai_exists($item->pn_txn_id) ) {
$this->Paypal_model->insert_biz_order_log($GAI_COLI_SN, 'Refunded');
}
$this->Paypal_model->add_account_info($GAI_COLI_SN, $advisor_info->COLI_ID, $item->pn_mc_gross, $item->pn_payment_date, mb_strtoupper($item->pn_mc_currency), $USD_amount, $ssje, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payer, $item->pn_payer_email, $item->pn_txn_id, $ht_memo);
$insertedID = $this->Paypal_model->add_account_info($GAI_COLI_SN, $advisor_info->COLI_ID, $item->pn_mc_gross, $item->pn_payment_date, mb_strtoupper($item->pn_mc_currency), $USD_amount, $ssje, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payer, $item->pn_payer_email, $item->pn_txn_id, $ht_memo);
}
// 添加HT任务
$this->Paypal_model->exec_addToTask($insertedID, 227002);
}
//更新还没有填的客邮和交易号的收款记录(传统订单)
elseif (isset($advisor_info->order_type) && $advisor_info->order_type == 1) {
@ -1124,21 +1427,26 @@ class Index extends CI_Controller {
$gai_sn = $this->Paypal_model->add_tour_account_info($GAI_COLI_SN, $item->pn_mc_gross, $item->pn_payment_date, mb_strtoupper($item->pn_mc_currency), $ssje, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payer, $item->pn_payer_email, $item->pn_txn_id, $ht_memo);
//添加汉特的订单提醒
$this->Paypal_model->update_coli_introduction($GAI_COLI_SN, '已退款 ' . mb_strtoupper($item->pn_mc_currency) . $item->pn_mc_gross);
// 添加HT任务
$this->Paypal_model->exec_addToTask($gai_sn, 227001);
}
}
$this->Note_model->update_send($item->pn_txn_id, 'send-', $item->pn_sn);
$opi_email = !empty($advisor_info->OPI_Email) ? $advisor_info->OPI_Email : ''; //lussie@chinahighlights.net
$opi_firstname = !empty($advisor_info->OPI_FirstName) ? $advisor_info->OPI_FirstName : !empty($advisor_info->OPI_Name) ? $advisor_info->OPI_Name : ''; //lussie
//没有外联信息表示订单未分配
if (empty($opi_email) || empty($opi_firstname)) {
if (empty($opi_email) && empty($opi_firstname)) {
$this->Note_model->update_send($item->pn_txn_id, 'sendfail');
return false;
}
//添加邮件发送记录
if ($item->pn_send !== 'send' && substr($item->pn_send, 0, 5) !== 'send-') {
//添加邮件发送记录; webhook不发送邮件, 避免重复
if ($is_webhook === false) {
if ($item->pn_send !== 'send' && substr($item->pn_send, 0, 5) !== 'send-'
) {
// 客人邮件中的外联落款
// $web_code = 'cht'; // 默认cht
$web_lgc = 1;
@ -1152,6 +1460,8 @@ class Index extends CI_Controller {
$advisor_detail = $this->Paypal_model->get_advisor_detail($advisor_info->COLI_SN, $advisor_info->OPI_SN, $web_lgc);
$item->advisor_detail = $advisor_detail;
$item->payment_date = isset($item->payment_date) ? $item->payment_date : $item->pn_payment_date;
//给外联发送通知邮件
$fromName = !empty($item->pn_payer) ? $item->pn_payer : '';
$fromEmail = !empty($item->pn_payer_email) ? $item->pn_payer_email : '';
@ -1162,7 +1472,20 @@ class Index extends CI_Controller {
$M_RelatedInfo = $item->pn_sn;
$M_AddTime = $item->pn_payment_date;
$M_State = 0;
$this->Paypal_model->save_automail($fromName, $fromEmail, $toName, $toEmail, $subject, $body, $M_RelatedInfo, $M_State, $M_AddTime, 'paypal note');
if (!empty($toEmail)) {
$this->Paypal_model->save_automail(
$fromName,
$fromEmail,
$toName,
$toEmail,
$subject,
$body,
$M_RelatedInfo,
$M_State,
$M_AddTime,
'paypal note'
);
}
// 通知客人, 客人邮箱
// $customer_detail = $this->Paypal_model->get_customer_detail($advisor_info->COLI_SN, $orderid_info->ordertype);
$c_fromName = $advisor_detail->fullname ? $advisor_detail->fullname : $opi_firstname;
@ -1197,10 +1520,12 @@ class Index extends CI_Controller {
if ($this->Paypal_model->if_finance_done($advisor_info->COLI_GRI_SN, $late_entry_date_set) === true) {
$this->Note_model->update_send($item->pn_txn_id, 'send-to-finance', $item->pn_sn);
}
}
$this->Note_model->update_send_case($parent_txn_id, 'send');
return ;
}
public function trippest_note($orderid_info, $paypal_msg)
public function trippest_note($orderid_info, $paypal_msg, $payment_memo)
{
$send_type = '';
$tp_orderid = '';
@ -1224,7 +1549,15 @@ class Index extends CI_Controller {
//更新正确的订单信息到记录中,以这个为主
$this->Note_model->set_invoice($paypal_msg->pn_txn_id, $ht_tp_order->COLI_ID . '_TP');
}
$ssje = $this->Paypal_model->get_ssje($paypal_msg->pn_mc_gross, '15002', mb_strtoupper($paypal_msg->pn_mc_currency));
$payment_fee = 0;
if (substr($payment_memo->id, 0, 2)==="WH") {
$payment_fee = $payment_memo->resource->transaction_fee->value;
} else {
$payment_fee = $payment_memo->mc_fee;
}
// $ssje = $this->Paypal_model->get_ssje($paypal_msg->pn_mc_gross, '15002', mb_strtoupper($paypal_msg->pn_mc_currency));
$ssje = $this->Paypal_model->get_ssje_exclude_fee(bcsub($paypal_msg->pn_mc_gross, $payment_fee), '15002', mb_strtoupper($paypal_msg->pn_mc_currency));
$ht_memo = '交易号(自动录入):' . $paypal_msg->pn_txn_id;
$USD_amount = $this->Paypal_model->get_USD($paypal_msg->pn_mc_gross, $paypal_msg->pn_mc_currency);
if (false == $this->Paypal_model->if_biz_gai_exists($paypal_msg->pn_txn_id) ) {
@ -1326,6 +1659,21 @@ class Index extends CI_Controller {
$this->load->view('n-footer');
}
/**
* 查找webhooks记录
* @author LYT
*/
public function note_wb_list() {
$this->permission->is_admin(true);
$data = array();
$data['date'] = $this->input->get('date');
empty($data['date']) ? $data['date'] = date('Y-m-d') : false;
$data['notelist'] = $this->Note_model->notewebhooks(200);
$this->load->view('n-header', $data);
$this->load->view('note_list');
$this->load->view('n-footer');
}
/**
* 按账户查找
* @author LYT
@ -1681,6 +2029,10 @@ class Index extends CI_Controller {
$pn_id = $this->input->post('pn_id');
$neworder = $this->input->post('pn_invoice');
// log_message('error','test: ' . __METHOD__ . ':' . __LINE__ . PHP_EOL . var_export(0, 1));
// $this->send_note($pn_txn_id, $old_ssje);
// return;
$data['note'] = $this->Note_model->note($pn_txn_id, $pn_id);
$orderid_info = $this->analysis_orderid($data['note']->pn_invoice);
if (!empty($orderid_info)) {

@ -0,0 +1,588 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Online_payment_note_model extends CI_Model {
function __construct() {
parent::__construct();
bcscale(2);
$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) {
return false;
}
$this->info->insert('OnlinePaymentNote', $column);
$ret = "SELECT TOP 1 * FROM OnlinePaymentNote WHERE OPN_transactionId=? ORDER BY OPN_SN DESC ";
return $this->info->query($ret, array($column['OPN_transactionId']))->row();
}
public function update_note($where, $column)
{
$update_str = $this->info->update_string('OnlinePaymentNote', $column, $where);
$this->info->query($update_str);
return TRUE;
}
public function update_send($id, $transactionId, $send)
{
$column = array("OPN_noticeSendStatus" => $send, "OPN_noticeSendTime" => date('Y-m-d H:i:s'));
$where = " OPN_transactionId = '$transactionId' AND OPN_SN=" . $id;
return $this->update_note($where, $column);
}
//设置订单号
public function set_invoice($id, $pn_invoice)
{
$column = array("OPN_orderId" => $pn_invoice);
$where = " OPN_SN=" . $id;
return $this->update_note($where, $column);
}
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 IN ($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) = 'closed' ";
$this->search = $method===null ? "" : " AND OPN_accountMethod IN ($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, $method=null)
{
$this->init_query();
$this->topnum = $num;
$this->search = $method===null ? "" : " AND OPN_accountMethod IN ($method) ";
// 1小时前
$date = date("Y-m-d H:i:s", time() - 3600);
$this->search .= $num !== false ? " AND OPN_noticeSendTime < '$date' " : '';
$this->send = " AND OPN_noticeSendStatus='sendfail' ";
return $this->query_note();
}
public $topnum = false;
public $orderby = false;
public $send = false;
public $search = false;
public $transactionId = false;
public $payment_status = false;
// public $payment_method = false;
public function init_query() {
$this->topnum = false;
$this->send = false;
$this->search = false;
$this->payment_status = false;
$this->transactionId = false;
// if ($GLOBALS['__PAYMENT_METHOD_CODE__']) {
// $this->payment_method = ' AND opn.OPN_accountMethod = ' . $GLOBALS['__PAYMENT_METHOD_CODE__'] . ' ';
// }
$this->orderby = ' ORDER BY OPN_SN DESC ';
}
private $code_brandname = array(
"15002" => "PayPal",
"15010" => "PayPal",
"15015" => "Alipay",
"15016" => "WeChat",
"15018" => "Credit Card-iPaylinks",
"15035" => "Credit Card-Lianlian",
);
private $wxpay_app = array(
"wx749246dd935ca07b" => "APP",
"wx5d01021a6d515098" => "HLY", // "花梨鹰小程序", // 交行收款码
"wxd6c8dd69af5128cd" => "", // "NATIVE",
"wx7e605820faf98a05" => "Trippest-NATIVE",
"0" => "unknown",
);
public function set_brandname(&$ele)
{
$ele->brand_name = "none";
if ($this->code_brandname[$ele->OPN_accountMethod]) {
$ele->brand_name = $this->code_brandname[$ele->OPN_accountMethod];
}
$raw = json_decode($ele->OPN_rawContent);
$wx_app = isset($raw->app_id) ? $raw->app_id : '0';
$wx_app = $wx_app!=='0' ? $wx_app : (isset($raw->appid) ? $raw->appid : '0');
$ele->app_name = "";
if ($this->wxpay_app[$wx_app]) {
$ele->app_name = $this->wxpay_app[$wx_app];
}
}
public function query_note()
{
$top_sql = $this->topnum ? (" TOP " . $this->topnum) : "";
$sql = "SELECT $top_sql opn.*
FROM [InfoManager].[dbo].[OnlinePaymentNote] opn
WHERE 1=1 ";
// $this->payment_method ? $sql.=$this->payment_method : false;
$this->send ? $sql.=$this->send : false;
$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);
$result = $query->result();
array_walk($result, 'Online_payment_note_model::set_brandname');
return $result;
}
public function get_note($opn_id)
{
$this->init_query();
$this->topnum=1;
$this->search = " AND opn.OPN_SN=" . $this->info->escape($opn_id);
return $this->query_note();
}
/**
* @param mixed $where ['OPN_SN' => ['=', {val}] ]
*/
public function get_note_where($where) {
$this->init_query();
$this->topnum=1;
$this->search = '';
foreach ($where as $key => $value) {
$where_val = '';
switch (strtolower($value[0])) {
case '=':
$where_val = " = {$this->info->escape($value[1])}";
break;
case 'in':
$where_val = " IN ({$this->info->escape($value[1])})";
break;
default:
$where_val = " = {$this->info->escape($value[1])}";
break;
}
$this->search .= " AND {$key} {$where_val} ";
}
return $this->query_note();
}
public function search_key($keyword)
{
$this->init_query();
$this->topnum = 300;
$keyword = trim($keyword);
$search_sql = "";
if ( ! empty($keyword)) {
$search_sql.=" AND ( OPN_transactionId = '$keyword'
OR OPN_relatedId like '%$keyword%'
OR OPN_orderId like '%$keyword%'
OR OPN_rawOrderId like '%$keyword%' )";
}
$this->search = $search_sql;
return $this->query_note();
}
public function search_date($date, $method=null)
{
$this->init_query();
$this->search = $method===null ? "" : " AND OPN_accountMethod IN ($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();
}
/*!
* 导出记录
* @date 2019-04-28
* @param integer $sn [description]
*/
public function list_export_record($sn=0)
{
$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";
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 isnull(cal.select_date_method,ISNULL(cal.last_method,ISNULL(cal.year_method, cal.this_year_method ))) as 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
,case when ISNULL( method_total_income_cmp,0)=0 then 100 else CONVERT(decimal(10,2),
round( (method_total_income-method_total_income_cmp)/method_total_income_cmp*100 ,2 )
) end AS quarter_rate
--,REPLACE(CONVERT(VARCHAR, CONVERT(MONEY, isnull(year_method_total_income,0)), 1), '.00', '') year_method_total_income
,case when ISNULL( year_method_total_income,0)=0 then 100 else CONVERT(decimal(10,2),
round( (method_total_income-year_method_total_income)/year_method_total_income*100 ,2 )
) end 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,OPN_accountMethod select_date_method
,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
full 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
full 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 isnull(method.OPN_accountMethod,cmp.last_method)=year_cmp.year_method
full 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 isnull(method.OPN_accountMethod,cmp.last_method)=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;
}
/**
* @uses WxpayService::query
*/
public function add_note_wxpay($result_data, $target_account, $type='pay')
{
$this->load->model('paypal_model', 'account_model');
foreach ($result_data as $key => $row) {
$save_column = array();
$save_column['OPN_accountMethod'] = $this->config->item('method_code', 'wxpay');
$total_fee = bcdiv($row['total_fee'], $this->config->item('currency_unit', 'wxpay'));
$OPN_currency = isset($row['currency_type']) ? $row['currency_type'] : (isset($row['fee_type']) ? $row['fee_type'] : 'CNY');
if ($type != 'pay') {
// 退款
$refund_fee = bcdiv($row['refund_fee'], $this->config->item('currency_unit', 'wxpay'));
$ssje = $this->account_model->get_ssje($refund_fee, str_replace("CNY", "RMB", strtoupper($OPN_currency)), $save_column['OPN_accountMethod']);
$save_column['OPN_transactionId'] = $row['refund_id'];
$save_column['OPN_orderAmount'] = "-" . $refund_fee;
$save_column['OPN_payAmount'] = "-" . $refund_fee;
$save_column['OPN_resultCode'] = $row['refund_status'];
$save_column['OPN_resultMsg'] = $row['refund_status'];
$save_column['OPN_entryAmountCNY'] = floatval("-" . $ssje);
$save_column['OPN_noticeType'] = $type;
$save_column['OPN_relatedId'] = $row['transaction_id'];
$save_column['OPN_acquiringTime'] = date('Y-m-d H:i:s', strtotime($row['refund_success_time']));
$save_column['OPN_completeTime'] = date('Y-m-d H:i:s', strtotime($row['refund_success_time']));
} else {
// 收款
$total_fee = bcdiv($row['total_fee'], $this->config->item('currency_unit', 'wxpay'));
$ssje = $this->account_model->get_ssje($total_fee, str_replace("CNY", "RMB", strtoupper($OPN_currency)), $save_column['OPN_accountMethod']);
$save_column['OPN_transactionId'] = $row['transaction_id'];
$save_column['OPN_orderAmount'] = $total_fee;
$save_column['OPN_payAmount'] = $total_fee;
$save_column['OPN_resultCode'] = $row['trade_state'];
$save_column['OPN_resultMsg'] = $row['trade_state'];
$save_column['OPN_entryAmountCNY'] = floatval($ssje);
$save_column['OPN_noticeType'] = 'pay';
$save_column['OPN_relatedId'] = '';
$save_column['OPN_acquiringTime'] = date('Y-m-d H:i:s', strtotime($row['time_end']));
$save_column['OPN_completeTime'] = date('Y-m-d H:i:s', strtotime($row['time_end']));
}
$save_column['OPN_noticeSendStatus'] = 'unsend';
$save_column['OPN_transactionResult'] = 'completed';
$save_column['OPN_orderId'] = $row['out_trade_no'];
$save_column['OPN_rawOrderId'] = $row['out_trade_no'];
$save_column['OPN_invoiceId'] = $row['out_trade_no'];
$save_column['OPN_subject'] = isset($row['item_name']) ? $row['item_name'] : '';
$save_column['OPN_currency'] = $OPN_currency;
$save_column['OPN_remark'] = empty($row['attach']) ? '' : json_encode($row['attach']);
$save_column['OPN_payerLogId'] = isset( $row['openid']) ? $row['openid'] : '';
$save_column['OPN_fundSource'] = $target_account;
$save_column['OPN_rawContent'] = json_encode($row);
$save_column['OPN_noticeTime'] = date('Y-m-d H:i:s');
// $this->insert_note($save_column) ; // todo:
// log_message('error', 'test: ' . __CLASS__ . PHP_EOL . var_export($save_column, 1));
}
return;
}
/**
*
* $to_online = [
* 'memo' => $pn_memo,
* 'transaction_id' => $pn_txn_id,
* 'invoice_id' => $pn_invoice,
* 'custom_id' => $pn_custom,
* 'pay_amount' => $pn_mc_gross,
* 'pay_currency' => $pn_mc_currency,
* 'net_amount' => $net_amount,
* 'pay_fee' => $post_data->mc_fee,
* 'transaction_status' => 'completed', // $pn_payment_status,
* 'payment_date' => $pn_payment_date, // UTC
* 'fund_source' => $pn_receiver_account_name,
* 'fund_type' => $fund_type,
* 'event' => $post_data->event_type,
* 'event_result' => $pn_payment_status,
* 'referer_id' => isset($post_data->parent_txn_id) ? $post_data->parent_txn_id : '',
* ];
* @uses Index::paypal_webhook
*/
public function add_note_paypal($result_data)
{
$this->load->model('paypal_model', 'account_model');
$ssje = $this->account_model->get_ssje_exclude_fee($result_data['net_amount'],'', str_replace("CNY", "RMB", strtoupper($result_data['pay_currency'])));
$localSqlDateTime = date('Y-m-d H:i:s', strtotime($result_data['payment_date']) + 3600 * 8);
$save_column = array();
$save_column['OPN_transactionId'] = $result_data['transaction_id'];
$save_column['OPN_orderAmount'] = $result_data['pay_amount'];
$save_column['OPN_payAmount'] = $result_data['pay_amount'];
$save_column['OPN_payFee'] = bcsub(0,$result_data['pay_fee']);
$save_column['OPN_netAmount'] = $result_data['net_amount'];
$save_column['OPN_resultCode'] = $result_data['event_result'];
$save_column['OPN_resultMsg'] = $result_data['event'];
$save_column['OPN_entryAmountCNY'] = floatval($ssje);
$save_column['OPN_noticeType'] = $result_data['fund_type'];
$save_column['OPN_relatedId'] = $result_data['referer_id'];
$save_column['OPN_acquiringTime'] = $localSqlDateTime;
$save_column['OPN_completeTime'] = $localSqlDateTime;
$save_column['OPN_accountMethod'] = 15002; // $this->config->item('method_code', 'paypal');
$save_column['OPN_noticeSendStatus'] = 'closed';
$save_column['OPN_transactionResult'] = $result_data['transaction_status'];
$save_column['OPN_orderId'] = $result_data['invoice_id'];
$save_column['OPN_rawOrderId'] = $result_data['invoice_id'];
$save_column['OPN_invoiceId'] = $result_data['invoice_id'];
$save_column['OPN_subject'] = isset($result_data['custom_id']) ? $result_data['custom_id'] : '';
$save_column['OPN_currency'] = $result_data['pay_currency'];
// $save_column['OPN_remark'] = empty($row['attach']) ? '' : json_encode($row['attach']);
// $save_column['OPN_payerLogId'] = isset( $row['openid']) ? $row['openid'] : '';
$save_column['OPN_fundSource'] = $result_data['fund_source'];
$save_column['OPN_rawContent'] = $result_data['memo'];
$save_column['OPN_noticeTime'] = date('Y-m-d H:i:s');
$this->insert_note($save_column) ;
return;
}
}

@ -39,7 +39,10 @@ class Note_model extends CI_Model {
public function failnotec($topnum = 2) {
$this->init();
$this->topnum = $topnum;
$this->pn_send = " AND (pn_send='sendfail' OR pn_send='') AND pn_payment_status='Completed' ";
$this->pn_send = " AND (pn_send='sendfail' OR pn_send='') AND pn_payment_status COLLATE SQL_Latin1_General_CP1_CI_AS ='Completed' ";
// 1小时前
$date = date("Y-m-d H:i:s", time() - 1800);
$this->search = " AND pn_lastedittime < '$date' " ;
//$this->orderby = ' ORDER BY pn.pn_sn ASC ';
return $this->get_list();
}
@ -48,6 +51,9 @@ class Note_model extends CI_Model {
$this->init();
$this->topnum = $topnum;
$this->pn_send = " AND (pn_send='sendfail' OR pn_send='') ";
// 1小时前
$date = date("Y-m-d H:i:s", time() - 3600);
$this->search = $topnum === 20 ? " AND pn_lastedittime < '$date' " : '';
//$this->orderby = ' ORDER BY pn.pn_sn ASC ';
return $this->get_list();
}
@ -67,6 +73,17 @@ class Note_model extends CI_Model {
return $this->get_list();
}
public function notewebhooks($topnum = 2, $api = false) {
$this->init();
$this->topnum = $topnum;
$sql = " AND (SUBSTRING(pn_memo, 8, 3) ='WH-' ) ";
$this->pn_send = $sql;
// $this->orderby=" ORDER BY pn_payment_date DESC, pn.pn_sn ASC ";
$api_order = $api === false ? "" : " WHEN 'send-wh' THEN 2 ";
$this->orderby=" ORDER BY CASE pn.pn_send WHEN 'sendfail' THEN 1 $api_order ELSE 99 END ,pn.pn_sn DESC ";
return $this->get_list();
}
public function noteaccount($topnum = 2, $account = '') {
$this->init();
$this->topnum = $topnum;
@ -78,10 +95,14 @@ class Note_model extends CI_Model {
public function search_date($date) {
$this->init();
$search_sql = " AND (pn.pn_datetime BETWEEN '$date 00:00:00' AND '$date 23:59:59' OR isnull(pn_send,'') in ('sendfail','unsend','')) AND pn_memo NOT LIKE '{\"id\":\"WH-%' "; // {"id":"WH-
$search_sql = " AND (pn.pn_datetime BETWEEN '$date 00:00:00' AND '$date 23:59:59' OR isnull(pn_send,'') in ('sendfail','unsend','')) AND pn_send NOT LIKE 'send-wh%' "; // {"id":"WH-
// AND pn_memo NOT LIKE '{\"id\":\"WH-%'
$this->search = $search_sql;
// $this->orderby=" ORDER BY CASE pn.pn_send WHEN 'sendfail' THEN 1 ELSE 2 END ,pn.pn_sn DESC ";
$this->orderby=" ORDER BY CASE WHEN pn.pn_send='sendfail' AND pn.pn_payment_status='Completed' THEN 1 WHEN pn.pn_send = 'sendfail' THEN 2 ELSE 9 END ,pn.pn_sn DESC ";
$this->orderby=" ORDER BY CASE WHEN pn.pn_send='sendfail' AND pn.pn_payment_status COLLATE SQL_Latin1_General_CP1_CI_AS = 'Completed' THEN 1
WHEN pn.pn_payment_status = 'DECLINED'
THEN 99
WHEN pn.pn_send = 'sendfail' THEN 2 ELSE 9 END, pn.pn_payment_date DESC ,pn.pn_sn DESC ";
// WHEN pn.pn_send = 'sendfail' THEN 2
return $this->get_list();
@ -95,6 +116,21 @@ class Note_model extends CI_Model {
$this->orderby=" ORDER BY pn_payment_date, pn_payer desc ";
return $this->get_list();
}
public function note_completed($pn_txn_id){
$this->init();
$this->topnum=1;
$this->pn_txn_id=" AND pn_payment_status='Completed' AND pn.pn_txn_id=".$this->HT->escape($pn_txn_id);
$this->orderby=" ORDER BY pn_payment_date, pn_payer desc ";
return $this->get_list();
}
public function search_note($pn_txn_id){
$this->init();
$this->topnum=10;
$this->pn_txn_id=" AND pn.pn_txn_id=".$this->HT->escape($pn_txn_id);
$this->orderby=" ORDER BY pn_payer desc ";
return $this->get_list();
}
public function search_key($search_key) {
$this->init();
@ -103,43 +139,47 @@ class Note_model extends CI_Model {
$search_key = trim($search_key);
if (!empty($search_key)) {
$search_sql.=" AND ( pn.pn_txn_id = '$search_key'
OR pn_reference_id = '$search_key'
OR pn.pn_invoice like '%$search_key%'
OR pn.pn_custom like '%$search_key%'
OR pn.pn_item_name like '%$search_key%'
OR pn.pn_item_number like '%$search_key%'
OR pn.pn_payer like '%$search_key%'
OR pn.pn_payer_email like '%$search_key%' )";
OR pn.pn_payer_email like '%$search_key%'
-- OR SUBSTRING(pn_memo, CHARINDEX('parent_txn_id\"', pn_memo) + 16, 17) = '$search_key'
) ";
}
$this->search = $search_sql;
return $this->get_list();
}
//存储paypal的实时通知
public function save_paypal_note($pn_txn_id, $pn_invoice, $pn_custom, $pn_mc_gross, $pn_item_name, $pn_item_number, $pn_mc_currency, $pn_payment_status, $pn_payer, $pn_payer_email, $pn_payment_date, $pn_memo) {
public function save_paypal_note($pn_txn_id, $pn_invoice, $pn_custom, $pn_mc_gross, $pn_mc_fee, $pn_item_name, $pn_item_number, $pn_mc_currency, $pn_payment_status, $pn_payer, $pn_payer_email, $pn_payment_date, $pn_memo, $pn_receiver_account=null, $pn_reference_id=null) {
$sql = "
INSERT INTO paypal_note
(
pn_txn_id,pn_invoice,pn_custom, pn_mc_gross, pn_item_name, pn_item_number,pn_mc_currency, pn_payment_status,pn_payer,pn_payer_email,pn_payment_date, pn_memo,pn_datetime,pn_send
pn_txn_id,pn_invoice,pn_custom, pn_mc_gross, pn_mc_fee, pn_item_name, pn_item_number,pn_mc_currency, pn_payment_status,pn_payer,pn_payer_email,pn_payment_date, pn_memo, pn_receiver_account, pn_lastedittime, pn_reference_id,
pn_datetime, pn_send
)
VALUES
(
?,N?,N?,?,N?,N?,?,?,N?,N?,?, N?, GETDATE(),'unsend'
?,N?,N?,?,?,N?,N?,?,?,N?,N?,?, N?, ?, GETDATE(), ?, GETDATE(),'unsend'
)
";
$query = $this->HT->query($sql, array($pn_txn_id, $pn_invoice, $pn_custom, $pn_mc_gross, mb_substr($pn_item_name, 0, 250) , $pn_item_number, $pn_mc_currency, $pn_payment_status, $pn_payer, $pn_payer_email, $pn_payment_date, $pn_memo));
$query = $this->HT->query($sql, array($pn_txn_id, $pn_invoice, $pn_custom, $pn_mc_gross, $pn_mc_fee, mb_substr($pn_item_name, 0, 250) , $pn_item_number, $pn_mc_currency, $pn_payment_status, $pn_payer, $pn_payer_email, $pn_payment_date, $pn_memo, $pn_receiver_account, $pn_reference_id));
$insertid = $this->HT->last_id('paypal_note');
return $query;
}
public function get_list() {
$this->topnum ? $sql = "SELECT TOP " . $this->topnum : $sql = "SELECT ";
// ,dbo.GetOrderCusCountry(pn_invoice) as payer_country
$sql .= "
pn.pn_sn
,pn.pn_txn_id
,dbo.GetOrderCusCountry(pn_invoice) as payer_country
,replace(replace(pn.pn_invoice,char(13),' '),char(10),' ') pn_invoice
,pn.pn_custom
,pn.pn_mc_gross
,pn.pn_mc_gross,pn.pn_mc_fee
,pn.pn_item_name
,pn.pn_item_number
,pn.pn_mc_currency
@ -148,6 +188,7 @@ class Note_model extends CI_Model {
,pn.pn_payer_email
,pn.pn_memo
,pn.pn_datetime
,pn.pn_lastedittime
,pn.pn_payment_date
,pn.pn_send
FROM paypal_note pn
@ -178,26 +219,32 @@ class Note_model extends CI_Model {
"pay@trippest.com" => "Trippest", // business":"pay@trippest.com"
"pays@chinahighlights.com" => "", // "CHT",
"paypal@chinahighlights.com" => "2", // "CHT",
"ycc@hainatravel.com" => "dev",
"0" => "unknown",
);
public function set_fundsource(&$ele)
{
$ele->fundsource = "";
$raw = json_decode($ele->pn_memo);
$business = isset($raw->business) ? $raw->business : (isset($raw->receiver_email) ? $raw->receiver_email : '0');
$business = isset($raw->business) ? $raw->business : (isset($raw->receiver_email) ? $raw->receiver_email : '');
$business = (isset($raw->GAI_API->payee) && isset($raw->GAI_API->payee->email_address)) ? $raw->GAI_API->payee->email_address : $business;
$business = $business ? $business : '0';
if ($this->code_fundsource[$business]) {
$ele->fundsource = $this->code_fundsource[$business];
}
if ( ! isset($raw->ipn_track_id) && (isset($raw->id) && strpos($raw->id, "WH-") === 0)) {
$is_webhook = ! isset($raw->ipn_track_id) && (isset($raw->id) && strpos($raw->id, "WH-") === 0);
if ($is_webhook && $business === '0') {
$ele->fundsource = '';
}
$ele->parent_txn_id = isset($raw->parent_txn_id) ? $raw->parent_txn_id : '';
$ele->ipn_time = isset($raw->ipn_time)? $raw->ipn_time : $ele->pn_datetime;
}
public function update_send($pn_txn_id, $pn_send, $pn_sn=NULL) {
$sql = "
UPDATE paypal_note
SET pn_send = ?
SET pn_send = ?, pn_lastedittime=GETDATE()
WHERE pn_txn_id = ?
";
$sql .= ($pn_sn===NULL) ? "" : " and pn_sn=$pn_sn ";
@ -213,6 +260,16 @@ class Note_model extends CI_Model {
return $this->HT->query($sql, array($pn_send, $pn_txn_id));
}
public function update_send_case($pn_txn_id, $pn_send) {
$sql = "
UPDATE paypal_note
SET pn_send = ?
WHERE pn_txn_id = ? AND pn_payment_status='0' AND pn_send != 'send'
AND LEFT(CAST(pn_memo AS VARCHAR(100)), 22) = '{\"txn_type\":\"new_case\"'
";
return $this->HT->query($sql, array($pn_send, $pn_txn_id));
}
//设置订单号
public function set_invoice($pn_txn_id, $pn_invoice) {
$sql = "

@ -33,7 +33,7 @@ class Paypal_model extends CI_Model {
order by CHARINDEX('$COLI_ID', COLI_ID) ";
$query = $this->HT->query($sql);
$result = $query->result();
if ($handpick === TRUE) {
if ($handpick === TRUE && count($result) > 0) {
$result = array($result[0]);
}
}
@ -77,7 +77,11 @@ class Paypal_model extends CI_Model {
//print_r($result[0]);
//die();
if (count($result) > 1 && $handpick===false) {
$result = array();
// $result = array();
$result = array_filter($result, function($item) use ($COLI_ID) {
return $item->COLI_ID === $COLI_ID;
});
$result = $result[0];
} else {
$result = $result[0];
}
@ -99,12 +103,12 @@ class Paypal_model extends CI_Model {
where GAI_COLI_SN = $coli_sn and GAI_AccreditNo = '$pn_txn_id'";
$info_query = $this->HT->query($info_sql);
$info_result = $info_query->result();
$info_result = $info_query->result_array();
$group_accout_info = array(
'GAI_SN' => 0,
'GAI_State' => 0
);
if (!empty($info_empty)) {
if (!empty($info_result)) {
$group_accout_info = $info_result[0];
}
return $group_accout_info;
@ -184,13 +188,13 @@ class Paypal_model extends CI_Model {
}
//添加收款记录(商务订单),APP会自动增加记录所以添加前根据金额来判断是否有重复记录
public function add_account_info_forAPP($GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo) {
public function add_account_info_forAPP($GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo, $GAI_API=null) {
//先判断是否有这条数据
$sql = "
IF NOT EXISTS(
SELECT TOP 1 1
FROM BIZ_GroupAccountInfo
WHERE GAI_COLI_SN = ? AND DeleteFlag=0 AND GAI_Type='15010'
WHERE GAI_COLI_SN = ? AND DeleteFlag=0 AND GAI_Type IN ('15010','15002')
and (
(GAI_AccreditNo IS NULL AND GAI_SQJE=? )
OR
@ -212,16 +216,25 @@ class Paypal_model extends CI_Model {
,GAI_CusEmail
,GAI_AccreditNo
,GAI_Memo
,GAI_API
,GAI_State
,DeleteFlag,LastEditTime
) VALUES (?,?,15010,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE())";
$query = $this->HT->query($sql, array($GAI_COLI_SN, $GAI_SQJE, $GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo));
$insertid = $this->HT->last_id('BIZ_GroupAccountInfo');
return $query;
) VALUES (?,?,15010,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE())";
$query = $this->HT->query($sql, array($GAI_COLI_SN, $GAI_SQJE, $GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo,$GAI_API));
$insertid = ($query && $query->num_rows() > 0) ? $this->HT->last_id('BIZ_GroupAccountInfo') : false;
return $insertid;
// affected_rows() doesn't work with the 'sqlsrv' driver in CI2
// The solution: Upgrade to the latest CodeIgniter 3.0.x version
// $ssql = "SELECT 1 as 'exist' from BIZ_GroupAccountInfo where GAI_AccreditNo=? ";
// $squery = $this->HT->query($ssql, array($GAI_AccreditNo));
// $ret = $squery->result();
// log_message('error','test: empty insert ' . __METHOD__ . ': ' . __LINE__ . PHP_EOL . var_export((!empty($ret)), 1));
// return !empty($ret);
}
//添加收款记录(商务订单)
public function add_account_info($GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_Money, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo) {
public function add_account_info($GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_Money, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo, $GAI_API=null) {
//先判断是否有这条数据
$sql = "
@ -246,16 +259,17 @@ class Paypal_model extends CI_Model {
,GAI_CusEmail
,GAI_AccreditNo
,GAI_Memo
,GAI_API
,GAI_State
,DeleteFlag,LastEditTime
) VALUES (?,?,15002,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE())";
$query = $this->HT->query($sql, array($GAI_AccreditNo, $GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_Money, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo));
$insertid = $this->HT->last_id('BIZ_GroupAccountInfo');
return $query;
) VALUES (?,?,15002,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE())";
$query = $this->HT->query($sql, array($GAI_AccreditNo, $GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_Money, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo,$GAI_API));
$insertid = ($query && $query->num_rows() > 0) ? $this->HT->last_id('BIZ_GroupAccountInfo') : false;
return $insertid;
}
//添加收款记录(传统订单)
public function add_tour_account_info($GAI_COLI_SN, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo) {
public function add_tour_account_info($GAI_COLI_SN, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo,$GAI_API=null) {
//先判断是否有这条数据
$sql = "
@ -277,12 +291,13 @@ class Paypal_model extends CI_Model {
,GAI_CusName
,GAI_CusEmail
,GAI_AccreditNo
,GAI_Memo
,GAI_Memo,GAI_API
,GAI_State
,DeleteFlag,LastEditTime
) VALUES (?,15002,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE())";
$query = $this->HT->query($sql, array($GAI_AccreditNo, $GAI_COLI_SN, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo));
$insertid = $this->HT->last_id('GroupAccountInfo');
) VALUES (?,15002,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE())";
$query = $this->HT->query($sql, array($GAI_AccreditNo, $GAI_COLI_SN, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo,$GAI_API));
$insertid = ($query && $query->num_rows() > 0) ? $this->HT->last_id('GroupAccountInfo') : false;
return $insertid;
}
@ -569,6 +584,16 @@ class Paypal_model extends CI_Model {
}
return 0;
}
public function get_ssje_exclude_fee($amount, $pay_type='15002', $currency='USD')
{
$sql = "SELECT dbo.ConvertToRMB(?, ?) as ssje";
$query = $this->HT->query($sql,array($currency, $amount));
$result = $query->result();
if ( ! empty($result)) {
return $result[0]->ssje;
}
return 0;
}
/*!
* 更新订单主表付款方式,防止没访问thankyou-train.asp
* @author LYT <lyt@hainatravel.com>
@ -582,21 +607,25 @@ class Paypal_model extends CI_Model {
}
//根据交易号获取收款记录(传统订单)
public function get_money_t($pn_invoice) {
$sql = "SELECT GroupAccountInfo.*
from GroupAccountInfo
where DeleteFlag=0 and GAI_AccreditNo=?
$sql = "SELECT cli.COLI_ID, gai.*
from GroupAccountInfo gai
LEFT JOIN ConfirmLineInfo AS cli ON cli.COLI_SN =GAI_COLI_SN
where gai.DeleteFlag=0 and gai.GAI_AccreditNo=?
";
$query = $this->HT->query($sql, array($pn_invoice));
// log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . PHP_EOL . var_export($this->HT->last_query(), 1));
$result = $query->result();
return $result;
}
//根据交易号获取收款记录(商务订单)
public function get_money_b($pn_invoice) {
$sql = "SELECT BIZ_GroupAccountInfo.*
public function get_money_b($pn_invoice, $find_memo = true) {
$find_memo_sql = $find_memo === true ? " OR GAI_Memo='$pn_invoice' " : "";
$sql = "SELECT GAI_COLI_ID AS COLI_ID, BIZ_GroupAccountInfo.*
from BIZ_GroupAccountInfo
where DeleteFlag=0 and ( GAI_AccreditNo=? or GAI_Memo=? )
where DeleteFlag=0 and ( GAI_AccreditNo=? $find_memo_sql )
";
$query = $this->HT->query($sql, array($pn_invoice, $pn_invoice));
$query = $this->HT->query($sql, array($pn_invoice));
// log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . PHP_EOL . var_export($this->HT->last_query(), 1));
$result = $query->result();
return $result;
}
@ -614,17 +643,50 @@ class Paypal_model extends CI_Model {
return $query;
}
/** JJH: 添加订单收款记录之后执行 */
public function exec_addToTask($GAI_SN)
/** 更新收款记录 */
public function update_money_api_t($deadId, $links)
{
$sql = "UPDATE GroupAccountInfo SET GAI_API=? WHERE GAI_AccreditNo=? AND GAI_API IS NULL ";
$query = $this->HT->query($sql, array($links, $deadId));
return $query;
}
public function update_money_api_b($deadId, $links)
{
$sql = "UPDATE BIZ_GroupAccountInfo SET GAI_API=? WHERE GAI_AccreditNo=? AND GAI_API IS NULL ";
$query = $this->HT->query($sql, array($links, $deadId));
return $query;
}
/**
* JJH: 添加订单收款记录之后执行
* @OrderSourceType: 线路订单填写 227001, 商务订单填写227002
**/
public function exec_addToTask($GAI_SN, $OrderSourceType =227001)
{
if (empty($GAI_SN)) return false;
$sql = " if not exists (
select top 1 1 from Sysautotask
where SAT_Type=1 and SAT_SourceSN=$GAI_SN
) exec SP_AddToSystask 1," . $GAI_SN;
where SAT_Type=1 and SAT_SourceSN=$GAI_SN and SAT_OrderSourceType= $OrderSourceType
) exec SP_AddToSystask 1," . $GAI_SN . "," . $OrderSourceType;
$query = $this->HT->query($sql);
return $query;
}
/**
* QQS: APP组退款之后执行
* 插入数据到“我的支付”
**/
public function exec_BIZ_TrainCostAdd($COLI_SN, $ssje)
{
// return false; // todo: 暂时关闭
log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . ' exec_BIZ_TrainCostAdd' . PHP_EOL . var_export(1, 1));
$sql = " exec SP_BIZ_TrainCostAdd $COLI_SN,$ssje ; select 0;";
log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . ' ' . PHP_EOL . var_export($sql, 1));
$this->HT->query($sql);
return false;
// return $query;
}
/** 写入商务订单操作记录 */
public function insert_biz_order_log($coli_sn, $log_info)
{

@ -17,7 +17,7 @@
</tr>
</tbody>
</table>
<div style="margin-top: 10px;color:#333 !important;font-family: arial,helvetica,sans-serif;font-size:12px;"><span style="color:#333333 !important;font-weight:bold;font-family: arial,helvetica,sans-serif;">Hello Guilin China International Travel Service Co., Ltd,</span>
<div style="margin-top: 10px;color:#333 !important;font-family: arial,helvetica,sans-serif;font-size:12px;"><span style="color:#333333 !important;font-weight:bold;font-family: arial,helvetica,sans-serif;">Hello China Highlights International Travel Service Co., Ltd,</span>
<br>
<span style="font-size:14px;color:#C88039;font-weight:bold;text-decoration:none;">You received a payment of <?php echo $mailinfo->pm_money.' '.$mailinfo->pm_currency; ?> from <?php echo $mailinfo->pm_payer; ?></span><span style="font-size:14px;color:#C88039;font-weight:bold;text-decoration:none;"> (<?php echo $mailinfo->pm_payer_email; ?>)</span><br>
<table cellpadding="5" style="color:#333333 !important;font-family: arial,helvetica,sans-serif;font-size:12px;">

@ -1 +1 @@
<?php $jsondata=json_decode($pn_memo);?><html><head><meta http-equiv="Content-Type"content="text/html; charset=utf-8"/></head><body style="font-size: 12px;font-family: arial,helvetica,sans-serif;margin-top:0;margin-bottom:0;"><div class="ppmail"><table align="center"border="0"cellpadding="0"cellspacing="0"width="100%"><tbody><tr valign="top"><td width="100%"><table align="center"border="0"cellpadding="0"cellspacing="0"style="color:#333333 !important;font-family: arial,helvetica,sans-serif;font-size:12px;"width="100%"><tbody><tr valign="top"><td><img src="http://www.mycht.cn/css/images/paypal_logo.gif"border="0"alt="PayPal logo"></td><td valign="middle"align="right"><?php echo $pn_payment_date;?><br>Transaction ID:<a target="new"href="https://www.paypal.com/c2/cgi-bin/webscr?cmd=_view-a-trans&amp;id=<?php echo $pn_txn_id; ?>"><?php echo $pn_txn_id;?></a></td></tr></tbody></table><div style="margin-top: 10px;color:#333 !important;font-family: arial,helvetica,sans-serif;font-size:12px;"><span style="color:#333333 !important;font-weight:bold;font-family: arial,helvetica,sans-serif;">Hello China Highlights International Travel Service Co.,Ltd,</span><br><span style="font-size:14px;color:#C88039;font-weight:bold;text-decoration:none;">You received a payment of <?php echo $pn_mc_gross;?> <?php echo $pn_mc_currency;?> from <?php echo $pn_payer;?> </span><span style="font-size:14px;color:#C88039;font-weight:bold;text-decoration:none;">( <?php echo $pn_payer_email;?> )</span><br><table cellpadding="5"style="color:#333333 !important;font-family: arial,helvetica,sans-serif;font-size:12px;"><tbody><tr><td valign="top">Thanks for using PayPal.You can now ship any items.To see all the transaction details,log in to your PayPal account.<br>It may take a few moments for this transaction to appear in your account.<br><span style="font-weight:bold;color:#333333;">Seller Protection-</span><span style="color: #4c8f3a;"></span></td><td></td></tr></tbody></table><div style="margin-top:0px;border-bottom:1px solid #aaaaaa;"></div><table border="0"cellpadding="0"cellspacing="0"style="color:#333 !important;font-family: arial,helvetica,sans-serif;font-size:12px; margin-bottom:5px;"width="98%"align="left"><tbody><tr><td style="padding-top:5px;"valign="top"width="50%"align="left"><span style="color:#333333;font-weight:bold;">Buyer</span><br><?php echo $pn_payer;?><br><?php echo $pn_payer_email;?><br><?php echo!empty($jsondata->payer_status)?$jsondata->payer_status:false;?></td><td style="padding-top:5px;"valign="top"><span style="color:#333333;font-weight:bold;display:none;">Instructions to merchant<br></span><span style="color:#333333;font-weight:bold;">Shipping Address:</span><br><span style="font-size:12px;"><?php echo!empty($jsondata->address_name)?$jsondata->address_name:false;?><br><?php echo!empty($jsondata->address_street)?$jsondata->address_street:false;?><br><?php echo!empty($jsondata->address_city)?$jsondata->address_city:false;?><br><?php echo!empty($jsondata->address_zip)?$jsondata->address_zip:false;?><br><?php echo!empty($jsondata->address_country)?$jsondata->address_country:false;?></span></td></tr></tbody></table><table align="center"border="0"cellpadding="0"cellspacing="0"style="clear:both;color:#333 !important;font-family: arial,helvetica,sans-serif;font-size:12px;margin-top:5px;"width="100%"><tbody><tr><td style="border:1px solid #ccc;border-right:none;border-left:none;padding:5px 10px 5px 10px !important;color: #333333 !important;"width="330"align="left">Description</td><td style="border:1px solid #ccc;border-right:none;border-left:none;padding:5px 10px 5px 10px !important;color: #333333 !important;"width="75"align="right">&nbsp;</td><td style="border:1px solid #ccc;border-right:none;border-left:none;padding:5px 10px 5px 10px !important;color: #333333 !important;"width="75"align="right">&nbsp;</td><td style="border:1px solid #ccc;border-right:none;border-left:none;padding:5px 10px 5px 10px !important;color: #333333 !important;"width="80"align="right">Amount</td></tr><tr><td style="padding:10px;"width="330"align="left"><?php echo $pn_invoice;?><br><?php echo $pn_custom;?><br><?php echo $pn_item_name;?><br><?php echo $pn_item_number;?><br></td><td style="padding:10px;"width="75"align="right"></td><td style="padding:10px;"width="75"align="right"></td><td style="padding:10px;"width="80"align="right"><?php echo $pn_mc_gross;?><?php echo $pn_mc_currency;?></td></tr></tbody></table></tr></tbody></table></div></body></html>
<?php $jsondata=json_decode($pn_memo);?><html><head><meta http-equiv="Content-Type"content="text/html; charset=utf-8"/></head><body style="font-size: 12px;font-family: arial,helvetica,sans-serif;margin-top:0;margin-bottom:0;"><div class="ppmail"><table align="center"border="0"cellpadding="0"cellspacing="0"width="100%"><tbody><tr valign="top"><td width="100%"><table align="center"border="0"cellpadding="0"cellspacing="0"style="color:#333333 !important;font-family: arial,helvetica,sans-serif;font-size:12px;"width="100%"><tbody><tr valign="top"><td><img src="http://www.mycht.cn/css/images/paypalLogo-2.png"border="0"alt="PayPal logo"></td><td valign="middle"align="right"><?php echo $pn_payment_date;?><br>Transaction ID:<a target="new"href="https://www.paypal.com/c2/cgi-bin/webscr?cmd=_view-a-trans&amp;id=<?php echo $pn_txn_id; ?>"><?php echo $pn_txn_id;?></a></td></tr></tbody></table><div style="margin-top: 10px;color:#333 !important;font-family: arial,helvetica,sans-serif;font-size:12px;"><span style="color:#333333 !important;font-weight:bold;font-family: arial,helvetica,sans-serif;">Hello China Highlights International Travel Service Co.,Ltd,</span><br><span style="font-size:14px;color:#C88039;font-weight:bold;text-decoration:none;">You received a payment of <?php echo $pn_mc_gross;?> <?php echo $pn_mc_currency;?> from <?php echo $pn_payer;?> </span><span style="font-size:14px;color:#C88039;font-weight:bold;text-decoration:none;">( <?php echo $pn_payer_email;?> )</span><br><table cellpadding="5"style="color:#333333 !important;font-family: arial,helvetica,sans-serif;font-size:12px;"><tbody><tr><td valign="top">Thanks for using PayPal.You can now ship any items.To see all the transaction details,log in to your PayPal account.<br>It may take a few moments for this transaction to appear in your account.<br><span style="font-weight:bold;color:#333333;">Seller Protection-</span><span style="color: #4c8f3a;"></span></td><td></td></tr></tbody></table><div style="margin-top:0px;border-bottom:1px solid #aaaaaa;"></div><table border="0"cellpadding="0"cellspacing="0"style="color:#333 !important;font-family: arial,helvetica,sans-serif;font-size:12px; margin-bottom:5px;"width="98%"align="left"><tbody><tr><td style="padding-top:5px;"valign="top"width="50%"align="left"><span style="color:#333333;font-weight:bold;">Buyer</span><br><?php echo $pn_payer;?><br><?php echo $pn_payer_email;?><br><?php echo!empty($jsondata->payer_status)?$jsondata->payer_status:false;?></td><td style="padding-top:5px;"valign="top"><span style="color:#333333;font-weight:bold;display:none;">Instructions to merchant<br></span><span style="color:#333333;font-weight:bold;">Shipping Address:</span><br><span style="font-size:12px;"><?php echo!empty($jsondata->address_name)?$jsondata->address_name:false;?><br><?php echo!empty($jsondata->address_street)?$jsondata->address_street:false;?><br><?php echo!empty($jsondata->address_city)?$jsondata->address_city:false;?><br><?php echo!empty($jsondata->address_zip)?$jsondata->address_zip:false;?><br><?php echo!empty($jsondata->address_country)?$jsondata->address_country:false;?></span></td></tr></tbody></table><table align="center"border="0"cellpadding="0"cellspacing="0"style="clear:both;color:#333 !important;font-family: arial,helvetica,sans-serif;font-size:12px;margin-top:5px;"width="100%"><tbody><tr><td style="border:1px solid #ccc;border-right:none;border-left:none;padding:5px 10px 5px 10px !important;color: #333333 !important;"width="330"align="left">Description</td><td style="border:1px solid #ccc;border-right:none;border-left:none;padding:5px 10px 5px 10px !important;color: #333333 !important;"width="75"align="right">&nbsp;</td><td style="border:1px solid #ccc;border-right:none;border-left:none;padding:5px 10px 5px 10px !important;color: #333333 !important;"width="75"align="right">&nbsp;</td><td style="border:1px solid #ccc;border-right:none;border-left:none;padding:5px 10px 5px 10px !important;color: #333333 !important;"width="80"align="right">Amount</td></tr><tr><td style="padding:10px;"width="330"align="left"><?php echo $pn_invoice;?><br><?php echo $pn_custom;?><br><?php echo $pn_item_name;?><br><?php echo $pn_item_number;?><br></td><td style="padding:10px;"width="75"align="right"></td><td style="padding:10px;"width="75"align="right"></td><td style="padding:10px;"width="80"align="right"><?php echo $pn_mc_gross;?><?php echo $pn_mc_currency;?></td></tr></tbody></table></tr></tbody></table></div></body></html>

@ -17,7 +17,7 @@
</tr>
</tbody>
</table>
<div style="margin-top: 30px;color:#333 !important;font-family: arial,helvetica,sans-serif;font-size:12px;"><span style="color:#333333 !important;font-weight:bold;font-family: arial,helvetica,sans-serif;">Hello Guilin China International Travel Service Co., Ltd,</span><br>
<div style="margin-top: 30px;color:#333 !important;font-family: arial,helvetica,sans-serif;font-size:12px;"><span style="color:#333333 !important;font-weight:bold;font-family: arial,helvetica,sans-serif;">Hello China Highlights International Travel Service Co., Ltd,</span><br>
<br>
<span style="font-size:14px;color:#C88039;font-weight:bold;text-decoration:none;">You received a payment of <?php echo $mailinfo->pm_money.' '.$mailinfo->pm_currency; ?> from <?php echo $mailinfo->pm_payer; ?></span><span style="font-size:14px;color:#C88039;font-weight:bold;text-decoration:none;"> (<?php echo $mailinfo->pm_payer_email; ?>)</span><br>
<table cellpadding="5" style="color:#333333 !important;font-family: arial,helvetica,sans-serif;font-size:12px;">

@ -1,4 +1,4 @@
<link href="http://www.mycht.cn/min?f=/css/destination.css" rel="stylesheet">
<link href="/css/destination.css" rel="stylesheet">
<script type="text/javascript">
$(document).ready(function() {
// $('.trigger_export_btn').trigger('click');// test
@ -55,6 +55,7 @@
.unknown-color{background-color: dimgray; }
.cht-color {background-color: #A31022;}
.trippest-color {background-color: #E83201;}
.dev-color {background-color: #00A2E8;}
</style>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary trigger_export_btn hidden-xs" data-toggle="modal" data-target="#exampleModal">
@ -185,6 +186,11 @@
<!-- Denied, Failed -->
</ul>
<hr width="100%" />
<ul class="list-unstyled ">
<li><a href="<?php echo site_url('apps/paypal/index/note_wb_list'); ?>" >webhooks</a></li>
</ul>
<hr width="100%" />
<div class="well well-sm hidden-xs" >
@ -202,33 +208,38 @@
<ul class="row mail_list hidden-xs">
<a href="javascript:void(0);" style="cursor:default;color:#000;">
<li class="col-sm-1 "><strong>#</strong></li>
<li class="col-sm-7 "><strong>主题</strong></li>
<li class="col-sm-6 "><strong>主题</strong></li>
<li class="col-sm-4"><strong>客人邮箱</strong></li>
<li class="col-sm-4 "><strong>交易号</strong></li>
<li class="col-sm-3 "><strong>收款(北京)时间</strong></li>
<li class="col-sm-2 "><strong>通知时间</strong></li>
<li class="col-sm-3 "><strong>交易(北京)时间</strong></li>
<li class="col-sm-3 "><strong>系统处理时间</strong></li>
<li class="col-sm-3 "><strong>通知状态</strong></li>
</a>
</ul>
<?php
foreach ($notelist as $key => $item) {
$raw_content = json_decode($item->pn_memo);
?>
<ul class="row mail_list">
<li class="col-sm-1 nopadding-L" style="overflow:hidden;word-break: break-all;height: 25px;"><?php echo ($key + 1); ?></li>
<li class="col-sm-7 nopadding-L" style="overflow:hidden;word-break: break-all;height: 25px;">
<li class="col-sm-6 nopadding-L" style="overflow:hidden;word-break: break-all;height: 25px;">
<span class="brand_text <?php echo strtolower(str_replace(" ","",$item->fundsource))."-color"; ?>"><?php echo $item->fundsource; ?></span>
<span class="brand_text <?php echo strtolower(str_replace(" ","",$item->fundsource))."-color"; ?>"><?php echo ($item->fundsource=== 'unknown' ? $raw_content->txn_type : $item->fundsource); ?></span>
<a href="<?php $p_invoice = explode('_', $item->pn_invoice); echo site_url('apps/paypal/index/note_list?search_key='.($p_invoice[0] ? $p_invoice[0] : $item->pn_invoice)); ?>"><?php echo $item->pn_invoice; ?></a>
<span>/</span>
<a class="seen" target="_blank" href="<?php echo site_url('apps/paypal/index/detail_ht/' . $item->pn_txn_id); ?>">
<?php echo htmlentities($item->pn_invoice) . ' / ' . $item->pn_mc_gross . $item->pn_mc_currency . ' / ' . $item->pn_payer; ?>
<?php echo $item->pn_mc_gross . $item->pn_mc_currency . ' / ' . $item->pn_payer; ?>
</a></li>
<li class="col-sm-4 nopadding-L" style="overflow:hidden;word-break: break-all;height: 25px;">
<a href="<?php echo site_url('apps/paypal/index/note_list?search_key='.$item->pn_payer_email); ?>"><?php echo $item->pn_payer_email; ?></a>
</li>
<li class="col-sm-4 nopadding-L" style="overflow:hidden;word-break: break-all;height: 45px;">
<?php echo $item->pn_txn_id; ?>
<?php // echo $item->pn_txn_id; ?>
<a href="<?php echo site_url('apps/paypal/index/note_list?search_key='.$item->pn_txn_id); ?>"><?php echo $item->pn_txn_id; ?></a>
<div>
<span>
<?php if ($item->parent_txn_id) { ?>
@ -239,12 +250,12 @@
</li>
<li class="col-sm-3 nopadding-L" style="overflow:hidden;word-break: break-all;height: 25px;"><?php echo date('Y-m-d H:i:s', strtotime($item->pn_payment_date) + 3600 * 8); ?></li>
<li class="col-sm-2 nopadding-L" ><?php echo $item->pn_datetime; ?></li>
<li class="col-sm-3 nopadding-L" ><?php echo empty($item->pn_lastedittime) ? $item->pn_datetime : $item->pn_lastedittime; ?></li>
<li class="col-sm-3" >
<?php
$show_send = '';
$status_detail = '';
$class_css = '';
$raw_content = json_decode($item->pn_memo);
$show_record = '查看录入状态';
if ($item->pn_send == 'send' || substr($item->pn_send, 0, 5) == "send-") {
$show_send = $item->pn_send . " / " . str_ireplace('completed', '', $item->pn_payment_status);
@ -257,8 +268,14 @@
} else {
$class_css = 'btn-danger';
$show_send = $item->pn_payment_status ? $item->pn_payment_status : $raw_content->txn_type;
// $show_send .= '. ';
$status_detail .= isset($raw_content->resource->status_details) ? $raw_content->resource->status_details->reason : '';
}
?><a href="javascript:void(0);" onclick="show_order_modal('<?php echo $item->pn_txn_id; ?>', '<?php echo $item->pn_sn; ?>')" class="btn btn-sm <?php echo $class_css; ?>"><?php echo $show_send; ?></a>
<?php if ($status_detail) { ?>
<br class="hidden-xs">
<span class="text-muted"><?php echo $status_detail; ?></span>
<?php } ?>
<br class="hidden-xs">
<a href="javascript:void(0);" class="text_padding text-primary" style="padding: 10px;"
onclick="show_gai_modal('<?php echo $item->pn_txn_id; ?>','<?php echo $item->pn_sn; ?>')"

@ -22,7 +22,7 @@
</dl>
<dl class="dl-horizontal">
<dt>付款时间</dt>
<dd><?php echo date('Y-m-d H:i:s', strtotime($note->pn_payment_date) + 3600 * 8); ?></dd>
<dd><?php echo date('Y-m-d H:i:s', strtotime($note->pn_payment_date) + 3600 * 8); ?>&nbsp;&nbsp;&nbsp;&nbsp;通知:<?php echo date('Y-m-d H:i:s', strtotime($note->pn_datetime)); ?></dd>
</dl>
<dl class="dl-horizontal">
<dt>备注&nbsp;/&nbsp;留言</dt>
@ -37,6 +37,10 @@
} ?>
</dd>
</dl>
<dl class="dl-horizontal">
<dt>Custom</dt>
<dd><?php echo $note->pn_custom ?></dd>
</dl>
<dl class="dl-horizontal">
@ -82,9 +86,13 @@
</dl>
<dl class="dl-horizontal">
<dt><a href="javascript:void(0);" onclick="$('#note_original_data').toggle()">原始数据</a></dt>
<dd> <span style="display: none;" id="note_original_data">
<?php echo str_replace('","', '"<br/>"', $note->pn_memo); ?>
</span></dd>
<dd> </dd><span style="display: none;" id="note_original_data">
<?php
$array = json_decode($note->pn_memo, true);
$jsonPretty = json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
echo "<pre>$jsonPretty</pre>";
?>
</span>
</dl>
<input type="hidden" name="pn_txn_id" id="pn_txn_id" value="<?php echo $note->pn_txn_id ?>" />

@ -1,5 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=http://www.w3.org/1999/xhtml> <head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><title>Your Submission Was Successful! - China Highlights</title><style type=text/css>* { margin:0; font-family: Verdana, Arial, Helvetica, sans-serif; }body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size:13px; color:#545454; right: auto; }img, ul, ul li { padding:0; margin:0; border:0; }#warp { border-top:8px solid #a31022!important; }#logo { border: none!important}#logo, #surveyContent { width:210mm; margin:5px auto; padding:5px; }h1 { margin:15px 0 10px 0; font-size:24px; border-bottom:1px solid #d9d9d9; color:#545454; }h2 { margin:15px 0 10px 0; font-size:20px; color:#545454; }.tableSurvey table td { padding:5px; }.tableSurvey table td strong { margin-top:8px; }.tableSurvey1 { border:1px solid #e1e1e1; }.tableSurvey1 th { border:1px solid #fff; height:30px; padding-right:10px; text-align:right; background:#f1f1f1; }.tableSurvey1 td { border:1px solid #f9f9f9; padding:5px; text-align:center; width:80px; }.tableSurvey2 { border:1px solid #e1e1e1; }.tableSurvey2 th { border:1px solid #fff; padding:5px 10px; text-align:right; background:#f1f1f1; font-weight:normal; }.tableSurvey2 td { border:1px solid #f9f9f9; padding:5px; text-align:center; width:80px; }.blue{ color:#0070C0}.text-bold {font-weight: bold;}.text-right{text-align: right;}.title-bold{font-weight: bold;background-color: #ddd;padding: 3px 0;}</style></head> <body> <div id=warp> <div id=surveyContent> <?php $raw = json_decode($pn_memo); $c_gross = str_replace("-", "", $pn_mc_gross); ?> <p>Dear <?php echo $pn_payer ?>,</p> <br> <p>China Highlights has refunded to your account today - <?php echo $c_gross ?><?php echo $pn_mc_currency ?>. The transaction to appear on your account may take up to 2-weeks.</p> <br> <p>Please find below details of your refund transaction:</p> <br> <p class=title-bold>Transaction details</p> <p><?php echo $raw->payment_date ?></p> <p>Payment status: <?php echo $pn_payment_status ?></p> <br> <p class=title-bold>Payment details</p> <p>Gross amount</p> <p class=text-right><?php echo $pn_mc_gross ?> <?php echo $pn_mc_currency ?></p> <br> <p class=title-bold>Invoice ID</p> <p><?php echo $pn_invoice ?></p> <br> <p class=title-bold>Contact information</p> <p><?php echo $pn_payer ?></p> <p><?php echo $pn_payer_email ?></p> <br> <br> <pre style="font-family: Verdana, Arial, Helvetica, sans-serif;font-size:13px;">
<html xmlns=http://www.w3.org/1999/xhtml> <head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><title>Your Submission Was Successful! - China Highlights</title><style type=text/css>* { margin:0; font-family: Verdana, Arial, Helvetica, sans-serif; }body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size:13px; color:#545454; right: auto; }img, ul, ul li { padding:0; margin:0; border:0; }#warp { border-top:8px solid #a31022!important; }#logo { border: none!important}#logo, #surveyContent { width:210mm; margin:5px auto; padding:5px; }h1 { margin:15px 0 10px 0; font-size:24px; border-bottom:1px solid #d9d9d9; color:#545454; }h2 { margin:15px 0 10px 0; font-size:20px; color:#545454; }.tableSurvey table td { padding:5px; }.tableSurvey table td strong { margin-top:8px; }.tableSurvey1 { border:1px solid #e1e1e1; }.tableSurvey1 th { border:1px solid #fff; height:30px; padding-right:10px; text-align:right; background:#f1f1f1; }.tableSurvey1 td { border:1px solid #f9f9f9; padding:5px; text-align:center; width:80px; }.tableSurvey2 { border:1px solid #e1e1e1; }.tableSurvey2 th { border:1px solid #fff; padding:5px 10px; text-align:right; background:#f1f1f1; font-weight:normal; }.tableSurvey2 td { border:1px solid #f9f9f9; padding:5px; text-align:center; width:80px; }.blue{ color:#0070C0}.text-bold {font-weight: bold;}.text-right{text-align: right;}.title-bold{font-weight: bold;background-color: #ddd;padding: 3px 0;}</style></head> <body> <div id=warp> <div id=surveyContent> <?php $raw = json_decode($pn_memo); $c_gross = str_replace("-", "", $pn_mc_gross); ?> <p>Dear <?php echo $pn_payer ?>,</p> <br> <p>China Highlights has refunded to your account today - <?php echo $c_gross ?><?php echo $pn_mc_currency ?>. The transaction to appear on your account may take up to 2-weeks.</p> <br> <p>Please find below details of your refund transaction:</p> <br> <p class=title-bold>Transaction details</p> <p><?php echo isset($raw->payment_date) ? $raw->payment_date : $pn_payment_date ?></p> <p>Payment status: <?php echo $pn_payment_status ?></p> <br> <p class=title-bold>Payment details</p> <p>Gross amount</p> <p class=text-right><?php echo $pn_mc_gross ?> <?php echo $pn_mc_currency ?></p> <br> <p class=title-bold>Invoice ID</p> <p><?php echo $pn_invoice ?></p> <br> <p class=title-bold>Contact information</p> <p><?php echo $pn_payer ?></p> <p><?php echo $pn_payer_email ?></p> <br> <br> <pre style="font-family: Verdana, Arial, Helvetica, sans-serif;font-size:13px;">
Best Regards!
<?php echo $advisor_detail->fullname ?>, Travel Advisor<br>

@ -8,8 +8,11 @@
<link href="/css/webht/bootstrap.min.css" rel="stylesheet">
<link href="/css/nav/nav.css?v=20200316" rel="stylesheet">
<link href="/css/webht/jquery-ui-1.10.0.custom.css" rel="stylesheet">
<script src="http://www.mycht.cn/min?f=/js/jquery.js,/js/bootstrap.min.js,/js/navigation.js,/js/jquery.form.min.js"></script>
<script src="http://www.mycht.cn/js/jquery-ui.min.js?v=1"></script>
<script src="/js/jquery.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/navigation.js"></script>
<script src="/js/jquery.form.min.js"></script>
<script src="/js/jquery-ui.min.js?v=1"></script>
<!--[if lt IE 9]>
<script src="/js/respond.min.js" type="text/javascript"></script>
<![endif]-->

Loading…
Cancel
Save