feat(order): 展示上传联系电话并隔离用户端快照
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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{}
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -1206,6 +1206,10 @@ function formatRatioNumber(value: number) {
|
||||
<dt>号主</dt>
|
||||
<dd>{{ sellerDisplay(order) }}</dd>
|
||||
</div>
|
||||
<div v-if="order.upload_contact_phone">
|
||||
<dt>上传联系电话</dt>
|
||||
<dd>{{ order.upload_contact_phone }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>创建时间</dt>
|
||||
<dd>{{ formatDateTime(order.created_at) }}</dd>
|
||||
|
||||
@@ -19,6 +19,7 @@ export interface Order {
|
||||
renter_id: number
|
||||
owner_phone?: string
|
||||
renter_phone?: string
|
||||
upload_contact_phone?: string
|
||||
title: string
|
||||
server_region: string
|
||||
login_platform: string
|
||||
|
||||
Reference in New Issue
Block a user