diff --git a/webht/third_party/pay/controllers/AlipayTradeService.php b/webht/third_party/pay/controllers/AlipayTradeService.php index eeb1ca5c..aa9207a0 100644 --- a/webht/third_party/pay/controllers/AlipayTradeService.php +++ b/webht/third_party/pay/controllers/AlipayTradeService.php @@ -197,7 +197,7 @@ class AlipayTradeService extends CI_Controller // if (strcmp(strval($response->trade_status), "TRADE_SUCCESS") == 0) { // $this->Alipay_note_model->update_query($response->trade_no,$response->buyer_logon_id); // } - $fund_bill_list = json_decode($asyns_resp->data->fund_bill_list, true); + $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), @@ -217,7 +217,7 @@ class AlipayTradeService extends CI_Controller '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, + '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") { @@ -1035,8 +1035,8 @@ class AlipayTradeService extends CI_Controller 'complate_date' => $row['complete_time'], 'fund_source' => $this->get_fundsource($row['app_id']), 'fund_type' => $trade_type, - 'event' => isset($row['biz_type']) ? strval($row['biz_type']) : $row['trade_type'], - 'event_result' => 'TRADE_SUCCESS', + '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 : '', ]; @@ -1045,6 +1045,7 @@ class AlipayTradeService extends CI_Controller } $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); } diff --git a/webht/third_party/pay/controllers/PaymentService.php b/webht/third_party/pay/controllers/PaymentService.php index 90f8178e..97a288cc 100644 --- a/webht/third_party/pay/controllers/PaymentService.php +++ b/webht/third_party/pay/controllers/PaymentService.php @@ -582,6 +582,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); @@ -592,8 +593,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); diff --git a/webht/third_party/pay/controllers/WxpayService.php b/webht/third_party/pay/controllers/WxpayService.php index 69b50fdc..c139f948 100644 --- a/webht/third_party/pay/controllers/WxpayService.php +++ b/webht/third_party/pay/controllers/WxpayService.php @@ -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'] ? $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'] ? $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; @@ -97,7 +97,7 @@ class WxpayService extends CI_Controller { 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日账单 // 检查PayPal的额度 - async_get('https://www.mycht.cn/webht.php/apps/pay/paymentservice/check_paypal_limit'); + async_curl('https://www.mycht.cn/webht.php/apps/pay/paymentservice/check_paypal_limit'); /** * 每月20号发送退款给财务 */ @@ -108,7 +108,7 @@ class WxpayService extends CI_Controller { * 每月2号: 检查PayPal的费率 */ if (date('d')==='2') { - async_get('https://www.mycht.cn/webht.php/apps/pay/paymentservice/check_paypal_rate'); + async_curl('https://www.mycht.cn/webht.php/apps/pay/paymentservice/check_paypal_rate'); } return; } @@ -134,17 +134,20 @@ class WxpayService extends CI_Controller { $save_column['OPN_accountMethod'] = $this->config->item('method_code', 'wxpay'); if ($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_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_transactionResult'] = $row['refund_status'] === 'SUCCESS' ? 'completed' : strtolower($row['refund_status']); } else { // 收款 $save_column['OPN_payFee'] = bcsub(0, $row['wxpay_fee']); @@ -156,14 +159,14 @@ class WxpayService extends CI_Controller { $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']; @@ -177,7 +180,7 @@ class WxpayService extends CI_Controller { $save_column['OPN_rawContent'] = json_encode($row); $save_column['OPN_noticeTime'] = date('Y-m-d H:i:s'); - $this->note_model->insert_note($save_column); + $this->note_model->insert_note($save_column, true); } return; } diff --git a/webht/third_party/pay/helpers/payment_helper.php b/webht/third_party/pay/helpers/payment_helper.php index a6dd6476..fdc17b5b 100644 --- a/webht/third_party/pay/helpers/payment_helper.php +++ b/webht/third_party/pay/helpers/payment_helper.php @@ -473,6 +473,25 @@ function array_some($array, $condition) { 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 diff --git a/webht/third_party/pay/models/Online_payment_account_model.php b/webht/third_party/pay/models/Online_payment_account_model.php index 21560bfd..2d00a10f 100644 --- a/webht/third_party/pay/models/Online_payment_account_model.php +++ b/webht/third_party/pay/models/Online_payment_account_model.php @@ -130,6 +130,30 @@ class Online_payment_account_model extends CI_Model { 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 + ,'B' AS ordertype FROM BIZ_GroupAccountInfo + WHERE GAI_AccreditNo = '$pn_txn_id' + 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 + ,'T' AS ordertype + FROM GroupAccountInfo + WHERE GAI_AccreditNo = '$pn_txn_id'"; + + $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) { diff --git a/webht/third_party/pay/models/Online_payment_note_model.php b/webht/third_party/pay/models/Online_payment_note_model.php index bebe4964..75082daf 100644 --- a/webht/third_party/pay/models/Online_payment_note_model.php +++ b/webht/third_party/pay/models/Online_payment_note_model.php @@ -33,12 +33,18 @@ class Online_payment_note_model extends CI_Model { return false; } if ($check_exists === true) { - $sql = "SELECT TOP 1 1 + $sql = "SELECT TOP 1 OPN_SN FROM OnlinePaymentNote WHERE OPN_accountMethod={$column['OPN_accountMethod']} AND OPN_transactionId = '{$column['OPN_transactionId']}'"; $query = $this->info->query($sql); if ($query->num_rows() > 0) { - // todo: update pay_fee, CNY ssje + $update = array( + 'OPN_payFee' => isset($column['OPN_payFee']) ? bcsub(0,$column['OPN_payFee']) : null, + 'OPN_netAmount' => $column['OPN_netAmount'], + 'OPN_entryAmountCNY' => $column['OPN_entryAmountCNY'], + ); + $where = " OPN_SN=" . $query->row()->OPN_SN; + $this->update_note($where, $update); return false; } } @@ -542,12 +548,20 @@ class Online_payment_note_model extends CI_Model { { $this->load->model('Online_payment_account_model', 'account_model'); if ($check_exists === true) { - $sql = "SELECT TOP 1 1 + $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) { - // todo: update pay_fee, CNY ssje + $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; } }