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 1/7] =?UTF-8?q?feat:=201.=E5=A2=9E=E5=8A=A0=E7=9B=B4?= =?UTF-8?q?=E8=BF=9E=E5=A4=A9=E4=B8=8B=E5=94=AE=E5=90=8E=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=202.=20=E5=A2=9E=E5=8A=A0=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=203.=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, + } +} From 687678e7d515c0d802db9258b6854ca08a8d5cb6 Mon Sep 17 00:00:00 2001 From: wuchao <1272174216@qq.com> Date: Wed, 19 Nov 2025 15:44:53 +0800 Subject: [PATCH 2/7] =?UTF-8?q?feat(config):=20=E6=B7=BB=E5=8A=A0=E5=94=AE?= =?UTF-8?q?=E5=90=8E=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.yaml | 9 ++ internal/config/config.go | 4 + internal/tools/manager.go | 11 +++ internal/tools/zltx_after_direct.go | 119 ++++++++++++++++++++++++++ internal/tools/zltx_after_pre.go | 125 ++++++++++++++++++++++++++++ 5 files changed, 268 insertions(+) create mode 100644 internal/tools/zltx_after_direct.go create mode 100644 internal/tools/zltx_after_pre.go diff --git a/config/config.yaml b/config/config.yaml index 7824fd8..51d1009 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -55,6 +55,15 @@ tools: enabled: true api_key: "dingsbbntrkeiyazcfdg" api_secret: "ObqxwyR20r9rVNhju0sCPQyQA98_FZSc32W4vgxnGFH_b02HZr1BPCJsOAF816nu" + zltxOrderAfterSaleDetail: + enabled: true + base_url: "https://revcl.1688sup.com/api/admin/afterSales/direct/%s" + api_key : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyQ2VudGVyIiwiZXhwIjoxNzU2MTgyNTM1LCJuYmYiOjE3NTYxODA3MzUsImp0aSI6IjEiLCJQaG9uZSI6IjE4MDAwMDAwMDAwIiwiVXNlck5hbWUiOiJsc3hkIiwiUmVhbE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJBY2NvdW50VHlwZSI6MSwiR3JvdXBDb2RlcyI6IlZDTF9DQVNISUVSLFZDTF9PUEVSQVRFLFZDTF9BRE1JTixWQ0xfQUFBLFZDTF9WQ0xfT1BFUkFULFZDTF9JTlZPSUNFLENSTV9BRE1JTixMSUFOTElBTl9BRE1JTixNQVJLRVRNQUcyX0FETUlOLFBIT05FQklMTF9BRE1JTixRSUFOWkhVX1NVUFBFUl9BRE0sTUFSS0VUSU5HU0FBU19TVVBFUkFETUlOLENBUkRfQ09ERSxDQVJEX1BST0NVUkVNRU5ULE1BUktFVElOR1NZU1RFTV9TVVBFUixTVEFUSVNUSUNBTFNZU1RFTV9BRE1JTixaTFRYX0FETUlOLFpMVFhfT1BFUkFURSIsIkRpbmdVc2VySWQiOiIxNjIwMjYxMjMwMjg5MzM4MzQifQ.N1xv1PYbcO8_jR5adaczc16YzGsr4z101gwEZdulkRaREBJNYTOnFrvRxTFx3RJTooXsqTqroE1MR84v_1WPX6BS6kKonA-kC1Jgot6yrt5rFWhGNGb2Cpr9rKIFCCQYmiGd3AUgDazEeaQ0_sodv3E-EXg9VfE1SX8nMcck9Yjnc8NCy7RTWaBIaSeOdZcEl-JfCD0S6GSx3oErp_hk-U9FKGwf60wAuDGTY1R0BP4BYpcEqS-C2LSnsSGyURi54Cuk5xH8r1WuF0Dm5bwAj5d7Hvs77-N_sUF-C5ONqyZJRAEhYLgcmN9RX_WQZfizdQJxizlTczdpzYfy-v-1eQ" + zltxOrderAfterSalePreCheck: + enabled: true + base_url: "https://gateway.dev.cdlsxd.cn/zltx_api/admin/afterSales/reseller_pre" + api_key : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyQ2VudGVyIiwiZXhwIjoxNzU2MTgyNTM1LCJuYmYiOjE3NTYxODA3MzUsImp0aSI6IjEiLCJQaG9uZSI6IjE4MDAwMDAwMDAwIiwiVXNlck5hbWUiOiJsc3hkIiwiUmVhbE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJBY2NvdW50VHlwZSI6MSwiR3JvdXBDb2RlcyI6IlZDTF9DQVNISUVSLFZDTF9PUEVSQVRFLFZDTF9BRE1JTixWQ0xfQUFBLFZDTF9WQ0xfT1BFUkFULFZDTF9JTlZPSUNFLENSTV9BRE1JTixMSUFOTElBTl9BRE1JTixNQVJLRVRNQUcyX0FETUlOLFBIT05FQklMTF9BRE1JTixRSUFOWkhVX1NVUFBFUl9BRE0sTUFSS0VUSU5HU0FBU19TVVBFUkFETUlOLENBUkRfQ09ERSxDQVJEX1BST0NVUkVNRU5ULE1BUktFVElOR1NZU1RFTV9TVVBFUixTVEFUSVNUSUNBTFNZU1RFTV9BRE1JTixaTFRYX0FETUlOLFpMVFhfT1BFUkFURSIsIkRpbmdVc2VySWQiOiIxNjIwMjYxMjMwMjg5MzM4MzQifQ.N1xv1PYbcO8_jR5adaczc16YzGsr4z101gwEZdulkRaREBJNYTOnFrvRxTFx3RJTooXsqTqroE1MR84v_1WPX6BS6kKonA-kC1Jgot6yrt5rFWhGNGb2Cpr9rKIFCCQYmiGd3AUgDazEeaQ0_sodv3E-EXg9VfE1SX8nMcck9Yjnc8NCy7RTWaBIaSeOdZcEl-JfCD0S6GSx3oErp_hk-U9FKGwf60wAuDGTY1R0BP4BYpcEqS-C2LSnsSGyURi54Cuk5xH8r1WuF0Dm5bwAj5d7Hvs77-N_sUF-C5ONqyZJRAEhYLgcmN9RX_WQZfizdQJxizlTczdpzYfy-v-1eQ" + default_prompt: img_recognize: diff --git a/internal/config/config.go b/internal/config/config.go index d39d80a..de68808 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -89,6 +89,10 @@ type ToolsConfig struct { //通过账号获取订单统计信息 ZltxOrderStatistics ToolConfig `mapstructure:"zltxOrderStatistics"` DingTalkBot ToolConfig `mapstructure:"dingTalkBot"` + //上游售后订单流水详情 + ZltxOrderAfterSaleDetail ToolConfig `mapstructure:"zltxOrderAfterSaleDetail"` + //下游订单预检 + ZltxOrderAfterSalePreCheck ToolConfig `mapstructure:"zltxOrderAfterSalePreCheck"` } // ToolConfig 单个工具配置 diff --git a/internal/tools/manager.go b/internal/tools/manager.go index 4b7425f..3530add 100644 --- a/internal/tools/manager.go +++ b/internal/tools/manager.go @@ -74,6 +74,17 @@ func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager { knowledgeTool := NewKnowledgeBaseTool(config.Tools.Knowledge) m.tools[knowledgeTool.Name()] = knowledgeTool } + //注册直连天下售后订单详情工具 + if config.Tools.ZltxOrderAfterSaleDetail.Enabled { + zltxOrderAfterSaleDetailTool := NewZltxOrderAfterSaleDetailTool(config.Tools.ZltxOrderAfterSaleDetail) + m.tools[zltxOrderAfterSaleDetailTool.Name()] = zltxOrderAfterSaleDetailTool + } + //注册直连天下售后订单预检工具 + if config.Tools.ZltxOrderAfterSalePreCheck.Enabled { + zltxOrderAfterSalePreCheckTool := NewZltxOrderAfterSalePreCheckTool(config.Tools.ZltxOrderAfterSalePreCheck) + m.tools[zltxOrderAfterSalePreCheckTool.Name()] = zltxOrderAfterSalePreCheckTool + } + // 普通对话 chat := NewNormalChatTool(m.llm, config) m.tools[chat.Name()] = chat diff --git a/internal/tools/zltx_after_direct.go b/internal/tools/zltx_after_direct.go new file mode 100644 index 0000000..5f1e20e --- /dev/null +++ b/internal/tools/zltx_after_direct.go @@ -0,0 +1,119 @@ +package tools + +import ( + "ai_scheduler/internal/config" + "ai_scheduler/internal/entitys" + "ai_scheduler/internal/pkg/l_request" + "context" + "encoding/json" + "fmt" +) + +type ZltxOrderAfterSaleDetailTool struct { + config config.ToolConfig +} + +// NewZltxOrderAfterSaleDetailTool 创建售后订单详情工具 +func NewZltxOrderAfterSaleDetailTool(config config.ToolConfig) *ZltxOrderAfterSaleDetailTool { + return &ZltxOrderAfterSaleDetailTool{config: config} +} + +// Definition 返回工具定义 +func (this *ZltxOrderAfterSaleDetailTool) Definition() entitys.ToolDefinition { + return entitys.ToolDefinition{ + Type: "function", + Function: entitys.FunctionDef{ + Name: this.Name(), + Description: this.Description(), + Parameters: map[string]interface{}{ + "type": "object", + "properties": map[string]interface{}{ + "direct_order_number": map[string]interface{}{ + "type": "string", + "description": "售后订单号", + }, + }, + "required": []string{"direct_order_number"}, + }, + }, + } +} + +type ZltxOrderAfterSaleDetailRequest struct { + DirectOrderNumber string `json:"direct_order_number"` +} + +type ZltxOrderAfterSaleDetailResponse struct { + Code int `json:"code"` + Data struct { + AfterSaleOrder ZltxOrderAfterSaleDetailData `json:"afterSaleOrder"` + } `json:"data"` + Error string `json:"error"` +} + +type ZltxOrderAfterSaleDetailData struct { + SerialNumber string `json:"serialNumber"` + PlatformName string `json:"platformName"` + SignCompany int `json:"signCompany"` + PlatformProductName string `json:"platformProductName"` + PlatformPrice float64 `json:"platformPrice"` + TerminalAccount string `json:"terminalAccount"` + Status int `json:"status"` + PlatformProductID int `json:"platformProductId"` + PlatformID int `json:"platformId"` + SignCompanyName string `json:"signCompanyName"` + ExecuteTime int `json:"executeTime"` +} + +func (this *ZltxOrderAfterSaleDetailTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { + var req ZltxOrderAfterSaleDetailRequest + if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { + return err + } + if req.DirectOrderNumber == "" { + return fmt.Errorf("direct_order_number is required") + } + return this.getZltxOrderAfterSaleDetail(ctx, requireData, req.DirectOrderNumber) +} + +func (this *ZltxOrderAfterSaleDetailTool) getZltxOrderAfterSaleDetail(ctx context.Context, requireData *entitys.RequireData, directOrderNumber string) error { + //查询订单详情 + url := fmt.Sprintf("%s%s", this.config.BaseURL, directOrderNumber) + 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 ZltxOrderAfterSaleDetailResponse + 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)) + } + jsonByte, err := json.Marshal(resData) + if err != nil { + return err + } + entitys.ResJson(requireData.Ch, this.Name(), string(jsonByte)) + return nil +} + +func (this *ZltxOrderAfterSaleDetailTool) GetConfig() config.ToolConfig { + return this.config +} + +// Name 工具名称 +func (this *ZltxOrderAfterSaleDetailTool) Name() string { + return "zltx_order_after_sale_detail" +} + +func (this *ZltxOrderAfterSaleDetailTool) Description() string { + return "查询直连天下上游售后订单详情" +} diff --git a/internal/tools/zltx_after_pre.go b/internal/tools/zltx_after_pre.go new file mode 100644 index 0000000..b44812b --- /dev/null +++ b/internal/tools/zltx_after_pre.go @@ -0,0 +1,125 @@ +package tools + +import ( + "ai_scheduler/internal/config" + "ai_scheduler/internal/entitys" + "ai_scheduler/internal/pkg/l_request" + "context" + "encoding/json" + "fmt" +) + +type ZltxOrderAfterSalePreCheckTool struct { + config config.ToolConfig +} + +// NewZltxOrderAfterSalePreCheckTool 创建售后订单预检工具 +func NewZltxOrderAfterSalePreCheckTool(config config.ToolConfig) *ZltxOrderAfterSalePreCheckTool { + return &ZltxOrderAfterSalePreCheckTool{config: config} +} + +// Name 返回工具名称 +func (t *ZltxOrderAfterSalePreCheckTool) Name() string { + return "zltxOrderAfterSalePreCheck" +} + +func (t *ZltxOrderAfterSalePreCheckTool) Description() string { + return "直连天下售后订单预检工具" +} + +func (t *ZltxOrderAfterSalePreCheckTool) 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 ZltxOrderAfterSalePreCheckRequest struct { + OrderType int `json:"orderType"` + OrderNumber string `json:"orderNumber"` +} + +type ZltxOrderAfterSalePreCheckResponse struct { + Code int `json:"code"` + Msg string `json:"msg"` + Data struct { + CheckResult bool `json:"checkResult"` + } `json:"data"` +} + +type CheckResult 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 struct { + Num4 string `json:"4"` + } `json:"platforms"` +} + +func (t *ZltxOrderAfterSalePreCheckTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { + var req ZltxOrderAfterSalePreCheckRequest + if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { + return err + } + if req.OrderType == 0 || req.OrderNumber == "" { + return fmt.Errorf("orderType and orderNumber are required") + } + return t.checkZltxOrderAfterSalePreCheck(req.OrderType, req.OrderNumber, requireData) +} + +func (t *ZltxOrderAfterSalePreCheckTool) checkZltxOrderAfterSalePreCheck(orderType int, 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 ZltxOrderAfterSalePreCheckResponse + if err := json.Unmarshal(res.Content, &resp); err != nil { + return err + } + if resp.Code != 0 { + return fmt.Errorf("check failed: %s", resp.Msg) + } + jsonByte, err := json.Marshal(resp) + if err != nil { + return err + } + entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) + return nil +} From 4a0cdacbe9c8402df784f0b6fddf324dcb4b7242 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Thu, 20 Nov 2025 19:25:52 +0800 Subject: [PATCH 3/7] =?UTF-8?q?feat:=20=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/data/constants/bot.go | 5 +- internal/tools/zltx_after_sale.go | 131 --------------------- internal/tools_bot/after_sales_supplier.go | 77 ++++++++++++ internal/tools_bot/dtalk_bot.go | 7 ++ 4 files changed, 88 insertions(+), 132 deletions(-) delete mode 100644 internal/tools/zltx_after_sale.go create mode 100644 internal/tools_bot/after_sales_supplier.go diff --git a/internal/data/constants/bot.go b/internal/data/constants/bot.go index 6dc6680..0863cb8 100644 --- a/internal/data/constants/bot.go +++ b/internal/data/constants/bot.go @@ -3,5 +3,8 @@ package constants type BotTools string const ( - BotToolsBugOptimizationSubmit = "bug_optimization_submit" // 系统的bug/优化建议 + BotToolsBugOptimizationSubmit = "bug_optimization_submit" // 系统的bug/优化建议 + BotToolsAfterSalesSupplier = "after_sales_supplier" // 供应商售后 + BotToolsAfterSalesResellerSingle = "after_sales_reseller_single" // 分销商单条售后 + BotToolsAfterSalesResellerBatch = "after_sales_reseller_batch" // 分销商批量售后 ) diff --git a/internal/tools/zltx_after_sale.go b/internal/tools/zltx_after_sale.go deleted file mode 100644 index d5706ac..0000000 --- a/internal/tools/zltx_after_sale.go +++ /dev/null @@ -1,131 +0,0 @@ -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, - } -} diff --git a/internal/tools_bot/after_sales_supplier.go b/internal/tools_bot/after_sales_supplier.go new file mode 100644 index 0000000..aca4a45 --- /dev/null +++ b/internal/tools_bot/after_sales_supplier.go @@ -0,0 +1,77 @@ +package tools_bot + +import ( + "ai_scheduler/internal/entitys" + "context" + "encoding/json" + "fmt" + "strings" + + "github.com/ollama/ollama/api" +) + +type AfterSalesSupplierArgs struct { + OrderNumber string `json:"orderNumber"` + SerialNumber string `json:"serialNumber"` + Account string `json:"account"` + OrderTimeStart int `json:"orderTimeStart"` + OrderTimeEnd int `json:"orderTimeEnd"` +} + +type AfterSalesSupplierList struct { + AfterSalesSupplierData []*AfterSalesSupplierData `json:"afterSalesSupplierData"` +} + +type AfterSalesSupplierData struct { + OrderNumber string `json:"orderNumber"` + SerialNumber string `json:"serialNumber"` + Account string `json:"account"` + OrderTimeStart int `json:"orderTimeStart"` + OrderTimeEnd int `json:"orderTimeEnd"` +} + +// AfterSalesSupplier 售后供应商 +func (w *BotTool) AfterSalesSupplier(ctx context.Context, requireData *entitys.RequireData) (err error) { + // 1. 参数提取 + extractResponse, err := w.llm.Generation(ctx, &api.GenerateRequest{ + Model: w.config.Ollama.Model, + Stream: new(bool), + System: ` + 你是一个内容提取工具,用户会提供上游供应商售后流水/订单相关问题,你需要提取用户咨询的订单/流水信息。 + - 提取的信息有 订单号、流水号、充值账号、订单时间区间 + - 仅返回json: {"orderNumber":"","serialNumber":"","account":"","orderTimeStart":unix时间戳,"orderTimeEnd":unix时间戳} + - 不要有额外的描述、markdown等 + 用户输入:%s + `, + Prompt: requireData.Req.Text, + }) + if err != nil { + return + } + afterSalesSupplierArgs := &AfterSalesSupplierArgs{} + _ = json.Unmarshal([]byte(extractResponse.Response), afterSalesSupplierArgs) + + // 流水号为空 + if afterSalesSupplierArgs.SerialNumber == "" { + // 1.1 通过充值账号查询订单号 + + // 1.2 通过订单号拉取流水号 + + } + + // 流水号不存在 + if afterSalesSupplierArgs.SerialNumber == "" { + return fmt.Errorf("serialNumber is required") + } + + // 流水号转切片 + serialNumbers := strings.Split(afterSalesSupplierArgs.SerialNumber, ",") + _ = serialNumbers + + // 2. 获取流水详情 + // ZltxOrderAfterSaleDetailTool + + // 3. 组装售后订单详情 + + return nil +} diff --git a/internal/tools_bot/dtalk_bot.go b/internal/tools_bot/dtalk_bot.go index 18ac27f..e699a3b 100644 --- a/internal/tools_bot/dtalk_bot.go +++ b/internal/tools_bot/dtalk_bot.go @@ -17,6 +17,7 @@ type BotTool struct { llm *utils_ollama.Client sessionImpl *impl.SessionImpl taskMap map[string]string // task_id -> session_id + // zltxOrderAfterSaleTool tools.ZltxOrderAfterSaleTool } // NewBotTool 创建直连天下订单详情工具 @@ -29,6 +30,12 @@ func (w *BotTool) Execute(ctx context.Context, toolName string, requireData *ent switch toolName { case constants.BotToolsBugOptimizationSubmit: err = w.BugOptimizationSubmit(ctx, requireData) + case constants.BotToolsAfterSalesSupplier: + err = w.AfterSalesSupplier(ctx, requireData) + // case constants.BotToolsAfterSalesResellerSingle: + // err = w.AfterSalesResellerSingle(ctx, requireData) + // case constants.BotToolsAfterSalesResellerBatch: + // err = w.AfterSalesResellerBatch(ctx, requireData) default: log.Errorf("未知的工具类型:%s", toolName) err = errors.ParamErr("未知的工具类型:%s", toolName) From a8cfb118febc0d004624ba91a138b8c0b00b0b3f Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Fri, 21 Nov 2025 15:04:15 +0800 Subject: [PATCH 4/7] feat: dev --- config/config_test.yaml | 3 + internal/config/config.go | 2 + internal/tools/manager.go | 6 + internal/tools/zltx_order_after_supplier.go | 169 ++++++++++++++++++++ internal/tools_bot/after_sales_supplier.go | 77 --------- internal/tools_bot/dtalk_bot.go | 6 - 6 files changed, 180 insertions(+), 83 deletions(-) create mode 100644 internal/tools/zltx_order_after_supplier.go delete mode 100644 internal/tools_bot/after_sales_supplier.go diff --git a/config/config_test.yaml b/config/config_test.yaml index ff2d2d8..1e7907b 100644 --- a/config/config_test.yaml +++ b/config/config_test.yaml @@ -55,6 +55,9 @@ tools: enabled: true api_key: "dingsbbntrkeiyazcfdg" api_secret: "ObqxwyR20r9rVNhju0sCPQyQA98_FZSc32W4vgxnGFH_b02HZr1BPCJsOAF816nu" + zltxOrderAfterSaleSupplier: + enabled: true + base_url: "https://revcl.1688sup.com/api/admin/afterSales/reseller_supplier" default_prompt: img_recognize: diff --git a/internal/config/config.go b/internal/config/config.go index de68808..c1e13a7 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -93,6 +93,8 @@ type ToolsConfig struct { ZltxOrderAfterSaleDetail ToolConfig `mapstructure:"zltxOrderAfterSaleDetail"` //下游订单预检 ZltxOrderAfterSalePreCheck ToolConfig `mapstructure:"zltxOrderAfterSalePreCheck"` + // 上游订单售后 + ZltxOrderAfterSaleSupplier ToolConfig `mapstructure:"zltxOrderAfterSaleSupplier"` } // ToolConfig 单个工具配置 diff --git a/internal/tools/manager.go b/internal/tools/manager.go index d6dc195..148d8fd 100644 --- a/internal/tools/manager.go +++ b/internal/tools/manager.go @@ -81,6 +81,12 @@ func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager { m.tools[zltxOrderAfterSalePreCheckTool.Name()] = zltxOrderAfterSalePreCheckTool } + // 注册直连天下上游售后订单工具 + if config.Tools.ZltxOrderAfterSaleSupplier.Enabled { + zltxOrderAfterSaleSupplierTool := NewZltxOrderAfterSaleSupplierTool(config.Tools.ZltxOrderAfterSaleSupplier) + m.tools[zltxOrderAfterSaleSupplierTool.Name()] = zltxOrderAfterSaleSupplierTool + } + // 普通对话 chat := NewNormalChatTool(m.llm, config) m.tools[chat.Name()] = chat diff --git a/internal/tools/zltx_order_after_supplier.go b/internal/tools/zltx_order_after_supplier.go new file mode 100644 index 0000000..5b311de --- /dev/null +++ b/internal/tools/zltx_order_after_supplier.go @@ -0,0 +1,169 @@ +package tools + +import ( + "ai_scheduler/internal/config" + "ai_scheduler/internal/entitys" + "context" + "encoding/json" + "fmt" +) + +type ZltxOrderAfterSaleSupplierTool struct { + config config.ToolConfig +} + +// NewZltxOrderAfterSaleSupplierTool 创建售后订单预检工具 +func NewZltxOrderAfterSaleSupplierTool(config config.ToolConfig) *ZltxOrderAfterSaleSupplierTool { + return &ZltxOrderAfterSaleSupplierTool{config: config} +} + +// Name 返回工具名称 +func (t *ZltxOrderAfterSaleSupplierTool) Name() string { + return "zltxOrderAfterSaleSupplier" +} + +func (t *ZltxOrderAfterSaleSupplierTool) Description() string { + return "直连天下售后订单供应商工具" +} + +func (t *ZltxOrderAfterSaleSupplierTool) 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 ZltxOrderAfterSaleSupplierRequest 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 ZltxOrderAfterSaleSupplierResponse struct { + Code int `json:"code"` + Msg string `json:"msg"` + Data []CheckResult2 `json:"data"` +} + +type CheckResult2 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 struct { + Num4 string `json:"4"` + } `json:"platforms"` +} + +func (t *ZltxOrderAfterSaleSupplierTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { + var req ZltxOrderAfterSaleSupplierRequest + 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.checkZltxOrderAfterSaleSupplier(req.OrderNumber, requireData) +} + +func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(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 ZltxOrderAfterSaleSupplierResponse + // if err := json.Unmarshal(res.Content, &resp); err != nil { + // return err + // } + // if resp.Code != 0 { + // return fmt.Errorf("check failed: %s", resp.Msg) + // } + resp := ZltxOrderAfterSaleSupplierResponse{ + Code: 0, + Msg: "success", + Data: []CheckResult2{ + { + OrderType: 1, + OrderNumber: orderNumber, + OrderAmount: 100, + OrderPrice: 100, + SignCompany: 1, + OrderQuantity: 1, + ResellerID: 1, + ResellerName: "测试", + OurProductID: 1, + OurProductTitle: "测试", + Account: []string{"123456"}, + Platforms: struct { + Num4 string `json:"4"` + }{ + Num4: "123456", + }, + }, + { + OrderType: 2, + OrderNumber: orderNumber, + OrderAmount: 100, + OrderPrice: 100, + SignCompany: 1, + OrderQuantity: 1, + ResellerID: 1, + ResellerName: "测试", + OurProductID: 1, + OurProductTitle: "测试", + Account: []string{"123456"}, + Platforms: struct { + Num4 string `json:"4"` + }{ + Num4: "123456", + }, + }, + }, + } + jsonByte, err := json.Marshal(resp) + if err != nil { + return err + } + entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) + return nil +} diff --git a/internal/tools_bot/after_sales_supplier.go b/internal/tools_bot/after_sales_supplier.go deleted file mode 100644 index aca4a45..0000000 --- a/internal/tools_bot/after_sales_supplier.go +++ /dev/null @@ -1,77 +0,0 @@ -package tools_bot - -import ( - "ai_scheduler/internal/entitys" - "context" - "encoding/json" - "fmt" - "strings" - - "github.com/ollama/ollama/api" -) - -type AfterSalesSupplierArgs struct { - OrderNumber string `json:"orderNumber"` - SerialNumber string `json:"serialNumber"` - Account string `json:"account"` - OrderTimeStart int `json:"orderTimeStart"` - OrderTimeEnd int `json:"orderTimeEnd"` -} - -type AfterSalesSupplierList struct { - AfterSalesSupplierData []*AfterSalesSupplierData `json:"afterSalesSupplierData"` -} - -type AfterSalesSupplierData struct { - OrderNumber string `json:"orderNumber"` - SerialNumber string `json:"serialNumber"` - Account string `json:"account"` - OrderTimeStart int `json:"orderTimeStart"` - OrderTimeEnd int `json:"orderTimeEnd"` -} - -// AfterSalesSupplier 售后供应商 -func (w *BotTool) AfterSalesSupplier(ctx context.Context, requireData *entitys.RequireData) (err error) { - // 1. 参数提取 - extractResponse, err := w.llm.Generation(ctx, &api.GenerateRequest{ - Model: w.config.Ollama.Model, - Stream: new(bool), - System: ` - 你是一个内容提取工具,用户会提供上游供应商售后流水/订单相关问题,你需要提取用户咨询的订单/流水信息。 - - 提取的信息有 订单号、流水号、充值账号、订单时间区间 - - 仅返回json: {"orderNumber":"","serialNumber":"","account":"","orderTimeStart":unix时间戳,"orderTimeEnd":unix时间戳} - - 不要有额外的描述、markdown等 - 用户输入:%s - `, - Prompt: requireData.Req.Text, - }) - if err != nil { - return - } - afterSalesSupplierArgs := &AfterSalesSupplierArgs{} - _ = json.Unmarshal([]byte(extractResponse.Response), afterSalesSupplierArgs) - - // 流水号为空 - if afterSalesSupplierArgs.SerialNumber == "" { - // 1.1 通过充值账号查询订单号 - - // 1.2 通过订单号拉取流水号 - - } - - // 流水号不存在 - if afterSalesSupplierArgs.SerialNumber == "" { - return fmt.Errorf("serialNumber is required") - } - - // 流水号转切片 - serialNumbers := strings.Split(afterSalesSupplierArgs.SerialNumber, ",") - _ = serialNumbers - - // 2. 获取流水详情 - // ZltxOrderAfterSaleDetailTool - - // 3. 组装售后订单详情 - - return nil -} diff --git a/internal/tools_bot/dtalk_bot.go b/internal/tools_bot/dtalk_bot.go index e699a3b..0e9525a 100644 --- a/internal/tools_bot/dtalk_bot.go +++ b/internal/tools_bot/dtalk_bot.go @@ -30,12 +30,6 @@ func (w *BotTool) Execute(ctx context.Context, toolName string, requireData *ent switch toolName { case constants.BotToolsBugOptimizationSubmit: err = w.BugOptimizationSubmit(ctx, requireData) - case constants.BotToolsAfterSalesSupplier: - err = w.AfterSalesSupplier(ctx, requireData) - // case constants.BotToolsAfterSalesResellerSingle: - // err = w.AfterSalesResellerSingle(ctx, requireData) - // case constants.BotToolsAfterSalesResellerBatch: - // err = w.AfterSalesResellerBatch(ctx, requireData) default: log.Errorf("未知的工具类型:%s", toolName) err = errors.ParamErr("未知的工具类型:%s", toolName) From baff6ef5731c386a8a1ce2a436e37c02ac78cf60 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Mon, 24 Nov 2025 09:47:23 +0800 Subject: [PATCH 5/7] feat: add --- internal/tools/zltx_order_after_supplier.go | 95 ++++++++++----------- 1 file changed, 44 insertions(+), 51 deletions(-) diff --git a/internal/tools/zltx_order_after_supplier.go b/internal/tools/zltx_order_after_supplier.go index 5b311de..3767b40 100644 --- a/internal/tools/zltx_order_after_supplier.go +++ b/internal/tools/zltx_order_after_supplier.go @@ -61,26 +61,25 @@ type ZltxOrderAfterSaleSupplierRequest struct { } type ZltxOrderAfterSaleSupplierResponse struct { - Code int `json:"code"` - Msg string `json:"msg"` - Data []CheckResult2 `json:"data"` + Code int `json:"code"` + Msg string `json:"msg"` + Data []ZltxOrderAfterSaleSupplierData `json:"data"` } -type CheckResult2 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 struct { - Num4 string `json:"4"` - } `json:"platforms"` +type ZltxOrderAfterSaleSupplierData struct { + SerialNumber string `json:"serialNumber"` + PlatformName string `json:"platformName"` + SignCompany int `json:"signCompany"` + PlatformProductName string `json:"platformProductName"` + PlatformPrice float64 `json:"platformPrice"` + TerminalAccount string `json:"terminalAccount"` + Status int `json:"status"` + PlatformProductID int `json:"platformProductId"` + PlatformID int `json:"platformId"` + SignCompanyName string `json:"signCompanyName"` + ExecuteTime int `json:"executeTime"` + AfterSalesReason string `json:"afterSalesReason"` + AfterSalesPrice float64 `json:"afterSalesPrice"` } func (t *ZltxOrderAfterSaleSupplierTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { @@ -121,42 +120,36 @@ func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(orderNu resp := ZltxOrderAfterSaleSupplierResponse{ Code: 0, Msg: "success", - Data: []CheckResult2{ + Data: []ZltxOrderAfterSaleSupplierData{ { - OrderType: 1, - OrderNumber: orderNumber, - OrderAmount: 100, - OrderPrice: 100, - SignCompany: 1, - OrderQuantity: 1, - ResellerID: 1, - ResellerName: "测试", - OurProductID: 1, - OurProductTitle: "测试", - Account: []string{"123456"}, - Platforms: struct { - Num4 string `json:"4"` - }{ - Num4: "123456", - }, + SerialNumber: "123456", + PlatformName: "测试平台", + SignCompany: 1, + PlatformProductName: "测试商品", + PlatformPrice: 100, + TerminalAccount: "123456", + Status: 1, + PlatformProductID: 1, + PlatformID: 1, + SignCompanyName: "测试公司", + ExecuteTime: 1694560000, + AfterSalesReason: "测试售后", + AfterSalesPrice: 50, }, { - OrderType: 2, - OrderNumber: orderNumber, - OrderAmount: 100, - OrderPrice: 100, - SignCompany: 1, - OrderQuantity: 1, - ResellerID: 1, - ResellerName: "测试", - OurProductID: 1, - OurProductTitle: "测试", - Account: []string{"123456"}, - Platforms: struct { - Num4 string `json:"4"` - }{ - Num4: "123456", - }, + SerialNumber: "123457", + PlatformName: "测试平台2", + SignCompany: 1, + PlatformProductName: "测试商品2", + PlatformPrice: 100, + TerminalAccount: "123456", + Status: 1, + PlatformProductID: 1, + PlatformID: 1, + SignCompanyName: "测试公司2", + ExecuteTime: 1694570000, + AfterSalesReason: "测试售后2", + AfterSalesPrice: 30, }, }, } From 57788c990868a104bcd506d0fc94a44796ee38a8 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Mon, 24 Nov 2025 11:16:01 +0800 Subject: [PATCH 6/7] =?UTF-8?q?feat:=20=E5=B7=A5=E5=85=B7=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E8=BE=93=E5=87=BA=20mock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config_test.yaml | 3 + internal/biz/do/handle.go | 12 +- internal/config/config.go | 2 + internal/services/chat.go | 5 +- internal/tools/manager.go | 5 + internal/tools/zltx_order_after_reseller.go | 176 ++++++++++++++++++++ internal/tools/zltx_order_after_supplier.go | 42 +++-- 7 files changed, 219 insertions(+), 26 deletions(-) create mode 100644 internal/tools/zltx_order_after_reseller.go diff --git a/config/config_test.yaml b/config/config_test.yaml index ba26040..c5c8451 100644 --- a/config/config_test.yaml +++ b/config/config_test.yaml @@ -58,6 +58,9 @@ tools: zltxOrderAfterSaleSupplier: enabled: true base_url: "https://revcl.1688sup.com/api/admin/afterSales/reseller_supplier" + zltxOrderAfterSaleReseller: + enabled: true + base_url: "https://revcl.1688sup.com/api/admin/afterSales/reseller_supplier" default_prompt: img_recognize: diff --git a/internal/biz/do/handle.go b/internal/biz/do/handle.go index 828e443..e3fe794 100644 --- a/internal/biz/do/handle.go +++ b/internal/biz/do/handle.go @@ -17,9 +17,9 @@ import ( "context" "encoding/json" "fmt" - "github.com/gofiber/fiber/v2/log" - "gorm.io/gorm/utils" "strings" + + "gorm.io/gorm/utils" ) type Handle struct { @@ -95,10 +95,10 @@ func (r *Handle) HandleMatch(ctx context.Context, client *gateway.Client, requir } // 校验用户权限 - if err = r.PermissionAuth(client, pointTask); err != nil { - log.Errorf("权限验证失败: %s", err.Error()) - return - } + // if err = r.PermissionAuth(client, pointTask); err != nil { + // log.Errorf("权限验证失败: %s", err.Error()) + // return + // } switch constants.TaskType(pointTask.Type) { case constants.TaskTypeApi: diff --git a/internal/config/config.go b/internal/config/config.go index 8241987..6002a36 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -96,6 +96,8 @@ type ToolsConfig struct { ZltxOrderAfterSalePreCheck ToolConfig `mapstructure:"zltxOrderAfterSalePreCheck"` // 上游订单售后 ZltxOrderAfterSaleSupplier ToolConfig `mapstructure:"zltxOrderAfterSaleSupplier"` + // 下游订单售后 + ZltxOrderAfterSaleReseller ToolConfig `mapstructure:"zltxOrderAfterSaleReseller"` } // ToolConfig 单个工具配置 diff --git a/internal/services/chat.go b/internal/services/chat.go index bb28412..5dc0cf5 100644 --- a/internal/services/chat.go +++ b/internal/services/chat.go @@ -9,11 +9,12 @@ import ( "ai_scheduler/internal/gateway" "ai_scheduler/internal/pkg/l_request" "encoding/json" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/websocket/v2" "log" "net/http" "sync" + + "github.com/gofiber/fiber/v2" + "github.com/gofiber/websocket/v2" ) // ChatHandler 聊天处理器 diff --git a/internal/tools/manager.go b/internal/tools/manager.go index 148d8fd..36ea74d 100644 --- a/internal/tools/manager.go +++ b/internal/tools/manager.go @@ -86,6 +86,11 @@ func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager { zltxOrderAfterSaleSupplierTool := NewZltxOrderAfterSaleSupplierTool(config.Tools.ZltxOrderAfterSaleSupplier) m.tools[zltxOrderAfterSaleSupplierTool.Name()] = zltxOrderAfterSaleSupplierTool } + // 注册直连天下下游售后订单工具 + if config.Tools.ZltxOrderAfterSaleReseller.Enabled { + zltxOrderAfterSaleResellerTool := NewZltxOrderAfterSaleResellerTool(config.Tools.ZltxOrderAfterSaleReseller) + m.tools[zltxOrderAfterSaleResellerTool.Name()] = zltxOrderAfterSaleResellerTool + } // 普通对话 chat := NewNormalChatTool(m.llm, config) diff --git a/internal/tools/zltx_order_after_reseller.go b/internal/tools/zltx_order_after_reseller.go new file mode 100644 index 0000000..8a1a68d --- /dev/null +++ b/internal/tools/zltx_order_after_reseller.go @@ -0,0 +1,176 @@ +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 +} diff --git a/internal/tools/zltx_order_after_supplier.go b/internal/tools/zltx_order_after_supplier.go index 3767b40..a258a56 100644 --- a/internal/tools/zltx_order_after_supplier.go +++ b/internal/tools/zltx_order_after_supplier.go @@ -23,7 +23,7 @@ func (t *ZltxOrderAfterSaleSupplierTool) Name() string { } func (t *ZltxOrderAfterSaleSupplierTool) Description() string { - return "直连天下售后订单供应商工具" + return "直连天下上游供应商售后工具" } func (t *ZltxOrderAfterSaleSupplierTool) Definition() entitys.ToolDefinition { @@ -67,19 +67,21 @@ type ZltxOrderAfterSaleSupplierResponse struct { } type ZltxOrderAfterSaleSupplierData struct { - SerialNumber string `json:"serialNumber"` - PlatformName string `json:"platformName"` - SignCompany int `json:"signCompany"` - PlatformProductName string `json:"platformProductName"` - PlatformPrice float64 `json:"platformPrice"` - TerminalAccount string `json:"terminalAccount"` - Status int `json:"status"` - PlatformProductID int `json:"platformProductId"` - PlatformID int `json:"platformId"` - SignCompanyName string `json:"signCompanyName"` - ExecuteTime int `json:"executeTime"` - AfterSalesReason string `json:"afterSalesReason"` - AfterSalesPrice float64 `json:"afterSalesPrice"` + SerialNumber string `json:"serialNumber"` // 流水号 + PlatformName string `json:"platformName"` // 供应商名称 + SignCompany int `json:"signCompany"` // 签约主体 + PlatformProductName string `json:"platformProductName"` // 商品名称 + PlatformPrice float64 `json:"platformPrice"` // 上游价格 + TerminalAccount string `json:"terminalAccount"` // 充值账号 + Status int `json:"status"` // 充值状态 + PlatformProductID int `json:"platformProductId"` // 上有商品id + PlatformID int `json:"platformId"` // 上游平台id + SignCompanyName string `json:"signCompanyName"` // 签约主体名称 + ExecuteTime int `json:"executeTime"` // 订单执行时间 + Reason string `json:"reason"` // 售后原因 + SalePrice float64 `json:"salePrice"` // 售后金额 + SaleType int `json:"saleType"` // 处理方式 1.加款 2.扣款 + IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 } func (t *ZltxOrderAfterSaleSupplierTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { @@ -133,8 +135,10 @@ func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(orderNu PlatformID: 1, SignCompanyName: "测试公司", ExecuteTime: 1694560000, - AfterSalesReason: "测试售后", - AfterSalesPrice: 50, + Reason: "测试售后", + SalePrice: 50, + SaleType: 1, + IsExistsAfterSale: true, }, { SerialNumber: "123457", @@ -148,8 +152,10 @@ func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(orderNu PlatformID: 1, SignCompanyName: "测试公司2", ExecuteTime: 1694570000, - AfterSalesReason: "测试售后2", - AfterSalesPrice: 30, + Reason: "测试售后2", + SalePrice: 30, + SaleType: 2, + IsExistsAfterSale: false, }, }, } From af54224504a9219dbee72658ab27ada6b4d9a522 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Mon, 24 Nov 2025 13:38:30 +0800 Subject: [PATCH 7/7] =?UTF-8?q?fix:=20mock=E6=95=B0=E6=8D=AE=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/tools/zltx_order_after_reseller.go | 41 ++++++++------- internal/tools/zltx_order_after_supplier.go | 55 +++++++++++++-------- 2 files changed, 54 insertions(+), 42 deletions(-) diff --git a/internal/tools/zltx_order_after_reseller.go b/internal/tools/zltx_order_after_reseller.go index 8a1a68d..f08beb3 100644 --- a/internal/tools/zltx_order_after_reseller.go +++ b/internal/tools/zltx_order_after_reseller.go @@ -126,39 +126,38 @@ func (t *ZltxOrderAfterSaleResellerTool) checkZltxOrderAfterSaleReseller(orderNu Code: 0, Msg: "success", Data: []ZltxOrderAfterSaleResellerData{ - // 为我生成两条不一样的数据 { OrderType: 1, - OrderNumber: orderNumber, - OrderAmount: 100, - OrderPrice: 100, + OrderNumber: "846784115378364417", + OrderAmount: 0.1, + OrderPrice: 0.1, SignCompany: 1, OrderQuantity: 1, - ResellerID: 1, - ResellerName: "测试供应商", - OurProductID: 1, - OurProductTitle: "测试商品", - Account: []string{"123456"}, - Platforms: map[int]string{4: "测试平台"}, + ResellerID: 23329, + ResellerName: "分销商23329", + OurProductID: 106, + OurProductTitle: "爱奇艺黄金会员周卡", + Account: []string{"15516353308"}, + Platforms: map[int]string{4: "爱奇艺"}, AfterType: 1, Remark: "测试售后", AfterAmount: 50, ResponsibleType: 1, - IsExistsAfterSale: true, + IsExistsAfterSale: false, }, { - OrderType: 1, - OrderNumber: orderNumber, - OrderAmount: 100, - OrderPrice: 100, + OrderType: 101, + OrderNumber: "846052057729867777", + OrderAmount: 23, + OrderPrice: 23, SignCompany: 1, OrderQuantity: 1, - ResellerID: 1, - ResellerName: "测试供应商2", - OurProductID: 1, - OurProductTitle: "测试商品2", - Account: []string{"123456"}, - Platforms: map[int]string{4: "测试平台2"}, + ResellerID: 25629, + ResellerName: "二期财务分销商简称", + OurProductID: 104, + OurProductTitle: "优酷年卡", + Account: []string{"18380416326"}, + Platforms: map[int]string{1: "爱瓦力"}, AfterType: 2, Remark: "测试售后2", AfterAmount: 30, diff --git a/internal/tools/zltx_order_after_supplier.go b/internal/tools/zltx_order_after_supplier.go index a258a56..ec5e129 100644 --- a/internal/tools/zltx_order_after_supplier.go +++ b/internal/tools/zltx_order_after_supplier.go @@ -123,39 +123,52 @@ func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(orderNu Code: 0, Msg: "success", Data: []ZltxOrderAfterSaleSupplierData{ + // { + // "serialNumber": "847465394004430849", + // "platformName": "爱奇艺", + // "signCompany": 1, + // "platformProductName": "爱奇艺官方周卡", + // "platformPrice": 6, + // "terminalAccount": "15516353308", + // "status": 1, + // "platformProductId": 2, + // "platformId": 4, + // "signCompanyName": "成都蓝色兄弟网络科技有限公司", + // "executeTime": 1763961931 + // } { - SerialNumber: "123456", - PlatformName: "测试平台", + SerialNumber: "847465394004430849", + PlatformName: "爱奇艺", SignCompany: 1, - PlatformProductName: "测试商品", - PlatformPrice: 100, - TerminalAccount: "123456", + PlatformProductName: "爱奇艺官方周卡", + PlatformPrice: 6, + TerminalAccount: "15516353308", Status: 1, - PlatformProductID: 1, - PlatformID: 1, - SignCompanyName: "测试公司", - ExecuteTime: 1694560000, + PlatformProductID: 2, + PlatformID: 4, + SignCompanyName: "成都蓝色兄弟网络科技有限公司", + ExecuteTime: 1763961931, Reason: "测试售后", SalePrice: 50, SaleType: 1, - IsExistsAfterSale: true, + IsExistsAfterSale: false, }, { - SerialNumber: "123457", - PlatformName: "测试平台2", + SerialNumber: "843493448012140545", + PlatformName: "卓望别名1", SignCompany: 1, - PlatformProductName: "测试商品2", - PlatformPrice: 100, - TerminalAccount: "123456", - Status: 1, - PlatformProductID: 1, - PlatformID: 1, - SignCompanyName: "测试公司2", - ExecuteTime: 1694570000, + PlatformProductName: "卓望--别名商品1", + PlatformPrice: 897.7765, + TerminalAccount: "18380416326", + Status: -1, + PlatformProductID: 7497, + PlatformID: 15, + SignCompanyName: "成都蓝色兄弟网络科技有限公司", + ExecuteTime: 1763014914, Reason: "测试售后2", SalePrice: 30, SaleType: 2, - IsExistsAfterSale: false, + IsExistsAfterSale: true, }, }, }