From 8b4e696c772989aefb03535091f911eaf7ce1150 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Tue, 18 Nov 2025 18:24:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=201.=E5=A2=9E=E5=8A=A0=E7=9B=B4=E8=BF=9E?= =?UTF-8?q?=E5=A4=A9=E4=B8=8B=E5=94=AE=E5=90=8E=E4=BB=BB=E5=8A=A1=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=202.=20=E5=A2=9E=E5=8A=A0=E5=B7=A5=E5=85=B7=203.?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BE=93=E5=85=A5=E8=BE=93=E5=87=BAmock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.yaml | 5 ++ internal/config/config.go | 2 + internal/tools/manager.go | 12 ++- internal/tools/zltx_after_sale.go | 131 ++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 internal/tools/zltx_after_sale.go diff --git a/config/config.yaml b/config/config.yaml index 7824fd8..0719bdb 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -55,6 +55,11 @@ tools: enabled: true api_key: "dingsbbntrkeiyazcfdg" api_secret: "ObqxwyR20r9rVNhju0sCPQyQA98_FZSc32W4vgxnGFH_b02HZr1BPCJsOAF816nu" + zltxOrderAfterSale: + enabled: true + base_url: "https://revcl.1688sup.com/api/admin/direct/ai/%s" + add_url: "https://revcl.1688sup.com/api/admin/direct/log/%s/%s" + default_prompt: img_recognize: diff --git a/internal/config/config.go b/internal/config/config.go index d39d80a..18d33a5 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -89,6 +89,8 @@ type ToolsConfig struct { //通过账号获取订单统计信息 ZltxOrderStatistics ToolConfig `mapstructure:"zltxOrderStatistics"` DingTalkBot ToolConfig `mapstructure:"dingTalkBot"` + //直连天下订单售后工具 + ZltxOrderAfterSale ToolConfig `mapstructure:"zltxOrderAfterSale"` } // ToolConfig 单个工具配置 diff --git a/internal/tools/manager.go b/internal/tools/manager.go index 4b7425f..77efc10 100644 --- a/internal/tools/manager.go +++ b/internal/tools/manager.go @@ -70,10 +70,16 @@ func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager { m.tools[knowledgeTool.Name()] = knowledgeTool } - if config.Tools.Knowledge.Enabled { - knowledgeTool := NewKnowledgeBaseTool(config.Tools.Knowledge) - m.tools[knowledgeTool.Name()] = knowledgeTool + // 注册直连天下订单售后工具 + if config.Tools.ZltxOrderAfterSale.Enabled { + zltxOrderAfterSaleTool := NewZltxOrderAfterSaleTool(config.Tools.ZltxOrderAfterSale) + m.tools[zltxOrderAfterSaleTool.Name()] = zltxOrderAfterSaleTool } + + // if config.Tools.Knowledge.Enabled { + // knowledgeTool := NewKnowledgeBaseTool(config.Tools.Knowledge) + // m.tools[knowledgeTool.Name()] = knowledgeTool + // } // 普通对话 chat := NewNormalChatTool(m.llm, config) m.tools[chat.Name()] = chat diff --git a/internal/tools/zltx_after_sale.go b/internal/tools/zltx_after_sale.go new file mode 100644 index 0000000..d5706ac --- /dev/null +++ b/internal/tools/zltx_after_sale.go @@ -0,0 +1,131 @@ +package tools + +import ( + "ai_scheduler/internal/config" + "ai_scheduler/internal/entitys" + "context" + "encoding/json" + "fmt" + "sort" + + "gitea.cdlsxd.cn/self-tools/l_request" +) + +type ZltxOrderAfterSaleTool struct { + config config.ToolConfig +} + +func (z ZltxOrderAfterSaleTool) Name() string { + return "zltxOrderAfterSale" +} + +func (z ZltxOrderAfterSaleTool) Description() string { + return "查询直连天下订单售后信息" +} + +func (z ZltxOrderAfterSaleTool) Definition() entitys.ToolDefinition { + return entitys.ToolDefinition{ + Type: "function", + Function: entitys.FunctionDef{ + Name: z.Name(), + Description: z.Description(), + Parameters: map[string]interface{}{ + "type": "object", + "properties": map[string]interface{}{ + "number": map[string]interface{}{ + "type": "string", + "description": "账号或分销商号", + }, + }, + "required": []string{"number"}, + }, + }, + } +} + +type ZltxOrderAfterSaleRequest struct { + Number string `json:"number"` +} + +func (z ZltxOrderAfterSaleTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { + var req ZltxOrderAfterSaleRequest + if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { + return err + } + if req.Number == "" { + return fmt.Errorf("number is required") + } + return z.getZltxOrderAfterSale(req.Number, requireData) +} + +type ZltxOrderAfterSaleResponse struct { + Code int `json:"code"` + Data struct { + List []*ZltxOrderAfterSaleData `json:"list"` + } `json:"data"` + Error string `json:"error"` +} + +type ZltxOrderAfterSaleData struct { + // 处理方式 价款/扣款 + HandleMethod string `json:"handle_method"` + // 售后金额 + AfterSaleAmount float64 `json:"after_sale_amount"` + // 售后原因 + AfterSaleReason string `json:"after_sale_reason"` + // 原单信息 + OriginalOrderInfo *OrderInfo +} + +type OrderInfo struct { + SerialNumber string `json:"serial_number"` // 订单流水号 + SupplierName string `json:"supplier_name"` // 供应商名称 + SigningBody string `json:"signing_body"` // 签约主体 + ProductName string `json:"product_name"` // 商品名称 + UpstreamPrice float64 `json:"upstream_price"` // 上游价格 + RechargeAccount string `json:"recharge_account"` // 充值账号 + RechargeStatus string `json:"recharge_status"` // 充值状态 +} + +func (z ZltxOrderAfterSaleTool) getZltxOrderAfterSale(number string, requireData *entitys.RequireData) error { + //查询订单详情 + + url := fmt.Sprintf("%s%s", z.config.BaseURL, number) + req := l_request.Request{ + Url: url, + Headers: map[string]string{ + "Authorization": fmt.Sprintf("Bearer %s", requireData.Auth), + }, + Method: "GET", + } + res, err := req.Send() + var resData ZltxOrderAfterSaleResponse + if err != nil { + return err + } + if err := json.Unmarshal(res.Content, &resData); err != nil { + return err + } + if resData.Code != 200 { + return fmt.Errorf("为获取到数据,请检查权限: %s", string(res.Content)) + } + //按照日期排序 + sort.Slice(resData.Data.RecentThreeDays, func(i, j int) bool { + return resData.Data.RecentThreeDays[i].Date < resData.Data.RecentThreeDays[j].Date + }) + sort.Slice(resData.Data.RecentOneMonth, func(i, j int) bool { + return resData.Data.RecentOneMonth[i].Date < resData.Data.RecentOneMonth[j].Date + }) + jsonByte, err := json.Marshal(resData) + if err != nil { + return err + } + entitys.ResJson(requireData.Ch, z.Name(), string(jsonByte)) + return nil +} + +func NewZltxOrderAfterSaleTool(config config.ToolConfig) *ZltxOrderAfterSaleTool { + return &ZltxOrderAfterSaleTool{ + config: config, + } +}