From a844d12979c5d69173ae81c8a87cfbbc89e60479 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Wed, 26 Nov 2025 20:00:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=8B=E6=B8=B8=E5=94=AE=E5=90=8E?= =?UTF-8?q?=EF=BC=88=E6=89=B9=E5=85=85=E3=80=81=E7=9B=B4=E5=85=85=EF=BC=89?= =?UTF-8?q?zltx=20api=20=E6=8E=A5=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/tools/zltx/order_after_reseller.go | 169 +++++++++--------- .../tools/zltx/order_after_reseller_batch.go | 101 +++-------- internal/tools/zltx/order_after_supplier.go | 13 +- 3 files changed, 118 insertions(+), 165 deletions(-) diff --git a/internal/tools/zltx/order_after_reseller.go b/internal/tools/zltx/order_after_reseller.go index f1444a5..51dff22 100644 --- a/internal/tools/zltx/order_after_reseller.go +++ b/internal/tools/zltx/order_after_reseller.go @@ -4,6 +4,7 @@ import ( "ai_scheduler/internal/config" "ai_scheduler/internal/entitys" "ai_scheduler/internal/pkg/l_request" + "ai_scheduler/internal/pkg/util" "context" "encoding/json" "fmt" @@ -39,10 +40,10 @@ type OrderAfterSaleResellerRequest struct { OrderNumber []string `json:"orderNumber"` // 订单号 Account []string `json:"account"` // 充值账号 SerialCreateTime string `json:"serialCreateTime"` // 流水创建时间 - AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款 - AfterSalesPrice float64 `json:"afterSalesPrice"` // 售后金额 + AfterType string `json:"afterType"` // 处理方式 1.退款 2.扣款 + AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额 AfterSalesReason string `json:"afterSalesReason"` // 售后原因 - ResponsibleType int `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无 + ResponsibleType string `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无 ResponsiblePerson string `json:"responsiblePerson"` // 费用承担供应商 } @@ -67,7 +68,7 @@ type OrderAfterSaleResellerData struct { Platforms map[int]string `json:"platforms"` AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款 Remark string `json:"remark"` // 售后原因 - AfterAmount float64 `json:"afterAmount"` // 售后金额 + AfterAmount string `json:"afterAmount"` // 售后金额 ResponsibleType int `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无 ResponsiblePerson string `json:"responsiblePerson"` // 费用承担供应商 IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 @@ -76,13 +77,13 @@ type OrderAfterSaleResellerData struct { // 接口返回 type OrderAfterSaleResellerApiResponse struct { - Code int `json:"code"` - Msg string `json:"msg"` - Data OrderAfterSaleResellerApiData `json:"data"` + Code int `json:"code"` + Error string `json:"error"` + Data OrderAfterSaleResellerApiData `json:"data"` } type OrderAfterSaleResellerApiData struct { Data []OrderAfterSaleResellerApiBase `json:"data"` - ExtData map[string]OrderAfterSaleResellerApiExtItem `json:"ext"` + ExtData map[string]OrderAfterSaleResellerApiExtItem `json:"extraData"` } type OrderAfterSaleResellerApiBase struct { OrderType int `json:"orderType"` @@ -99,13 +100,14 @@ type OrderAfterSaleResellerApiBase struct { Platforms map[int]string `json:"platforms"` } type OrderAfterSaleResellerApiExtItem struct { - IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 - SerialCreateTime int `json:"serialCreateTime"` // 流水创建时间 + IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 - 未使用 + SerialCreateTime int `json:"createTime"` // 流水创建时间 } 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 } if len(req.OrderNumber) == 0 && len(req.Account) == 0 { @@ -114,15 +116,20 @@ func (t *OrderAfterSaleResellerTool) Execute(ctx context.Context, requireData *e entitys.ResLog(requireData.Ch, t.Name(), "正在拉取售后订单信息") - return t.checkOrderAfterSaleResellerMock(req, requireData) + return t.checkOrderAfterSaleReseller(req, requireData) } func (t *OrderAfterSaleResellerTool) checkOrderAfterSaleReseller(toolReq OrderAfterSaleResellerRequest, requireData *entitys.RequireData) error { // 流水创建时间上下浮动10min - serialCreateTime, err := time.ParseInLocation(time.DateTime, toolReq.SerialCreateTime, time.Local) - if err != nil { - return err + serialCreateTime := time.Now() + var err error + if toolReq.SerialCreateTime != "" { + serialCreateTime, err = time.ParseInLocation(time.DateTime, toolReq.SerialCreateTime, time.Local) + if err != nil { + return err + } } + serialStartTime := serialCreateTime.Unix() - 10*60 serialEndTime := serialCreateTime.Unix() + 10*60 @@ -142,7 +149,7 @@ func (t *OrderAfterSaleResellerTool) checkOrderAfterSaleReseller(toolReq OrderAf // 多订单号 if len(toolReq.OrderNumber) > 0 { body := map[string]any{ - "orderNumber": toolReq.OrderNumber, // 订单号 + "order_numbers": toolReq.OrderNumber, // 订单号 } orderList, err = t.getAfterSaleResellerList(headers, body, toolReq) if err != nil { @@ -160,9 +167,9 @@ func (t *OrderAfterSaleResellerTool) checkOrderAfterSaleReseller(toolReq OrderAf defer waitGroup.Done() body := map[string]any{ - "account": account, // 充值账号 - "serialStartTime": serialStartTime, // 流水创建时间 - "serialEndTime": serialEndTime, // 流水结束时间 + "account": account, // 充值账号 + "create_time": []int64{serialStartTime, serialEndTime}, // 流水创建时间区间 + "order_type": 1, // 1.直充 } orderListIn, errIn := t.getAfterSaleResellerList(headers, body, toolReq) if errIn != nil { @@ -216,8 +223,8 @@ func (t *OrderAfterSaleResellerTool) getAfterSaleResellerList(headers map[string if err = json.Unmarshal(res.Content, &resp); err != nil { return nil, err } - if resp.Code != 0 { - return nil, fmt.Errorf("after sale reseller failed: %s", resp.Msg) + if resp.Code != 200 { + return nil, fmt.Errorf("after sale reseller failed: %s", resp.Error) } orderList := make([]*OrderAfterSaleResellerData, 0, len(resp.Data.Data)) @@ -237,10 +244,10 @@ func (t *OrderAfterSaleResellerTool) getAfterSaleResellerList(headers map[string OurProductTitle: item.OurProductTitle, Account: item.Account, Platforms: item.Platforms, - AfterType: originInput.AfterType, + AfterType: util.StringToInt(originInput.AfterType), Remark: originInput.AfterSalesReason, AfterAmount: originInput.AfterSalesPrice, - ResponsibleType: originInput.ResponsibleType, + ResponsibleType: util.StringToInt(originInput.ResponsibleType), ResponsiblePerson: originInput.ResponsiblePerson, }) } @@ -248,7 +255,7 @@ func (t *OrderAfterSaleResellerTool) getAfterSaleResellerList(headers map[string // 追加扩展数据 for _, item := range orderList { if extItem, ok := resp.Data.ExtData[item.OrderNumber]; ok { - item.IsExistsAfterSale = extItem.IsExistsAfterSale + item.IsExistsAfterSale = item.OrderType > 100 // 101 直充&已售后 item.CreateTime = extItem.SerialCreateTime } } @@ -256,64 +263,64 @@ func (t *OrderAfterSaleResellerTool) getAfterSaleResellerList(headers map[string return orderList, nil } -func (t *OrderAfterSaleResellerTool) checkOrderAfterSaleResellerMock(req OrderAfterSaleResellerRequest, requireData *entitys.RequireData) error { - resp := OrderAfterSaleResellerResponse{ - Code: 0, - Msg: "success", - Data: []*OrderAfterSaleResellerData{ - { - OrderType: 1, - OrderNumber: "846784115378364417", - OrderAmount: 0.1, - OrderPrice: 0.1, - SignCompany: 1, - OrderQuantity: 1, - ResellerID: 23329, - ResellerName: "分销商23329", - OurProductID: 106, - OurProductTitle: "爱奇艺黄金会员周卡", - Account: []string{"15516353308"}, - Platforms: map[int]string{4: "爱奇艺"}, - CreateTime: 1723304000, - AfterType: 1, - Remark: "测试售后", - AfterAmount: 50, - ResponsibleType: 1, - IsExistsAfterSale: false, - }, - { - OrderType: 101, - OrderNumber: "846052057729867777", - OrderAmount: 23, - OrderPrice: 23, - SignCompany: 1, - OrderQuantity: 1, - ResellerID: 25629, - ResellerName: "二期财务分销商简称", - OurProductID: 104, - OurProductTitle: "优酷年卡", - Account: []string{"18380416326"}, - Platforms: map[int]string{1: "爱瓦力"}, - CreateTime: 1723305000, - AfterType: 2, - Remark: "测试售后2", - AfterAmount: 30, - ResponsibleType: 2, - IsExistsAfterSale: false, - }, - }, - } +// func (t *OrderAfterSaleResellerTool) checkOrderAfterSaleResellerMock(req OrderAfterSaleResellerRequest, requireData *entitys.RequireData) error { +// resp := OrderAfterSaleResellerResponse{ +// Code: 0, +// Msg: "success", +// Data: []*OrderAfterSaleResellerData{ +// { +// OrderType: 1, +// OrderNumber: "846784115378364417", +// OrderAmount: 0.1, +// OrderPrice: 0.1, +// SignCompany: 1, +// OrderQuantity: 1, +// ResellerID: 23329, +// ResellerName: "分销商23329", +// OurProductID: 106, +// OurProductTitle: "爱奇艺黄金会员周卡", +// Account: []string{"15516353308"}, +// Platforms: map[int]string{4: "爱奇艺"}, +// CreateTime: 1723304000, +// AfterType: 1, +// Remark: "测试售后", +// AfterAmount: 50, +// ResponsibleType: 1, +// IsExistsAfterSale: false, +// }, +// { +// OrderType: 101, +// OrderNumber: "846052057729867777", +// OrderAmount: 23, +// OrderPrice: 23, +// SignCompany: 1, +// OrderQuantity: 1, +// ResellerID: 25629, +// ResellerName: "二期财务分销商简称", +// OurProductID: 104, +// OurProductTitle: "优酷年卡", +// Account: []string{"18380416326"}, +// Platforms: map[int]string{1: "爱瓦力"}, +// CreateTime: 1723305000, +// AfterType: 2, +// Remark: "测试售后2", +// AfterAmount: 30, +// ResponsibleType: 2, +// IsExistsAfterSale: false, +// }, +// }, +// } - if len(req.OrderNumber) == 1 { - resp.Data = resp.Data[:1] - } +// if len(req.OrderNumber) == 1 { +// resp.Data = resp.Data[:1] +// } - jsonByte, err := json.Marshal(resp) - if err != nil { - return err - } +// jsonByte, err := json.Marshal(resp) +// if err != nil { +// return err +// } - entitys.ResLog(requireData.Ch, t.Name(), "售后订单信息拉取完成") - entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) - return nil -} +// entitys.ResLog(requireData.Ch, t.Name(), "售后订单信息拉取完成") +// entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) +// return nil +// } diff --git a/internal/tools/zltx/order_after_reseller_batch.go b/internal/tools/zltx/order_after_reseller_batch.go index d3916f2..c039ecc 100644 --- a/internal/tools/zltx/order_after_reseller_batch.go +++ b/internal/tools/zltx/order_after_reseller_batch.go @@ -4,6 +4,7 @@ import ( "ai_scheduler/internal/config" "ai_scheduler/internal/entitys" "ai_scheduler/internal/pkg/l_request" + "ai_scheduler/internal/pkg/util" "context" "encoding/json" "fmt" @@ -35,10 +36,10 @@ func (t *OrderAfterSaleResellerBatchTool) Definition() entitys.ToolDefinition { type OrderAfterSaleResellerBatchRequest struct { OrderNumber []string `json:"orderNumber"` // 订单号 - AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款 - AfterSalesPrice float64 `json:"afterSalesPrice"` // 售后金额 + AfterType string `json:"afterType"` // 处理方式 1.退款 2.扣款 + AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额 AfterSalesReason string `json:"afterSalesReason"` // 售后原因 - ResponsibleType int `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无 + ResponsibleType string `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无 ResponsiblePerson string `json:"responsiblePerson"` // 费用承担供应商 } @@ -63,7 +64,7 @@ type OrderAfterSaleResellerBatchData struct { Platforms map[int]string `json:"platforms"` AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款 Remark string `json:"remark"` // 售后原因 - AfterAmount float64 `json:"afterAmount"` // 售后金额 + AfterAmount string `json:"afterAmount"` // 售后金额 ResponsibleType int `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无 ResponsiblePerson string `json:"responsiblePerson"` // 费用承担供应商 IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 @@ -72,13 +73,13 @@ type OrderAfterSaleResellerBatchData struct { // 接口返回 type OrderAfterSaleResellerBatchApiResponse struct { - Code int `json:"code"` - Msg string `json:"msg"` - Data OrderAfterSaleResellerBatchApiData `json:"data"` + Code int `json:"code"` + Error string `json:"error"` + Data OrderAfterSaleResellerBatchApiData `json:"data"` } type OrderAfterSaleResellerBatchApiData struct { Data []OrderAfterSaleResellerBatchApiBase `json:"data"` - ExtData map[string]OrderAfterSaleResellerBatchApiExtItem `json:"ext"` + ExtData map[string]OrderAfterSaleResellerBatchApiExtItem `json:"extraData"` } type OrderAfterSaleResellerBatchApiBase struct { OrderType int `json:"orderType"` @@ -95,13 +96,14 @@ type OrderAfterSaleResellerBatchApiBase struct { Platforms map[int]string `json:"platforms"` } type OrderAfterSaleResellerBatchApiExtItem struct { - IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 - SerialCreateTime int `json:"serialCreateTime"` // 流水创建时间 + IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 - 未使用 + SerialCreateTime int `json:"createTime"` // 流水创建时间 } 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 } if len(req.OrderNumber) == 0 { @@ -110,7 +112,7 @@ func (t *OrderAfterSaleResellerBatchTool) Execute(ctx context.Context, requireDa entitys.ResLog(requireData.Ch, t.Name(), "正在拉取售后订单信息") - return t.checkOrderAfterSaleResellerBatchMock(req, requireData) + return t.checkOrderAfterSaleResellerBatch(req, requireData) } func (t *OrderAfterSaleResellerBatchTool) checkOrderAfterSaleResellerBatch(toolReq OrderAfterSaleResellerBatchRequest, requireData *entitys.RequireData) error { @@ -121,7 +123,8 @@ func (t *OrderAfterSaleResellerBatchTool) checkOrderAfterSaleResellerBatch(toolR }, Method: "POST", Json: map[string]any{ - "orderNumber": toolReq.OrderNumber, // 流水号 + "order_numbers": toolReq.OrderNumber, // 流水号 + "order_type": 2, // 2.批充 }, } res, err := req.Send() @@ -133,13 +136,13 @@ func (t *OrderAfterSaleResellerBatchTool) checkOrderAfterSaleResellerBatch(toolR if err = json.Unmarshal(res.Content, &resp); err != nil { return err } - if resp.Code != 0 { - return fmt.Errorf("after sale supplier failed: %s", resp.Msg) + if resp.Code != 200 { + return fmt.Errorf("after sale supplier failed: %s", resp.Error) } toolResp := OrderAfterSaleResellerBatchResponse{ Code: resp.Code, - Msg: resp.Msg, + Msg: resp.Error, Data: make([]*OrderAfterSaleResellerBatchData, 0, len(resp.Data.Data)), } @@ -158,10 +161,10 @@ func (t *OrderAfterSaleResellerBatchTool) checkOrderAfterSaleResellerBatch(toolR OurProductTitle: item.OurProductTitle, Account: item.Account, Platforms: item.Platforms, - AfterType: toolReq.AfterType, + AfterType: util.StringToInt(toolReq.AfterType), Remark: toolReq.AfterSalesReason, AfterAmount: toolReq.AfterSalesPrice, - ResponsibleType: toolReq.ResponsibleType, + ResponsibleType: util.StringToInt(toolReq.ResponsibleType), ResponsiblePerson: toolReq.ResponsiblePerson, }) } @@ -169,7 +172,7 @@ func (t *OrderAfterSaleResellerBatchTool) checkOrderAfterSaleResellerBatch(toolR // 追加扩展数据 for _, item := range toolResp.Data { if extItem, ok := resp.Data.ExtData[item.OrderNumber]; ok { - item.IsExistsAfterSale = extItem.IsExistsAfterSale + item.IsExistsAfterSale = item.OrderType > 100 // 102 批充&已售后 item.CreateTime = extItem.SerialCreateTime } } @@ -183,65 +186,3 @@ func (t *OrderAfterSaleResellerBatchTool) checkOrderAfterSaleResellerBatch(toolR entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) return nil } - -func (t *OrderAfterSaleResellerBatchTool) checkOrderAfterSaleResellerBatchMock(req OrderAfterSaleResellerBatchRequest, requireData *entitys.RequireData) error { - resp := OrderAfterSaleResellerBatchResponse{ - Code: 0, - Msg: "success", - Data: []*OrderAfterSaleResellerBatchData{ - { - OrderType: 1, - OrderNumber: "846784115378364417", - OrderAmount: 0.1, - OrderPrice: 0.1, - SignCompany: 1, - OrderQuantity: 1, - ResellerID: 23329, - ResellerName: "分销商23329", - OurProductID: 106, - OurProductTitle: "爱奇艺黄金会员周卡", - Account: []string{"15516353308"}, - Platforms: map[int]string{4: "爱奇艺"}, - CreateTime: 1723304000, - AfterType: 1, - Remark: "测试售后", - AfterAmount: 50, - ResponsibleType: 1, - IsExistsAfterSale: false, - }, - { - OrderType: 101, - OrderNumber: "846052057729867777", - OrderAmount: 23, - OrderPrice: 23, - SignCompany: 1, - OrderQuantity: 1, - ResellerID: 25629, - ResellerName: "二期财务分销商简称", - OurProductID: 104, - OurProductTitle: "优酷年卡", - Account: []string{"18380416326"}, - Platforms: map[int]string{1: "爱瓦力"}, - CreateTime: 1723305000, - AfterType: 2, - Remark: "测试售后2", - AfterAmount: 30, - ResponsibleType: 2, - IsExistsAfterSale: false, - }, - }, - } - - if len(req.OrderNumber) == 1 { - resp.Data = resp.Data[:1] - } - - jsonByte, err := json.Marshal(resp) - if err != nil { - return err - } - - entitys.ResLog(requireData.Ch, t.Name(), "售后订单信息拉取完成") - entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) - return nil -} diff --git a/internal/tools/zltx/order_after_supplier.go b/internal/tools/zltx/order_after_supplier.go index 321f2aa..3ed294e 100644 --- a/internal/tools/zltx/order_after_supplier.go +++ b/internal/tools/zltx/order_after_supplier.go @@ -94,13 +94,14 @@ type OrderAfterSaleSupplierApiBase struct { ExecuteTime int `json:"executeTime"` // 充值执行时间 } type OrderAfterSaleSupplierApiExtItem struct { - IsExistsAfterSale bool `json:"existAfterSales"` // 是否已存在售后 + IsExistsAfterSale bool `json:"existAfterSales"` // 是否已存在售后 - 未使用 SerialCreateTime int `json:"createTime"` // 流水创建时间 } 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 } if len(req.SerialNumber) == 0 && len(req.Account) == 0 { @@ -114,9 +115,13 @@ func (t *OrderAfterSaleSupplierTool) Execute(ctx context.Context, requireData *e func (t *OrderAfterSaleSupplierTool) checkOrderAfterSaleSupplier(toolReq OrderAfterSaleSupplierRequest, requireData *entitys.RequireData) error { // 流水创建时间上下浮动10min - serialCreateTime, err := time.ParseInLocation(time.DateTime, toolReq.SerialCreateTime, time.Local) - if err != nil { - return err + serialCreateTime := time.Now() + var err error + if toolReq.SerialCreateTime != "" { + serialCreateTime, err = time.ParseInLocation(time.DateTime, toolReq.SerialCreateTime, time.Local) + if err != nil { + return err + } } serialStartTime := serialCreateTime.Unix() - 10*60 serialEndTime := serialCreateTime.Unix() + 10*60