diff --git a/app/Console/Commands/SyncStoreReceiptOrderMatches.php b/app/Console/Commands/SyncStoreReceiptOrderMatches.php index 80118e47..01402f1c 100644 --- a/app/Console/Commands/SyncStoreReceiptOrderMatches.php +++ b/app/Console/Commands/SyncStoreReceiptOrderMatches.php @@ -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, diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index 12de7c90..97193f11 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -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( - self::RECEIPT_PLATFORM_OPTIONS, - array_map('strval', $filterOptions['platforms'] ?? []), - ))); + $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') diff --git a/database/migrations/2026_10_20_000000_purge_jd_wallet_from_performance_details.php b/database/migrations/2026_10_20_000000_purge_jd_wallet_from_performance_details.php new file mode 100644 index 00000000..3aabac29 --- /dev/null +++ b/database/migrations/2026_10_20_000000_purge_jd_wallet_from_performance_details.php @@ -0,0 +1,33 @@ +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 + { + // 历史镜像可由同步命令重建;本迁移只做排除清理,不回填已删除的数据。 + } +};