From e85a2e90ef72bdaea9863ba13d72885aba8c950e Mon Sep 17 00:00:00 2001 From: DoDo <1060330844@qq.com> Date: Mon, 26 Oct 2026 13:52:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=BB=8F=E8=90=A5=E6=8A=A5?= =?UTF-8?q?=E8=A1=A8=E6=B1=87=E6=80=BB=E5=8D=A1=E7=89=87=20(#588)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增六类经营报表汇总卡片,复用共享镜像筛选和排序,并完成真实数据口径、桌面及移动端验证。 --- app/Business/UpstreamBusinessInformation.php | 219 +++++++++++++++++- .../BusinessInformationMirrorRepository.php | 109 ++++++--- .../StoreAccountMirrorRepository.php | 15 +- .../partials/business-summary-cards.blade.php | 132 +++++++++++ .../pages/partials/directory-table.blade.php | 3 + tests/Feature/Business/PrototypePageTest.php | 43 ++++ ...usinessInformationMirrorRepositoryTest.php | 33 +++ .../StoreAccountMirrorRepositoryTest.php | 10 +- .../StoreReportRepositoryTest.php | 27 ++- .../UpstreamBusinessInformationTest.php | 58 +++++ 10 files changed, 611 insertions(+), 38 deletions(-) create mode 100644 resources/views/business/pages/partials/business-summary-cards.blade.php diff --git a/app/Business/UpstreamBusinessInformation.php b/app/Business/UpstreamBusinessInformation.php index fe60e25e..c56a449b 100644 --- a/app/Business/UpstreamBusinessInformation.php +++ b/app/Business/UpstreamBusinessInformation.php @@ -40,6 +40,10 @@ class UpstreamBusinessInformation 'financial-risk-control/process-statistics' => $this->shopInfoFlowPage($currentPage, $perPage), default => ['data' => [], 'total' => 0], }; + request()->attributes->set( + 'business-page-summary-cards', + $this->businessSummaryCards($key, $payload['summary'] ?? []), + ); return new LengthAwarePaginator( array_map(static fn (array $row) => (object) $row, $payload['data']), @@ -53,6 +57,97 @@ class UpstreamBusinessInformation ); } + private function businessSummaryCards(string $key, array $summary): array + { + if ($summary === []) { + return []; + } + + return match ($key) { + 'store-management/store-report' => [ + $this->summaryCard('店铺总数', $summary['stores'] ?? 0, '当前筛选内唯一店铺,明细按期间拆分'), + $this->summaryCard('正常店铺', $summary['normal'] ?? 0, '店铺状态为正常(开店中)', ['status' => '0']), + $this->summaryCard('关店中', $summary['closing'] ?? 0, '店铺状态为关闭中', ['status' => '3']), + $this->summaryCard('已关闭', $summary['closed'] ?? 0, '店铺状态为已关闭', ['status' => '6']), + $this->summaryCard('期间销量', $summary['period_sales'] ?? 0, '收入 + 优惠 + 冲减 + 退款', [ + 'sort' => 'period_sales', + 'direction' => 'desc', + ], 'money'), + ], + 'company-management/subject-operating-report' => [ + $this->summaryCard('主体总数', $summary['total'] ?? 0, '当前筛选内唯一主体'), + ($summary['company_status_ready'] ?? false) + ? $this->summaryCard('有效主体', $summary['normal'] ?? 0, '经营状态为正常', ['company_status' => '正常']) + : $this->summaryCard('有效主体', '—', '公司资料镜像未就绪', [], 'text'), + ($summary['company_status_ready'] ?? false) + ? $this->summaryCard('已注销主体', $summary['deregistered'] ?? 0, '最新公司资料状态为已注销', ['company_status' => '已注销']) + : $this->summaryCard('已注销主体', '—', '公司资料镜像未就绪', [], 'text'), + $this->summaryCard('最近12个月收入', $summary['rolling_income'] ?? 0, '最近 12 个完整月账单收入', [ + 'sort' => 'rolling_12m_income', + 'direction' => 'desc', + ], 'money'), + $this->summaryCard('本月收入', $summary['current_month_income'] ?? 0, (string) ($summary['current_month_label'] ?? '本月') . '账单收入', [ + 'sort' => 'income_' . ($summary['current_month_number'] ?? now()->format('m')), + 'direction' => 'desc', + ], 'money'), + ], + 'store-management/basic-information' => [ + $this->summaryCard('店铺总数', $summary['total'] ?? 0, '当前筛选内店铺档案'), + $this->summaryCard('正常店铺', $summary['normal'] ?? 0, '店铺状态为正常', ['store_status' => '正常']), + $this->summaryCard('关闭中', $summary['closing'] ?? 0, '店铺状态为关闭中', ['store_status' => '关闭中']), + $this->summaryCard('已关闭', $summary['closed'] ?? 0, '店铺状态为已关闭', ['store_status' => '已关闭']), + $this->summaryCard('平台数', $summary['platforms'] ?? 0, '按店铺档案平台去重', [ + 'sort' => 'platform', + 'direction' => 'asc', + ]), + ], + 'store-management/store-accounts' => [ + $this->summaryCard('账号总数', $summary['total'] ?? 0, '当前筛选内账号记录'), + $this->summaryCard('主账号', $summary['main_accounts'] ?? 0, '账号类型为 MAIN', ['account_type' => '主账号']), + $this->summaryCard('子账号', $summary['sub_accounts'] ?? 0, '账号类型为 SUB', ['account_type' => '子账号']), + $this->summaryCard('密码已设置', $summary['password_set'] ?? 0, '仅统计是否设置,不展示密码', ['password_configured' => '已设置']), + $this->summaryCard('密码未设置', $summary['password_missing'] ?? 0, '需店铺负责人补充', ['password_configured' => '未设置']), + ], + 'company-management/basic-information' => [ + $this->summaryCard('公司总数', $summary['total'] ?? 0, '当前筛选内公司档案'), + $this->summaryCard('正常公司', $summary['normal'] ?? 0, '公司状态为正常', ['company_status' => '正常']), + $this->summaryCard('已注销公司', $summary['deregistered'] ?? 0, '公司状态为已注销', ['company_status' => '已注销']), + $this->summaryCard('一般纳税人', $summary['general_taxpayer'] ?? 0, '纳税人类型为一般纳税人', ['taxpayer_type' => '一般纳税人']), + $this->summaryCard('小规模纳税人', $summary['small_taxpayer'] ?? 0, '纳税人类型为小规模纳税人', ['taxpayer_type' => '小规模纳税人']), + ], + 'trademark-management/information' => [ + $this->summaryCard('商标总数', $summary['total'] ?? 0, '当前筛选内商标档案'), + $this->summaryCard('有效商标', $summary['enabled'] ?? 0, '商标状态为有效', ['trademark_status' => '有效']), + $this->summaryCard('未启用', $summary['disabled'] ?? 0, '商标状态为未启用', ['trademark_status' => '未启用']), + $this->summaryCard('最终持有人', $summary['holders'] ?? 0, '按非空最终持有人去重', [ + 'sort' => 'final_holder', + 'direction' => 'asc', + ]), + $this->summaryCard('保管部门', $summary['departments'] ?? 0, '按非空保管部门去重', [ + 'sort' => 'custody_department', + 'direction' => 'asc', + ]), + ], + default => [], + }; + } + + private function summaryCard( + string $label, + mixed $value, + string $hint, + array $query = [], + string $format = 'integer', + ): array { + return [ + 'label' => $label, + 'value' => $value, + 'hint' => $hint, + 'format' => $format, + 'query' => ['page' => null, ...$query], + ]; + } + /** * 财务经营风险管控 › 流程统计:店铺申请流程(开店 / 变更 / 关店)只读镜像。 * @@ -215,11 +310,49 @@ SQL); $rows, fn (array $row): bool => $this->storeOwnershipMatchesFilters($row, $filters), )); + $summary = $this->storeInformationSummary($rows); $this->sortStoreInformation($rows, $filters); $total = count($rows); $offset = ($page - 1) * $perPage; - return ['data' => array_slice($rows, $offset, $perPage), 'total' => $total]; + return [ + 'data' => array_slice($rows, $offset, $perPage), + 'total' => $total, + 'summary' => $summary, + ]; + } + + /** @param list> $rows */ + private function storeInformationSummary(array $rows): array + { + $stores = []; + $platforms = []; + foreach ($rows as $row) { + $key = trim((string) ($row['id'] ?? $row['erp_store_name'] ?? $row['store_name'] ?? '')); + if ($key === '') { + continue; + } + $stores[$key] = match ((string) ($row['store_status'] ?? '')) { + '0', '正常' => '正常', + '3', '关闭中' => '关闭中', + '6', '已关闭', '关店' => '已关闭', + default => (string) ($row['store_status'] ?? ''), + }; + $platform = trim((string) ($row['platform'] ?? '')); + if ($platform !== '') { + $platforms[$platform] = true; + } + } + + $statusCounts = array_count_values($stores); + + return [ + 'total' => count($stores), + 'normal' => (int) ($statusCounts['正常'] ?? 0), + 'closing' => (int) ($statusCounts['关闭中'] ?? 0), + 'closed' => (int) ($statusCounts['已关闭'] ?? 0), + 'platforms' => count($platforms), + ]; } /** @param array> $filters */ @@ -269,7 +402,39 @@ SQL); $offset = ($page - 1) * $perPage; - return ['data' => array_slice($rows, $offset, $perPage), 'total' => count($rows)]; + return [ + 'data' => array_slice($rows, $offset, $perPage), + 'total' => count($rows), + 'summary' => $this->storeReportSummary($rows), + ]; + } + + /** @param list> $rows */ + private function storeReportSummary(array $rows): array + { + $stores = []; + $periodSales = 0.0; + foreach ($rows as $row) { + $key = trim((string) ($row['erp_store_name'] ?? '')); + if ($key === '') { + $key = trim((string) ($row['store_id'] ?? $row['id'] ?? '')); + } + if ($key === '') { + continue; + } + $stores[$key] = (string) ($row['status'] ?? ''); + $periodSales += (float) ($row['period_sales'] ?? 0); + } + + $statusCounts = array_count_values($stores); + + return [ + 'stores' => count($stores), + 'normal' => (int) ($statusCounts['开店中'] ?? 0), + 'closing' => (int) ($statusCounts['关店中'] ?? 0), + 'closed' => (int) ($statusCounts['关店'] ?? 0), + 'period_sales' => round($periodSales, 2), + ]; } /** @return array{data:array>,total:int} */ @@ -372,6 +537,11 @@ SQL); private function subjectOperatingReportPage(int $page, int $perPage): array { $filters = $this->pageFilters('company-management', 'subject-operating-report'); + $companyStatusReady = $this->mirror->ready('company-information.read'); + $companyStatus = trim((string) request('company_status', '')); + if (in_array($companyStatus, ['正常', '已注销'], true)) { + $filters['company_status'] = $companyStatus; + } $rows = $this->storeReportRows(array_intersect_key($filters, array_flip(['company_type']))); $entities = []; @@ -408,6 +578,7 @@ SQL); foreach ($rows as &$row) { $row['company_details'] = $details[$row['entity']] ?? []; $row['city'] = $this->cityFromDetails($row['company_details']); + $row['company_status'] = $row['company_details'][0]['company_status'] ?? null; } unset($row); @@ -418,11 +589,47 @@ SQL); ); $rows = array_values(array_filter($rows, fn (array $row): bool => $this->subjectMatchesFilters($row, $filters))); + $summary = $this->subjectSummary($rows, $companyStatusReady); $this->sortSubjectRows($rows, $filters); $offset = ($page - 1) * $perPage; $pageRows = array_slice($rows, $offset, $perPage); - return ['data' => $pageRows, 'total' => count($rows)]; + return ['data' => $pageRows, 'total' => count($rows), 'summary' => $summary]; + } + + /** @param list> $rows */ + private function subjectSummary(array $rows, bool $companyStatusReady): array + { + $normal = 0; + $deregistered = 0; + $rollingIncome = 0.0; + $currentMonthKey = 'income_' . now()->format('m'); + $currentMonthIncome = 0.0; + foreach ($rows as $row) { + $status = trim((string) ($row['company_status'] ?? '')); + if ($status === '正常') { + $normal++; + } elseif ($status === '已注销') { + $deregistered++; + } + if (($row['rolling_12m_income'] ?? null) !== null) { + $rollingIncome += (float) $row['rolling_12m_income']; + } + if (($row[$currentMonthKey] ?? null) !== null) { + $currentMonthIncome += (float) $row[$currentMonthKey]; + } + } + + return [ + 'total' => count($rows), + 'normal' => $normal, + 'deregistered' => $deregistered, + 'rolling_income' => round($rollingIncome, 2), + 'current_month_income' => round($currentMonthIncome, 2), + 'current_month_number' => now()->format('m'), + 'current_month_label' => now()->format('Y年n月'), + 'company_status_ready' => $companyStatusReady, + ]; } /** @@ -461,6 +668,11 @@ SQL); /** @param array $row @param array $filters */ private function subjectMatchesFilters(array $row, array $filters): bool { + $companyStatus = trim((string) ($filters['company_status'] ?? '')); + if ($companyStatus !== '' && (string) ($row['company_status'] ?? '') !== $companyStatus) { + return false; + } + if (($filters['company_type'] ?? '') !== '' && (string) ($row['company_type'] ?? '') !== (string) $filters['company_type']) { return false; } @@ -819,6 +1031,7 @@ SQL); return [ 'data' => array_map($mapper, $payload['data']), 'total' => (int) $payload['total'], + 'summary' => (array) ($payload['summary'] ?? []), ]; } diff --git a/modules/EcommerceFinance/Repositories/BusinessInformationMirrorRepository.php b/modules/EcommerceFinance/Repositories/BusinessInformationMirrorRepository.php index a315204a..d1cd972e 100644 --- a/modules/EcommerceFinance/Repositories/BusinessInformationMirrorRepository.php +++ b/modules/EcommerceFinance/Repositories/BusinessInformationMirrorRepository.php @@ -30,7 +30,7 @@ class BusinessInformationMirrorRepository return $this->mirror->ready($this->dataset($scope)); } - /** @return array{data: array>, total: int} */ + /** @return array{data: array>, total: int, summary?: array} */ public function paginate(string $scope, int $page, int $perPage, array $filters = []): array { if (! $this->ready($scope)) { @@ -126,8 +126,13 @@ SQL) $query->where('c.businessLicenseType', '=', trim((string) $filters['company_type'])); } - if (trim((string) ($filters['status'] ?? '')) !== '') { - $query->where('s.shopState', '=', (string) $filters['status']); + $status = trim((string) ($filters['store_status'] ?? '')); + if ($status === '') { + $status = trim((string) ($filters['status'] ?? '')); + } + if ($status !== '') { + $statusCode = ['正常' => '0', '关闭中' => '3', '已关闭' => '6'][$status] ?? $status; + $query->where('s.shopState', '=', $statusCode); } if (trim((string) ($filters['opened_at_from'] ?? '')) !== '') { @@ -161,7 +166,7 @@ SQL) ->all(); } - /** @return array{data: array>, total: int} */ + /** @return array{data: array>, total: int, summary: array} */ private function companies(int $page, int $perPage, array $filters): array { $query = $this->connection->table('ops_fys_company_info') @@ -213,18 +218,29 @@ SQL); ->orWhere('financialManager', 'like', $like); }); } - return $this->page($query, $page, $perPage, 'Id', $filters, [ - 'unified_social_credit_code' => 'unifiedSocialCreditCode', 'company_name' => 'businessLicenseName', - 'taxpayer_type' => 'taxCategoryAndType', 'company_status' => 'companyStatus', - 'subscribed_capital' => 'registeredCapital', 'registered_at' => 'IncorporationDate', - 'legal_representative' => 'legalRepresentative', 'supervisor' => 'supervisor', - 'billing_officer' => 'financialManager', 'registered_address' => 'registeredAddress', - 'city' => 'registeredAddress', 'business_scope' => 'businessScope', - 'basic_deposit_account' => 'accountSerialNumber', 'subscribed_at' => 'registeredCapitalVaildTime', - ]); + $summary = $this->summaryCounts($query, <<<'SQL' +COUNT(*) AS total, +COALESCE(SUM(CASE WHEN companyStatus = '0' THEN 1 ELSE 0 END), 0) AS normal, +COALESCE(SUM(CASE WHEN companyStatus = '1' THEN 1 ELSE 0 END), 0) AS deregistered, +COALESCE(SUM(CASE WHEN taxCategoryAndType = ? THEN 1 ELSE 0 END), 0) AS general_taxpayer, +COALESCE(SUM(CASE WHEN taxCategoryAndType = ? THEN 1 ELSE 0 END), 0) AS small_taxpayer +SQL, ['一般纳税人', '小规模纳税人']); + + return [ + ...$this->page($query, $page, $perPage, 'Id', $filters, [ + 'unified_social_credit_code' => 'unifiedSocialCreditCode', 'company_name' => 'businessLicenseName', + 'taxpayer_type' => 'taxCategoryAndType', 'company_status' => 'companyStatus', + 'subscribed_capital' => 'registeredCapital', 'registered_at' => 'IncorporationDate', + 'legal_representative' => 'legalRepresentative', 'supervisor' => 'supervisor', + 'billing_officer' => 'financialManager', 'registered_address' => 'registeredAddress', + 'city' => 'registeredAddress', 'business_scope' => 'businessScope', + 'basic_deposit_account' => 'accountSerialNumber', 'subscribed_at' => 'registeredCapitalVaildTime', + ]), + 'summary' => $summary, + ]; } - /** @return array{data: array>, total: int} */ + /** @return array{data: array>, total: int, summary: array} */ private function stores(int $page, int $perPage, array $filters): array { $query = $this->storeQuery(); @@ -247,14 +263,25 @@ SQL); $query->whereNull('s.shopBankAccount')->orWhere('s.shopBankAccount', '=', ''); }); } - return $this->page($query, $page, $perPage, 's.Id', $filters, [ - 'platform' => 's.platform', 'store_id' => 's.sotreId', 'store_name' => 's.erpShopName', - 'store_entity' => 'c.businessLicenseName', 'store_status' => 's.shopState', - 'trademark' => 't.trademarkName', 'trademark_number' => 's.trademarkNumber', - 'business_department' => 's.responsibleDepartment', 'store_manager' => 's.shopHead', - 'department_manager' => 's.customerDeptManager', 'opened_at' => 's.openTime', - 'renewed_at' => 's.renewalTime', 'withdrawal_account' => 's.shopBankAccount', - ]); + $summary = $this->summaryCounts($query, <<<'SQL' +COUNT(*) AS total, +COALESCE(SUM(CASE WHEN s.shopState = 0 THEN 1 ELSE 0 END), 0) AS normal, +COALESCE(SUM(CASE WHEN s.shopState = 3 THEN 1 ELSE 0 END), 0) AS closing, +COALESCE(SUM(CASE WHEN s.shopState = 6 THEN 1 ELSE 0 END), 0) AS closed, +COUNT(DISTINCT CASE WHEN s.platform IS NOT NULL AND s.platform <> '' THEN s.platform END) AS platforms +SQL); + + return [ + ...$this->page($query, $page, $perPage, 's.Id', $filters, [ + 'platform' => 's.platform', 'store_id' => 's.sotreId', 'store_name' => 's.erpShopName', + 'store_entity' => 'c.businessLicenseName', 'store_status' => 's.shopState', + 'trademark' => 't.trademarkName', 'trademark_number' => 's.trademarkNumber', + 'business_department' => 's.responsibleDepartment', 'store_manager' => 's.shopHead', + 'department_manager' => 's.customerDeptManager', 'opened_at' => 's.openTime', + 'renewed_at' => 's.renewalTime', 'withdrawal_account' => 's.shopBankAccount', + ]), + 'summary' => $summary, + ]; } private function storeQuery() @@ -308,7 +335,7 @@ SQL); return $query; } - /** @return array{data: array>, total: int} */ + /** @return array{data: array>, total: int, summary: array} */ private function trademarks(int $page, int $perPage, array $filters): array { $query = $this->connection->table('ops_fys_trademark_info') @@ -340,13 +367,35 @@ SQL); $statusCode = ['未启用' => '0', '有效' => '1'][$status] ?? $status; $query->where('trademarkStatus', '=', $statusCode); } - return $this->page($query, $page, $perPage, 'Id', $filters, [ - 'trademark_name' => 'trademarkName', 'trademark_number' => 'trademarkNumber', - 'trademark_status' => 'trademarkStatus', 'registration_date' => 'registrationDate', - 'expiry_date' => 'termOfValidity', 'international_classification' => 'internationalClassification', - 'approved_goods' => 'approvedCommodities', 'final_holder' => 'transferenceUser', - 'registered_address' => 'registrationAddress', 'custody_department' => 'custodyDepartment', - ]); + $summary = $this->summaryCounts($query, <<<'SQL' +COUNT(*) AS total, +COALESCE(SUM(CASE WHEN trademarkStatus = '1' THEN 1 ELSE 0 END), 0) AS enabled, +COALESCE(SUM(CASE WHEN trademarkStatus = '0' THEN 1 ELSE 0 END), 0) AS disabled, +COUNT(DISTINCT CASE WHEN transferenceUser IS NOT NULL AND transferenceUser <> '' THEN transferenceUser END) AS holders, +COUNT(DISTINCT CASE WHEN custodyDepartment IS NOT NULL AND custodyDepartment <> '' THEN custodyDepartment END) AS departments +SQL); + + return [ + ...$this->page($query, $page, $perPage, 'Id', $filters, [ + 'trademark_name' => 'trademarkName', 'trademark_number' => 'trademarkNumber', + 'trademark_status' => 'trademarkStatus', 'registration_date' => 'registrationDate', + 'expiry_date' => 'termOfValidity', 'international_classification' => 'internationalClassification', + 'approved_goods' => 'approvedCommodities', 'final_holder' => 'transferenceUser', + 'registered_address' => 'registrationAddress', 'custody_department' => 'custodyDepartment', + ]), + 'summary' => $summary, + ]; + } + + /** @return array */ + private function summaryCounts($query, string $sql, array $bindings = []): array + { + $row = (clone $query) + ->select([]) + ->selectRaw($sql, $bindings) + ->first(); + + return array_map(static fn ($value): int => (int) $value, (array) $row); } /** @param array $textColumns @param array $exactColumns @param array $enumColumns */ diff --git a/modules/EcommerceFinance/Repositories/StoreAccountMirrorRepository.php b/modules/EcommerceFinance/Repositories/StoreAccountMirrorRepository.php index 4b9be552..89e098c6 100644 --- a/modules/EcommerceFinance/Repositories/StoreAccountMirrorRepository.php +++ b/modules/EcommerceFinance/Repositories/StoreAccountMirrorRepository.php @@ -43,7 +43,7 @@ class StoreAccountMirrorRepository private readonly GenericBusinessMirrorRepository $mirror, ) {} - /** @return array{data:array>,total:int} */ + /** @return array{data:array>,total:int,summary:array} */ public function paginate(int $page, int $perPage, array $filters = []): array { $dataset = $this->datasets->get(self::DATASET); @@ -106,6 +106,17 @@ class StoreAccountMirrorRepository $query->whereIn('storeName', $this->storeNamesWithStatuses($statuses[$bucket], $expected)); } } + $summaryRow = (clone $query) + ->select([]) + ->selectRaw(<<<'SQL' +COUNT(*) AS total, +COALESCE(SUM(CASE WHEN accountType = 'MAIN' THEN 1 ELSE 0 END), 0) AS main_accounts, +COALESCE(SUM(CASE WHEN accountType = 'SUB' THEN 1 ELSE 0 END), 0) AS sub_accounts, +COALESCE(SUM(CASE WHEN passwordConfigured = 1 THEN 1 ELSE 0 END), 0) AS password_set, +COALESCE(SUM(CASE WHEN passwordConfigured = 0 THEN 1 ELSE 0 END), 0) AS password_missing +SQL) + ->first(); + $summary = array_map(static fn ($value): int => (int) $value, (array) $summaryRow); $total = (clone $query)->count(); $sortColumns = [ 'store_name' => 'storeName', 'operation_owner' => 'operationOwner', @@ -174,7 +185,7 @@ class StoreAccountMirrorRepository }) ->all(); - return ['data' => $rows, 'total' => $total]; + return ['data' => $rows, 'total' => $total, 'summary' => $summary]; } /** diff --git a/resources/views/business/pages/partials/business-summary-cards.blade.php b/resources/views/business/pages/partials/business-summary-cards.blade.php new file mode 100644 index 00000000..7f8fe31a --- /dev/null +++ b/resources/views/business/pages/partials/business-summary-cards.blade.php @@ -0,0 +1,132 @@ +@php + $summaryCards = $summaryCards ?? []; + $summaryTitle = $page['title'] ?? '业务页面'; +@endphp + +@once + +@endonce + +@if ($summaryCards !== []) + +@endif diff --git a/resources/views/business/pages/partials/directory-table.blade.php b/resources/views/business/pages/partials/directory-table.blade.php index 8bd63c60..ad27c894 100644 --- a/resources/views/business/pages/partials/directory-table.blade.php +++ b/resources/views/business/pages/partials/directory-table.blade.php @@ -2932,6 +2932,9 @@ @endif + @include('business.pages.partials.business-summary-cards', [ + 'summaryCards' => request()->attributes->get('business-page-summary-cards', []), + ]) @if (! $directoryUsesFieldQuery) @php $directoryMonthOptions = []; diff --git a/tests/Feature/Business/PrototypePageTest.php b/tests/Feature/Business/PrototypePageTest.php index 89f0be0d..adfce13e 100644 --- a/tests/Feature/Business/PrototypePageTest.php +++ b/tests/Feature/Business/PrototypePageTest.php @@ -50,6 +50,49 @@ class PrototypePageTest extends FeatureTestCase ->assertDontSeeText('共享镜像中暂未读取到店铺账号数据'); } + public function testSharedBusinessPagesRenderClickableSummaryCards(): void + { + $rows = new LengthAwarePaginator([(object) [ + 'id' => 'account-summary', + 'store_name' => '汇总测试店铺', + 'account_type' => '主账号', + 'account' => 'summary-account', + 'password_configured' => true, + ]], 958, 50, 1, ['path' => '/']); + + $this->mock(\App\Business\UpstreamBusinessInformation::class) + ->shouldReceive('paginate') + ->once() + ->with('store-management', 'store-accounts', 50) + ->andReturnUsing(function () use ($rows): LengthAwarePaginator { + request()->attributes->set('business-page-summary-cards', [ + ['label' => '账号总数', 'value' => 958, 'hint' => '当前筛选内账号记录', 'format' => 'integer', 'query' => ['page' => null]], + ['label' => '主账号', 'value' => 640, 'hint' => '账号类型为 MAIN', 'format' => 'integer', 'query' => ['page' => null, 'account_type' => '主账号']], + ['label' => '子账号', 'value' => 318, 'hint' => '账号类型为 SUB', 'format' => 'integer', 'query' => ['page' => null, 'account_type' => '子账号']], + ]); + + return $rows; + }); + + $this->loginAs() + ->get(route('business.pages.show', [ + 'section' => 'store-management', + 'page' => 'store-accounts', + 'account_type' => '主账号', + ])) + ->assertOk() + ->assertSee('data-business-summary-cards', false) + ->assertSee('data-business-summary-card="账号总数"', false) + ->assertSee('data-business-summary-card="主账号"', false) + ->assertSee('data-business-summary-card="子账号"', false) + ->assertSee('account_type=', false) + ->assertSee('aria-current="true"', false) + ->assertSeeText('958') + ->assertSeeText('640') + ->assertSeeText('318') + ->assertSee('查看明细', false); + } + public function testNavigationUsesConfiguredPermissionsAndTitles(): void { $this->user->roles()->sync([\App\Models\Auth\Role::where('name', 'admin')->firstOrFail()->id]); diff --git a/tests/Unit/EcommerceFinance/BusinessInformationMirrorRepositoryTest.php b/tests/Unit/EcommerceFinance/BusinessInformationMirrorRepositoryTest.php index befbb0ca..1b56c8a0 100644 --- a/tests/Unit/EcommerceFinance/BusinessInformationMirrorRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/BusinessInformationMirrorRepositoryTest.php @@ -64,6 +64,10 @@ class BusinessInformationMirrorRepositoryTest extends TestCase 'legalRepresentative' => '张三', 'registeredAddress' => '上海市浦东新区测试路1号', ]); + $connection->table('ops_fys_company_info')->where('Id', 3)->update([ + 'companyStatus' => '1', + 'taxCategoryAndType' => '一般纳税人', + ]); $connection->table('ops_fys_shop_info')->where('Id', 8)->update(['sotreId' => 'STORE-8', 'renewalTime' => '2027-08-14', 'shopBankAccount' => 'fixture-account', 'trademarkNumber' => 'TM-5']); $connection->table('ops_fys_trademark_info')->where('Id', 5)->update(['trademarkNumber' => 'TM-5', 'approvedCommodities' => '家具', 'transferenceUser' => '测试持有人', 'registrationAddress' => '测试地址', 'custodyDepartment' => '资料部']); @@ -75,6 +79,9 @@ class BusinessInformationMirrorRepositoryTest extends TestCase 'store_name' => '上游店铺名', 'store_id' => 'STORE-8', ]); + $normalStores = $this->repository->allStores(['store_status' => '正常']); + $closedStores = $this->repository->allStores(['store_status' => '已关闭']); + $legacyStatusStores = $this->repository->allStores(['status' => '0']); $filteredStore = $this->repository->paginate('store-information.read', 1, 20, [ 'platform' => '天猫', 'store_status' => '0', 'opened_at_from' => '2026-08-14', ]); @@ -98,6 +105,9 @@ class BusinessInformationMirrorRepositoryTest extends TestCase $this->assertSame('STORE-8', $store['data'][0]['store_id']); $this->assertSame('上游店铺名', $store['data'][0]['store_name']); $this->assertCount(1, $filteredStores); + $this->assertCount(1, $normalStores); + $this->assertSame([], $closedStores); + $this->assertCount(1, $legacyStatusStores); $this->assertSame([], $this->repository->allStores(['store_id' => '测试店'])); $this->assertSame('2027-08-14', $store['data'][0]['renewed_at']); $this->assertSame('负责人', $store['data'][0]['store_manager']); @@ -114,6 +124,29 @@ class BusinessInformationMirrorRepositoryTest extends TestCase $this->assertSame('新公司', $relatedCompany['data'][0]['company_name']); $this->assertSame(1, $typedCompany['total']); $this->assertSame(1, $cityCompany['total']); + $this->assertSame([ + 'total' => 3, + 'normal' => 2, + 'deregistered' => 1, + 'general_taxpayer' => 1, + 'small_taxpayer' => 1, + ], $companies['summary']); + $this->assertSame([ + 'total' => 1, + 'normal' => 1, + 'closing' => 0, + 'closed' => 0, + 'platforms' => 1, + ], $store['summary']); + $this->assertSame([ + 'total' => 1, + 'enabled' => 1, + 'disabled' => 0, + 'holders' => 1, + 'departments' => 1, + ], $trademarks['summary']); + $this->assertSame(1, $filteredCompany['summary']['total']); + $this->assertSame(1, $filteredTrademark['summary']['enabled']); } public function test_dataset_is_not_ready_until_initial_full_sync_is_marked_complete(): void diff --git a/tests/Unit/EcommerceFinance/StoreAccountMirrorRepositoryTest.php b/tests/Unit/EcommerceFinance/StoreAccountMirrorRepositoryTest.php index 710d5b11..cffa0fa7 100644 --- a/tests/Unit/EcommerceFinance/StoreAccountMirrorRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/StoreAccountMirrorRepositoryTest.php @@ -107,7 +107,8 @@ class StoreAccountMirrorRepositoryTest extends TestCase ]); } - $rows = collect($this->repository->paginate(1, 50)['data'])->keyBy('id'); + $payload = $this->repository->paginate(1, 50); + $rows = collect($payload['data'])->keyBy('id'); $this->assertSame('主账号', $rows['account-' . md5('MAIN')]['account_type']); $this->assertSame('子账号', $rows['account-' . md5('SUB')]['account_type']); @@ -115,6 +116,13 @@ class StoreAccountMirrorRepositoryTest extends TestCase $this->assertTrue($rows['account-' . md5('MAIN')]['password_configured']); $this->assertFalse($rows['account-' . md5('SUB')]['password_configured']); $this->assertNull($rows['account-' . md5('/')]['password_configured']); + $this->assertSame([ + 'total' => 3, + 'main_accounts' => 1, + 'sub_accounts' => 1, + 'password_set' => 1, + 'password_missing' => 1, + ], $payload['summary']); $sorted = $this->repository->paginate(1, 50, ['_sort' => 'store_name', '_direction' => 'asc']); $this->assertSame(['A店铺', 'B店铺', 'C店铺'], array_column($sorted['data'], 'store_name')); diff --git a/tests/Unit/EcommerceFinance/StoreReportRepositoryTest.php b/tests/Unit/EcommerceFinance/StoreReportRepositoryTest.php index 1d4f561d..55dc7e6a 100644 --- a/tests/Unit/EcommerceFinance/StoreReportRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/StoreReportRepositoryTest.php @@ -286,6 +286,12 @@ class StoreReportRepositoryTest extends TestCase $this->assertSame('店铺负责人', $paginator->items()[0]->store_manager); $this->assertSame('部门负责人', $paginator->items()[0]->department_manager); $this->assertSame('运营中心A', $paginator->items()[0]->profit_center); + $summaryCards = collect($this->app['request']->attributes->get('business-page-summary-cards'))->keyBy('label'); + $this->assertSame(1, $summaryCards['店铺总数']['value']); + $this->assertSame(1, $summaryCards['正常店铺']['value']); + $this->assertSame(0, $summaryCards['关店中']['value']); + $this->assertSame(0, $summaryCards['已关闭']['value']); + $this->assertSame(60.0, (float) $summaryCards['期间销量']['value']); } public function test_store_report_hides_sales_months_without_data_by_default(): void @@ -325,12 +331,19 @@ class StoreReportRepositoryTest extends TestCase $this->insertBill('店铺B', '2026-08-11', 40); $mirror = Mockery::mock(BusinessInformationMirrorRepository::class); $mirror->shouldReceive('ready')->with('store-information.read')->andReturnTrue(); - $mirror->shouldReceive('allStores')->times(3)->andReturn([ + $mirror->shouldReceive('allStores')->times(5)->andReturn([ ['erp_store_name' => '店铺A', 'company_name' => '主体甲', 'store_status' => '0'], ['erp_store_name' => '店铺B', 'company_name' => '主体甲', 'store_status' => '0'], ]); $mirror->shouldReceive('ready')->with('company-information.read')->andReturnTrue(); - $mirror->shouldReceive('companiesByNames')->andReturn([]); + $mirror->shouldReceive('companiesByNames')->andReturn([ + '主体甲' => [[ + 'Id' => 1, + 'businessLicenseName' => '主体甲', + 'companyStatus' => '0', + 'registeredAddress' => '常州市测试路1号', + ]], + ]); $accounts = Mockery::mock(StoreAccountMirrorRepository::class); $accounts->shouldReceive('ownershipByStoreName')->andReturn([]); $service = new UpstreamBusinessInformation( @@ -347,9 +360,19 @@ class StoreReportRepositoryTest extends TestCase $this->assertSame(90.0, $rows[0]->rolling_12m_income); $this->assertSame(20.0, $rows[0]->income_07); $this->assertSame(70.0, $rows[0]->income_08); + $summaryCards = collect($this->app['request']->attributes->get('business-page-summary-cards'))->keyBy('label'); + $this->assertSame(1, $summaryCards['主体总数']['value']); + $this->assertSame(1, $summaryCards['有效主体']['value']); + $this->assertSame(0, $summaryCards['已注销主体']['value']); + $this->assertSame(90.0, (float) $summaryCards['最近12个月收入']['value']); request()->merge(['income_08' => '70.00']); $this->assertSame(1, $service->paginate('company-management', 'subject-operating-report', 50)->total()); + request()->merge(['company_status' => '正常']); + $this->assertSame(1, $service->paginate('company-management', 'subject-operating-report', 50)->total()); + request()->merge(['company_status' => '已注销']); + $this->assertSame(0, $service->paginate('company-management', 'subject-operating-report', 50)->total()); + request()->merge(['company_status' => null]); request()->merge(['income_08' => '71.00']); $this->assertSame(0, $service->paginate('company-management', 'subject-operating-report', 50)->total()); } diff --git a/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php b/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php index 5cccbf64..19879193 100644 --- a/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php +++ b/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php @@ -121,12 +121,16 @@ class UpstreamBusinessInformationTest extends TestCase 'erp_store_name' => '拼多多_测试店铺', 'store_manager' => '旧店铺负责人', 'department_manager' => '旧部门负责人', + 'store_status' => '0', + 'platform' => '拼多多', ], [ 'id' => 8, 'erp_store_name' => '拼多多-其他店铺', 'store_manager' => '其他负责人', 'department_manager' => '其他部门负责人', + 'store_status' => '6', + 'platform' => '拼多多', ], ]); $accounts = Mockery::mock(StoreAccountMirrorRepository::class); @@ -154,6 +158,60 @@ class UpstreamBusinessInformationTest extends TestCase $this->assertSame('正确店铺负责人', $paginator->items()[0]->store_manager); $this->assertSame('正确部门负责人', $paginator->items()[0]->department_manager); $this->assertNotSame('运营总监', $paginator->items()[0]->department_manager); + $summaryCards = collect($this->app['request']->attributes->get('business-page-summary-cards'))->keyBy('label'); + $this->assertSame(1, $summaryCards['店铺总数']['value']); + $this->assertSame(1, $summaryCards['正常店铺']['value']); + $this->assertSame(0, $summaryCards['关闭中']['value']); + $this->assertSame(0, $summaryCards['已关闭']['value']); + $this->assertSame(1, $summaryCards['平台数']['value']); + } + + public function test_company_and_trademark_mirror_summaries_become_clickable_cards(): void + { + $mirror = Mockery::mock(BusinessInformationMirrorRepository::class); + $mirror->shouldReceive('ready')->times(2)->andReturnUsing( + static fn (string $scope): bool => in_array($scope, ['company-information.read', 'trademark-information.read'], true), + ); + $mirror->shouldReceive('paginate')->once()->with('company-information.read', 1, 50, [])->andReturn([ + 'data' => [], + 'total' => 818, + 'summary' => [ + 'total' => 818, + 'normal' => 520, + 'deregistered' => 298, + 'general_taxpayer' => 123, + 'small_taxpayer' => 606, + ], + ]); + $mirror->shouldReceive('paginate')->once()->with('trademark-information.read', 1, 50, [])->andReturn([ + 'data' => [], + 'total' => 593, + 'summary' => [ + 'total' => 593, + 'enabled' => 548, + 'disabled' => 45, + 'holders' => 5, + 'departments' => 6, + ], + ]); + + $information = new UpstreamBusinessInformation( + Mockery::mock(UpstreamQueryCacheFactory::class), + $mirror, + null, + ); + $information->paginate('company-management', 'basic-information', 50); + $companyCards = collect($this->app['request']->attributes->get('business-page-summary-cards'))->keyBy('label'); + $this->assertSame(818, $companyCards['公司总数']['value']); + $this->assertSame(['page' => null, 'company_status' => '正常'], $companyCards['正常公司']['query']); + $this->assertSame(['page' => null, 'taxpayer_type' => '一般纳税人'], $companyCards['一般纳税人']['query']); + + $information->paginate('trademark-management', 'information', 50); + $trademarkCards = collect($this->app['request']->attributes->get('business-page-summary-cards'))->keyBy('label'); + $this->assertSame(593, $trademarkCards['商标总数']['value']); + $this->assertSame(45, $trademarkCards['未启用']['value']); + $this->assertSame(['page' => null, 'trademark_status' => '有效'], $trademarkCards['有效商标']['query']); + $this->assertSame('final_holder', $trademarkCards['最终持有人']['query']['sort']); } public function test_bootstrap_without_mirror_explains_shared_connection_instead_of_requesting_upstream_credentials(): void