diff --git a/backend/internal/modules/listing/presenter.go b/backend/internal/modules/listing/presenter.go index b7e7570e..6bbe996b 100644 --- a/backend/internal/modules/listing/presenter.go +++ b/backend/internal/modules/listing/presenter.go @@ -145,6 +145,7 @@ func applySellerListingPrice(item *ListingDTO) { if item.AssetSummary == nil { return } + delete(item.AssetSummary, "import_meta") breakdown, ok := item.AssetSummary["price_breakdown"].(map[string]any) if !ok { return diff --git a/backend/internal/modules/listing/service_test.go b/backend/internal/modules/listing/service_test.go index 926c3d15..514d504e 100644 --- a/backend/internal/modules/listing/service_test.go +++ b/backend/internal/modules/listing/service_test.go @@ -291,6 +291,10 @@ func TestApplySellerListingPriceUsesSellerTotalPrice(t *testing.T) { item := &ListingDTO{ PriceCent: 23800, AssetSummary: map[string]any{ + "import_meta": map[string]any{ + "uploader_name": "客服1", + "contact_phone": "15196354603", + }, "price_breakdown": map[string]any{ "seller_total_price": 200, }, @@ -302,6 +306,9 @@ func TestApplySellerListingPriceUsesSellerTotalPrice(t *testing.T) { if item.PriceCent != 20000 { t.Fatalf("expected seller price 20000, got %d", item.PriceCent) } + if _, ok := item.AssetSummary["import_meta"]; ok { + t.Fatal("expected import_meta hidden from seller listing") + } } func TestApplySellerListingPriceKeepsFallbackPrice(t *testing.T) { diff --git a/backend/internal/modules/order/dto.go b/backend/internal/modules/order/dto.go index 2b4eb676..87f35bcd 100644 --- a/backend/internal/modules/order/dto.go +++ b/backend/internal/modules/order/dto.go @@ -22,6 +22,7 @@ type OrderDTO struct { RenterID uint64 `json:"renter_id"` OwnerPhone string `json:"owner_phone,omitempty"` RenterPhone string `json:"renter_phone,omitempty"` + UploadContactPhone string `json:"upload_contact_phone,omitempty"` Title string `json:"title"` ServerRegion string `json:"server_region"` LoginPlatform string `json:"login_platform"` diff --git a/backend/internal/modules/order/presenter.go b/backend/internal/modules/order/presenter.go index 30395431..082eeacb 100644 --- a/backend/internal/modules/order/presenter.go +++ b/backend/internal/modules/order/presenter.go @@ -2,6 +2,7 @@ package order import ( "encoding/json" + "strings" "time" "hfb_sys/backend/internal/model" @@ -78,6 +79,7 @@ func (row orderRow) toAdminDTO() OrderDTO { RenterID: row.RenterID, OwnerPhone: row.OwnerPhone, RenterPhone: row.RenterPhone, + UploadContactPhone: uploadContactPhoneFromSnapshot(row.AccountSnapshot), Title: row.Title, ServerRegion: row.ServerRegion, LoginPlatform: row.LoginPlatform, @@ -173,6 +175,7 @@ func (row orderRow) toDTOForUser(userID uint64) OrderDTO { dto.DepositHeldAt = nil dto.DepositHoldReleasedAt = nil dto.ManagedAdminID = nil + dto.UploadContactPhone = "" dto.OfflineSettlementStatus = "" dto.OfflineSettlementAmountCent = 0 dto.OfflineSettlementRemark = "" @@ -610,6 +613,9 @@ func sanitizeOrderSnapshot(snapshot *datatypes.JSON, role string) { } } delete(summary, "price_breakdown") + // import_meta 含外部上传人员与联系电话,仅允许后台订单详情读取。 + delete(summary, "import_meta") + delete(payload, "import_meta") payload["asset_summary"] = summary raw, err := json.Marshal(payload) if err != nil { @@ -618,6 +624,38 @@ func sanitizeOrderSnapshot(snapshot *datatypes.JSON, role string) { *snapshot = datatypes.JSON(raw) } +func uploadContactPhoneFromSnapshot(snapshot datatypes.JSON) string { + if len(snapshot) == 0 { + return "" + } + var payload map[string]json.RawMessage + if err := json.Unmarshal(snapshot, &payload); err != nil { + return "" + } + rawSummary, ok := payload["asset_summary"] + if !ok || len(rawSummary) == 0 { + return "" + } + var summary map[string]json.RawMessage + if err := json.Unmarshal(rawSummary, &summary); err != nil { + var summaryText string + if textErr := json.Unmarshal(rawSummary, &summaryText); textErr != nil || + json.Unmarshal([]byte(summaryText), &summary) != nil { + return "" + } + } + var importMeta map[string]any + if err := json.Unmarshal(summary["import_meta"], &importMeta); err != nil { + return "" + } + for _, key := range []string{"contact_phone", "contactPhone"} { + if value, ok := importMeta[key].(string); ok { + return strings.TrimSpace(value) + } + } + return "" +} + func marshalStringList(items []string) (datatypes.JSON, error) { if items == nil { items = []string{} diff --git a/backend/internal/modules/order/presenter_test.go b/backend/internal/modules/order/presenter_test.go index ee0702de..cb1d328b 100644 --- a/backend/internal/modules/order/presenter_test.go +++ b/backend/internal/modules/order/presenter_test.go @@ -44,6 +44,70 @@ func TestOrderDTOForUserHidesDepositHoldFields(t *testing.T) { } } +func TestAdminOrderDTOIncludesUploadContactPhone(t *testing.T) { + row := orderRow{ + RentalOrder: model.RentalOrder{ + ID: 1, + AccountSnapshot: datatypes.JSON([]byte(`{ + "asset_summary":{ + "import_meta":{ + "uploader_name":"客服1", + "contact_phone":"15196354603" + } + } + }`)), + }, + } + + dto := row.toAdminDTO() + if dto.UploadContactPhone != "15196354603" { + t.Fatalf("upload contact phone = %q", dto.UploadContactPhone) + } + raw, err := json.Marshal(dto) + if err != nil { + t.Fatalf("Marshal() error = %v", err) + } + if !strings.Contains(string(raw), `"upload_contact_phone":"15196354603"`) { + t.Fatalf("admin response missing upload contact phone: %s", raw) + } +} + +func TestUserOrderDTOHidesUploadContactPhone(t *testing.T) { + row := orderRow{ + RentalOrder: model.RentalOrder{ + ID: 1, + OwnerID: 10, + RenterID: 20, + AccountSnapshot: datatypes.JSON([]byte(`{ + "asset_summary":{ + "haf_coin_amount":108000000, + "import_meta":{ + "uploader_name":"客服1", + "contact_phone":"15196354603" + } + } + }`)), + }, + } + + for _, userID := range []uint64{row.OwnerID, row.RenterID} { + dto := row.toDTOForUser(userID) + if dto.UploadContactPhone != "" { + t.Fatalf("user %d upload contact phone = %q, want empty", userID, dto.UploadContactPhone) + } + raw, err := json.Marshal(dto) + if err != nil { + t.Fatalf("Marshal() error = %v", err) + } + text := string(raw) + for _, forbidden := range []string{"15196354603", "import_meta", "upload_contact_phone"} { + if strings.Contains(text, forbidden) { + t.Fatalf("user %d response contains forbidden %q: %s", userID, forbidden, text) + } + } + } +} + func TestUserOrderListItemDoesNotSerializeDetailFields(t *testing.T) { row := orderRow{ RentalOrder: model.RentalOrder{ diff --git a/frontend/src/features/admin/views/AdminOrderDetailView.vue b/frontend/src/features/admin/views/AdminOrderDetailView.vue index 58ed1972..98bb2f70 100644 --- a/frontend/src/features/admin/views/AdminOrderDetailView.vue +++ b/frontend/src/features/admin/views/AdminOrderDetailView.vue @@ -1206,6 +1206,10 @@ function formatRatioNumber(value: number) {