mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 15:32:48 +08:00
feat: 模型基类增加时间戳格式的通用处理方法
This commit is contained in:
@@ -37,4 +37,33 @@ class TimeModelBase extends BaseModel
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
protected $defaultSoftDelete = 0;
|
||||
|
||||
public static function timeAttrSet($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return 0;
|
||||
}
|
||||
if (is_numeric($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$time = strtotime($value);
|
||||
if ($time === false) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $time;
|
||||
}
|
||||
|
||||
public static function timeAttrGet($value, $format = 'Y-m-d H:i:s')
|
||||
{
|
||||
if (empty($value)) {
|
||||
return '';
|
||||
}
|
||||
if (is_numeric($value)) {
|
||||
return date($format, $value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user