weizong song 4 months ago
parent 5886041d03
commit e11a977c79

@ -44,7 +44,7 @@ class FixOrderItemsPaidAt extends Command
public function handle()
{
$date = $this->argument('date');
// 验证日期格式
try {
$serviceDate = Carbon::createFromFormat('Y-m-d', $date);
@ -103,7 +103,7 @@ class FixOrderItemsPaidAt extends Command
try {
// 获取客户ID
$customerId = $item->order ? $item->order->customer_id : null;
if (!$customerId) {
if (!$isDryRun) {
$this->line('');
@ -114,14 +114,14 @@ class FixOrderItemsPaidAt extends Command
continue;
}
// 计算在 service_date 23:59:59 时的客户余额
$balanceAtTime = $this->calculateCustomerBalanceAtTime($customerId, $serviceDateEnd, $item->id);
// 计算在 service_date 时的客户余额
$balanceAtTime = $this->calculateCustomerBalanceAtTime($customerId, $serviceDateStr, $item->id);
// 判断是否满足修复条件
if ($balanceAtTime >= $item->total) {
// 满足修复条件
$originalPaidAt = $item->paid_at;
// 检查是否有关联的 balance 记录
$balanceRecord = Balance::where('belongs_type', OrderItems::class)
->where('belongs_id', $item->id)
@ -165,7 +165,7 @@ class FixOrderItemsPaidAt extends Command
DB::commit();
$fixedCount++;
Log::info("修复订单项 {$item->id}:原 paid_at {$originalPaidAt} -> {$serviceDateEnd}");
} catch (\Exception $e) {
DB::rollBack();
@ -213,17 +213,17 @@ class FixOrderItemsPaidAt extends Command
}
$this->line('');
$this->line('');
// 试运行模式:显示详细预览信息
if ($isDryRun && !empty($previewData)) {
$this->info("=== 预览详情 ===");
$this->line('');
// 显示满足条件的记录
$willFix = array_filter($previewData, function($item) {
return !isset($item['skip_reason']);
});
if (!empty($willFix)) {
$this->info("满足条件将修复的记录(" . count($willFix) . " 条):");
$this->line('');
@ -245,12 +245,12 @@ class FixOrderItemsPaidAt extends Command
);
$this->line('');
}
// 显示跳过的记录
$willSkip = array_filter($previewData, function($item) {
return isset($item['skip_reason']);
});
if (!empty($willSkip)) {
$this->warn("不满足条件将跳过的记录(" . count($willSkip) . " 条):");
$this->line('');
@ -272,7 +272,7 @@ class FixOrderItemsPaidAt extends Command
$this->line('');
}
}
// 输出统计信息
$this->info(($isDryRun ? "预览" : "修复") . "完成!");
$this->table(
@ -284,7 +284,7 @@ class FixOrderItemsPaidAt extends Command
['处理失败', $errorCount],
]
);
if ($isDryRun) {
$this->line('');
$this->comment("提示:这是试运行模式,没有执行实际修复。");

Loading…
Cancel
Save