946684800) { return date('Y-m-d H:i:s', (int)$value); } $s = trim((string)$value); if ($s === '' || preg_match('/^0000-00-00/i', $s)) { return ''; } if (preg_match('/^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/', $s, $m)) { return $m[1]; } if (preg_match('/^(\d{4}-\d{2}-\d{2})$/', $s, $m)) { return $m[1] . ' 00:00:00'; } if (preg_match('/^(\d{4}-\d{2}-\d{2})/', $s, $m)) { $ts = strtotime($s); return ($ts !== false && $ts > 0) ? date('Y-m-d H:i:s', $ts) : $m[1] . ' 00:00:00'; } $ts = strtotime($s); return ($ts !== false && $ts > 0) ? date('Y-m-d H:i:s', $ts) : $s; } /** 兼容旧调用:与 formatDisplayDateTime 相同 */ public static function formatDisplayDate($value): string { return self::formatDisplayDateTime($value); } /** 排序/月份统计用 Unix 时间 */ public static function parseToTimestamp($value): int { if ($value === null || $value === '') { return 0; } if (is_numeric($value) && (int)$value > 946684800) { return (int)$value; } $s = trim((string)$value); if ($s === '' || preg_match('/^0000-00-00/i', $s)) { return 0; } if (preg_match('/^(\d{4}-\d{2}-\d{2})(?:\s+\d{2}:\d{2}:\d{2})?/', $s)) { $ts = strtotime($s); return ($ts !== false && $ts > 0) ? $ts : 0; } $ts = strtotime($s); return ($ts !== false && $ts > 0) ? $ts : 0; } /** * @param int[] $scydgyIds * @param array $actions * @return array scydgy_id => unix */ public static function loadOperLogTimestampMap(array $scydgyIds, array $actions): array { $out = []; $scydgyIds = array_values(array_unique(array_filter(array_map('intval', $scydgyIds)))); $actions = array_values(array_filter(array_map('strval', $actions))); if ($scydgyIds === [] || $actions === []) { return $out; } try { $logs = Db::table('purchase_order_oper_log') ->where('scydgy_id', 'in', $scydgyIds) ->where('action', 'in', $actions) ->field('scydgy_id,createtime') ->order('id', 'asc') ->select(); } catch (\Throwable $e) { return $out; } if (!is_array($logs)) { return $out; } foreach ($logs as $log) { if (!is_array($log)) { continue; } $sid = (int)($log['scydgy_id'] ?? 0); $ct = self::parseToTimestamp($log['createtime'] ?? null); if ($sid > 0 && $ct > 946684800) { $out[$sid] = isset($out[$sid]) ? max($out[$sid], $ct) : $ct; } } return $out; } /** * 已完结时间:与详情进度一致,优先采购确认/直接完结操作日志 * * @param array $row * @param array $completeTsMap * @return array{ts:int, text:string} */ public static function resolveCompletedDone(array $row, array $completeTsMap = []): array { $sid = (int)($row['scydgy_id'] ?? 0); $ts = 0; $text = ''; if ($sid > 0 && isset($completeTsMap[$sid]) && (int)$completeTsMap[$sid] > 946684800) { $ts = (int)$completeTsMap[$sid]; } if ($ts <= 0) { foreach (['pick_time', 'createtime', 'dStamp'] as $key) { $t = self::parseToTimestamp($row[$key] ?? null); if ($t > $ts) { $ts = $t; } } } if ($ts > 0) { $text = date('Y-m-d H:i:s', $ts); } return ['ts' => $ts, 'text' => $text]; } /** * 操作记录展示文案:统一步骤用语(下发 / 确认供应商 / 审核确认供应商) */ public static function formatOperLogContent(string $content, string $action = ''): string { $content = trim($content); if ($content === '') { return ''; } $action = trim($action); if ($action === 'purchase_confirm') { if (preg_match('/[「『](.+?)[」』]/u', $content, $m)) { return '审核确认供应商:已选定「' . trim($m[1]) . '」'; } } if ($action === 'audit_select') { if (preg_match('/选定[::]\s*(.+)$/u', $content, $m)) { $name = trim($m[1]); if (preg_match('/^确认供应商/u', $content) && preg_match('/订单([^),]+)/u', $content, $om)) { return '确认供应商(订单' . trim($om[1]) . '):已选定「' . $name . '」'; } return '确认供应商:已选定「' . $name . '」'; } } if ($action === 'bid_open_verify') { if (preg_match('/开标验证/u', $content)) { return $content; } return '开标验证:' . $content; } if ($action === 'issue_submit') { if (preg_match('/通知供应商[((](\d+)\s*家[))].*?[::]\s*(.+)$/u', $content, $m)) { return '下发:通知供应商(' . $m[1] . ' 家):' . trim($m[2]); } } $content = preg_replace('/^采购确认:已选中供应商/u', '审核确认供应商:已选定', $content); $content = preg_replace('/^采购确认:/u', '审核确认供应商:', $content); $content = preg_replace('/已选中供应商/u', '已选定', $content); $content = preg_replace('/^(合并)?(协助|外发)初选/u', '下发', $content); $content = preg_replace('/^采购终审驳回/u', '审核驳回', $content); $content = preg_replace('/退回外发初选/u', '退回协助初选', $content); $content = preg_replace('/^重新下发(([^)]+)),/u', '重新下发($1):', $content); $content = preg_replace('/;+$/u', '', $content); return trim($content); } }