feat(api): 增强导出数据处理逻辑以支持支付状态和活动渠道字段
在exports.go中添加支付状态检查逻辑,确保仅在订单已支付时展示活动渠道字段。同时,新增辅助函数以处理支付状态的解析,提升导出数据的准确性和可读性。
This commit is contained in:
parent
61e8cc04e7
commit
84ab45da8c
|
|
@ -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 {
|
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 {
|
for i := range fields {
|
||||||
if i >= len(vals) {
|
if i >= len(vals) {
|
||||||
break
|
break
|
||||||
|
|
@ -1076,10 +1089,79 @@ func transformRow(ds string, fields []string, vals []string) []string {
|
||||||
vals[i] = decodeOrderKey(vals[i])
|
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
|
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 {
|
func decodeOrderKey(s string) string {
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return s
|
return s
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue