Compare commits

...

126 Commits

Author SHA1 Message Date
Lei OT e6268d6090 perf: 微信支付: 交易号查询 3 months ago
Lei OT 9652b9aad1 perf: 微信支付: 交易号查询 4 months ago
Lei OT f9a7839851 perf: GAI 删除标记 4 months ago
Lei OT f4e7106c9c perf: GAI 删除标记 4 months ago
Lei OT 4a4b4af048 perf: paypal: IPN 记录gai_api 用于退款接口 5 months ago
Lei OT 65624e9a8e paypal ... 5 months ago
Lei OT 3614c4b7c2 fix: PayPal 费率提醒 5 months ago
Lei OT cbeb85f4e9 style: 6 months ago
Lei OT 5521f2e5cd style: 6 months ago
Lei OT e0d7cf49d2 OPN : 保存订单时, 记录删除备注; 跳过不是wxpay 6 months ago
Lei OT 95513a69ae PayPal webhook 监听重复 6 months ago
Lei OT a7afee3d34 style: 6 months ago
Lei OT 44db54a8a2 perf: PayPal 每月费率 6 months ago
Lei OT cce47f2111 PayPal webhook 时间; style: payment_list 6 months ago
Lei OT e7a83740ec fix: 查找付款记录,用于判断是否已经审核。style: OPN 6 months ago
Lei OT c4500b4819 PayPal webhook 接收 case 6 months ago
Lei OT 36192408b1 PayPal 付款账号的认证状态, 先从approved事件获取 6 months ago
Lei OT f0074e88ba style: 6 months ago
Lei OT 974e4c6fc2 PayPal webhook PAYMENT.CAPTURE.PENDING 6 months ago
Lei OT 360f73cf30 style: 6 months ago
Lei OT 329717d87f PayPal 查询订单信息, 先从approved事件获取 6 months ago
Lei OT 72deffe67d perf: online payment list 6 months ago
Lei OT 4586fb3645 PayPal webhook PAYMENT.CAPTURE.REVERSED 6 months ago
Lei OT 2491353373 style: declined 6 months ago
Lei OT adb98391c3 fix: PayPal查询支付方式 6 months ago
Lei OT a8b0179c81 perf: PayPal 付款记录, 删除链接 6 months ago
Lei OT 4ff6f42768 perf: WxPay: 付款记录, 模糊查找 6 months ago
Lei OT 6c60b4ef01 perf: 支付宝退款: 付款状态更新财务系统 7 months ago
Lei OT 2ffcda34ee perf: 支付宝退款: 没有交易号的跳过 7 months ago
Lei OT 3329ddd85a perf: payment list 7 months ago
Lei OT c3b265a58f feat: 支付宝退款: 异步更新状态到财务系统 7 months ago
Lei OT def549e8ac feat: 支付宝退款: 状态值使用财务系统的值 7 months ago
Lei OT e0bd459a52 perf: PayPal: 记录 `CHECKOUT.ORDER.APPROVED` 事件 7 months ago
Lei OT a74d363bf8 feat: 支付宝退款API 7 months ago
Lei OT ad1a4386e5 fix: PayPal查询order 的账户 7 months ago
Lei OT c313278459 fix: 支付宝退款: 发客人邮件 7 months ago
Lei OT a1ebec60e4 fix: 支付宝退款: 发客人邮件 9 months ago
Lei OT 2303109064 perf: 收款记录显示: Highlights Travel 9 months ago
Lei OT 3a7e39a302 perf: alipay: 订单绑定, 查询订单信息 9 months ago
Lei OT 0f1bb349e7 feat: 新PayPal账户: Highlights Travel 9 months ago
Lei OT 13832b8eba perf: 微信账单原文 10 months ago
Lei OT 7f4c2acb0d fix: 存储过程: APP组退款记录录入后补充记录: 录入`我的支付` 10 months ago
Lei OT a55f4f65cd feat: 微信查询接口 10 months ago
Lei OT f5441607e8 fix: PayPal, 缺少custom id 10 months ago
Lei OT 9493a94540 fix: 微信资金账单 10 months ago
Lei OT bad05aa0ed fix: PayPal: 重复的webhook记录 10 months ago
Lei OT b6a0658cf0 perf: 操作人记录 10 months ago
Lei OT 564325ab6d perf: 支付宝 账单 10 months ago
Lei OT 9e390b23b0 perf: 微信: 操作人记录 1 year ago
Lei OT 29c620c216 perf: 微信: 页面默认 15016 1 year ago
Lei OT d8f1751378 perf: 微信: 下载资金账单; 证书 1 year ago
Lei OT d1782865c9 fix: PayPal v1的退款 PAYMENT.SALE.REFUNDED 1 year ago
Lei OT a7625be398 微信, 支付宝: 账单 1 year ago
Lei OT d6bd578b99 PayPal: 汇总查询额度; 查询当前的费率 1 year ago
Lei OT c8a60364f1 PayPal webhook 接收 `PAYMENT.SALE.REVERSED` 1 year ago
Lei OT 100d06edb4 onlinepayment: PayPal 获取支付方式 1 year ago
Lei OT da2d812070 . 1 year ago
Lei OT 6ca3fb75de GAI_API 1 year ago
Lei OT cc8d76a8db 集中Alipay 的记录到在线支付记录 1 year ago
Lei OT 098316794b wxpay: 记录 payment Source; 账单录入, 查询录入等 1 year ago
Lei OT 155c137a97 集中PayPal的webhook记录到在线支付记录 1 year ago
Lei OT 740f1aed0a perf: PayPal: APP组退款记录录入后补充记录: 录入`我的支付`; 执行HT任务`SP_AddToSystask`; ACDC付款忽略邮箱地址 1 year ago
Lei OT 102ce623d3 feat: 连连信用卡: 异步通知; 处理 1 year ago
Lei OT 51972536ad perf: APP组退款记录录入后补充记录: 录入`我的支付` 1 year ago
Lei OT b0f15b97fe perf: 支付中心: 录入记录后, 执行HT任务`SP_AddToSystask` 1 year ago
Lei OT 99c4d6743a perf: APP组退款记录录入后补充记录: 录入`我的支付` 1 year ago
Lei OT 3d4a2bdea4 perf: 收款通知邮件的公司名称 1 year ago
Lei OT 991d8d2e96 perf: 每月20号, 发送退款调账记录给财务; 修复PayPal重复 2 years ago
Lei OT f226619289 perf: PayPal退款: 优先处理IPN 2 years ago
Lei OT b6da466e81 perf: PayPal记录: 调整列表页面排序 2 years ago
Lei OT 028f48d069 perf: PayPal退款: 优先处理IPN 2 years ago
Lei OT 18bb1e1e84 fix: PayPal退款记录: 重复发邮件 2 years ago
Lei OT 370dfd42e2 fix: PayPal记录, Webhook数据中的手续费读取, pengding状态无数据; todo: 查询已完成的 2 years ago
Lei OT c064662783 perf: PayPal记录: 显示pending的原因 2 years ago
Lei OT dc01f8e59d fix: PayPal记录: 判断APP的是否已存在手动的记录 2 years ago
Lei OT 7e1140a6d6 fix: PayPal退款减去手续费 2 years ago
Lei OT ce7d7b7ce0 fix: PayPal wh记录手动录入 2 years ago
Lei OT 0c3d3be577 perf: `支付宝`退款处理: 金额明细已记录数据库 2 years ago
Lei OT 160d6e6621 perf: PayPal退款处理: 只有wh记录 2 years ago
Lei OT cfa8070b3b perf: PayPal DECLINED 保留记录, 自动忽略 2 years ago
Lei OT 9107425120 perf: PayPal记录 2 years ago
Lei OT 2a50bae00c perf: PayPal: wenhook , 记录被拒绝的 2 years ago
Lei OT 36a86c93d2 微信支付的send notify 2 years ago
Lei OT 1e2f088eb4 style: wxpay 2 years ago
Lei OT 56a546875f perf: PayPal退款处理: 从收款记录获取订单号 2 years ago
Lei OT d6363ef9ce sync: 网前的版本 2 years ago
Lei OT 9bbc6ad408 fix: Alipay退款账单的处理,不发送以前的邮件 2 years ago
Lei OT 1b4459a744 fix: PayPal detail logo 2 years ago
Lei OT 1f52e51106 fix: PayPal记录: 商户账户 2 years ago
Lei OT 5c731a3782 perf: PayPal记录: 查询交易关联的退款 2 years ago
Lei OT b421108b43 perf: PayPal字段: 更新时间 2 years ago
Lei OT f40d5ec7e6 # 2 years ago
Lei OT 0449fc0070 perf: PayPal收款记录: 增加账户等字段 2 years ago
Lei OT 00299e79d0 perf: PayPal记录: 显示webhook的账户 2 years ago
Lei OT a53984540c 记录通知的时间 2 years ago
Lei OT ac7a6fc57c perf: PayPal webhook处理 2 years ago
Lei OT a5ea8d1519 perf: PayPal webhook 处理. 解决部分交易没有IPN 2 years ago
Lei OT be664ebc9c perf: PayPal收款, 显示wb记录 2 years ago
Lei OT 6f91702704 perf: PayPal note modal 显示custom 2 years ago
Lei OT 2a56950e72 perf: PayPal 退款处理: 没有外联地址 2 years ago
Lei OT 60f3c62005 feat: PayPal API退款的custom_id 2 years ago
Lei OT 747b768ccb perf: PayPal收款处理: 多条订单匹配处理 2 years ago
Lei OT 70bb2695d3 feat: PayPal: 处理webhook, 把PayPal账户写入 GAI 表 2 years ago
Lei OT 3c0dcfa90c fix: PayPal 收款记录审核提示 2 years ago
Lei OT e1829d5685 feat: PayPal: 处理webhook, 把资源地址写入 GAI 表 2 years ago
Lei OT a1d4c4cce1 perf: PayPal 已录入订单但是外联没有设置邮箱, 忽略了 2 years ago
Lei OT 56db24fc56 . 2 years ago
Lei OT 90edc01a7a conf: https 2 years ago
Lei OT df56ba5f60 # 2 years ago
Lei OT 5c50297c72 perf: PayPal webhooks: custom_id 2 years ago
Lei OT 04eba4d8c6 fix: 字段检查 2 years ago
Lei OT 8afa987676 fix: Alipay: 解决多次退款时, 异步通知每次都返回已退的总金额, 直接录入导致金额累加了. 2 years ago
Lei OT 4a1a0fd6e1 fix: PayPal webhooks: 退款 currency 2 years ago
Lei OT babc652ce9 fix: PayPal webhooks: 退款 invoice number 2 years ago
Lei OT 857e318e03 perf: PayPal webhooks: 处理手续费 2 years ago
Lei OT d6e692a3ac feat: PayPal webhooks 接收V2 API 2 years ago
Lei OT 5798195e0f feat: PayPal收款: 实收金额计算, 使用实际扣的服务费 2 years 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

5
.gitignore vendored

@ -10,11 +10,12 @@
*/cache/*
/author/document/*
*/settlement_files/*
*/statement_files/*
*/statement_files/*
download_statement
*/paypal_activities/*
/author/document/*
/application/libraries/composer
/application/config/database.php
**/*cert

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,18 @@
欢迎使用微信支付!
附件中的三份文件证书pkcs12格式、证书pem格式、证书密钥pem格式,为接口中强制要求时需携带的证书文件。
证书属于敏感信息,请妥善保管不要泄露和被他人复制。
不同开发语言下的证书格式不同,以下为说明指引:
证书pkcs12格式apiclient_cert.p12
包含了私钥信息的证书文件为p12(pfx)格式,由微信支付签发给您用来标识和界定您的身份
部分安全性要求较高的API需要使用该证书来确认您的调用身份
windows上可以直接双击导入系统导入过程中会提示输入证书密码证书密码默认为您的商户号1900006031
证书pem格式apiclient_cert.pem
从apiclient_cert.p12中导出证书部分的文件为pem格式请妥善保管不要泄漏和被他人复制
部分开发语言和环境不能直接使用p12文件而需要使用pem所以为了方便您使用已为您直接提供
您也可以使用openssl命令来自己导出openssl pkcs12 -clcerts -nokeys -in apiclient_cert.p12 -out apiclient_cert.pem
证书密钥pem格式apiclient_key.pem
从apiclient_cert.p12中导出密钥部分的文件为pem格式
部分开发语言和环境不能直接使用p12文件而需要使用pem所以为了方便您使用已为您直接提供
您也可以使用openssl命令来自己导出openssl pkcs12 -nocerts -in apiclient_cert.p12 -out apiclient_key.pem
备注说明:
由于绝大部分操作系统已内置了微信支付服务器证书的根CA证书, 2018年3月6日后, 不再提供CA证书文件rootca.pem下载

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

