fix(导出): 修复立减金批次号在不同数据源和订单类型下的显示与过滤逻辑

调整前端条件渲染和后端过滤逻辑,确保立减金批次号字段仅在营销数据源类型2或易码通数据源类型3时显示和生效
修复易码通直充卡密订单不应包含立减金相关字段的问题
This commit is contained in:
zhouyonggao 2025-12-12 15:24:57 +08:00
parent b0e5bb0282
commit e45db7fcb1
4 changed files with 72 additions and 39 deletions

View File

@ -189,19 +189,43 @@ func (a *ExportsAPI) create(w http.ResponseWriter, r *http.Request) {
return return
} }
} }
// 过滤非法字段,保持列头与查询列一致 // 过滤非法字段,保持列头与查询列一致
filtered := make([]string, 0, len(fs)) // 计算订单类型(若提供)以便做场景化列过滤
for _, tf := range fs { tv := 0
if ds == "ymt" && strings.HasPrefix(tf, "order_info.") { if v, ok := p.Filters["type_eq"]; ok {
tf = strings.Replace(tf, "order_info.", "order.", 1) switch t := v.(type) {
} case float64:
if ds == "marketing" && tf == "order_voucher.channel_batch_no" { tv = int(t)
tf = "order_voucher.channel_activity_id" case int:
} tv = t
if wl[tf] { case string:
filtered = append(filtered, tf) 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 非必填,若权限中提供其他边界将被合并为等值过滤 // relax: creator_in 非必填,若权限中提供其他边界将被合并为等值过滤
req := exporter.BuildRequest{MainTable: main, Datasource: ds, Fields: filtered, Filters: p.Filters} req := exporter.BuildRequest{MainTable: main, Datasource: ds, Fields: filtered, Filters: p.Filters}
q, args, err := rrepo.Build(req, wl) q, args, err := rrepo.Build(req, wl)

View File

@ -262,13 +262,13 @@ func BuildSQL(req BuildRequest, whitelist map[string]bool) (string, []interface{
} }
args = append(args, arr[0], arr[1]) args = append(args, arr[0], arr[1])
} }
if v, ok := req.Filters["type_eq"]; ok { var tv int
var tv int if v, ok := req.Filters["type_eq"]; ok {
switch t := v.(type) { switch t := v.(type) {
case float64: case float64:
tv = int(t) tv = int(t)
case int: case int:
tv = t tv = t
case string: case string:
// simple digits parsing and label mapping // simple digits parsing and label mapping
_s := strings.TrimSpace(t) _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 tv == 1 || tv == 2 || tv == 3 {
if tbl, col, ok := sch.FilterColumn("type_eq"); ok { if tbl, col, ok := sch.FilterColumn("type_eq"); ok {
where = append(where, fmt.Sprintf("`%s`.%s = ?", sch.TableName(tbl), escape(col))) where = append(where, fmt.Sprintf("`%s`.%s = ?", sch.TableName(tbl), escape(col)))
} }
args = append(args, tv) args = append(args, tv)
} }
} }
if v, ok := req.Filters["out_trade_no_eq"]; ok { if v, ok := req.Filters["out_trade_no_eq"]; ok {
s := toString(v) s := toString(v)
if s != "" { if s != "" {
@ -386,15 +386,20 @@ func BuildSQL(req BuildRequest, whitelist map[string]bool) (string, []interface{
args = append(args, s) args = append(args, s)
} }
} }
if v, ok := req.Filters["order_voucher_channel_activity_id_eq"]; ok { if v, ok := req.Filters["order_voucher_channel_activity_id_eq"]; ok {
s := toString(v) // 易码通直充卡密订单不允许使用立减金批次号过滤
if s != "" { if req.Datasource == "ymt" && tv == 2 {
if tbl, col, ok := sch.FilterColumn("order_voucher_channel_activity_id_eq"); ok { // skip
where = append(where, fmt.Sprintf("`%s`.%s = ?", sch.TableName(tbl), escape(col))) } else {
} s := toString(v)
args = append(args, s) 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 { if v, ok := req.Filters["voucher_batch_channel_activity_id_eq"]; ok {
s := toString(v) s := toString(v)
if s != "" { if s != "" {

View File

@ -295,7 +295,7 @@
<el-row :gutter="8" v-if="isOrder"> <el-row :gutter="8" v-if="isOrder">
<el-col :span="12" v-if="exportType===2"> <el-col :span="12" v-if="(exportForm.datasource==='marketing' && exportType===2) || (exportForm.datasource==='ymt' && exportType===3)">
<el-form-item label="立减金批次号" prop="voucherChannelActivityId"><el-input v-model="exportForm.voucherChannelActivityId" placeholder="请输入立减金批次号" /></el-form-item> <el-form-item label="立减金批次号" prop="voucherChannelActivityId"><el-input v-model="exportForm.voucherChannelActivityId" placeholder="请输入立减金批次号" /></el-form-item>
</el-col> </el-col>
</el-row> </el-row>

View File

@ -1044,7 +1044,11 @@ const app = createApp({
filters.reseller_id_eq = Number(state.exportForm.resellerId); filters.reseller_id_eq = Number(state.exportForm.resellerId);
} }
if (state.exportForm.voucherChannelActivityId) { 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) { if (Array.isArray(state.exportForm.creatorIds) && state.exportForm.creatorIds.length) {