实际修改: - 店铺维度报表新增真实数据库条件查询:店铺字段走共享镜像 SQL WHERE,主体/能否变更/生效/失效走生命周期行级过滤(左闭右开) - 店铺负责人/部门负责人/利润中心改为店铺账号 PostgreSQL 镜像值, 按店铺名称关联,未匹配时回退经营分析副本库原值 - 能否变更按主表 platform 判定(唯品会MP/淘工厂=否,其余=是), 筛选改为 是/否 下拉;默认生效时间 2026-07-01,失效未记录显示存续中 - 主体维度经营报表接入生命周期收入窗口与注册地址解析市字段 - 同步更新视图测试并重写 StoreReportRepositoryTest 匹配 SQLite 实现 验证:容器内 tests/Feature/Business + tests/Unit/EcommerceFinance + tests/Unit/Business 共 324 passed / 4 skipped;真实数据端到端验证 (无筛选 1935 行、负责人/利润中心/失效区间筛选抽样全对)。 无新增数据库迁移,不涉及生产数据写入。
97 lines
3.4 KiB
PHP
97 lines
3.4 KiB
PHP
<?php
|
||
|
||
namespace Modules\EcommerceFinance\Repositories;
|
||
|
||
use Modules\EcommerceFinance\Services\BusinessMirrorDatasetRegistry;
|
||
use RuntimeException;
|
||
|
||
class StoreAccountMirrorRepository
|
||
{
|
||
public const DATASET = 'database_4.external_store_accounts.accounts_v1';
|
||
|
||
public function __construct(
|
||
private readonly BusinessMirrorDatasetRegistry $datasets,
|
||
private readonly GenericBusinessMirrorRepository $mirror,
|
||
) {}
|
||
|
||
/** @return array{data:array<int,array<string,mixed>>,total:int} */
|
||
public function paginate(int $page, int $perPage): array
|
||
{
|
||
$dataset = $this->datasets->get(self::DATASET);
|
||
if (! $this->mirror->ready($dataset)) {
|
||
throw new RuntimeException('store_account_mirror_not_ready');
|
||
}
|
||
|
||
$page = max($page, 1);
|
||
$perPage = min(max($perPage, 1), 100);
|
||
$query = $this->mirror->connection()->table($dataset->targetTable());
|
||
$total = (clone $query)->count();
|
||
$rows = $query
|
||
->orderByDesc('id')
|
||
->forPage($page, $perPage)
|
||
->get()
|
||
->map(fn (object $row): array => [
|
||
'id' => $row->id,
|
||
'store_name' => $row->storeName,
|
||
'operation_owner' => $row->operationOwner,
|
||
'operation_department_head' => $row->operationDepartmentHead,
|
||
'operation_director' => $row->operationDirector,
|
||
'profit_center' => $row->profitCenter,
|
||
'account_type' => $this->accountType($row->accountType),
|
||
'account' => $row->account,
|
||
// 上游只读视图明确不返回密码密文,列表只能展示未知配置状态。
|
||
'password_configured' => null,
|
||
'bound_phone' => $row->boundPhone,
|
||
'verification_contact' => $row->verificationContact,
|
||
'account_group_name' => $row->accountGroupName,
|
||
'created_at' => $row->createdAt,
|
||
'updated_at' => $row->updatedAt,
|
||
])
|
||
->all();
|
||
|
||
return ['data' => $rows, 'total' => $total];
|
||
}
|
||
|
||
/**
|
||
* 店铺维度报表的归属字段覆盖表,以店铺名称(storeName)为键。
|
||
*
|
||
* @return array<string,array{operation_owner:string,operation_director:string,profit_center:string}>
|
||
*/
|
||
public function ownershipByStoreName(): array
|
||
{
|
||
$dataset = $this->datasets->get(self::DATASET);
|
||
if (! $this->mirror->ready($dataset)) {
|
||
throw new RuntimeException('store_account_mirror_not_ready');
|
||
}
|
||
|
||
$map = [];
|
||
foreach ($this->mirror->connection()->table($dataset->targetTable())
|
||
->select('storeName', 'operationOwner', 'operationDirector', 'profitCenter')
|
||
->get() as $row) {
|
||
$name = trim((string) $row->storeName);
|
||
if ($name === '') {
|
||
continue;
|
||
}
|
||
$map[$name] = [
|
||
'operation_owner' => trim((string) $row->operationOwner),
|
||
'operation_director' => trim((string) $row->operationDirector),
|
||
'profit_center' => trim((string) $row->profitCenter),
|
||
];
|
||
}
|
||
|
||
return $map;
|
||
}
|
||
|
||
private function accountType(mixed $value): ?string
|
||
{
|
||
$type = trim((string) $value);
|
||
|
||
return match (strtoupper($type)) {
|
||
'MAIN' => '主账号',
|
||
'SUB' => '子账号',
|
||
'', '/' => null,
|
||
default => $type,
|
||
};
|
||
}
|
||
}
|