perf: 优化退款待确认状态查询
This commit is contained in:
parent
e026132a1d
commit
ba306eb6dd
@ -497,6 +497,7 @@ return [
|
||||
'columns' => ['as_id', 'status', 'shop_status', 'confirm_date', 'modified', 'as_date'],
|
||||
'indexes' => [
|
||||
['as_id'],
|
||||
['status(20)', 'shop_status(20)', 'as_id'],
|
||||
],
|
||||
],
|
||||
'operations_replica.rpt.jst_shopInfo' => ['source_key' => 'operations_replica', 'schema' => 'rpt', 'object' => 'jst_shopInfo', 'target' => 'ops_jst_shop_info', 'keys' => ['Id'], 'watermark' => 'updateTime', 'indexes' => [['shop_id', 'Id']]],
|
||||
|
||||
@ -42,6 +42,7 @@ class NonJingxiRefundMirrorRepository
|
||||
self::SUPPLEMENT_DATASET => [['as_id'], ['as_date', 'as_id'], ['so_id'], ['outer_as_id'], ['status', 'shop_status', 'as_date', 'as_id']],
|
||||
self::SUPPLEMENT_ITEM_DATASET => [['as_id', 'asi_id']],
|
||||
self::SHOP_DATASET => [['shop_id', 'Id']],
|
||||
self::STATUS_DATASET => [['as_id'], ['status', 'shop_status', 'as_id']],
|
||||
'operations_replica.rpt.jst_Orders' => [['o_id', 'Id']],
|
||||
'operations_replica.rpt.jst_OrderItem' => [['o_id', 'Id']],
|
||||
];
|
||||
@ -480,8 +481,12 @@ class NonJingxiRefundMirrorRepository
|
||||
private function sourceQuery(array $filters, bool $supplement, bool $withItems = true): Builder
|
||||
{
|
||||
$table = $supplement ? 'ops_jst_qmcust_refunds' : 'ops_jst_return_refund_info';
|
||||
$query = $this->connection->table($table . ' as r');
|
||||
if ($supplement && $filters['order_no'] === '' && $this->supplementDateIndex !== null
|
||||
$statusAuthoritative = (bool) ($filters['_status_authoritative'] ?? false);
|
||||
$query = $statusAuthoritative
|
||||
? $this->connection->table('ops_jst_refund_status as current_refund')
|
||||
->join($table . ' as r', 'r.as_id', '=', 'current_refund.as_id')
|
||||
: $this->connection->table($table . ' as r');
|
||||
if (! $statusAuthoritative && $supplement && $filters['order_no'] === '' && $this->supplementDateIndex !== null
|
||||
&& $this->connection->getDriverName() === 'mysql') {
|
||||
// The legacy text payload makes a full table scan very expensive;
|
||||
// keep date windows on the verified shared-mirror lookup index.
|
||||
@ -543,10 +548,12 @@ class NonJingxiRefundMirrorRepository
|
||||
if (trim((string) ($filters['status'] ?? '')) !== ''
|
||||
|| trim((string) ($filters['shop_status'] ?? '')) !== '') {
|
||||
$statusAlias = 'current_refund';
|
||||
$query->leftJoin('ops_jst_refund_status as current_refund', 'current_refund.as_id', '=', 'r.as_id');
|
||||
if (! $statusAuthoritative) {
|
||||
$query->leftJoin('ops_jst_refund_status as current_refund', 'current_refund.as_id', '=', 'r.as_id');
|
||||
}
|
||||
}
|
||||
$this->applyPlatformFilter($query, $filters, $supplement);
|
||||
$this->applyFilters($query, $filters, $statusAlias);
|
||||
$this->applyFilters($query, $filters, $statusAlias, $statusAuthoritative);
|
||||
if ($filters['sku_id'] !== '') {
|
||||
if ($withItems) {
|
||||
$this->applySkuFilter($query, $filters['sku_id']);
|
||||
@ -728,7 +735,12 @@ class NonJingxiRefundMirrorRepository
|
||||
}
|
||||
|
||||
/** @param array{from:string,to:string,order_no:string,waybill_no:string,shop_name:string,sku_id:string,platform?:string} $filters */
|
||||
private function applyFilters(Builder $query, array $filters, ?string $statusAlias = null): void
|
||||
private function applyFilters(
|
||||
Builder $query,
|
||||
array $filters,
|
||||
?string $statusAlias = null,
|
||||
bool $statusAuthoritative = false,
|
||||
): void
|
||||
{
|
||||
$query->where('r.as_date', '>=', $filters['from'] . ' 00:00:00')
|
||||
->where('r.as_date', '<', Carbon::parse($filters['to'])->addDay()->format('Y-m-d 00:00:00'));
|
||||
@ -737,6 +749,8 @@ class NonJingxiRefundMirrorRepository
|
||||
if ($status !== '') {
|
||||
if ($statusAlias === null) {
|
||||
$query->where('r.status', $status);
|
||||
} elseif ($statusAuthoritative) {
|
||||
$query->where("{$statusAlias}.status", $status);
|
||||
} else {
|
||||
$query->whereRaw("COALESCE({$statusAlias}.status, r.status) = ?", [$status]);
|
||||
}
|
||||
@ -746,6 +760,8 @@ class NonJingxiRefundMirrorRepository
|
||||
if ($shopStatus !== '') {
|
||||
if ($statusAlias === null) {
|
||||
$query->where('r.shop_status', $shopStatus);
|
||||
} elseif ($statusAuthoritative) {
|
||||
$query->where("{$statusAlias}.shop_status", $shopStatus);
|
||||
} else {
|
||||
$query->whereRaw("COALESCE({$statusAlias}.shop_status, r.shop_status) = ?", [$shopStatus]);
|
||||
}
|
||||
@ -845,6 +861,7 @@ class NonJingxiRefundMirrorRepository
|
||||
return array_replace($filters, [
|
||||
'status' => self::PENDING_CONFIRMATION_STATUS,
|
||||
'shop_status' => self::PENDING_CONFIRMATION_ONLINE_STATUS,
|
||||
'_status_authoritative' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@ -587,6 +587,7 @@ class NonJingxiRefundMirrorRepositoryTest extends TestCase
|
||||
$table->string('as_id'); $table->string('status')->nullable(); $table->string('shop_status')->nullable();
|
||||
$table->dateTime('confirm_date')->nullable(); $table->dateTime('modified')->nullable(); $table->dateTime('as_date')->nullable();
|
||||
$table->index(['as_id']);
|
||||
$table->index(['status', 'shop_status', 'as_id']);
|
||||
});
|
||||
$schema->create('ops_jst_qmcust_refunds', function (Blueprint $table): void {
|
||||
$table->string('as_id'); $table->dateTime('as_date'); $table->string('outer_as_id')->nullable();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user