CaiWuXiTong/modules/EcommerceFinance/Http/Concerns/DecoratesLedgerRemarks.php
qiuxiang 7175d3f73e 店铺收款账户账单:所有页签新增「总账备注」筛选(页面与导出同口径)
- AccountLedgerRemarkMap:新增 页签→平台→账单项目 的翻译(remarksForTab / billItemGroupsForTab / billItemsForTab);淘系支付宝、淘系微信同页签混有多个平台,按店铺名前缀再分平台
- LedgerRemarkFilter(新):把「总账备注」翻译成 SQL 条件,单平台页签 whereIn(账单项目),多平台页签 (店铺前缀 AND 账单项目 IN ...) OR ...
- 控制器/仓库:AccountBills、AlipayBills、Pinduoduo/Dewu/TaobaoWechat 账户账单 + 对应仓库(含抖音权威、京东日账单、京东钱包、共享原始账单镜像)全部接入 ledger_remark 筛选;filter-options 统一返回 ledger_remarks 供下拉
- 前端:AccountBills.vue / TaobaoAlipayBills.vue 在「店铺」右侧新增「总账备注」下拉,参与查询、重置与导出
- 测试:新增映射翻译、SQL 条件、唯品会JX 页面+导出筛选用例;同步 filter-options 断言
2026-10-06 18:46:16 +08:00

86 lines
2.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Modules\EcommerceFinance\Http\Concerns;
use Modules\EcommerceFinance\Services\AccountLedgerRemarkMap;
/**
* 店铺收款账户账单:给每行账单补「总账备注」(按平台 + 账单项目匹配映射表)。
*
* 只在读取时补齐,不改动上游账单与镜像数据。
*/
trait DecoratesLedgerRemarks
{
/** 「总账备注」在本页签没有对应账单项目时的占位条件(保证命中 0 行)。 */
private const LEDGER_REMARK_NO_MATCH_ITEM = '__no_such_ledger_remark_item__';
protected function ledgerRemarkMap(): AccountLedgerRemarkMap
{
return app(AccountLedgerRemarkMap::class);
}
/**
* 把「总账备注」筛选翻译成账单项目集合。
*
* 页面、列设置与导出都调用这里,保证同一份筛选口径;
* bill_items 供各仓库 whereIn(账单项目) 使用,bill_item_groups 供
* 淘系这种同一页签混多平台的仓库按店铺名前缀再细分。
*
* @param array<string,mixed> $filters
* @return array<string,mixed>
*/
protected function withLedgerRemarkFilter(array $filters, string $tab): array
{
$remark = trim((string) ($filters['ledger_remark'] ?? ''));
if ($remark === '') {
return $filters;
}
$groups = $this->ledgerRemarkMap()->billItemGroupsForTab($tab, $remark);
$filters['bill_item_groups'] = $groups;
$items = [];
foreach ($groups as $group) {
foreach ($group['items'] as $item) {
$items[$item] = true;
}
}
$filters['bill_items'] = array_keys($items);
if ($filters['bill_items'] === []) {
$filters['bill_items'] = [self::LEDGER_REMARK_NO_MATCH_ITEM];
}
return $filters;
}
/**
* 分页结果(含 data 行数组)补总账备注。
*
* @param array<string,mixed> $data
* @return array<string,mixed>
*/
protected function withLedgerRemarks(array $data, string $tab): array
{
if (! empty($data['data']) && is_array($data['data'])) {
$map = $this->ledgerRemarkMap();
$data['data'] = array_map(
static fn (mixed $row): mixed => is_array($row) ? $map->decorate($row, $tab) : $row,
$data['data'],
);
}
return $data;
}
/**
* 导出/流式行补总账备注。
*
* @param iterable<int,array<string,mixed>> $rows
* @return iterable<int,array<string,mixed>>
*/
protected function ledgerRemarkRows(iterable $rows, string $tab): iterable
{
return $this->ledgerRemarkMap()->decorateAll($rows, $tab);
}
}