feat(order): 展示上传联系电话并隔离用户端快照
This commit is contained in:
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user