'未出租', 'num' => 2];
}
$now_time = time();
$days = ceil(($time - $now_time) / 3600 / 24);
if ($days > 0) {
return ['msg' => $days . '天后到期', 'num' => 2];
} else {
return ['msg' => '已过期' . abs($days) . '天', 'num' => 1];
}
}
/**
* 格式化数组,删除字段
* @param type $_arr 数组对象
* @param type $field 需要删除的字段
*/
function format_field(&$_arr = array(), $_field = array())
{
if (!$_arr || !$_field) {
return;
}
if (!is_array($_field)) {
$_field = explode(',', $_field);
}
$_field = array_flip($_field);
array_walk($_arr, function (&$v, &$k) use ($_field) {
$v = array_intersect_key($v, $_field);
});
}
/**
*
* @param type $code 状态编码
* @param type $data 返回数据
* @param type $msg 错误的提示信息
* @return type
*/
function send_http_status($code, $_data = array(), $msg = '')
{
if (!$code) {
return;
}
$_status = config('status');
if (isset($_status[$code])) {
header('HTTP/1.1 200 ' . $_status[$code]);
// 确保FastCGI模式下正常
header('Status: 200 ' . $_status[$code]);
}
if ($_data == null) {
$_data = [];
}
$msg = empty($msg) ? $_status[$code] : $msg;
$_msg = [
'code' => $code,
'msg' => $msg,
'data' => $_data,
'time' => $_SERVER['REQUEST_TIME'],
];
return json_encode($_msg, JSON_UNESCAPED_UNICODE);
}
/**
* 去除html js css 危险注入代码
*/
function filter_danger_str($_string)
{
$search = array("''si", // 去掉 javascript
"''si", // 去掉 css
"'<[/!]*?[^<>]*?>'si", // 去掉 HTML 标记
"'