|
|
|
|
@ -757,25 +757,49 @@ class PaymentService extends CI_Controller {
|
|
|
|
|
* 检查PayPal是否达到最低汇率的额度
|
|
|
|
|
* * 达到120万美元, 发邮件提醒
|
|
|
|
|
* 15号之后开始检查
|
|
|
|
|
*
|
|
|
|
|
* 换美元汇率: https://www.chinahighlights.com/api/cht/currency/getCurrencydata.php
|
|
|
|
|
**/
|
|
|
|
|
public function check_paypal_limit()
|
|
|
|
|
{
|
|
|
|
|
$this->load->helper('file');
|
|
|
|
|
if (date('d') < '15') {
|
|
|
|
|
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) {
|
|
|
|
|
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);
|
|
|
|
|
$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');
|
|
|
|
|
$fromName = 'PayPal 额度提醒';
|
|
|
|
|
@ -783,10 +807,45 @@ class PaymentService extends CI_Controller {
|
|
|
|
|
$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>";
|
|
|
|
|
$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()
|
|
|
|
|
{
|
|
|
|
|
if (date('d') !== '2') {
|
|
|
|
|
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');
|
|
|
|
|
$fromName = 'PayPal 费率提醒';
|
|
|
|
|
$fromEmail = 'lyt@hainatravel.com';
|
|
|
|
|
$toName = 'LOT, fgy'; // 'fgy';
|
|
|
|
|
$toEmail = 'lyt@hainatravel.com, fgy@hainatravel.com'; // 'fgy@hainatravel.com';
|
|
|
|
|
$subject = $fromName;
|
|
|
|
|
$body = "PayPal费率高于3.2%,请及时处理. <br>当前费率: <br/>PayPal钱包渠道: {$current_BCDC}%<br/>PayPal ACDC渠道(GooglePay, ApplePay): {$current_ACDC}%<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);
|
|
|
|
|
$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;
|
|
|
|
|
|