业绩明细排除京东网银钱包账户数据

This commit is contained in:
qiuxiang 2026-10-20 09:37:12 +08:00
parent 366dcc1da7
commit 9b6c3d2477
3 changed files with 78 additions and 8 deletions

View File

@ -136,6 +136,11 @@ class SyncStoreReceiptOrderMatches extends Command
'往来',
];
/** 这些收款账户不进入业绩明细,收、支都不取。 */
private const EXCLUDED_TARGET_SOURCES = [
'jd-wallet',
];
private const TARGET_TABLE = 'store_receipt_order_match_rows';
private const STATUS_MATCHED = '已匹配';
@ -237,6 +242,24 @@ class SyncStoreReceiptOrderMatches extends Command
$end = $start->copy()->addMonthNoOverflow();
$reportMonth = $start->toDateString();
if (in_array($platform, self::EXCLUDED_TARGET_SOURCES, true)) {
$deleted = 0;
if (! (bool) $this->option('dry-run')) {
$deleted = DB::connection($connection)->table(self::TARGET_TABLE)
->where('report_month', $reportMonth)
->where('platform', (string) $source['label'])
->delete();
}
$this->warn(sprintf(
'%s 已从业绩明细排除,%s 删除镜像行 %d 行(收、支均不取)。',
(string) $source['label'],
$month,
$deleted,
));
return self::SUCCESS;
}
$this->info(sprintf(
'账期 %s(%s ~ %s),收款账户 %s(%s)',
$month,

View File

@ -105,11 +105,15 @@ class Pages extends Controller
'拼多多',
'京东账单',
'京喜账单',
'京东网银钱包',
'抖音',
'得物',
];
/** 业绩明细不纳入的收款账户:京东网银钱包的收、支均不取。 */
private const RECEIPT_MATCH_EXCLUDED_PLATFORMS = [
'京东网银钱包',
];
/**
* 京东「直营补贴款」备注适用的京喜店铺(前缀)。
*
@ -1251,7 +1255,8 @@ class Pages extends Controller
// 镜像表本身就是「一个店铺 + 一个订单号 + 一个商品金额」的行口径,直接统计即可。
$base = static fn () => DB::connection((string) config('upstream_mirrors.connection', 'business_mirror'))
->table('store_receipt_order_match_rows')
->where('report_month', $month);
->where('report_month', $month)
->whereNotIn('platform', self::RECEIPT_MATCH_EXCLUDED_PLATFORMS);
// 计数与合计合并为一次全表扫描:重筛选项(如按备注筛选)下少一次全表重算。
$aggQuery = $base();
@ -1316,7 +1321,8 @@ class Pages extends Controller
now()->addHours(6),
static function () use ($connection, $month): array {
$maker = static fn () => DB::connection($connection)->table('store_receipt_order_match_rows')
->where('report_month', $month);
->where('report_month', $month)
->whereNotIn('platform', self::RECEIPT_MATCH_EXCLUDED_PLATFORMS);
return [
'platforms' => $maker()->whereNotNull('platform')->distinct()->orderBy('platform')->pluck('platform')->all(),
@ -1327,10 +1333,13 @@ class Pages extends Controller
);
$stats['selected_platforms'] = $platformFilter;
$stats['selected_stores'] = $storeFilter;
$stats['platform_options'] = array_values(array_unique(array_merge(
$stats['platform_options'] = array_values(array_diff(
array_unique(array_merge(
self::RECEIPT_PLATFORM_OPTIONS,
array_map('strval', $filterOptions['platforms'] ?? []),
)));
)),
self::RECEIPT_MATCH_EXCLUDED_PLATFORMS,
));
$stats['store_options'] = array_values(array_unique(array_merge(
$storeFilter,
array_map('strval', $filterOptions['stores'] ?? []),
@ -1482,7 +1491,8 @@ class Pages extends Controller
{
$query = DB::connection((string) config('upstream_mirrors.connection', 'business_mirror'))
->table('store_receipt_order_match_rows')
->where('report_month', $month);
->where('report_month', $month)
->whereNotIn('platform', self::RECEIPT_MATCH_EXCLUDED_PLATFORMS);
foreach ($filters as $key => $values) {
if ($key === 'difference_state' || $values === [] || $values === '') {
@ -1548,6 +1558,7 @@ class Pages extends Controller
{
$connection = (string) config('upstream_mirrors.connection', 'business_mirror');
$months = DB::connection($connection)->table('store_receipt_order_match_rows')
->whereNotIn('platform', self::RECEIPT_MATCH_EXCLUDED_PLATFORMS)
->select('report_month')
->distinct()
->orderByDesc('report_month')
@ -1809,6 +1820,7 @@ class Pages extends Controller
[, $month] = $this->receiptOrderMatchMonths();
$query = DB::connection($connection)->table('store_receipt_order_match_rows')
->whereNotIn('platform', self::RECEIPT_MATCH_EXCLUDED_PLATFORMS)
->when($month !== null, static fn ($builder) => $builder->where('report_month', $month));
$platforms = $this->receiptOrderMatchFilterValues($request->query('platform'));
@ -2208,6 +2220,7 @@ class Pages extends Controller
'financial-analysis-months-v1',
now()->addMinutes(10),
static fn () => DB::connection($connection)->table('store_receipt_order_match_rows')
->whereNotIn('platform', self::RECEIPT_MATCH_EXCLUDED_PLATFORMS)
->distinct()->orderByDesc('report_month')->pluck('report_month')
->map(static fn ($value): string => substr((string) $value, 0, 7))->all(),
);
@ -2234,6 +2247,7 @@ class Pages extends Controller
$rows = [];
$incomeRows = DB::connection($connection)->table('store_receipt_order_match_rows')
->where('report_month', $reportMonth)
->whereNotIn('platform', self::RECEIPT_MATCH_EXCLUDED_PLATFORMS)
->selectRaw('platform, store_name, SUM(COALESCE(income_amount, 0) + COALESCE(discount_amount, 0)'
. ' + COALESCE(offset_amount, 0) + COALESCE(refund_amount, 0)) as income')
->groupBy('platform', 'store_name')

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
/**
* 京东网银钱包账户不再进入业绩明细:清理历史镜像行,收、支均不展示。
*/
return new class extends Migration
{
private function connection(): string
{
return (string) config('upstream_mirrors.connection', 'business_mirror');
}
public function up(): void
{
if (! Schema::connection($this->connection())->hasTable('store_receipt_order_match_rows')) {
return;
}
DB::connection($this->connection())
->table('store_receipt_order_match_rows')
->where('platform', '京东网银钱包')
->delete();
}
public function down(): void
{
// 历史镜像可由同步命令重建;本迁移只做排除清理,不回填已删除的数据。
}
};