增加店铺主体筛选及提现管理 XLSX 导入导出;导入采用预览确认并限制可写字段。 Co-authored-by: 92451 <924518135@qq.com> Co-committed-by: 92451 <924518135@qq.com>
107 lines
3.5 KiB
PHP
107 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Business;
|
|
|
|
use App\Business\WithdrawalManagementReport;
|
|
use App\Business\WithdrawalManagementSpreadsheet;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Str;
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
|
|
class WithdrawalManagement extends Controller
|
|
{
|
|
private const PREVIEW_CACHE_PREFIX = 'withdrawal-management-import:';
|
|
|
|
public function __construct(
|
|
private readonly WithdrawalManagementReport $report,
|
|
private readonly WithdrawalManagementSpreadsheet $spreadsheet,
|
|
) {
|
|
$this->middleware('auth');
|
|
$this->middleware('company.identify');
|
|
$this->middleware('business.page:fund-management,withdrawal-management');
|
|
}
|
|
|
|
public function export(Request $request): StreamedResponse
|
|
{
|
|
return $this->spreadsheet->export($this->report->results($request));
|
|
}
|
|
|
|
public function template(): StreamedResponse
|
|
{
|
|
return $this->spreadsheet->template();
|
|
}
|
|
|
|
public function importPreview(Request $request): RedirectResponse
|
|
{
|
|
$file = $request->validate([
|
|
'import' => ['required', 'file', 'mimes:xlsx,xls', 'max:10240'],
|
|
])['import'];
|
|
$preview = $this->spreadsheet->preview($file, (int) company_id());
|
|
$token = Str::random(48);
|
|
Cache::put($this->cacheKey($token), [
|
|
'company_id' => (int) company_id(),
|
|
'user_id' => (int) user_id(),
|
|
'plan' => $preview['plan'],
|
|
], now()->addMinutes(30));
|
|
unset($preview['plan']);
|
|
|
|
return $this->redirect($request)->with(
|
|
'withdrawalImportPreview',
|
|
$preview + ['token' => $token],
|
|
);
|
|
}
|
|
|
|
public function importCommit(Request $request): RedirectResponse
|
|
{
|
|
$token = $request->validate([
|
|
'preview_token' => ['required', 'string', 'size:48'],
|
|
])['preview_token'];
|
|
$payload = Cache::pull($this->cacheKey($token));
|
|
|
|
if (! is_array($payload)
|
|
|| (int) ($payload['company_id'] ?? 0) !== (int) company_id()
|
|
|| (int) ($payload['user_id'] ?? 0) !== (int) user_id()
|
|
|| ! is_array($payload['plan'] ?? null)) {
|
|
return $this->redirect($request)->withErrors([
|
|
'import' => '导入预览已失效或不属于当前账号,请重新上传并预览。',
|
|
]);
|
|
}
|
|
|
|
$updated = $this->spreadsheet->commit($payload['plan'], (int) company_id());
|
|
|
|
return $this->redirect($request)->with('success', "提现配置导入完成,共更新 {$updated} 家店铺。");
|
|
}
|
|
|
|
private function cacheKey(string $token): string
|
|
{
|
|
return self::PREVIEW_CACHE_PREFIX . hash('sha256', $token);
|
|
}
|
|
|
|
private function redirect(Request $request): RedirectResponse
|
|
{
|
|
$filters = $this->report->filters($request);
|
|
$parameters = [
|
|
'section' => 'fund-management',
|
|
'page' => 'withdrawal-management',
|
|
];
|
|
$queryNames = [
|
|
'platform' => 'platform',
|
|
'withdrawalPath' => 'withdrawal_path',
|
|
'storeEntity' => 'store_entity',
|
|
'keyword' => 'keyword',
|
|
'balanceStatus' => 'balance_status',
|
|
];
|
|
|
|
foreach ($queryNames as $filterName => $queryName) {
|
|
if ($filters[$filterName] !== '') {
|
|
$parameters[$queryName] = $filters[$filterName];
|
|
}
|
|
}
|
|
|
|
return redirect()->route('business.pages.show', $parameters);
|
|
}
|
|
}
|