CaiWuXiTong/modules/EcommerceFinance/Services/JianSunSnapshotRefresher.php
WuYongJie 28a62434d2 整合并修正京东钱包账单 (#26)
接入京东充值与消耗账单,修复快照冷启动、刷新依赖、日期边界与标签局部切换。
2026-08-11 12:22:41 +08:00

215 lines
9.5 KiB
PHP

<?php
namespace Modules\EcommerceFinance\Services;
use InvalidArgumentException;
use Modules\EcommerceFinance\Contracts\UpstreamSnapshotRefresher;
use Modules\EcommerceFinance\Repositories\AlibabaBillRepository;
use Modules\EcommerceFinance\Repositories\EdgeBandingRepository;
use Modules\EcommerceFinance\Repositories\GoodsReconciliationRepository;
use Modules\EcommerceFinance\Repositories\InventoryRepository;
use Modules\EcommerceFinance\Repositories\JdWalletBillRepository;
use Modules\EcommerceFinance\Repositories\PinduoduoSpreadBillRepository;
use Modules\EcommerceFinance\Repositories\ProductPriceRepository;
use Modules\EcommerceFinance\Repositories\RawBoardPayablesRepository;
use Modules\EcommerceFinance\Repositories\SupplierPayableRepository;
use Modules\EcommerceFinance\Repositories\SupplierPayableReportRepository;
use Modules\EcommerceFinance\Repositories\TmallTaobaoSpreadBillRepository;
/**
* 将活跃查询登记项还原成仓库调用,供定时任务刷新共享快照。
*/
class JianSunSnapshotRefresher implements UpstreamSnapshotRefresher
{
public function __construct(
private readonly JianSunQueryCache $cache,
private readonly EdgeBandingRepository $edgeBanding,
private readonly GoodsReconciliationRepository $goods,
private readonly InventoryRepository $inventory,
private readonly AlibabaBillRepository $alibaba,
private readonly PinduoduoSpreadBillRepository $pinduoduo,
private readonly ProductPriceRepository $productPrices,
private readonly RawBoardPayablesRepository $rawBoardPayables,
private readonly TmallTaobaoSpreadBillRepository $taobaoAlipay,
private readonly SupplierPayableRepository $supplier,
private readonly SupplierPayableReportRepository $supplierPayableReports,
private readonly JdWalletBillRepository $jdWallet,
) {
}
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['shop_name'])
? (string) $filters['shop_name']
: (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;
$productType = isset($filters['product_type']) ? (string) $filters['product_type'] : 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(),
'inventory.board-details' => $this->inventory->boardInventoryDetails($filters, $page, $limit),
'marketing-account-bills.alibaba.list' => $this->alibaba->paginate(
$storeName,
$productType,
$fromDate,
$toDate,
$page,
$limit,
),
'marketing-account-bills.alibaba.summary' => $this->alibaba->summary(
$storeName,
$productType,
$fromDate,
$toDate,
),
'marketing-account-bills.alibaba.options' => $this->alibaba->filterOptions(),
'raw-board.prices' => $this->rawBoardPayables->prices($filters, $page, $limit),
'raw-board.reconciliations' => $this->rawBoardPayables->reconciliations($filters, $page, $limit),
'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(),
'jd-wallet-bills.recharge.list' => $this->jdWallet->paginateRecharge(
$storeName,
$fromDate,
$toDate,
$page,
$limit,
),
'jd-wallet-bills.recharge.summary' => $this->jdWallet->summaryRecharge(
$storeName,
$fromDate,
$toDate,
),
'jd-wallet-bills.consumption.list' => $this->jdWallet->paginateConsumption(
$storeName,
$fromDate,
$toDate,
$page,
$limit,
),
'jd-wallet-bills.consumption.summary' => $this->jdWallet->summaryConsumption(
$storeName,
$fromDate,
$toDate,
),
'jd-wallet-bills.options' => $this->jdWallet->shopOptions(),
'taobao-alipay-bills.list' => $this->taobaoAlipay->paginate(
$storeName,
$fromDate,
$toDate,
$flowType,
$page,
$limit
),
'taobao-alipay-bills.summary' => $this->taobaoAlipay->summary(
$storeName,
$fromDate,
$toDate,
$flowType
),
'taobao-alipay-bills.options' => $this->taobaoAlipay->storeOptions(),
'supplier-payables.product-prices.list' => $this->productPrices->paginate(
$filters,
$page,
$limit,
),
'supplier-payables.board-deductions.list' => $this->supplierPayableReports->boardDeductions(
$filters,
$page,
$limit,
),
'supplier-payables.report.list' => $this->supplierPayableReports->supplierPayables(
$filters,
$page,
$limit,
),
'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),
};
}
}