关于招聘项目的常用方法类(PHP版)

 1、最低工资与最高工资的数字转化为 几千到几千的形式

/**
     * @param $minwage 最低工资
     * @param $maxwage 最高工资
     * @param int $negotiable 0表示具体工资,1表示面议
     * @return string|string[]
     */
public function handle_wage($minwage, $maxwage, $negotiable = 0)
    {
        $wage_unit = "0";// 0表示K,1表示千
        if ($negotiable == 0) {
            if ($wage_unit == 1) {
                $minwage =
                $minwage % 1000 == 0
                ? $minwage / 1000 . 'K'
                : round($minwage / 1000, 1) . 'K';
                $maxwage = $maxwage
                ? ($maxwage % 1000 == 0
                    ? $maxwage / 1000 . 'K'
                    : round($maxwage / 1000, 1) . 'K')
                : 0;
            } elseif ($wage_unit == 2) {
                if ($minwage >= 10000) {
                    if ($minwage % 10000 == 0) {
                        $minwage = $minwage / 10000 . '万';
                    } else {
                        $minwage = round($minwage / 10000, 1);
                        $minwage = strpos($minwage, '.')
                        ? str_replace('.', '万', $minwage)
                        : $minwage . '万';
                    }
                } elseif ($minwage < 1000) {
                    $minwage = $minwage;
                } else {
                    if ($minwage % 1000 == 0) {
                        $minwage = $minwage / 1000 . '千';
                    } else {
                        $minwage = round($minwage / 1000, 1);
                        $minwage = strpos($minwage, '.')
                        ? str_replace('.', '千', $minwage)
                        : $minwage . '千';
                    }
                }
                if ($maxwage >= 10000) {
                    if ($maxwage % 10000 == 0) {
                        $maxwage = $maxwage / 10000 . '万';
                    } else {
                        $maxwage = round($maxwage / 10000, 1);
                        $maxwage = strpos($maxwage, '.')
                        ? str_replace('.', '万', $maxwage)
                        : $maxwage . '万';
                    }
                } elseif ($maxwage) {
                    if ($maxwage % 1000 == 0) {
                        $maxwage = $maxwage / 1000 . '千';
                    } else {
                        $maxwage = round($maxwage / 1000, 1);
                        $maxwage = strpos($maxwage, '.')
                        ? str_replace('.', '千', $maxwage)
                        : $maxwage . '千';
                    }
                } else {
                    $maxwage = 0;
                }
            }
            if ($maxwage == 0) {
                $return = '面议';
            } else {
                if ($minwage == $maxwage) {
                    $return = $minwage;
                } else {
                    $return = $minwage . '~' . $maxwage;
                }
            }
        } else {
            $return = '面议';
        }
        return $return;
    }

2、根据时间戳大小返回时间的差值

/**
 * 返回两个时间的相距时间,*年*月*日*时*分*秒
 * @param int $remainder_seconds 时间戳差值
 * @param int $return_type 默认值为0,0/不为0则拼接返回,1/*秒,2/*分*秒,3/*时*分*秒/,4/*日*时*分*秒,5/*月*日*时*分*秒,6/*年*月*日*时*分*秒
 * @param array $format_array 格式化字符,例,array('年', '月', '日', '时', '分', '秒')
 * @return String or false
 */
