CaiWuXiTong/modules/EcommerceFinance/Services/OperationsReplicaSnapshotRefresher.php

52 lines
1.7 KiB
PHP

<?php
namespace Modules\EcommerceFinance\Services;
use App\Business\UpstreamBusinessInformation;
use Modules\EcommerceFinance\Contracts\UpstreamSnapshotRefresher;
use Modules\EcommerceFinance\Repositories\OrderDataRepository;
/**
* 将经营分析副本库已登记的业务信息查询还原为共享快照刷新任务。
*/
class OperationsReplicaSnapshotRefresher implements UpstreamSnapshotRefresher
{
private const SOURCE = 'operations_replica';
public function __construct(
private readonly UpstreamQueryCacheFactory $caches,
private readonly UpstreamBusinessInformation $information,
private readonly OrderDataRepository $orders,
) {
}
public function sourceKey(): string
{
return self::SOURCE;
}
public function refresh(array $entry): string
{
$scope = (string) ($entry['scope'] ?? '');
$parameters = (array) ($entry['parameters'] ?? []);
return $this->caches->forSource(self::SOURCE)->refresh(
$scope,
$parameters,
fn () => match ($scope) {
'order-data.after-sales.list' => $this->orders->afterSales(
(array) ($parameters['filters'] ?? []),
(int) ($parameters['page'] ?? 1),
(int) ($parameters['limit'] ?? 25),
),
'order-data.promotion.list' => $this->orders->promotionExpenses(
(array) ($parameters['filters'] ?? []),
(int) ($parameters['page'] ?? 1),
(int) ($parameters['limit'] ?? 25),
),
default => $this->information->snapshot($scope, $parameters),
},
);
}
}