119 lines
5.7 KiB
PHP
119 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace Modules\EcommerceFinance\Services;
|
|
|
|
use InvalidArgumentException;
|
|
use Modules\EcommerceFinance\Contracts\UpstreamSnapshotRefresher;
|
|
use Modules\EcommerceFinance\Repositories\EdgeBandingRepository;
|
|
use Modules\EcommerceFinance\Repositories\GoodsReconciliationRepository;
|
|
use Modules\EcommerceFinance\Repositories\PinduoduoSpreadBillRepository;
|
|
use Modules\EcommerceFinance\Repositories\SupplierPayableRepository;
|
|
|
|
/**
|
|
* 将活跃查询登记项还原成仓库调用,供定时任务刷新共享快照。
|
|
*/
|
|
class JianSunSnapshotRefresher implements UpstreamSnapshotRefresher
|
|
{
|
|
public function __construct(
|
|
private readonly JianSunQueryCache $cache,
|
|
private readonly EdgeBandingRepository $edgeBanding,
|
|
private readonly GoodsReconciliationRepository $goods,
|
|
private readonly PinduoduoSpreadBillRepository $pinduoduo,
|
|
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);
|
|
$storeName = isset($filters['store_name']) ? (string) $filters['store_name'] : null;
|
|
$fromDate = isset($filters['from']) ? (string) $filters['from'] : null;
|
|
$toDate = isset($filters['to']) ? (string) $filters['to'] : null;
|
|
$flowType = isset($filters['flow_type']) ? (string) $filters['flow_type'] : null;
|
|
$flowType = in_array($flowType, ['income', 'expense'], true) ? $flowType : null;
|
|
|
|
return match ($scope) {
|
|
'edge-banding.prices' => $this->edgeBanding->prices($filters, $page, $limit),
|
|
'edge-banding.details' => $this->edgeBanding->details($filters, $page, $limit),
|
|
'edge-banding.payables' => $this->edgeBanding->payables($filters, $page, $limit),
|
|
|
|
'goods.list' => $this->goods->list($filters, $page, $limit),
|
|
'goods.summary' => $this->goods->summary($filters),
|
|
'goods.options' => $this->goods->filterOptions(),
|
|
|
|
'pinduoduo-bills.list' => $this->pinduoduo->paginate(
|
|
$storeName,
|
|
$fromDate,
|
|
$toDate,
|
|
$flowType,
|
|
$page,
|
|
$limit
|
|
),
|
|
'pinduoduo-bills.summary' => $this->pinduoduo->summary(
|
|
$storeName,
|
|
$fromDate,
|
|
$toDate,
|
|
$flowType
|
|
),
|
|
'pinduoduo-bills.options' => $this->pinduoduo->storeOptions(),
|
|
|
|
'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),
|
|
};
|
|
}
|
|
}
|