添加通用逻辑错误处理
This commit is contained in:
parent
6bf11f04f8
commit
702d6a209f
@ -7,19 +7,6 @@ use think\Db;
|
|||||||
use think\facade\Cache;
|
use think\facade\Cache;
|
||||||
use think\facade\Request;
|
use think\facade\Request;
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取默认分页信息
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
function defaultRows()
|
|
||||||
{
|
|
||||||
$rows = intval(Request::param('rows', cookie('page-rows')));
|
|
||||||
if (!$rows) {
|
|
||||||
$rows = 20;
|
|
||||||
}
|
|
||||||
cookie('page-rows', $rows);
|
|
||||||
return $rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isDebug()
|
function isDebug()
|
||||||
{
|
{
|
||||||
@ -51,7 +38,7 @@ function auth($node, $moduleApp = 'project')
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生产表唯一标记
|
* 生成表唯一标记
|
||||||
* @param string $tableName 表名
|
* @param string $tableName 表名
|
||||||
* @param string $fieldName 字段名
|
* @param string $fieldName 字段名
|
||||||
* @param int $len 长度
|
* @param int $len 长度
|
||||||
@ -91,6 +78,34 @@ function sysconf($name, $value = null)
|
|||||||
return isset($config[$name]) ? $config[$name] : '';
|
return isset($config[$name]) ? $config[$name] : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误消息,一般用于向上抛出逻辑错误
|
||||||
|
* @param $errno
|
||||||
|
* @param string $message
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function error($errno, $message = '')
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'errno' => $errno,
|
||||||
|
'message' => $message,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否含有错误消息
|
||||||
|
* @param $data
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function isError($data)
|
||||||
|
{
|
||||||
|
if (empty($data) || !is_array($data) || !array_key_exists('errno', $data) || (array_key_exists('errno', $data) && $data['errno'] == 0)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日期格式标准输出
|
* 日期格式标准输出
|
||||||
* @param string $datetime 输入日期
|
* @param string $datetime 输入日期
|
||||||
@ -102,6 +117,10 @@ function format_datetime($datetime, $format = 'Y年m月d日 H:i:s')
|
|||||||
return date($format, strtotime($datetime));
|
return date($format, strtotime($datetime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前时间
|
||||||
|
* @return false|string
|
||||||
|
*/
|
||||||
function nowTime()
|
function nowTime()
|
||||||
{
|
{
|
||||||
return date('Y-m-d H:i:s', time());
|
return date('Y-m-d H:i:s', time());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user