@ -0,0 +1,38 @@
<?php
$config['htravel']['host_account'] = "htravel";
// test: sanbox
// $config['client_id'] = "AVfErlDftQcNj22239jNQmTV-J-rLqBdNf3HZO0-McmElUDxadiF8vAQdeXmZAnB_nKy06ZwFazs1kKU";
// $config['secret'] = "EJUmlpxrNHkm3Kv4xBd1Qm2_kLGAmAcS8hbYKarYGAvQrDaJT-HrPgx_AEXL12-mt_3EM2KqM_E2eJtt";
// prod: live
// * App display name:highlightstravel
$config['htravel']['client_id'] = "AYyIRML2sjjuIni-45f3DWCe1qeD13sIbhwqQm25SKqxswmcA-jLynXmPDwMzSDjZWT13FnKVOSOuWBD";
$config['htravel']['secret'] = "EC0pW9plsWk3kyvKRDb1K45Z5Szzlk9hEmgqiv4RxT3TkFEkLrHvD5R04IRt6hgcNPw9GRWAE5zOS9Gy";
// * App display name:NVP SOAP
// $config['htravel']['client_id'] = "AfJ8StOuWvKkyRjWk_3FQz1gnUjEE_z_mcM69xjm-jlr5Qawgs5K2NNgt7rfDqsm0iNO2QsMAspaJ5y4";
// $config['htravel']['secret'] = "EO3P8TDnBb9xgUad3mKJuFZzyvFafBlAUSdiPclde5hdemcz1Pb3thpqn2ZKjGPQuZT5P0Ck8iC3f0Xf";
// * App display name:NVP SOAP
// $config['htravel']['client_id'] = "AYhAcbb6bC5eLQFHoXVXDIj7NON0yrM4EOU5d8PHXy9XxRE4K1shyxDI1im6yR0DHBsaHIlcxFZjvLbv";
// $config['htravel']['secret'] = "EBiT77stdZPNXYB87F5dFLn9a10csMAOGiulEzmWorq3nt_87RLwqyWubu_JRPzgDg82Aqh_A67lO2Zc";
$config['htravel']['biz_account'] = 'pays@highlightstravel.com';
$config['htravel']['locale'] = "en_US";
$config['htravel']['currency'] = "USD";
$config['htravel']['token_url'] = "https://api.paypal.com/v1/oauth2/token";
// $config['htravel']['web_profiles_url'] = "https://api.paypal.com/v1/payment-experience/web-profiles/";
// $config['htravel']['webhooks_url'] = "https://api.paypal.com/v1/notifications/webhooks";
// $config['htravel']['payment_url'] = "https://api.paypal.com/v1/payments/payment";
$config['htravel']['paypal_url'] = "https://www.paypal.com";
$config['htravel']['paypal_base'] = "https://api.paypal.com";
$config['htravel']['notify_verify_url'] = "https://ipnpb.paypal.com/cgi-bin/webscr";
$config['htravel']['return_url'] = "https://www.chinahighlights.com";
$config['htravel']['cancel_url'] = "https://www.chinahighlights.com";
$config['htravel']['notify_url'] = "https://callback.chinahighlights.com/webht.php/apps/paypal/index/paypal_note";
$config['htravel']['webhook_url'] = "https://callback.chinahighlights.com/webht.php/apps/paypal/index/paypal_webhook";

@ -21,10 +21,12 @@ $config['trippest']["app_id"] = "wx7e605820faf98a05";
$config['trippest']["mch_id"] = "1528541381";
$config['trippest']["key"] = "b6f4db121410468e814d812c6c641efd";
$config['trippest']["app_secret"] = "";
$config['trippest']["cert_path"] = dirname(__FILE__) . "/1528541381_cert";
// ChinaHighlights = China train booking
$config['cht']["notify_url"] = "https://www.mycht.cn/webht.php/apps/pay/wxpayservice/notify/cht";
$config['cht']["app_id"] = "wxd6c8dd69af5128cd";
$config['cht']["mch_id"] = "1353239702";
$config['cht']["key"] = "aada7476b3fecc2c6e33a7c765298516";
$config['cht']["app_secret"] = "";
$config['cht']["cert_path"] = dirname(__FILE__) . "/1353239702_cert";
// wx5d01021a6d515098 花梨鹰小程序

@ -49,11 +49,15 @@ class AlipayTradeService extends CI_Controller
$this->load->model('AlipayTradePagePayContentBuilder');
$this->load->model('AlipayTradeWapPayContentBuilder');
$this->load->model('AlipayTradeQueryContentBuilder');
$this->load->model('AlipayTradeRefundContentBuilder');
$this->load->model('Alipay_note_model');
$this->load->model('Alipay_model');
$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 +102,15 @@ class AlipayTradeService extends CI_Controller
}
}
private function get_fundsource($app_id)
{
$code_fundsource = array(
"2021004129643221" => "trippest",
"2017092108849921" => "cht", // "CHT",
);
return $app_id && isset($code_fundsource[$app_id]) ? $code_fundsource[$app_id] : 'cht';
}
public function index()
{
$this->note_list();
@ -152,6 +165,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 +200,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 = isset($asyns_resp->data->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 +497,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 +521,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 +540,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 +564,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);
}
}
@ -567,6 +621,14 @@ class AlipayTradeService extends CI_Controller
*/
public function send_refund($item, $old_ssje=null, $handpick)
{
if (empty($item->ALI_resultMsg)) {
return;
}
if (($item->ALI_resultMsg) === 'pending') {
// 查询退款结果
$this->query_refund_result($item);
return;
}
// raw
$raw = json_decode($item->ALI_memo);
$parent_order = $raw->out_trade_no;
@ -617,7 +679,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 +693,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 +719,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 +742,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 +751,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;
}
@ -714,11 +789,11 @@ class AlipayTradeService extends CI_Controller
$this->Alipay_model->save_automail($fromName, $fromEmail, $toName, $toEmail, $subject, $body, $M_RelatedInfo, $M_State, $M_AddTime, 'Alipay note');
// 通知客人, 客人邮箱
$customer_detail = $this->Alipay_model->get_customer_detail($advisor_info->COLI_SN, $orderid_info->ordertype);
$c_fromName = $advisor_detail->fullname;
$c_fromName = $advisor_detail->fullname ? $advisor_detail->fullname : '';
$opi_email_list = explode(";", $advisor_detail->email); // 解析外联的邮件
$c_fromEmail = trim($opi_email_list[0]);
$c_toName = $customer_detail->fullname;
$c_toEmail = $customer_detail->email;
$c_toEmail = isset($customer_detail->email) ? $customer_detail->email : '';
$c_subject = $currencyCode . " " . str_replace('-', '', $item->ALI_orderAmount) . " Refunded to your account, booking number " . $item->ALI_orderId;
// 修改一些字段名, 为了和iPaylinks等用同一个邮件模板
$item->payer = $customer_detail->fullname;
@ -752,7 +827,7 @@ class AlipayTradeService extends CI_Controller
// 更新是否需要发送财务
$refund_finance_day = 20;
$now_day = date('d');
$late_entry_date_set = $now_day<$refund_finance_day ? date('Y-m-01', strtotime("-1 month")) : date('Y-m-01');
$late_entry_date_set = $now_day < $refund_finance_day ? date('Y-m-01', strtotime("-1 month")) : date('Y-m-01');
if ($this->payment_model->if_finance_done($advisor_info->COLI_GRI_SN, $late_entry_date_set) === true) {
$this->Alipay_note_model->update_send($item->ALI_dealId, 'send-to-finance');
}
@ -797,13 +872,15 @@ class AlipayTradeService extends CI_Controller
/*!
* 查询退款
* @date 2019-04-24
* @param [type] $dealId 必须, 退款请求号.out_biz_no, 或原始交易订单号
* @param [type] $request_no 必须, 退款请求号.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)
public function query_refund($request_no=NULL,$trade_no=NULL, $order_id=NULL)
{
$this->AlipayTradeQueryContentBuilder->setOutRequestNo($dealId);
$this->AlipayTradeQueryContentBuilder->setOutRequestNo($request_no);
$this->AlipayTradeQueryContentBuilder->setTradeNo($trade_no);
$this->AlipayTradeQueryContentBuilder->setOutTradeNo($order_id);
@ -812,8 +889,9 @@ class AlipayTradeService extends CI_Controller
$request->setBizContent ( $biz_content );
$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));
$response = $response->alipay_trade_fastpay_refund_query_response;
return $response;
// return $this->output->set_content_type('application/json')->set_output(json_encode($response));
}
public function get_billfile($date=NULL)
@ -841,26 +919,34 @@ class AlipayTradeService extends CI_Controller
public function download_billfile($date=NULL)
{
ignore_user_abort(true);
bcscale(2);
$request = new AlipayDataDataserviceBillDownloadurlQueryRequest();
$date = $date===NULL ? date("Y-m-d", strtotime("-1 day")) : $date;
$request->setBizContent("{" .
"\"bill_type\":\"signcustomer\"," .
"\"bill_date\":\"$date\"" .
"}");
$response = $this->aopclientRequestExecute ($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $response->$responseNode->code;
if(empty($resultCode) || strval($resultCode) !== "10000"){
return false;
}
set_time_limit(0);
$file = file_get_contents($response->$responseNode->bill_download_url);
$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);
if (file_exists($file_name)) {
// 已经下载, 直接读取
} else {
$request->setBizContent("{" .
"\"bill_type\":\"signcustomer\"," .
"\"bill_date\":\"$date\"" .
"}");
$response = $this->aopclientRequestExecute ($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $response->$responseNode->code;
if(empty($resultCode) || strval($resultCode) !== "10000"){
return false;
}
set_time_limit(0);
$file = file_get_contents($response->$responseNode->bill_download_url);
$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 +956,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 +977,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 +986,18 @@ 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;
}
if (strpos($row['remark'], '基金申购') !== false) {
continue;
}
$total_amount = floatval($row['income'])>0 ? $row['income'] : $row['expenditure'];
@ -915,6 +1009,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 +1031,37 @@ 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_result' => isset($row['biz_type']) ? strval($row['biz_type']) : $row['trade_type'],
'event' => 'BILL',
'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;
}
$to_online_arr = array_unique_by_key($to_online_arr, 'transaction_id');
foreach ($to_online_arr as $key => $item) {
$this->online_note->add_note_alipay($item, true);
}
return;
}
@ -995,7 +1121,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 +1129,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;
@ -1263,6 +1389,184 @@ class AlipayTradeService extends CI_Controller
);
}
/**
* 退款API *****************************************************************************************************
* ************************************************************************************************************
*/
function call_refund($builder){
$biz_content=$builder->getBizContent();
$request = new AlipayTradeRefundRequest();
$request->setBizContent ( $biz_content );
$response = $this->aopclientRequestExecute ($request);
// var_dump($response);
$response = $response->alipay_trade_refund_response;
// log_message('error','test:rrr2 ' . __CLASS__ . PHP_EOL . var_export($response, 1));
return $response;
}
public function Refund()
{
$this->set_merchant('cht');
$refund_payload = $this->input->post();
$res = array(
"errcode" => "0",
"errmsg" => "",
"result" => new stdClass(),
);
$refundRequestId = $refund_payload['refund_id'];
$dealId = $refund_payload['res_id'];
$orderId = '';
// $originRow = $this->Alipay_note_model->note($dealId);
$originRows = [];
if (!empty($dealId)) {
$originRows = $this->online_note->get_note_where(['OPN_transactionId' => ['=', $dealId]]);
}
if (empty($originRows)) {
$orderId = $refund_payload['order_id'];
$orderId = trim($orderId);
$originRows = $this->online_note->get_note_where([
'OPN_rawOrderId' => ['=', $orderId],
'OPN_noticeType' => ['=', 'pay'],
'OPN_accountMethod' => ['=', 15015],
]);
}
if (empty($originRows) || count($originRows) > 1) {
$res['errcode'] = '1';
$res['errmsg'] = empty($originRows) ? '没有找到该笔交易' : '无法匹配交易';
return $this->output->set_content_type('application/json')->set_output(json_encode($res)); // test
}
$originRow = $originRows[0];
$dealId = $originRow->OPN_transactionId;
$dealAccount = $originRow->OPN_fundSource;
$paymentOrder = $originRow->OPN_rawOrderId;
$this->set_merchant($dealAccount ? $dealAccount : 'cht');
// * refund_amount 退款金额
$this->AlipayTradeRefundContentBuilder->setRefundAmount($refund_payload['amount']);
// * out_trade_no trade_no 二选一 传入. 优先取值trade_no
// - out_trade_no 订单支付时传入的商户订单号
// - trade_no 支付宝交易号
$this->AlipayTradeRefundContentBuilder->setTradeNo($dealId);
if ($paymentOrder) {
$this->AlipayTradeRefundContentBuilder->setOutTradeNo($paymentOrder);
}
// refund_reason len 256
$this->AlipayTradeRefundContentBuilder->setRefundReason($refund_payload['reason']);
// * out_request_no 退款请求号。 标识一次退款请求 *refund_id*
$generateId = $refundRequestId ? $refundRequestId : str_replace('-', '', getGuid());
$this->AlipayTradeRefundContentBuilder->setOutRequestNo($generateId);
// [-] query_options 同步需要额外返回的信息字段 ["refund_detail_item_list"]
// var_dump($this->AlipayTradeRefundContentBuilder);
$response = $this->call_refund($this->AlipayTradeRefundContentBuilder);
$refund_res = $response;
$refund_res->id = $generateId;
$refund_res->custom_id = $refund_payload['custom_id'];
$refund_res->trade_no = $dealId;
$refund_res->out_trade_no = $paymentOrder;
$refund_res->merchant_account = $dealAccount ? $dealAccount : 'cht';
// $ret_status_mapped = array(
// "Y" => "1", // COMPLETED
// "N" => "3", // FAILED
// // "PENDING" => "4", // todo:
// // "CANCELLED" => "2", // todo:
// );
// $refund_res->status = $response->code === '10000' ? '1' : '3';
$refund_status = $response->code === '10000' && $response->fund_change === 'Y' ? '1' : $response->code === '10000' ? '4' : '3';
$refund_res->refund_payload = $refund_payload;
// log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . ' ' . PHP_EOL . var_export($response, 1));
// var_dump($response);
$res['errcode'] = $response->code === '10000' ? '0' : '1';
// query result
// var_dump($generateId, $dealId, $paymentOrder);
$query_res = $this->query_refund($generateId, $dealId, $paymentOrder);
$refund_res->query_refund_result = $query_res;
$query_refund_status = isset($query_res->refund_status) && $query_res->refund_status === 'REFUND_SUCCESS' ? '1' : '3';
$refund_res->status = $query_refund_status === '1' ? $query_refund_status : $refund_status;
$res['result'] = $refund_res;
if ($refund_status !== '3') {
// if ($query_refund_status === '1') {
$this->Alipay_note_model->save_alipay(
strval($generateId) // $ALI_dealId,
,strval($paymentOrder) // $ALI_orderId,
,"CNY" // $ALI_currencyCode,
,"-" . strval($query_res->refund_amount) // $ALI_orderAmount,
,NULL // $ALI_payAmount,
,NULL // $ALI_stateCode,
,date('Y-m-d H:i:s') // $ALI_acquiringTime,
,date('Y-m-d H:i:s') // $ALI_completeTime,
,json_encode($refund_res, JSON_UNESCAPED_UNICODE) // $ALI_memo,
,'refund' // $ALI_payType,
,NULL // $ALI_resultCode=null,
,$query_refund_status === '1' ? 'TRADE_SUCCESS' : 'pending' // $ALI_resultMsg=null,
,NULL // $ALI_payerName=null,
,$refund_res->buyer_logon_id // $ALI_payerEmail=NULL,
// $check_exists=false
);
// } else {
// }
}
return $this->output->set_content_type('application/json')->set_output(json_encode($res));
}
/**
* private
* 异步查询退款结果
* * 更新交易记录的状态
* * 更新财务系统状态
*/
private function query_refund_result($item)
{
$ready_to_financesystem = new stdClass();
// if (empty($item)) { // debug:
// $item = new stdClass();
// $item->ALI_resultMsg = '';
// $item->ALI_dealId = '-1';
// $item->ALI_memo = json_encode(array(
// "id" => "2F179741CB174200G-qqs",
// "custom_id" => "75",
// "trade_no" => "-1",
// "out_trade_no" => "-1",
// "merchant_account" => "cht",
// "status" => "4",
// ), JSON_UNESCAPED_UNICODE);
// }
$raw = json_decode($item->ALI_memo);
$merchant_account = $raw->merchant_account;
$this->set_merchant($merchant_account);
$request_no = $raw->id;
$trade_no = $raw->trade_no;
$order_id = $raw->out_trade_no;
$query_res = $this->query_refund($request_no, $trade_no, $order_id);
$trade_status = isset($query_res->refund_status) && $query_res->refund_status === 'REFUND_SUCCESS' ? 'TRADE_SUCCESS' : $item->ALI_resultMsg;
$query_refund_status = isset($query_res->refund_status) && $query_res->refund_status === 'REFUND_SUCCESS' ? '1' : '3';
$note_status = $query_refund_status === '1' ? '' : 'sendfail';
$ready_to_financesystem = $query_res;
$ready_to_financesystem->status = $query_res->code === '10000' ? $query_refund_status : $raw->status;
$ready_to_financesystem->id = $request_no;
$ready_to_financesystem->custom_id = $raw->custom_id;
$this->Alipay_note_model->update_note(['ALI_dealId' => $request_no], ['ALI_resultMsg' => $trade_status]);
$this->Alipay_note_model->update_send($item->ALI_dealId, $note_status);
call_api('https://p9axztuwd7x8a7.mycht.cn/Service_BaseInfoWeb/alipayrefund_status_set', $ready_to_financesystem, 'POST');
// call_api('http://202.103.68.144:890/Service_BaseInfoWeb/alipayrefund_status_set', $ready_to_financesystem, 'POST');
return;
}
}

