diff --git a/library/think/Model.php b/library/think/Model.php index 8f5b8cdd..4c974ef5 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -916,7 +916,23 @@ abstract class Model implements \JsonSerializable, \ArrayAccess { if (is_null($value) && in_array($name, $this->autoTimeField)) { // 自动写入的时间戳字段 - $value = NOW_TIME; + if (isset($this->type[$name])) { + $type = $this->type[$name]; + if (strpos($type, ':')) { + list($type, $param) = explode(':', $type, 2); + } + switch ($type) { + case 'timestamp': + $format = !empty($param) ? $param : $this->dateFormat; + $value = date($format, NOW_TIME); + break; + case 'datetime': + $value = NOW_TIME; + break; + } + } else { + $value = NOW_TIME; + } } else { // 检测修改器 $method = 'set' . Loader::parseName($name, 1) . 'Attr'; @@ -947,6 +963,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $value = strtotime($value); } break; + case 'timestamp': + $format = !empty($param) ? $param : $this->dateFormat; + $value = date($format, is_numeric($valiue) ? $value : strtotime($value)); + break; case 'object': if (is_object($value)) { $value = json_encode($value, JSON_FORCE_OBJECT); @@ -1008,6 +1028,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $format = !empty($param) ? $param : $this->dateFormat; $value = date($format, $value); break; + case 'timestamp': + $format = !empty($param) ? $param : $this->dateFormat; + $value = date($format, strtotime($value)); + break; case 'json': case 'array': $value = json_decode($value, true); diff --git a/library/think/db/connector/Oracle.php b/library/think/db/connector/Oracle.php index cc4f6496..ab35d7bc 100644 --- a/library/think/db/connector/Oracle.php +++ b/library/think/db/connector/Oracle.php @@ -102,6 +102,7 @@ class Oracle extends Connection */ public function getFields($tableName) { + $this->initConnect(true); list($tableName) = explode(' ', $tableName); $sql = "select a.column_name,data_type,DECODE (nullable, 'Y', 0, 1) notnull,data_default, DECODE (A .column_name,b.column_name,1,0) pk from all_tab_columns a,(select column_name from all_constraints c, all_cons_columns col where c.constraint_name = col.constraint_name and c.constraint_type = 'P' and c.table_name = '" . strtoupper($tableName) . "' ) b where table_name = '" . strtoupper($tableName) . "' and a.column_name = b.column_name (+)"; $pdo = $this->linkID->query($sql); diff --git a/library/think/db/connector/Pgsql.php b/library/think/db/connector/Pgsql.php index 58a33c34..a2c40b17 100644 --- a/library/think/db/connector/Pgsql.php +++ b/library/think/db/connector/Pgsql.php @@ -43,6 +43,7 @@ class Pgsql extends Connection */ public function getFields($tableName) { + $this->initConnect(true); list($tableName) = explode(' ', $tableName); $sql = 'select fields_name as "field",fields_type as "type",fields_not_null as "null",fields_key_name as "key",fields_default as "default",fields_default as "extra" from table_msg(' . $tableName . ');'; $pdo = $this->linkID->query($sql); diff --git a/library/think/db/connector/Sqlite.php b/library/think/db/connector/Sqlite.php index e3b03afb..cac8c352 100644 --- a/library/think/db/connector/Sqlite.php +++ b/library/think/db/connector/Sqlite.php @@ -40,6 +40,7 @@ class Sqlite extends Connection */ public function getFields($tableName) { + $this->initConnect(true); list($tableName) = explode(' ', $tableName); $sql = 'PRAGMA table_info( ' . $tableName . ' )'; $pdo = $this->linkID->query($sql); diff --git a/library/think/db/connector/Sqlsrv.php b/library/think/db/connector/Sqlsrv.php index 2eead773..cfc80991 100644 --- a/library/think/db/connector/Sqlsrv.php +++ b/library/think/db/connector/Sqlsrv.php @@ -50,6 +50,7 @@ class Sqlsrv extends Connection */ public function getFields($tableName) { + $this->initConnect(true); list($tableName) = explode(' ', $tableName); $sql = "SELECT column_name, data_type, column_default, is_nullable FROM information_schema.tables AS t