Merge branch 'master' of /mnt/git/v2.tiantianxinye.365care

master
songweizong 5 months ago
commit 489b35ed5d

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

Loading…
Cancel
Save