From eaeae9775292ddd3c263c2846f656dabcc49ddad Mon Sep 17 00:00:00 2001 From: shanshi <3316401569@qq.com> Date: Wed, 21 Oct 2026 14:37:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A2=E5=8A=A1=E5=8F=B0=E8=B4=A6=EF=BC=9A?= =?UTF-8?q?=E5=85=AC=E5=8F=B8=E8=A7=84=E5=88=92=E4=B8=8E=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=A2=9E=E5=8A=A0=E4=B8=8B=E6=8B=89=E7=BC=96?= =?UTF-8?q?=E8=BE=91=20(#431)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Business/FinanceLedger.php | 79 +++++++++++++++++++ .../View/FinanceLedgerPageData.php | 17 ++++ .../pages/financial-ledger/ledger.blade.php | 35 +++++++- routes/admin.php | 8 ++ .../FinanceLedgerAccountStatusTest.php | 61 ++++++++++++++ 5 files changed, 199 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Business/FinanceLedger.php b/app/Http/Controllers/Business/FinanceLedger.php index 0c877320..a328b41f 100644 --- a/app/Http/Controllers/Business/FinanceLedger.php +++ b/app/Http/Controllers/Business/FinanceLedger.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Business; use App\Utilities\FinanceLedgerAccountStatus; +use App\Utilities\FinanceLedgerAccountShouldKeep; use App\Utilities\FinanceLedgerAccountType; use App\Utilities\FinanceLedgerAccess; use Illuminate\Http\JsonResponse; @@ -176,6 +177,84 @@ class FinanceLedger extends Controller ], 200, ['Cache-Control' => 'private, no-store']); } + public function updateAccountPlan(Request $request): JsonResponse + { + abort_unless(FinanceLedgerAccess::canEditAccountStatus(user()), 403, '只有财务台账管理员可以修改公司规划。'); + + $data = $request->validate([ + 'account_short' => ['required', 'string', 'max:100'], + 'company_plan' => ['nullable', 'string', 'max:50'], + ]); + $accountShort = trim((string) $data['account_short']); + $plan = trim((string) ($data['company_plan'] ?? '')); + if ($accountShort === '') { + abort(422, '账户简称不能为空。'); + } + + $connection = DB::connection((string) config('upstream_mirrors.connection', 'business_mirror')); + abort_unless( + $connection->table('fin_accounts')->where('account_short', $accountShort)->exists(), + 422, + '账户简称不存在,请刷新账户总表后重试。', + ); + $allowedPlans = $connection->table('fin_accounts') + ->whereNotNull('company_plan') + ->where('company_plan', '<>', '') + ->distinct() + ->pluck('company_plan') + ->map(static fn (mixed $value): string => trim((string) $value)) + ->filter() + ->values() + ->all(); + abort_unless($plan === '' || in_array($plan, $allowedPlans, true), 422, '请选择现有公司规划。'); + + $connection->table('fin_accounts')->where('account_short', $accountShort)->update([ + 'company_plan' => $plan !== '' ? $plan : null, + 'updated_at' => now(), + ]); + + return response()->json([ + 'ok' => true, + 'account_short' => $accountShort, + 'company_plan' => $plan, + 'label' => $plan !== '' ? $plan : '未填写', + ], 200, ['Cache-Control' => 'private, no-store']); + } + + public function updateAccountKeep(Request $request): JsonResponse + { + abort_unless(FinanceLedgerAccess::canEditAccountStatus(user()), 403, '只有财务台账管理员可以修改账户是否保留。'); + + $data = $request->validate([ + 'account_short' => ['required', 'string', 'max:100'], + 'account_should_keep' => ['nullable', 'string', Rule::in(FinanceLedgerAccountShouldKeep::OPTIONS)], + ]); + $accountShort = trim((string) $data['account_short']); + $keep = FinanceLedgerAccountShouldKeep::normalize((string) ($data['account_should_keep'] ?? '')); + if ($accountShort === '') { + abort(422, '账户简称不能为空。'); + } + + $connection = DB::connection((string) config('upstream_mirrors.connection', 'business_mirror')); + abort_unless( + $connection->table('fin_accounts')->where('account_short', $accountShort)->exists(), + 422, + '账户简称不存在,请刷新账户总表后重试。', + ); + + $connection->table('fin_accounts')->where('account_short', $accountShort)->update([ + 'account_should_keep' => $keep !== '' ? $keep : null, + 'updated_at' => now(), + ]); + + return response()->json([ + 'ok' => true, + 'account_short' => $accountShort, + 'account_should_keep' => $keep, + 'label' => $keep !== '' ? $keep : '未填写', + ], 200, ['Cache-Control' => 'private, no-store']); + } + public function previewShopMapping(FinanceLedgerShopMappingBulk $bulk): JsonResponse { abort_unless(FinanceLedgerAccess::canEditMapping(user()), 403, '只有财务台账管理员可以批量修改账户映射。'); diff --git a/modules/EcommerceFinance/View/FinanceLedgerPageData.php b/modules/EcommerceFinance/View/FinanceLedgerPageData.php index 1d5a9951..f76310ef 100644 --- a/modules/EcommerceFinance/View/FinanceLedgerPageData.php +++ b/modules/EcommerceFinance/View/FinanceLedgerPageData.php @@ -59,6 +59,8 @@ class FinanceLedgerPageData 'ledgerAccountOptions' => $this->accountOptions(), 'ledgerAccountFilterOptions' => $this->accountFilterOptions(), 'ledgerAccountStatusOptions' => FinanceLedgerAccountStatus::OPTIONS, + 'ledgerAccountPlanOptions' => $this->accountPlanOptions(), + 'ledgerAccountKeepOptions' => FinanceLedgerAccountShouldKeep::OPTIONS, 'ledgerCanEditMapping' => FinanceLedgerAccess::canEditMapping(user()), 'ledgerCanEditAccountStatus' => FinanceLedgerAccess::canEditAccountStatus(user()), 'ledgerCanEditAccountType' => FinanceLedgerAccess::canEditAccountType(user()), @@ -376,6 +378,21 @@ class FinanceLedgerPageData ]; } + private function accountPlanOptions(): array + { + return $this->db()->table('fin_accounts') + ->whereNotNull('company_plan') + ->where('company_plan', '<>', '') + ->distinct() + ->orderBy('company_plan') + ->pluck('company_plan') + ->map(static fn (mixed $value): string => trim((string) $value)) + ->filter() + ->unique() + ->values() + ->all(); + } + private function db() { return DB::connection((string) config('upstream_mirrors.connection', 'business_mirror')); diff --git a/resources/views/business/pages/financial-ledger/ledger.blade.php b/resources/views/business/pages/financial-ledger/ledger.blade.php index df2880b3..ced7755e 100644 --- a/resources/views/business/pages/financial-ledger/ledger.blade.php +++ b/resources/views/business/pages/financial-ledger/ledger.blade.php @@ -9,6 +9,8 @@ $accountStatusOptions = $ledgerAccountStatusOptions ?? \App\Utilities\FinanceLedgerAccountStatus::OPTIONS; $accountFilterOptions = $ledgerAccountFilterOptions ?? ['regions' => [], 'types' => []]; $accountTypeOptions = $accountFilterOptions['types'] ?? []; + $accountPlanOptions = $ledgerAccountPlanOptions ?? []; + $accountKeepOptions = $ledgerAccountKeepOptions ?? \App\Utilities\FinanceLedgerAccountShouldKeep::OPTIONS; $activeAccountFilterCount = count(array_filter([ request('accounts_q'), request('accounts_short'), @@ -133,6 +135,8 @@ .ledger-inline-select { display:block; height:1.75rem; margin:0 auto; padding:0 .1rem; border:1px solid var(--vip-border, #D8D2C7); border-radius:.4rem; background:#fff; color:var(--vip-content-ink, #171717); font:inherit; font-size:.68rem; font-weight:600; text-align:center; text-align-last:center; cursor:pointer; } .ledger-status-select { width:4.15rem; min-width:4.15rem; } .ledger-type-select { width:5.2rem; min-width:5.2rem; } + .ledger-plan-select { width:6.5rem; min-width:6.5rem; } + .ledger-keep-select { width:4.8rem; min-width:4.8rem; } .ledger-inline-select:focus { border-color:var(--vip-content-accent-dark, #856632); outline:none; box-shadow:0 0 0 3px rgba(133,102,50,.16); } .ledger-inline-select[data-status="normal"] { border-color:rgba(83,121,62,.38); background:#f3f7ee; color:var(--vip-success, #53793E); } .ledger-inline-select[data-status="online_banking_abnormal"] { border-color:rgba(184,0,0,.34); background:#fff5f5; color:var(--vip-danger, #B80000); } @@ -247,7 +251,29 @@ @endif