feat(资金管理): 新增月度资金余额监控并统一支付宝账户口径
合并月度资金余额监控页、店铺每日余额本页小计标识及全部/店铺支付宝账户名称区分。
This commit is contained in:
parent
e330d94090
commit
4dfed91c92
@ -5676,6 +5676,7 @@ class Pages extends Controller
|
||||
'shipping-data' => $this->contentForShippingData(),
|
||||
'return-pickup-management' => $this->contentForReturnPickupManagement(),
|
||||
'withdrawal-management' => $this->contentForWithdrawalManagement(),
|
||||
'fund-balance-monitor' => app(\Modules\EcommerceFinance\View\FundBalanceMonitorPageData::class)->page(),
|
||||
'systemization-todos' => app(\App\Http\Controllers\Business\SystemizationTodos::class)->page(),
|
||||
'log-statistics' => app(\Modules\EcommerceFinance\View\DingWorklogStatisticsPageData::class)->page(request()),
|
||||
'order-profit-list' => app(\Modules\EcommerceFinance\View\OrderProfitPageData::class)->page(),
|
||||
|
||||
@ -563,6 +563,7 @@ $navigation = [
|
||||
'route_page' => 'fund-ledger',
|
||||
'permission_key' => 'financial-operations/fund-ledger',
|
||||
],
|
||||
['slug' => 'fund-balance-monitor', 'title' => '资金余额监控'],
|
||||
[
|
||||
'slug' => 'store-receiving-accounts',
|
||||
'title' => '店铺收款账户',
|
||||
@ -591,7 +592,7 @@ $navigation = [
|
||||
'title' => '店铺收款账户账单',
|
||||
'tabs' => [
|
||||
['slug' => 'balance-overview', 'title' => '账户余额总览'],
|
||||
['slug' => 'taobao-alipay', 'title' => '淘系支付宝账户'],
|
||||
['slug' => 'taobao-alipay', 'title' => '全部支付宝账户'],
|
||||
['slug' => 'taobao-wechat', 'title' => '淘系微信账户'],
|
||||
['slug' => 'pinduoduo', 'title' => '拼多多账户'],
|
||||
['slug' => 'jd-wallet', 'title' => '京东网银钱包账户'],
|
||||
|
||||
@ -48,7 +48,7 @@ class StoreReceivingBalanceOverviewService
|
||||
|
||||
/** @var array<int,array{slug:string,name:string}> */
|
||||
public const PLATFORMS = [
|
||||
['slug' => 'taobao-alipay', 'name' => '淘系支付宝账户'],
|
||||
['slug' => 'taobao-alipay', 'name' => '店铺支付宝账户'],
|
||||
['slug' => 'taobao-wechat', 'name' => '淘系微信账户'],
|
||||
['slug' => 'pinduoduo', 'name' => '拼多多账户'],
|
||||
['slug' => 'jd-wallet', 'name' => '京东网银钱包账户'],
|
||||
|
||||
438
modules/EcommerceFinance/View/FundBalanceMonitorPageData.php
Normal file
438
modules/EcommerceFinance/View/FundBalanceMonitorPageData.php
Normal file
@ -0,0 +1,438 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\EcommerceFinance\View;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Modules\EcommerceFinance\Services\PinduoduoOpeningBalanceService;
|
||||
use Modules\EcommerceFinance\Services\StoreReceivingBalanceOverviewService;
|
||||
use Throwable;
|
||||
|
||||
final class FundBalanceMonitorPageData
|
||||
{
|
||||
private const STORE_CACHE_MINUTES = 15;
|
||||
|
||||
public function __construct(
|
||||
private readonly NonStoreAccountMonitorPageData $accounts,
|
||||
private readonly StoreReceivingBalanceOverviewService $stores,
|
||||
private readonly PinduoduoOpeningBalanceService $pinduoduoOpeningBalances,
|
||||
) {}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
public function page(): array
|
||||
{
|
||||
$month = $this->selectedMonth();
|
||||
$periodStart = $month['start'];
|
||||
$periodEnd = $month['end'];
|
||||
$accountError = null;
|
||||
|
||||
try {
|
||||
$accountData = $this->accounts->page([
|
||||
'from' => $periodStart,
|
||||
'to' => $periodEnd,
|
||||
]);
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
$accountData = [];
|
||||
$accountError = '非店铺账户余额暂时无法读取。';
|
||||
}
|
||||
|
||||
$storeError = null;
|
||||
try {
|
||||
$storeDaily = $this->cachedStoreDaily($periodStart, $periodEnd);
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
$storeDaily = [];
|
||||
$storeError = '店铺每日余额暂时无法读取。';
|
||||
}
|
||||
|
||||
return $this->build(
|
||||
$month,
|
||||
$accountData,
|
||||
$storeDaily,
|
||||
$accountError,
|
||||
$storeError,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 月度资金页默认查看最近已结束月份;本次进入页面即为 2026 年 10 月。
|
||||
*
|
||||
* @return array{
|
||||
* value:string,label:string,start:string,end:string,
|
||||
* options:array<int,array{value:string,label:string}>
|
||||
* }
|
||||
*/
|
||||
private function selectedMonth(): array
|
||||
{
|
||||
$now = CarbonImmutable::now('Asia/Shanghai')->startOfDay();
|
||||
$default = $now->subMonthNoOverflow()->startOfMonth();
|
||||
$requested = trim((string) request('month', ''));
|
||||
$selected = $default;
|
||||
if (preg_match('/^\d{4}-\d{2}$/', $requested) === 1) {
|
||||
try {
|
||||
$candidate = CarbonImmutable::createFromFormat(
|
||||
'!Y-m',
|
||||
$requested,
|
||||
'Asia/Shanghai',
|
||||
);
|
||||
if ($candidate instanceof CarbonImmutable
|
||||
&& $candidate->format('Y-m') === $requested) {
|
||||
$selected = $candidate;
|
||||
}
|
||||
} catch (Throwable) {
|
||||
// 非法月份回落到最近已结束月份。
|
||||
}
|
||||
}
|
||||
|
||||
$periodStart = $selected->startOfMonth();
|
||||
$periodEnd = $selected->endOfMonth();
|
||||
if ($selected->isSameMonth($now)) {
|
||||
$periodEnd = $now;
|
||||
}
|
||||
|
||||
$options = [];
|
||||
for ($offset = 0; $offset < 12; $offset++) {
|
||||
$month = $default->subMonthsNoOverflow($offset);
|
||||
$options[] = [
|
||||
'value' => $month->format('Y-m'),
|
||||
'label' => $month->format('Y年n月'),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'value' => $selected->format('Y-m'),
|
||||
'label' => $selected->format('Y年n月'),
|
||||
'start' => $periodStart->format('Y-m-d'),
|
||||
'end' => $periodEnd->format('Y-m-d'),
|
||||
'options' => $options,
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
private function cachedStoreDaily(string $start, string $end): array
|
||||
{
|
||||
$cacheKey = implode(':', [
|
||||
'ecommerce-finance',
|
||||
'fund-balance-monitor-month',
|
||||
'v2',
|
||||
(string) company_id(),
|
||||
$start,
|
||||
$end,
|
||||
$this->pinduoduoOpeningBalances->cacheVersion(),
|
||||
]);
|
||||
|
||||
return Cache::remember(
|
||||
$cacheKey,
|
||||
now()->addMinutes(self::STORE_CACHE_MINUTES),
|
||||
fn (): array => $this->stores->dailyBalances($start, $end),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $month
|
||||
* @param array<string,mixed> $accountData
|
||||
* @param array<string,mixed> $storeDaily
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function build(
|
||||
array $month,
|
||||
array $accountData,
|
||||
array $storeDaily,
|
||||
?string $accountError,
|
||||
?string $storeError,
|
||||
): array {
|
||||
$accountReady = $accountError === null && $accountData !== [];
|
||||
$storeReady = $storeError === null && $storeDaily !== [];
|
||||
$fundOverview = (array) ($accountData['fundOverview'] ?? []);
|
||||
$distribution = collect((array) ($fundOverview['distribution'] ?? []))
|
||||
->keyBy(static fn (array $row): string => (string) ($row['category'] ?? ''));
|
||||
$retainedCard = (array) ($accountData['retainedCard'] ?? []);
|
||||
$unretainedCard = (array) ($accountData['unretainedCard'] ?? []);
|
||||
$storePlatforms = $this->storePlatformRows(
|
||||
(array) ($storeDaily['platforms'] ?? []),
|
||||
$month['end'],
|
||||
);
|
||||
$storeReadyPlatforms = count(array_filter(
|
||||
$storePlatforms,
|
||||
static fn (array $row): bool => $row['available'],
|
||||
));
|
||||
$storePlatformTotal = count(StoreReceivingBalanceOverviewService::PLATFORMS);
|
||||
$storeComplete = $storeReady
|
||||
&& $storeReadyPlatforms === $storePlatformTotal
|
||||
&& $storePlatformTotal > 0;
|
||||
$storeBalance = round(array_sum(array_column($storePlatforms, 'balance')), 2);
|
||||
$accountLinks = $this->accountLinks($month);
|
||||
$storeLink = $this->storeLink($month);
|
||||
|
||||
$categories = [
|
||||
$this->accountCategory(
|
||||
'bank',
|
||||
'银行账户余额',
|
||||
'保留银行账户',
|
||||
(array) $distribution->get('bank', []),
|
||||
$accountLinks['bank'],
|
||||
'查看银行余额明细',
|
||||
),
|
||||
$this->accountCategory(
|
||||
'alipay',
|
||||
'非店铺支付宝余额',
|
||||
'保留非店铺支付宝账户',
|
||||
(array) $distribution->get('alipay', []),
|
||||
$accountLinks['alipay'],
|
||||
'查看支付宝账户明细',
|
||||
),
|
||||
$this->accountCategory(
|
||||
'wangshang',
|
||||
'网商银行余额',
|
||||
'保留网商银行账户',
|
||||
(array) $distribution->get('wangshang', []),
|
||||
$accountLinks['wangshang'],
|
||||
'查看网商银行明细',
|
||||
),
|
||||
$this->accountCategory(
|
||||
'other',
|
||||
'其他账户余额',
|
||||
'其他支付宝、微信等保留账户',
|
||||
(array) $distribution->get('other', []),
|
||||
$accountLinks['other'],
|
||||
'查看其他账户明细',
|
||||
),
|
||||
[
|
||||
'key' => 'store',
|
||||
'label' => '店铺余额',
|
||||
'description' => '8 个店铺平台每日余额汇总',
|
||||
'count' => $storeReadyPlatforms,
|
||||
'count_label' => $storeReadyPlatforms . '/' . $storePlatformTotal . ' 个平台',
|
||||
'balance' => $storeBalance,
|
||||
'available' => $storeBalance,
|
||||
'blocked' => 0.0,
|
||||
'share' => 0.0,
|
||||
'status' => $storeComplete ? '完整' : ($storeReady ? '部分平台未就绪' : '暂不可用'),
|
||||
'status_level' => $storeComplete ? 'complete' : 'warning',
|
||||
'link' => $storeLink,
|
||||
'link_label' => '查看店铺每日余额明细',
|
||||
],
|
||||
];
|
||||
|
||||
$totalBalance = round(array_sum(array_column($categories, 'balance')), 2);
|
||||
$availableBalance = round(array_sum(array_column($categories, 'available')), 2);
|
||||
$blockedBalance = round(array_sum(array_column($categories, 'blocked')), 2);
|
||||
foreach ($categories as &$category) {
|
||||
$category['share'] = $totalBalance > 0
|
||||
? round(max(0.0, (float) $category['balance']) / $totalBalance * 100, 1)
|
||||
: 0.0;
|
||||
}
|
||||
unset($category);
|
||||
|
||||
$complete = $accountReady && $storeComplete;
|
||||
$status = $this->status(
|
||||
$complete,
|
||||
$accountReady,
|
||||
$storeReady,
|
||||
$storeReadyPlatforms,
|
||||
$storePlatformTotal,
|
||||
$accountError,
|
||||
$storeError,
|
||||
);
|
||||
|
||||
return [
|
||||
'view' => 'business.pages.fund-management.balance-monitor',
|
||||
'month' => $month,
|
||||
'periodLabel' => $month['start'] . ' 至 ' . $month['end'],
|
||||
'summary' => [
|
||||
'total' => $totalBalance,
|
||||
'available' => $availableBalance,
|
||||
'blocked' => $blockedBalance,
|
||||
'available_percent' => $totalBalance > 0
|
||||
? round($availableBalance / $totalBalance * 100, 1)
|
||||
: 0.0,
|
||||
'blocked_percent' => $totalBalance > 0
|
||||
? round($blockedBalance / $totalBalance * 100, 1)
|
||||
: 0.0,
|
||||
'retained_account_count' => (int) ($retainedCard['count'] ?? 0),
|
||||
'unretained_account_count' => (int) ($unretainedCard['count'] ?? 0),
|
||||
'unretained_balance' => $this->number($unretainedCard['current_balance'] ?? null),
|
||||
'store_platform_ready' => $storeReadyPlatforms,
|
||||
'store_platform_total' => $storePlatformTotal,
|
||||
'complete' => $complete,
|
||||
],
|
||||
'categories' => $categories,
|
||||
'status' => $status,
|
||||
'links' => [
|
||||
'refresh' => route('business.pages.show', [
|
||||
'section' => 'fund-management',
|
||||
'page' => 'fund-balance-monitor',
|
||||
'month' => $month['value'],
|
||||
]),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $rowData
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function accountCategory(
|
||||
string $key,
|
||||
string $label,
|
||||
string $description,
|
||||
array $rowData,
|
||||
string $link,
|
||||
string $linkLabel,
|
||||
): array {
|
||||
$balance = $this->number($rowData['current_balance'] ?? null);
|
||||
$available = $this->number($rowData['available_balance'] ?? null);
|
||||
$blocked = $this->number($rowData['blocked_balance'] ?? null);
|
||||
$count = (int) ($rowData['count'] ?? 0);
|
||||
$missing = array_key_exists('current_balance', $rowData)
|
||||
&& $rowData['current_balance'] === null;
|
||||
|
||||
return [
|
||||
'key' => $key,
|
||||
'label' => $label,
|
||||
'description' => $description,
|
||||
'count' => $count,
|
||||
'count_label' => number_format($count) . ' 户',
|
||||
'balance' => $balance,
|
||||
'available' => $available,
|
||||
'blocked' => $blocked,
|
||||
'share' => 0.0,
|
||||
'status' => $missing ? '余额待核对' : ($count > 0 ? '正常' : '无账户'),
|
||||
'status_level' => $missing ? 'warning' : 'complete',
|
||||
'link' => $link,
|
||||
'link_label' => $linkLabel,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int,array<string,mixed>> $platforms
|
||||
* @return array<int,array<string,mixed>>
|
||||
*/
|
||||
private function storePlatformRows(array $platforms, string $asOf): array
|
||||
{
|
||||
$bySlug = collect($platforms)->keyBy(
|
||||
static fn (array $platform): string => (string) ($platform['slug'] ?? ''),
|
||||
);
|
||||
$rows = [];
|
||||
foreach (StoreReceivingBalanceOverviewService::PLATFORMS as $definition) {
|
||||
$platform = (array) $bySlug->get((string) $definition['slug'], []);
|
||||
$daily = (array) ($platform['daily'][$asOf] ?? []);
|
||||
$closing = $daily['closing'] ?? null;
|
||||
$available = is_numeric($closing);
|
||||
$rows[] = [
|
||||
'slug' => (string) $definition['slug'],
|
||||
'name' => (string) $definition['name'],
|
||||
'available' => $available,
|
||||
'balance' => $available ? round((float) $closing, 2) : 0.0,
|
||||
'date' => $asOf,
|
||||
'error' => $available
|
||||
? ''
|
||||
: trim((string) (
|
||||
$platform['daily_error']
|
||||
?? $platform['error']
|
||||
?? '月末余额未就绪'
|
||||
)),
|
||||
];
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $month
|
||||
* @return array<string,string>
|
||||
*/
|
||||
private function accountLinks(array $month): array
|
||||
{
|
||||
$query = [
|
||||
'section' => 'financial-operations',
|
||||
'page' => 'ledger',
|
||||
'tab' => 'overview',
|
||||
'view' => 'accounts',
|
||||
'keep' => 'retained',
|
||||
'period_from' => $month['start'],
|
||||
'period_to' => $month['end'],
|
||||
];
|
||||
|
||||
return [
|
||||
'bank' => route('business.pages.show', [
|
||||
'section' => 'financial-operations',
|
||||
'page' => 'fund-ledger',
|
||||
'tab' => 'bank_balance',
|
||||
'period_from' => $month['start'],
|
||||
'period_to' => $month['end'],
|
||||
]),
|
||||
'alipay' => route('business.pages.show', [
|
||||
...$query,
|
||||
'account_category' => 'alipay',
|
||||
]),
|
||||
'wangshang' => route('business.pages.show', [
|
||||
...$query,
|
||||
'account_category' => 'wangshang',
|
||||
]),
|
||||
'other' => route('business.pages.show', [
|
||||
...$query,
|
||||
'account_category' => 'other',
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $month */
|
||||
private function storeLink(array $month): string
|
||||
{
|
||||
$url = route('business.pages.show', [
|
||||
'section' => 'billing-transactions',
|
||||
'page' => 'store-receiving-bills',
|
||||
'tab' => 'balance-overview',
|
||||
'month' => $month['value'],
|
||||
]);
|
||||
|
||||
return $url . '#trend-table-title';
|
||||
}
|
||||
|
||||
/** @return array{level:string,title:string,message:string} */
|
||||
private function status(
|
||||
bool $complete,
|
||||
bool $accountReady,
|
||||
bool $storeReady,
|
||||
int $readyPlatforms,
|
||||
int $platformTotal,
|
||||
?string $accountError,
|
||||
?string $storeError,
|
||||
): array {
|
||||
if (! $accountReady) {
|
||||
return [
|
||||
'level' => 'warning',
|
||||
'title' => '账户余额待补齐',
|
||||
'message' => $accountError ?: '非店铺账户余额暂时无法读取。',
|
||||
];
|
||||
}
|
||||
if (! $storeReady) {
|
||||
return [
|
||||
'level' => 'warning',
|
||||
'title' => '店铺余额待补齐',
|
||||
'message' => $storeError ?: '店铺每日余额暂时无法读取,当前总资金为已接入数据小计。',
|
||||
];
|
||||
}
|
||||
if (! $complete) {
|
||||
return [
|
||||
'level' => 'warning',
|
||||
'title' => '部分店铺平台未就绪',
|
||||
'message' => $readyPlatforms . '/' . $platformTotal
|
||||
. ' 个平台已返回月末余额,当前总资金为已接入数据小计。',
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'level' => 'complete',
|
||||
'title' => '本月数据完整',
|
||||
'message' => '五类资金均已按月末口径汇总,可直接用于资金审阅。',
|
||||
];
|
||||
}
|
||||
|
||||
private function number(mixed $value): float
|
||||
{
|
||||
return is_numeric($value) ? round((float) $value, 2) : 0.0;
|
||||
}
|
||||
}
|
||||
@ -96,9 +96,10 @@ final class NonStoreAccountMonitorPageData
|
||||
) {
|
||||
}
|
||||
|
||||
public function page(): array
|
||||
/** @param array{from:string,to:string}|null $periodOverride */
|
||||
public function page(?array $periodOverride = null): array
|
||||
{
|
||||
$period = $this->period();
|
||||
$period = $periodOverride ?? $this->period();
|
||||
$accountRows = $this->accountRows()->all();
|
||||
$this->attachFlowMetrics($accountRows, $period, true);
|
||||
$this->attachBankBillMetrics($accountRows, $period, true);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
<h2>账户余额总览</h2>
|
||||
<p class="trend-subtitle">8 个平台账户 · {{ queryPeriodLabel }} · 单位:万元</p>
|
||||
<p class="trend-platform-note">
|
||||
聚合 8 个收款平台(淘系支付宝账户、淘系微信账户、拼多多账户、京东网银钱包账户、抖音账户、唯品会MP账户、唯品会JX账户、小红书账户)在选定发生时间范围内的期初、收入与支出(单位:万元)
|
||||
聚合 8 个收款平台(店铺支付宝账户、淘系微信账户、拼多多账户、京东网银钱包账户、抖音账户、唯品会MP账户、唯品会JX账户、小红书账户)在选定发生时间范围内的期初、收入与支出(单位:万元)
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@ -406,14 +406,14 @@
|
||||
@click="toggleStoreGroup(group.slug)"
|
||||
>
|
||||
<span>{{ isStoreGroupExpanded(group.slug) ? '▾' : '▸' }}</span>
|
||||
{{ group.stores.length }} 家店铺
|
||||
本页小计 · {{ group.stores.length }} 家店铺
|
||||
</button>
|
||||
</td>
|
||||
<td v-for="date in visibleDates" :key="`group-${group.slug}-${date}`">
|
||||
<button
|
||||
type="button"
|
||||
class="trend-matrix-cell"
|
||||
:aria-label="`${group.platform} ${date} 店铺合计`"
|
||||
:aria-label="`${group.platform} ${date} 本页小计`"
|
||||
:disabled="!group.totals[date]"
|
||||
@click="openDailyDetail('group', group, date)"
|
||||
>{{ groupCell(group, date) }}</button>
|
||||
@ -495,6 +495,21 @@ const lastCompleteMonthRange = () => {
|
||||
};
|
||||
};
|
||||
|
||||
const requestedMonthRange = () => {
|
||||
const month = new URLSearchParams(window.location.search).get('month') || '';
|
||||
const match = /^(\d{4})-(\d{2})$/.exec(month);
|
||||
if (!match) return null;
|
||||
const year = Number(match[1]);
|
||||
const monthNumber = Number(match[2]);
|
||||
if (monthNumber < 1 || monthNumber > 12) return null;
|
||||
const lastDay = new Date(year, monthNumber, 0).getDate();
|
||||
|
||||
return {
|
||||
start: `${year}-${pad(monthNumber)}-01`,
|
||||
end: `${year}-${pad(monthNumber)}-${pad(lastDay)}`,
|
||||
};
|
||||
};
|
||||
|
||||
const emptySummary = () => ({
|
||||
opening_balance: null,
|
||||
income: null,
|
||||
@ -519,7 +534,7 @@ export default {
|
||||
apiBase: { type: String, required: true },
|
||||
},
|
||||
data() {
|
||||
const range = lastCompleteMonthRange();
|
||||
const range = requestedMonthRange() || lastCompleteMonthRange();
|
||||
|
||||
return {
|
||||
dateRange: { ...range },
|
||||
|
||||
@ -49,7 +49,7 @@
|
||||
<p v-if="filterOptionsError" class="tw-filter-error" role="alert">筛选选项加载失败,可输入名称查询。<button type="button" class="tw-button" @click="fetchFilterOptions">重试选项</button></p>
|
||||
</form>
|
||||
|
||||
<section class="tw-panel" aria-label="淘系支付宝账户账单明细">
|
||||
<section class="tw-panel" aria-label="全部支付宝账户账单明细">
|
||||
<div v-if="error" class="tw-alert" role="alert"><span>{{ error }}</span><button type="button" @click="fetch">重新加载</button></div>
|
||||
<div class="tw-toolbar">
|
||||
<div><strong>账单明细</strong><span v-if="!loading" class="tw-count">{{ total }} 条</span></div>
|
||||
|
||||
@ -0,0 +1,630 @@
|
||||
@php
|
||||
$money = static fn (mixed $value): string => number_format((float) $value / 10000, 2, '.', ',');
|
||||
$summary = $summary ?? [];
|
||||
$categories = $categories ?? [];
|
||||
$status = $status ?? [];
|
||||
$month = $month ?? [];
|
||||
@endphp
|
||||
|
||||
<style>
|
||||
.monthly-funds {
|
||||
--mf-gold: #b9954f;
|
||||
--mf-gold-dark: #856632;
|
||||
--mf-gold-soft: #f7f0de;
|
||||
--mf-border: #d8d2c7;
|
||||
--mf-ink: #171717;
|
||||
--mf-muted: #595959;
|
||||
display: grid;
|
||||
gap: 1rem;
|
||||
margin: 1rem 0 2rem;
|
||||
color: var(--mf-ink);
|
||||
font-size: .8125rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.monthly-funds * {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.monthly-funds__header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
padding-bottom: .9rem;
|
||||
border-bottom: 1px solid var(--mf-border);
|
||||
}
|
||||
|
||||
.monthly-funds__title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .5rem;
|
||||
margin: 0;
|
||||
font-size: .875rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.monthly-funds__title .material-icons-outlined {
|
||||
color: var(--mf-gold-dark);
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.monthly-funds__subtitle {
|
||||
margin: .28rem 0 0;
|
||||
color: var(--mf-muted);
|
||||
font-size: .75rem;
|
||||
}
|
||||
|
||||
.monthly-funds__toolbar {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
justify-content: flex-end;
|
||||
gap: .55rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.monthly-funds__field {
|
||||
display: grid;
|
||||
gap: .25rem;
|
||||
}
|
||||
|
||||
.monthly-funds__field label {
|
||||
color: var(--mf-muted);
|
||||
font-size: .6875rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.monthly-funds__select {
|
||||
min-width: 9rem;
|
||||
height: 2.125rem;
|
||||
padding: 0 .65rem;
|
||||
border: 1px solid var(--mf-border);
|
||||
border-radius: .5rem;
|
||||
background: #fff;
|
||||
color: var(--mf-ink);
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.monthly-funds__select:focus {
|
||||
border-color: var(--mf-gold-dark);
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 3px rgba(133, 102, 50, .18);
|
||||
}
|
||||
|
||||
.monthly-funds__button {
|
||||
display: inline-flex;
|
||||
min-height: 2.125rem;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: .35rem;
|
||||
padding: 0 .72rem;
|
||||
border: 1px solid var(--mf-border);
|
||||
border-radius: .5rem;
|
||||
background: #fff;
|
||||
color: var(--mf-ink);
|
||||
font: inherit;
|
||||
font-size: .75rem;
|
||||
font-weight: 500;
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.monthly-funds__button--primary {
|
||||
border-color: var(--mf-gold-dark);
|
||||
background: var(--mf-gold-dark);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.monthly-funds__button:hover,
|
||||
.monthly-funds__button:focus-visible {
|
||||
border-color: var(--mf-gold);
|
||||
background: #fffdf8;
|
||||
color: var(--mf-gold-dark);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.monthly-funds__button--primary:hover,
|
||||
.monthly-funds__button--primary:focus-visible {
|
||||
border-color: #6a5129;
|
||||
background: #6a5129;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.monthly-funds__button .material-icons-outlined {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.monthly-funds__status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .55rem;
|
||||
padding: .7rem .85rem;
|
||||
border: 1px solid #cfddc6;
|
||||
border-radius: .5rem;
|
||||
background: #f6faf3;
|
||||
color: #405f31;
|
||||
font-size: .75rem;
|
||||
}
|
||||
|
||||
.monthly-funds__status.is-warning {
|
||||
border-color: #e3d1aa;
|
||||
background: #fffaf0;
|
||||
color: #7b4d00;
|
||||
}
|
||||
|
||||
.monthly-funds__status .material-icons-outlined {
|
||||
flex: 0 0 auto;
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
.monthly-funds__summary {
|
||||
display: grid;
|
||||
gap: .75rem;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.monthly-funds__card {
|
||||
display: grid;
|
||||
min-width: 0;
|
||||
gap: .35rem;
|
||||
padding: 1rem 1.1rem;
|
||||
border: 1px solid var(--mf-border);
|
||||
border-radius: .75rem;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.monthly-funds__card:first-child {
|
||||
border-color: #c7ad72;
|
||||
background: linear-gradient(135deg, #fffdf8 0%, #f7f0de 100%);
|
||||
}
|
||||
|
||||
.monthly-funds__card-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: .5rem;
|
||||
color: var(--mf-muted);
|
||||
font-size: .75rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.monthly-funds__card-label .material-icons-outlined {
|
||||
color: var(--mf-gold-dark);
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.monthly-funds__card-value {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: .25rem;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.monthly-funds__card-value strong {
|
||||
overflow: hidden;
|
||||
font-size: 1.45rem;
|
||||
line-height: 1.15;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.monthly-funds__card-value span {
|
||||
color: var(--mf-muted);
|
||||
font-size: .6875rem;
|
||||
}
|
||||
|
||||
.monthly-funds__card-note {
|
||||
overflow: hidden;
|
||||
color: var(--mf-muted);
|
||||
font-size: .6875rem;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.monthly-funds__panel {
|
||||
min-width: 0;
|
||||
padding: 1rem;
|
||||
border: 1px solid var(--mf-border);
|
||||
border-radius: .75rem;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.monthly-funds__panel-head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: .75rem;
|
||||
margin-bottom: .75rem;
|
||||
}
|
||||
|
||||
.monthly-funds__panel-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .38rem;
|
||||
margin: 0;
|
||||
font-size: .8125rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.monthly-funds__panel-title .material-icons-outlined {
|
||||
color: var(--mf-gold-dark);
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.monthly-funds__panel-note {
|
||||
color: var(--mf-muted);
|
||||
font-size: .6875rem;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.monthly-funds__table-shell {
|
||||
width: 100%;
|
||||
overflow-x: auto;
|
||||
scrollbar-color: var(--mf-gold) #f1eee7;
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.monthly-funds__table {
|
||||
width: 100%;
|
||||
min-width: 58rem;
|
||||
border-collapse: separate;
|
||||
border-spacing: 0;
|
||||
font-size: .75rem;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.monthly-funds__table th,
|
||||
.monthly-funds__table td {
|
||||
padding: .72rem .65rem;
|
||||
border-bottom: 1px solid #ebe7df;
|
||||
text-align: left;
|
||||
vertical-align: middle;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.monthly-funds__table th {
|
||||
background: #faf8f3;
|
||||
color: var(--mf-muted);
|
||||
font-size: .6875rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.monthly-funds__table th.num,
|
||||
.monthly-funds__table td.num {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.monthly-funds__table tbody tr:hover td {
|
||||
background: #fffdf8;
|
||||
}
|
||||
|
||||
.monthly-funds__table tfoot td {
|
||||
border-top: 1px solid #cbbfae;
|
||||
border-bottom: 0;
|
||||
background: #fbf8f1;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.monthly-funds__category {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .6rem;
|
||||
min-width: 10rem;
|
||||
}
|
||||
|
||||
.monthly-funds__dot {
|
||||
width: .55rem;
|
||||
height: .55rem;
|
||||
flex: 0 0 auto;
|
||||
border-radius: 50%;
|
||||
background: #bfb6a5;
|
||||
}
|
||||
|
||||
.monthly-funds__dot.is-bank { background: #856632; }
|
||||
.monthly-funds__dot.is-alipay { background: #b9954f; }
|
||||
.monthly-funds__dot.is-wangshang { background: #9eaa86; }
|
||||
.monthly-funds__dot.is-other { background: #c9c3b8; }
|
||||
.monthly-funds__dot.is-store { background: #d5bd86; }
|
||||
|
||||
.monthly-funds__category-copy {
|
||||
display: grid;
|
||||
gap: .08rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.monthly-funds__category-copy strong {
|
||||
font-size: .75rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.monthly-funds__category-copy small {
|
||||
color: var(--mf-muted);
|
||||
font-size: .625rem;
|
||||
}
|
||||
|
||||
.monthly-funds__share {
|
||||
display: grid;
|
||||
min-width: 5.5rem;
|
||||
gap: .22rem;
|
||||
}
|
||||
|
||||
.monthly-funds__share-track {
|
||||
height: .3rem;
|
||||
overflow: hidden;
|
||||
border-radius: 999px;
|
||||
background: #eeeae3;
|
||||
}
|
||||
|
||||
.monthly-funds__share-track span {
|
||||
display: block;
|
||||
height: 100%;
|
||||
border-radius: inherit;
|
||||
background: var(--mf-gold);
|
||||
}
|
||||
|
||||
.monthly-funds__badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: .25rem;
|
||||
min-height: 1.45rem;
|
||||
padding: 0 .45rem;
|
||||
border: 1px solid #c7d6bc;
|
||||
border-radius: 999px;
|
||||
background: #f4f8f1;
|
||||
color: #405f31;
|
||||
font-size: .625rem;
|
||||
}
|
||||
|
||||
.monthly-funds__badge.is-warning {
|
||||
border-color: #e3d1aa;
|
||||
background: #fffaf0;
|
||||
color: #7b4d00;
|
||||
}
|
||||
|
||||
.monthly-funds__detail-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: .28rem;
|
||||
color: var(--mf-gold-dark);
|
||||
font-size: .6875rem;
|
||||
font-weight: 500;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.monthly-funds__detail-link:hover,
|
||||
.monthly-funds__detail-link:focus-visible {
|
||||
color: #6a5129;
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 3px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.monthly-funds__detail-link .material-icons-outlined {
|
||||
font-size: .9rem;
|
||||
}
|
||||
|
||||
.monthly-funds__footnote {
|
||||
display: grid;
|
||||
gap: .25rem;
|
||||
color: var(--mf-muted);
|
||||
font-size: .6875rem;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.monthly-funds__footnote strong {
|
||||
color: var(--mf-ink);
|
||||
font-size: .75rem;
|
||||
}
|
||||
|
||||
@media (max-width: 860px) {
|
||||
.monthly-funds__header {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.monthly-funds__toolbar {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.monthly-funds__summary {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.monthly-funds__panel-head {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.monthly-funds__panel-note {
|
||||
text-align: left;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<section class="monthly-funds" aria-label="{{ $month['label'] }}资金余额">
|
||||
<header class="monthly-funds__header">
|
||||
<div>
|
||||
<h2 class="monthly-funds__title">
|
||||
<span class="material-icons-outlined" aria-hidden="true">account_balance_wallet</span>
|
||||
{{ $month['label'] }}资金余额
|
||||
</h2>
|
||||
<p class="monthly-funds__subtitle">
|
||||
{{ $periodLabel ?? '' }} · 月末余额口径,统一查看总资金、可用资金和不可用资金。
|
||||
</p>
|
||||
</div>
|
||||
<form class="monthly-funds__toolbar" method="GET" action="{{ route('business.pages.show', [
|
||||
'section' => 'fund-management',
|
||||
'page' => 'fund-balance-monitor',
|
||||
]) }}">
|
||||
<div class="monthly-funds__field">
|
||||
<label for="fund-monitor-month">统计月份</label>
|
||||
<select class="monthly-funds__select" id="fund-monitor-month" name="month">
|
||||
@foreach ($month['options'] as $option)
|
||||
<option value="{{ $option['value'] }}" @selected($option['value'] === $month['value'])>
|
||||
{{ $option['label'] }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<button class="monthly-funds__button monthly-funds__button--primary" type="submit">
|
||||
<span class="material-icons-outlined" aria-hidden="true">search</span>
|
||||
查看
|
||||
</button>
|
||||
<a class="monthly-funds__button" href="{{ $links['refresh'] ?? url()->full() }}">
|
||||
<span class="material-icons-outlined" aria-hidden="true">refresh</span>
|
||||
刷新
|
||||
</a>
|
||||
</form>
|
||||
</header>
|
||||
|
||||
<div @class([
|
||||
'monthly-funds__status',
|
||||
'is-warning' => ($status['level'] ?? '') !== 'complete',
|
||||
])>
|
||||
<span class="material-icons-outlined" aria-hidden="true">
|
||||
{{ ($status['level'] ?? '') === 'complete' ? 'check_circle' : 'warning' }}
|
||||
</span>
|
||||
<span><strong>{{ $status['title'] ?? '' }}</strong> · {{ $status['message'] ?? '' }}</span>
|
||||
</div>
|
||||
|
||||
<div class="monthly-funds__summary" aria-label="本月资金核心指标">
|
||||
<section class="monthly-funds__card">
|
||||
<span class="monthly-funds__card-label">
|
||||
本月资金总额
|
||||
<span class="material-icons-outlined" aria-hidden="true">account_balance_wallet</span>
|
||||
</span>
|
||||
<span class="monthly-funds__card-value">
|
||||
<strong>{{ $money($summary['total'] ?? 0) }}</strong>
|
||||
<span>万元</span>
|
||||
</span>
|
||||
<span class="monthly-funds__card-note">五类月末余额合计</span>
|
||||
</section>
|
||||
<section class="monthly-funds__card">
|
||||
<span class="monthly-funds__card-label">
|
||||
本月可用资金
|
||||
<span class="material-icons-outlined" aria-hidden="true">payments</span>
|
||||
</span>
|
||||
<span class="monthly-funds__card-value">
|
||||
<strong>{{ $money($summary['available'] ?? 0) }}</strong>
|
||||
<span>万元</span>
|
||||
</span>
|
||||
<span class="monthly-funds__card-note">
|
||||
占资金总额 {{ number_format((float) ($summary['available_percent'] ?? 0), 1) }}%
|
||||
</span>
|
||||
</section>
|
||||
<section class="monthly-funds__card">
|
||||
<span class="monthly-funds__card-label">
|
||||
本月不可用资金
|
||||
<span class="material-icons-outlined" aria-hidden="true">lock</span>
|
||||
</span>
|
||||
<span class="monthly-funds__card-value">
|
||||
<strong>{{ $money($summary['blocked'] ?? 0) }}</strong>
|
||||
<span>万元</span>
|
||||
</span>
|
||||
<span class="monthly-funds__card-note">
|
||||
占资金总额 {{ number_format((float) ($summary['blocked_percent'] ?? 0), 1) }}%
|
||||
</span>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="monthly-funds__panel" aria-label="本月资金类别汇总">
|
||||
<div class="monthly-funds__panel-head">
|
||||
<h3 class="monthly-funds__panel-title">
|
||||
<span class="material-icons-outlined" aria-hidden="true">table_view</span>
|
||||
资金类别汇总
|
||||
</h3>
|
||||
<span class="monthly-funds__panel-note">
|
||||
月末余额 · {{ $month['end'] }} · 单位:万元
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="monthly-funds__table-shell">
|
||||
<table class="monthly-funds__table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">资金类别</th>
|
||||
<th scope="col">账户范围</th>
|
||||
<th scope="col" class="num">月末余额</th>
|
||||
<th scope="col">资金占比</th>
|
||||
<th scope="col" class="num">可用金额</th>
|
||||
<th scope="col" class="num">不可用金额</th>
|
||||
<th scope="col">状态</th>
|
||||
<th scope="col">明细入口</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($categories as $category)
|
||||
<tr>
|
||||
<td>
|
||||
<span class="monthly-funds__category">
|
||||
<span @class([
|
||||
'monthly-funds__dot',
|
||||
'is-' . $category['key'] => true,
|
||||
]) aria-hidden="true"></span>
|
||||
<span class="monthly-funds__category-copy">
|
||||
<strong>{{ $category['label'] }}</strong>
|
||||
<small>{{ $category['count_label'] }}</small>
|
||||
</span>
|
||||
</span>
|
||||
</td>
|
||||
<td>{{ $category['description'] }}</td>
|
||||
<td class="num">{{ $money($category['balance']) }}</td>
|
||||
<td>
|
||||
<span class="monthly-funds__share">
|
||||
<span>{{ number_format((float) $category['share'], 1) }}%</span>
|
||||
<span class="monthly-funds__share-track">
|
||||
<span style="width: {{ max(0, min(100, (float) $category['share'])) }}%"></span>
|
||||
</span>
|
||||
</span>
|
||||
</td>
|
||||
<td class="num">{{ $money($category['available']) }}</td>
|
||||
<td class="num">{{ $money($category['blocked']) }}</td>
|
||||
<td>
|
||||
<span @class([
|
||||
'monthly-funds__badge',
|
||||
'is-warning' => $category['status_level'] !== 'complete',
|
||||
])>
|
||||
{{ $category['status'] }}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<a class="monthly-funds__detail-link" href="{{ $category['link'] }}">
|
||||
<span>{{ $category['link_label'] }}</span>
|
||||
<span class="material-icons-outlined" aria-hidden="true">open_in_new</span>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="2">资金合计</td>
|
||||
<td class="num">{{ $money($summary['total'] ?? 0) }}</td>
|
||||
<td>100.0%</td>
|
||||
<td class="num">{{ $money($summary['available'] ?? 0) }}</td>
|
||||
<td class="num">{{ $money($summary['blocked'] ?? 0) }}</td>
|
||||
<td colspan="2">
|
||||
{{ ($summary['complete'] ?? false) ? '本月数据完整' : '按已接入数据汇总' }}
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<footer class="monthly-funds__footnote">
|
||||
<strong>口径说明</strong>
|
||||
<span>
|
||||
非店铺资金按保留账户的月末余额计算,包含银行账户、非店铺支付宝、网商银行和其他账户;
|
||||
其他账户包含其他支付宝、微信等。
|
||||
</span>
|
||||
<span>
|
||||
店铺资金取 {{ $summary['store_platform_ready'] ?? 0 }}/{{ $summary['store_platform_total'] ?? 0 }}
|
||||
个平台的月末每日余额;未就绪平台不计为 0,页面会提示按已接入数据汇总。
|
||||
@if (($summary['unretained_account_count'] ?? 0) > 0)
|
||||
另有不保留账户 {{ $summary['unretained_account_count'] }} 户、余额
|
||||
{{ $money($summary['unretained_balance'] ?? 0) }} 万元,未计入总资金。
|
||||
@endif
|
||||
</span>
|
||||
</footer>
|
||||
</section>
|
||||
@ -43,6 +43,7 @@ class FinanceLedgerNavigationTest extends FeatureTestCase
|
||||
$this->assertSame([
|
||||
'账户资金管理',
|
||||
'资金台账',
|
||||
'资金余额监控',
|
||||
], array_column($visiblePages, 'title'));
|
||||
$this->assertSame('financial-operations', $visiblePages[0]['route_section']);
|
||||
$this->assertSame('ledger', $visiblePages[0]['route_page']);
|
||||
|
||||
251
tests/Feature/Business/FundBalanceMonitorPageTest.php
Normal file
251
tests/Feature/Business/FundBalanceMonitorPageTest.php
Normal file
@ -0,0 +1,251 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Business;
|
||||
|
||||
use App\Models\Auth\Permission;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mockery;
|
||||
use Modules\EcommerceFinance\Services\PinduoduoOpeningBalanceService;
|
||||
use Modules\EcommerceFinance\Services\StoreReceivingBalanceOverviewService;
|
||||
use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class FundBalanceMonitorPageTest extends FeatureTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Carbon::setTestNow('2026-11-27 10:30:00');
|
||||
|
||||
$this->user->attachPermission(
|
||||
Permission::where('name', 'read-admin-panel')->firstOrFail(),
|
||||
);
|
||||
|
||||
$connection = DB::connection('business_mirror');
|
||||
foreach ([
|
||||
[
|
||||
'company_name' => '监控测试有限公司',
|
||||
'account_short' => '监控工商银行',
|
||||
'account_type' => '公户',
|
||||
'bank_name' => '中国工商银行常州分行',
|
||||
'account_no' => '100200300400500',
|
||||
'company_plan' => '保留',
|
||||
'account_should_keep' => '是',
|
||||
'current_balance' => 100000,
|
||||
'daily_available' => 80000,
|
||||
'blocked_amount' => 20000,
|
||||
],
|
||||
[
|
||||
'company_name' => '监控测试有限公司',
|
||||
'account_short' => '非店铺支付宝',
|
||||
'account_type' => '支付宝',
|
||||
'account_no' => 'monitor@example.com',
|
||||
'company_plan' => '保留',
|
||||
'account_should_keep' => '是',
|
||||
'current_balance' => 50000,
|
||||
'daily_available' => 50000,
|
||||
'blocked_amount' => 0,
|
||||
],
|
||||
[
|
||||
'company_name' => '监控测试有限公司',
|
||||
'account_short' => '非店铺网商',
|
||||
'account_type' => '网商银行',
|
||||
'account_no' => 'wangshang-monitor',
|
||||
'company_plan' => '保留',
|
||||
'account_should_keep' => '是',
|
||||
'current_balance' => 25000,
|
||||
'daily_available' => 25000,
|
||||
'blocked_amount' => 0,
|
||||
],
|
||||
[
|
||||
'company_name' => '朱俊祥',
|
||||
'account_short' => '朱俊祥微信',
|
||||
'account_type' => '微信',
|
||||
'account_no' => 'wx-monitor',
|
||||
'company_plan' => '保留',
|
||||
'account_should_keep' => '是',
|
||||
'current_balance' => 10000,
|
||||
'daily_available' => 10000,
|
||||
'blocked_amount' => 0,
|
||||
],
|
||||
[
|
||||
'company_name' => '不保留测试有限公司',
|
||||
'account_short' => '待注销华夏银行',
|
||||
'account_type' => '公户',
|
||||
'bank_name' => '华夏银行常州分行',
|
||||
'account_no' => '131500000001',
|
||||
'company_plan' => '不保留',
|
||||
'account_should_keep' => '否',
|
||||
'current_balance' => 30000,
|
||||
'daily_available' => 30000,
|
||||
'blocked_amount' => 0,
|
||||
],
|
||||
] as $account) {
|
||||
$connection->table('fin_accounts')->insert($account);
|
||||
}
|
||||
|
||||
$connection->table('fin_flow_summary_account_sources')->insert([
|
||||
['account_short' => '监控工商银行', 'data_source' => '银企直连', 'updated_by' => '测试'],
|
||||
['account_short' => '非店铺支付宝', 'data_source' => '手动', 'updated_by' => '测试'],
|
||||
['account_short' => '非店铺网商', 'data_source' => '手动', 'updated_by' => '测试'],
|
||||
['account_short' => '朱俊祥微信', 'data_source' => '手动', 'updated_by' => '测试'],
|
||||
['account_short' => '待注销华夏银行', 'data_source' => '手动', 'updated_by' => '测试'],
|
||||
]);
|
||||
$connection->table('fin_account_opening')->insert([
|
||||
['account_short' => '监控工商银行', 'opening_date' => '2026-10-01', 'opening_balance' => 90000],
|
||||
['account_short' => '非店铺支付宝', 'opening_date' => '2026-10-01', 'opening_balance' => 40000],
|
||||
['account_short' => '朱俊祥微信', 'opening_date' => '2026-10-01', 'opening_balance' => 5000],
|
||||
]);
|
||||
$connection->table('fin_daily_flows')->insert([
|
||||
[
|
||||
'flow_date' => '2026-10-31',
|
||||
'account_short' => '非店铺支付宝',
|
||||
'opening_balance' => 40000,
|
||||
'inflow' => 10000,
|
||||
'outflow' => 0,
|
||||
'closing_balance' => 50000,
|
||||
],
|
||||
[
|
||||
'flow_date' => '2026-10-31',
|
||||
'account_short' => '朱俊祥微信',
|
||||
'opening_balance' => 5000,
|
||||
'inflow' => 5000,
|
||||
'outflow' => 0,
|
||||
'closing_balance' => 10000,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Carbon::setTestNow();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_page_combines_retained_accounts_and_complete_store_balances(): void
|
||||
{
|
||||
$this->bindStoreBalances($this->storeDailyPayload(8));
|
||||
|
||||
$response = $this->loginAs()->get($this->pageUrl());
|
||||
|
||||
$response->assertOk()
|
||||
->assertSeeText('2026年10月资金余额')
|
||||
->assertSeeText('月末余额口径')
|
||||
->assertSeeText('97.50')
|
||||
->assertSeeText('80.00')
|
||||
->assertSeeText('95.50')
|
||||
->assertSeeText('2.00')
|
||||
->assertSeeText('银行账户余额')
|
||||
->assertSeeText('非店铺支付宝余额')
|
||||
->assertSeeText('网商银行余额')
|
||||
->assertSeeText('其他账户余额')
|
||||
->assertSeeText('店铺余额')
|
||||
->assertSeeText('查看银行余额明细')
|
||||
->assertSeeText('查看店铺每日余额明细')
|
||||
->assertSee('bank_balance', false)
|
||||
->assertSee('period_from=2026-10-01', false)
|
||||
->assertSee('month=2026-10', false)
|
||||
->assertDontSeeText('银行资金集中度')
|
||||
->assertDontSeeText('近 30 天')
|
||||
->assertDontSeeText('100.50');
|
||||
}
|
||||
|
||||
public function test_page_uses_an_explicit_partial_total_when_a_store_platform_is_missing(): void
|
||||
{
|
||||
$this->bindStoreBalances($this->storeDailyPayload(7));
|
||||
|
||||
$response = $this->loginAs()->get($this->pageUrl());
|
||||
|
||||
$response->assertOk()
|
||||
->assertSeeText('部分店铺平台未就绪')
|
||||
->assertSeeText('按已接入数据汇总')
|
||||
->assertSeeText('87.50')
|
||||
->assertSeeText('70.00')
|
||||
->assertSeeText('7/8 个平台已返回月末余额');
|
||||
}
|
||||
|
||||
public function test_page_uses_the_selected_month(): void
|
||||
{
|
||||
$this->bindStoreBalances(
|
||||
$this->storeDailyPayload(8, ['2026-09-28', '2026-09-29', '2026-09-30']),
|
||||
'2026-09-01',
|
||||
'2026-09-30',
|
||||
);
|
||||
|
||||
$response = $this->loginAs()->get($this->pageUrl() . '?month=2026-09');
|
||||
|
||||
$response->assertOk()
|
||||
->assertSeeText('2026年9月资金余额')
|
||||
->assertSeeText('2026-09-01 至 2026-09-30')
|
||||
->assertSee('month=2026-09', false);
|
||||
}
|
||||
|
||||
private function pageUrl(): string
|
||||
{
|
||||
return route('business.pages.show', [
|
||||
'section' => 'fund-management',
|
||||
'page' => 'fund-balance-monitor',
|
||||
]);
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $payload */
|
||||
private function bindStoreBalances(
|
||||
array $payload,
|
||||
string $start = '2026-10-01',
|
||||
string $end = '2026-10-31',
|
||||
): void
|
||||
{
|
||||
$stores = Mockery::mock(StoreReceivingBalanceOverviewService::class);
|
||||
$stores->shouldReceive('dailyBalances')
|
||||
->once()
|
||||
->with($start, $end)
|
||||
->andReturn($payload);
|
||||
$this->app->instance(StoreReceivingBalanceOverviewService::class, $stores);
|
||||
|
||||
$pinduoduo = Mockery::mock(PinduoduoOpeningBalanceService::class);
|
||||
$pinduoduo->shouldReceive('cacheVersion')->once()->andReturn('fund-monitor-test-v1');
|
||||
$this->app->instance(PinduoduoOpeningBalanceService::class, $pinduoduo);
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
private function storeDailyPayload(
|
||||
int $availablePlatforms,
|
||||
array $dates = ['2026-10-29', '2026-10-30', '2026-10-31'],
|
||||
): array
|
||||
{
|
||||
$platforms = [];
|
||||
foreach (StoreReceivingBalanceOverviewService::PLATFORMS as $index => $definition) {
|
||||
$available = $index < $availablePlatforms;
|
||||
$daily = [];
|
||||
foreach ($dates as $dateIndex => $date) {
|
||||
$currentDateAvailable = $available;
|
||||
$daily[$date] = [
|
||||
'opening' => $currentDateAvailable ? 90000 : null,
|
||||
'income' => $currentDateAvailable ? 10000 : null,
|
||||
'expense' => 0,
|
||||
'closing' => $currentDateAvailable && $dateIndex === 2
|
||||
? 100000
|
||||
: ($available ? 90000 : null),
|
||||
'available' => $currentDateAvailable,
|
||||
];
|
||||
}
|
||||
$platforms[] = [
|
||||
'slug' => $definition['slug'],
|
||||
'name' => $definition['name'],
|
||||
'available' => $available,
|
||||
'opening_balance' => $available ? 90000 : null,
|
||||
'income' => $available ? 10000 : null,
|
||||
'expense' => 0,
|
||||
'balance' => $available ? 100000 : null,
|
||||
'error' => $available ? null : '平台期初余额未就绪',
|
||||
'daily_error' => null,
|
||||
'daily' => $daily,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'dates' => $dates,
|
||||
'platforms' => $platforms,
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -120,7 +120,7 @@ class StoreReceivingBalanceOverviewServiceTest extends TestCase
|
||||
$this->assertCount(8, $result['details']);
|
||||
$this->assertSame([
|
||||
'platform_slug' => 'taobao-alipay',
|
||||
'platform' => '淘系支付宝账户',
|
||||
'platform' => '店铺支付宝账户',
|
||||
'store_name' => '店铺-1',
|
||||
'bill_item' => '货款收入',
|
||||
'amount' => 100.30,
|
||||
@ -167,7 +167,7 @@ class StoreReceivingBalanceOverviewServiceTest extends TestCase
|
||||
$this->assertCount(8, $result['details']);
|
||||
$this->assertSame([
|
||||
'platform_slug' => 'taobao-alipay',
|
||||
'platform' => '淘系支付宝账户',
|
||||
'platform' => '店铺支付宝账户',
|
||||
'store_name' => '店铺-1',
|
||||
'bill_item' => '平台扣费',
|
||||
'amount' => 20.30,
|
||||
@ -198,7 +198,7 @@ class StoreReceivingBalanceOverviewServiceTest extends TestCase
|
||||
$this->assertCount(8, $result['details']);
|
||||
$this->assertSame([
|
||||
'platform_slug' => 'taobao-alipay',
|
||||
'platform' => '淘系支付宝账户',
|
||||
'platform' => '店铺支付宝账户',
|
||||
'store_name' => '',
|
||||
'bill_item' => '',
|
||||
'amount' => 109.05,
|
||||
@ -237,7 +237,7 @@ class StoreReceivingBalanceOverviewServiceTest extends TestCase
|
||||
$this->assertCount(8, $result['details']);
|
||||
$this->assertSame([
|
||||
'platform_slug' => 'taobao-alipay',
|
||||
'platform' => '淘系支付宝账户',
|
||||
'platform' => '店铺支付宝账户',
|
||||
'store_name' => '店铺-1',
|
||||
'bill_item' => '',
|
||||
'opening_balance' => 100.10,
|
||||
|
||||
@ -35,7 +35,7 @@ class StoreReceivingBalanceOverviewTest extends TestCase
|
||||
$source = $this->overviewSource();
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'聚合 8 个收款平台(淘系支付宝账户、淘系微信账户、拼多多账户、京东网银钱包账户、抖音账户、唯品会MP账户、唯品会JX账户、小红书账户)',
|
||||
'聚合 8 个收款平台(店铺支付宝账户、淘系微信账户、拼多多账户、京东网银钱包账户、抖音账户、唯品会MP账户、唯品会JX账户、小红书账户)',
|
||||
$source,
|
||||
);
|
||||
$this->assertStringContainsString('期初余额合计', $source);
|
||||
@ -54,6 +54,9 @@ class StoreReceivingBalanceOverviewTest extends TestCase
|
||||
{
|
||||
$source = $this->overviewSource();
|
||||
|
||||
$this->assertStringContainsString('const requestedMonthRange = () => {', $source);
|
||||
$this->assertStringContainsString("new URLSearchParams(window.location.search).get('month')", $source);
|
||||
$this->assertStringContainsString('requestedMonthRange() || lastCompleteMonthRange()', $source);
|
||||
$this->assertStringContainsString('${this.apiBase}/daily-balance', $source);
|
||||
$this->assertStringContainsString('${this.apiBase}/daily-balance-stores', $source);
|
||||
$this->assertStringContainsString('this.dailySummary = body.daily_summary || {}', $source);
|
||||
@ -88,6 +91,8 @@ class StoreReceivingBalanceOverviewTest extends TestCase
|
||||
$this->assertStringContainsString('v-model.trim="storeKeywordDraft"', $source);
|
||||
$this->assertStringContainsString('@submit.prevent="applyStoreFilters"', $source);
|
||||
$this->assertStringContainsString('@click="openDailyDetail(\'store\', store, date)"', $source);
|
||||
$this->assertStringContainsString('本页小计 · {{ group.stores.length }} 家店铺', $source);
|
||||
$this->assertStringContainsString('${group.platform} ${date} 本页小计', $source);
|
||||
$this->assertStringContainsString('v-if="selectedDailyDetail"', $source);
|
||||
$this->assertStringContainsString('dailyDetailMoney(\'opening\')', $source);
|
||||
$this->assertStringContainsString('dailyDetailSigned(\'income\')', $source);
|
||||
@ -124,7 +129,7 @@ class StoreReceivingBalanceOverviewTest extends TestCase
|
||||
$navigation = file_get_contents(__DIR__ . '/../../../config/business_navigation.php');
|
||||
|
||||
$this->assertLessThan(
|
||||
strpos($navigation, "['slug' => 'taobao-alipay', 'title' => '淘系支付宝账户']"),
|
||||
strpos($navigation, "['slug' => 'taobao-alipay', 'title' => '全部支付宝账户']"),
|
||||
strpos($navigation, "['slug' => 'balance-overview', 'title' => '账户余额总览']"),
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user