diff --git a/extend/base/common/model/TimeModelBase.php b/extend/base/common/model/TimeModelBase.php index c330bc0..ada264d 100644 --- a/extend/base/common/model/TimeModelBase.php +++ b/extend/base/common/model/TimeModelBase.php @@ -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; + } }