package tools import ( "ai_scheduler/internal/config" "ai_scheduler/internal/entitys" "context" "encoding/json" "fmt" ) type ZltxOrderAfterSaleResellerTool struct { config config.ToolConfig } // NewZltxOrderAfterSaleResellerTool 创建售后订单预检工具 func NewZltxOrderAfterSaleResellerTool(config config.ToolConfig) *ZltxOrderAfterSaleResellerTool { return &ZltxOrderAfterSaleResellerTool{config: config} } // Name 返回工具名称 func (t *ZltxOrderAfterSaleResellerTool) Name() string { return "zltxOrderAfterSaleReseller" } func (t *ZltxOrderAfterSaleResellerTool) Description() string { return "直连天下上游供应商售后工具" } func (t *ZltxOrderAfterSaleResellerTool) Definition() entitys.ToolDefinition { return entitys.ToolDefinition{ Type: "function", Function: entitys.FunctionDef{ Name: t.Name(), Description: t.Description(), Parameters: map[string]interface{}{ "type": "object", "properties": map[string]interface{}{ "orderType": map[string]interface{}{ "type": "integer", "description": "售后订单类型", }, "orderNumber": map[string]interface{}{ "type": "string", "description": "售后订单号", }, }, "required": []string{"orderType", "orderNumber"}, }, }, } } type ZltxOrderAfterSaleResellerRequest struct { OrderNumber string `json:"orderNumber"` // 订单号 SerialNumber string `json:"serialNumber"` // 流水号 Account string `json:"account"` // 充值账号 OrderTimeStart string `json:"orderTimeStart"` // 订单执行开始时间 OrderTimeEnd string `json:"orderTimeEnd"` // 订单执行结束时间 AfterSalesReason string `json:"afterSalesReason"` // 售后原因 AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额 } type ZltxOrderAfterSaleResellerResponse struct { Code int `json:"code"` Msg string `json:"msg"` Data []ZltxOrderAfterSaleResellerData `json:"data"` } type ZltxOrderAfterSaleResellerData struct { OrderType int `json:"orderType"` OrderNumber string `json:"orderNumber"` OrderAmount float64 `json:"orderAmount"` OrderPrice float64 `json:"orderPrice"` SignCompany int `json:"signCompany"` OrderQuantity int `json:"orderQuantity"` ResellerID int `json:"resellerId"` ResellerName string `json:"resellerName"` OurProductID int `json:"ourProductId"` OurProductTitle string `json:"ourProductTitle"` Account []string `json:"account"` Platforms map[int]string `json:"platforms"` AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款 Remark string `json:"remark"` // 售后原因 AfterAmount float64 `json:"afterAmount"` // 售后金额 ResponsibleType int `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无 ResponsiblePerson string `json:"responsiblePerson"` // 费用承担供应商 IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 } func (t *ZltxOrderAfterSaleResellerTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { var req ZltxOrderAfterSaleResellerRequest if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { return err } if req.OrderNumber == "" { return fmt.Errorf("orderType and orderNumber are required") } return t.checkZltxOrderAfterSaleReseller(req.OrderNumber, requireData) } func (t *ZltxOrderAfterSaleResellerTool) checkZltxOrderAfterSaleReseller(orderNumber string, requireData *entitys.RequireData) error { // req := l_request.Request{ // Url: t.config.BaseURL, // Headers: map[string]string{ // "Authorization": fmt.Sprintf("Bearer %s", requireData.Auth), // }, // Method: "POST", // Data: map[string]string{ // // "orderType": fmt.Sprintf("%d", orderType), // "orderNumber": orderNumber, // }, // } // res, err := req.Send() // if err != nil { // return err // } // // 解析响应 // var resp ZltxOrderAfterSaleResellerResponse // if err := json.Unmarshal(res.Content, &resp); err != nil { // return err // } // if resp.Code != 0 { // return fmt.Errorf("check failed: %s", resp.Msg) // } resp := ZltxOrderAfterSaleResellerResponse{ Code: 0, Msg: "success", Data: []ZltxOrderAfterSaleResellerData{ // 为我生成两条不一样的数据 { OrderType: 1, OrderNumber: orderNumber, OrderAmount: 100, OrderPrice: 100, SignCompany: 1, OrderQuantity: 1, ResellerID: 1, ResellerName: "测试供应商", OurProductID: 1, OurProductTitle: "测试商品", Account: []string{"123456"}, Platforms: map[int]string{4: "测试平台"}, AfterType: 1, Remark: "测试售后", AfterAmount: 50, ResponsibleType: 1, IsExistsAfterSale: true, }, { OrderType: 1, OrderNumber: orderNumber, OrderAmount: 100, OrderPrice: 100, SignCompany: 1, OrderQuantity: 1, ResellerID: 1, ResellerName: "测试供应商2", OurProductID: 1, OurProductTitle: "测试商品2", Account: []string{"123456"}, Platforms: map[int]string{4: "测试平台2"}, AfterType: 2, Remark: "测试售后2", AfterAmount: 30, ResponsibleType: 2, IsExistsAfterSale: false, }, }, } jsonByte, err := json.Marshal(resp) if err != nil { return err } entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) return nil }