CaiWuXiTong/modules/EcommerceFinance/Http/Controllers/StoreReceivingBalanceOverview.php
qiuxiang f5694567f2 feat: 新增店铺收款账户余额总览 (#1019)
聚合8个收款平台的月度期初、收入与支出,按期初加收入减支出计算期末余额,并支持月份切换和缺失数据保护。
2026-11-09 18:44:13 +08:00

43 lines
1.3 KiB
PHP

<?php
namespace Modules\EcommerceFinance\Http\Controllers;
use App\Utilities\SidebarPermissions;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\EcommerceFinance\Services\StoreReceivingBalanceOverviewService;
use Throwable;
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')),
));
} catch (Throwable $exception) {
report($exception);
return response()->json([
'message' => '账户余额总览暂时无法读取,请稍后重试。',
], 503);
}
}
private function authorizeStoreReceivingBills(): void
{
$section = collect(SidebarPermissions::navigationFor(user()))
->firstWhere('slug', 'billing-transactions');
$page = collect($section['pages'] ?? [])
->firstWhere('slug', 'store-receiving-bills');
abort_if(empty($page), 403, '当前账号没有店铺收款账户账单权限。');
}
}