From cdcbdfe0e35f824bac3113278ef52da9dbc3e4a0 Mon Sep 17 00:00:00 2001 From: renshen <1005457301@qq.com> Date: Wed, 21 Oct 2026 13:53:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=94=AE=E5=90=8E=E8=B4=B9?= =?UTF-8?q?=E7=94=A8=E5=AF=BC=E5=85=A5=EF=BC=9A=E5=8F=AA=E6=9C=89=E5=AE=8C?= =?UTF-8?q?=E6=95=B4=E8=A6=86=E7=9B=96=E6=89=80=E9=80=89=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E6=97=B6=E6=89=8D=E4=BD=BF=E7=94=A8=E5=AF=BC=E5=85=A5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AfterSalesCostRowRepository.php | 25 ++++++++++++++++- .../Business/AfterSalesCostImportTest.php | 28 +++++++++++++++++-- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/modules/EcommerceFinance/Repositories/AfterSalesCostRowRepository.php b/modules/EcommerceFinance/Repositories/AfterSalesCostRowRepository.php index 57fa7358..2a28da84 100644 --- a/modules/EcommerceFinance/Repositories/AfterSalesCostRowRepository.php +++ b/modules/EcommerceFinance/Repositories/AfterSalesCostRowRepository.php @@ -43,7 +43,30 @@ class AfterSalesCostRowRepository return false; } - return $this->filtered($filters)->limit(1)->exists(); + // 指定单号时,导入表里命中该单就完整(同单的所有明细行都在导入数据里)。 + if (trim((string) ($filters['order_no'] ?? '')) !== '') { + return $this->filtered($filters)->limit(1)->exists(); + } + + $from = trim((string) ($filters['from'] ?? '')); + $to = trim((string) ($filters['to'] ?? '')); + + // 不限日期时无法保证覆盖范围,回退镜像,避免把导入数据当成全量。 + if ($from === '' || $to === '') { + return false; + } + + $range = $this->filtered(['shop_names' => $filters['shop_names'] ?? []]) + ->selectRaw('MIN(order_time) as min_time, MAX(order_time) as max_time') + ->first(); + + if (! $range || $range->min_time === null) { + return false; + } + + // 只有导入范围完整覆盖所选日期时才使用导入数据,避免跨月时数据不全。 + return substr((string) $range->min_time, 0, 10) <= $from + && substr((string) $range->max_time, 0, 10) >= $to; } /** diff --git a/tests/Feature/Business/AfterSalesCostImportTest.php b/tests/Feature/Business/AfterSalesCostImportTest.php index 6378ad3c..97a26d58 100644 --- a/tests/Feature/Business/AfterSalesCostImportTest.php +++ b/tests/Feature/Business/AfterSalesCostImportTest.php @@ -27,6 +27,26 @@ class AfterSalesCostImportTest extends FeatureTestCase 'combine_type' => '组合单品', ])); + DB::table('ops_after_sales_cost_rows')->insert(AfterSalesCostRowRepository::toRecord([ + 'shop_name' => '天猫-亿家达旗舰店', + 'online_order_no' => '5120748758529014000', + 'product_code' => 'SJ038999N1410V01', + 'order_time' => '2026-06-01 00:00:00', + 'product_quantity' => 1, + 'product_amount' => 10, + 'product_cost' => 5, + ])); + + DB::table('ops_after_sales_cost_rows')->insert(AfterSalesCostRowRepository::toRecord([ + 'shop_name' => '天猫-亿家达旗舰店', + 'online_order_no' => '5120748758529014001', + 'product_code' => 'SJ038998N1410V01', + 'order_time' => '2026-06-30 23:00:00', + 'product_quantity' => 1, + 'product_amount' => 10, + 'product_cost' => 5, + ])); + $result = app(OrderDataPageData::class)->afterSalesRows([ 'from' => '2026-06-01', 'to' => '2026-06-30', @@ -36,9 +56,11 @@ class AfterSalesCostImportTest extends FeatureTestCase ], 1, 20); $this->assertSame('imported', $result['status']['X-Caiwu-Data-Status']); - $this->assertCount(1, $result['rows']); - $this->assertSame('SJ038020N1410V02', $result['rows'][0]['product_code']); - $this->assertEquals(110.53, $result['rows'][0]['product_cost']); + $this->assertCount(3, $result['rows']); + + $target = collect($result['rows'])->firstWhere('product_code', 'SJ038020N1410V02'); + $this->assertNotNull($target); + $this->assertEquals(110.53, $target['product_cost']); } public function test_import_command_reads_the_jst_export_file(): void -- 2.47.2