From c641b5cb1f60bab74f86ebfc05ea3bf3513be6ff Mon Sep 17 00:00:00 2001 From: mzl Date: Tue, 29 Jul 2025 19:02:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/command/DomainCommand.php | 2 +- app/command/FixInquiryLogOrderNo.php | 100 +++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 app/command/FixInquiryLogOrderNo.php diff --git a/app/command/DomainCommand.php b/app/command/DomainCommand.php index d3c7496..d23e755 100644 --- a/app/command/DomainCommand.php +++ b/app/command/DomainCommand.php @@ -41,7 +41,7 @@ class DomainCommand extends Command * @param string $oldDomain 旧域名(如: http://219.157.255.213:25326) * @return string 处理后的富文本内容 */ -function processRichTextImagesEnhanced($content, $newDomain = 'https://fdesk.hnxinyouhe.com', $oldDomain = 'http://219.157.255.213:25326') { +function processRichTextImagesEnhanced($content, $newDomain = 'https://x-server.hnxinyouhe.com', $oldDomain = 'http://219.157.255.213:25326') { // 标准化域名格式(去除末尾斜杠) $newDomain = rtrim($newDomain, '/'); $oldDomain = rtrim($oldDomain, '/'); diff --git a/app/command/FixInquiryLogOrderNo.php b/app/command/FixInquiryLogOrderNo.php new file mode 100644 index 0000000..ed959cd --- /dev/null +++ b/app/command/FixInquiryLogOrderNo.php @@ -0,0 +1,100 @@ +writeln('Starting duplicate order_no fix process...'); + + // Find all duplicate order_no values using Laravel-style query + $duplicates = Db::table('inquiry_log') + ->select('order_no', Db::raw('COUNT(*) as count')) + ->groupBy('order_no') + ->having('count', '>', 1) + ->get(); + + if ($duplicates->isEmpty()) { + $output->writeln('No duplicate order_no values found.'); + Db::commit(); + return self::SUCCESS; + } + + $output->writeln(sprintf('Found %d order_no values with duplicates.', $duplicates->count())); + + $totalFixed = 0; + + foreach ($duplicates as $dup) { + $orderNo = $dup->order_no; + + $output->writeln("Processing duplicates for order_no: {$orderNo}"); + + // Get all records with this order_no, ordered by created_at (oldest first) + $records = Db::table('inquiry_log') + ->where('order_no', $orderNo) + ->orderBy('created_at', 'asc') + ->get(); + + // Keep the first record as is, modify the rest + $keepOriginal = true; + + foreach ($records as $record) { + if ($keepOriginal) { + $output->writeln("Keeping original record ID {$record->id} with order_no {$record->order_no}"); + $keepOriginal = false; + continue; + } + + // Generate new order_no by appending suffix + $newOrderNo = orderNum(); + $output->writeln("Updating record ID {$record->id} from {$record->order_no} to {$newOrderNo}"); + + // Update the record + Db::table('inquiry_log') + ->where('id', $record->id) + ->update(['order_no' => $newOrderNo]); + + $totalFixed++; + + sleep(1); + } + } + + Db::commit(); + $output->writeln("Successfully fixed {$totalFixed} duplicate records."); + + // Verify no duplicates remain + $remainingDuplicates = Db::table('inquiry_log') + ->select('order_no', Db::raw('COUNT(*) as count')) + ->groupBy('order_no') + ->having('count', '>', 1) + ->get(); + + if ($remainingDuplicates->isEmpty()) { + $output->writeln('Verification: No duplicate order_no values remain.'); + } else { + $output->writeln('Warning: Some duplicates still remain. Please run the command again.'); + } + + return self::SUCCESS; + } catch (\Throwable $e) { + Db::rollback(); + $output->writeln("Error: " . $e->getMessage()); + Log::error("FixInquiryLogOrderNo command failed: " . $e->getMessage()); + return self::FAILURE; + } + } +} \ No newline at end of file