feat(order): 展示上传联系电话并隔离用户端快照
This commit is contained in:
@@ -145,6 +145,7 @@ func applySellerListingPrice(item *ListingDTO) {
|
|||||||
if item.AssetSummary == nil {
|
if item.AssetSummary == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
delete(item.AssetSummary, "import_meta")
|
||||||
breakdown, ok := item.AssetSummary["price_breakdown"].(map[string]any)
|
breakdown, ok := item.AssetSummary["price_breakdown"].(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -291,6 +291,10 @@ func TestApplySellerListingPriceUsesSellerTotalPrice(t *testing.T) {
|
|||||||
item := &ListingDTO{
|
item := &ListingDTO{
|
||||||
PriceCent: 23800,
|
PriceCent: 23800,
|
||||||
AssetSummary: map[string]any{
|
AssetSummary: map[string]any{
|
||||||
|
"import_meta": map[string]any{
|
||||||
|
"uploader_name": "客服1",
|
||||||
|
"contact_phone": "15196354603",
|
||||||
|
},
|
||||||
"price_breakdown": map[string]any{
|
"price_breakdown": map[string]any{
|
||||||
"seller_total_price": 200,
|
"seller_total_price": 200,
|
||||||
},
|
},
|
||||||
@@ -302,6 +306,9 @@ func TestApplySellerListingPriceUsesSellerTotalPrice(t *testing.T) {
|
|||||||
if item.PriceCent != 20000 {
|
if item.PriceCent != 20000 {
|
||||||
t.Fatalf("expected seller price 20000, got %d", item.PriceCent)
|
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) {
|
func TestApplySellerListingPriceKeepsFallbackPrice(t *testing.T) {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ type OrderDTO struct {
|
|||||||
RenterID uint64 `json:"renter_id"`
|
RenterID uint64 `json:"renter_id"`
|
||||||
OwnerPhone string `json:"owner_phone,omitempty"`
|
OwnerPhone string `json:"owner_phone,omitempty"`
|
||||||
RenterPhone string `json:"renter_phone,omitempty"`
|
RenterPhone string `json:"renter_phone,omitempty"`
|
||||||
|
UploadContactPhone string `json:"upload_contact_phone,omitempty"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
ServerRegion string `json:"server_region"`
|
ServerRegion string `json:"server_region"`
|
||||||
LoginPlatform string `json:"login_platform"`
|
LoginPlatform string `json:"login_platform"`
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package order
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"hfb_sys/backend/internal/model"
|
"hfb_sys/backend/internal/model"
|
||||||
@@ -78,6 +79,7 @@ func (row orderRow) toAdminDTO() OrderDTO {
|
|||||||
RenterID: row.RenterID,
|
RenterID: row.RenterID,
|
||||||
OwnerPhone: row.OwnerPhone,
|
OwnerPhone: row.OwnerPhone,
|
||||||
RenterPhone: row.RenterPhone,
|
RenterPhone: row.RenterPhone,
|
||||||
|
UploadContactPhone: uploadContactPhoneFromSnapshot(row.AccountSnapshot),
|
||||||
Title: row.Title,
|
Title: row.Title,
|
||||||
ServerRegion: row.ServerRegion,
|
ServerRegion: row.ServerRegion,
|
||||||
LoginPlatform: row.LoginPlatform,
|
LoginPlatform: row.LoginPlatform,
|
||||||
@@ -173,6 +175,7 @@ func (row orderRow) toDTOForUser(userID uint64) OrderDTO {
|
|||||||
dto.DepositHeldAt = nil
|
dto.DepositHeldAt = nil
|
||||||
dto.DepositHoldReleasedAt = nil
|
dto.DepositHoldReleasedAt = nil
|
||||||
dto.ManagedAdminID = nil
|
dto.ManagedAdminID = nil
|
||||||
|
dto.UploadContactPhone = ""
|
||||||
dto.OfflineSettlementStatus = ""
|
dto.OfflineSettlementStatus = ""
|
||||||
dto.OfflineSettlementAmountCent = 0
|
dto.OfflineSettlementAmountCent = 0
|
||||||
dto.OfflineSettlementRemark = ""
|
dto.OfflineSettlementRemark = ""
|
||||||
@@ -610,6 +613,9 @@ func sanitizeOrderSnapshot(snapshot *datatypes.JSON, role string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete(summary, "price_breakdown")
|
delete(summary, "price_breakdown")
|
||||||
|
// import_meta 含外部上传人员与联系电话,仅允许后台订单详情读取。
|
||||||
|
delete(summary, "import_meta")
|
||||||
|
delete(payload, "import_meta")
|
||||||
payload["asset_summary"] = summary
|
payload["asset_summary"] = summary
|
||||||
raw, err := json.Marshal(payload)
|
raw, err := json.Marshal(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -618,6 +624,38 @@ func sanitizeOrderSnapshot(snapshot *datatypes.JSON, role string) {
|
|||||||
*snapshot = datatypes.JSON(raw)
|
*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) {
|
func marshalStringList(items []string) (datatypes.JSON, error) {
|
||||||
if items == nil {
|
if items == nil {
|
||||||
items = []string{}
|
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) {
|
func TestUserOrderListItemDoesNotSerializeDetailFields(t *testing.T) {
|
||||||
row := orderRow{
|
row := orderRow{
|
||||||
RentalOrder: model.RentalOrder{
|
RentalOrder: model.RentalOrder{
|
||||||
|
|||||||
@@ -1206,6 +1206,10 @@ function formatRatioNumber(value: number) {
|
|||||||
<dt>号主</dt>
|
<dt>号主</dt>
|
||||||
<dd>{{ sellerDisplay(order) }}</dd>
|
<dd>{{ sellerDisplay(order) }}</dd>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="order.upload_contact_phone">
|
||||||
|
<dt>上传联系电话</dt>
|
||||||
|
<dd>{{ order.upload_contact_phone }}</dd>
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<dt>创建时间</dt>
|
<dt>创建时间</dt>
|
||||||
<dd>{{ formatDateTime(order.created_at) }}</dd>
|
<dd>{{ formatDateTime(order.created_at) }}</dd>
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export interface Order {
|
|||||||
renter_id: number
|
renter_id: number
|
||||||
owner_phone?: string
|
owner_phone?: string
|
||||||
renter_phone?: string
|
renter_phone?: string
|
||||||
|
upload_contact_phone?: string
|
||||||
title: string
|
title: string
|
||||||
server_region: string
|
server_region: string
|
||||||
login_platform: string
|
login_platform: string
|
||||||
|
|||||||
Reference in New Issue
Block a user