fix: preserve lifecycle effective dates
This commit is contained in:
parent
f6f66b6ff1
commit
e33f22a24f
@ -187,9 +187,11 @@ class StoreReportRepository
|
||||
$month = $this->connection->getDriverName() === 'sqlite'
|
||||
? "substr(d.occurred_on, 1, 7)"
|
||||
: "DATE_FORMAT(d.occurred_on, '%Y-%m')";
|
||||
// 生命周期记录的生效时间严格来自存续表;只有没有存续表记录的店铺
|
||||
// 才会在 fallbackSales() 中使用默认的 2026-07-01。
|
||||
$lowerBound = $this->connection->getDriverName() === 'sqlite'
|
||||
? 'date(d.occurred_on) >= date(COALESCE(l.effective_at, ?))'
|
||||
: 'd.occurred_on >= COALESCE(l.effective_at, ?)';
|
||||
? 'date(d.occurred_on) >= date(l.effective_at)'
|
||||
: 'd.occurred_on >= l.effective_at';
|
||||
$upperBound = $this->connection->getDriverName() === 'sqlite'
|
||||
? 'date(d.occurred_on) < date(COALESCE(l.expires_at, ?))'
|
||||
: 'd.occurred_on < COALESCE(l.expires_at, ?)';
|
||||
@ -209,7 +211,6 @@ class StoreReportRepository
|
||||
GROUP BY l.id, {$month}",
|
||||
[
|
||||
$dailyGeneration,
|
||||
self::DEFAULT_EFFECTIVE_AT,
|
||||
self::DEFAULT_EXPIRES_AT,
|
||||
$lifecycleGeneration,
|
||||
...$chunk,
|
||||
|
||||
@ -112,6 +112,22 @@ class StoreReportRepositoryTest extends TestCase
|
||||
$this->assertSame('存续中', $rows[0]['invalid_at']);
|
||||
}
|
||||
|
||||
public function test_lifecycle_effective_date_before_default_is_preserved(): void
|
||||
{
|
||||
$this->insertLifecycle('店铺A', '历史主体', '2026-05-15 00:00:00', '2026-06-20 00:00:00');
|
||||
$this->insertBill('店铺A', '2026-05-20 10:00:00', 18);
|
||||
$this->insertBill('店铺A', '2026-07-05 10:00:00', 30);
|
||||
|
||||
$rows = $this->repository->rows([
|
||||
['erp_store_name' => '店铺A', 'company_name' => '店铺主体', 'store_status' => '0'],
|
||||
], 2026);
|
||||
|
||||
$this->assertCount(1, $rows);
|
||||
$this->assertSame('2026-05-15', $rows[0]['effective_at']);
|
||||
$this->assertSame('2026-06-20', $rows[0]['invalid_at']);
|
||||
$this->assertSame(18.0, $rows[0]['period_sales']);
|
||||
}
|
||||
|
||||
public function test_unfinished_shared_daily_summary_is_reported_instead_of_returning_misleading_zeroes(): void
|
||||
{
|
||||
DB::connection('business_mirror')->table('store_report_import_states')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user