fix: preserve production promotion account page
This commit is contained in:
parent
ea76f8d5c9
commit
5679a41105
@ -31,6 +31,7 @@ use Modules\EcommerceFinance\Repositories\DingPayableWorkflowMirrorRepository;
|
||||
use Modules\EcommerceFinance\Repositories\SupplierPayableReportRepository;
|
||||
use Modules\EcommerceFinance\Repositories\TmallTaobaoSpreadBillRepository;
|
||||
use Modules\EcommerceFinance\Services\UpstreamQueryCacheFactory;
|
||||
use Modules\EcommerceFinance\View\PlatformPromotionAccountPageData;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
|
||||
use Throwable;
|
||||
@ -323,6 +324,7 @@ class Pages extends Controller
|
||||
'board-deductions' => $this->contentForBoardDeductions(),
|
||||
'supplier-payables-report' => $this->contentForSupplierPayablesReport(),
|
||||
'payable-cloud-warehouse-vehicle-fee' => $this->contentForDingPayableWorkflows(),
|
||||
'platform-promotion-accounts' => app(PlatformPromotionAccountPageData::class)->content($tab),
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
@ -670,6 +672,10 @@ class Pages extends Controller
|
||||
$pageConfig = collect($sectionConfig['pages'] ?? [])->firstWhere('slug', $page);
|
||||
abort_if(empty($pageConfig), 403, '当前账号没有该页面权限。');
|
||||
|
||||
if ($page === 'platform-promotion-accounts') {
|
||||
return $this->exportPlatformPromotionAccounts($request);
|
||||
}
|
||||
|
||||
if ($page === 'marketing-account-bills') {
|
||||
return $this->exportMarketingAccountBills($request, $section, $page, $tab);
|
||||
}
|
||||
@ -739,6 +745,56 @@ class Pages extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
private function exportPlatformPromotionAccounts(Request $request)
|
||||
{
|
||||
$month = trim((string) $request->query('month', ''));
|
||||
$month = preg_match('/^\d{4}-\d{2}$/', $month) === 1 ? $month : null;
|
||||
$filters = [
|
||||
'month' => $month,
|
||||
'shop_name' => mb_substr(trim((string) $request->query('shop_name', '')), 0, 100),
|
||||
'account' => mb_substr(trim((string) $request->query('account', '')), 0, 100),
|
||||
];
|
||||
|
||||
try {
|
||||
$repository = app(\Modules\EcommerceFinance\Repositories\PlatformPromotionAccountRepository::class);
|
||||
$filters['month'] = $month ?: ($repository->latestMonth() ?: now()->format('Y-m'));
|
||||
$data = $repository->dashboard($filters, 5000);
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
|
||||
return redirect()->route('business.pages.show', [
|
||||
'section' => 'billing-transactions',
|
||||
'page' => 'platform-promotion-accounts',
|
||||
])->with('error', '推广账户数据导出暂时无法完成,请稍后重试。');
|
||||
}
|
||||
|
||||
return response()->streamDownload(function () use ($data): void {
|
||||
$csv = fopen('php://output', 'w');
|
||||
fputs($csv, chr(0xEF) . chr(0xBB) . chr(0xBF));
|
||||
fputcsv($csv, ['平台', '店铺/账户', '日期', '类型', '金额(元)', '余额(元)', '备注']);
|
||||
$emit = static function (string $platform, array $rows, array $map) use ($csv): void {
|
||||
foreach ($rows as $row) {
|
||||
fputcsv($csv, [
|
||||
$platform,
|
||||
$map['name']($row),
|
||||
$map['date']($row),
|
||||
$map['type']($row),
|
||||
$map['amount']($row),
|
||||
$map['balance']($row),
|
||||
$map['remark']($row),
|
||||
]);
|
||||
}
|
||||
};
|
||||
$emit('京东京准通', $data['jd'] ?? [], ['name' => fn ($row) => $row['shop_name'] . ' / ' . $row['account'], 'date' => fn ($row) => $row['show_date'] ?? $row['settle_datetime'], 'type' => fn ($row) => $row['trade_type_name'] ?? $row['in_out_type_name'], 'amount' => fn ($row) => $row['amount'] ?? '', 'balance' => fn ($row) => $row['balance_amount'] ?? '', 'remark' => fn ($row) => $row['remark'] ?? '']);
|
||||
$emit('抖音千川', $data['dy'] ?? [], ['name' => fn ($row) => $row['shopName'] . ' / ' . $row['account'] . ' / ' . $row['qianchuanAavid'], 'date' => fn ($row) => $row['statDate'] ?? '', 'type' => fn () => '花费', 'amount' => fn ($row) => $row['cost'] ?? '', 'balance' => fn ($row) => $row['balance'] ?? '', 'remark' => fn ($row) => $row['remark'] ?? '']);
|
||||
$emit('得物推广', $data['dw'] ?? [], ['name' => fn ($row) => $row['shop_name'] . ' / ' . $row['account'], 'date' => fn ($row) => $row['trade_date'] ?? $row['date_time'], 'type' => fn ($row) => $row['flow_type'] ?? '', 'amount' => fn ($row) => $row['trade_amount_yuan'] ?? '', 'balance' => fn ($row) => $row['balance_yuan'] ?? '', 'remark' => fn ($row) => $row['remark'] ?? '']);
|
||||
$emit('VIP营销', $data['vipMarketing'] ?? [], ['name' => fn ($row) => $row['accountName'] . ' / ' . $row['advertiserId'], 'date' => fn ($row) => $row['dataMonth'], 'type' => fn () => '月度花费', 'amount' => fn ($row) => $row['totalCostYuan'] ?? '', 'balance' => fn () => '', 'remark' => fn ($row) => '曝光 ' . $row['totalImpressionCount']]);
|
||||
fclose($csv);
|
||||
}, '平台推广账户流水_' . $filters['month'] . '.csv', [
|
||||
'Content-Type' => 'text/csv; charset=UTF-8',
|
||||
]);
|
||||
}
|
||||
|
||||
private function exportMarketingAccountBills(
|
||||
Request $request,
|
||||
string $section,
|
||||
|
||||
@ -311,6 +311,16 @@ return [
|
||||
['slug' => 'vipshop', 'title' => '唯品会账户'],
|
||||
],
|
||||
],
|
||||
[
|
||||
'slug' => 'platform-promotion-accounts',
|
||||
'title' => '平台推广账户流水',
|
||||
'tabs' => [
|
||||
['slug' => 'jd', 'title' => '京东京准通'],
|
||||
['slug' => 'douyin', 'title' => '抖音千川'],
|
||||
['slug' => 'dewu', 'title' => '得物推广账户'],
|
||||
['slug' => 'vip', 'title' => 'VIP(唯品会)'],
|
||||
],
|
||||
],
|
||||
['slug' => 'deposit-account-balance', 'title' => '店铺保证金账户余额'],
|
||||
[
|
||||
'slug' => 'deposit-account-bills',
|
||||
|
||||
17
config/js_data_middle_platform.php
Normal file
17
config/js_data_middle_platform.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'enabled' => true,
|
||||
'connection' => [
|
||||
'host' => env('JS_DATA_MIDDLE_PLATFORM_HOST', '218.93.191.16'),
|
||||
'port' => (int) env('JS_DATA_MIDDLE_PLATFORM_PORT', 1433),
|
||||
'database' => env('JS_DATA_MIDDLE_PLATFORM_DATABASE', 'JSDataMiddlePlatform'),
|
||||
'username' => env('JS_DATA_MIDDLE_PLATFORM_USERNAME', 'sa'),
|
||||
'password' => env('JS_DATA_MIDDLE_PLATFORM_PASSWORD', ''),
|
||||
'odbc_driver' => env('JS_DATA_MIDDLE_PLATFORM_ODBC_DRIVER', 'FreeTDS'),
|
||||
'tds_version' => env('JS_DATA_MIDDLE_PLATFORM_TDS_VERSION', '7.4'),
|
||||
'connect_timeout' => (int) env('JS_DATA_MIDDLE_PLATFORM_CONNECT_TIMEOUT', 5),
|
||||
'query_timeout' => (int) env('JS_DATA_MIDDLE_PLATFORM_QUERY_TIMEOUT', 30),
|
||||
'encryption' => env('JS_DATA_MIDDLE_PLATFORM_ENCRYPTION', 'off'),
|
||||
],
|
||||
];
|
||||
@ -67,5 +67,10 @@ return [
|
||||
// Windows 和其他来源继续保持现有 PDO_ODBC 行为。
|
||||
'use_pdo_dblib' => true,
|
||||
],
|
||||
'js_data_middle_platform' => [
|
||||
'label' => 'JSDataMiddlePlatform 中台库',
|
||||
'config' => 'js_data_middle_platform',
|
||||
'use_pdo_dblib' => true,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\EcommerceFinance\Repositories;
|
||||
|
||||
use Modules\EcommerceFinance\Services\UpstreamReadOnlyQuery;
|
||||
use Modules\EcommerceFinance\Services\UpstreamReadOnlyQueryFactory;
|
||||
|
||||
/** 固定字段、固定表的四平台推广账户只读查询。 */
|
||||
class PlatformPromotionAccountRepository
|
||||
{
|
||||
private const SOURCE = 'js_data_middle_platform';
|
||||
|
||||
public function __construct(private readonly UpstreamReadOnlyQueryFactory $queries)
|
||||
{
|
||||
}
|
||||
|
||||
public function dashboard(array $filters, int $limit = 200): array
|
||||
{
|
||||
$month = $filters['month'];
|
||||
$shop = $filters['shop_name'] ?? null;
|
||||
$account = $filters['account'] ?? null;
|
||||
$limit = min(max($limit, 1), 5000);
|
||||
$query = $this->queries->forSource(self::SOURCE);
|
||||
|
||||
$jd = $this->query($query, "SELECT TOP {$limit} data_month, shop_name, account, login_pin, in_out_type_name, trade_type_name, amount, balance_amount, settle_datetime, show_date, trade_no, remark FROM JSDataMiddlePlatform.dbo.jd_jzt_finance_records WHERE data_month = ?", [$month], $shop, $account, 'shop_name');
|
||||
$jdSummary = $this->query($query, "SELECT COALESCE(SUM(CASE WHEN in_out_type='IN' THEN amount ELSE 0 END),0) income, COALESCE(SUM(CASE WHEN in_out_type='OUT' THEN amount ELSE 0 END),0) expense, COUNT(*) record_count FROM JSDataMiddlePlatform.dbo.jd_jzt_finance_records WHERE data_month = ?", [$month], $shop, $account, 'shop_name', true)[0] ?? [];
|
||||
|
||||
$douyin = $this->query($query, "SELECT TOP {$limit} shopName, account, qianchuanAavid, qianchuanAccountName, statDate, cost, income, transferOut, transferIn, balance, status, remark FROM JSDataMiddlePlatform.dbo.dy_qianchuan_finance_transactions WHERE dataMonth = ? AND rowType = N'daily' AND status = N'success'", [$month . '-01'], $shop, $account, 'shopName');
|
||||
$douyinSummary = $this->query($query, "SELECT COALESCE(SUM(cost),0) cost, COALESCE(SUM(income),0) income, COALESCE(SUM(transferOut),0) transfer_out, COALESCE(SUM(transferIn),0) transfer_in, COUNT(DISTINCT qianchuanAavid) account_count FROM JSDataMiddlePlatform.dbo.dy_qianchuan_finance_transactions WHERE dataMonth = ? AND rowType = N'daily' AND status = N'success'", [$month . '-01'], $shop, $account, 'shopName', true)[0] ?? [];
|
||||
$douyinStatus = $this->query($query, "SELECT COUNT(*) status_count FROM JSDataMiddlePlatform.dbo.dy_qianchuan_finance_transactions WHERE dataMonth = ? AND rowType = N'status' AND status = N'no_permission'", [$month . '-01'], $shop, $account, 'shopName', true)[0] ?? [];
|
||||
|
||||
$dewu = $this->query($query, "SELECT TOP {$limit} data_month, shop_name, account, amount_type, flow_type, trade_amount_yuan, balance_yuan, trade_date, date_time, remark FROM JSDataMiddlePlatform.dbo.dw_ad_finance_records WHERE data_month = ?", [$month], $shop, $account, 'shop_name');
|
||||
$dewuSummary = $this->query($query, 'SELECT COALESCE(SUM(total_income_amount),0) income, COALESCE(SUM(total_expense_amount),0) expense, COALESCE(SUM(net_amount),0) net, COALESCE(SUM(record_count),0) record_count FROM JSDataMiddlePlatform.dbo.dw_ad_finance_month_summaries WHERE data_month = ?', [$month], $shop, $account, 'shop_name', true)[0] ?? [];
|
||||
|
||||
$vipSales = $this->query($query, "SELECT TOP {$limit} shopName, dataMonth, monthName, previousYearSalesAmount, salesTarget, actualSalesAmount, updatedAt FROM JSDataMiddlePlatform.dbo.vip_monthlySaleProgress WHERE dataMonth = ?", [$month], $shop, null, 'shopName');
|
||||
$vipTax = $this->query($query, "SELECT TOP {$limit} shopName, storeName, reportAmount, returnOrderCount, returnServiceAmount, returnSkuAmount, saleOrderCount, salesServiceAmount, salesSkuAmount, transactionNum, transactionTime FROM JSDataMiddlePlatform.dbo.vip_taxDeclarationDetail WHERE dataMonth = ?", [$month], $shop, null, 'shopName');
|
||||
$vipMarketing = $this->query($query, "SELECT TOP {$limit} account, accountName, advertiserId, dataMonth, totalCostYuan, totalImpressionCount, recordCount, updatedAt FROM JSDataMiddlePlatform.dbo.vip_marketingMonthlySummary WHERE dataMonth = ?", [$month], null, $account, 'account');
|
||||
$vipSummary = [
|
||||
'sales' => $this->sum($vipSales, 'actualSalesAmount'),
|
||||
'target' => $this->sum($vipSales, 'salesTarget'),
|
||||
'tax' => $this->sum($vipTax, 'reportAmount'),
|
||||
'marketing_cost' => $this->sum($vipMarketing, 'totalCostYuan'),
|
||||
'impressions' => $this->sum($vipMarketing, 'totalImpressionCount'),
|
||||
];
|
||||
|
||||
return [
|
||||
'jd' => $jd,
|
||||
'jdSummary' => $jdSummary,
|
||||
'dy' => $douyin,
|
||||
'dySummary' => $douyinSummary,
|
||||
'dyStatus' => $douyinStatus,
|
||||
'dw' => $dewu,
|
||||
'dwSummary' => $dewuSummary,
|
||||
'vipSales' => $vipSales,
|
||||
'vipTax' => $vipTax,
|
||||
'vipMarketing' => $vipMarketing,
|
||||
'vipSummary' => $vipSummary,
|
||||
];
|
||||
}
|
||||
|
||||
public function latestMonth(): ?string
|
||||
{
|
||||
$row = $this->queries->forSource(self::SOURCE)->first(
|
||||
'SELECT MAX(data_month) AS month FROM JSDataMiddlePlatform.dbo.jd_jzt_finance_records'
|
||||
);
|
||||
$month = trim((string) ($row['month'] ?? ''));
|
||||
|
||||
return preg_match('/^\d{4}-\d{2}$/', $month) === 1 ? $month : null;
|
||||
}
|
||||
|
||||
private function query(
|
||||
UpstreamReadOnlyQuery $query,
|
||||
string $sql,
|
||||
array $bindings,
|
||||
?string $shop,
|
||||
?string $account,
|
||||
string $shopColumn,
|
||||
bool $summary = false,
|
||||
): array {
|
||||
if ($shop !== null && $shop !== '') {
|
||||
$sql .= " AND {$shopColumn} LIKE ?";
|
||||
$bindings[] = '%' . $shop . '%';
|
||||
}
|
||||
if ($account !== null && $account !== '') {
|
||||
$sql .= ' AND account LIKE ?';
|
||||
$bindings[] = '%' . $account . '%';
|
||||
}
|
||||
if (! $summary) {
|
||||
$sql .= ' ORDER BY 1';
|
||||
}
|
||||
|
||||
return $query->select($sql, $bindings);
|
||||
}
|
||||
|
||||
private function sum(array $rows, string $key): float
|
||||
{
|
||||
return round(array_sum(array_map(static fn (array $row): float => (float) ($row[$key] ?? 0), $rows)), 2);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\EcommerceFinance\View;
|
||||
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Modules\EcommerceFinance\Repositories\PlatformPromotionAccountRepository;
|
||||
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
|
||||
use Throwable;
|
||||
|
||||
class PlatformPromotionAccountPageData
|
||||
{
|
||||
public function __construct(private readonly PlatformPromotionAccountRepository $repository)
|
||||
{
|
||||
}
|
||||
|
||||
public function content(?string $tab = null): array
|
||||
{
|
||||
$requestedMonth = $this->month(request('month'));
|
||||
$month = $requestedMonth ?: now()->format('Y-m');
|
||||
$filters = [
|
||||
'month' => $month,
|
||||
'shop_name' => $this->text(request('shop_name')),
|
||||
'account' => $this->text(request('account')),
|
||||
];
|
||||
$tab = in_array($tab, ['jd', 'douyin', 'dewu', 'vip'], true) ? $tab : 'jd';
|
||||
|
||||
try {
|
||||
if ($requestedMonth === '') {
|
||||
$month = $this->repository->latestMonth() ?: $month;
|
||||
$filters['month'] = $month;
|
||||
}
|
||||
$data = $this->repository->dashboard($filters, 5000);
|
||||
|
||||
return [
|
||||
'view' => 'business.pages.billing-transactions.platform-promotion-accounts',
|
||||
'filters' => $filters,
|
||||
'data' => $data,
|
||||
'platform' => $tab,
|
||||
'rows' => $this->paginateRows($data, $tab),
|
||||
'error' => null,
|
||||
];
|
||||
} catch (ServiceUnavailableHttpException $exception) {
|
||||
return [
|
||||
'view' => 'business.pages.billing-transactions.platform-promotion-accounts',
|
||||
'filters' => $filters,
|
||||
'data' => [],
|
||||
'platform' => $tab,
|
||||
'rows' => $this->emptyPaginator(),
|
||||
'error' => $exception->getMessage(),
|
||||
];
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
|
||||
return [
|
||||
'view' => 'business.pages.billing-transactions.platform-promotion-accounts',
|
||||
'filters' => $filters,
|
||||
'data' => [],
|
||||
'platform' => $tab,
|
||||
'rows' => $this->emptyPaginator(),
|
||||
'error' => '推广账户数据暂时无法读取,请稍后重试。',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
private function paginateRows(array $data, string $tab): LengthAwarePaginator
|
||||
{
|
||||
$key = ['jd' => 'jd', 'douyin' => 'dy', 'dewu' => 'dw', 'vip' => 'vipSales'][$tab];
|
||||
$rows = $tab === 'vip'
|
||||
? array_merge($data['vipSales'] ?? [], $data['vipTax'] ?? [], $data['vipMarketing'] ?? [])
|
||||
: ($data[$key] ?? []);
|
||||
$page = max((int) request('page', 1), 1);
|
||||
$perPage = 50;
|
||||
|
||||
return new LengthAwarePaginator(
|
||||
Collection::make($rows)->forPage($page, $perPage)->values(),
|
||||
count($rows),
|
||||
$perPage,
|
||||
$page,
|
||||
['path' => request()->url(), 'query' => request()->except('page')],
|
||||
);
|
||||
}
|
||||
|
||||
private function emptyPaginator(): LengthAwarePaginator
|
||||
{
|
||||
return new LengthAwarePaginator([], 0, 50, 1, [
|
||||
'path' => request()->url(),
|
||||
'query' => request()->query(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function text(mixed $value): string
|
||||
{
|
||||
return mb_substr(trim((string) $value), 0, 100);
|
||||
}
|
||||
|
||||
private function month(mixed $value): string
|
||||
{
|
||||
$value = trim((string) $value);
|
||||
if (preg_match('/^(\d{4})-(\d{2})$/', $value, $matches) !== 1
|
||||
|| (int) $matches[2] < 1
|
||||
|| (int) $matches[2] > 12) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
@php
|
||||
$data = $data ?? [];
|
||||
$platform = $platform ?? 'jd';
|
||||
$summary = match ($platform) {
|
||||
'jd' => $data['jdSummary'] ?? [],
|
||||
'douyin' => $data['dySummary'] ?? [],
|
||||
'dewu' => $data['dwSummary'] ?? [],
|
||||
default => $data['vipSummary'] ?? [],
|
||||
};
|
||||
$titles = ['jd' => '京东京准通', 'douyin' => '抖音千川', 'dewu' => '得物推广账户', 'vip' => 'VIP(唯品会)'];
|
||||
$columns = match ($platform) {
|
||||
'jd' => [['shop_name', '店铺'], ['account', '账户'], ['show_date', '日期'], ['trade_type_name', '交易类型'], ['amount', '金额'], ['balance_amount', '余额'], ['remark', '备注']],
|
||||
'douyin' => [['shopName', '店铺'], ['account', '账户'], ['qianchuanAavid', '广告账户'], ['statDate', '日期'], ['cost', '花费'], ['balance', '余额'], ['status', '状态'], ['remark', '备注']],
|
||||
'dewu' => [['shop_name', '店铺'], ['account', '账户'], ['trade_date', '日期'], ['flow_type', '收支类型'], ['trade_amount_yuan', '金额'], ['balance_yuan', '余额'], ['remark', '备注']],
|
||||
default => [['shopName', '店铺'], ['storeName', '平台店铺'], ['accountName', '营销账户'], ['dataMonth', '月份'], ['actualSalesAmount', '实际销售额'], ['reportAmount', '申报金额'], ['totalCostYuan', '营销花费']],
|
||||
};
|
||||
$moneyFields = ['amount', 'balance_amount', 'cost', 'balance', 'trade_amount_yuan', 'balance_yuan', 'actualSalesAmount', 'reportAmount', 'totalCostYuan'];
|
||||
@endphp
|
||||
<style>
|
||||
.platform-promotion-page .biz-grid { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:12px; margin:14px 0; }
|
||||
.platform-promotion-page .biz-card { padding:16px 18px; }
|
||||
.platform-promotion-page .biz-card-title { color:#6b6255; font-size:13px; font-weight:600; }
|
||||
.platform-promotion-page .biz-kpi { margin-top:7px; color:#171717; font-size:22px; font-weight:700; }
|
||||
.platform-promotion-page .platform-pagination { display:flex; align-items:center; justify-content:space-between; gap:16px; padding:14px 4px 2px; color:#6b6255; font-size:13px; }
|
||||
.platform-promotion-page .platform-pagination nav { display:flex; align-items:center; justify-content:flex-end; min-width:0; }
|
||||
.platform-promotion-page .platform-pagination__buttons { display:flex !important; flex-direction:row !important; flex-wrap:nowrap; align-items:center; gap:8px; white-space:nowrap; }
|
||||
.platform-promotion-page .platform-pagination__buttons a,
|
||||
.platform-promotion-page .platform-pagination__buttons span { display:inline-flex !important; min-width:32px; height:32px; align-items:center; justify-content:center; padding:0 10px; border:1px solid #ded7ca; border-radius:7px; background:#fff; color:#433f39; text-decoration:none; }
|
||||
.platform-promotion-page .platform-pagination__buttons a.is-current { border-color:#856632; background:#856632; color:#fff; }
|
||||
.platform-promotion-page .platform-pagination__buttons span.is-disabled { color:#a7a095; background:#f8f6f2; }
|
||||
.platform-promotion-page .platform-pagination__buttons a:hover { border-color:#856632; color:#856632; }
|
||||
@media (max-width: 900px) { .platform-promotion-page .biz-grid { grid-template-columns:repeat(2,minmax(0,1fr)); } .platform-promotion-page .platform-pagination { align-items:flex-start; flex-direction:column; } }
|
||||
</style>
|
||||
<div class="platform-promotion-page">
|
||||
<form method="GET" class="upstream-data-toolbar" aria-label="平台推广账户筛选">
|
||||
<label>数据月份 <input type="month" name="month" value="{{ $filters['month'] ?? now()->format('Y-m') }}" required></label>
|
||||
<label>店铺 <input type="text" name="shop_name" value="{{ $filters['shop_name'] ?? '' }}" placeholder="店铺名称"></label>
|
||||
<label>账户 <input type="text" name="account" value="{{ $filters['account'] ?? '' }}" placeholder="账户名称"></label>
|
||||
<button class="biz-btn biz-btn-primary" type="submit">查询</button>
|
||||
<a class="biz-btn biz-btn-ghost" href="{{ route('business.pages.export', ['section' => 'billing-transactions', 'page' => 'platform-promotion-accounts', 'tab' => $platform] + request()->only(['month', 'shop_name', 'account'])) }}">导出 CSV</a>
|
||||
</form>
|
||||
|
||||
@if (! empty($error))
|
||||
<div class="biz-alert biz-alert-error" role="alert">{{ $error }}</div>
|
||||
@endif
|
||||
|
||||
<div class="biz-grid biz-grid-4">
|
||||
@if ($platform === 'jd')
|
||||
<div class="biz-card"><div class="biz-card-title">入账金额</div><div class="biz-kpi">{{ number_format((float) ($summary['income'] ?? 0), 2) }}</div></div>
|
||||
<div class="biz-card"><div class="biz-card-title">出账金额</div><div class="biz-kpi">{{ number_format((float) ($summary['expense'] ?? 0), 2) }}</div></div>
|
||||
<div class="biz-card"><div class="biz-card-title">净额</div><div class="biz-kpi">{{ number_format((float) ($summary['income'] ?? 0) - (float) ($summary['expense'] ?? 0), 2) }}</div></div>
|
||||
<div class="biz-card"><div class="biz-card-title">流水笔数</div><div class="biz-kpi">{{ number_format((int) ($summary['record_count'] ?? 0)) }}</div></div>
|
||||
@elseif ($platform === 'douyin')
|
||||
<div class="biz-card"><div class="biz-card-title">总花费</div><div class="biz-kpi">{{ number_format((float) ($summary['cost'] ?? 0), 2) }}</div></div>
|
||||
<div class="biz-card"><div class="biz-card-title">收入</div><div class="biz-kpi">{{ number_format((float) ($summary['income'] ?? 0), 2) }}</div></div>
|
||||
<div class="biz-card"><div class="biz-card-title">转入</div><div class="biz-kpi">{{ number_format((float) ($summary['transfer_in'] ?? 0), 2) }}</div></div>
|
||||
<div class="biz-card"><div class="biz-card-title">账户数</div><div class="biz-kpi">{{ number_format((int) ($summary['account_count'] ?? 0)) }}</div></div>
|
||||
@elseif ($platform === 'dewu')
|
||||
<div class="biz-card"><div class="biz-card-title">总收入</div><div class="biz-kpi">{{ number_format((float) ($summary['income'] ?? 0), 2) }}</div></div>
|
||||
<div class="biz-card"><div class="biz-card-title">总支出</div><div class="biz-kpi">{{ number_format((float) ($summary['expense'] ?? 0), 2) }}</div></div>
|
||||
<div class="biz-card"><div class="biz-card-title">净额</div><div class="biz-kpi">{{ number_format((float) ($summary['net'] ?? 0), 2) }}</div></div>
|
||||
<div class="biz-card"><div class="biz-card-title">流水笔数</div><div class="biz-kpi">{{ number_format((int) ($summary['record_count'] ?? 0)) }}</div></div>
|
||||
@else
|
||||
<div class="biz-card"><div class="biz-card-title">实际销售额</div><div class="biz-kpi">{{ number_format((float) ($summary['sales'] ?? 0), 2) }}</div></div>
|
||||
<div class="biz-card"><div class="biz-card-title">销售目标</div><div class="biz-kpi">{{ number_format((float) ($summary['target'] ?? 0), 2) }}</div></div>
|
||||
<div class="biz-card"><div class="biz-card-title">涉税申报</div><div class="biz-kpi">{{ number_format((float) ($summary['tax'] ?? 0), 2) }}</div></div>
|
||||
<div class="biz-card"><div class="biz-card-title">营销花费</div><div class="biz-kpi">{{ number_format((float) ($summary['marketing_cost'] ?? 0), 2) }}</div></div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<section class="biz-card mt-4">
|
||||
<div class="biz-card-head"><div class="biz-card-title">{{ $titles[$platform] }}明细</div><span class="biz-badge">{{ number_format($rows->total()) }} 条</span></div>
|
||||
<div class="biz-table-wrap"><table class="biz-table"><thead><tr>@foreach ($columns as $column)<th>{{ $column[1] }}</th>@endforeach</tr></thead><tbody>
|
||||
@forelse ($rows as $row)
|
||||
<tr>@foreach ($columns as $column)
|
||||
@php($value = $row[$column[0]] ?? null)
|
||||
<td>{{ in_array($column[0], $moneyFields, true) && is_numeric($value) ? number_format((float) $value, 2) : ($value ?? '—') }}</td>
|
||||
@endforeach</tr>
|
||||
@empty
|
||||
<tr><td colspan="{{ count($columns) }}">该月份暂无数据</td></tr>
|
||||
@endforelse
|
||||
</tbody></table></div>
|
||||
<div class="platform-pagination"><span>每页最多 50 条 · 共 {{ number_format($rows->total()) }} 条</span><nav aria-label="{{ $titles[$platform] }}分页"><div class="platform-pagination__buttons">
|
||||
@if ($rows->onFirstPage())<span class="is-disabled">上一页</span>@else<a href="{{ $rows->previousPageUrl() }}">上一页</a>@endif
|
||||
<span>第 {{ $rows->currentPage() }} / {{ max($rows->lastPage(), 1) }} 页</span>
|
||||
@if ($rows->hasMorePages())<a href="{{ $rows->nextPageUrl() }}">下一页</a>@else<span class="is-disabled">下一页</span>@endif
|
||||
</div></nav></div>
|
||||
</section>
|
||||
</div>
|
||||
100
tests/Feature/Business/PlatformPromotionAccountPageTest.php
Normal file
100
tests/Feature/Business/PlatformPromotionAccountPageTest.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Business;
|
||||
|
||||
use App\Models\Auth\Permission;
|
||||
use Mockery;
|
||||
use Modules\EcommerceFinance\Repositories\PlatformPromotionAccountRepository;
|
||||
use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class PlatformPromotionAccountPageTest extends FeatureTestCase
|
||||
{
|
||||
public function test_platform_promotion_page_remains_available_with_bill_offset_navigation(): void
|
||||
{
|
||||
$repository = Mockery::mock(PlatformPromotionAccountRepository::class);
|
||||
$repository->shouldReceive('latestMonth')->once()->andReturn('2026-08');
|
||||
$repository->shouldReceive('dashboard')->once()->with([
|
||||
'month' => '2026-08',
|
||||
'shop_name' => '',
|
||||
'account' => '',
|
||||
], 5000)->andReturn($this->dashboardData());
|
||||
$this->app->instance(PlatformPromotionAccountRepository::class, $repository);
|
||||
|
||||
$this->user->attachPermission(
|
||||
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
||||
);
|
||||
|
||||
$this->loginAs()
|
||||
->get(route('business.pages.show', [
|
||||
'section' => 'billing-transactions',
|
||||
'page' => 'platform-promotion-accounts',
|
||||
'tab' => 'jd',
|
||||
]))
|
||||
->assertOk()
|
||||
->assertSeeText('平台推广账户流水')
|
||||
->assertSeeText('京东京准通')
|
||||
->assertSeeText('测试店铺')
|
||||
->assertSeeText('导出 CSV')
|
||||
->assertSee(route('business.pages.show', [
|
||||
'section' => 'order-data',
|
||||
'page' => 'bill-offset',
|
||||
]), false);
|
||||
}
|
||||
|
||||
public function test_platform_promotion_export_keeps_the_complete_filtered_month(): void
|
||||
{
|
||||
$repository = Mockery::mock(PlatformPromotionAccountRepository::class);
|
||||
$repository->shouldReceive('latestMonth')->never();
|
||||
$repository->shouldReceive('dashboard')->once()->with([
|
||||
'month' => '2026-08',
|
||||
'shop_name' => '测试',
|
||||
'account' => 'account-01',
|
||||
], 5000)->andReturn($this->dashboardData());
|
||||
$this->app->instance(PlatformPromotionAccountRepository::class, $repository);
|
||||
|
||||
$this->user->attachPermission(
|
||||
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
||||
);
|
||||
|
||||
$response = $this->loginAs()->get(route('business.pages.export', [
|
||||
'section' => 'billing-transactions',
|
||||
'page' => 'platform-promotion-accounts',
|
||||
'tab' => 'jd',
|
||||
'month' => '2026-08',
|
||||
'shop_name' => '测试',
|
||||
'account' => 'account-01',
|
||||
]));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertHeader('Content-Type', 'text/csv; charset=UTF-8');
|
||||
$disposition = (string) $response->headers->get('Content-Disposition');
|
||||
$this->assertStringContainsString("filename*=utf-8''", $disposition);
|
||||
$this->assertStringContainsString('2026-08.csv', $disposition);
|
||||
$this->assertStringContainsString('测试店铺', $response->streamedContent());
|
||||
}
|
||||
|
||||
private function dashboardData(): array
|
||||
{
|
||||
return [
|
||||
'jd' => [[
|
||||
'shop_name' => '测试店铺',
|
||||
'account' => 'account-01',
|
||||
'show_date' => '2026-08-01',
|
||||
'trade_type_name' => '充值',
|
||||
'amount' => 100,
|
||||
'balance_amount' => 100,
|
||||
'remark' => '测试记录',
|
||||
]],
|
||||
'jdSummary' => ['income' => 100, 'expense' => 0, 'record_count' => 1],
|
||||
'dy' => [],
|
||||
'dySummary' => [],
|
||||
'dyStatus' => [],
|
||||
'dw' => [],
|
||||
'dwSummary' => [],
|
||||
'vipSales' => [],
|
||||
'vipTax' => [],
|
||||
'vipMarketing' => [],
|
||||
'vipSummary' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user