CaiWuXiTong/app/Console/Commands/SyncStoreReportMirror.php
WuYongJie f7daee9305 feat: 店铺维度报表销量改取业绩明细的订单实付/实收金额
店铺维度报表(店铺管理 → 店铺维度报表)的销量原来按平台账单收入汇总,改为按
业绩明细(店铺收款匹配订单明细)的「订单实付/实收金额」汇总:

- 新增镜像表 store_report_paid_sales_rows:业绩明细按「店铺名称 + 发生时间」
  预汇总,页面按发生日期与主体生效/失效时间关联,拆分到对应主体期间;
- StoreReportRepository 的销量(period_sales / sales_NN)改读该汇总表,
  收入(rolling_12m_income / income_NN,主体维度经营报表用)仍读平台账单日汇总,
  两个口径分开统计、互不覆盖;
- StoreReportMirrorSynchronizer 增加 syncPaidSales():用「行数 + 最近写入时间 +
  订单实付合计」指纹判断业绩明细是否变化,变化才全量重建,未变化沿用当前版本;
- 新增命令 business-mirror:sync-store-report-paid-sales(含 --force),并在
  store-receipt:order-match:sync 成功后自动刷新一次。

验证:StoreReportRepositoryTest / StoreReportRepositoryFilterTest /
StoreReportMirrorSyncTest 共 23 个用例、110 个断言通过。
2026-10-16 23:50:25 +08:00

58 lines
2.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Modules\EcommerceFinance\Services\StoreReportMirrorSynchronizer;
use Throwable;
class SyncStoreReportMirror extends Command
{
protected $signature = 'business-mirror:sync-store-report
{--batch= : 每批最多读取账单行数}
{--max-batches= : 本轮最多处理账单批次数}
{--daily-batch= : 每批最多汇总原始账单行数}
{--daily-max-batches= : 本轮最多处理日汇总批次数}';
protected $description = '自动初始化并增量同步店铺维度报表共享镜像';
public function handle(StoreReportMirrorSynchronizer $synchronizer): int
{
if (! (bool) config('upstream_mirrors.refresh_enabled', false)
|| ! (bool) config('upstream_mirrors.store_report.enabled', true)) {
return self::SUCCESS;
}
try {
$result = $synchronizer->sync(
$this->option('batch') === null ? null : (int) $this->option('batch'),
$this->option('max-batches') === null ? null : (int) $this->option('max-batches'),
$this->option('daily-batch') === null ? null : (int) $this->option('daily-batch'),
$this->option('daily-max-batches') === null ? null : (int) $this->option('daily-max-batches'),
);
} catch (Throwable $exception) {
Log::error('店铺维度报表共享镜像同步失败。', ['exception' => $exception::class]);
$this->error('店铺维度报表共享镜像同步失败,页面继续读取上一版数据。');
return self::FAILURE;
}
$this->info(sprintf(
'店铺报表镜像:流程期间 %s/%d 行,主体变更 %s(检查 %d 店,新增 %d 条),账单 %s/%d 行,日汇总 %s/%d 行,销量汇总 %s/%d 行。',
$result['lifecycles']['status'],
$result['lifecycles']['source_rows'],
$result['period_changes']['status'],
$result['period_changes']['checked'],
$result['period_changes']['created'],
$result['bills']['status'],
$result['bills']['source_rows'],
$result['daily']['status'],
$result['daily']['source_rows'],
$result['paid_sales']['status'],
$result['paid_sales']['stored_rows'],
));
return self::SUCCESS;
}
}