Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create vendors.php #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions wwwroot/Application/Admin/Common/vendors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 茉莉清茶 <[email protected]> <http://www.3spp.cn>
// +----------------------------------------------------------------------


/**
* 系统公共库文件扩展
* 主要定义系统公共函数库扩展
*/

//友好时间显示开始

function fdate($time) {
if (!$time)
return false;
$fdate = '';
$d = time() - intval($time);
$ld = $time - mktime(0, 0, 0, 0, 0, date('Y')); //得出年
$md = $time - mktime(0, 0, 0, date('m'), 0, date('Y')); //得出月
$byd = $time - mktime(0, 0, 0, date('m'), date('d') - 2, date('Y')); //前天
$yd = $time - mktime(0, 0, 0, date('m'), date('d') - 1, date('Y')); //昨天
$dd = $time - mktime(0, 0, 0, date('m'), date('d'), date('Y')); //今天
$td = $time - mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')); //明天
$atd = $time - mktime(0, 0, 0, date('m'), date('d') + 2, date('Y')); //后天
if ($d == 0) {
$fdate = '刚刚';
} else {
switch ($d) {
case $d < $atd:
$fdate = date('Y年m月d日', $time);
break;
case $d < $td:
$fdate = '后天' . date('H:i', $time);
break;
case $d < 0:
$fdate = '明天' . date('H:i', $time);
break;
case $d < 60:
$fdate = $d . '秒前';
break;
case $d < 3600:
$fdate = floor($d / 60) . '分钟前';
break;
case $d < $dd:
$fdate = floor($d / 3600) . '小时前';
break;
case $d < $yd:
$fdate = '昨天' . date('H:i', $time);
break;
case $d < $byd:
$fdate = '前天' . date('H:i', $time);
break;
case $d < $md:
$fdate = date('m月d日 H:i', $time);
break;
case $d < $ld:
$fdate = date('m月d日', $time);
break;
default:
$fdate = date('Y年m月d日', $time);
break;
}
}
return $fdate;
}
//友好时间显示结束
/**
* 获取 IP 地理位置
* 淘宝IP接口
* @Return: array
*/
function getCity($ip)
{
$url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;
$ipinfo=json_decode(file_get_contents($url));
if($ipinfo->code=='1'){
return false;
}
$city = $ipinfo->data->region.$ipinfo->data->city;//省市县
$ip = $ipinfo->data->ip;//IP地址
$ips = $ipinfo->data->isp;//运营商
$guo = $ipinfo->data->country;//国家
if($guo == '中国'){
$guo = '';
}
//if(in_array(strtok($ip, '.'), array('10', '127', '168', '192'))){
//$city = "本机地址或局域网";
//}
//$ipp = '110.113.161.105';
//$ipss = ip2long($ipp);
return $guo.$city.$ips.'['.$ip.']';

}

/**
* 添加邮件到队列
*/
function _mail_queue($to, $subject, $body, $priority = 1) {
$to_emails = is_array($to) ? $to : array($to);
$mails = array();
$time = time();
foreach ($to_emails as $_email) {
$mails[] = array(
'mail_to' => $_email,
'mail_subject' => $subject,
'mail_body' => $body,
'priority' => $priority,
'add_time' => $time,
'lock_expiry' => $time,
);
}
M('mail_queue')->addAll($mails);

//异步发送邮件
$this->send_mail(false);
}

/**
* 发送邮件
*/
function send_mail($is_sync = true) {
if (!$is_sync) {
//异步
session('async_sendmail', true);
return true;
} else {
//同步
session('async_sendmail', null);
return D('mail_queue')->send();
}
}