diff --git a/zhctproject/store/application/p/logic/SportExperience.php b/private/tmp/cdx-store-sport-archive-20261010/source/application/p/logic/SportExperience.php index 6b593ba..fb48e57 100644 --- a/zhctproject/store/application/p/logic/SportExperience.php +++ b/private/tmp/cdx-store-sport-archive-20261010/source/application/p/logic/SportExperience.php @@ -29,7 +29,7 @@ class SportExperience public function add($params, $createBy) { try { $params['uuid'] = guid(); - $params['create_by'] = $createBy; + $params['create_by'] = self::normalizeCreateBy($createBy, ltrim((string)\think\Config::get('database.type'), '\\') === \app\cores\database\Dm::class); $params['create_time'] = date("Y-m-d H:i:s"); $res = $this->model->add($params); if(!$res) { @@ -41,6 +41,12 @@ class SportExperience return ['code' => 0, 'message' => '新建成功', 'data' => []]; } + /** Preserve this legacy VARCHAR(32) field's observed non-strict MySQL truncation. */ + private static function normalizeCreateBy(string $value, bool $isDm): string + { + return $isDm ? mb_substr($value, 0, 32, 'UTF-8') : $value; + } + /** * 电子档案--运动经历列表 * @author 李鑫 @@ -65,9 +71,31 @@ class SportExperience */ public function info($uuid) { $info = $this->model->read($uuid); + if (is_array($info)) { + $info = self::normalizeInfoCreateTime($info, ltrim((string)\think\Config::get('database.type'), '\\') === \app\cores\database\Dm::class); + } return ['code' => 0, 'message' => '', 'data' => $info]; } + /** Only this detail's MySQL DATETIME(0) field is normalized at the JSON boundary. */ + private static function normalizeInfoCreateTime(array $info, bool $isDm): array + { + $value = $info['create_time'] ?? null; + if (!$isDm || !is_string($value) + || !preg_match('/^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\.\d{1,6}$/D', $value, $parts) + ) { + return $info; + } + $date = \DateTime::createFromFormat('!Y-m-d H:i:s', $parts[1]); + $errors = \DateTime::getLastErrors(); + if ($date && ($errors === false || ($errors['warning_count'] === 0 && $errors['error_count'] === 0)) + && $date->format('Y-m-d H:i:s') === $parts[1] + ) { + $info['create_time'] = $parts[1]; + } + return $info; + } + /** * @电子档案--运动经历编辑 * @author 李鑫 @@ -112,4 +140,4 @@ class SportExperience } return ['code' => 0, 'message' => '删除成功', 'data' => []]; } -} \ No newline at end of file +}