feat: load order profit page from shared mirror
This commit is contained in:
parent
5676117b14
commit
2448e4e4c7
@ -98,7 +98,11 @@ class OrderProfitRepository
|
||||
return ['rows' => [], 'has_more' => false];
|
||||
}
|
||||
$query = $this->connection()->table(self::TABLE)->whereIn('_mirror_key', $ids);
|
||||
$query = $this->filtered($query, array_replace($filters, ['order_no' => '']), $columns);
|
||||
$query = $this->filtered(
|
||||
$query,
|
||||
array_replace($filters, ['order_no' => '', 'from' => '', 'to' => '']),
|
||||
$columns,
|
||||
);
|
||||
} else {
|
||||
$query = $this->filtered($this->connection()->table(self::TABLE), $filters, $columns);
|
||||
}
|
||||
|
||||
@ -72,13 +72,26 @@ class OrderProfitPageData
|
||||
}
|
||||
}
|
||||
|
||||
$orderNo = $this->batchText($input['order_no'] ?? null);
|
||||
$sku = $this->batchText($input['sku_id'] ?? null);
|
||||
$hasOtherFilters = $orderNo !== '' || $sku !== '' || $shops !== [];
|
||||
$datesWereSubmitted = array_key_exists('from', $input) || array_key_exists('to', $input);
|
||||
$reset = ! empty($input['reset']);
|
||||
$from = $this->date($input['from'] ?? null);
|
||||
$to = $this->date($input['to'] ?? null);
|
||||
|
||||
if (! $datesWereSubmitted && ! $reset && ! $hasOtherFilters) {
|
||||
$from = now()->subDays(6)->toDateString();
|
||||
$to = now()->toDateString();
|
||||
}
|
||||
|
||||
return [
|
||||
'from' => $this->date($input['from'] ?? null),
|
||||
'to' => $this->date($input['to'] ?? null),
|
||||
'order_no' => $this->batchText($input['order_no'] ?? null),
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
'order_no' => $orderNo,
|
||||
'shop_name' => implode("\n", array_keys($shops)),
|
||||
'shop_names' => array_keys($shops),
|
||||
'sku_id' => $this->batchText($input['sku_id'] ?? null),
|
||||
'sku_id' => $sku,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -94,7 +94,7 @@
|
||||
<span class="material-icons-outlined" aria-hidden="true">search</span>
|
||||
<span>查询</span>
|
||||
</button>
|
||||
<a href="{{ route('business.pages.show', ['section' => 'order-profit']) }}" class="upstream-data-button">
|
||||
<a href="{{ route('business.pages.show', ['section' => 'order-profit', 'reset' => 1]) }}" class="upstream-data-button">
|
||||
<span class="material-icons-outlined" aria-hidden="true">refresh</span>
|
||||
<span>重置</span>
|
||||
</a>
|
||||
|
||||
@ -8,6 +8,49 @@ use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class OrderProfitPageTest extends FeatureTestCase
|
||||
{
|
||||
public function test_order_profit_page_loads_recent_rows_without_filters(): void
|
||||
{
|
||||
$repository = Mockery::mock(OrderProfitRepository::class);
|
||||
$repository->shouldReceive('status')->once()->andReturn([
|
||||
'ready' => true,
|
||||
'initial_completed_at' => '2026-10-01 00:00:00',
|
||||
'last_succeeded_at' => '2026-10-30 10:00:00',
|
||||
'last_error_code' => null,
|
||||
]);
|
||||
$repository->shouldReceive('shopNames')->once()->andReturn([]);
|
||||
$repository->shouldReceive('paginate')->once()
|
||||
->with(
|
||||
Mockery::on(static fn (array $filters): bool => $filters['from'] === now()->subDays(6)->toDateString()
|
||||
&& $filters['to'] === now()->toDateString()),
|
||||
1,
|
||||
25,
|
||||
)
|
||||
->andReturn([
|
||||
'has_more' => false,
|
||||
'rows' => [[
|
||||
'shop_name' => '最近订单店铺',
|
||||
'online_order_no' => 'RECENT-ORDER-1',
|
||||
'internal_order_no' => '9001',
|
||||
'cost_amount' => 12.0,
|
||||
'refund_amount' => 0.0,
|
||||
'platform_subsidy' => 0.0,
|
||||
'product_quantity' => 1.0,
|
||||
'product_amount' => 20.0,
|
||||
'items' => [],
|
||||
]],
|
||||
]);
|
||||
$this->app->instance(OrderProfitRepository::class, $repository);
|
||||
|
||||
$this->loginAs()->get(route('business.pages.show', [
|
||||
'section' => 'order-profit',
|
||||
'page' => 'order-profit-list',
|
||||
]))
|
||||
->assertOk()
|
||||
->assertSeeText('RECENT-ORDER-1')
|
||||
->assertSeeText('最近订单店铺')
|
||||
->assertSeeText('12.00');
|
||||
}
|
||||
|
||||
public function test_order_profit_page_renders_aggregated_order_and_source_details(): void
|
||||
{
|
||||
$repository = Mockery::mock(OrderProfitRepository::class);
|
||||
|
||||
@ -147,8 +147,8 @@ class OrderProfitRepositoryTest extends TestCase
|
||||
{
|
||||
$repository = app(OrderProfitRepository::class);
|
||||
$result = $repository->paginate([
|
||||
'from' => '',
|
||||
'to' => '',
|
||||
'from' => '2026-10-01',
|
||||
'to' => '2026-10-31',
|
||||
'order_no' => '26092142570188',
|
||||
'shop_name' => '',
|
||||
'sku_id' => '',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user