function diffTimeAll($remainder_seconds, $return_type=0, $format_array=array('年', '个月', '天', '个小时', '分', '秒')) {

    //年
    $years = 0;
    if (($return_type == 0 || $return_type == 6) && $remainder_seconds - 31536000 > 0) {
        $years = floor($remainder_seconds / (31536000));
    }
    //月
    $monthes = 0;
    if (($return_type == 0 || $return_type >= 5) && $remainder_seconds - $years * 31536000 - 2592000 > 0) {
        $monthes = floor(($remainder_seconds - $years * 31536000) / (2592000));
    }
    //日
    $days = 0;
    if (($return_type == 0 || $return_type >= 4) && $remainder_seconds - $years * 31536000 - $monthes * 2592000 - 86400 > 0) {
        $days = floor(($remainder_seconds - $years * 31536000 - $monthes * 2592000) / (86400));
    }
    //时
    $hours = 0;
    if (($return_type == 0 || $return_type >= 3) && $remainder_seconds - $years * 31536000 - $monthes * 2592000 - $days * 86400 - 3600 > 0) {
        $hours = floor(($remainder_seconds - $years * 31536000 - $monthes * 2592000 - $days * 86400) / 3600);
    }
    //分
    $minutes = 0;
    if (($return_type == 0 || $return_type >= 2) && $remainder_seconds - $years * 31536000 - $monthes * 2592000 - $days * 86400 - $hours * 3600 - 60 > 0) {
        $minutes = floor(($remainder_seconds - $years * 31536000 - $monthes * 2592000 - $days * 86400 - $hours * 3600) / 60);
    }
    //秒
    $seconds = $remainder_seconds - $years * 31536000 - $monthes * 2592000 - $days * 86400 - $hours * 3600 - $minutes * 60;
    $return = false;
    switch ($return_type) {
        case 0:
            if ($years > 0) {
                $return = $years . $format_array[0] . $monthes . $format_array[1] . $days . $format_array[2] . $hours . $format_array[3] . $minutes . $format_array[4] . $seconds . $format_array[5];
            } else if ($monthes > 0) {
                $return = $monthes . $format_array[1] . $days . $format_array[2] . $hours . $format_array[3] . $minutes . $format_array[4] . $seconds . $format_array[5];
            } else if ($days > 0) {
                $return = $days . $format_array[2] . $hours . $format_array[3] . $minutes . $format_array[4] . $seconds . $format_array[5];
            } else if ($hours > 0) {
                $return = $hours . $format_array[3] . $minutes . $format_array[4] . $seconds . $format_array[5];
            } else if ($minutes > 0) {
                $return = $minutes . $format_array[4] . $seconds . $format_array[5];
            } else {
                $return = $seconds . $format_array[5];
            }
            break;
        case 1:
            $return = $seconds . $format_array[5];
            break;
        case 2:
            $return = $minutes . $format_array[4] . $seconds . $format_array[5];
            break;
        case 3:
            $return = $hours . $format_array[3] . $minutes . $format_array[4] . $seconds . $format_array[5];
            break;
        case 4:
            $return = $days . $format_array[2] . $hours . $format_array[3] . $minutes . $format_array[4] . $seconds . $format_array[5];
            break;
        case 5:
            $return = $monthes . $format_array[1] . $days . $format_array[2] . $hours . $format_array[3] . $minutes . $format_array[4] . $seconds . $format_array[5];
            break;
        case 6:
//            第一行是返回年月日时分秒,第二行是年月,个人项目只需要年月,需要上面的自行修改
//            $return = $years . $format_array[0] . $monthes . $format_array[1] . $days . $format_array[2] . $hours . $format_array[3] . $minutes . $format_array[4] . $seconds . $format_array[5];
            $return = $years . $format_array[0] . $monthes . $format_array[1];
            break;
        default:
            $return = false;
    }
    return $return;
}

3、格式化当前登录时间,传的值为时间戳

/**
 * 格式化最近登录时间
 */
function format_last_login_time($login_time)
{
    if (date('Y-m-d', $login_time) == date('Y-m-d')) {
        return '今天';
    } elseif (
        date('Y-m-d', $login_time) == date('Y-m-d', strtotime('yesterday'))
    ) {
        return '昨天';
    } elseif (
        date('Y-m-d', $login_time) ==
        date('Y-m-d', strtotime('yesterday') - 1)
    ) {
        return '前天';
    } elseif (time() - $login_time > 7 * 24 * 3600) {
        return '超过一周';
    } else {
        return date('Y-m-d', $login_time);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值