From 84ab45da8c33237372be69e85ab41b9bfe6f5365 Mon Sep 17 00:00:00 2001 From: zhouyonggao <1971162852@qq.com> Date: Mon, 15 Dec 2025 15:39:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(api):=20=E5=A2=9E=E5=BC=BA=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E6=94=AF=E4=BB=98=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E5=92=8C=E6=B4=BB=E5=8A=A8=E6=B8=A0=E9=81=93=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在exports.go中添加支付状态检查逻辑,确保仅在订单已支付时展示活动渠道字段。同时,新增辅助函数以处理支付状态的解析,提升导出数据的准确性和可读性。 --- server/internal/api/exports.go | 82 ++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/server/internal/api/exports.go b/server/internal/api/exports.go index 91e9f02..e3b3027 100644 --- a/server/internal/api/exports.go +++ b/server/internal/api/exports.go @@ -1058,6 +1058,19 @@ func (a *ExportsAPI) download(w http.ResponseWriter, r *http.Request, id string) } func transformRow(ds string, fields []string, vals []string) []string { + payStatusIdx := -1 + for i := range fields { + if fields[i] == "order.pay_status" { + payStatusIdx = i + break + } + } + isPaid := func() bool { + if payStatusIdx < 0 || payStatusIdx >= len(vals) { + return true + } + return paidStatus(ds, vals[payStatusIdx]) + }() for i := range fields { if i >= len(vals) { break @@ -1076,10 +1089,79 @@ func transformRow(ds string, fields []string, vals []string) []string { vals[i] = decodeOrderKey(vals[i]) } } + if f == "activity.channels" { + if vals[i] == "" || vals[i] == "0" { + vals[i] = "无" + continue + } + if !isPaid { + vals[i] = "无" + continue + } + var arr []map[string]interface{} + if err := json.Unmarshal([]byte(vals[i]), &arr); err != nil { + vals[i] = "无" + continue + } + names := make([]string, 0, len(arr)) + for _, item := range arr { + if v, ok := item["pay_name"].(string); ok && strings.TrimSpace(v) != "" { + names = append(names, v) + continue + } + if v, ok := item["name"].(string); ok && strings.TrimSpace(v) != "" { + names = append(names, v) + } + } + if len(names) == 0 { + vals[i] = "无" + } else { + vals[i] = strings.Join(names, ",") + } + } } return vals } +func paidStatus(ds, status string) bool { + s := strings.TrimSpace(status) + if s == "" { + return false + } + // handle numeric codes + numeric := -1 + if allDigits(s) { + if n, err := strconv.Atoi(s); err == nil { + numeric = n + } + } + switch ds { + case "marketing": + if numeric >= 0 { + // 1:待支付 2:已支付 3:已退款 + return numeric == 2 || numeric == 3 + } + return s == "已支付" || s == "已退款" + case "ymt": + if numeric >= 0 { + // 1:待支付 2:支付中 3:已支付 4:取消支付 5:退款中 6:退款成功 + return numeric == 3 || numeric == 6 || numeric == 5 + } + return s == "已支付" || s == "退款成功" || s == "退款中" + default: + return strings.Contains(s, "支付") && !strings.Contains(s, "待") + } +} + +func allDigits(s string) bool { + for _, c := range s { + if c < '0' || c > '9' { + return false + } + } + return true +} + func decodeOrderKey(s string) string { if s == "" { return s