diff --git a/server/internal/api/exports.go b/server/internal/api/exports.go index 5a3a151..9ef178a 100644 --- a/server/internal/api/exports.go +++ b/server/internal/api/exports.go @@ -189,19 +189,43 @@ func (a *ExportsAPI) create(w http.ResponseWriter, r *http.Request) { return } } - // 过滤非法字段,保持列头与查询列一致 - filtered := make([]string, 0, len(fs)) - for _, tf := range fs { - if ds == "ymt" && strings.HasPrefix(tf, "order_info.") { - tf = strings.Replace(tf, "order_info.", "order.", 1) - } - if ds == "marketing" && tf == "order_voucher.channel_batch_no" { - tf = "order_voucher.channel_activity_id" - } - if wl[tf] { - filtered = append(filtered, tf) - } - } + // 过滤非法字段,保持列头与查询列一致 + // 计算订单类型(若提供)以便做场景化列过滤 + tv := 0 + if v, ok := p.Filters["type_eq"]; ok { + switch t := v.(type) { + case float64: + tv = int(t) + case int: + tv = t + case string: + s := strings.TrimSpace(t) + for i := 0; i < len(s); i++ { + c := s[i] + if c >= '0' && c <= '9' { + tv = tv*10 + int(c-'0') + } + } + } + } + filtered := make([]string, 0, len(fs)) + for _, tf := range fs { + if ds == "ymt" && strings.HasPrefix(tf, "order_info.") { + tf = strings.Replace(tf, "order_info.", "order.", 1) + } + if ds == "marketing" && tf == "order_voucher.channel_batch_no" { + tf = "order_voucher.channel_activity_id" + } + // 易码通直充卡密订单不输出立减金相关列 + if ds == "ymt" && tv == 2 { + if strings.HasPrefix(tf, "order_voucher.") || strings.HasPrefix(tf, "goods_voucher_batch.") || strings.HasPrefix(tf, "goods_voucher_subject_config.") { + continue + } + } + if wl[tf] { + filtered = append(filtered, tf) + } + } // relax: creator_in 非必填,若权限中提供其他边界将被合并为等值过滤 req := exporter.BuildRequest{MainTable: main, Datasource: ds, Fields: filtered, Filters: p.Filters} q, args, err := rrepo.Build(req, wl) diff --git a/server/internal/exporter/sqlbuilder.go b/server/internal/exporter/sqlbuilder.go index 9eda4cd..dfa982f 100644 --- a/server/internal/exporter/sqlbuilder.go +++ b/server/internal/exporter/sqlbuilder.go @@ -262,13 +262,13 @@ func BuildSQL(req BuildRequest, whitelist map[string]bool) (string, []interface{ } args = append(args, arr[0], arr[1]) } - if v, ok := req.Filters["type_eq"]; ok { - var tv int - switch t := v.(type) { - case float64: - tv = int(t) - case int: - tv = t + var tv int + if v, ok := req.Filters["type_eq"]; ok { + switch t := v.(type) { + case float64: + tv = int(t) + case int: + tv = t case string: // simple digits parsing and label mapping _s := strings.TrimSpace(t) @@ -302,14 +302,14 @@ func BuildSQL(req BuildRequest, whitelist map[string]bool) (string, []interface{ } } } - } - if tv == 1 || tv == 2 || tv == 3 { - if tbl, col, ok := sch.FilterColumn("type_eq"); ok { - where = append(where, fmt.Sprintf("`%s`.%s = ?", sch.TableName(tbl), escape(col))) - } - args = append(args, tv) - } - } + } + if tv == 1 || tv == 2 || tv == 3 { + if tbl, col, ok := sch.FilterColumn("type_eq"); ok { + where = append(where, fmt.Sprintf("`%s`.%s = ?", sch.TableName(tbl), escape(col))) + } + args = append(args, tv) + } + } if v, ok := req.Filters["out_trade_no_eq"]; ok { s := toString(v) if s != "" { @@ -386,15 +386,20 @@ func BuildSQL(req BuildRequest, whitelist map[string]bool) (string, []interface{ args = append(args, s) } } - if v, ok := req.Filters["order_voucher_channel_activity_id_eq"]; ok { - s := toString(v) - if s != "" { - if tbl, col, ok := sch.FilterColumn("order_voucher_channel_activity_id_eq"); ok { - where = append(where, fmt.Sprintf("`%s`.%s = ?", sch.TableName(tbl), escape(col))) - } - args = append(args, s) - } - } + if v, ok := req.Filters["order_voucher_channel_activity_id_eq"]; ok { + // 易码通直充卡密订单不允许使用立减金批次号过滤 + if req.Datasource == "ymt" && tv == 2 { + // skip + } else { + s := toString(v) + if s != "" { + if tbl, col, ok := sch.FilterColumn("order_voucher_channel_activity_id_eq"); ok { + where = append(where, fmt.Sprintf("`%s`.%s = ?", sch.TableName(tbl), escape(col))) + } + args = append(args, s) + } + } + } if v, ok := req.Filters["voucher_batch_channel_activity_id_eq"]; ok { s := toString(v) if s != "" { diff --git a/web/index.html b/web/index.html index b95452c..545b77b 100644 --- a/web/index.html +++ b/web/index.html @@ -295,7 +295,7 @@ - + diff --git a/web/main.js b/web/main.js index 9d565e0..0a52a1f 100644 --- a/web/main.js +++ b/web/main.js @@ -1044,7 +1044,11 @@ const app = createApp({ filters.reseller_id_eq = Number(state.exportForm.resellerId); } if (state.exportForm.voucherChannelActivityId) { - filters.order_voucher_channel_activity_id_eq = state.exportForm.voucherChannelActivityId; + const ds2 = state.exportForm.datasource; + const t2 = exportType.value; + if ((ds2 === 'marketing' && t2 === 2) || (ds2 === 'ymt' && t2 === 3)) { + filters.order_voucher_channel_activity_id_eq = state.exportForm.voucherChannelActivityId; + } } if (Array.isArray(state.exportForm.creatorIds) && state.exportForm.creatorIds.length) {