diff --git a/modules/EcommerceFinance/Http/Controllers/StoreReceivingBalanceOverview.php b/modules/EcommerceFinance/Http/Controllers/StoreReceivingBalanceOverview.php index 915c95f3..5e746ab1 100644 --- a/modules/EcommerceFinance/Http/Controllers/StoreReceivingBalanceOverview.php +++ b/modules/EcommerceFinance/Http/Controllers/StoreReceivingBalanceOverview.php @@ -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); diff --git a/modules/EcommerceFinance/Services/StoreReceivingBalanceOverviewService.php b/modules/EcommerceFinance/Services/StoreReceivingBalanceOverviewService.php index beef5537..8344c275 100644 --- a/modules/EcommerceFinance/Services/StoreReceivingBalanceOverviewService.php +++ b/modules/EcommerceFinance/Services/StoreReceivingBalanceOverviewService.php @@ -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 */ - 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, - ], ]; } diff --git a/resources/assets/js/components/business/StoreReceivingBalanceOverview.vue b/resources/assets/js/components/business/StoreReceivingBalanceOverview.vue index 813f380d..3e81334a 100644 --- a/resources/assets/js/components/business/StoreReceivingBalanceOverview.vue +++ b/resources/assets/js/components/business/StoreReceivingBalanceOverview.vue @@ -133,7 +133,7 @@ 新增

- 2026 年 7-10 月{{ monthlyClosingView === 'store' ? '店铺' : '各平台' }}期末余额 + {{ monthlyClosingMonthLabel }}{{ monthlyClosingView === 'store' ? '店铺' : '各平台' }}期末余额 · 金额单位:万元

@@ -160,22 +160,22 @@
-

正在汇总 4 个月度期末余额…

+

正在汇总 {{ monthlyClosingMonthLabel }}期末余额…

-

正在汇总 7-10 月店铺期末余额…

+

正在汇总 {{ monthlyClosingMonthLabel }}店铺期末余额…