mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
改进自动时间戳字段的自动识别机制 取消Model类的autoFetchFieldType和fieldType属性 改为由autoWriteTimestamp属性直接设置时间戳类型 支持 datetime date 和 timestamp
This commit is contained in:
@@ -65,9 +65,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
protected $insert = [];
|
protected $insert = [];
|
||||||
// 更新自动完成列表
|
// 更新自动完成列表
|
||||||
protected $update = [];
|
protected $update = [];
|
||||||
// 是否自动获取字段类型信息
|
// 是否需要自动写入时间戳 如果设置为字符串 则表示时间字段的类型
|
||||||
protected $autoFetchFieldType = false;
|
|
||||||
// 是否需要自动写入时间戳
|
|
||||||
protected $autoWriteTimestamp;
|
protected $autoWriteTimestamp;
|
||||||
// 创建时间字段
|
// 创建时间字段
|
||||||
protected $createTime = 'create_time';
|
protected $createTime = 'create_time';
|
||||||
@@ -85,8 +83,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
protected $updateWhere;
|
protected $updateWhere;
|
||||||
// 当前执行的关联对象
|
// 当前执行的关联对象
|
||||||
protected $relation;
|
protected $relation;
|
||||||
// 属性类型
|
|
||||||
protected $fieldType = [];
|
|
||||||
// 验证失败是否抛出异常
|
// 验证失败是否抛出异常
|
||||||
protected $failException = false;
|
protected $failException = false;
|
||||||
|
|
||||||
@@ -118,11 +114,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
$this->name = basename(str_replace('\\', '/', $this->class));
|
$this->name = basename(str_replace('\\', '/', $this->class));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->autoFetchFieldType && empty($this->fieldType)) {
|
|
||||||
// 获取字段类型信息
|
|
||||||
$this->fieldType = $this->db()->getTableInfo('', 'type');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_null($this->autoWriteTimestamp)) {
|
if (is_null($this->autoWriteTimestamp)) {
|
||||||
// 自动写入时间戳
|
// 自动写入时间戳
|
||||||
$this->autoWriteTimestamp = $this->db()->getConfig('auto_timestamp');
|
$this->autoWriteTimestamp = $this->db()->getConfig('auto_timestamp');
|
||||||
@@ -257,7 +248,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
$value = $_SERVER['REQUEST_TIME'];
|
$value = $_SERVER['REQUEST_TIME'];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} elseif (isset($this->fieldType[$name]) && preg_match('/(datetime|date|timestamp)/is', $this->fieldType[$name])) {
|
} elseif (is_string($this->autoWriteTimestamp) && in_array(strtolower($this->autoWriteTimestamp),['datetime','date','timestamp'])) {
|
||||||
$value = date($this->dateFormat, $_SERVER['REQUEST_TIME']);
|
$value = date($this->dateFormat, $_SERVER['REQUEST_TIME']);
|
||||||
} else {
|
} else {
|
||||||
$value = $_SERVER['REQUEST_TIME'];
|
$value = $_SERVER['REQUEST_TIME'];
|
||||||
|
|||||||
Reference in New Issue
Block a user