CaiWuXiTong/modules/EcommerceFinance/Repositories/StoreReceivingDewuAlipayBillMirrorRepository.php
qiuxiang 1a592c82a0 feat(得物支付宝账户): 增加店铺与商户号映射列 (#1373)
新增支付宝账户、得物店铺和商户号映射列。
2026-11-24 14:41:21 +08:00

89 lines
3.8 KiB
PHP

<?php
namespace Modules\EcommerceFinance\Repositories;
/**
* 得物支付宝账户:从聚水潭淘系支付宝完整账单中读取指定主体的账户流水。
*
* 聚水潭导出的展示名可能在末尾追加 8 位日期后缀;本页按八家主体的标准名称锁定范围,
* 表格继续展示源账单中的原始账户名。
*/
class StoreReceivingDewuAlipayBillMirrorRepository
{
/** @var list<string> */
public const STORE_NAMES = [
'支付宝-常州春之华家居有限公司',
'支付宝-常州诗科家电子商务有限公司',
'支付宝-常州玖阔家居有限公司20240319',
'支付宝-常州阔之煜家居有限公司',
'支付宝-常州熊泽家居有限公司',
'支付宝-常州雄川家居有限公司',
'支付宝-常州泽之云家居有限公司',
'支付宝-常州君佰家居有限公司',
];
/** @var array<string,array{store:string,merchant_no:string}> */
public const ACCOUNT_MAP = [
'支付宝-常州春之华家居有限公司' => ['store' => '得物-全米', 'merchant_no' => '2088641917126568'],
'支付宝-常州诗科家电子商务有限公司' => ['store' => '得物-木刻理想', 'merchant_no' => '2088741650909210'],
'支付宝-常州玖阔家居有限公司20240319' => ['store' => '得物-米客米家家居旗舰店', 'merchant_no' => '2088841004631652'],
'支付宝-常州阔之煜家居有限公司' => ['store' => '得物-宜造', 'merchant_no' => '2088841085257651'],
'支付宝-常州熊泽家居有限公司' => ['store' => '得物-墨尚思', 'merchant_no' => '2088841143397934'],
'支付宝-常州雄川家居有限公司' => ['store' => '得物-卓禾', 'merchant_no' => '2088741272387795'],
'支付宝-常州泽之云家居有限公司' => ['store' => '得物-欧意朗', 'merchant_no' => '2088841917714972'],
'支付宝-常州君佰家居有限公司' => ['store' => '得物-亿家达', 'merchant_no' => '2088970585568179'],
];
private readonly TaobaoAlipaySettlementBillRepository $source;
public function __construct(TaobaoAlipaySettlementBillRepository $source)
{
$this->source = $source->scopedToStores(self::STORE_NAMES);
}
/** @return array<string,mixed> */
public function paginate(array $filters, string $sort, string $direction, int $page, int $perPage): array
{
$result = $this->source->paginate($filters, $sort, $direction, $page, $perPage);
$result['data'] = array_map(
fn (array $row): array => $this->withAccountMap($row),
$result['data'],
);
return $result;
}
/** @return iterable<int,array<string,mixed>> */
public function exportRows(array $filters, string $sort = 'occurred_at', string $direction = 'asc'): iterable
{
foreach ($this->source->exportRows($filters, $sort, $direction) as $row) {
yield $this->withAccountMap($row);
}
}
/** @return array{shops:list<string>,bill_items:list<string>} */
public function filterOptions(): array
{
$options = $this->source->accountBillFilterOptions();
$shops = array_values(array_unique(array_merge(self::STORE_NAMES, $options['shops'])));
sort($shops, SORT_NATURAL);
return [
'shops' => $shops,
'bill_items' => $options['bill_items'],
];
}
/** @param array<string,mixed> $row @return array<string,mixed> */
private function withAccountMap(array $row): array
{
$accountName = trim((string) ($row['store_name'] ?? ''));
$mapping = self::ACCOUNT_MAP[$accountName] ?? null;
$row['dewu_alipay_account_name'] = $accountName;
$row['dewu_store_name'] = $mapping['store'] ?? '';
$row['dewu_merchant_no'] = $mapping['merchant_no'] ?? '';
return $row;
}
}