--- a/application/p/logic/FeedingHistory.php +++ b/application/p/logic/FeedingHistory.php @@ -29,7 +29,7 @@ class FeedingHistory 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) { @@ -51,6 +51,11 @@ class FeedingHistory * @param $field * @return array */ + private static function normalizeCreateBy(string $value, bool $isDm): string + { + return $isDm ? mb_substr($value, 0, 32, 'UTF-8') : $value; + } + public function lists($where, $page, $page_size, $order, $field) { $data['rows'] = $this->model->inquiry($where, $page, $page_size, $order, $field); $data['total'] = $this->model->inquiryCount($where); @@ -65,9 +70,25 @@ class FeedingHistory */ public function info($uuid) { $info = $this->model->read($uuid); + if (is_array($info)) { + $info = self::normalizeReadCreateTime($info, ltrim((string)\think\Config::get('database.type'), '\\') === \app\cores\database\Dm::class); + } return ['code' => 0, 'message' => '', 'data' => $info]; } + private static function normalizeReadCreateTime(array $row, bool $isDm): array + { + $value = $row['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 $row; + } + $date = \DateTime::createFromFormat('!Y-m-d H:i:s', $parts[1]); + if ($date && substr($parts[1], 0, 4) !== '0000' && $date->format('Y-m-d H:i:s') === $parts[1]) { + $row['create_time'] = $parts[1]; + } + return $row; + } + /** * @电子档案--输送历史编辑 * @author 李鑫 @@ -112,4 +133,4 @@ class FeedingHistory } return ['code' => 0, 'message' => '删除成功', 'data' => []]; } -} \ No newline at end of file +}