@ -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,9 @@ 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 ? '15016,15035' : $method; // explode(',', $method);
$data['method_code'] = $method ? $method : '';
$method = $method==='all' ? null : $method; // explode(',', $method);
// $data["paytext"] = $this->payment_status();
if (isset($this->code_brandname[$method])) {
$data['method_code'] = $method;
@ -49,11 +51,17 @@ class PaymentService extends CI_Controller {
if (!empty($data['keywords'])) {
$data['notelist'] = $this->note_model->search_key($data['keywords']);
} else {
// log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . ' ------' . PHP_EOL . var_export(1, 1));
$search_date = $this->note_model->search_date($data['date'], $method);
$unsend = $this->note_model->unsend_note(false, $method);
$sendfail = $this->note_model->sendfail_note(false, $method);
$pengding = [];
// $this->note_model->get_note_where([
// 'OPN_transactionResult' => ['=', 'pending'],
// 'OPN_noticeSendStatus' => ['!=', 'closed'],
// ], 200);
$closed = $this->note_model->closed_note($data['date'], 300, $method);
$data['notelist'] = array_merge(array_merge($unsend, $sendfail), array_merge($search_date, $closed));
$data['notelist'] = array_merge(array_merge($unsend, $sendfail, $pengding), array_merge($search_date, $closed));
}
array_walk($data["notelist"], 'PaymentService::set_brandname');
@ -85,7 +93,7 @@ class PaymentService extends CI_Controller {
"wx5d01021a6d515098" => "HLY", // "花梨鹰小程序", // 交行收款码
"wxd6c8dd69af5128cd" => "", // "NATIVE",
"wx7e605820faf98a05" => "Trippest-NATIVE",
"0" => "unknown",
"0" => "",
);
public function set_brandname(&$ele)
{
@ -99,7 +107,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];
}
}
@ -130,8 +138,14 @@ class PaymentService extends CI_Controller {
if (empty($data['unsend_list'])) {
$data['unsend_list'] = $this->note_model->sendfail_note(20);
}
// var_dump($data['unsend_list']);
// die;
// 开始处理
foreach ($data['unsend_list'] as $key => $item) {
if ($item->OPN_accountMethod === 15002) {
$this->paypal_flow($item);
continue;
}
// 只处理完成状态
if (mb_strtolower($item->OPN_transactionResult) !== 'completed') {
continue;
@ -168,6 +182,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 : '';
$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 +221,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 +235,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 +256,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 +273,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 +299,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 +365,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 +381,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
@ -416,6 +442,105 @@ class PaymentService extends CI_Controller {
return;
}
protected function paypal_flow($item)
{
// $calc_paypal_rate =
// 更新 付款方式, payer
$memo = json_decode($item->OPN_rawContent);
$paypal_order = '';
if ($item->OPN_noticeType == 'pay') {
$paypal_order = isset($memo->resource->supplementary_data) ?$memo->resource->supplementary_data->related_ids->order_id : (isset($memo->resource->application_context) ? $memo->resource->application_context->related_qualifiers[0]->id : '');
}
$paypal_account = $item->OPN_fundSource ? $item->OPN_fundSource : 'cht';
$paypal_account = $paypal_account==='Highlights' ? 'htravel' : $paypal_account;
// log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . ' ' . PHP_EOL . var_export($paypal_order, 1));
// log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . ' ' . PHP_EOL . var_export($paypal_account, 1));
// log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . ' ' . PHP_EOL . var_export($item->OPN_noticeType, 1));
if (!empty($paypal_order) && !empty($paypal_account)
&& $item->OPN_noticeType == 'pay'
// && substr($item->OPN_noticeSendStatus, 0, 4) !== 'send'
&& $item->OPN_noticeSendStatus == ''
) {
$payment_ret = $this->get_paypal_order($paypal_order, $paypal_account);
if (!empty($payment_ret)) {
$where_str = " OPN_SN=" . $item->OPN_SN;
$update_note_column = array(
'OPN_paymentSource' => $payment_ret->payment_source_type,
'OPN_remark' => $payment_ret->description,
'OPN_payerLogId' => isset($payment_ret->payer->payer_id) ? $payment_ret->payer->payer_id : '',
'OPN_payerName' => isset($payment_ret->payer->fullname) ? $payment_ret->payer->fullname : '',
'OPN_payerEmail' => isset($payment_ret->payer->email_address) ? $payment_ret->payer->email_address : '',
'OPN_payerStatus' => isset($payment_ret->payer->account_status) ? $payment_ret->payer->account_status : '',
'OPN_subject' => isset($payment_ret->item_number) && empty($item->subject) ? $payment_ret->item_number : $item->subject,
'OPN_noticeSendStatus' => $item->OPN_transactionResult!=='pending' ? 'closed' : 'sendfail', // 先忽略
);
$this->note_model->update_note($where_str, $update_note_column);
return false;
}
}
// todo: 退款记录
$where_str = " OPN_SN=" . $item->OPN_SN;
$update_note_column = array(
'OPN_noticeSendStatus' => 'closed', // 先忽略
);
$this->note_model->update_note($where_str, $update_note_column);
return false;
}
protected function get_paypal_order($paypal_order, $paypal_account)
{
$type = '';
$description = '';
$item_number = '';
$payer = new stdClass();
// 获取paypal订单信息 从数据库记录的授权事件
$paypal_order_rows = $this->note_model->get_note_where([
'OPN_transactionId' => ['=', $paypal_order],
'OPN_noticeType' => ['=', 'paypal.order'],
'OPN_accountMethod' => ['=', 15002],
]);
if (empty($paypal_order_rows)) {
// 获取paypal订单信息 从API
$url = "https://secure.chinahighlights.com/pay/paypalservice/get_v2/order/$paypal_order/$paypal_account";
$order_str = get_url_contents($url);
// log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . ' ' . PHP_EOL . var_export($order_str, 1));
$order = json_decode($order_str, true);
if ( ! isset($order['payment_source'])) {
return null;
}
$payment_source = $order['payment_source'];
$type = array_keys($payment_source)[0];
$purchase_units = $order['purchase_units'];
$description = isset($purchase_units[0]['description']) ? $purchase_units[0]['description'] : (isset($purchase_units[0]['items']) ? $purchase_units[0]['items'][0]['name'] : '');
$item_number = !isset($purchase_units[0]['invoice_id']) ? $description : '';
if (isset($order['payer'])) {
$payer = (object) $order['payer'];
$payer->fullname = $payer->name['given_name'] . ' ' . $payer->name['surname'];
} else {
$payer->fullname = $payment_source[$type]['name'];
}
} else {
$type = $paypal_order_rows[0]->OPN_paymentSource;
$description = $paypal_order_rows[0]->OPN_remark;
$item_number = $paypal_order_rows[0]->OPN_subject;
$payer->fullname = $paypal_order_rows[0]->OPN_payerName;
$payer->payer_id = $paypal_order_rows[0]->OPN_payerLogId;
$payer->email_address = $paypal_order_rows[0]->OPN_payerEmail;
$payer->account_status = $paypal_order_rows[0]->OPN_payerStatus;
}
$ret = new stdClass();
// $ret->payment_source = $payment_source;
$ret->payment_source_type = $type;
$ret->description = $description;
$ret->payer = $payer;
$ret->item_number = $item_number;
return $ret;
}
/** 支付方式参数对应的配置文件名 */
/** @Deprecated */
public function method_name($name)
@ -493,6 +618,7 @@ class PaymentService extends CI_Controller {
$pn_invoice = $data['note']->OPN_orderId ? $data['note']->OPN_orderId : $data['note']->OPN_rawOrderId;
$pn_txn_id = $data['note']->OPN_transactionId;
$orderid_info = analysis_orderid($pn_invoice);
$data['old_order'] = $pn_invoice;
if (!empty($orderid_info)) {
$orderid_info = json_decode($orderid_info);
$data['order_info'] = $this->account_model->get_order($orderid_info->orderid, true, $orderid_info->ordertype, true);
@ -503,8 +629,9 @@ class PaymentService extends CI_Controller {
) {
$data['gai_info'] = $this->account_model->get_money_b($pn_txn_id);
}
} else {
$data['gai_info'] = $this->account_model->get_group_info_by_transactionid($pn_txn_id);
}
$data['old_order'] = $pn_invoice;
$data['new_order'] = $neworder;
if ($neworder !== null ) {
$neworder_id = analysis_orderid($neworder);
@ -516,7 +643,11 @@ class PaymentService extends CI_Controller {
$order_sn = empty($data['order_info']) ? 0 : $data['order_info']->COLI_SN;
$data['group_accout_info'] =
$this->account_model->get_group_accout_info($order_sn, $pn_txn_id);
echo json_encode($this->load->view('payment_gai_setting', $data, true));
// var_dump($data);
$this->output
->set_content_type('application/json')
->set_output(json_encode($this->load->view('payment_gai_setting', $data, true)));
// echo json_encode($this->load->view('payment_gai_setting', $data, true), );
}
public function gai_modal_save()
@ -529,6 +660,9 @@ class PaymentService extends CI_Controller {
$note = $this->note_model->get_note($pn_id);
$data['note'] = $note[0];
if ($data['note']->OPN_accountMethod !== 15016) {
return;
}
$orderid_info = analysis_orderid($data['note']->OPN_orderId);
if (!empty($orderid_info)) {
$orderid_info = json_decode($orderid_info);
@ -536,7 +670,7 @@ class PaymentService extends CI_Controller {
$data['gai_info'] = $this->account_model->get_money_t($pn_txn_id);
if ( ! empty($data['gai_info'])) {
$old_ssje = $data['gai_info'][0]->GAI_SSJE;
$this->account_model->delete_money_t($pn_txn_id);
$this->account_model->delete_money_t($pn_txn_id, $data['gai_info'][0]->GAI_SN);
}
} elseif ($orderid_info->ordertype === 'B' || $orderid_info->ordertype === 'TP'
|| $orderid_info->ordertype === 'A'
@ -544,7 +678,7 @@ class PaymentService extends CI_Controller {
$data['gai_info'] = $this->account_model->get_money_b($pn_txn_id);
if ( ! empty($data['gai_info'])) {
$old_ssje = $data['gai_info'][0]->GAI_SSJE;
$this->account_model->delete_money_b($pn_txn_id);
$this->account_model->delete_money_b($pn_txn_id, $data['gai_info'][0]->GAI_SN);
}
}
}
@ -664,6 +798,116 @@ class PaymentService extends CI_Controller {
return false;
}
/**
* 检查PayPal是否达到最低汇率的额度
* * 达到120万美元, 发邮件提醒
* 15号之后开始检查
* 换美元汇率: https://www.chinahighlights.com/api/cht/currency/getCurrencydata.php
**/
public function check_paypal_limit($notify = '1')
{
$this->load->helper('file');
if (date('d') < '15' && $notify == '1') {
return false;
}
$this_month = date('Y-m-02');
$today = date('Y-m-d');
$next_month = date('Y-m-15', strtotime('+1 month', strtotime($this_month)));
$cache_file = md5('next_check_paypal_limit_date');
$filename = APPPATH . 'cache/' . $cache_file . '.txt';
if (!is_dir(APPPATH . 'cache/')) {
mkdir(APPPATH . 'cache/', 0755, TRUE);
}
$read_next_check = read_file($filename);
if ($today < $read_next_check && $notify == '1') {
echo 'Next Check Date: ' . $read_next_check . '<br>';
return false;
}
// 从前端取 外币换美元的汇率
$currency_rate_url = 'https://www.chinahighlights.com/api/cht/currency/getCurrencydata.php';
$all_rate_str = get_url_contents($currency_rate_url);
$all_rate = json_decode($all_rate_str, true);
$to_usd_rate = array_values(array_filter($all_rate['data'], function ($item) {
return $item['currency'] && $item['to'] == 'USD';
}));
$year = date('Y', time());
$month = date('m', time());
$start = date('Y-m-d', strtotime("{$year}-{$month}-02"));
$end = date('Y-m-d', strtotime('+1 month', strtotime($start)));
// ? PayPal使用太平洋时间? GMT时间?
// * 从本月2 号开始, 到下个月2号.
$summary = $this->account_model->query_paypal_note_summary($start, $end, $to_usd_rate);
$if_got_line = $summary[0]['running_total'] > 120*10000;
$current_total = number_format(bcdiv($summary[0]['running_total'], (1*10000)), 2);
if ( ! $if_got_line) {
echo '<p>当前总额: ' . $current_total . ' 万 USD</p>';
return false;
}
write_file($filename, $next_month);
// 达到了 120 万美元, 就发邮件, 提醒切换渠道
$time_set = date('Y-m-d_H_i_s');
if ($notify === '1') {
$fromName = 'PayPal 额度提醒';
$fromEmail = 'lyt@hainatravel.com';
$toName = 'LOT, fgy'; // 'fgy';
$toEmail = 'lyt@hainatravel.com, fgy@hainatravel.com'; // 'fgy@hainatravel.com';
$subject = $fromName;
$body = "PayPal收款额度已达, 可切换信用卡渠道. <br>当前总额: {$current_total} 万 USD<br/>------------<br/>支付系统自动发送<br>". date("Y-m-d H:i"). " <br>";
$M_AddTime = $time_set;
$M_State = 0;
$this->account_model->save_automail($fromName, $fromEmail, $toName, $toEmail, $subject, $body, 0, $M_State, $M_AddTime, $fromName, $fromName);
}
echo $toEmail.'<br>';
echo $body;
return false;
}
/**
* 检查PayPal的费率
*
**/
public function check_paypal_rate($notify = '1')
{
if (date('d') !== '02') {
echo '不是2号不检查';
return false;
}
$list = $this->note_model->query_paypal_current_rate();
$has_gt_rate = array_some($list, function($ele) { return $ele['OPN_paymentSource'] === 'paypal' ? $ele['calc_rate'] > 0.032 : false; });
// if (!$has_gt_rate) {
// return false;
// }
$BCDC_I = array_search('paypal', array_column($list, 'OPN_paymentSource'));
$current_BCDC = $list[$BCDC_I]['calc_rate']*100;
$ACDC = array_values(array_filter($list, function($ele) { return $ele['OPN_paymentSource'] !== 'paypal'; }));
$current_ACDC = isset($ACDC[0]) ? $ACDC[0]['calc_rate']*100 : '';
// BCDC 钱包渠道大于 3.2%
$time_set = date('Y-m-d_H_i_s');
$today = date('Y-m-d');
if ($notify === '1') {
$fromName = 'PayPal 费率提醒';
$fromEmail = 'lyt@hainatravel.com';
$toName = 'LOT, fgy'; // 'fgy';
$toEmail = 'lyt@hainatravel.com, fgy@hainatravel.com'; // 'fgy@hainatravel.com';
$subject = $fromName;
$feeTable = "<table><tr><th>账户</th><th>支付方式</th><th>费率</th></tr>";
foreach ($list as $key => $row) {
$feeTable .= "<tr><td>{$row['OPN_fundSource']}</td><td>{$row['OPN_paymentSource']}</td><td>{$row['calc_rate']}</td></tr>";
}
$feeTable .= "</table>";
$body = "本月费率: {$today}<br/>{$feeTable}------------<br/>支付系统自动发送<br>". date("Y-m-d H:i"). " <br>";
// PayPal费率高于3.2%,请及时处理. <br>
// PayPal钱包渠道: {$current_BCDC}%<br/>PayPal ACDC渠道(GooglePay, ApplePay, 信用卡收单): {$current_ACDC}%<br/>
$M_AddTime = $time_set;
$M_State = 0;
$this->account_model->save_automail($fromName, $fromEmail, $toName, $toEmail, $subject, $body, 0, $M_State, $M_AddTime, $fromName, $fromName);
}
echo $toEmail.'<br>';
echo $body;
return false;
}
public function ipalinks_settlement($year, $month, $day="01")
{
set_time_limit(0);
@ -884,5 +1128,32 @@ class PaymentService extends CI_Controller {
return;
}
/**
* 查询:交易/退款
*
* 从渠道接口查询
*
* @param Type $var Description
* @return type
* @throws conditon
**/
public function query()
{
$transaction_id = $this->input->get_post("transaction_id");
$account_type = $this->input->get_post("account_type");
if ($account_type == '15016') {
$this->wxpay_call->query_append_transaction($transaction_id);
}
redirect(site_url("/apps/pay/paymentservice/note_list?keywords=$transaction_id"));
exit;
// $data['notelist'] = $this->note_model->search_key($transaction_id);
// $data['method_code'] = '';
// $data["method_name"] = '';
// array_walk($data["notelist"], 'PaymentService::set_brandname');
// $this->load->view("payment_list",$data);
// return ;
}
}

@ -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,18 +54,18 @@ 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'] = ''; // isset($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'];
$save_column['OPN_transactionResult'] = 'completed';
$save_column['OPN_resultCode'] = $xml_arr['result_code'];
$save_column['OPN_resultMsg'] = isset($xml_arr['return_msg']) ? $xml_arr['return_msg'] : $xml_arr['result_code'];
$save_column['OPN_resultMsg'] = isset($xml_arr['trade_type']) ? $xml_arr['trade_type'] : $xml_arr['result_code'];
$save_column['OPN_errCode'] = isset($xml_arr['err_code']) ? $xml_arr['err_code'] : NULL;
$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'] = ''; // isset($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,15 +93,23 @@ 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日账单
// async_curl('https://www.mycht.cn/download_statement/download_files.php', 30); // iPaylinks日账单
// 检查PayPal的额度
async_curl('https://www.mycht.cn/webht.php/apps/pay/paymentservice/check_paypal_limit');
/**
* 每月20号发送退款给财务
*/
if (date('d')==='20') {
async_curl('https://www.mycht.cn/webht.php/apps/pay/paymentservice/refund_finance_notify');
}
/**
* 每月2号: 检查PayPal的费率
*/
if (date('d')==='02') {
async_curl('https://www.mycht.cn/webht.php/apps/pay/paymentservice/check_paypal_rate');
}
return;
}
@ -117,37 +126,49 @@ class WxpayService extends CI_Controller {
$this->query_builder->set_bill_type($bill_type);
$this->load->library('Wxpay_call');
$result = $this->wxpay_call->get_bill_data($this->query_builder);
$fund_result = $this->wxpay_call->get_fund_bill_data($this->query_builder);
if ($result['status'] !== true) {
log_message('error',"get wxpay bill failed. $target_account $bill_date");
}
foreach ($result['data'] as $key => $row) {
$all_bill = array_merge($result['data'], $fund_result['data']);
foreach ($all_bill as $key => $row) {
$save_column = array();
$save_column['OPN_accountMethod'] = $this->config->item('method_code', 'wxpay');
if ($row['refund_id'] != '0') {
if (isset($row['refund_id']) && $row['refund_id'] != '0') {
// 退款
$ssje = $this->account_model->get_ssje($row['settlement_refund_fee'], str_replace("CNY", "RMB", strtoupper($row['currency_type'])), $save_column['OPN_accountMethod']);
$save_column['OPN_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);
$save_column['OPN_resultMsg'] = $row['trade_type'];
$ssje = $this->account_model->get_ssje_exclude_fee($save_column['OPN_netAmount'], str_replace("CNY", "RMB", strtoupper($row['currency_type'])));
$save_column['OPN_entryAmountCNY'] = floatval($ssje); // $save_column['OPN_netAmount'];
$save_column['OPN_noticeType'] = 'refund';
$save_column['OPN_relatedId'] = $row['transaction_id'];
$save_column['OPN_relatedId'] = isset($row['fund_transaction_id']) ? $row['fund_transaction_id'] : $row['transaction_id'];
$save_column['OPN_transactionResult'] = $row['refund_status'] === 'SUCCESS' ? 'completed' : strtolower($row['refund_status']);
} 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'];
$save_column['OPN_resultCode'] = $row['trade_state'];
$save_column['OPN_resultMsg'] = $row['trade_state'];
$save_column['OPN_resultMsg'] = $row['trade_type'];
$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_transactionResult'] = 'completed';
}
$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'];
@ -155,17 +176,69 @@ class WxpayService extends CI_Controller {
$save_column['OPN_currency'] = $row['currency_type'];
$save_column['OPN_acquiringTime'] = date('Y-m-d H:i:s',strtotime($row['complete_time']));
$save_column['OPN_completeTime'] = date('Y-m-d H:i:s',strtotime($row['complete_time']));
$save_column['OPN_remark'] = $row['attach'];
$save_column['OPN_remark'] = ''; // $row['attach'];
$save_column['OPN_payerLogId'] = $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->note_model->insert_note($save_column) ;
// var_dump($save_column);
$this->note_model->insert_note($save_column, true);
}
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;
}
public function refund() {
$this->load->model('WxpayRefundContentBuilder', 'refund_builder');
$refund_payload = $this->input->post();
$res = array(
"errcode" => "0",
"errmsg" => "",
"result" => "{}",
);
$transaction_id = '';
$this->query_builder->set_transaction_id($transaction_id);
}
public function response_to_wx($response_arr)
{
$response_body = to_xml($response_arr);

@ -316,3 +316,328 @@ 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;
}
function get_url_contents($url)
{
if (ini_get("allow_url_fopen") == "1")
{
return file_get_contents($url);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
/**
* 发一个异步的请求
* @param string $url
* @param mixed $data
* @param array $headers
*/
function async_post_json($url, $data = '', $headers = []) {
$parts = parse_url($url);
$host = $parts['host'];
$path = isset($parts['path']) ? $parts['path'] : '/';
$port = isset($parts['port']) ? $parts['port'] : 80;
$scheme = isset($parts['scheme']) ? $parts['scheme'] : 'http';
$query = isset($parts['query']) ? '?' . $parts['query'] : '';
// $post_string = http_build_query($data);
$post_string = json_encode($data);
$request_headers = [
"POST $path$query HTTP/1.1",
"Host: $host",
"Content-Type: application/json",
"Content-Length: " . strlen($post_string),
"Connection: close",
];
foreach ($headers as $header) {
$request_headers[] = $header;
}
$request_headers[] = ""; // Add a blank line to separate headers from body
$request = implode("\r\n", $request_headers) . "\r\n" . $post_string;
if ($scheme === 'https') {
$port = 443;
$host = 'ssl://' . $host;
}
$fp = fsockopen($host, $port, $errno, $errstr, 1);
log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . ' open' . PHP_EOL . var_export($request, 1));
if (!$fp) {
log_message('error', "Webhook failed: $errstr ($errno)");
return false;
} else {
fwrite($fp, $request);
fclose($fp);
return true;
}
}
/**
* 发一个异步的请求 Get
* @param string $url
* @param mixed $query_params
* @param array $headers
*/
function async_get($url, $query_params = [], $headers = []) {
$parts = parse_url($url);
$host = $parts['host'];
$path = isset($parts['path']) ? $parts['path'] : '/';
$port = isset($parts['port']) ? $parts['port'] : 80;
$scheme = isset($parts['scheme']) ? $parts['scheme'] : 'http';
$base_query = isset($parts['query']) ? $parts['query'] : '';
$query_string = '';
if (!empty($query_params)) {
$query_string = http_build_query($query_params);
if (!empty($base_query)) {
$query_string = $base_query . '&' . $query_string;
}
} else {
$query_string = $base_query;
}
$full_url = $path;
if (!empty($query_string)) {
$full_url .= '?' . $query_string;
}
$request_headers = [
"GET $full_url HTTP/1.1",
"Host: $host",
"Connection: close",
];
foreach ($headers as $header) {
$request_headers[] = $header;
}
$request_headers[] = "";
$request = implode("\r\n", $request_headers);
if ($scheme === 'https') {
$port = 443;
$host = 'ssl://' . $host;
}
$fp = fsockopen($host, $port, $errno, $errstr, 1);
log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . ' open' . PHP_EOL . var_export($request, 1));
if (!$fp) {
// error_log("Webhook failed: $errstr ($errno)");
log_message('error', "Webhook failed: $errstr ($errno)");
return false;
} else {
fwrite($fp, $request);
fclose($fp);
return true;
}
}
function array_some($array, $condition) {
foreach ($array as $element) {
if ($condition($element)) {
return true;
}
}
return false;
}
function array_unique_by_key($array, $key, $keepMissingKey = false) {
$unique = [];
$seenValues = [];
foreach ($array as $item) {
if (is_array($item) && isset($item[$key])) {
$value = $item[$key];
if (!in_array($value, $seenValues)) {
$seenValues[] = $value;
$unique[] = $item;
}
} elseif ($keepMissingKey) {
$unique[] = $item;
}
}
return $unique;
}
/**
* 连连支付
* @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 连连支付
*/
/**
* Returns a string representation of a version 4 GUID, which uses random
* numbers.There are 6 reserved bits, and the GUIDs have this format:
* xxxxxxxx-xxxx-4xxx-[8|9|a|b]xxx-xxxxxxxxxxxx
* where 'x' is a hexadecimal digit, 0-9a-f.
*
* See http://tools.ietf.org/html/rfc4122 for more information.
*
* Note: This function is available on all platforms, while the
* com_create_guid() is only available for Windows.
*
* @return string A new GUID.
*/
function getGuid()
{
// @codingStandardsIgnoreStart
return sprintf(
'%04x%04x-%04x-%04x-%02x%02x-%04x%04x%04x',
mt_rand(0, 65535),
mt_rand(0, 65535), // 32 bits for "time_low"
mt_rand(0, 65535), // 16 bits for "time_mid"
mt_rand(0, 4096) + 16384, // 16 bits for "time_hi_and_version", with
// the most significant 4 bits being 0100
// to indicate randomly generated version
mt_rand(0, 64) + 128, // 8 bits for "clock_seq_hi", with
// the most significant 2 bits being 10,
// required by version 4 GUIDs.
mt_rand(0, 256), // 8 bits for "clock_seq_low"
mt_rand(0, 65535), // 16 bits for "node 0" and "node 1"
mt_rand(0, 65535), // 16 bits for "node 2" and "node 3"
mt_rand(0, 65535) // 16 bits for "node 4" and "node 5"
);
// @codingStandardsIgnoreEnd
}
function call_api($url, $body = false, $method = 'GET')
{
$header = array(
"Content-Type:application/json",
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_SSLVERSION, 6);
// CURL_SSLVERSION_TLSv1_2 Available since PHP 5.5.19 and 5.6.3
$param_str = "";
// $param_str = $this->toJSON($body);
$param_str = to_json($body);
if ($method == 'POST')
curl_setopt($ch, CURLOPT_POST, true);
// if (is_array($body) && 0 < count($body)) {
if ((is_array($body) && !empty($body)) || (is_object($body) && get_class($body) === 'stdClass' && !empty((array) $body))) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $param_str);
}
$reponse = curl_exec($ch);
$reponse_obj = json_decode($reponse);
if (curl_errno($ch)) {
log_message('error', "curl REST API error code: " . curl_error($ch) . "; $method: ".$param_str);
} else {
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (200 !== $httpStatusCode) {
log_message('error', "curl REST API Request http Status Code: ".$httpStatusCode);
if (is_object($reponse_obj)) {
$reponse_obj->httpStatusCode = $httpStatusCode;
}
}
}
curl_close($ch);
return ($reponse_obj);
// return json_decode($reponse);
}

@ -7,22 +7,108 @@ class Wxpay_call
protected $ci;
private $api_info_arr = array();
private $merchant_account = '';
private $wx_site_config = array();
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->ci->load->model('WxpayQueryContentBuilder', 'query_builder');
$this->merchant_account = $account;
bcscale(2);
}
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'];
}
function query_append_transaction($transaction_id) {
$ret = [];
$all_account = explode(",", $this->ci->config->item('all_account', 'wxpay'));
$this->merchant_account = $all_account[0];
$this->ci->query_builder->set_transaction_id($transaction_id);
// var_dump($transaction_id);
// var_dump($all_account);
foreach ($all_account as $account) {
$resultR = $this->query_order_refund($this->ci->query_builder, 0, $account);
$result = $this->query_order_refund($this->ci->query_builder, 1, $account);
// var_dump(json_encode($result));
// var_dump(json_encode($resultR));
if ($result['status'] === true) {
$ret = array_merge($ret, $result['data']);
$this->ci->note_model->add_note_wxpay($result['data'], $account, 'pay');
}
if ($resultR['status'] === true) {
$ret = array_merge($ret, $result['data']);
$this->ci->note_model->add_note_wxpay($resultR['data'], $account, 'refund');
}
if (!empty($ret)) {
break;
}
}
// var_dump($ret);
return $ret;
}
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 Exception("查询接口中,缺少必填参数 transaction_id ", 1);
// 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));
// var_dump('api', 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);
// var_dump($response_arr);
$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;
}
/**
@ -42,7 +128,7 @@ class Wxpay_call
$query_content_input = $query_content->getBizContent(true);
//检测必填参数
if(!$query_content_input['bill_date']) {
throw new WxPayException("对账单接口中缺少必填参数bill_date");
throw new Exception("对账单接口中缺少必填参数bill_date");
}
$this->api_info_arr['nonce_str'] = ($this->get_nonce_str());//随机字符串
@ -74,6 +160,92 @@ class Wxpay_call
return $ret;
}
/**
* 获取资金账单数据
*/
public function get_fund_bill_data($query_content)
{
$ret = array('status'=>false, 'data'=>array());
$this->init_api();
// return false;
$url = "https://api.mch.weixin.qq.com/pay/downloadfundflow";
$query_content_input = $query_content->getBizContent(true);
//检测必填参数
if(!$query_content_input['bill_date']) {
throw new Exception("对账单接口中缺少必填参数bill_date", 1);
}
unset($query_content_input['bill_type']);
$query_content_input['account_type'] = 'Basic';
$this->api_info_arr['nonce_str'] = ($this->get_nonce_str());//随机字符串
$ready_api = array_merge($this->api_info_arr, $query_content_input);
$this->api_info_arr['sign'] = $this->make_sign($ready_api, 'HMAC-SHA256');//签名
$ready_api['sign'] = $this->api_info_arr['sign'];
$xml = to_xml($ready_api);
$response = $this->post_xml_curl($this->api_info_arr, $xml, $url, 20);
if(substr($response, 0 , 5) == "<xml>"){
log_message('error',"Wxpay fund bill error \r\n" . var_export($response, 1));
return $ret;
}
$ret['status'] = true;
$response_arr = explode("\n",$response);
// var_dump($response_arr);
// die();
$data_title = $this->fund_bill_data_title();
$data_arr = [];
for ($i=1; $i < count($response_arr)-1; $i++) {
if (empty($response_arr[$i])) {
continue;
}
$row = explode(",", $response_arr[$i]);
$row_arr = array();
foreach ($data_title as $key => $title) {
if ( ! isset($row[$key])) {
continue;
}
$row_arr[$title] = str_replace("`","",trim($row[$key]));
}
$row_arr['wxpay_fee'] = '';
!empty($row_arr['trade_direction']) ? $data_arr[] = $row_arr : false;
}
$ret_g = array_reduce($data_arr, function($carry, $item) {
$item['currency_type'] = 'CNY';
$item['trade_state'] = $item['trade_type'];
$item['trade_type'] = 'BILL';
$item['bank_type'] = $item['item_name'] = $item['attach'] = $item['openid'] = '';
if (isset($carry[$item['transaction_id']]) && !empty($carry[$item['transaction_id']])) {
$fee = $item['trade_direction'] == '支出' && stripos($item['sub_trade_type'], '手续费') !== false ? $item['settlement_total_fee'] : 0;
$net_amount = bcsub($carry[$item['transaction_id']][0]['settlement_total_fee'], $fee);
$carry[$item['transaction_id']][0]['net_amount'] = $net_amount;
$carry[$item['transaction_id']][0]['wxpay_fee'] = $fee;
$carry[$item['transaction_id']][0]['refund_id'] = '0';
} else {
if ($item['sub_trade_type'] == '退款') {
$item['net_amount'] = $item['settlement_total_fee'];
preg_match_all('/(\d+\.\d+)/', $item['remark'], $matches);
$amount = isset($matches[1][0]) ? $matches[1][0] : $item['settlement_total_fee'];
$fee = isset($matches[1][1]) ? $matches[1][1] * -1 : '';
$item['settlement_refund_fee'] = $amount;
$item['call_refund_fee'] = $amount;
$item['wxpay_fee'] = $fee;
$item['out_refund_id'] = $item['out_trade_no'];
$item['refund_id'] = $item['transaction_id'];
$item['refund_status'] = 'SUCCESS';
$item['out_trade_no'] = '';
}
$item['item_name'] = preg_match('/^[A-Z0-9]{6}-[A-Z0-9]{7}-[A-Z0-9]{4}$/', $item['out_trade_no']) ? '收钱码收款' : '';
$carry[$item['transaction_id']][] = $item;
}
return $carry;
}, []);
$ret['data'] = array_reduce(array_values($ret_g), function($carry, $item) {
$carry[] = $item[0];
return $carry;
}, []);
return $ret;
}
/*!
* @Author: LYT
* @Date: 2019-06-18 15:23:15
@ -113,6 +285,27 @@ class Wxpay_call
);
}
/**
* 资金账单数据的格式
* 记账时间,微信支付业务单号,资金流水单号,业务名称,业务类型,收支类型,收支金额(元),账户结余(元),资金变更提交申请人,备注,业务凭证号
*/
private function fund_bill_data_title()
{
return array(
"complete_time", // 记账时间
"transaction_id", // 微信支付业务单号
"fund_transaction_id", // 资金流水单号
"trade_type", // 业务名称
"sub_trade_type", // 业务类型
"trade_direction", // 收支类型
"settlement_total_fee", // 收支金额(元)
"balance", // 账户结余(元)
"handler", // 资金变更提交申请人
"remark", // 备注
"out_trade_no", // 业务凭证号, 退款是out_refund_id
);
}
/**
* 以post方式提交xml到对应的接口url
*
@ -144,6 +337,14 @@ class Wxpay_call
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,TRUE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2);//严格校验
}
if (is_dir($this->wx_site_config['cert_path'])) {
curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $this->wx_site_config['mch_id']);
curl_setopt($ch, CURLOPT_SSLCERT, $this->wx_site_config['cert_path'] . "/apiclient_cert.pem");
curl_setopt($ch, CURLOPT_SSLKEY, $this->wx_site_config['cert_path'] . "/apiclient_key.pem");
}
curl_setopt($ch,CURLOPT_USERAGENT, $ua);
//设置header
curl_setopt($ch, CURLOPT_HEADER, FALSE);
@ -189,7 +390,11 @@ class Wxpay_call
return true;
}
public function make_sign($xml_arr, $needSignType = false)
/**
* @param mixed $xml_arr
* @param string $SignType 签名方式MD5 或 HMAC-SHA256
*/
public function make_sign($xml_arr, $SignType = 'MD5')
{
//签名步骤一:按字典序排序参数
ksort($xml_arr);
@ -197,12 +402,17 @@ class Wxpay_call
//签名步骤二在string后加入KEY
$string = $string . "&key=" . $this->wx_site_config['key'];
//签名步骤三MD5加密或者HMAC-SHA256
if(!isset($xml_arr['sign']) || strlen($xml_arr['sign']) <= 32){
//如果签名小于等于32个,则使用md5验证
$string = md5($string);
} else {
//是用sha256校验
$string = hash_hmac("sha256", $string , $this->wx_site_config['key']);
switch ($SignType) {
case 'MD5':
$string = md5($string);
break;
case 'HMAC-SHA256':
$string = hash_hmac("sha256", $string, $this->wx_site_config['key']);
break;
default:
$string = md5($string);
break;
}
//签名步骤四:所有字符转为大写
$result = strtoupper($string);
@ -241,6 +451,9 @@ class Wxpay_call
return $str;
}
/**
* @deprecated
*/
protected function curl($url, $postFields = null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);

@ -28,7 +28,7 @@ class Alipay_model extends CI_Model {
if (empty($result) && ($ordertype == 'T')) {
$sql = "SELECT TOP 2 1 as order_type, COLI_SN,COLI_ID,COLI_GRI_SN,OPI_SN,OPI_Email,OPI_FirstName,OPI_Name,COLI_WebCode,COLI_State $fieldsql from ConfirmLineInfo
LEFT JOIN OperatorInfo ON COLI_OPI_ID=OPI_SN
where COLI_ID like '%$COLI_ID'";
where LTRIM(RTRIM(COLI_ID)) like '%$COLI_ID'";
$query = $this->HT->query($sql);
$result = $query->result();
}
@ -87,10 +87,10 @@ class Alipay_model extends CI_Model {
*/
public function get_group_accout_info($coli_sn, $pn_txn_id) {
// select * from BIZ_GroupAccountInfo where GAI_COLI_SN = 559007281 and GAI_AccreditNo = '91R84932UM059045C'
$info_sql = "select GAI_SN, GAI_State from BIZ_GroupAccountInfo
$info_sql = "select GAI_SN, GAI_State from BIZ_GroupAccountInfo
where GAI_COLI_SN = $coli_sn and GAI_AccreditNo = '$pn_txn_id'
union
select GAI_SN, GAI_State from GroupAccountInfo
select GAI_SN, GAI_State from GroupAccountInfo
where GAI_COLI_SN = $coli_sn and GAI_AccreditNo = '$pn_txn_id'";
$info_query = $this->HT->query($info_sql);
@ -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
(
@ -216,5 +247,11 @@ class Alipay_note_model extends CI_Model {
return $this->INFO->query($sql, array($payer,$dealId));
}
public function update_note($where, $column)
{
$update_str = $this->INFO->update_string('AlipayLog', $column, $where);
$this->INFO->query($update_str);
return TRUE;
}
}

@ -3,9 +3,43 @@ defined('BASEPATH') OR exit('No direct script access allowed');
class Online_payment_account_model extends CI_Model {
private $userdata;
private $userID;
function __construct() {
parent::__construct();
$this->HT = $this->load->database('HT', TRUE);
$this->userdata = $this->session->userdata('userdata');
$this->userID = isset($this->userdata['OPI_SN']) ? $this->userdata['OPI_SN'] : 'null';
}
public function call_sp_fun($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);
$result_object = array();
if (false !== $stmt ) { // 无权限或执行错误返回false
// 存储过程中每个select都产生结果集
// 设置了SET NOCOUNT ON;就只有输出的结果集
$a = true;
while ($a !== false) {
$row = sqlsrv_fetch_object($stmt); // Retrieves the next row of data as a PHP object.
$a = !empty($row);
$a===true ? $result_object[] = $row : null;
}
sqlsrv_free_stmt($stmt);
}
sqlsrv_close($conn);
return $result_object;
}
/*!
@ -23,6 +57,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) {
@ -109,17 +153,46 @@ class Online_payment_account_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;
}
public function get_group_info_by_transactionid($pn_txn_id) {
$info_sql = "SELECT GAI_SN, GAI_State,GAI_COLI_ID as orderId
,CAST(GAI_SQJE AS VARCHAR) GAI_SQJE,GAI_SQJECurrency
,CAST(GAI_SSJE AS VARCHAR) GAI_SSJE,GAI_Memo
,'B' AS ordertype
FROM BIZ_GroupAccountInfo
WHERE (GAI_AccreditNo = '$pn_txn_id'
OR CHARINDEX('$pn_txn_id', gai_memo) > 0)
AND BIZ_GroupAccountInfo.DeleteFlag =0
UNION
SELECT GAI_SN, GAI_State
,(
SELECT coli_id
FROM ConfirmLineInfo AS cli
WHERE cli.COLI_SN = GAI_COLI_SN
) AS orderId
,cast(GAI_SQJE as varchar) GAI_SQJE,GAI_SQJECurrency
,cast(GAI_SSJE as varchar) GAI_SSJE,GAI_Memo
,'T' AS ordertype
FROM GroupAccountInfo
WHERE (GAI_AccreditNo = '$pn_txn_id'
OR CHARINDEX('$pn_txn_id', gai_memo) > 0)
AND GroupAccountInfo.DeleteFlag =0";
$info_query = $this->HT->query($info_sql);
$info_result = $info_query->result();
return $info_result;
}
public function if_biz_gai_exists($GAI_AccreditNo, $is_app=false, $coli_sn=null, $je=null, $type=null)
{
if ($is_app===true && $coli_sn!==null) {
@ -234,21 +307,21 @@ class Online_payment_account_model extends CI_Model {
return $result;
}
/** 删除收款记录 */
public function delete_money_t($deadId)
public function delete_money_t($deadId, $gai_sn)
{
$sql = "UPDATE GroupAccountInfo SET DeleteFlag=1 WHERE GAI_AccreditNo=?";
$query = $this->HT->query($sql, array($deadId));
$sql = "UPDATE GroupAccountInfo SET DeleteFlag=1, LastEditTime=GETDATE(), GAI_Memo='删除 '+GAI_Memo WHERE GAI_AccreditNo=? and GAI_SN=?";
$query = $this->HT->query($sql, array($deadId, $gai_sn));
return $query;
}
public function delete_money_b($deadId)
public function delete_money_b($deadId, $gai_sn)
{
$sql = "UPDATE BIZ_GroupAccountInfo SET DeleteFlag=1 WHERE GAI_AccreditNo=?";
$query = $this->HT->query($sql, array($deadId));
$sql = "UPDATE BIZ_GroupAccountInfo SET DeleteFlag=1, LastEditTime=GETDATE(), GAI_Memo='删除 '+GAI_Memo WHERE GAI_AccreditNo=? and GAI_SN=?";
$query = $this->HT->query($sql, array($deadId, $gai_sn));
return $query;
}
//添加收款记录(商务订单)
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 +345,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,LastEditUser
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE(),{$this->userID})";
$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 +379,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,LastEditUser
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE(),{$this->userID})";
$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 +418,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,LastEditUser
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE(),{$this->userID})";
$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,16 +442,29 @@ 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);
$query = $this->call_sp_fun($sql);
return $query;
}
public function save_automail($fromName, $fromEmail, $toName, $toEmail, $subject, $body, $M_RelatedInfo = '', $M_State = 0, $M_AddTime = '', $frominfo = 'paypal msg', $M_Web = 'paypal msg') {
$sql = "INSERT INTO
Email_AutomaticSend (
@ -429,36 +525,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
@ -552,6 +679,54 @@ class Online_payment_account_model extends CI_Model {
return $this->HT->query($sql, $note_sn);
}
function query_paypal_note_summary($start, $end, $to_usd_rate=[]) {
$rates_sql = "case pn_mc_currency when 'USD' then 1
when 'AUD' then 0.63
when 'CAD' then 0.70
when 'CHF' then 1.13
when 'EUR' then 1.08
when 'GBP' then 1.29
when 'HKD' then 0.13
when 'JPY' then 0.0067
when 'SGD' then 0.75
when 'NZD' then 0.57
else 1
end ";
if (!empty($to_usd_rate)) {
$rates_sql = " case pn_mc_currency when 'USD' then 1 ";
$rates_sql .= "\n when 'CHF' then 1.13 ";
$rates_sql .= "\n when 'NZD' then 0.57 ";
foreach ($to_usd_rate as $key => $ele) {
$rates_sql .= $ele['currency'] ? "\n when '{$ele['from']}' then {$ele['currency']} " : "";
}
$rates_sql .= " else 1 end ";
}
$sql = "SELECT pn_mc_currency
,round(sum(pn_mc_gross), 3) AS _sum_currency
,round(sum(pn_mc_gross)*to_usd,3) as _sum_usd
,SUM(sum(pn_mc_gross)*to_usd) OVER () AS running_total
FROM (
SELECT pn_txn_id
,pn_invoice
,cast(pn_mc_gross AS FLOAT) AS pn_mc_gross
,pn_mc_currency
,$rates_sql as to_usd
,pn_payer_email
,pn_payer
,pn_payment_date
,pn_datetime
,pn_sn
,ROW_NUMBER() OVER ( PARTITION BY pn_txn_id ORDER BY pn_sn DESC ) AS rn
FROM paypal_note p1
WHERE p1.pn_send = 'send'
AND p1.pn_datetime BETWEEN '{$start}' AND '{$end}'
) cn
GROUP BY cn.pn_mc_currency, to_usd
order by pn_mc_currency ";
$ret = $this->HT->query($sql)->result_array();
return $ret;
}
public function get_advisor_detail($COLI_SN, $OPI_SN, $lgc=1)
{
$advisor_signature = $this->get_advisor_signature($COLI_SN);

@ -27,11 +27,30 @@ 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 OPN_SN, OPN_payFee, OPN_netAmount, OPN_entryAmountCNY
FROM OnlinePaymentNote
WHERE OPN_accountMethod={$column['OPN_accountMethod']} AND OPN_transactionId = '{$column['OPN_transactionId']}'";
$query = $this->info->query($sql);
if ($query->num_rows() > 0) {
$raw_row = $query->row();
$update = array(
'OPN_payFee' => isset($column['OPN_payFee']) ? $column['OPN_payFee'] : $raw_row->OPN_payFee,
'OPN_netAmount' => isset($column['OPN_netAmount']) ? $column['OPN_netAmount'] : $raw_row->OPN_netAmount,
'OPN_entryAmountCNY' => isset($column['OPN_entryAmountCNY']) && isset($column['OPN_payFee']) ? $column['OPN_entryAmountCNY'] : $raw_row->OPN_entryAmountCNY,
);
$where = " OPN_SN=" . $query->row()->OPN_SN;
// var_dump($update);
// var_dump($query->row());
$this->update_note($where, $update);
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 +83,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,8 +94,9 @@ 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' ";
$this->orderby = " ORDER BY CASE OPN_transactionResult WHEN 'completed' THEN 0 ELSE 1 END, OPN_SN DESC ";
return $this->query_note();
}
@ -84,7 +104,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 +133,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) : "";
@ -125,10 +177,12 @@ class Online_payment_note_model extends CI_Model {
$this->transactionId ? $sql.=$this->transactionId : false;
$this->orderby ? $sql.=$this->orderby : false;
// log_message('error', PHP_EOL . $sql);
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 +193,33 @@ class Online_payment_note_model extends CI_Model {
return $this->query_note();
}
/**
* @param mixed $where ['OPN_SN' => ['=', {val}] ]
*/
public function get_note_where($where, $num=1) {
$this->init_query();
$this->topnum=$num;
$this->search = '';
foreach ($where as $key => $value) {
$where_val = '';
$sysbol = strtolower($value[0]);
switch ($sysbol) {
case '=':
$where_val = " = {$this->info->escape($value[1])}";
break;
case 'in':
$where_val = " IN ({$this->info->escape($value[1])})";
break;
default:
$where_val = " {$sysbol} {$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,8 +228,11 @@ 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%' )";
OR OPN_rawOrderId like '%$keyword%'
OR OPN_payerEmail like '%$keyword%'
)";
}
$this->search = $search_sql;
return $this->query_note();
@ -157,8 +241,12 @@ 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 .= " AND OPN_noticeTime BETWEEN '$date 00:00:00' AND '$date 23:59:59' ";
$this->search = $method===null ? "" : " AND OPN_accountMethod IN ($method) ";
$this->search .= " AND (OPN_noticeTime BETWEEN '$date 00:00:00' AND '$date 23:59:59'
OR OPN_noticeSendTime BETWEEN '$date 00:00:00' AND '$date 23:59:59'
OR OPN_completeTime 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 +492,152 @@ 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['result_code'];
$save_column['OPN_resultMsg'] = $row['trade_type'];
$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');
// var_dump(($save_column));
$this->insert_note($save_column, true) ; // 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 OPN_SN
FROM OnlinePaymentNote
WHERE OPN_accountMethod=15015 AND OPN_transactionId = '{$result_data['transaction_id']}'";
$query = $this->info->query($sql);
if ($query->num_rows() > 0) {
$ssje = $this->account_model->get_ssje_exclude_fee($result_data['net_amount'], str_replace("CNY", "RMB", strtoupper($result_data['pay_currency'])));
$update = array(
'OPN_payFee' => isset($result_data['pay_fee']) ? bcsub(0,$result_data['pay_fee']) : null,
'OPN_netAmount' => $result_data['net_amount'],
'OPN_payerEmail' => isset( $result_data['buyer_email']) ? $result_data['buyer_email'] : '',
'OPN_entryAmountCNY' => floatval($ssje),
);
$where = " OPN_SN=" . $query->row()->OPN_SN;
$this->update_note($where, $update);
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;
}
public function query_paypal_current_rate() {
$sql = "SELECT *
FROM (
SELECT TOP 1000
row_number() OVER (PARTITION BY OPN_paymentSource,opn.OPN_fundSource ORDER BY OPN_completeTime ASC) AS rownum
,opn.OPN_fundSource
,opn.OPN_paymentSource
,round(((0 - cast(opn_payfee AS FLOAT) - 0.3) / cast(OPN_payAmount AS FLOAT)), 4) AS calc_rate
,OPN_completeTime
,opn.OPN_transactionId
FROM InfoManager.dbo.OnlinePaymentNote AS opn
WHERE OPN_accountMethod = 15002
AND opn.OPN_transactionResult = 'completed'
AND opn.OPN_noticeType = 'pay'
AND cast(OPN_payAmount AS FLOAT) > 100
-- AND opn.OPN_paymentSource IS NOT NULL
AND isnull(opn.OPN_paymentSource, '') != ''
AND opn.OPN_completeTime >= DATEADD(month, DATEDIFF(month, 0, GETDATE()) + 0, 0)
) AS tt
WHERE tt.rownum = 1
ORDER BY OPN_fundSource,OPN_paymentSource";
$ret = $this->info->query($sql)->result_array();
return $ret;
}
}

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

@ -34,10 +34,10 @@
<dl class="dl-horizontal">
<div class="input-group">
<input type="text" class="form-control" id="pn_invoice" name="pn_invoice" value="<?php //echo!empty($ALI_orderId) ? $ALI_orderId : $note->ALI_orderId; ?><?php echo !empty($new_order) ? $new_order : $old_order; ?>"
<?php
<?php
if ($group_accout_info['GAI_State'] > 0) { ?>
disabled="disabled"
<?php } ?>
<?php } ?>
>
<span class="input-group-addon search-btn" onclick="show_order_modal('<?php echo $note->ALI_dealId; ?>', $('#pn_invoice').val(),'<?php echo $note->ALI_noticeTime; ?>','<?php echo $note->ALI_orderId; ?>')"></span>
</div>
@ -67,7 +67,14 @@
</dl>
<dl class="dl-horizontal">
<p><a href="javascript:void(0);" onclick="$('#note_original_data').toggle()" style="color:#a31022;" >原始数据&nbsp;&raquo;</a></p>
<span style="display: none;" id="note_original_data"><?php echo str_replace('","', '"<br/>"', $note->ALI_memo); ?></span>
<div style="display: none;font-size:smaller;" id="note_original_data">
<pre><?php
$array = json_decode($note->ALI_memo, true); // var_dump($array);
$jsonPretty = json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
echo htmlspecialchars($jsonPretty);
?>
</pre>
</div>
</dl>
<input type="hidden" name="pn_txn_id" id="pn_txn_id" value="<?php echo $note->ALI_dealId; ?>" />

@ -1,17 +1,30 @@
<form action="/webht.php/apps/pay/paymentService/gai_modal_save" method="post" id="form_modal_gai" name="form_modal_gai">
<?php if ( ! empty($gai_info)) { ?>
<p>已录入订单 <?php echo!empty($old_order) ? $old_order : ""; ?></p>
<details>
<summary class="r">交易数据</summary>
<pre><?php
// $array = json_decode($note, true); // var_dump($array);
// unset($note->OPN_rawContent);
$jsonPretty = json_encode($note, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
echo htmlspecialchars($jsonPretty);
?>
</pre>
</details>
<?php // var_dump($gai_info);
if ( ! empty($gai_info)) { ?>
<p>已录入订单 <?php echo !empty($old_order) ? $old_order : ""; ?></p>
<table class="table table-hover table-bordered">
<thead>
<th>订单号</th>
<th>申请金额/币种</th>
<th>实收金额</th>
<th>付款记录备注</th>
</thead>
<?php foreach ($gai_info as $key => $value) { ?>
<tr>
<td><?php echo $value->orderId; ?></td>
<td><?php echo $value->GAI_SQJE; ?>&nbsp;<?php echo $value->GAI_SQJECurrency; ?></td>
<td><?php echo $value->GAI_SSJE; ?>&nbsp;CNY</td>
<td><?php echo $value->GAI_Memo; ?></td>
</tr>
<?php } ?>
</table>
@ -41,17 +54,21 @@
</div>
<label class="text-danger">订单号形如: 160414408_B , B商务订单JJ160321052_T,T传统订单请务必加上后缀</label>
<div style='display: none'><?php var_dump($group_accout_info); ?></div>
<div style='display: none'><?php var_dump($order_info); ?></div>
<div style='display: none'><?php // var_dump($order_info); ?></div>
<div>订单详细内容: </div>
<p>
<?php
if (!empty($order_info)) {
$show_info = array_intersect_key((array)$order_info, array_flip(['COLI_SN', 'COLI_ID', 'OPI_Email', 'OPI_Name','COLI_GroupCode', 'COLI_OrderDetailText']));
$show_json = json_encode($show_info, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
echo "<pre style='max-height:220px;overflow-y:auto;'>";
echo "COLI_SN => $order_info->COLI_SN<br/>";
echo "COLI_ID => $order_info->COLI_ID<br/>";
echo "OPI_Email => $order_info->OPI_Email<br/>";
echo "OPI_Name => $order_info->OPI_Name<br/>";
echo!empty($order_info->COLI_GroupCode) ? "COLI_GroupCode => $order_info->COLI_GroupCode<br/>" : false;
echo!empty($order_info->COLI_OrderDetailText) ? "COLI_OrderDetailText => $order_info->COLI_OrderDetailText\n" : false;
echo!empty($order_info->COLI_OrderDetailText) ? "COLI_OrderDetailText => $order_info->COLI_OrderDetailText" : false;
echo "</pre>";
} else {
echo '找不到目标订单内容';
}
@ -62,7 +79,13 @@
</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">
<pre><?php
$array = json_decode($note->OPN_rawContent, true); // var_dump($array);
$jsonPretty = json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
echo htmlspecialchars($jsonPretty);
?>
</pre>
<?php // echo str_replace('","', '"<br/>"', json_encode(json_decode($note->OPN_rawContent, true), JSON_UNESCAPED_UNICODE)); ?>
</div></p>
</div>

@ -8,9 +8,16 @@
<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>
@media (min-width: 768px){ .modal-dialog{ width: min(60%, 800px); margin: 30px auto;}}
</style>
<style type="text/css">
.export_form_area{display: inline-block;padding: 6px;border: 1px solid #ccc;background-color: #ccc;/*position: absolute;top: 0;left: 17%;*/}
.trigger_export_btn{position: absolute;top: 0;left: 50%;}
@ -25,18 +32,60 @@
.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;}
.dev-color {background-color: #00A2E8;}
.test-color {background-color: #00A2E8;}
.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;}
.highlights-color {background-color: #eb5e26;}
.trippest-color {background-color: #E83201;}
.opacity-4 {opacity: 0.4;}
.app-color {background-color: #EC3A4F;}
.hly-color {background-color: #009fe9;}
.unknown-color{ background-color: #999999;}
.table { table-layout: fixed; }
.table td { word-break: break-word; }
/* .text-completed {color: #00CC00;} */
/* .text-pending {color: #ff9900;} */
.text-pending, .text-pending a:not(.btn) {color: #00A2E8;}
.text-declined, .text-declined a:not(.btn) {color: #c0192a;}
.text-under_review, .text-under_review a:not(.btn) {color: #ff9900;}
.text-resolved, .text-resolved a:not(.btn) {color: #ff9900;}
.text-paypal_dispute, .text-paypal_dispute a:not(.btn),
.text-customer_dispute_resolved, .text-customer_dispute_resolved a:not(.btn),
.text-customer_dispute_updated, .text-customer_dispute_updated a:not(.btn) {color: #ff9900;}
.text-approved, .text-approved a:not(.btn),
.text-paypal_order, .text-paypal_order a:not(.btn)
{color: #777;}
.flex {display: flex;}
.items-center {align-items: center;}
.justify-center {justify-content: center;}
.ml-auto {margin-left: auto;}
#queryFormModal .btn-group .btn:active, #queryFormModal .btn-group .btn.active{ color: #fff; background-color: #337ab7;border-color: #2e6da4;}
.modal-header .close {position: absolute;right: 15px;top: 15px;}
</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 -->
@ -130,23 +179,23 @@
<img width="150" style="height:40px;" src="/css/nav/img/6000.png">
</a>
<h1>Payment List</h1>
<a <?php if($method_code==='') { ?> class="text-muted"<?php } ?>
href="/webht.php/apps/pay/paymentservice/note_list">ALL</a>
<a <?php if($method_code==='all') { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('keywords'=>'','method'=>'all')) ?>">ALL</a>
&NonBreakingSpace;&boxv;&NonBreakingSpace;
<a <?php if($method_code==='15016') { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('method'=>15016)) ?>">微信&raquo;</a>
<a <?php if(stripos($method_code, '15016') !== false) { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('keywords'=>'','method'=>15016)) ?>">微信&raquo;</a>
&NonBreakingSpace;
<a <?php if($method_code==='15002') { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('method'=>15002)) ?>">PayPal&raquo;</a>
<a <?php if(stripos($method_code,'15002') !== false) { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('keywords'=>'','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(stripos($method_code,'15018') !== false || stripos($method_code,'15035') !== false) { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('keywords'=>'','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>
<a <?php if(stripos($method_code,'15015') !== false) { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('keywords'=>'','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,14 +214,17 @@
<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>
</label>
</div> -->
<div class="input-group">
<input type="text" name="keywords" value="<?php echo isset($keywords) ? $keywords : ''; ?>" class="form-control" placeholder="订单号" style="height: 33px;-webkit-box-shadow: inset 0 0px 0px rgba(0,0,0,0.075);box-shadow: inset 0 0px 0px rgba(0,0,0,0.075);border-bottom:1px solid #ddd;">
<span class="input-group-addon search-btn" onclick="$('#search_note_list').submit();"></span>
<input type="text" name="keywords" value="<?php echo isset($keywords) ? $keywords : ''; ?>" class="form-control" placeholder="订单号" style="height: 33px;-webkit-box-shadow: inset 0 0px 0px rgba(0,0,0,0.075);box-shadow: inset 0 0px 0px rgba(0,0,0,0.075);border-bottom:1px solid #ddd;border-right:0;">
<span class="input-group-btn">
<button class="btn btn-default p-0" type="submit" style="border: none; padding: 0"><span class="glyphicon glyphicon-search"></span></button>
</span>
</div>
<div id="datepicker"></div>
</form>
@ -186,8 +238,18 @@
<li><a class="text-primary" href="/webht.php/apps/pay/paymentservice/send_notify" target="_blank">&gt;手动处理通知</a></li>
<li class="btn-sm"></li>
<li><a class="text-primary" href="http://share.chtcdn.com/info.php/sendmail/send_mail" target="_blank">&gt;发送邮件</a></li>
<li class="btn-lg"></li>
<!-- <li class="btn-lg"></li> -->
</ul>
<hr width="100%" />
<ul class="list-unstyled ">
<li>
<button type="button" class="btn text-primary " data-toggle="modal" data-target="#queryFormModal">
&gt; 交易号查询
</button>
</li>
</ul>
<div class="well well-sm hidden-xs" >
<h4>通知状态:</h4>
<p>1.send 表示通知正确发送给外联</p>
@ -195,48 +257,96 @@
<p>3.sendfail 状态的需要手工设置正确的订单号</p>
<p>4.Pending 还未到账,需要人工检查,确认支付或者取消,需要手工关闭此通知</p>
<p>5.Denied 银行拒付,需要手工关闭此通知</p>
<p>6.closed 已经关闭此通知</p>
<h4>记录状态:</h4>
<p>1.✅ 表示已经录入HT订单收款</p>
</div>
</div>
<!-- left end -->
<div class=" pay_form_div col-sm-20 col-xs-24" style="min-height:1024px;border-left:1px solid #ddd;">
<table class="table table-bordered table-hover">
<!-- table-bordered -->
<table class="table table-hover">
<thead>
<tr>
<th >#</th>
<th >主题</th>
<th width="260" 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="40">#</th>
<th width="210">主题</th>
<th width="200">付款人</th>
<th width="200" class="hidden-xs">subject</th>
<th width="200" class="hidden-xs">凭证号</th>
<th width="120">收单时间</th>
<!-- <th width="150" class="hidden-xs">通知时间</th> -->
<th width="120" class="hidden-xs">账单&nbsp;/&nbsp;录入</th>
<th width="120">状态[通知/记录]</th>
</tr>
</thead>
<tbody>
<?php
foreach ($notelist as $key => $item) {
$row_cls = implode(' ',[
"text-{$item->OPN_transactionResult}",
"text-".str_ireplace('.', '_', strtolower($item->OPN_resultMsg)),
"text-".str_ireplace('.', '_', strtolower($item->OPN_noticeType)),
]);
?>
<tr>
<tr class="<?php echo $row_cls ?>">
<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>
<?php echo $item->OPN_orderId . ' / ' . $item->OPN_orderAmount . $item->OPN_currency; ?></td>
<td class="hidden-xs">
<td>
<span class="brand_text <?php echo strtolower(str_replace(" ","",$item->brand_name))."-color"; ?>"><?php echo $item->brand_name; ?></span>
<?php if ($item->OPN_paymentSource != '' && stripos($item->OPN_paymentSource, $item->brand_name) === false) { ?>
<span class="brand_text opacity-4 <?php echo strtolower(str_replace(" ","",$item->brand_name))."-color"; ?>"><?php echo $item->OPN_paymentSource; ?></span>
<?php } ?>
<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><div></div>
<span class="brand_text <?php echo strtolower(str_replace(" ","",$item->app_name))."-color"; ?>"><?php echo $item->app_name; ?></span>
<a href="<?php $p_invoice_arr = explode('_', $item->OPN_invoiceId);
$p_invoice_arr = isset($p_invoice_arr[1]) ? $p_invoice_arr : explode('--', $item->OPN_invoiceId);
echo set_url_param(
array(
'keywords'=>$p_invoice_arr[0] ? $p_invoice_arr[0] : $item->OPN_orderId,
'method' => '',
)
);
?>"><?php echo $item->OPN_orderId; ?></a>
<?php
echo $item->OPN_subject;
?>
<span><?php // echo $item->OPN_orderId . ' / ' ?>&nbsp;/&nbsp;<b><?php echo $item->OPN_orderAmount; ?></b><?php echo $item->OPN_currency; ?></span>
<?php // echo $item->OPN_orderId . ' / ' . $item->OPN_orderAmount . $item->OPN_currency; ?>
</td>
<td><?= $item->OPN_payerName .'<br>' ?>
<a href="<?php echo set_url_param(array('keywords'=>$item->OPN_payerEmail,'method' => '','date'=>'')); ?>"><?php echo $item->OPN_payerEmail; ?></a>
</td>
<td class="hidden-xs"><?php echo $item->OPN_transactionId; ?></td>
<td class="hidden-xs">
<?php if ($item->app_name) { ?>
<span class="brand_text <?php echo strtolower(str_replace(" ","",$item->app_name))."-color"; ?>"><?php echo $item->app_name; ?></span>
<?php } ?>
<?php if ($item->OPN_remark) { ?>
<span><?= $item->OPN_remark ?></span>
<?php } else { ?>
<div><?= $item->OPN_subject ?></div>
<?php } ?>
<?php // echo $item->OPN_subject ? "<span>{$item->OPN_subject}</span>" : ''; ?>
<?php // echo $item->OPN_remark ? "<div>{$item->OPN_remark}</div>" : ''; ?>
</td>
<td class="hidden-xs"><?php // echo $item->OPN_transactionId; ?>
<a href="<?php echo set_url_param(array('keywords'=>$item->OPN_transactionId,'method' => '','date'=>'')); ?>"><?php echo $item->OPN_transactionId; ?></a>
<div>
<?php if ($item->OPN_relatedId) { ?>
<a href="<?php echo set_url_param(array('keywords'=>$item->OPN_relatedId,'method' => '','date'=>'')); ?>"><?php echo $item->OPN_relatedId; ?></a>
<?php } ?>
</div>
</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 +355,33 @@
$send_class = '';
}
?>
<?php if ($item->OPN_noticeType !== 'pay') {
echo '<span class=text-danger >' . strtoupper($item->OPN_noticeType) . '</span><br>';
<?php
if ($item->OPN_transactionResult !== 'completed') {
// declined pending dispute approved
$cls = "text-{$item->OPN_transactionResult}";
$text = strtoupper($item->OPN_transactionResult);
$send_text = $item->OPN_noticeType !== 'pay' ? strtoupper($item->OPN_noticeType) : $item->OPN_resultCode;
echo "<span class={$cls} >{$text}</span><br>";
} elseif ($item->OPN_noticeType !== 'pay') {
// refund
$send_text = $item->OPN_noticeType == 'refund' ? ($item->OPN_noticeSendStatus) : $item->OPN_resultCode;
$_cls = "tag-".$item->OPN_noticeType;
echo "<span class='text-danger {$_cls}' >" . strtoupper($item->OPN_noticeType) . '</span><br>';
} else {
// completed pay
$send_text = ($item->OPN_noticeSendStatus ? $item->OPN_noticeSendStatus : '⏳');
$_cls = "tag-".$item->OPN_transactionResult;
echo "<span class=\"text-success {$_cls}\" >" . strtoupper($item->OPN_transactionResult) . '</span><br>';
} ?>
<div class="flex items-center">
<!-- <button type="button" class="btn btn-sm btn-default <?php // echo $send_class; ?>" onclick="show_gai_modal('<?php // echo $item->OPN_SN; ?>')">
<?php // echo $send_text; ?>
</button> -->
<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 $send_text ; ?>
</a>
<span class="ml-auto"><?php echo ($recored_text); ?></span>
</div>
</td>
</tr>
<?php } ?>
@ -281,6 +412,55 @@
</div>
</div>
</div>
<!-- 退款/交易查询 -->
<div class="modal fade" id="queryFormModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">交易号查询</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<!-- <form class="form-horizontal" role="form" method="post" id="search_list" action="/webht.php/apps/paypal/index/export_list/">
</form> -->
<form class="form-horizontal" role="form" method="post" id="search_refund_list" action="/webht.php/apps/pay/paymentservice/query">
<div class="form-group row">
<label for="account_type" class="col-md-4">付款方式</label>
<div class="col-md-16">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default active">
<input type="radio" name="account_type" id="15016" value="15016" autocomplete="off" checked> 微信
</label>
<!-- <label class="btn btn-default">
<input type="radio" name="account_type" id="15015" value="15015" autocomplete="off"> 支付宝
</label> -->
</div>
</div>
</div>
<div class="form-group row">
<label for="transaction_id" class="col-md-4">原交易号</label>
<div class="col-md-16">
<input type="text" class="form-control col-md-8" id="transaction_id" name="transaction_id" placeholder="原交易号" required>
</div>
</div>
<hr />
<div class="form-group">
<div class="col-sm-24 text-right">
<button type="submit" class="btn btn-primary ">查询</button>
</div>
</div>
</form>
</div>
<!-- <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
<button type="submit" class="btn btn-primary center-block">查询</button>
</div> -->
</div>
</div>
</div>
</body>
<script type="text/javascript" src="/js/flatpickr-4.4.4.min.js"></script>
<script type="text/javascript">
@ -297,9 +477,15 @@ jQuery.browser = {};
$("#datepicker").flatpickr({
inline: true,
dateFormat: "Y-m-d",
defaultDate: "<?php echo $date; ?>",
defaultDate: "<?php echo isset($date) ? $date : ''; ?>",
onChange: function (selectedDates, dateStr, instance) {
window.location.href = '/webht.php/apps/pay/paymentservice/note_list?date=' + dateStr;
var currentParam = window.location.search ? window.location.search : '?_t=1';
if (currentParam.indexOf('date') > -1) {
currentParam = currentParam.replace(/date=[^&]*/, 'date=' + dateStr);
} else {
currentParam += '&date=' + dateStr;
}
window.location.href = '/webht.php/apps/pay/paymentservice/note_list' + currentParam;
}
});
})
@ -315,7 +501,7 @@ jQuery.browser = {};
$('#modal_set_gai').modal('show');
},
error: function(msg) {
alert('\u53d1\u751f\u9519\u8bef\uff0c\u8bf7\u8054\u7cfbYoyo...');
alert('\u53d1\u751f\u9519\u8bef\uff0c\u8bf7\u8054\u7cfbYoyo....');
}
});
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,620 @@
<?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, $check_exists = false)
{
if ($column === null) {
return false;
}
if ($check_exists === true) {
$sql = "SELECT TOP 1 OPN_SN,OPN_transactionResult
FROM OnlinePaymentNote
WHERE OPN_accountMethod={$column['OPN_accountMethod']} AND OPN_transactionId = '{$column['OPN_transactionId']}' AND OPN_resultMsg = '{$column['OPN_resultMsg']}' ";
$query = $this->info->query($sql);
if ($query->num_rows() > 0) {
$update = array(
'OPN_payFee' => isset($column['OPN_payFee']) ? $column['OPN_payFee'] : null,
'OPN_netAmount' => $column['OPN_netAmount'],
'OPN_entryAmountCNY' => $column['OPN_entryAmountCNY'],
);
if ($query->row()->OPN_transactionResult !== $column['OPN_transactionResult']) {
$update['OPN_transactionResult'] = $column['OPN_transactionResult'];
$update['OPN_resultCode'] = $column['OPN_resultCode'];
$update['OPN_rawContent'] = $column['OPN_rawContent'];
$update['OPN_completeTime'] = $column['OPN_completeTime'];
}
$where = " OPN_SN=" . $query->row()->OPN_SN;
$this->update_note($where, $update);
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'])));
$localSqlDateTime0 = date('Y-m-d H:i:s', strtotime($result_data['payment_create']) + 3600 * 8);
$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'] = $localSqlDateTime0;
$save_column['OPN_completeTime'] = $localSqlDateTime;
$save_column['OPN_accountMethod'] = 15002; // $this->config->item('method_code', 'paypal');
$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');
$save_column['OPN_noticeSendStatus'] = isset($result_data['notice_status']) ? $result_data['notice_status'] : '';
$save_column['OPN_payerLogId'] = isset($result_data['payer_id']) ? $result_data['payer_id'] : null;
$save_column['OPN_payerName'] = isset($result_data['payer_name']) ? $result_data['payer_name'] : null;
$save_column['OPN_payerEmail'] = isset($result_data['payer_email']) ? $result_data['payer_email'] : null;
$save_column['OPN_payerStatus'] = isset($result_data['payer_state']) ? $result_data['payer_state'] : null;
$save_column['OPN_remark'] = isset($result_data['remark']) ? $result_data['remark'] : null;
$save_column['OPN_paymentSource'] = isset($result_data['payment_type']) ? $result_data['payment_type'] : null;
$this->insert_note($save_column, true) ;
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
@ -175,29 +216,36 @@ class Note_model extends CI_Model {
}
}
private $code_fundsource = array(
"pays@highlightstravel.com" => "Highlights", // business":"pay@trippest.com"
"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 +261,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 = "

@ -6,11 +6,43 @@ if (!defined('BASEPATH'))
class Paypal_model extends CI_Model {
private $HT;
private $userdata;
private $userID;
function __construct() {
parent::__construct();
$this->HT = $this->load->database('HT', TRUE);
//$this->DEST = $this->load->database('DEST', TRUE);
$this->userdata = $this->session->userdata('userdata');
$this->userID = isset($this->userdata['OPI_SN']) ? $this->userdata['OPI_SN'] : 'null';
}
public function call_sp_fun($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);
$result_object = array();
if (false !== $stmt ) { // 无权限或执行错误返回false
// 存储过程中每个select都产生结果集
// 设置了SET NOCOUNT ON;就只有输出的结果集
$a = true;
while ($a !== false) {
$row = sqlsrv_fetch_object($stmt); // Retrieves the next row of data as a PHP object.
$a = !empty($row);
$a===true ? $result_object[] = $row : null;
}
sqlsrv_free_stmt($stmt);
}
sqlsrv_close($conn);
return $result_object;
}
//根据订单号获取外联邮箱
@ -33,7 +65,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 +109,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 +135,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 +220,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 +248,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;
,DeleteFlag,LastEditTime,LastEditUser
) VALUES (?,?,15010,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE(),{$this->userID})";
$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 +291,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;
,DeleteFlag,LastEditTime,LastEditUser
) VALUES (?,?,15002,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE(),{$this->userID})";
$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 +323,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');
,DeleteFlag,LastEditTime,LastEditUser
) VALUES (?,15002,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE(),{$this->userID})";
$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 +616,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,49 +639,87 @@ 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;
}
/** 删除收款记录 */
public function delete_money_t($deadId)
public function delete_money_t($deadId, $gai_sn)
{
$sql = "UPDATE GroupAccountInfo SET DeleteFlag=1 WHERE GAI_AccreditNo=?";
$query = $this->HT->query($sql, array($deadId));
$sql = "UPDATE GroupAccountInfo SET DeleteFlag=1, LastEditTime=GETDATE(), GAI_Memo='删除 '+GAI_Memo WHERE GAI_AccreditNo=? and GAI_SN=?";
$query = $this->HT->query($sql, array($deadId, $gai_sn));
return $query;
}
public function delete_money_b($deadId)
public function delete_money_b($deadId, $gai_sn)
{
$sql = "UPDATE BIZ_GroupAccountInfo SET DeleteFlag=1 WHERE GAI_AccreditNo=?";
$query = $this->HT->query($sql, array($deadId));
$sql = "UPDATE BIZ_GroupAccountInfo SET DeleteFlag=1, LastEditTime=GETDATE(), GAI_Memo='删除 '+GAI_Memo WHERE GAI_AccreditNo=? and GAI_SN=?";
$query = $this->HT->query($sql, array($deadId, $gai_sn));
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);
$this->call_sp_fun($sql);
return false;
// return $query;
}
/** 写入商务订单操作记录 */
public function insert_biz_order_log($coli_sn, $log_info)
{

@ -4,7 +4,7 @@
</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">
@ -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;">
@ -79,4 +79,4 @@
</table>
</div>
</body>
</html>
</html>

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

@ -4,7 +4,7 @@
</head>
<body style="font-size: 12px;font-family: arial,helvetica,sans-serif;">
<div class="ppmail">
<table align="center" border="0" cellpadding="0" cellspacing="0" width="600">
<tbody>
<tr valign="top">
@ -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;">
@ -57,7 +57,7 @@
<?php echo isset($ship->SHIPTOZIP)?$ship->SHIPTOZIP:''; ?><br>
<?php echo isset($ship->SHIPTOCOUNTRYNAME)?$ship->SHIPTOCOUNTRYNAME:''; ?>
</span>
</td>
</tr>
<tr>
@ -82,7 +82,7 @@
</tr>
</tbody>
</table>
<br>
<img src="http://www.mycht.cn/css/images/icon_help_16x16.gif" border="0" style="margin-right: 5px;vertical-align: middle;" alt="">Questions? Go to the Help Center at: www.paypal.com/c2/help.<br>
<br>
@ -101,4 +101,4 @@
</table>
</div>
</body>
</html>
</html>

@ -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
@ -54,7 +54,9 @@
.webhooks-color{background-color: dimgrey; }
.unknown-color{background-color: dimgray; }
.cht-color {background-color: #A31022;}
.highlights-color {background-color: #eb5e26;}
.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 +187,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 +209,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 +251,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 +269,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">
@ -44,10 +48,10 @@
<dd>
<div class="input-group">
<input type="text" class="form-control" id="pn_invoice" name="pn_invoice" value="<?php echo !empty($pn_invoice) ? $pn_invoice : $note->pn_invoice; ?>"
<?php
<?php
if ($group_accout_info['GAI_State'] > 0) { ?>
disabled="disabled"
<?php } ?>
<?php } ?>
>
<span class="input-group-btn">
<button class="btn btn-default" type="button" onclick="show_order_modal('<?php echo $note->pn_txn_id; ?>', 0, $('#pn_invoice').val())"><span class="glyphicon glyphicon-search"></span></button>
@ -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