59 lines
2.1 KiB
PHP
59 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Modules\EcommerceFinance\Services;
|
|
|
|
use App\Business\UpstreamBusinessInformation;
|
|
use Modules\EcommerceFinance\Contracts\UpstreamSnapshotRefresher;
|
|
use Modules\EcommerceFinance\Repositories\OrderDataRepository;
|
|
use Modules\EcommerceFinance\Repositories\ProductPriceRepository;
|
|
|
|
/**
|
|
* 将经营分析副本库已登记的业务信息查询还原为共享快照刷新任务。
|
|
*/
|
|
class OperationsReplicaSnapshotRefresher implements UpstreamSnapshotRefresher
|
|
{
|
|
private const SOURCE = 'operations_replica';
|
|
|
|
public function __construct(
|
|
private readonly UpstreamQueryCacheFactory $caches,
|
|
private readonly UpstreamBusinessInformation $information,
|
|
private readonly OrderDataRepository $orders,
|
|
private readonly ProductPriceRepository $productPrices,
|
|
) {
|
|
}
|
|
|
|
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),
|
|
),
|
|
'supplier-payables.product-prices.list' => $this->productPrices->paginate(
|
|
(array) ($parameters['filters'] ?? []),
|
|
(int) ($parameters['page'] ?? 1),
|
|
(int) ($parameters['limit'] ?? 25),
|
|
),
|
|
default => $this->information->snapshot($scope, $parameters),
|
|
},
|
|
);
|
|
}
|
|
}
|