完善配送订单联系人明文展示

This commit is contained in:
czl231
2026-08-29 20:55:02 +08:00
parent 44014a0e4f
commit 965e12cbcc
6 changed files with 89 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
// 功能描述:实现配送点范围内的合同、合同气瓶和配送订单接口。
// 版本v1.3.0。
// 版本v1.4.0。
package delivery
import (
@@ -387,7 +387,30 @@ func ListOrder(ctx *gin.Context) {
infra.Response.Error(ctx, err)
return
}
infra.Response.Success(ctx, gin.H{"total": total, "list": response})
infra.Response.Success(ctx, gin.H{"total": total, "list": restoreDeliveryOrderListContacts(response, orders)})
}
// restoreDeliveryOrderListContacts 为当前配送点管理员恢复本点订单联系人快照明文。
// 调用前订单必须已经按当前配送点完成范围过滤,避免跨配送点暴露联系人信息。
func restoreDeliveryOrderListContacts(response any, orders []models.GasorderBasic) any {
list, ok := response.([]any)
if !ok {
return response
}
for index, item := range list {
if index >= len(orders) {
break
}
record, ok := item.(map[string]any)
if !ok {
continue
}
record["contact_name"] = orders[index].ContactName
record["contact_phone"] = orders[index].ContactPhone
delete(record, "contact_name_masked")
delete(record, "contact_phone_masked")
}
return response
}
func GetOrder(ctx *gin.Context) {

View File

@@ -0,0 +1,28 @@
// 功能描述:验证配送点订单列表仅恢复当前分页订单的联系人明文。
// 版本v1.0.0。
package delivery
import (
"testing"
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
)
// TestRestoreDeliveryOrderListContacts 验证明文字段覆盖脱敏辅助字段且保持分页顺序。
func TestRestoreDeliveryOrderListContacts(t *testing.T) {
response := []any{
map[string]any{"identity": "order-1", "contact_name_masked": "张*", "contact_phone_masked": "138****8000"},
}
orders := []models.GasorderBasic{{ContactName: "张三", ContactPhone: "13800138000"}}
restored := restoreDeliveryOrderListContacts(response, orders).([]any)
record := restored[0].(map[string]any)
if record["contact_name"] != "张三" || record["contact_phone"] != "13800138000" {
t.Fatalf("配送点订单联系人未恢复明文:%#v", record)
}
if _, exists := record["contact_name_masked"]; exists {
t.Fatalf("联系人姓名脱敏辅助字段未删除:%#v", record)
}
if _, exists := record["contact_phone_masked"]; exists {
t.Fatalf("联系人电话脱敏辅助字段未删除:%#v", record)
}
}