diff --git a/app/Console/Commands/ComputeProductMonthlyWeightedAverage.php b/app/Console/Commands/ComputeProductMonthlyWeightedAverage.php index e4e9648e..064fe38f 100644 --- a/app/Console/Commands/ComputeProductMonthlyWeightedAverage.php +++ b/app/Console/Commands/ComputeProductMonthlyWeightedAverage.php @@ -196,38 +196,39 @@ class ComputeProductMonthlyWeightedAverage extends Command $previousStatus = trim((string) ($row->previous_pricing_status ?? '')); $changePrice = $change['price'] ?? null; $workPrice = $work['price'] ?? null; - // 方案乙:生效开始日期或记录时间为空 → 视为未匹配(用原始价格、保持预估价); - // 记录时间 > 次月2号(新价当月未生效)→ 取变价前价格、状态保持原状态;其余取变价后价格。 + // 最终规则:生效开始日期为空 → 未匹配到工作平台价格; + // 生效开始日期 > 本月,或记录时间 > 次月2号(记录时间为空视为 ≤ 次月2号)→ 新价当月未生效,取变价前价格。 $changeTime = $change['time'] ?? null; $changeCreated = $change['created'] ?? null; + $monthStart = $deadline->startOfMonth(); + $hasWorkPlatformRecord = $changePrice !== null && $changeTime !== null; $newPricePending = false; - if ($changePrice !== null && ($changeTime === null || $changeCreated === null)) { - $changePrice = null; - } elseif ($changePrice !== null && CarbonImmutable::parse($changeCreated)->greaterThan($deadline)) { - $newPricePending = true; - $changePrice = $change['before'] ?? $changePrice; + if ($hasWorkPlatformRecord) { + $newPricePending = CarbonImmutable::parse($changeTime)->greaterThanOrEqualTo($monthStart) + || ($changeCreated !== null && CarbonImmutable::parse($changeCreated)->greaterThan($deadline)); + $changePrice = $newPricePending ? ($change['before'] ?? $changePrice) : $changePrice; } + $previousStatus = in_array($previousStatus, ['预估价', '未定价'], true) ? '未定价' : $previousStatus; // 更改价格 + 定价状态(表2 第10条) if ($openingUnitPrice !== null) { - if ($previousStatus !== '预估价') { + if ($previousStatus !== '未定价') { $adjusted = $openingUnitPrice; $status = $previousStatus !== '' ? $previousStatus : '已定价'; - } elseif ($changePrice !== null) { + } elseif ($hasWorkPlatformRecord) { $adjusted = $changePrice; $status = $newPricePending ? '未定价' : '已定价'; } else { $adjusted = $openingUnitPrice; - // 未匹配到工作平台价格 → 用原始价格,状态统一记为「未定价」(原「预估价」)。 $status = '未定价'; } - } elseif ($changePrice !== null) { + } elseif ($hasWorkPlatformRecord) { $adjusted = $changePrice; - $status = '已定价'; + $status = $newPricePending ? '未定价' : '已定价'; } elseif ($cost !== null) { + // 方案①:能取到成本价即视为"有生效开始日期" → 已定价。 $adjusted = $cost; - // 无原始价格、未匹配工作平台价格但匹配到成本价 → 定价状态「未定价」。 - $status = '未定价'; + $status = '已定价'; } else { $adjusted = null; $status = '待人工核查';