|
|
|
@ -50,6 +50,7 @@ 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);
|
|
|
|
@ -133,6 +134,10 @@ class PaymentService extends CI_Controller {
|
|
|
|
|
}
|
|
|
|
|
// 开始处理
|
|
|
|
|
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;
|
|
|
|
@ -429,6 +434,74 @@ 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';
|
|
|
|
|
// 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') {
|
|
|
|
|
$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_subject' => isset($payment_ret->item_number) && empty($item->subject) ? $payment_ret->item_number : $item->subject,
|
|
|
|
|
'OPN_noticeSendStatus' => 'closed', // 先忽略
|
|
|
|
|
);
|
|
|
|
|
$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)
|
|
|
|
|
{
|
|
|
|
|
$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);
|
|
|
|
|
$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 : '';
|
|
|
|
|
|
|
|
|
|
$payer = new stdClass();
|
|
|
|
|
if (isset($order['payer'])) {
|
|
|
|
|
$payer = (object) $order['payer'];
|
|
|
|
|
$payer->fullname = $payer->name['given_name'] . ' ' . $payer->name['surname'];
|
|
|
|
|
} else {
|
|
|
|
|
$payer->fullname = $payment_source[$type]['name'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$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)
|
|
|
|
@ -677,6 +750,45 @@ class PaymentService extends CI_Controller {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查PayPal是否达到最低汇率的额度
|
|
|
|
|
* * 达到120万美元, 发邮件提醒
|
|
|
|
|
* 15号之后开始检查
|
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
public function check_paypal_limit()
|
|
|
|
|
{
|
|
|
|
|
if (date('d') < '15') {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$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);
|
|
|
|
|
$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) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// 达到了 120 万美元, 就发邮件, 提醒切换渠道
|
|
|
|
|
$time_set = date('Y-m-d_H_i_s');
|
|
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function ipalinks_settlement($year, $month, $day="01")
|
|
|
|
|
{
|
|
|
|
|
set_time_limit(0);
|
|
|
|
|