From 0429cf62c491c62fb6077a6685da16fe02dbc50d Mon Sep 17 00:00:00 2001 From: zhenhui <1276357500@qq.com> Date: Wed, 1 Apr 2026 15:27:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96CURD=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/crud/Crud.php | 7 +++++++ app/admin/library/crud/stubs/mixins/controller/index.stub | 1 + app/admin/library/traits/Backend.php | 1 + 3 files changed, 9 insertions(+) diff --git a/app/admin/controller/crud/Crud.php b/app/admin/controller/crud/Crud.php index 992cee8..0ca7e13 100644 --- a/app/admin/controller/crud/Crud.php +++ b/app/admin/controller/crud/Crud.php @@ -581,6 +581,13 @@ class Crud extends Backend private function parseModelMethods($field, &$modelData): void { + // MySQL bigint/int 时间戳字段:显式声明为 integer,避免 ThinkORM 自动时间戳写入 'now' 字符串 + if (in_array($field['name'] ?? '', ['create_time', 'update_time', 'createtime', 'updatetime'], true) + && in_array($field['type'] ?? '', ['int', 'bigint'], true) + ) { + $modelData['fieldType'][$field['name']] = 'integer'; + } + if (($field['designType'] ?? '') == 'array') { $modelData['fieldType'][$field['name']] = 'json'; } elseif (!in_array($field['name'], ['create_time', 'update_time', 'updatetime', 'createtime']) diff --git a/app/admin/library/crud/stubs/mixins/controller/index.stub b/app/admin/library/crud/stubs/mixins/controller/index.stub index 24cba92..3f8e53f 100644 --- a/app/admin/library/crud/stubs/mixins/controller/index.stub +++ b/app/admin/library/crud/stubs/mixins/controller/index.stub @@ -18,6 +18,7 @@ list($where, $alias, $limit, $order) = $this->queryBuilder(); $res = $this->model ->withJoin($this->withJoinTable, $this->withJoinType) + ->with($this->withJoinTable) {%relationVisibleFields%} ->alias($alias) ->where($where) diff --git a/app/admin/library/traits/Backend.php b/app/admin/library/traits/Backend.php index 5eae2a3..356950a 100644 --- a/app/admin/library/traits/Backend.php +++ b/app/admin/library/traits/Backend.php @@ -50,6 +50,7 @@ trait Backend $res = $this->model ->field($this->indexField) ->withJoin($this->withJoinTable, $this->withJoinType) + ->with($this->withJoinTable) ->alias($alias) ->where($where) ->order($order)