fix: 月度期末余额按发生时间仅展示单月
移除 7-9 月历史列和环比列,按发生时间结束日期所在月份读取平台及店铺汇总。
This commit is contained in:
parent
394a6838d3
commit
e5e11a25cb
@ -25,12 +25,12 @@ class StoreReceivingBalanceOverview extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function monthlyClosing(StoreReceivingBalanceOverviewService $service)
|
||||
public function monthlyClosing(Request $request, StoreReceivingBalanceOverviewService $service)
|
||||
{
|
||||
$this->authorizeStoreReceivingBills();
|
||||
|
||||
try {
|
||||
return response()->json($service->monthlyClosing());
|
||||
return response()->json($service->monthlyClosing(...$this->requestedPeriod($request)));
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
|
||||
|
||||
@ -59,13 +59,6 @@ class StoreReceivingBalanceOverviewService
|
||||
['slug' => 'xiaohongshu', 'name' => '小红书账户'],
|
||||
];
|
||||
|
||||
public const MONTHLY_CLOSING_MONTHS = [
|
||||
['key' => '2026-07', 'label' => '7月'],
|
||||
['key' => '2026-08', 'label' => '8月'],
|
||||
['key' => '2026-09', 'label' => '9月'],
|
||||
['key' => '2026-10', 'label' => '10月'],
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
private readonly AlipayBills $alipayBills,
|
||||
private readonly TaobaoWechatAccountBills $taobaoWechatBills,
|
||||
@ -159,71 +152,61 @@ class StoreReceivingBalanceOverviewService
|
||||
}
|
||||
|
||||
/**
|
||||
* 2026 年 7-10 月各平台期末余额矩阵。环比为 10 月相对 9 月。
|
||||
* 选定月份各平台期末余额。只读取当前发生时间对应的一个月。
|
||||
*
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function monthlyClosing(): array
|
||||
public function monthlyClosing(string $periodStart, ?string $periodEnd = null): array
|
||||
{
|
||||
$monthOverviews = [];
|
||||
foreach (self::MONTHLY_CLOSING_MONTHS as $month) {
|
||||
$monthOverviews[$month['key']] = $this->overview($month['key']);
|
||||
}
|
||||
|
||||
[$periodStart, $periodEnd, $periodMonth] = $this->periodForRange($periodStart, $periodEnd);
|
||||
$periodOverview = $this->overview($periodStart, $periodEnd);
|
||||
$rows = [];
|
||||
$availableRows = 0;
|
||||
foreach (self::PLATFORMS as $definition) {
|
||||
$balances = [];
|
||||
foreach (self::MONTHLY_CLOSING_MONTHS as $month) {
|
||||
$platform = $this->platformFromOverview(
|
||||
$monthOverviews[$month['key']],
|
||||
$definition['slug'],
|
||||
);
|
||||
$balances[$month['key']] = $platform !== null
|
||||
&& $platform['available']
|
||||
&& is_numeric($platform['balance'] ?? null)
|
||||
? round((float) $platform['balance'], 2)
|
||||
: null;
|
||||
}
|
||||
|
||||
$available = ! in_array(null, $balances, true);
|
||||
foreach (self::PLATFORMS as $definition) {
|
||||
$platform = $this->platformFromOverview($periodOverview, $definition['slug']);
|
||||
$balance = $platform !== null
|
||||
&& $platform['available']
|
||||
&& is_numeric($platform['balance'] ?? null)
|
||||
? round((float) $platform['balance'], 2)
|
||||
: null;
|
||||
$available = $balance !== null;
|
||||
if ($available) {
|
||||
$availableRows++;
|
||||
}
|
||||
$rows[] = $this->monthlyClosingRow(
|
||||
$definition['slug'],
|
||||
$definition['name'],
|
||||
$balances,
|
||||
[$periodMonth => $balance],
|
||||
$available,
|
||||
);
|
||||
}
|
||||
|
||||
$totals = [];
|
||||
foreach (self::MONTHLY_CLOSING_MONTHS as $month) {
|
||||
$overview = $monthOverviews[$month['key']];
|
||||
$totals[$month['key']] = $overview['summary']['complete']
|
||||
&& is_numeric($overview['summary']['balance'] ?? null)
|
||||
? round((float) $overview['summary']['balance'], 2)
|
||||
: null;
|
||||
}
|
||||
$totalBalance = $periodOverview['summary']['complete']
|
||||
&& is_numeric($periodOverview['summary']['balance'] ?? null)
|
||||
? round((float) $periodOverview['summary']['balance'], 2)
|
||||
: null;
|
||||
|
||||
return [
|
||||
'months' => self::MONTHLY_CLOSING_MONTHS,
|
||||
'comparison' => [
|
||||
'current' => '2026-10',
|
||||
'previous' => '2026-09',
|
||||
'month' => $periodMonth,
|
||||
'period' => [
|
||||
'start' => $periodStart,
|
||||
'end' => $periodEnd,
|
||||
],
|
||||
'months' => [[
|
||||
'key' => $periodMonth,
|
||||
'label' => (int) CarbonImmutable::parse($periodStart, 'Asia/Shanghai')->format('n') . '月',
|
||||
]],
|
||||
'summary' => [
|
||||
'platform_count' => count(self::PLATFORMS),
|
||||
'available_platform_count' => $availableRows,
|
||||
'complete' => $availableRows === count(self::PLATFORMS)
|
||||
&& ! in_array(null, $totals, true),
|
||||
'complete' => $availableRows === count(self::PLATFORMS) && $totalBalance !== null,
|
||||
],
|
||||
'total' => $this->monthlyClosingRow(
|
||||
'total',
|
||||
'合计',
|
||||
$totals,
|
||||
! in_array(null, $totals, true),
|
||||
[$periodMonth => $totalBalance],
|
||||
$totalBalance !== null,
|
||||
),
|
||||
'platforms' => $rows,
|
||||
];
|
||||
@ -252,26 +235,11 @@ class StoreReceivingBalanceOverviewService
|
||||
bool $available,
|
||||
): array
|
||||
{
|
||||
$currentMonth = (string) self::MONTHLY_CLOSING_MONTHS[array_key_last(self::MONTHLY_CLOSING_MONTHS)]['key'];
|
||||
$previousMonth = (string) self::MONTHLY_CLOSING_MONTHS[array_key_last(self::MONTHLY_CLOSING_MONTHS) - 1]['key'];
|
||||
$current = $balances[$currentMonth];
|
||||
$previous = $balances[$previousMonth];
|
||||
$changeAmount = $current !== null && $previous !== null
|
||||
? round($current - $previous, 2)
|
||||
: null;
|
||||
$changeRate = $changeAmount !== null && abs($previous) >= 0.005
|
||||
? round($changeAmount / abs($previous) * 100, 2)
|
||||
: ($changeAmount === 0.0 ? 0.0 : null);
|
||||
|
||||
return [
|
||||
'slug' => $slug,
|
||||
'name' => $name,
|
||||
'available' => $available,
|
||||
'balances' => $balances,
|
||||
'change' => [
|
||||
'amount' => $changeAmount,
|
||||
'rate' => $changeRate,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -133,7 +133,7 @@
|
||||
<span class="monthly-closing-badge">新增</span>
|
||||
</div>
|
||||
<p>
|
||||
2026 年 7-10 月{{ monthlyClosingView === 'store' ? '店铺' : '各平台' }}期末余额
|
||||
{{ monthlyClosingMonthLabel }}{{ monthlyClosingView === 'store' ? '店铺' : '各平台' }}期末余额
|
||||
· 金额单位:万元
|
||||
</p>
|
||||
</div>
|
||||
@ -160,22 +160,22 @@
|
||||
|
||||
<div v-if="monthlyClosingLoading" class="monthly-closing-loading" role="status">
|
||||
<span v-for="index in 4" :key="index"></span>
|
||||
<p>正在汇总 4 个月度期末余额…</p>
|
||||
<p>正在汇总 {{ monthlyClosingMonthLabel }}期末余额…</p>
|
||||
</div>
|
||||
<div v-else-if="monthlyClosingError" class="monthly-closing-error" role="alert">
|
||||
<span>{{ monthlyClosingError }}</span>
|
||||
<button type="button" @click="fetchMonthlyClosing">重新加载</button>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="monthlyClosingView === 'store' && monthlyClosingStoreLoading && !monthlyStoreMonthDetails.length"
|
||||
v-else-if="monthlyClosingView === 'store' && monthlyClosingStoreLoading"
|
||||
class="monthly-closing-loading"
|
||||
role="status"
|
||||
>
|
||||
<span v-for="index in 4" :key="index"></span>
|
||||
<p>正在汇总 7-10 月店铺期末余额…</p>
|
||||
<p>正在汇总 {{ monthlyClosingMonthLabel }}店铺期末余额…</p>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="monthlyClosingView === 'store' && monthlyClosingStoreError && !monthlyStoreMonthDetails.length"
|
||||
v-else-if="monthlyClosingView === 'store' && monthlyClosingStoreError"
|
||||
class="monthly-closing-error"
|
||||
role="alert"
|
||||
>
|
||||
@ -187,10 +187,9 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">平台账户</th>
|
||||
<th v-for="month in monthlyClosing.months" :key="month.key" scope="col" class="is-number">
|
||||
<th v-for="month in monthlyClosing.months" :key="month.key" scope="col" class="is-number monthly-closing-month-head">
|
||||
{{ month.label }}
|
||||
</th>
|
||||
<th scope="col" class="is-number monthly-closing-compare-head">环比</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -204,39 +203,20 @@
|
||||
<td v-for="month in monthlyClosing.months" :key="month.key" class="is-number">
|
||||
{{ monthlyBalanceWan(row, month.key) }}
|
||||
</td>
|
||||
<td class="is-number monthly-closing-compare">
|
||||
<span :class="changeClass(row.change.amount)">{{ signedMoneyWan(row.change.amount) }}</span>
|
||||
<small v-if="row.change.rate !== null" :class="changeClass(row.change.amount)">
|
||||
{{ signedPercent(row.change.rate) }}
|
||||
</small>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<template v-else>
|
||||
<div
|
||||
v-if="monthlyClosingStoreLoading || monthlyClosingStoreError"
|
||||
class="monthly-store-progress"
|
||||
:class="{ 'is-error': monthlyClosingStoreError }"
|
||||
role="status"
|
||||
>
|
||||
<span v-if="monthlyClosingStoreLoading">
|
||||
正在补齐历史月份({{ monthlyStoreMonthDetails.length }} / {{ monthlyClosing.months.length }})…
|
||||
</span>
|
||||
<span v-else>{{ monthlyClosingStoreError }}</span>
|
||||
<button v-if="monthlyClosingStoreError" type="button" @click="fetchMonthlyClosingStores">重新加载</button>
|
||||
</div>
|
||||
<div class="monthly-closing-scroll is-store">
|
||||
<table class="monthly-closing-table monthly-closing-store-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">平台账户</th>
|
||||
<th scope="col">店铺名称</th>
|
||||
<th v-for="month in monthlyClosing.months" :key="month.key" scope="col" class="is-number">
|
||||
<th v-for="month in monthlyClosing.months" :key="month.key" scope="col" class="is-number monthly-closing-month-head">
|
||||
{{ month.label }}
|
||||
</th>
|
||||
<th scope="col" class="is-number monthly-closing-compare-head">环比</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -250,19 +230,13 @@
|
||||
<td v-for="month in monthlyClosing.months" :key="month.key" class="is-number">
|
||||
{{ monthlyBalanceWan(row, month.key) }}
|
||||
</td>
|
||||
<td class="is-number monthly-closing-compare">
|
||||
<span :class="changeClass(row.change.amount)">{{ signedMoneyWan(row.change.amount) }}</span>
|
||||
<small v-if="row.change.rate !== null" :class="changeClass(row.change.amount)">
|
||||
{{ signedPercent(row.change.rate) }}
|
||||
</small>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
<footer class="monthly-closing-foot">
|
||||
<span>环比口径:2026年10月期末余额 − 2026年9月期末余额,金额单位为万元,百分比以上月余额为基数。</span>
|
||||
<span>统计月份:{{ monthlyClosingMonthLabel }};金额单位为万元。</span>
|
||||
<span v-if="!monthlyClosingLoading && !monthlyClosingError">
|
||||
{{ monthlyClosingView === 'store'
|
||||
? '店铺期末余额 = 期初余额 + 收入 - 支出;缺少期初时显示“—”。'
|
||||
@ -428,19 +402,6 @@ const dateConfig = {
|
||||
onReady: (_, value, picker) => picker.calendarContainer.classList.add('overview-calendar'),
|
||||
};
|
||||
|
||||
const closingChange = (balances, currentMonth, previousMonth) => {
|
||||
const current = balances[currentMonth];
|
||||
const previous = balances[previousMonth];
|
||||
const amount = Number.isFinite(current) && Number.isFinite(previous)
|
||||
? Math.round((current - previous) * 100) / 100
|
||||
: null;
|
||||
const rate = amount !== null && Math.abs(previous) >= 0.005
|
||||
? Math.round((amount / Math.abs(previous)) * 10000) / 100
|
||||
: (amount === 0 ? 0 : null);
|
||||
|
||||
return { amount, rate };
|
||||
};
|
||||
|
||||
export default {
|
||||
name: 'StoreReceivingBalanceOverview',
|
||||
components: { flatPicker },
|
||||
@ -449,6 +410,7 @@ export default {
|
||||
},
|
||||
data() {
|
||||
const range = currentMonthRange();
|
||||
const closingMonth = range.end.slice(0, 7);
|
||||
|
||||
return {
|
||||
dateRange: { ...range },
|
||||
@ -481,16 +443,20 @@ export default {
|
||||
monthlyClosingStoreRequestSerial: 0,
|
||||
monthlyStoreMonthDetails: [],
|
||||
monthlyClosing: {
|
||||
months: [],
|
||||
month: closingMonth,
|
||||
period: {
|
||||
start: range.start,
|
||||
end: range.end,
|
||||
},
|
||||
months: [{
|
||||
key: closingMonth,
|
||||
label: `${Number(closingMonth.slice(5))}月`,
|
||||
}],
|
||||
summary: {
|
||||
platform_count: 8,
|
||||
available_platform_count: 0,
|
||||
complete: false,
|
||||
},
|
||||
comparison: {
|
||||
current: '2026-10',
|
||||
previous: '2026-09',
|
||||
},
|
||||
total: null,
|
||||
platforms: [],
|
||||
},
|
||||
@ -728,6 +694,17 @@ export default {
|
||||
? `${total} 个店铺 · ${incomplete} 个期初待补`
|
||||
: `${total} 个店铺`;
|
||||
},
|
||||
monthlyClosingMonth() {
|
||||
const selectedDate = this.queryRange.end || this.queryRange.start;
|
||||
|
||||
return selectedDate ? selectedDate.slice(0, 7) : '';
|
||||
},
|
||||
monthlyClosingMonthLabel() {
|
||||
const monthKey = this.monthlyClosingMonth;
|
||||
if (!/^\d{4}-\d{2}$/.test(monthKey)) return '';
|
||||
|
||||
return `${monthKey.slice(0, 4)}年${Number(monthKey.slice(5))}月`;
|
||||
},
|
||||
monthlyStoreRows() {
|
||||
const months = Array.isArray(this.monthlyClosing.months)
|
||||
? this.monthlyClosing.months.map(month => month.key)
|
||||
@ -756,17 +733,14 @@ export default {
|
||||
});
|
||||
});
|
||||
|
||||
const currentMonth = this.monthlyClosing.comparison.current;
|
||||
const previousMonth = this.monthlyClosing.comparison.previous;
|
||||
const rows = Array.from(grouped.values()).map(row => ({
|
||||
...row,
|
||||
available: months.some(month => row.balances[month] !== null),
|
||||
change: closingChange(row.balances, currentMonth, previousMonth),
|
||||
}));
|
||||
const latestMonth = months[months.length - 1];
|
||||
const selectedMonth = months[0];
|
||||
rows.sort((left, right) => {
|
||||
const leftBalance = left.balances[latestMonth];
|
||||
const rightBalance = right.balances[latestMonth];
|
||||
const leftBalance = left.balances[selectedMonth];
|
||||
const rightBalance = right.balances[selectedMonth];
|
||||
|
||||
return (
|
||||
(leftBalance === null ? 1 : 0) - (rightBalance === null ? 1 : 0)
|
||||
@ -831,6 +805,7 @@ export default {
|
||||
this.queryRange = { ...this.dateRange };
|
||||
if (this.detailOpen) this.closeDetails();
|
||||
this.fetchOverview();
|
||||
this.fetchMonthlyClosing();
|
||||
},
|
||||
async fetchMonthlyClosing() {
|
||||
const requestId = ++this.monthlyClosingRequestSerial;
|
||||
@ -841,10 +816,19 @@ export default {
|
||||
this.monthlyStoreMonthDetails = [];
|
||||
|
||||
try {
|
||||
const response = await window.axios.get(`${this.apiBase}/monthly-closing`);
|
||||
const response = await window.axios.get(`${this.apiBase}/monthly-closing`, {
|
||||
params: {
|
||||
month: this.monthlyClosingMonth,
|
||||
},
|
||||
});
|
||||
if (requestId !== this.monthlyClosingRequestSerial) return;
|
||||
const body = response.data || {};
|
||||
this.monthlyClosing = {
|
||||
month: body.month || this.monthlyClosingMonth,
|
||||
period: body.period || {
|
||||
start: this.queryRange.start,
|
||||
end: this.queryRange.end,
|
||||
},
|
||||
months: Array.isArray(body.months) ? body.months : [],
|
||||
summary: {
|
||||
platform_count: 8,
|
||||
@ -852,11 +836,6 @@ export default {
|
||||
complete: false,
|
||||
...(body.summary || {}),
|
||||
},
|
||||
comparison: {
|
||||
current: '2026-10',
|
||||
previous: '2026-09',
|
||||
...(body.comparison || {}),
|
||||
},
|
||||
total: body.total || null,
|
||||
platforms: Array.isArray(body.platforms) ? body.platforms : [],
|
||||
};
|
||||
@ -881,8 +860,10 @@ export default {
|
||||
}
|
||||
},
|
||||
async fetchMonthlyClosingStores() {
|
||||
const months = Array.isArray(this.monthlyClosing.months) ? this.monthlyClosing.months : [];
|
||||
if (!months.length) return;
|
||||
const month = Array.isArray(this.monthlyClosing.months)
|
||||
? this.monthlyClosing.months[0]
|
||||
: null;
|
||||
if (!month) return;
|
||||
|
||||
const requestId = ++this.monthlyClosingStoreRequestSerial;
|
||||
this.monthlyClosingStoreLoading = true;
|
||||
@ -890,26 +871,19 @@ export default {
|
||||
this.monthlyStoreMonthDetails = [];
|
||||
|
||||
try {
|
||||
for (const month of months) {
|
||||
const [year, monthNumber] = month.key.split('-').map(Number);
|
||||
const lastDay = new Date(year, monthNumber, 0).getDate();
|
||||
const response = await window.axios.get(`${this.apiBase}/balance-store-detail`, {
|
||||
params: {
|
||||
start: `${month.key}-01`,
|
||||
end: `${month.key}-${pad(lastDay)}`,
|
||||
},
|
||||
});
|
||||
if (requestId !== this.monthlyClosingStoreRequestSerial) return;
|
||||
|
||||
this.monthlyStoreMonthDetails = [...this.monthlyStoreMonthDetails, {
|
||||
const response = await window.axios.get(`${this.apiBase}/balance-store-detail`, {
|
||||
params: {
|
||||
month: month.key,
|
||||
details: Array.isArray(response.data && response.data.details)
|
||||
? response.data.details
|
||||
: [],
|
||||
}];
|
||||
}
|
||||
},
|
||||
});
|
||||
if (requestId !== this.monthlyClosingStoreRequestSerial) return;
|
||||
|
||||
this.monthlyStoreMonthDetails = [{
|
||||
month: month.key,
|
||||
details: Array.isArray(response.data && response.data.details)
|
||||
? response.data.details
|
||||
: [],
|
||||
}];
|
||||
this.monthlyClosingStoreLoaded = true;
|
||||
} catch (error) {
|
||||
if (requestId !== this.monthlyClosingStoreRequestSerial) return;
|
||||
@ -1079,28 +1053,6 @@ export default {
|
||||
maximumFractionDigits: 2,
|
||||
})}万`;
|
||||
},
|
||||
signedMoneyWan(value) {
|
||||
if (value === null || value === undefined || !Number.isFinite(Number(value))) return '—';
|
||||
const amount = Number(value);
|
||||
const sign = amount > 0 ? '+' : '';
|
||||
|
||||
return `${sign}¥${(amount / 10000).toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
})}万`;
|
||||
},
|
||||
signedPercent(value) {
|
||||
if (value === null || value === undefined || !Number.isFinite(Number(value))) return '';
|
||||
const percent = Number(value);
|
||||
|
||||
return `${percent > 0 ? '+' : ''}${percent.toFixed(2)}%`;
|
||||
},
|
||||
changeClass(value) {
|
||||
if (value === null || value === undefined || !Number.isFinite(Number(value))) return '';
|
||||
if (Number(value) > 0) return 'is-up';
|
||||
if (Number(value) < 0) return 'is-down';
|
||||
return 'is-flat';
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@ -1548,40 +1500,16 @@ export default {
|
||||
z-index: 2;
|
||||
top: 0;
|
||||
}
|
||||
.monthly-store-progress {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: .75rem;
|
||||
padding: .5rem .8rem;
|
||||
border-bottom: 1px solid #eee7da;
|
||||
background: #fbf7ef;
|
||||
color: var(--overview-muted);
|
||||
font-size: .6875rem;
|
||||
}
|
||||
.monthly-store-progress.is-error {
|
||||
background: #fff6f3;
|
||||
color: #9b3c2d;
|
||||
}
|
||||
.monthly-store-progress button {
|
||||
padding: .2rem .55rem;
|
||||
border: 1px solid currentColor;
|
||||
border-radius: .35rem;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
.monthly-closing-table {
|
||||
width: 100%;
|
||||
min-width: 44rem;
|
||||
min-width: 34rem;
|
||||
border-collapse: separate;
|
||||
border-spacing: 0;
|
||||
font-size: .75rem;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.monthly-closing-store-table {
|
||||
min-width: 60rem;
|
||||
min-width: 46rem;
|
||||
}
|
||||
.monthly-closing-table th,
|
||||
.monthly-closing-table td {
|
||||
@ -1598,15 +1526,14 @@ export default {
|
||||
text-align: left;
|
||||
}
|
||||
.monthly-closing-table thead th.is-number,
|
||||
.monthly-closing-table td.is-number,
|
||||
.monthly-closing-compare-head {
|
||||
.monthly-closing-table td.is-number {
|
||||
text-align: right;
|
||||
}
|
||||
.monthly-closing-table thead th:last-child,
|
||||
.monthly-closing-table td:last-child {
|
||||
border-right: 0;
|
||||
}
|
||||
.monthly-closing-table thead th:nth-last-child(2) {
|
||||
.monthly-closing-table thead th.monthly-closing-month-head {
|
||||
background: #f3e5c9;
|
||||
color: #6e5025;
|
||||
}
|
||||
@ -1635,23 +1562,6 @@ export default {
|
||||
.monthly-closing-store-table .monthly-store-name {
|
||||
min-width: 15rem;
|
||||
}
|
||||
.monthly-closing-compare span,
|
||||
.monthly-closing-compare small {
|
||||
display: block;
|
||||
}
|
||||
.monthly-closing-compare small {
|
||||
margin-top: .1rem;
|
||||
font-size: .625rem;
|
||||
}
|
||||
.monthly-closing-compare .is-up {
|
||||
color: #4d7436;
|
||||
}
|
||||
.monthly-closing-compare .is-down {
|
||||
color: #a43d3d;
|
||||
}
|
||||
.monthly-closing-compare .is-flat {
|
||||
color: #777066;
|
||||
}
|
||||
.monthly-closing-foot {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
@ -79,19 +79,15 @@ class StoreReceivingBalanceOverviewEndpointTest extends FeatureTestCase
|
||||
->assertJsonPath('summary.complete', true);
|
||||
}
|
||||
|
||||
public function test_monthly_closing_endpoint_returns_four_months_and_eight_platforms(): void
|
||||
public function test_monthly_closing_endpoint_returns_selected_month_and_eight_platforms(): void
|
||||
{
|
||||
$this->user->attachPermission(
|
||||
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
||||
);
|
||||
|
||||
$payload = [
|
||||
'months' => [
|
||||
['key' => '2026-07', 'label' => '7月'],
|
||||
['key' => '2026-08', 'label' => '8月'],
|
||||
['key' => '2026-09', 'label' => '9月'],
|
||||
['key' => '2026-10', 'label' => '10月'],
|
||||
],
|
||||
'month' => '2026-10',
|
||||
'months' => [['key' => '2026-10', 'label' => '10月']],
|
||||
'summary' => [
|
||||
'platform_count' => 8,
|
||||
'available_platform_count' => 8,
|
||||
@ -101,21 +97,22 @@ class StoreReceivingBalanceOverviewEndpointTest extends FeatureTestCase
|
||||
'slug' => 'total',
|
||||
'name' => '合计',
|
||||
'balances' => ['2026-10' => 1040.0],
|
||||
'change' => ['amount' => 10.0, 'rate' => 0.97],
|
||||
],
|
||||
'platforms' => [],
|
||||
];
|
||||
$service = Mockery::mock(StoreReceivingBalanceOverviewService::class);
|
||||
$service->shouldReceive('monthlyClosing')->once()->andReturn($payload);
|
||||
$service->shouldReceive('monthlyClosing')->once()->with('2026-10')->andReturn($payload);
|
||||
$this->app->instance(StoreReceivingBalanceOverviewService::class, $service);
|
||||
|
||||
$this->loginAs()
|
||||
->getJson(route('ecommerce-finance.account-bills.overview.monthly-closing'))
|
||||
->getJson(route('ecommerce-finance.account-bills.overview.monthly-closing', [
|
||||
'month' => '2026-10',
|
||||
]))
|
||||
->assertOk()
|
||||
->assertJsonCount(4, 'months')
|
||||
->assertJsonCount(1, 'months')
|
||||
->assertJsonPath('months.0.label', '10月')
|
||||
->assertJsonPath('summary.complete', true)
|
||||
->assertJsonPath('total.change.amount', 10)
|
||||
->assertJsonPath('total.change.rate', 0.97);
|
||||
->assertJsonMissingPath('total.change');
|
||||
}
|
||||
|
||||
public function test_overview_page_uses_the_vue_mount_point(): void
|
||||
|
||||
@ -320,36 +320,35 @@ class StoreReceivingBalanceOverviewServiceTest extends TestCase
|
||||
$this->assertNull($rows[0]['amount']);
|
||||
}
|
||||
|
||||
public function test_monthly_closing_returns_july_to_october_for_all_platforms(): void
|
||||
public function test_monthly_closing_returns_only_the_selected_month_for_all_platforms(): void
|
||||
{
|
||||
$monthOrdinal = ['2026-07' => 1, '2026-08' => 2, '2026-09' => 3, '2026-10' => 4];
|
||||
$seenPeriods = [];
|
||||
$service = $this->service(function (string $platform, string $start, string $end) use (&$seenPeriods, $monthOrdinal): array {
|
||||
$service = $this->service(function (string $platform, string $start, string $end) use (&$seenPeriods): array {
|
||||
$seenPeriods[] = [$platform, $start, $end];
|
||||
$index = array_search($platform, array_column(StoreReceivingBalanceOverviewService::PLATFORMS, 'slug'), true) + 1;
|
||||
|
||||
return [
|
||||
'opening_balance' => 1000.00 * $index,
|
||||
'income' => 10.00 * $monthOrdinal[substr($start, 0, 7)],
|
||||
'income' => 10.00,
|
||||
'expense' => 0.0,
|
||||
];
|
||||
});
|
||||
|
||||
$result = $service->monthlyClosing();
|
||||
$result = $service->monthlyClosing('2026-10');
|
||||
|
||||
$this->assertCount(32, $seenPeriods);
|
||||
$this->assertSame(['2026-07', '2026-08', '2026-09', '2026-10'], array_column($result['months'], 'key'));
|
||||
$this->assertCount(8, $seenPeriods);
|
||||
$this->assertSame(
|
||||
['2026-10-01|2026-10-31'],
|
||||
array_values(array_unique(array_map(
|
||||
static fn (array $period): string => $period[1] . '|' . $period[2],
|
||||
$seenPeriods,
|
||||
))),
|
||||
);
|
||||
$this->assertSame(['2026-10'], array_column($result['months'], 'key'));
|
||||
$this->assertSame('10月', $result['months'][0]['label']);
|
||||
$this->assertCount(8, $result['platforms']);
|
||||
$this->assertSame([
|
||||
'2026-07' => 1010.00,
|
||||
'2026-08' => 1020.00,
|
||||
'2026-09' => 1030.00,
|
||||
'2026-10' => 1040.00,
|
||||
], $result['platforms'][0]['balances']);
|
||||
$this->assertSame([
|
||||
'amount' => 10.0,
|
||||
'rate' => 0.97,
|
||||
], $result['platforms'][0]['change']);
|
||||
$this->assertSame(['2026-10' => 1010.00], $result['platforms'][0]['balances']);
|
||||
$this->assertArrayNotHasKey('change', $result['platforms'][0]);
|
||||
$this->assertSame('合计', $result['total']['name']);
|
||||
$this->assertTrue($result['summary']['complete']);
|
||||
$this->assertSame(8, $result['summary']['available_platform_count']);
|
||||
|
||||
@ -65,7 +65,7 @@ class StoreReceivingBalanceOverviewTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function test_overview_contains_four_month_closing_summary_and_comparison(): void
|
||||
public function test_overview_contains_selected_month_closing_summary_without_comparison(): void
|
||||
{
|
||||
$source = file_get_contents(
|
||||
__DIR__ . '/../../../resources/assets/js/components/business/StoreReceivingBalanceOverview.vue'
|
||||
@ -74,14 +74,14 @@ class StoreReceivingBalanceOverviewTest extends TestCase
|
||||
$this->assertStringContainsString('月度期末余额汇总', $source);
|
||||
$this->assertStringContainsString('平台账户', $source);
|
||||
$this->assertStringContainsString('monthly-closing-table', $source);
|
||||
$this->assertStringContainsString('2026 年 7-10 月', $source);
|
||||
$this->assertStringContainsString('monthlyClosingMonthLabel', $source);
|
||||
$this->assertStringContainsString('const selectedDate = this.queryRange.end || this.queryRange.start', $source);
|
||||
$this->assertStringContainsString('month: this.monthlyClosingMonth', $source);
|
||||
$this->assertStringContainsString('month: month.key', $source);
|
||||
$this->assertStringContainsString("'各平台'", $source);
|
||||
$this->assertStringContainsString('金额单位:万元', $source);
|
||||
$this->assertStringContainsString('monthlyBalanceWan', $source);
|
||||
$this->assertStringContainsString('signedMoneyWan', $source);
|
||||
$this->assertStringContainsString('Number(value) / 10000', $source);
|
||||
$this->assertStringContainsString('amount / 10000', $source);
|
||||
$this->assertStringContainsString('环比口径:2026年10月期末余额 − 2026年9月期末余额', $source);
|
||||
$this->assertStringContainsString('monthlyClosingRows', $source);
|
||||
$this->assertStringContainsString('fetchMonthlyClosing', $source);
|
||||
$this->assertStringContainsString('店铺汇总', $source);
|
||||
@ -90,8 +90,10 @@ class StoreReceivingBalanceOverviewTest extends TestCase
|
||||
$this->assertStringContainsString('fetchMonthlyClosingStores', $source);
|
||||
$this->assertStringContainsString('monthlyStoreRows', $source);
|
||||
$this->assertStringContainsString('monthly-closing-store-table', $source);
|
||||
$this->assertStringContainsString('...(body.comparison || {})', $source);
|
||||
$this->assertStringContainsString('店铺期末余额 = 期初余额 + 收入 - 支出', $source);
|
||||
$this->assertStringContainsString('缺少期初时显示“—”', $source);
|
||||
$this->assertStringNotContainsString('环比', $source);
|
||||
$this->assertStringNotContainsString('2026 年 7-10 月', $source);
|
||||
$this->assertStringNotContainsString('body.comparison', $source);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user