feat: filter account balance overview by occurrence date (#1025)
This commit is contained in:
parent
4c866dadcb
commit
ef33a32b88
@ -13,14 +13,9 @@ class StoreReceivingBalanceOverview extends Controller
|
||||
public function index(Request $request, StoreReceivingBalanceOverviewService $service)
|
||||
{
|
||||
$this->authorizeStoreReceivingBills();
|
||||
$validated = $request->validate([
|
||||
'month' => ['nullable', 'date_format:Y-m'],
|
||||
]);
|
||||
|
||||
try {
|
||||
return response()->json($service->overview(
|
||||
(string) ($validated['month'] ?? now('Asia/Shanghai')->format('Y-m')),
|
||||
));
|
||||
return response()->json($service->overview(...$this->requestedPeriod($request)));
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
|
||||
@ -33,14 +28,9 @@ class StoreReceivingBalanceOverview extends Controller
|
||||
public function incomeDetail(Request $request, StoreReceivingBalanceOverviewService $service)
|
||||
{
|
||||
$this->authorizeStoreReceivingBills();
|
||||
$validated = $request->validate([
|
||||
'month' => ['nullable', 'date_format:Y-m'],
|
||||
]);
|
||||
|
||||
try {
|
||||
return response()->json($service->incomeDetail(
|
||||
(string) ($validated['month'] ?? now('Asia/Shanghai')->format('Y-m')),
|
||||
));
|
||||
return response()->json($service->incomeDetail(...$this->requestedPeriod($request)));
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
|
||||
@ -53,14 +43,9 @@ class StoreReceivingBalanceOverview extends Controller
|
||||
public function expenseDetail(Request $request, StoreReceivingBalanceOverviewService $service)
|
||||
{
|
||||
$this->authorizeStoreReceivingBills();
|
||||
$validated = $request->validate([
|
||||
'month' => ['nullable', 'date_format:Y-m'],
|
||||
]);
|
||||
|
||||
try {
|
||||
return response()->json($service->expenseDetail(
|
||||
(string) ($validated['month'] ?? now('Asia/Shanghai')->format('Y-m')),
|
||||
));
|
||||
return response()->json($service->expenseDetail(...$this->requestedPeriod($request)));
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
|
||||
@ -73,14 +58,9 @@ class StoreReceivingBalanceOverview extends Controller
|
||||
public function balanceDetail(Request $request, StoreReceivingBalanceOverviewService $service)
|
||||
{
|
||||
$this->authorizeStoreReceivingBills();
|
||||
$validated = $request->validate([
|
||||
'month' => ['nullable', 'date_format:Y-m'],
|
||||
]);
|
||||
|
||||
try {
|
||||
return response()->json($service->balanceDetail(
|
||||
(string) ($validated['month'] ?? now('Asia/Shanghai')->format('Y-m')),
|
||||
));
|
||||
return response()->json($service->balanceDetail(...$this->requestedPeriod($request)));
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
|
||||
@ -90,6 +70,22 @@ class StoreReceivingBalanceOverview extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/** @return array{0:string,1?:string} */
|
||||
private function requestedPeriod(Request $request): array
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'month' => ['nullable', 'date_format:Y-m'],
|
||||
'start' => ['nullable', 'date_format:Y-m-d', 'required_with:end'],
|
||||
'end' => ['nullable', 'date_format:Y-m-d', 'required_with:start', 'after_or_equal:start'],
|
||||
]);
|
||||
|
||||
if (! empty($validated['start']) && ! empty($validated['end'])) {
|
||||
return [(string) $validated['start'], (string) $validated['end']];
|
||||
}
|
||||
|
||||
return [(string) ($validated['month'] ?? now('Asia/Shanghai')->format('Y-m'))];
|
||||
}
|
||||
|
||||
private function authorizeStoreReceivingBills(): void
|
||||
{
|
||||
$section = collect(SidebarPermissions::navigationFor(user()))
|
||||
|
||||
@ -41,9 +41,9 @@ class StoreReceivingBalanceOverviewService
|
||||
) {}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
public function overview(string $month): array
|
||||
public function overview(string $periodStart, ?string $periodEnd = null): array
|
||||
{
|
||||
[$periodStart, $periodEnd] = $this->periodForMonth($month);
|
||||
[$periodStart, $periodEnd, $periodMonth] = $this->periodForRange($periodStart, $periodEnd);
|
||||
$platforms = [];
|
||||
$availableTotals = [
|
||||
'opening_balance' => 0.0,
|
||||
@ -105,7 +105,7 @@ class StoreReceivingBalanceOverviewService
|
||||
$expense = $complete ? round($availableTotals['expense'], 2) : null;
|
||||
|
||||
return [
|
||||
'month' => $month,
|
||||
'month' => $periodMonth,
|
||||
'period' => [
|
||||
'start' => $periodStart,
|
||||
'end' => $periodEnd,
|
||||
@ -133,9 +133,9 @@ class StoreReceivingBalanceOverviewService
|
||||
*
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function incomeDetail(string $month): array
|
||||
public function incomeDetail(string $periodStart, ?string $periodEnd = null): array
|
||||
{
|
||||
return $this->flowDetail($month, 'income');
|
||||
return $this->flowDetail($periodStart, $periodEnd, 'income');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,9 +146,9 @@ class StoreReceivingBalanceOverviewService
|
||||
*
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function expenseDetail(string $month): array
|
||||
public function expenseDetail(string $periodStart, ?string $periodEnd = null): array
|
||||
{
|
||||
return $this->flowDetail($month, 'expense');
|
||||
return $this->flowDetail($periodStart, $periodEnd, 'expense');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,9 +159,9 @@ class StoreReceivingBalanceOverviewService
|
||||
*
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function balanceDetail(string $month): array
|
||||
public function balanceDetail(string $periodStart, ?string $periodEnd = null): array
|
||||
{
|
||||
$overview = $this->overview($month);
|
||||
$overview = $this->overview($periodStart, $periodEnd);
|
||||
$details = [];
|
||||
|
||||
foreach ($overview['platforms'] as $platform) {
|
||||
@ -179,7 +179,7 @@ class StoreReceivingBalanceOverviewService
|
||||
}
|
||||
|
||||
return [
|
||||
'month' => $month,
|
||||
'month' => $overview['month'],
|
||||
'period' => $overview['period'],
|
||||
'summary' => [
|
||||
'balance' => $overview['summary']['balance'],
|
||||
@ -192,9 +192,9 @@ class StoreReceivingBalanceOverviewService
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
private function flowDetail(string $month, string $flow): array
|
||||
private function flowDetail(string $periodStart, ?string $periodEnd, string $flow): array
|
||||
{
|
||||
[$periodStart, $periodEnd] = $this->periodForMonth($month);
|
||||
[$periodStart, $periodEnd, $periodMonth] = $this->periodForRange($periodStart, $periodEnd);
|
||||
$platformOrder = [];
|
||||
$details = [];
|
||||
$totalAmount = 0.0;
|
||||
@ -266,7 +266,7 @@ class StoreReceivingBalanceOverviewService
|
||||
});
|
||||
|
||||
return [
|
||||
'month' => $month,
|
||||
'month' => $periodMonth,
|
||||
'period' => [
|
||||
'start' => $periodStart,
|
||||
'end' => $periodEnd,
|
||||
@ -281,17 +281,42 @@ class StoreReceivingBalanceOverviewService
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array{0:string,1:string} */
|
||||
private function periodForMonth(string $month): array
|
||||
/** @return array{0:string,1:string,2:string} */
|
||||
private function periodForRange(string $start, ?string $end): array
|
||||
{
|
||||
$start = CarbonImmutable::createFromFormat('!Y-m', $month, 'Asia/Shanghai');
|
||||
if (! $start instanceof CarbonImmutable || $start->format('Y-m') !== $month) {
|
||||
throw new RuntimeException('invalid_balance_overview_month');
|
||||
if ($end === null && preg_match('/^\d{4}-\d{2}$/', $start) === 1) {
|
||||
$month = CarbonImmutable::createFromFormat('!Y-m', $start, 'Asia/Shanghai');
|
||||
if ($month instanceof CarbonImmutable && $month->format('Y-m') === $start) {
|
||||
return [
|
||||
$month->startOfMonth()->format('Y-m-d'),
|
||||
$month->endOfMonth()->format('Y-m-d'),
|
||||
$start,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$periodStart = CarbonImmutable::createFromFormat('!Y-m-d', $start, 'Asia/Shanghai');
|
||||
$periodEnd = $end !== null
|
||||
? CarbonImmutable::createFromFormat('!Y-m-d', $end, 'Asia/Shanghai')
|
||||
: null;
|
||||
} catch (Throwable) {
|
||||
throw new RuntimeException('invalid_balance_overview_period');
|
||||
}
|
||||
|
||||
if (! $periodStart instanceof CarbonImmutable
|
||||
|| $periodStart->format('Y-m-d') !== $start
|
||||
|| ! $periodEnd instanceof CarbonImmutable
|
||||
|| $periodEnd->format('Y-m-d') !== (string) $end
|
||||
|| $periodEnd->lt($periodStart)
|
||||
) {
|
||||
throw new RuntimeException('invalid_balance_overview_period');
|
||||
}
|
||||
|
||||
return [
|
||||
$start->startOfMonth()->format('Y-m-d'),
|
||||
$start->endOfMonth()->format('Y-m-d'),
|
||||
$periodStart->format('Y-m-d'),
|
||||
$periodEnd->format('Y-m-d'),
|
||||
$periodStart->format('Y-m'),
|
||||
];
|
||||
}
|
||||
|
||||
@ -365,10 +390,9 @@ class StoreReceivingBalanceOverviewService
|
||||
->where($flow, '>', 0);
|
||||
|
||||
if (in_array($platform, ['vipshop', 'vipshop-jx'], true)) {
|
||||
$query->whereRaw(
|
||||
"JSON_UNQUOTE(JSON_EXTRACT(payload, '$.settle_period')) = ?",
|
||||
[substr($start, 0, 7)],
|
||||
);
|
||||
$settlePeriod = "JSON_UNQUOTE(JSON_EXTRACT(payload, '$.settle_period'))";
|
||||
$query->whereRaw($settlePeriod . ' >= ?', [substr($start, 0, 7)])
|
||||
->whereRaw($settlePeriod . ' <= ?', [substr($end, 0, 7)]);
|
||||
} else {
|
||||
$query->where('occurred_at', '>=', $start . ' 00:00:00')
|
||||
->where('occurred_at', '<', CarbonImmutable::parse($end, 'Asia/Shanghai')->addDay()->format('Y-m-d') . ' 00:00:00');
|
||||
@ -457,7 +481,7 @@ class StoreReceivingBalanceOverviewService
|
||||
return match ($message) {
|
||||
'平台期初余额未就绪' => $message,
|
||||
'平台账单汇总数据不完整' => $message,
|
||||
'invalid_balance_overview_month' => '月份格式无效',
|
||||
'invalid_balance_overview_period' => '日期范围无效',
|
||||
'unsupported_balance_overview_platform' => '平台类型无效',
|
||||
'' => '平台账单暂时无法读取',
|
||||
default => mb_substr($message, 0, 160),
|
||||
|
||||
@ -4,16 +4,81 @@
|
||||
<div>
|
||||
<p class="overview-eyebrow">店铺收款账户</p>
|
||||
<h2>账户余额总览</h2>
|
||||
<p class="overview-subtitle">聚合 8 个收款平台的月度期初、收入与支出(单位:万元)</p>
|
||||
<p class="overview-subtitle">聚合 8 个收款平台在选定发生时间范围内的期初、收入与支出(单位:万元)</p>
|
||||
</div>
|
||||
<div class="month-switcher" role="group" aria-label="选择统计月份">
|
||||
<button type="button" aria-label="上一个月" @click="changeMonth(-1)">
|
||||
<span class="material-icons-outlined" aria-hidden="true">chevron_left</span>
|
||||
</button>
|
||||
<strong data-overview-month>{{ monthLabel }}</strong>
|
||||
<button type="button" aria-label="下一个月" @click="changeMonth(1)">
|
||||
<span class="material-icons-outlined" aria-hidden="true">chevron_right</span>
|
||||
</button>
|
||||
<div class="overview-time-filter-wrap">
|
||||
<form class="overview-time-filter" aria-label="按发生时间筛选" @submit.prevent="applyTimeRange">
|
||||
<span class="overview-time-label">发生时间</span>
|
||||
<div class="overview-time-row">
|
||||
<span class="overview-date-control" @click="openDatePicker('startDate')">
|
||||
<flat-picker
|
||||
ref="startDate"
|
||||
:value="dateRange.start"
|
||||
:config="startDateConfig"
|
||||
aria-label="开始日期"
|
||||
placeholder="开始日期"
|
||||
@on-change="(_, value) => changeDate('start', value)"
|
||||
/>
|
||||
<button
|
||||
v-if="dateRange.start"
|
||||
type="button"
|
||||
class="overview-date-clear"
|
||||
title="清除开始日期"
|
||||
aria-label="清除开始日期"
|
||||
@click.stop="changeDate('start', '')"
|
||||
>×</button>
|
||||
<button
|
||||
type="button"
|
||||
class="overview-date-picker"
|
||||
title="选择开始日期"
|
||||
aria-label="选择开始日期"
|
||||
@click.stop="openDatePicker('startDate')"
|
||||
>
|
||||
<svg class="overview-date-icon" viewBox="0 0 24 24" aria-hidden="true">
|
||||
<rect x="3" y="5" width="18" height="16" rx="2"></rect>
|
||||
<path d="M16 3v4M8 3v4M3 10h18"></path>
|
||||
</svg>
|
||||
</button>
|
||||
</span>
|
||||
<b>至</b>
|
||||
<span class="overview-date-control" @click="openDatePicker('endDate')">
|
||||
<flat-picker
|
||||
ref="endDate"
|
||||
:value="dateRange.end"
|
||||
:config="endDateConfig"
|
||||
aria-label="结束日期"
|
||||
placeholder="结束日期"
|
||||
@on-change="(_, value) => changeDate('end', value)"
|
||||
/>
|
||||
<button
|
||||
v-if="dateRange.end"
|
||||
type="button"
|
||||
class="overview-date-clear"
|
||||
title="清除结束日期"
|
||||
aria-label="清除结束日期"
|
||||
@click.stop="changeDate('end', '')"
|
||||
>×</button>
|
||||
<button
|
||||
type="button"
|
||||
class="overview-date-picker"
|
||||
title="选择结束日期"
|
||||
aria-label="选择结束日期"
|
||||
@click.stop="openDatePicker('endDate')"
|
||||
>
|
||||
<svg class="overview-date-icon" viewBox="0 0 24 24" aria-hidden="true">
|
||||
<rect x="3" y="5" width="18" height="16" rx="2"></rect>
|
||||
<path d="M16 3v4M8 3v4M3 10h18"></path>
|
||||
</svg>
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
<button type="submit" class="overview-query-button" :disabled="invalidDateRange || !dateRange.start || !dateRange.end">
|
||||
{{ loading ? '查询中…' : '查询' }}
|
||||
</button>
|
||||
</form>
|
||||
<p v-if="invalidDateRange" class="overview-filter-error" role="alert">结束日期不能早于开始日期</p>
|
||||
<p v-else-if="!dateRange.start || !dateRange.end" class="overview-filter-error" role="alert">请选择完整的开始和结束日期</p>
|
||||
<p v-else-if="filtersDirty && !loading" class="overview-filter-note" role="status">时间条件已修改,点击查询后生效。</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@ -73,7 +138,7 @@
|
||||
<header class="flow-detail-head">
|
||||
<div>
|
||||
<strong id="flow-detail-title">{{ detailTitle }}</strong>
|
||||
<p>{{ monthLabel }} · {{ detailDescription }}</p>
|
||||
<p>{{ queryPeriodLabel }} · {{ detailDescription }}</p>
|
||||
</div>
|
||||
<div class="flow-detail-total">
|
||||
<span>当前筛选合计(万元)</span>
|
||||
@ -179,6 +244,10 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import flatPicker from 'vue-flatpickr-component';
|
||||
import { Mandarin } from 'flatpickr/dist/l10n/zh';
|
||||
import 'flatpickr/dist/flatpickr.css';
|
||||
|
||||
const emptySummary = () => ({
|
||||
opening_balance: null,
|
||||
income: null,
|
||||
@ -190,19 +259,37 @@ const emptySummary = () => ({
|
||||
});
|
||||
|
||||
const pad = value => String(value).padStart(2, '0');
|
||||
const currentMonth = () => {
|
||||
const currentMonthRange = () => {
|
||||
const now = new Date();
|
||||
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}`;
|
||||
const year = now.getFullYear();
|
||||
const month = now.getMonth() + 1;
|
||||
const lastDay = new Date(year, month, 0).getDate();
|
||||
|
||||
return {
|
||||
start: `${year}-${pad(month)}-01`,
|
||||
end: `${year}-${pad(month)}-${pad(lastDay)}`,
|
||||
};
|
||||
};
|
||||
const dateConfig = {
|
||||
dateFormat: 'Y-m-d',
|
||||
locale: Mandarin,
|
||||
disableMobile: true,
|
||||
allowInput: false,
|
||||
onReady: (_, value, picker) => picker.calendarContainer.classList.add('overview-calendar'),
|
||||
};
|
||||
|
||||
export default {
|
||||
name: 'StoreReceivingBalanceOverview',
|
||||
components: { flatPicker },
|
||||
props: {
|
||||
apiBase: { type: String, required: true },
|
||||
},
|
||||
data() {
|
||||
const range = currentMonthRange();
|
||||
|
||||
return {
|
||||
month: currentMonth(),
|
||||
dateRange: { ...range },
|
||||
queryRange: { ...range },
|
||||
loading: true,
|
||||
error: '',
|
||||
summary: emptySummary(),
|
||||
@ -222,9 +309,25 @@ export default {
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
monthLabel() {
|
||||
const [year, month] = this.month.split('-');
|
||||
return `${year}年${Number(month)}月`;
|
||||
invalidDateRange() {
|
||||
return Boolean(
|
||||
this.dateRange.start
|
||||
&& this.dateRange.end
|
||||
&& this.dateRange.start > this.dateRange.end,
|
||||
);
|
||||
},
|
||||
filtersDirty() {
|
||||
return this.dateRange.start !== this.queryRange.start
|
||||
|| this.dateRange.end !== this.queryRange.end;
|
||||
},
|
||||
startDateConfig() {
|
||||
return { ...dateConfig, maxDate: this.dateRange.end || null };
|
||||
},
|
||||
endDateConfig() {
|
||||
return { ...dateConfig, minDate: this.dateRange.start || null };
|
||||
},
|
||||
queryPeriodLabel() {
|
||||
return `${this.queryRange.start} 至 ${this.queryRange.end}`;
|
||||
},
|
||||
statusClass() {
|
||||
return {
|
||||
@ -413,7 +516,10 @@ export default {
|
||||
|
||||
try {
|
||||
const response = await window.axios.get(this.apiBase, {
|
||||
params: { month: this.month },
|
||||
params: {
|
||||
start: this.queryRange.start,
|
||||
end: this.queryRange.end,
|
||||
},
|
||||
});
|
||||
if (requestId !== this.requestSerial) return;
|
||||
|
||||
@ -431,13 +537,21 @@ export default {
|
||||
if (requestId === this.requestSerial) this.loading = false;
|
||||
}
|
||||
},
|
||||
changeMonth(offset) {
|
||||
const [year, month] = this.month.split('-').map(Number);
|
||||
const next = new Date(year, month - 1 + offset, 1);
|
||||
applyTimeRange() {
|
||||
if (this.invalidDateRange) return;
|
||||
this.queryRange = { ...this.dateRange };
|
||||
if (this.detailOpen) this.closeDetails();
|
||||
this.month = `${next.getFullYear()}-${pad(next.getMonth() + 1)}`;
|
||||
this.fetchOverview();
|
||||
},
|
||||
changeDate(field, value) {
|
||||
const date = value || '';
|
||||
if (this.dateRange[field] === date) return;
|
||||
this.dateRange[field] = date;
|
||||
},
|
||||
openDatePicker(refName) {
|
||||
const picker = this.$refs[refName];
|
||||
if (picker && picker.fp) picker.fp.open();
|
||||
},
|
||||
openDetails(flow = 'income') {
|
||||
const requestId = ++this.detailRequestSerial;
|
||||
this.detailFlow = ['income', 'expense', 'balance'].includes(flow) ? flow : 'income';
|
||||
@ -468,7 +582,10 @@ export default {
|
||||
balance: 'balance-detail',
|
||||
}[this.detailFlow] || 'income-detail';
|
||||
const response = await window.axios.get(`${this.apiBase}/${endpoint}`, {
|
||||
params: { month: this.month },
|
||||
params: {
|
||||
start: this.queryRange.start,
|
||||
end: this.queryRange.end,
|
||||
},
|
||||
});
|
||||
if (requestId !== this.detailRequestSerial || !this.detailOpen) return;
|
||||
const body = response.data || {};
|
||||
@ -576,42 +693,146 @@ export default {
|
||||
color: var(--overview-muted);
|
||||
font-size: .75rem;
|
||||
}
|
||||
.month-switcher {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
.overview-time-filter-wrap {
|
||||
display: flex;
|
||||
flex: 0 0 auto;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
gap: .25rem;
|
||||
}
|
||||
.overview-time-filter {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .55rem;
|
||||
padding: .35rem .45rem .35rem .75rem;
|
||||
flex: 0 0 auto;
|
||||
overflow: hidden;
|
||||
border: 1px solid #cabda7;
|
||||
border-radius: .55rem;
|
||||
border-radius: .75rem;
|
||||
background: rgba(255, 255, 255, .86);
|
||||
box-shadow: 0 4px 16px rgba(75, 58, 31, .06);
|
||||
}
|
||||
.month-switcher button {
|
||||
.overview-time-label {
|
||||
color: var(--overview-muted);
|
||||
font-size: .6875rem;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.overview-time-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .4rem;
|
||||
}
|
||||
.overview-time-row b {
|
||||
color: var(--overview-muted);
|
||||
font-size: .6875rem;
|
||||
font-weight: 400;
|
||||
}
|
||||
.overview-date-control {
|
||||
position: relative;
|
||||
display: flex;
|
||||
width: 9.6rem;
|
||||
height: 2rem;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
border: 1px solid #d8cdbc;
|
||||
border-radius: 999px;
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
}
|
||||
.overview-date-control:focus-within {
|
||||
border-color: var(--overview-gold);
|
||||
box-shadow: 0 0 0 3px rgba(138, 104, 47, .16);
|
||||
}
|
||||
.overview-date-control input {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-width: 0;
|
||||
padding: 0 3.75rem 0 .85rem;
|
||||
border: 0;
|
||||
border-radius: inherit;
|
||||
background: transparent;
|
||||
color: var(--overview-ink);
|
||||
font: 400 .75rem/1 "JetBrains Mono", "Microsoft YaHei", "PingFang SC", monospace;
|
||||
font-variant-numeric: tabular-nums;
|
||||
cursor: pointer;
|
||||
}
|
||||
.overview-date-control input:focus {
|
||||
outline: none;
|
||||
}
|
||||
.overview-date-picker,
|
||||
.overview-date-clear {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
display: inline-flex;
|
||||
height: 100%;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 2.25rem;
|
||||
height: 2.25rem;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: var(--overview-gold);
|
||||
font: 500 .95rem/1 inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
.month-switcher button:hover,
|
||||
.month-switcher button:focus-visible {
|
||||
background: #f4ecdc;
|
||||
.overview-date-picker {
|
||||
right: .55rem;
|
||||
width: 1.5rem;
|
||||
}
|
||||
.overview-date-clear {
|
||||
right: 1.95rem;
|
||||
width: 1.25rem;
|
||||
color: var(--overview-muted);
|
||||
}
|
||||
.overview-date-picker:hover,
|
||||
.overview-date-picker:focus-visible,
|
||||
.overview-date-clear:hover,
|
||||
.overview-date-clear:focus-visible {
|
||||
color: #6a5129;
|
||||
outline: none;
|
||||
}
|
||||
.month-switcher button .material-icons-outlined {
|
||||
font-size: 1.25rem;
|
||||
.overview-date-icon {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
fill: none;
|
||||
stroke: currentColor;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
stroke-width: 1.8;
|
||||
}
|
||||
.month-switcher strong {
|
||||
min-width: 8.5rem;
|
||||
padding: 0 1rem;
|
||||
text-align: center;
|
||||
font-size: .8125rem;
|
||||
font-variant-numeric: tabular-nums;
|
||||
.overview-query-button {
|
||||
display: inline-flex;
|
||||
height: 2rem;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0 .9rem;
|
||||
border: 1px solid var(--overview-gold);
|
||||
border-radius: .45rem;
|
||||
background: var(--overview-gold);
|
||||
color: #fff;
|
||||
font: 600 .75rem/1 inherit;
|
||||
white-space: nowrap;
|
||||
cursor: pointer;
|
||||
}
|
||||
.overview-query-button:hover,
|
||||
.overview-query-button:focus-visible {
|
||||
border-color: #6a5129;
|
||||
background: #6a5129;
|
||||
outline: none;
|
||||
}
|
||||
.overview-query-button:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: .55;
|
||||
}
|
||||
.overview-filter-error,
|
||||
.overview-filter-note {
|
||||
margin: 0;
|
||||
font-size: .6875rem;
|
||||
}
|
||||
.overview-filter-error {
|
||||
color: #b80000;
|
||||
}
|
||||
.overview-filter-note {
|
||||
color: var(--overview-muted);
|
||||
}
|
||||
.overview-cards {
|
||||
display: grid;
|
||||
@ -1025,6 +1246,14 @@ export default {
|
||||
to { background-position: -200% 0; }
|
||||
}
|
||||
@media (max-width: 900px) {
|
||||
.overview-head {
|
||||
align-items: flex-start;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.overview-time-filter-wrap {
|
||||
width: 100%;
|
||||
align-items: stretch;
|
||||
}
|
||||
.overview-cards {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
@ -1037,11 +1266,24 @@ export default {
|
||||
align-items: flex-start;
|
||||
flex-direction: column;
|
||||
}
|
||||
.month-switcher {
|
||||
.overview-time-filter {
|
||||
flex-wrap: wrap;
|
||||
width: 100%;
|
||||
}
|
||||
.month-switcher strong {
|
||||
flex: 1;
|
||||
.overview-time-row {
|
||||
flex: 1 1 100%;
|
||||
order: 3;
|
||||
}
|
||||
.overview-date-control {
|
||||
width: auto;
|
||||
flex: 1 1 0;
|
||||
}
|
||||
.overview-query-button {
|
||||
margin-left: auto;
|
||||
}
|
||||
.overview-filter-error,
|
||||
.overview-filter-note {
|
||||
text-align: left;
|
||||
}
|
||||
.overview-cards {
|
||||
grid-template-columns: 1fr;
|
||||
@ -1076,3 +1318,25 @@ export default {
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style>
|
||||
.overview-calendar {
|
||||
font-family: "Microsoft YaHei", sans-serif;
|
||||
border: 1px solid #d8d2c7;
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
}
|
||||
.overview-calendar .flatpickr-day.selected,
|
||||
.overview-calendar .flatpickr-day.selected:hover {
|
||||
border-color: #856632;
|
||||
background: #856632;
|
||||
}
|
||||
.overview-calendar .flatpickr-day.today {
|
||||
border-color: #856632;
|
||||
}
|
||||
.overview-calendar .flatpickr-day:hover,
|
||||
.overview-calendar .flatpickr-day:focus {
|
||||
border-color: #d8d2c7;
|
||||
background: #f7f0de;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -41,6 +41,44 @@ class StoreReceivingBalanceOverviewEndpointTest extends FeatureTestCase
|
||||
->assertJsonPath('summary.complete', true);
|
||||
}
|
||||
|
||||
public function test_overview_endpoint_accepts_an_explicit_date_range(): void
|
||||
{
|
||||
$this->user->attachPermission(
|
||||
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
||||
);
|
||||
|
||||
$payload = [
|
||||
'month' => '2026-10',
|
||||
'period' => ['start' => '2026-10-05', 'end' => '2026-10-20'],
|
||||
'summary' => [
|
||||
'opening_balance' => 100.0,
|
||||
'income' => 30.0,
|
||||
'expense' => 10.0,
|
||||
'balance' => 120.0,
|
||||
'platform_count' => 8,
|
||||
'available_platform_count' => 8,
|
||||
'complete' => true,
|
||||
],
|
||||
'platforms' => [],
|
||||
];
|
||||
$service = Mockery::mock(StoreReceivingBalanceOverviewService::class);
|
||||
$service->shouldReceive('overview')
|
||||
->once()
|
||||
->with('2026-10-05', '2026-10-20')
|
||||
->andReturn($payload);
|
||||
$this->app->instance(StoreReceivingBalanceOverviewService::class, $service);
|
||||
|
||||
$this->loginAs()
|
||||
->getJson(route('ecommerce-finance.account-bills.overview', [
|
||||
'start' => '2026-10-05',
|
||||
'end' => '2026-10-20',
|
||||
]))
|
||||
->assertOk()
|
||||
->assertJsonPath('period.start', '2026-10-05')
|
||||
->assertJsonPath('period.end', '2026-10-20')
|
||||
->assertJsonPath('summary.complete', true);
|
||||
}
|
||||
|
||||
public function test_overview_page_uses_the_vue_mount_point(): void
|
||||
{
|
||||
$this->user->attachPermission(
|
||||
|
||||
@ -62,6 +62,28 @@ class StoreReceivingBalanceOverviewServiceTest extends TestCase
|
||||
$this->assertFalse($vipshopJx['available']);
|
||||
}
|
||||
|
||||
public function test_overview_uses_an_explicit_date_range_for_all_platforms(): void
|
||||
{
|
||||
$seenPeriods = [];
|
||||
$service = $this->service(function (string $platform, string $start, string $end) use (&$seenPeriods): array {
|
||||
$seenPeriods[] = [$platform, $start, $end];
|
||||
|
||||
return [
|
||||
'opening_balance' => 10.0,
|
||||
'income' => 2.0,
|
||||
'expense' => 1.0,
|
||||
];
|
||||
});
|
||||
|
||||
$result = $service->overview('2026-10-05', '2026-10-20');
|
||||
|
||||
$this->assertSame(['start' => '2026-10-05', 'end' => '2026-10-20'], $result['period']);
|
||||
$this->assertCount(8, $seenPeriods);
|
||||
$this->assertSame(['taobao-alipay', '2026-10-05', '2026-10-20'], $seenPeriods[0]);
|
||||
$this->assertSame(['xiaohongshu', '2026-10-05', '2026-10-20'], $seenPeriods[7]);
|
||||
$this->assertTrue($result['summary']['complete']);
|
||||
}
|
||||
|
||||
public function test_income_detail_groups_platform_store_and_bill_item_rows(): void
|
||||
{
|
||||
$service = new class extends StoreReceivingBalanceOverviewService {
|
||||
|
||||
@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
class StoreReceivingBalanceOverviewTest extends TestCase
|
||||
{
|
||||
public function test_overview_renders_month_switcher_and_four_required_totals(): void
|
||||
public function test_overview_renders_occurrence_date_filter_and_four_required_totals(): void
|
||||
{
|
||||
$source = file_get_contents(
|
||||
__DIR__ . '/../../../resources/assets/js/components/business/StoreReceivingBalanceOverview.vue'
|
||||
@ -18,9 +18,13 @@ class StoreReceivingBalanceOverviewTest extends TestCase
|
||||
$this->assertStringContainsString('支出合计', $source);
|
||||
$this->assertStringContainsString('期末余额合计', $source);
|
||||
$this->assertStringContainsString('期初余额 + 收入合计 - 支出合计', $source);
|
||||
$this->assertStringContainsString('@click="changeMonth(-1)"', $source);
|
||||
$this->assertStringContainsString('@click="changeMonth(1)"', $source);
|
||||
$this->assertStringContainsString('params: { month: this.month }', $source);
|
||||
$this->assertStringContainsString('@submit.prevent="applyTimeRange"', $source);
|
||||
$this->assertStringContainsString('<flat-picker', $source);
|
||||
$this->assertStringContainsString('发生时间', $source);
|
||||
$this->assertStringContainsString('查询中…', $source);
|
||||
$this->assertStringContainsString('start: this.queryRange.start', $source);
|
||||
$this->assertStringContainsString('end: this.queryRange.end', $source);
|
||||
$this->assertStringContainsString('结束日期不能早于开始日期', $source);
|
||||
$this->assertStringContainsString('暂不展示不完整合计', $source);
|
||||
$this->assertStringContainsString(':aria-busy="loading', $source);
|
||||
$this->assertStringContainsString('(单位:万元)', $source);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user