diff --git a/app/Business/StoreReceiptPlantingDailySynchronizer.php b/app/Business/StoreReceiptPlantingDailySynchronizer.php index 479635c97..5a2d733bc 100644 --- a/app/Business/StoreReceiptPlantingDailySynchronizer.php +++ b/app/Business/StoreReceiptPlantingDailySynchronizer.php @@ -9,7 +9,7 @@ use RuntimeException; use Throwable; /** - * 每日编排:先核对标签覆盖,再同步种菜报销工单,最后重算业绩明细种菜金额。 + * 每日编排:先同步种菜报销工单,再核对标签覆盖,最后重算业绩明细种菜金额。 */ class StoreReceiptPlantingDailySynchronizer { @@ -37,15 +37,16 @@ class StoreReceiptPlantingDailySynchronizer throw new InvalidArgumentException('公司 ID 无效。'); } - $coverage = $this->labelCoverage->assertCovered( - $fromDate->toDateString(), - $toDate->toDateString(), - $companyId, - ); $months = $this->months($months, $toDate); $this->assertWorkOrderSourceReady(); if ($dryRun) { + $coverage = $this->labelCoverage->assertCovered( + $fromDate->toDateString(), + $toDate->toDateString(), + $companyId, + ); + return [ 'status' => 'ready', 'from' => $fromDate->toDateString(), @@ -65,6 +66,24 @@ class StoreReceiptPlantingDailySynchronizer ); } + try { + $coverage = $this->labelCoverage->assertCovered( + $fromDate->toDateString(), + $toDate->toDateString(), + $companyId, + ); + } catch (Throwable $exception) { + return [ + 'status' => 'failed', + 'error' => '种菜明细已同步,但标签覆盖检查失败:' . $exception->getMessage(), + 'from' => $fromDate->toDateString(), + 'to' => $toDate->toDateString(), + 'months' => $months, + 'planting_sync' => $plantingSync, + 'dry_run' => false, + ]; + } + return [ 'status' => 'ready_to_refresh', 'from' => $fromDate->toDateString(), diff --git a/app/Console/Commands/SyncStoreReceiptPlantingDaily.php b/app/Console/Commands/SyncStoreReceiptPlantingDaily.php index ef34997d1..82765ea44 100644 --- a/app/Console/Commands/SyncStoreReceiptPlantingDaily.php +++ b/app/Console/Commands/SyncStoreReceiptPlantingDaily.php @@ -49,6 +49,11 @@ class SyncStoreReceiptPlantingDaily extends Command return self::FAILURE; } + if (($result['status'] ?? '') === 'failed') { + $this->outputResult($result); + return self::FAILURE; + } + if ((bool) $this->option('dry-run')) { $this->outputResult($result); return self::SUCCESS; diff --git a/deploy/activate-incremental-release.sh b/deploy/activate-incremental-release.sh index 603b38cde..1f2ba6d9f 100644 --- a/deploy/activate-incremental-release.sh +++ b/deploy/activate-incremental-release.sh @@ -223,9 +223,9 @@ CRON_TZ=Asia/Shanghai # 聚水潭推广费用:每天汇总最近 7 天,覆盖迟到改单并供财务经营报表直接读取。 10 3 * * * root /usr/bin/timeout 1800 /bin/sh /opt/caiwuxitong/run-finance-batch.sh business-mirror:sync-promotion-expenses --days=7 --quiet >/dev/null 2>&1 # 聚水潭订单标签明细:先核对 2026-10-01 起逐日覆盖,补历史缺口,再刷新最近 7 天。 -10 6 * * * root /bin/sh /opt/caiwuxitong/run-finance-batch.sh jst-order-labels:sync-daily --from=2026-10-01 --company=1 --quiet >/dev/null 2>&1 -# 业绩明细种菜金额:每天 09:30 核查标签覆盖,同步本月/上月种菜报销并重算种菜金额。 -30 9 * * * root /bin/sh /opt/caiwuxitong/run-finance-batch.sh store-receipt:planting-daily --from=2026-10-01 --company=1 --quiet >/dev/null 2>&1 +10 6 * * * root CAIWU_BATCH_LOCK_WAIT=10800 /bin/sh /opt/caiwuxitong/run-finance-batch.sh jst-order-labels:sync-daily --from=2026-10-01 --company=1 --quiet >> /opt/caiwuxitong/runtime/sync-logs/jst-order-labels-daily.log 2>&1 +# 种菜明细与业绩种菜金额:每天 09:30 先同步本月/上月工单明细,再做标签覆盖和业绩重算。 +30 9 * * * root CAIWU_BATCH_LOCK_WAIT=10800 /bin/sh /opt/caiwuxitong/run-finance-batch.sh store-receipt:planting-daily --from=2026-10-01 --company=1 --quiet >> /opt/caiwuxitong/runtime/sync-logs/planting-daily.log 2>&1 # 商品月加权与成本:先算月加权单价,再同步商品成本,避免成本先于价格生成。 0 18 * * * root /bin/sh /opt/caiwuxitong/run-finance-batch.sh finance:monthly-weighted-product-cost:auto >/dev/null 2>&1 # 店铺违规信息预警:每天 05:30 把副本库抓取结果追平到统一表(本地补充字段不覆盖)。 diff --git a/deploy/activate-release.sh b/deploy/activate-release.sh index 9789f8d5b..3bcba02e9 100644 --- a/deploy/activate-release.sh +++ b/deploy/activate-release.sh @@ -227,9 +227,9 @@ CRON_TZ=Asia/Shanghai # 聚水潭推广费用:每天汇总最近 7 天,覆盖迟到改单并供财务经营报表直接读取。 10 3 * * * root /usr/bin/timeout 1800 /bin/sh /opt/caiwuxitong/run-finance-batch.sh business-mirror:sync-promotion-expenses --days=7 --quiet >/dev/null 2>&1 # 聚水潭订单标签明细:先核对 2026-10-01 起逐日覆盖,补历史缺口,再刷新最近 7 天。 -10 6 * * * root /bin/sh /opt/caiwuxitong/run-finance-batch.sh jst-order-labels:sync-daily --from=2026-10-01 --company=1 --quiet >/dev/null 2>&1 -# 业绩明细种菜金额:每天 09:30 核查标签覆盖,同步本月/上月种菜报销并重算种菜金额。 -30 9 * * * root /bin/sh /opt/caiwuxitong/run-finance-batch.sh store-receipt:planting-daily --from=2026-10-01 --company=1 --quiet >/dev/null 2>&1 +10 6 * * * root CAIWU_BATCH_LOCK_WAIT=10800 /bin/sh /opt/caiwuxitong/run-finance-batch.sh jst-order-labels:sync-daily --from=2026-10-01 --company=1 --quiet >> /opt/caiwuxitong/runtime/sync-logs/jst-order-labels-daily.log 2>&1 +# 种菜明细与业绩种菜金额:每天 09:30 先同步本月/上月工单明细,再做标签覆盖和业绩重算。 +30 9 * * * root CAIWU_BATCH_LOCK_WAIT=10800 /bin/sh /opt/caiwuxitong/run-finance-batch.sh store-receipt:planting-daily --from=2026-10-01 --company=1 --quiet >> /opt/caiwuxitong/runtime/sync-logs/planting-daily.log 2>&1 # 商品月加权与成本:先算月加权单价,再同步商品成本,避免成本先于价格生成。 0 18 * * * root /bin/sh /opt/caiwuxitong/run-finance-batch.sh finance:monthly-weighted-product-cost:auto >/dev/null 2>&1 # 店铺违规信息预警:每天 05:30 把副本库抓取结果追平到统一表(本地补充字段不覆盖)。 diff --git a/tests/Unit/Business/StoreReceiptPlantingDailySynchronizerTest.php b/tests/Unit/Business/StoreReceiptPlantingDailySynchronizerTest.php index b044aea61..f7485cb5b 100644 --- a/tests/Unit/Business/StoreReceiptPlantingDailySynchronizerTest.php +++ b/tests/Unit/Business/StoreReceiptPlantingDailySynchronizerTest.php @@ -86,14 +86,17 @@ class StoreReceiptPlantingDailySynchronizerTest extends TestCase $this->assertSame(['2026-10', '2026-11'], $result['months']); } - public function test_blocks_recalculation_when_label_coverage_is_not_ready(): void + public function test_syncs_planting_details_before_label_coverage_failure_blocks_recalculation(): void { $coverage = Mockery::mock(JstOrderLabelDailySynchronizer::class); $coverage->shouldReceive('assertCovered') ->once() ->andThrow(new \RuntimeException('历史数据检查未通过')); $workOrders = Mockery::mock(PlantingWorkOrderSynchronizer::class); - $workOrders->shouldNotReceive('sync'); + $workOrders->shouldReceive('sync') + ->once() + ->with('2026-10-01', '2026-10-31', 1) + ->andReturn(['orders' => 10, 'inserted' => 10]); $synchronizer = new StoreReceiptPlantingDailySynchronizer( app(DatabaseManager::class), @@ -101,8 +104,11 @@ class StoreReceiptPlantingDailySynchronizerTest extends TestCase $workOrders, ); - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('历史数据检查未通过'); - $synchronizer->sync('2026-10-01', '2026-10-31', 1, ['2026-10']); + $result = $synchronizer->sync('2026-10-01', '2026-10-31', 1, ['2026-10']); + + $this->assertSame('failed', $result['status']); + $this->assertSame(10, $result['planting_sync']['2026-10']['inserted']); + $this->assertStringContainsString('种菜明细已同步', $result['error']); + $this->assertStringContainsString('历史数据检查未通过', $result['error']); } }