From 0bc6cf9f468eb2c9decdefb91145fc5262e1a817 Mon Sep 17 00:00:00 2001 From: yml2213 Date: Mon, 17 Aug 2026 20:30:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BE=AE=E4=BF=A1=E6=89=AB?= =?UTF-8?q?=E7=A0=81=E5=8C=BA=E6=9C=8D=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/listing/external_upload.go | 5 +++-- .../internal/modules/listing/service_test.go | 22 +++++++++++++++++++ ...0051_fix_external_wechat_server_region.sql | 21 ++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 backend/migrations/000051_fix_external_wechat_server_region.sql diff --git a/backend/internal/modules/listing/external_upload.go b/backend/internal/modules/listing/external_upload.go index a812db0..3c467cd 100644 --- a/backend/internal/modules/listing/external_upload.go +++ b/backend/internal/modules/listing/external_upload.go @@ -382,10 +382,11 @@ func buildExternalListingTitle(rank string, insurance string, hafCoinM float64, func serverRegionFromLoginMethod(value string) string { value = strings.TrimSpace(value) + normalized := strings.ToLower(value) switch { - case strings.Contains(value, "微信"): + case strings.Contains(value, "微信"), strings.HasPrefix(normalized, "vx"), strings.HasPrefix(normalized, "wx"): return "微信" - case strings.Contains(strings.ToLower(value), "steam"): + case strings.Contains(normalized, "steam"): return "Steam" default: return "QQ" diff --git a/backend/internal/modules/listing/service_test.go b/backend/internal/modules/listing/service_test.go index 19e8b01..c623461 100644 --- a/backend/internal/modules/listing/service_test.go +++ b/backend/internal/modules/listing/service_test.go @@ -566,6 +566,28 @@ func TestExternalAccountToCreateRequestMapsUploadFields(t *testing.T) { } } +func TestServerRegionFromLoginMethod(t *testing.T) { + tests := []struct { + name string + loginMethod string + want string + }{ + {name: "QQ账号密码", loginMethod: "QQ账号密码", want: "QQ"}, + {name: "微信扫码", loginMethod: "微信扫码", want: "微信"}, + {name: "VX扫码", loginMethod: "VX扫码", want: "微信"}, + {name: "小写WX扫码", loginMethod: "wx扫码", want: "微信"}, + {name: "Steam", loginMethod: "Steam令牌", want: "Steam"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := serverRegionFromLoginMethod(tt.loginMethod); got != tt.want { + t.Fatalf("serverRegionFromLoginMethod(%q) = %q, want %q", tt.loginMethod, got, tt.want) + } + }) + } +} + func TestExternalAccountToCreateRequestSeparatesPureCoinAndExtraItems(t *testing.T) { req := externalAccountToCreateRequest("客服1", 1772526103000, ExternalAccountData{ LoginMethod: "QQ账号密码", diff --git a/backend/migrations/000051_fix_external_wechat_server_region.sql b/backend/migrations/000051_fix_external_wechat_server_region.sql new file mode 100644 index 0000000..4745e27 --- /dev/null +++ b/backend/migrations/000051_fix_external_wechat_server_region.sql @@ -0,0 +1,21 @@ +-- +goose Up + +-- 修正历史外部上传中以 VX/WX 表示微信扫码、但被默认归类为 QQ 的账号。 +UPDATE game_accounts AS a +JOIN rental_listings AS l ON l.account_id = a.id +SET a.server_region = '微信' +WHERE a.server_region = 'QQ' + AND EXISTS ( + SELECT 1 + FROM listing_uploads AS lu + WHERE lu.listing_id = l.id + ) + AND ( + a.login_platform LIKE '%微信%' + OR LOWER(TRIM(a.login_platform)) LIKE 'vx%' + OR LOWER(TRIM(a.login_platform)) LIKE 'wx%' + ); + +-- +goose Down + +-- 此数据修复不可逆,避免将已修正的微信账号错误回退为 QQ。