diff --git a/internal/pkg/util/string.go b/internal/pkg/util/string.go index e179c4a..1fc898a 100644 --- a/internal/pkg/util/string.go +++ b/internal/pkg/util/string.go @@ -26,3 +26,9 @@ func StringToInt(s string) int { i, _ := strconv.Atoi(s) return i } + +// string 转 float64 +func StringToFloat64(s string) float64 { + i, _ := strconv.ParseFloat(s, 64) + return i +} diff --git a/internal/tools/zltx/order_after_reseller.go b/internal/tools/zltx/order_after_reseller.go index 51dff22..aefc18b 100644 --- a/internal/tools/zltx/order_after_reseller.go +++ b/internal/tools/zltx/order_after_reseller.go @@ -68,7 +68,7 @@ type OrderAfterSaleResellerData struct { Platforms map[int]string `json:"platforms"` AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款 Remark string `json:"remark"` // 售后原因 - AfterAmount string `json:"afterAmount"` // 售后金额 + AfterAmount float64 `json:"afterAmount"` // 售后金额 ResponsibleType int `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无 ResponsiblePerson string `json:"responsiblePerson"` // 费用承担供应商 IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 @@ -107,8 +107,7 @@ type OrderAfterSaleResellerApiExtItem struct { func (t *OrderAfterSaleResellerTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { var req OrderAfterSaleResellerRequest if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { - entitys.ResError(requireData.Ch, t.Name(), "解析参数失败,请重试或联系管理员") - return err + return fmt.Errorf("解析参数失败,请重试或联系管理员") } if len(req.OrderNumber) == 0 && len(req.Account) == 0 { return fmt.Errorf("订单号 和 充值账号 不能同时为空") @@ -190,6 +189,11 @@ func (t *OrderAfterSaleResellerTool) checkOrderAfterSaleReseller(toolReq OrderAf return fmt.Errorf("订单号 和 充值账号 不能同时为空") } + // 未查询到相应售后订单,请核实提供信息是否正确 + if len(orderList) == 0 { + return fmt.Errorf("未查询到相应售后订单,请核实提供信息是否正确") + } + toolResp := OrderAfterSaleResellerResponse{ Code: 0, Msg: "Success", @@ -231,6 +235,17 @@ func (t *OrderAfterSaleResellerTool) getAfterSaleResellerList(headers map[string // 转换数据 for _, item := range resp.Data.Data { + // 处理方式 + afterType := util.StringToInt(originInput.AfterType) + if afterType == 0 { + afterType = 1 // 默认退款 + } + // 费用承担者 + responsibleType := util.StringToInt(originInput.ResponsibleType) + if responsibleType == 0 { + responsibleType = 4 // 默认无 + } + orderList = append(orderList, &OrderAfterSaleResellerData{ OrderType: item.OrderType, OrderNumber: item.OrderNumber, @@ -244,10 +259,10 @@ func (t *OrderAfterSaleResellerTool) getAfterSaleResellerList(headers map[string OurProductTitle: item.OurProductTitle, Account: item.Account, Platforms: item.Platforms, - AfterType: util.StringToInt(originInput.AfterType), + AfterType: afterType, Remark: originInput.AfterSalesReason, - AfterAmount: originInput.AfterSalesPrice, - ResponsibleType: util.StringToInt(originInput.ResponsibleType), + AfterAmount: util.StringToFloat64(originInput.AfterSalesPrice), + ResponsibleType: responsibleType, ResponsiblePerson: originInput.ResponsiblePerson, }) } diff --git a/internal/tools/zltx/order_after_reseller_batch.go b/internal/tools/zltx/order_after_reseller_batch.go index c039ecc..7a87115 100644 --- a/internal/tools/zltx/order_after_reseller_batch.go +++ b/internal/tools/zltx/order_after_reseller_batch.go @@ -64,7 +64,7 @@ type OrderAfterSaleResellerBatchData struct { Platforms map[int]string `json:"platforms"` AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款 Remark string `json:"remark"` // 售后原因 - AfterAmount string `json:"afterAmount"` // 售后金额 + AfterAmount float64 `json:"afterAmount"` // 售后金额 ResponsibleType int `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无 ResponsiblePerson string `json:"responsiblePerson"` // 费用承担供应商 IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 @@ -103,8 +103,7 @@ type OrderAfterSaleResellerBatchApiExtItem struct { func (t *OrderAfterSaleResellerBatchTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { var req OrderAfterSaleResellerBatchRequest if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { - entitys.ResError(requireData.Ch, t.Name(), "解析参数失败,请重试或联系管理员") - return err + return fmt.Errorf("解析参数失败,请重试或联系管理员") } if len(req.OrderNumber) == 0 { return fmt.Errorf("批充订单号不能为空") @@ -137,7 +136,10 @@ func (t *OrderAfterSaleResellerBatchTool) checkOrderAfterSaleResellerBatch(toolR return err } if resp.Code != 200 { - return fmt.Errorf("after sale supplier failed: %s", resp.Error) + return fmt.Errorf("售后订单查询异常: %s", resp.Error) + } + if len(resp.Data.Data) == 0 { + return fmt.Errorf("未查询到相应售后订单,请核实订单号是否正确") } toolResp := OrderAfterSaleResellerBatchResponse{ @@ -148,6 +150,17 @@ func (t *OrderAfterSaleResellerBatchTool) checkOrderAfterSaleResellerBatch(toolR // 转换数据 for _, item := range resp.Data.Data { + // 处理方式 + afterType := util.StringToInt(toolReq.AfterType) + if afterType == 0 { + afterType = 1 // 默认退款 + } + // 费用承担者 + responsibleType := util.StringToInt(toolReq.ResponsibleType) + if responsibleType == 0 { + responsibleType = 4 // 默认无 + } + toolResp.Data = append(toolResp.Data, &OrderAfterSaleResellerBatchData{ OrderType: item.OrderType, OrderNumber: item.OrderNumber, @@ -161,10 +174,10 @@ func (t *OrderAfterSaleResellerBatchTool) checkOrderAfterSaleResellerBatch(toolR OurProductTitle: item.OurProductTitle, Account: item.Account, Platforms: item.Platforms, - AfterType: util.StringToInt(toolReq.AfterType), + AfterType: afterType, Remark: toolReq.AfterSalesReason, - AfterAmount: toolReq.AfterSalesPrice, - ResponsibleType: util.StringToInt(toolReq.ResponsibleType), + AfterAmount: util.StringToFloat64(toolReq.AfterSalesPrice), + ResponsibleType: responsibleType, ResponsiblePerson: toolReq.ResponsiblePerson, }) } diff --git a/internal/tools/zltx/order_after_supplier.go b/internal/tools/zltx/order_after_supplier.go index 3ed294e..d5631ff 100644 --- a/internal/tools/zltx/order_after_supplier.go +++ b/internal/tools/zltx/order_after_supplier.go @@ -64,7 +64,7 @@ type OrderAfterSaleSupplierData struct { PlatformID int `json:"platformId"` // 上游平台id SignCompanyName string `json:"signCompanyName"` // 签约主体名称 Reason string `json:"reason"` // 售后原因 - SalePrice string `json:"salePrice"` // 售后金额 + SalePrice float64 `json:"salePrice"` // 售后金额 SaleType int `json:"saleType"` // 处理方式 1.加款 2.扣款 ExecuteTime int `json:"executeTime"` // 流水创建时间 IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 @@ -101,8 +101,7 @@ type OrderAfterSaleSupplierApiExtItem struct { func (t *OrderAfterSaleSupplierTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { var req OrderAfterSaleSupplierRequest if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { - entitys.ResError(requireData.Ch, t.Name(), "解析参数失败,请重试或联系管理员") - return err + return fmt.Errorf("解析参数失败,请重试或联系管理员") } if len(req.SerialNumber) == 0 && len(req.Account) == 0 { return fmt.Errorf("充值流水号 和 充值账号 不能同时为空") @@ -182,6 +181,11 @@ func (t *OrderAfterSaleSupplierTool) checkOrderAfterSaleSupplier(toolReq OrderAf return fmt.Errorf("充值流水号 和 充值账号 不能同时为空") } + // 未查询到相应售后订单,请核实提供信息是否正确 + if len(orderList) == 0 { + return fmt.Errorf("未查询到相应售后订单,请核实提供信息是否正确") + } + toolResp := OrderAfterSaleSupplierResponse{ Code: 0, Msg: "Success", @@ -223,6 +227,12 @@ func (t *OrderAfterSaleSupplierTool) getAfterSaleSupplierList(headers map[string // 转换数据 for _, item := range resp.Data.Data { + // 处理方式 + afterType := util.StringToInt(originInput.AfterType) + if afterType == 0 { + afterType = 1 // 默认退款 + } + orderList = append(orderList, &OrderAfterSaleSupplierData{ SerialNumber: item.SerialNumber, PlatformName: item.PlatformName, @@ -235,8 +245,8 @@ func (t *OrderAfterSaleSupplierTool) getAfterSaleSupplierList(headers map[string PlatformID: item.PlatformID, SignCompanyName: item.SignCompanyName, Reason: originInput.AfterSalesReason, - SalePrice: originInput.AfterSalesPrice, - SaleType: util.StringToInt(originInput.AfterType), + SalePrice: util.StringToFloat64(originInput.AfterSalesPrice), + SaleType: afterType, }) }