26 lines
772 B
PHP
26 lines
772 B
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace app\common\model\traits;
|
||
|
||
/**
|
||
* 时间戳整型字段修复
|
||
*
|
||
* ThinkORM 对 MySQL bigint 类型识别为 'bigint',自动时间戳会错误地写入 'now' 字符串,
|
||
* 导致 SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'now' for column 'update_time'
|
||
*
|
||
* 通过显式指定 create_time、update_time 等为 integer 类型,使 ThinkORM 使用 time() 写入正确的时间戳。
|
||
*/
|
||
trait TimestampInteger
|
||
{
|
||
/**
|
||
* 字段类型映射:将 bigint 时间戳字段显式声明为 integer,避免 ThinkORM 写入 'now' 字符串
|
||
*/
|
||
protected array $type = [
|
||
'create_time' => 'integer',
|
||
'update_time' => 'integer',
|
||
'last_login_time' => 'integer',
|
||
];
|
||
}
|