- 基础环境:Docker 部署配置,源码挂载实时同步 - 修复:super_admin 权限补全、登录重定向循环 - 开发:店铺营销账户账单 - 抖音账户(15字段汇总账单) - 开发:店铺营销账户账单 - 淘系支付宝账户(8字段流水账单) - 开发:店铺营销账户账单 - 拼多多账户(7字段流水账单) - 业务页面导航集成:config/business_navigation.php + Business\Pages 控制器 - 各平台独立表结构和视图,互不影响
183 lines
5.9 KiB
PHP
183 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Banking;
|
|
|
|
use App\Abstracts\Http\Controller;
|
|
use App\Http\Requests\Banking\FundAccount as Request;
|
|
use App\Models\Banking\FundAccount;
|
|
use App\Utilities\FundAccountSpreadsheet;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request as HttpRequest;
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
|
|
class FundAccounts extends Controller
|
|
{
|
|
private const PLATFORMS = [
|
|
'bank' => 'bank_accounts',
|
|
'alipay' => 'alipay_accounts',
|
|
'web_wallet' => 'web_wallet_accounts',
|
|
'pdd' => 'pdd_accounts',
|
|
'dewu' => 'dewu_accounts',
|
|
];
|
|
|
|
public function __construct()
|
|
{
|
|
$this->middleware('permission:read-banking-accounts')->only('bankIndex', 'storeIndex', 'platformIndex');
|
|
$this->middleware('permission:create-banking-accounts')->only('create', 'store', 'import', 'template');
|
|
$this->middleware('permission:update-banking-accounts')->only('edit', 'update', 'export');
|
|
$this->middleware('permission:delete-banking-accounts')->only('destroy');
|
|
}
|
|
|
|
public function bankIndex()
|
|
{
|
|
return $this->index('bank');
|
|
}
|
|
|
|
public function storeIndex()
|
|
{
|
|
return view('banking.fund_accounts.store-index', [
|
|
'platforms' => array_filter(self::PLATFORMS, fn ($platform) => $platform !== 'bank', ARRAY_FILTER_USE_KEY),
|
|
]);
|
|
}
|
|
|
|
public function platformIndex(string $platform)
|
|
{
|
|
return $this->index($platform);
|
|
}
|
|
|
|
public function create(string $platform)
|
|
{
|
|
return view('banking.fund_accounts.form', [
|
|
'platform' => $this->platform($platform),
|
|
'account' => new FundAccount([
|
|
'company_name' => company()?->name ?? '',
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public function template(string $platform, FundAccountSpreadsheet $spreadsheet): StreamedResponse
|
|
{
|
|
return $spreadsheet->downloadTemplate($this->platform($platform));
|
|
}
|
|
|
|
public function export(HttpRequest $request, string $platform, FundAccountSpreadsheet $spreadsheet): StreamedResponse
|
|
{
|
|
$platform = $this->platform($platform);
|
|
$ids = $request->validate([
|
|
'ids' => ['nullable', 'array', 'max:5000'],
|
|
'ids.*' => ['integer'],
|
|
])['ids'] ?? [];
|
|
|
|
$query = FundAccount::where('platform', $platform)->oldest('id');
|
|
|
|
if (! empty($ids)) {
|
|
$query->whereKey($ids);
|
|
}
|
|
|
|
return $spreadsheet->downloadAccounts($platform, $query->get());
|
|
}
|
|
|
|
public function import(HttpRequest $request, string $platform, FundAccountSpreadsheet $spreadsheet): RedirectResponse
|
|
{
|
|
$platform = $this->platform($platform);
|
|
$validated = $request->validate([
|
|
'import' => ['required', 'file', 'mimes:xlsx,xls,csv', 'max:5120'],
|
|
], [
|
|
'import.required' => trans('fund_accounts.import_required'),
|
|
'import.mimes' => trans('fund_accounts.import_file_type'),
|
|
'import.max' => trans('fund_accounts.import_file_size'),
|
|
]);
|
|
|
|
$count = $spreadsheet->import($platform, $validated['import']);
|
|
|
|
flash(trans('fund_accounts.import_success', ['count' => $count]))->success();
|
|
|
|
return redirect()->route('fund-accounts.platform.index', $platform);
|
|
}
|
|
|
|
public function store(Request $request, string $platform): RedirectResponse
|
|
{
|
|
$platform = $this->platform($platform);
|
|
$data = $request->validated();
|
|
|
|
if ($platform === 'bank') {
|
|
$data['account_name'] = $data['bank_name'];
|
|
}
|
|
|
|
$account = FundAccount::create(array_merge($data, [
|
|
'company_id' => company_id(),
|
|
'platform' => $platform,
|
|
'created_from' => 'core::ui',
|
|
'created_by' => user()->id,
|
|
]));
|
|
|
|
flash(trans('messages.success.created', ['type' => $this->title($account->platform)]))->success();
|
|
|
|
return redirect()->route('fund-accounts.platform.index', $account->platform);
|
|
}
|
|
|
|
public function edit(string $platform, FundAccount $fundAccount)
|
|
{
|
|
abort_unless($fundAccount->platform === $this->platform($platform), 404);
|
|
|
|
return view('banking.fund_accounts.form', [
|
|
'platform' => $fundAccount->platform,
|
|
'account' => $fundAccount,
|
|
]);
|
|
}
|
|
|
|
public function update(Request $request, string $platform, FundAccount $fundAccount): RedirectResponse
|
|
{
|
|
abort_unless($fundAccount->platform === $this->platform($platform), 404);
|
|
|
|
$data = $request->validated();
|
|
|
|
if (empty($data['login_password'])) {
|
|
unset($data['login_password']);
|
|
}
|
|
|
|
if ($fundAccount->platform === 'bank') {
|
|
$data['account_name'] = $data['bank_name'];
|
|
}
|
|
|
|
$fundAccount->update($data);
|
|
|
|
flash(trans('messages.success.updated', ['type' => $this->title($fundAccount->platform)]))->success();
|
|
|
|
return redirect()->route('fund-accounts.platform.index', $fundAccount->platform);
|
|
}
|
|
|
|
public function destroy(string $platform, FundAccount $fundAccount): RedirectResponse
|
|
{
|
|
abort_unless($fundAccount->platform === $this->platform($platform), 404);
|
|
|
|
$fundAccount->delete();
|
|
|
|
flash(trans('messages.success.deleted', ['type' => $this->title($platform)]))->success();
|
|
|
|
return redirect()->route('fund-accounts.platform.index', $platform);
|
|
}
|
|
|
|
private function index(string $platform)
|
|
{
|
|
$platform = $this->platform($platform);
|
|
|
|
return view('banking.fund_accounts.index', [
|
|
'platform' => $platform,
|
|
'accounts' => FundAccount::where('platform', $platform)->latest()->paginate(setting('default.list_limit', 25)),
|
|
]);
|
|
}
|
|
|
|
private function platform(string $platform): string
|
|
{
|
|
abort_unless(array_key_exists($platform, self::PLATFORMS), 404);
|
|
|
|
return $platform;
|
|
}
|
|
|
|
private function title(string $platform): string
|
|
{
|
|
return trans('fund_accounts.' . self::PLATFORMS[$platform]);
|
|
}
|
|
}
|