83 lines
2.7 KiB
PHP
83 lines
2.7 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);
|
|
}
|
|
}
|
|
|
|
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')),
|
|
));
|
|
} catch (Throwable $exception) {
|
|
report($exception);
|
|
|
|
return response()->json([
|
|
'message' => '收入明细暂时无法读取,请稍后重试。',
|
|
], 503);
|
|
}
|
|
}
|
|
|
|
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')),
|
|
));
|
|
} 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, '当前账号没有店铺收款账户账单权限。');
|
|
}
|
|
}
|