90 lines
4.2 KiB
PHP
90 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\EcommerceFinance\Services;
|
|
|
|
use InvalidArgumentException;
|
|
use Modules\EcommerceFinance\Contracts\UpstreamSnapshotRefresher;
|
|
use Modules\EcommerceFinance\Repositories\GoodsReconciliationRepository;
|
|
use Modules\EcommerceFinance\Repositories\SupplierPayableRepository;
|
|
|
|
/**
|
|
* 将活跃查询登记项还原成仓库调用,供定时任务刷新本地快照。
|
|
*/
|
|
class JianSunSnapshotRefresher implements UpstreamSnapshotRefresher
|
|
{
|
|
public function __construct(
|
|
private readonly JianSunQueryCache $cache,
|
|
private readonly GoodsReconciliationRepository $goods,
|
|
private readonly SupplierPayableRepository $supplier,
|
|
) {
|
|
}
|
|
|
|
public function sourceKey(): string
|
|
{
|
|
return 'jiansun';
|
|
}
|
|
|
|
public function refresh(array $entry): string
|
|
{
|
|
$scope = (string) ($entry['scope'] ?? '');
|
|
$parameters = (array) ($entry['parameters'] ?? []);
|
|
|
|
return $this->cache->refresh(
|
|
$scope,
|
|
$parameters,
|
|
fn () => $this->resolve($scope, $parameters)
|
|
);
|
|
}
|
|
|
|
private function resolve(string $scope, array $parameters): mixed
|
|
{
|
|
$filters = (array) ($parameters['filters'] ?? []);
|
|
$page = max((int) ($parameters['page'] ?? 1), 1);
|
|
$limit = min(max((int) ($parameters['limit'] ?? 25), 1), 100);
|
|
|
|
return match ($scope) {
|
|
'goods.list' => $this->goods->list($filters, $page, $limit),
|
|
'goods.summary' => $this->goods->summary($filters),
|
|
'goods.options' => $this->goods->filterOptions(),
|
|
|
|
'return-reconciliations.list' => $this->supplier->returnReconciliations($filters, $page, $limit),
|
|
'return-reconciliations.summary' => $this->supplier->returnReconciliationSummary($filters),
|
|
'return-reconciliations.options' => $this->supplier->filterOptionsForReturn(),
|
|
|
|
'invoice-deductions.list' => $this->supplier->invoiceDeductions($filters, $page, $limit),
|
|
'invoice-deductions.summary' => $this->supplier->invoiceDeductionSummary($filters),
|
|
'invoice-deductions.options' => $this->supplier->filterOptionsForInvoice(),
|
|
|
|
'compensation-details.list' => $this->supplier->compensationDetails($filters, $page, $limit),
|
|
'compensation-details.summary' => $this->supplier->compensationDetailSummary($filters),
|
|
'compensation-details.options' => $this->supplier->filterOptionsForCompensation(),
|
|
|
|
'advance-details.list' => $this->supplier->advanceDetails($filters, $page, $limit),
|
|
'advance-details.summary' => $this->supplier->advanceDetailSummary($filters),
|
|
'advance-details.options' => $this->supplier->filterOptionsForAdvance(),
|
|
|
|
'delivery-unpriced.list' => $this->supplier->deliveryUnpriced($filters, $page, $limit),
|
|
'delivery-unpriced.summary' => $this->supplier->deliveryUnpricedSummary($filters),
|
|
'delivery-unpriced.options' => $this->supplier->filterOptionsForDeliveryUnpriced(),
|
|
|
|
'return-unpriced.list' => $this->supplier->returnUnpriced($filters, $page, $limit),
|
|
'return-unpriced.summary' => $this->supplier->returnUnpricedSummary($filters),
|
|
'return-unpriced.options' => $this->supplier->filterOptionsForReturnUnpriced(),
|
|
|
|
'sample-deductions.list' => $this->supplier->sampleDeductions($filters, $page, $limit),
|
|
'sample-deductions.summary' => $this->supplier->sampleDeductionSummary($filters),
|
|
'sample-deductions.options' => $this->supplier->filterOptionsForSample(),
|
|
|
|
'other-adjustments.list' => $this->supplier->otherAdjustments($filters, $page, $limit),
|
|
'other-adjustments.summary' => $this->supplier->otherAdjustmentsSummary($filters),
|
|
'other-adjustments.options' => $this->supplier->filterOptionsForOtherAdjustments(),
|
|
|
|
'dropshipping-express.list' => $this->supplier->dropshippingExpress($filters, $page, $limit),
|
|
'dropshipping-express.summary' => $this->supplier->dropshippingExpressSummary($filters),
|
|
'dropshipping-express.options' => $this->supplier->filterOptionsForDropshippingExpress(),
|
|
|
|
default => throw new InvalidArgumentException('未知的上游快照类型:' . $scope),
|
|
};
|
|
}
|
|
}
|