Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
b49332e5d9
@ -112,6 +112,10 @@ class JstOrderLabelImporter
|
||||
->distinct()
|
||||
->count('label');
|
||||
|
||||
// 导入会改变筛选选项,重新预热缓存,避免页面下次打开时做几秒的 distinct 扫描。
|
||||
app(JstOrderLabelOptions::class)->forget($companyId);
|
||||
app(JstOrderLabelOptions::class)->warm($companyId);
|
||||
|
||||
return [
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
|
||||
96
app/Business/JstOrderLabelOptions.php
Normal file
96
app/Business/JstOrderLabelOptions.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Business;
|
||||
|
||||
use App\Models\Business\JstOrderLabel;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/**
|
||||
* 聚水潭订单标签明细的筛选下拉选项。
|
||||
*
|
||||
* 表里有 200 万行以上,distinct 扫描一次要几秒;这里按公司缓存 24 小时,
|
||||
* 导入命令结束时会主动预热,避免每次打开页面都慢。
|
||||
*/
|
||||
class JstOrderLabelOptions
|
||||
{
|
||||
private const TTL_HOURS = 24;
|
||||
|
||||
private const TOTAL_TTL_MINUTES = 30;
|
||||
|
||||
private const LIMIT = 500;
|
||||
|
||||
/** @return list<string> */
|
||||
public function labels(int $companyId): array
|
||||
{
|
||||
return $this->remember($companyId, 'label');
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
public function shops(int $companyId): array
|
||||
{
|
||||
return $this->remember($companyId, 'shop_name');
|
||||
}
|
||||
|
||||
public function warm(int $companyId): void
|
||||
{
|
||||
$this->labels($companyId);
|
||||
$this->shops($companyId);
|
||||
$this->total($companyId);
|
||||
}
|
||||
|
||||
public function forget(int $companyId): void
|
||||
{
|
||||
Cache::forget($this->key($companyId, 'label'));
|
||||
Cache::forget($this->key($companyId, 'shop_name'));
|
||||
Cache::forget($this->totalKey($companyId));
|
||||
}
|
||||
|
||||
/** 无筛选时的总行数:233 万行上 COUNT(*) 要 2 秒,缓存后翻页不再重复统计。 */
|
||||
public function total(int $companyId): int
|
||||
{
|
||||
$key = $this->totalKey($companyId);
|
||||
$cached = Cache::get($key);
|
||||
if (is_numeric($cached)) {
|
||||
return (int) $cached;
|
||||
}
|
||||
|
||||
$count = (int) JstOrderLabel::query()->where('company_id', $companyId)->count();
|
||||
Cache::put($key, $count, now()->addMinutes(self::TOTAL_TTL_MINUTES));
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
private function remember(int $companyId, string $column): array
|
||||
{
|
||||
$key = $this->key($companyId, $column);
|
||||
$cached = Cache::get($key);
|
||||
if (is_array($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
|
||||
$values = JstOrderLabel::query()
|
||||
->where('company_id', $companyId)
|
||||
->whereNotNull($column)
|
||||
->where($column, '<>', '')
|
||||
->distinct()
|
||||
->orderBy($column)
|
||||
->limit(self::LIMIT)
|
||||
->pluck($column)
|
||||
->all();
|
||||
|
||||
Cache::put($key, $values, now()->addHours(self::TTL_HOURS));
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
private function key(int $companyId, string $column): string
|
||||
{
|
||||
return "jst-order-labels:options:v1:{$companyId}:{$column}";
|
||||
}
|
||||
|
||||
private function totalKey(int $companyId): string
|
||||
{
|
||||
return "jst-order-labels:total:v1:{$companyId}";
|
||||
}
|
||||
}
|
||||
@ -1330,11 +1330,19 @@ class Pages extends Controller
|
||||
$query = $this->jstOrderLabelQuery($filters);
|
||||
|
||||
$limit = min(max((int) setting('default.list_limit', 25), 10), 100);
|
||||
$records = $query
|
||||
->orderByDesc('ordered_at')
|
||||
->orderByDesc('id')
|
||||
->paginate($limit)
|
||||
->withQueryString();
|
||||
$page = max((int) $request->query('page', 1), 1);
|
||||
$hasFilters = collect($filters)->contains(static fn (string $value): bool => $value !== '');
|
||||
// 无筛选时复用缓存总数,避免每次翻页都在 233 万行上重跑 COUNT(*)。
|
||||
$total = $hasFilters
|
||||
? (clone $query)->count()
|
||||
: app(\App\Business\JstOrderLabelOptions::class)->total((int) company_id());
|
||||
$records = new \Illuminate\Pagination\LengthAwarePaginator(
|
||||
$query->orderByDesc('ordered_at')->orderByDesc('id')->forPage($page, $limit)->get(),
|
||||
$total,
|
||||
$limit,
|
||||
$page,
|
||||
['path' => $request->url(), 'query' => $request->query()],
|
||||
);
|
||||
|
||||
return [
|
||||
'view' => 'business.pages.billing-transactions.jst-order-labels',
|
||||
@ -1342,8 +1350,8 @@ class Pages extends Controller
|
||||
'filters' => $filters,
|
||||
'totalRows' => $records->total(),
|
||||
'filterOptions' => [
|
||||
'shops' => $this->jstOrderLabelOptions('shop_name', 500),
|
||||
'labels' => $this->jstOrderLabelOptions('label', 500),
|
||||
'shops' => app(\App\Business\JstOrderLabelOptions::class)->shops((int) company_id()),
|
||||
'labels' => app(\App\Business\JstOrderLabelOptions::class)->labels((int) company_id()),
|
||||
],
|
||||
];
|
||||
}
|
||||
@ -1384,20 +1392,6 @@ class Pages extends Controller
|
||||
return $query;
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
private function jstOrderLabelOptions(string $column, int $limit): array
|
||||
{
|
||||
return \App\Models\Business\JstOrderLabel::query()
|
||||
->where('company_id', company_id())
|
||||
->whereNotNull($column)
|
||||
->where($column, '<>', '')
|
||||
->distinct()
|
||||
->orderBy($column)
|
||||
->limit($limit)
|
||||
->pluck($column)
|
||||
->all();
|
||||
}
|
||||
|
||||
/** 账单流水数据 › 聚水潭订单标签明细导出(按当前筛选,全量) */
|
||||
public function exportJstOrderLabels(Request $request): StreamedResponse
|
||||
{
|
||||
|
||||
@ -426,8 +426,6 @@ $navigation = [
|
||||
'icon' => 'receipt_long',
|
||||
'pages' => [
|
||||
['slug' => 'bank-transactions', 'title' => '银行账户流水'],
|
||||
['slug' => 'planting-details', 'title' => '种菜明细表'],
|
||||
['slug' => 'jst-order-labels', 'title' => '聚水潭订单标签明细'],
|
||||
[
|
||||
'slug' => 'store-receiving-bills',
|
||||
'title' => '店铺收款账户账单',
|
||||
@ -473,6 +471,15 @@ $navigation = [
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'slug' => 'planting-data',
|
||||
'title' => '种菜数据汇总',
|
||||
'icon' => 'grass',
|
||||
'pages' => [
|
||||
['slug' => 'planting-details', 'title' => '种菜明细表'],
|
||||
['slug' => 'jst-order-labels', 'title' => '聚水潭订单标签明细'],
|
||||
],
|
||||
],
|
||||
[
|
||||
'slug' => 'account-balance-data',
|
||||
'title' => '账单余额数据',
|
||||
@ -839,6 +846,7 @@ $requestedSectionOrder = [
|
||||
'order-data',
|
||||
'refunds',
|
||||
'billing-transactions',
|
||||
'planting-data',
|
||||
'account-balance-data',
|
||||
'product-inventory',
|
||||
];
|
||||
|
||||
@ -106,7 +106,7 @@
|
||||
<span class="material-icons-outlined" aria-hidden="true">restart_alt</span>
|
||||
<span>重置</span>
|
||||
</a>
|
||||
<a class="upstream-data-button" href="{{ route('business.billing-transactions.jst-order-labels.export', array_merge(['company_id' => company_id()], request()->query())) }}" title="按当前筛选导出全部明细">
|
||||
<a class="upstream-data-button" href="{{ route('business.planting-data.jst-order-labels.export', array_merge(['company_id' => company_id()], request()->query())) }}" title="按当前筛选导出全部明细">
|
||||
<span class="material-icons-outlined" aria-hidden="true">download</span>
|
||||
<span>导出</span>
|
||||
</a>
|
||||
|
||||
@ -189,7 +189,7 @@
|
||||
<span class="material-icons-outlined" aria-hidden="true">restart_alt</span>
|
||||
<span>重置</span>
|
||||
</a>
|
||||
<a class="upstream-data-button" href="{{ route('business.billing-transactions.planting-details.export', array_merge(['company_id' => company_id()], request()->query())) }}" title="按当前筛选导出全部明细">
|
||||
<a class="upstream-data-button" href="{{ route('business.planting-data.planting-details.export', array_merge(['company_id' => company_id()], request()->query())) }}" title="按当前筛选导出全部明细">
|
||||
<span class="material-icons-outlined" aria-hidden="true">download</span>
|
||||
<span>导出</span>
|
||||
</a>
|
||||
|
||||
@ -172,13 +172,13 @@ Route::get('workspace/product-inventory/monthly-weighted-average-price/export',
|
||||
->middleware('business.page:product-inventory,monthly-weighted-average-price')
|
||||
->name('business.product-inventory.monthly-weighted-average-price.export');
|
||||
|
||||
Route::get('workspace/billing-transactions/planting-details/export', 'Business\Pages@exportPlantingDetails')
|
||||
->middleware('business.page:billing-transactions,planting-details')
|
||||
->name('business.billing-transactions.planting-details.export');
|
||||
Route::get('workspace/planting-data/planting-details/export', 'Business\Pages@exportPlantingDetails')
|
||||
->middleware('business.page:planting-data,planting-details')
|
||||
->name('business.planting-data.planting-details.export');
|
||||
|
||||
Route::get('workspace/billing-transactions/jst-order-labels/export', 'Business\Pages@exportJstOrderLabels')
|
||||
->middleware('business.page:billing-transactions,jst-order-labels')
|
||||
->name('business.billing-transactions.jst-order-labels.export');
|
||||
Route::get('workspace/planting-data/jst-order-labels/export', 'Business\Pages@exportJstOrderLabels')
|
||||
->middleware('business.page:planting-data,jst-order-labels')
|
||||
->name('business.planting-data.jst-order-labels.export');
|
||||
|
||||
Route::prefix('workspace/product-inventory/inventory-report/warehouse-mappings')
|
||||
->middleware('business.page:product-inventory,inventory-report')
|
||||
|
||||
@ -76,7 +76,7 @@ class JstOrderLabelsPageTest extends FeatureTestCase
|
||||
app(JstOrderLabelImporter::class)->import('2026-09-01', '2026-09-15', $this->company->id, true);
|
||||
|
||||
$page = $this->loginAs()->get(route('business.pages.show', [
|
||||
'section' => 'billing-transactions',
|
||||
'section' => 'planting-data',
|
||||
'page' => 'jst-order-labels',
|
||||
]));
|
||||
|
||||
@ -89,7 +89,7 @@ class JstOrderLabelsPageTest extends FeatureTestCase
|
||||
->assertSee('data-jst-labels-clear="jst-label-date-to"', false);
|
||||
|
||||
$filtered = $this->loginAs()->get(route('business.pages.show', [
|
||||
'section' => 'billing-transactions',
|
||||
'section' => 'planting-data',
|
||||
'page' => 'jst-order-labels',
|
||||
'label' => '京喜',
|
||||
]));
|
||||
@ -97,7 +97,7 @@ class JstOrderLabelsPageTest extends FeatureTestCase
|
||||
->assertSee('3608400015164657')
|
||||
->assertDontSee('260901-391328633273048');
|
||||
|
||||
$export = $this->loginAs()->get(route('business.billing-transactions.jst-order-labels.export', [
|
||||
$export = $this->loginAs()->get(route('business.planting-data.jst-order-labels.export', [
|
||||
'label' => '京喜',
|
||||
]));
|
||||
$export->assertOk()->assertDownload();
|
||||
|
||||
@ -42,6 +42,12 @@ class MarketingAccountBillsTabsTest extends FeatureTestCase
|
||||
'marketing-account-bills',
|
||||
'deposit-account-bills',
|
||||
], $flowPages);
|
||||
// 种菜明细表 / 聚水潭订单标签明细已移到并列的「种菜数据汇总」下
|
||||
$plantingPages = collect($navigation->firstWhere('slug', 'planting-data')['pages'])
|
||||
->pluck('slug')->all();
|
||||
$this->assertSame(['planting-details', 'jst-order-labels'], $plantingPages);
|
||||
$this->assertNotContains('planting-details', $flowPages);
|
||||
$this->assertNotContains('jst-order-labels', $flowPages);
|
||||
$this->assertSame([
|
||||
'bank-balance',
|
||||
'store-receiving-balance',
|
||||
|
||||
@ -39,7 +39,7 @@ class PlantingDetailsPageTest extends FeatureTestCase
|
||||
$this->assertSame('2026-07-15', $result['date_max']);
|
||||
|
||||
$page = $this->loginAs()->get(route('business.pages.show', [
|
||||
'section' => 'billing-transactions',
|
||||
'section' => 'planting-data',
|
||||
'page' => 'planting-details',
|
||||
]));
|
||||
|
||||
@ -60,7 +60,7 @@ class PlantingDetailsPageTest extends FeatureTestCase
|
||||
|
||||
// 按店铺 + 日期筛选
|
||||
$filtered = $this->loginAs()->get(route('business.pages.show', [
|
||||
'section' => 'billing-transactions',
|
||||
'section' => 'planting-data',
|
||||
'page' => 'planting-details',
|
||||
'store' => '拼多多-亿家达实木家具官方旗舰店',
|
||||
'date_from' => '2026-07-01',
|
||||
@ -71,7 +71,7 @@ class PlantingDetailsPageTest extends FeatureTestCase
|
||||
->assertDontSee('3306215028042824171');
|
||||
|
||||
// 导出:表头 + 行数与页面筛选一致
|
||||
$export = $this->loginAs()->get(route('business.billing-transactions.planting-details.export', [
|
||||
$export = $this->loginAs()->get(route('business.planting-data.planting-details.export', [
|
||||
'store' => '拼多多-亿家达实木家具官方旗舰店',
|
||||
]));
|
||||
|
||||
|
||||
@ -207,10 +207,11 @@ class NavigationTest extends FeatureTestCase
|
||||
'order-data',
|
||||
'refunds',
|
||||
'billing-transactions',
|
||||
'planting-data',
|
||||
'account-balance-data',
|
||||
'product-inventory',
|
||||
],
|
||||
array_slice($slugs, $invoiceIndex, 7)
|
||||
array_slice($slugs, $invoiceIndex, 8)
|
||||
);
|
||||
$this->assertSame(
|
||||
[
|
||||
@ -219,10 +220,11 @@ class NavigationTest extends FeatureTestCase
|
||||
'订单数据',
|
||||
'退款数据',
|
||||
'账单流水数据',
|
||||
'种菜数据汇总',
|
||||
'账单余额数据',
|
||||
'商品价格管理',
|
||||
],
|
||||
array_column(array_slice($navigation, $invoiceIndex, 7), 'title')
|
||||
array_column(array_slice($navigation, $invoiceIndex, 8), 'title')
|
||||
);
|
||||
$this->assertGreaterThan($invoiceIndex, $orderIndex);
|
||||
$this->assertGreaterThan($orderIndex, $refundIndex);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user