From 5264f78fb080185b8ad8c4cd429c7c6c41db72c4 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Wed, 26 Nov 2025 14:37:47 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=201.=E8=B0=83=E6=95=B4zltx=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=9B=AE=E5=BD=95=E5=B1=82=E7=BA=A7=202.=E5=AE=8C?= =?UTF-8?q?=E6=95=B4mock=20zltx=20api=203.=E7=A7=BB=E9=99=A4=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E6=97=A0=E6=95=88=E9=A3=98=E7=BA=A2=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config_test.yaml | 5 + internal/biz/router_test.go | 208 +++++++------- internal/config/config.go | 6 +- internal/tools/konwledge_base_test.go | 14 +- internal/tools/manager.go | 25 +- internal/tools/zltx/order_after_reseller.go | 261 ++++++++++++++++++ .../tools/zltx/order_after_reseller_batch.go | 247 +++++++++++++++++ internal/tools/zltx/order_after_supplier.go | 248 +++++++++++++++++ internal/tools/zltx_order_after_reseller.go | 192 ------------- .../tools/zltx_order_after_reseller_batch.go | 190 ------------- internal/tools/zltx_order_after_supplier.go | 180 ------------ utils/utils_test.go | 130 ++++----- 12 files changed, 948 insertions(+), 758 deletions(-) create mode 100644 internal/tools/zltx/order_after_reseller.go create mode 100644 internal/tools/zltx/order_after_reseller_batch.go create mode 100644 internal/tools/zltx/order_after_supplier.go delete mode 100644 internal/tools/zltx_order_after_reseller.go delete mode 100644 internal/tools/zltx_order_after_reseller_batch.go delete mode 100644 internal/tools/zltx_order_after_supplier.go diff --git a/config/config_test.yaml b/config/config_test.yaml index 21e44fc..8134c01 100644 --- a/config/config_test.yaml +++ b/config/config_test.yaml @@ -61,6 +61,11 @@ tools: zltxOrderAfterSaleReseller: enabled: true base_url: "https://revcl.1688sup.com/api/admin/afterSales/reseller_supplier" + zltxOrderAfterSaleResellerBatch: + enabled: true + base_url: "https://revcl.1688sup.com/api/admin/afterSales/reseller_supplier_batch" + + default_prompt: img_recognize: diff --git a/internal/biz/router_test.go b/internal/biz/router_test.go index 6358e51..2fb9f65 100644 --- a/internal/biz/router_test.go +++ b/internal/biz/router_test.go @@ -1,122 +1,122 @@ package biz -import ( - "ai_scheduler/internal/config" - "ai_scheduler/internal/data/impl" - "ai_scheduler/internal/data/model" - "ai_scheduler/internal/entitys" - "ai_scheduler/internal/pkg" - "ai_scheduler/internal/pkg/utils_ollama" - "ai_scheduler/internal/tools" - "ai_scheduler/utils" - "encoding/json" - "flag" - "fmt" - "os" - "path/filepath" - "testing" +// import ( +// "ai_scheduler/internal/config" +// "ai_scheduler/internal/data/impl" +// "ai_scheduler/internal/data/model" +// "ai_scheduler/internal/entitys" +// "ai_scheduler/internal/pkg" +// "ai_scheduler/internal/pkg/utils_ollama" +// "ai_scheduler/internal/tools" +// "ai_scheduler/utils" +// "encoding/json" +// "flag" +// "fmt" +// "os" +// "path/filepath" +// "testing" - "github.com/gofiber/fiber/v2/log" -) +// "github.com/gofiber/fiber/v2/log" +// ) -func Test_task(t *testing.T) { - var c entitys.TaskConfig - config := `{"param": {"type": "object", "required": ["number"], "properties": {"number": {"type": "string", "description": "订单编号/流水号"}}}, "request": {"url": "http://www.baidu.com/${number}", "headers": {"Authorization": "${authorization}"}, "method": "GET"}}` - err := json.Unmarshal([]byte(config), &c) - t.Log(err) -} +// func Test_task(t *testing.T) { +// var c entitys.TaskConfig +// config := `{"param": {"type": "object", "required": ["number"], "properties": {"number": {"type": "string", "description": "订单编号/流水号"}}}, "request": {"url": "http://www.baidu.com/${number}", "headers": {"Authorization": "${authorization}"}, "method": "GET"}}` +// err := json.Unmarshal([]byte(config), &c) +// t.Log(err) +// } -type configData struct { - Param map[string]interface{} `json:"param"` - Do map[string]interface{} `json:"do"` -} +// type configData struct { +// Param map[string]interface{} `json:"param"` +// Do map[string]interface{} `json:"do"` +// } -func Test_Order(t *testing.T) { - routerBiz := in() - ch := make(chan entitys.Response, 5) - defer close(ch) - err := routerBiz.handleTask(ch, nil, &entitys.Match{Index: "order_diagnosis", Parameters: `{"order_number":"822895927188791297"}`}, &model.AiTask{Config: `{"tool": "zltxOrderDetail", "param": {"type": "object", "optional": [], "required": ["order_number"], "properties": {"order_number": {"type": "string", "description": "订单编号/流水号"}}}}`}) - select { - case v := <-ch: // 尝试接收 - fmt.Println("接收到值:", v) - default: - fmt.Println("无数据可接收") - } - t.Log(err) -} +// func Test_Order(t *testing.T) { +// routerBiz := in() +// ch := make(chan entitys.Response, 5) +// defer close(ch) +// err := routerBiz.handleTask(ch, nil, &entitys.Match{Index: "order_diagnosis", Parameters: `{"order_number":"822895927188791297"}`}, &model.AiTask{Config: `{"tool": "zltxOrderDetail", "param": {"type": "object", "optional": [], "required": ["order_number"], "properties": {"order_number": {"type": "string", "description": "订单编号/流水号"}}}}`}) +// select { +// case v := <-ch: // 尝试接收 +// fmt.Println("接收到值:", v) +// default: +// fmt.Println("无数据可接收") +// } +// t.Log(err) +// } -func Test_OrderLog(t *testing.T) { - routerBiz := in() - ch := make(chan entitys.Response, 5) - defer close(ch) - err := routerBiz.handleTask(ch, nil, &entitys.Match{Index: "order_diagnosis", Parameters: `{"order_number":"822979421673758721","serial_number":"822979421979938817"}`}, &model.AiTask{Config: `{"tool": "zltxOrderDirectLog", "param": {"type": "object", "optional": [], "required": ["order_number"], "properties": {"order_number": {"type": "string", "description": "订单编号/流水号"}}}}`}) - t.Log(err) -} +// func Test_OrderLog(t *testing.T) { +// routerBiz := in() +// ch := make(chan entitys.Response, 5) +// defer close(ch) +// err := routerBiz.handleTask(ch, nil, &entitys.Match{Index: "order_diagnosis", Parameters: `{"order_number":"822979421673758721","serial_number":"822979421979938817"}`}, &model.AiTask{Config: `{"tool": "zltxOrderDirectLog", "param": {"type": "object", "optional": [], "required": ["order_number"], "properties": {"order_number": {"type": "string", "description": "订单编号/流水号"}}}}`}) +// t.Log(err) +// } -func Test_ProductLog(t *testing.T) { - routerBiz := in() - ch := make(chan entitys.Response, 5) - defer close(ch) - err := routerBiz.handleTask(ch, nil, &entitys.Match{Index: "order_diagnosis", Parameters: `{"name":"利楚测试"}`}, &model.AiTask{Config: `{"tool": "zltxProduct", "param": {"type": "object", "optional": [], "required": ["order_number"], "properties": {"order_number": {"type": "string", "description": "订单编号/流水号"}}}}`}) - t.Log(err) -} +// func Test_ProductLog(t *testing.T) { +// routerBiz := in() +// ch := make(chan entitys.Response, 5) +// defer close(ch) +// err := routerBiz.handleTask(ch, nil, &entitys.Match{Index: "order_diagnosis", Parameters: `{"name":"利楚测试"}`}, &model.AiTask{Config: `{"tool": "zltxProduct", "param": {"type": "object", "optional": [], "required": ["order_number"], "properties": {"order_number": {"type": "string", "description": "订单编号/流水号"}}}}`}) +// t.Log(err) +// } -func Test_ZltxStatistics(t *testing.T) { - routerBiz := in() - ch := make(chan entitys.Response, 5) - defer close(ch) - err := routerBiz.handleTask(ch, nil, &entitys.Match{Index: "order_diagnosis", Parameters: `{"number":"13737882067"}`}, &model.AiTask{Config: `{"tool": "zltxOrderStatistics", "param": {"type": "object", "optional": [], "required": ["number"], "properties": {"number": {"type": "string", "description": "充值账号/分销商ID"}}}}`}) - t.Log(err) -} +// func Test_ZltxStatistics(t *testing.T) { +// routerBiz := in() +// ch := make(chan entitys.Response, 5) +// defer close(ch) +// err := routerBiz.handleTask(ch, nil, &entitys.Match{Index: "order_diagnosis", Parameters: `{"number":"13737882067"}`}, &model.AiTask{Config: `{"tool": "zltxOrderStatistics", "param": {"type": "object", "optional": [], "required": ["number"], "properties": {"number": {"type": "string", "description": "充值账号/分销商ID"}}}}`}) +// t.Log(err) +// } -func in() *AiRouterBiz { +// func in() *AiRouterBiz { - modDir, err := getModuleDir() - if err != nil { - panic("1") - } - configPath := flag.String("config", fmt.Sprintf("%s/config/config.yaml", modDir), "Path to configuration file") - flag.Parse() +// modDir, err := getModuleDir() +// if err != nil { +// panic("1") +// } +// configPath := flag.String("config", fmt.Sprintf("%s/config/config.yaml", modDir), "Path to configuration file") +// flag.Parse() - configConfig, err := config.LoadConfig(*configPath) - if err != nil { - panic("加载配置失败") - } - client, _, err := utils_ollama.NewClient(configConfig) - allLogger := log.DefaultLogger() - utilOllama := utils_ollama.NewUtilOllama(configConfig, allLogger) - manager := tools.NewManager(configConfig, client) +// configConfig, err := config.LoadConfig(*configPath) +// if err != nil { +// panic("加载配置失败") +// } +// client, _, err := utils_ollama.NewClient(configConfig) +// allLogger := log.DefaultLogger() +// utilOllama := utils_ollama.NewUtilOllama(configConfig, allLogger) +// manager := tools.NewManager(configConfig, client) - db, _ := utils.NewGormDb(configConfig) - sessionImpl := impl.NewSessionImpl(db) - sysImpl := impl.NewSysImpl(db) - taskImpl := impl.NewTaskImpl(db) - chatImpl := impl.NewChatImpl(db) - safeChannelPool, _ := pkg.NewSafeChannelPool(configConfig) - routerBiz := NewAiRouterBiz(manager, sessionImpl, sysImpl, taskImpl, chatImpl, configConfig, utilOllama, safeChannelPool, client) +// db, _ := utils.NewGormDb(configConfig) +// sessionImpl := impl.NewSessionImpl(db) +// sysImpl := impl.NewSysImpl(db) +// taskImpl := impl.NewTaskImpl(db) +// chatImpl := impl.NewChatImpl(db) +// safeChannelPool, _ := pkg.NewSafeChannelPool(configConfig) +// routerBiz := NewAiRouterBiz(manager, sessionImpl, sysImpl, taskImpl, chatImpl, configConfig, utilOllama, safeChannelPool, client) - return routerBiz -} +// return routerBiz +// } -func getModuleDir() (string, error) { - dir, err := os.Getwd() - if err != nil { - return "", err - } +// func getModuleDir() (string, error) { +// dir, err := os.Getwd() +// if err != nil { +// return "", err +// } - for { - modPath := filepath.Join(dir, "go.mod") - if _, err := os.Stat(modPath); err == nil { - return dir, nil // 找到 go.mod - } +// for { +// modPath := filepath.Join(dir, "go.mod") +// if _, err := os.Stat(modPath); err == nil { +// return dir, nil // 找到 go.mod +// } - // 向上查找父目录 - parent := filepath.Dir(dir) - if parent == dir { - break // 到达根目录,未找到 - } - dir = parent - } +// // 向上查找父目录 +// parent := filepath.Dir(dir) +// if parent == dir { +// break // 到达根目录,未找到 +// } +// dir = parent +// } - return "", fmt.Errorf("go.mod not found in current directory or parents") -} +// return "", fmt.Errorf("go.mod not found in current directory or parents") +// } diff --git a/internal/config/config.go b/internal/config/config.go index 32710ff..5c9fa21 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -90,14 +90,12 @@ type ToolsConfig struct { //通过账号获取订单统计信息 ZltxOrderStatistics ToolConfig `mapstructure:"zltxOrderStatistics"` DingTalkBot ToolConfig `mapstructure:"dingTalkBot"` - //上游售后订单流水详情 - ZltxOrderAfterSaleDetail ToolConfig `mapstructure:"zltxOrderAfterSaleDetail"` - //下游订单预检 - ZltxOrderAfterSalePreCheck ToolConfig `mapstructure:"zltxOrderAfterSalePreCheck"` // 上游订单售后 ZltxOrderAfterSaleSupplier ToolConfig `mapstructure:"zltxOrderAfterSaleSupplier"` // 下游订单售后 ZltxOrderAfterSaleReseller ToolConfig `mapstructure:"zltxOrderAfterSaleReseller"` + // 下游批充订单售后 + ZltxOrderAfterSaleResellerBatch ToolConfig `mapstructure:"zltxOrderAfterSaleResellerBatch"` } // ToolConfig 单个工具配置 diff --git a/internal/tools/konwledge_base_test.go b/internal/tools/konwledge_base_test.go index 4ea9bed..de1ab3f 100644 --- a/internal/tools/konwledge_base_test.go +++ b/internal/tools/konwledge_base_test.go @@ -1,19 +1,17 @@ package tools import ( - "ai_scheduler/internal/config" - "ai_scheduler/internal/entitys" "testing" ) func TestKnowledgeBaseTool_Execute(t *testing.T) { - kb := NewKnowledgeBaseTool(config.ToolConfig{}) - channel := make(chan entitys.ResponseData) - err := kb.Execute(channel, nil, nil) - if err != nil { - t.Errorf("Execute() error = %v", err) - } + // kb := NewKnowledgeBaseTool(config.ToolConfig{}) + // channel := make(chan entitys.ResponseData) + // err := kb.Execute(channel, nil, nil) + // if err != nil { + // t.Errorf("Execute() error = %v", err) + // } } diff --git a/internal/tools/manager.go b/internal/tools/manager.go index 36ea74d..2ebbb69 100644 --- a/internal/tools/manager.go +++ b/internal/tools/manager.go @@ -5,6 +5,7 @@ import ( "ai_scheduler/internal/data/constants" "ai_scheduler/internal/entitys" "ai_scheduler/internal/pkg/utils_ollama" + zltxtool "ai_scheduler/internal/tools/zltx" "context" "fmt" @@ -70,27 +71,21 @@ func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager { 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 - } - - // 注册直连天下上游售后订单工具 + // 注册直连天下上游订单售后工具 if config.Tools.ZltxOrderAfterSaleSupplier.Enabled { - zltxOrderAfterSaleSupplierTool := NewZltxOrderAfterSaleSupplierTool(config.Tools.ZltxOrderAfterSaleSupplier) + zltxOrderAfterSaleSupplierTool := zltxtool.NewOrderAfterSaleSupplierTool(config.Tools.ZltxOrderAfterSaleSupplier) m.tools[zltxOrderAfterSaleSupplierTool.Name()] = zltxOrderAfterSaleSupplierTool } - // 注册直连天下下游售后订单工具 + // 注册直连天下下游订单售后工具 if config.Tools.ZltxOrderAfterSaleReseller.Enabled { - zltxOrderAfterSaleResellerTool := NewZltxOrderAfterSaleResellerTool(config.Tools.ZltxOrderAfterSaleReseller) + zltxOrderAfterSaleResellerTool := zltxtool.NewOrderAfterSaleResellerTool(config.Tools.ZltxOrderAfterSaleReseller) m.tools[zltxOrderAfterSaleResellerTool.Name()] = zltxOrderAfterSaleResellerTool } + // 注册直连天下下游批充订单售后工具 + if config.Tools.ZltxOrderAfterSaleResellerBatch.Enabled { + zltxOrderAfterSaleResellerBatchTool := zltxtool.NewOrderAfterSaleResellerBatchTool(config.Tools.ZltxOrderAfterSaleResellerBatch) + m.tools[zltxOrderAfterSaleResellerBatchTool.Name()] = zltxOrderAfterSaleResellerBatchTool + } // 普通对话 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..5f38e5a --- /dev/null +++ b/internal/tools/zltx/order_after_reseller.go @@ -0,0 +1,261 @@ +package zltx + +import ( + "ai_scheduler/internal/config" + "ai_scheduler/internal/entitys" + "ai_scheduler/internal/pkg/l_request" + "context" + "encoding/json" + "fmt" + "time" +) + +type OrderAfterSaleResellerTool struct { + config config.ToolConfig +} + +// NewOrderAfterSaleResellerTool 创建售后订单预检工具 +func NewOrderAfterSaleResellerTool(config config.ToolConfig) *OrderAfterSaleResellerTool { + return &OrderAfterSaleResellerTool{config: config} +} + +// Name 返回工具名称 +func (t *OrderAfterSaleResellerTool) Name() string { + return "zltxOrderAfterSaleReseller" +} + +// 未使用-仅实现接口 +func (t *OrderAfterSaleResellerTool) Description() string { + return "直连天下下游分销商直充订单售后工具" +} + +// 未使用-仅实现接口 +func (t *OrderAfterSaleResellerTool) Definition() entitys.ToolDefinition { + return entitys.ToolDefinition{} +} + +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"` // 售后金额 + AfterSalesReason string `json:"afterSalesReason"` // 售后原因 + ResponsibleType int `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无 + ResponsiblePerson string `json:"responsiblePerson"` // 费用承担供应商 +} + +type OrderAfterSaleResellerResponse struct { + Code int `json:"code"` + Msg string `json:"msg"` + Data []*OrderAfterSaleResellerData `json:"data"` +} + +type OrderAfterSaleResellerData 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"` // 是否已存在售后 + CreateTime int `json:"createTime"` // 流水创建时间 +} + +// 接口返回 +type OrderAfterSaleResellerApiResponse struct { + Code int `json:"code"` + Msg string `json:"msg"` + Data OrderAfterSaleResellerApiData `json:"data"` +} +type OrderAfterSaleResellerApiData struct { + Data []OrderAfterSaleResellerApiBase `json:"data"` + ExtData map[string]OrderAfterSaleResellerApiExtItem `json:"ext"` +} +type OrderAfterSaleResellerApiBase 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"` +} +type OrderAfterSaleResellerApiExtItem struct { + IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 + SerialCreateTime int `json:"serialCreateTime"` // 流水创建时间 +} + +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 { + return err + } + if len(req.OrderNumber) == 0 && req.Account == "" { + return fmt.Errorf("订单号 和 充值账号 不能同时为空") + } + + entitys.ResLog(requireData.Ch, t.Name(), "正在拉取售后订单信息") + + return t.checkOrderAfterSaleResellerMock(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 + } + serialStartTime := serialCreateTime.Unix() - 10*60 + serialEndTime := serialCreateTime.Unix() + 10*60 + + req := l_request.Request{ + Url: t.config.BaseURL, + Headers: map[string]string{ + "Authorization": fmt.Sprintf("Bearer %s", requireData.Auth), + }, + Method: "POST", + Json: map[string]any{ + "orderNumber": toolReq.OrderNumber, // 流水号 + "account": toolReq.Account, // 充值账号 + "serialStartTime": serialStartTime, // 流水创建时间 + "serialEndTime": serialEndTime, // 流水结束时间 + }, + } + res, err := req.Send() + if err != nil { + return err + } + // 解析响应 + var resp OrderAfterSaleResellerApiResponse + 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) + } + + toolResp := OrderAfterSaleResellerResponse{ + Code: resp.Code, + Msg: resp.Msg, + Data: make([]*OrderAfterSaleResellerData, 0, len(resp.Data.Data)), + } + + // 转换数据 + for _, item := range resp.Data.Data { + toolResp.Data = append(toolResp.Data, &OrderAfterSaleResellerData{ + OrderType: item.OrderType, + OrderNumber: item.OrderNumber, + OrderAmount: item.OrderAmount, + OrderPrice: item.OrderPrice, + SignCompany: item.SignCompany, + OrderQuantity: item.OrderQuantity, + ResellerID: item.ResellerID, + ResellerName: item.ResellerName, + OurProductID: item.OurProductID, + OurProductTitle: item.OurProductTitle, + Account: item.Account, + Platforms: item.Platforms, + AfterType: toolReq.AfterType, + Remark: toolReq.AfterSalesReason, + AfterAmount: toolReq.AfterSalesPrice, + ResponsibleType: toolReq.ResponsibleType, + ResponsiblePerson: toolReq.ResponsiblePerson, + }) + } + + // 追加扩展数据 + for _, item := range toolResp.Data { + if extItem, ok := resp.Data.ExtData[item.OrderNumber]; ok { + item.IsExistsAfterSale = extItem.IsExistsAfterSale + item.CreateTime = extItem.SerialCreateTime + } + } + + jsonByte, err := json.Marshal(toolResp) + if err != nil { + return err + } + + entitys.ResLog(requireData.Ch, t.Name(), "售后订单信息拉取完成") + entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) + return 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, + }, + }, + } + + 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_reseller_batch.go b/internal/tools/zltx/order_after_reseller_batch.go new file mode 100644 index 0000000..d3916f2 --- /dev/null +++ b/internal/tools/zltx/order_after_reseller_batch.go @@ -0,0 +1,247 @@ +package zltx + +import ( + "ai_scheduler/internal/config" + "ai_scheduler/internal/entitys" + "ai_scheduler/internal/pkg/l_request" + "context" + "encoding/json" + "fmt" +) + +type OrderAfterSaleResellerBatchTool struct { + config config.ToolConfig +} + +// NewOrderAfterSaleResellerBatchTool 创建售后订单预检工具 +func NewOrderAfterSaleResellerBatchTool(config config.ToolConfig) *OrderAfterSaleResellerBatchTool { + return &OrderAfterSaleResellerBatchTool{config: config} +} + +// Name 返回工具名称 +func (t *OrderAfterSaleResellerBatchTool) Name() string { + return "zltxOrderAfterSaleResellerBatch" +} + +// 未使用-仅实现接口 +func (t *OrderAfterSaleResellerBatchTool) Description() string { + return "直连天下下游分销商批充订单售后工具" +} + +// 未使用-仅实现接口 +func (t *OrderAfterSaleResellerBatchTool) Definition() entitys.ToolDefinition { + return entitys.ToolDefinition{} +} + +type OrderAfterSaleResellerBatchRequest struct { + OrderNumber []string `json:"orderNumber"` // 订单号 + AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款 + AfterSalesPrice float64 `json:"afterSalesPrice"` // 售后金额 + AfterSalesReason string `json:"afterSalesReason"` // 售后原因 + ResponsibleType int `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无 + ResponsiblePerson string `json:"responsiblePerson"` // 费用承担供应商 +} + +type OrderAfterSaleResellerBatchResponse struct { + Code int `json:"code"` + Msg string `json:"msg"` + Data []*OrderAfterSaleResellerBatchData `json:"data"` +} + +type OrderAfterSaleResellerBatchData 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"` // 是否已存在售后 + CreateTime int `json:"createTime"` // 创建时间 +} + +// 接口返回 +type OrderAfterSaleResellerBatchApiResponse struct { + Code int `json:"code"` + Msg string `json:"msg"` + Data OrderAfterSaleResellerBatchApiData `json:"data"` +} +type OrderAfterSaleResellerBatchApiData struct { + Data []OrderAfterSaleResellerBatchApiBase `json:"data"` + ExtData map[string]OrderAfterSaleResellerBatchApiExtItem `json:"ext"` +} +type OrderAfterSaleResellerBatchApiBase 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"` +} +type OrderAfterSaleResellerBatchApiExtItem struct { + IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 + SerialCreateTime int `json:"serialCreateTime"` // 流水创建时间 +} + +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 { + return err + } + if len(req.OrderNumber) == 0 { + return fmt.Errorf("批充订单号不能为空") + } + + entitys.ResLog(requireData.Ch, t.Name(), "正在拉取售后订单信息") + + return t.checkOrderAfterSaleResellerBatchMock(req, requireData) +} + +func (t *OrderAfterSaleResellerBatchTool) checkOrderAfterSaleResellerBatch(toolReq OrderAfterSaleResellerBatchRequest, 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", + Json: map[string]any{ + "orderNumber": toolReq.OrderNumber, // 流水号 + }, + } + res, err := req.Send() + if err != nil { + return err + } + // 解析响应 + var resp OrderAfterSaleResellerBatchApiResponse + 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) + } + + toolResp := OrderAfterSaleResellerBatchResponse{ + Code: resp.Code, + Msg: resp.Msg, + Data: make([]*OrderAfterSaleResellerBatchData, 0, len(resp.Data.Data)), + } + + // 转换数据 + for _, item := range resp.Data.Data { + toolResp.Data = append(toolResp.Data, &OrderAfterSaleResellerBatchData{ + OrderType: item.OrderType, + OrderNumber: item.OrderNumber, + OrderAmount: item.OrderAmount, + OrderPrice: item.OrderPrice, + SignCompany: item.SignCompany, + OrderQuantity: item.OrderQuantity, + ResellerID: item.ResellerID, + ResellerName: item.ResellerName, + OurProductID: item.OurProductID, + OurProductTitle: item.OurProductTitle, + Account: item.Account, + Platforms: item.Platforms, + AfterType: toolReq.AfterType, + Remark: toolReq.AfterSalesReason, + AfterAmount: toolReq.AfterSalesPrice, + ResponsibleType: toolReq.ResponsibleType, + ResponsiblePerson: toolReq.ResponsiblePerson, + }) + } + + // 追加扩展数据 + for _, item := range toolResp.Data { + if extItem, ok := resp.Data.ExtData[item.OrderNumber]; ok { + item.IsExistsAfterSale = extItem.IsExistsAfterSale + item.CreateTime = extItem.SerialCreateTime + } + } + + jsonByte, err := json.Marshal(toolResp) + if err != nil { + return err + } + + entitys.ResLog(requireData.Ch, t.Name(), "售后订单信息拉取完成") + 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 new file mode 100644 index 0000000..67a2391 --- /dev/null +++ b/internal/tools/zltx/order_after_supplier.go @@ -0,0 +1,248 @@ +package zltx + +import ( + "ai_scheduler/internal/config" + "ai_scheduler/internal/entitys" + "ai_scheduler/internal/pkg/l_request" + "context" + "encoding/json" + "fmt" + "time" +) + +type OrderAfterSaleSupplierTool struct { + config config.ToolConfig +} + +// NewOrderAfterSaleSupplierTool 创建售后订单预检工具 +func NewOrderAfterSaleSupplierTool(config config.ToolConfig) *OrderAfterSaleSupplierTool { + return &OrderAfterSaleSupplierTool{config: config} +} + +// Name 返回工具名称 +func (t *OrderAfterSaleSupplierTool) Name() string { + return "zltxOrderAfterSaleSupplier" +} + +// 未使用-仅实现接口 +func (t *OrderAfterSaleSupplierTool) Description() string { + return "直连天下上游供应商直充订单售后工具" +} + +// 未使用-仅实现接口 +func (t *OrderAfterSaleSupplierTool) Definition() entitys.ToolDefinition { + return entitys.ToolDefinition{} +} + +type OrderAfterSaleSupplierRequest struct { + SerialNumber []string `json:"serialNumber"` // 流水号 + Account string `json:"account"` // 充值账号 + SerialCreateTime string `json:"serialCreateTime"` // 流水创建时间 + AfterSalesReason string `json:"afterSalesReason"` // 售后原因 + AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额 + AfterType int `json:"afterType"` // 售后类型 1.加款 2.扣款 +} + +// 工具最终返回 +type OrderAfterSaleSupplierResponse struct { + Code int `json:"code"` + Msg string `json:"msg"` + Data []*OrderAfterSaleSupplierData `json:"data"` +} + +type OrderAfterSaleSupplierData 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"` // 上有商品id + PlatformID int `json:"platformId"` // 上游平台id + SignCompanyName string `json:"signCompanyName"` // 签约主体名称 + Reason string `json:"reason"` // 售后原因 + SalePrice float64 `json:"salePrice"` // 售后金额 + SaleType int `json:"saleType"` // 处理方式 1.加款 2.扣款 + ExecuteTime int `json:"executeTime"` // 流水创建时间 + IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 +} + +// 接口返回 +type OrderAfterSaleSupplierApiResponse struct { + Code int `json:"code"` + Msg string `json:"msg"` + Data OrderAfterSaleSupplierApiData `json:"data"` +} +type OrderAfterSaleSupplierApiData struct { + Data []OrderAfterSaleSupplierApiBase `json:"data"` + ExtData map[string]OrderAfterSaleSupplierApiExtItem `json:"ext"` +} +type OrderAfterSaleSupplierApiBase 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"` // 上有商品id + PlatformID int `json:"platformId"` // 上游平台id + SignCompanyName string `json:"signCompanyName"` // 签约主体名称 + Reason string `json:"reason"` // 售后原因 + SalePrice float64 `json:"salePrice"` // 售后金额 + SaleType int `json:"saleType"` // 处理方式 1.加款 2.扣款 +} +type OrderAfterSaleSupplierApiExtItem struct { + IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 + SerialCreateTime int `json:"serialCreateTime"` // 流水创建时间 +} + +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 { + return err + } + if len(req.SerialNumber) == 0 && req.Account == "" { + return fmt.Errorf("充值流水号 和 充值账号 不能同时为空") + } + + entitys.ResLog(requireData.Ch, t.Name(), "正在拉取售后订单信息") + + return t.checkOrderAfterSaleSupplierMock(req, requireData) +} + +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 + } + serialStartTime := serialCreateTime.Unix() - 10*60 + serialEndTime := serialCreateTime.Unix() + 10*60 + + req := l_request.Request{ + Url: t.config.BaseURL, + Headers: map[string]string{ + "Authorization": fmt.Sprintf("Bearer %s", requireData.Auth), + }, + Method: "POST", + Json: map[string]any{ + "serialNumber": toolReq.SerialNumber, // 流水号 + "account": toolReq.Account, // 充值账号 + "serialStartTime": serialStartTime, // 流水创建时间 + "serialEndTime": serialEndTime, // 流水结束时间 + }, + } + res, err := req.Send() + if err != nil { + return err + } + // 解析响应 + var resp OrderAfterSaleSupplierApiResponse + 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) + } + + toolResp := OrderAfterSaleSupplierResponse{ + Code: resp.Code, + Msg: resp.Msg, + Data: make([]*OrderAfterSaleSupplierData, 0, len(resp.Data.Data)), + } + + // 转换数据 + for _, item := range resp.Data.Data { + toolResp.Data = append(toolResp.Data, &OrderAfterSaleSupplierData{ + SerialNumber: item.SerialNumber, + PlatformName: item.PlatformName, + SignCompany: item.SignCompany, + PlatformProductName: item.PlatformProductName, + PlatformPrice: item.PlatformPrice, + TerminalAccount: item.TerminalAccount, + Status: item.Status, + PlatformProductID: item.PlatformProductID, + PlatformID: item.PlatformID, + SignCompanyName: item.SignCompanyName, + Reason: item.Reason, + SalePrice: item.SalePrice, + SaleType: item.SaleType, + }) + } + + // 追加扩展数据 + for _, item := range toolResp.Data { + if extItem, ok := resp.Data.ExtData[item.SerialNumber]; ok { + item.IsExistsAfterSale = extItem.IsExistsAfterSale + item.ExecuteTime = extItem.SerialCreateTime + } + } + + jsonByte, err := json.Marshal(toolResp) + if err != nil { + return err + } + + entitys.ResLog(requireData.Ch, t.Name(), "售后订单信息拉取完成") + entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) + return nil +} + +// mock待删除 +func (t *OrderAfterSaleSupplierTool) checkOrderAfterSaleSupplierMock(req OrderAfterSaleSupplierRequest, requireData *entitys.RequireData) error { + resp := OrderAfterSaleSupplierResponse{ + Code: 0, + Msg: "success", + Data: []*OrderAfterSaleSupplierData{ + { + SerialNumber: "847465394004430849", + PlatformName: "爱奇艺", + SignCompany: 1, + PlatformProductName: "爱奇艺官方周卡", + PlatformPrice: 6, + TerminalAccount: "15516353308", + Status: 1, + PlatformProductID: 2, + PlatformID: 4, + SignCompanyName: "成都蓝色兄弟网络科技有限公司", + ExecuteTime: 1763961931, + Reason: "测试售后", + SalePrice: 50, + SaleType: 1, + IsExistsAfterSale: false, + }, + { + SerialNumber: "843493448012140545", + PlatformName: "卓望别名1", + SignCompany: 1, + PlatformProductName: "卓望--别名商品1", + PlatformPrice: 897.7765, + TerminalAccount: "18380416326", + Status: -1, + PlatformProductID: 7497, + PlatformID: 15, + SignCompanyName: "成都蓝色兄弟网络科技有限公司", + ExecuteTime: 1763014914, + Reason: "测试售后2", + SalePrice: 30, + SaleType: 2, + IsExistsAfterSale: true, + }, + }, + } + + if len(req.SerialNumber) == 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_reseller.go b/internal/tools/zltx_order_after_reseller.go deleted file mode 100644 index 51bbb0a..0000000 --- a/internal/tools/zltx_order_after_reseller.go +++ /dev/null @@ -1,192 +0,0 @@ -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"` // 订单号 - Account string `json:"account"` // 充值账号 - SerialCreateTime string `json:"serialCreateTime"` // 流水创建时间 - AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款 - AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额 - AfterSalesReason string `json:"afterSalesReason"` // 售后原因 - ResponsibleType int `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无 - ResponsiblePerson string `json:"responsiblePerson"` // 费用承担供应商 -} - -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"` - CreateTime string `json:"createTime"` // 创建时间 - 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 len(req.OrderNumber) == 0 && req.Account == "" { - return fmt.Errorf("订单号 和 充值账号 不能同时为空") - } - - entitys.ResLog(requireData.Ch, t.Name(), "正在拉取售后订单信息") - - return t.checkZltxOrderAfterSaleReseller(req, requireData) -} - -func (t *ZltxOrderAfterSaleResellerTool) checkZltxOrderAfterSaleReseller(req ZltxOrderAfterSaleResellerRequest, 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) - // } - - // === mock start === - resp := ZltxOrderAfterSaleResellerResponse{ - Code: 0, - Msg: "success", - Data: []ZltxOrderAfterSaleResellerData{ - { - 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: "2025-08-10 10:00:00", - 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: "2025-08-11 10:00:00", - AfterType: 2, - Remark: "测试售后2", - AfterAmount: 30, - ResponsibleType: 2, - IsExistsAfterSale: false, - }, - }, - } - - if len(req.OrderNumber) == 1 { - resp.Data = resp.Data[:1] - } - // === mock end === - - 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_reseller_batch.go b/internal/tools/zltx_order_after_reseller_batch.go deleted file mode 100644 index 35c9140..0000000 --- a/internal/tools/zltx_order_after_reseller_batch.go +++ /dev/null @@ -1,190 +0,0 @@ -package tools - -import ( - "ai_scheduler/internal/config" - "ai_scheduler/internal/entitys" - "context" - "encoding/json" - "fmt" -) - -type ZltxOrderAfterSaleResellerBatchTool struct { - config config.ToolConfig -} - -// NewZltxOrderAfterSaleResellerBatchTool 创建售后订单预检工具 -func NewZltxOrderAfterSaleResellerBatchTool(config config.ToolConfig) *ZltxOrderAfterSaleResellerBatchTool { - return &ZltxOrderAfterSaleResellerBatchTool{config: config} -} - -// Name 返回工具名称 -func (t *ZltxOrderAfterSaleResellerBatchTool) Name() string { - return "zltxOrderAfterSaleResellerBatch" -} - -func (t *ZltxOrderAfterSaleResellerBatchTool) Description() string { - return "直连天下下游分销商批充订单售后工具" -} - -func (t *ZltxOrderAfterSaleResellerBatchTool) 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 ZltxOrderAfterSaleResellerBatchRequest struct { - OrderNumber []string `json:"orderNumber"` // 订单号 - AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款 - AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额 - AfterSalesReason string `json:"afterSalesReason"` // 售后原因 - ResponsibleType int `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无 - ResponsiblePerson string `json:"responsiblePerson"` // 费用承担供应商 -} - -type ZltxOrderAfterSaleResellerBatchResponse struct { - Code int `json:"code"` - Msg string `json:"msg"` - Data []ZltxOrderAfterSaleResellerBatchData `json:"data"` -} - -type ZltxOrderAfterSaleResellerBatchData 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"` - CreateTime string `json:"createTime"` // 创建时间 - 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 *ZltxOrderAfterSaleResellerBatchTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { - var req ZltxOrderAfterSaleResellerBatchRequest - if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { - return err - } - if len(req.OrderNumber) == 0 { - return fmt.Errorf("批充订单号不能为空") - } - - entitys.ResLog(requireData.Ch, t.Name(), "正在拉取售后订单信息") - - return t.checkZltxOrderAfterSaleResellerBatch(req, requireData) -} - -func (t *ZltxOrderAfterSaleResellerBatchTool) checkZltxOrderAfterSaleResellerBatch(req ZltxOrderAfterSaleResellerBatchRequest, 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 ZltxOrderAfterSaleResellerBatchResponse - // if err := json.Unmarshal(res.Content, &resp); err != nil { - // return err - // } - // if resp.Code != 0 { - // return fmt.Errorf("check failed: %s", resp.Msg) - // } - - // === mock start === - resp := ZltxOrderAfterSaleResellerBatchResponse{ - Code: 0, - Msg: "success", - Data: []ZltxOrderAfterSaleResellerBatchData{ - { - 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: "2025-08-10 10:00:00", - 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: "2025-08-11 10:00:00", - AfterType: 2, - Remark: "测试售后2", - AfterAmount: 30, - ResponsibleType: 2, - IsExistsAfterSale: false, - }, - }, - } - - if len(req.OrderNumber) == 1 { - resp.Data = resp.Data[:1] - } - // === mock end === - - 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 deleted file mode 100644 index c3d5d2c..0000000 --- a/internal/tools/zltx_order_after_supplier.go +++ /dev/null @@ -1,180 +0,0 @@ -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 { - SerialNumber []string `json:"serialNumber"` // 流水号 - Account string `json:"account"` // 充值账号 - SerialCreateTime string `json:"serialCreateTime"` // 流水创建时间 - AfterSalesReason string `json:"afterSalesReason"` // 售后原因 - AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额 - AfterType int `json:"afterType"` // 售后类型 1.加款 2.扣款 -} - -type ZltxOrderAfterSaleSupplierResponse struct { - Code int `json:"code"` - Msg string `json:"msg"` - Data []ZltxOrderAfterSaleSupplierData `json:"data"` -} - -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"` // 上有商品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 { - var req ZltxOrderAfterSaleSupplierRequest - if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { - return err - } - if len(req.SerialNumber) == 0 && req.Account == "" { - return fmt.Errorf("充值流水号 和 充值账号 不能同时为空") - } - - entitys.ResLog(requireData.Ch, t.Name(), "正在拉取售后订单信息") - - return t.checkZltxOrderAfterSaleSupplier(req, requireData) -} - -func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(req ZltxOrderAfterSaleSupplierRequest, 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) - // } - - // === mock start === - resp := ZltxOrderAfterSaleSupplierResponse{ - 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, - Reason: "测试售后", - SalePrice: 50, - SaleType: 1, - IsExistsAfterSale: false, - }, - { - SerialNumber: "843493448012140545", - PlatformName: "卓望别名1", - SignCompany: 1, - PlatformProductName: "卓望--别名商品1", - PlatformPrice: 897.7765, - TerminalAccount: "18380416326", - Status: -1, - PlatformProductID: 7497, - PlatformID: 15, - SignCompanyName: "成都蓝色兄弟网络科技有限公司", - ExecuteTime: 1763014914, - Reason: "测试售后2", - SalePrice: 30, - SaleType: 2, - IsExistsAfterSale: true, - }, - }, - } - - if len(req.SerialNumber) == 1 { - resp.Data = resp.Data[:1] - } - // === mock end === - - 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/utils/utils_test.go b/utils/utils_test.go index 63363f0..14d8d35 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -1,72 +1,72 @@ package utils -import ( - "fmt" - "github.com/go-kratos/kratos/v2/log" - "google.golang.org/protobuf/runtime/protoimpl" - "gopkg.in/yaml.v3" - "io/fs" - "os" - "path/filepath" - "testing" - baseconf "trans_hub/base_conf" - "trans_hub/pkg" - "trans_hub/pkg/mapstructure" -) +// import ( +// "fmt" +// "github.com/go-kratos/kratos/v2/log" +// "google.golang.org/protobuf/runtime/protoimpl" +// "gopkg.in/yaml.v3" +// "io/fs" +// "os" +// "path/filepath" +// "testing" +// baseconf "trans_hub/base_conf" +// "trans_hub/pkg" +// "trans_hub/pkg/mapstructure" +// ) -const SPACE = "public" -const PORT = 8848 -const User = "" -const Pass = "" -const IP = "192.168.110.93" -const Group = "DEFAULT_GROUP" -const DataId = "PG_BASE_CONFIG" +// const SPACE = "public" +// const PORT = 8848 +// const User = "" +// const Pass = "" +// const IP = "192.168.110.93" +// const Group = "DEFAULT_GROUP" +// const DataId = "PG_BASE_CONFIG" -func TestConfig(t *testing.T) { - type Nacos struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - Ip string `protobuf:"bytes,1,opt,name=ip,proto3" json:"ip,omitempty"` - Port uint64 `protobuf:"varint,2,opt,name=port,proto3" json:"port,omitempty"` - } - type Conf struct { - Nacos *Nacos `protobuf:"bytes,8,opt,name=nacos,proto3" json:"nacos,omitempty"` - } - var c Conf - nc := &baseconf.Nacos{Ip: IP, Port: PORT, Space: SPACE, User: User, Password: Pass} +// func TestConfig(t *testing.T) { +// type Nacos struct { +// state protoimpl.MessageState +// sizeCache protoimpl.SizeCache +// unknownFields protoimpl.UnknownFields +// Ip string `protobuf:"bytes,1,opt,name=ip,proto3" json:"ip,omitempty"` +// Port uint64 `protobuf:"varint,2,opt,name=port,proto3" json:"port,omitempty"` +// } +// type Conf struct { +// Nacos *Nacos `protobuf:"bytes,8,opt,name=nacos,proto3" json:"nacos,omitempty"` +// } +// var c Conf +// nc := &baseconf.Nacos{Ip: IP, Port: PORT, Space: SPACE, User: User, Password: Pass} - var s = ServerConfig(nc, Group, DataId) - err := mapstructure.Decode(s, &c) - t.Log(s, err) -} +// var s = ServerConfig(nc, Group, DataId) +// err := mapstructure.Decode(s, &c) +// t.Log(s, err) +// } -func TestMod(t *testing.T) { - dir := pkg.GetRootPath() - // 读取目录内容 - err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { - if err != nil { - return err - } - if !d.IsDir() && filepath.Ext(path) == ".yaml" { - data, err := os.ReadFile(path) - if err != nil { - return err - } - var result map[string]interface{} - err = yaml.Unmarshal(data, &result) // 解析YAML到map中,使用gopkg.v3的yaml包或其他你选择的版本(例如encoding/yaml) - if err != nil { - return err - } - fmt.Printf("File: %s\nContent: %+v\n", path, result) - } - return nil - }) - if err != nil { - log.Fatal(err) - } -} +// func TestMod(t *testing.T) { +// dir := pkg.GetRootPath() +// // 读取目录内容 +// err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { +// if err != nil { +// return err +// } +// if !d.IsDir() && filepath.Ext(path) == ".yaml" { +// data, err := os.ReadFile(path) +// if err != nil { +// return err +// } +// var result map[string]interface{} +// err = yaml.Unmarshal(data, &result) // 解析YAML到map中,使用gopkg.v3的yaml包或其他你选择的版本(例如encoding/yaml) +// if err != nil { +// return err +// } +// fmt.Printf("File: %s\nContent: %+v\n", path, result) +// } +// return nil +// }) +// if err != nil { +// log.Fatal(err) +// } +// } -func TestYaml(t *testing.T) { - t.Log(GetBaseYaml()) -} +// func TestYaml(t *testing.T) { +// t.Log(GetBaseYaml()) +// } From 2a312dc2052d8bebc76e13502fa50276a0ab3416 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Wed, 26 Nov 2025 16:25:07 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=A4=9A?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E5=B9=B6=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/tools/zltx/order_after_reseller.go | 130 +++++++++++++------ internal/tools/zltx/order_after_supplier.go | 132 ++++++++++++++------ 2 files changed, 189 insertions(+), 73 deletions(-) diff --git a/internal/tools/zltx/order_after_reseller.go b/internal/tools/zltx/order_after_reseller.go index 5f38e5a..f1444a5 100644 --- a/internal/tools/zltx/order_after_reseller.go +++ b/internal/tools/zltx/order_after_reseller.go @@ -7,6 +7,7 @@ import ( "context" "encoding/json" "fmt" + "sync" "time" ) @@ -36,7 +37,7 @@ func (t *OrderAfterSaleResellerTool) Definition() entitys.ToolDefinition { type OrderAfterSaleResellerRequest struct { OrderNumber []string `json:"orderNumber"` // 订单号 - Account string `json:"account"` // 充值账号 + Account []string `json:"account"` // 充值账号 SerialCreateTime string `json:"serialCreateTime"` // 流水创建时间 AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款 AfterSalesPrice float64 `json:"afterSalesPrice"` // 售后金额 @@ -107,7 +108,7 @@ func (t *OrderAfterSaleResellerTool) Execute(ctx context.Context, requireData *e if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { return err } - if len(req.OrderNumber) == 0 && req.Account == "" { + if len(req.OrderNumber) == 0 && len(req.Account) == 0 { return fmt.Errorf("订单号 和 充值账号 不能同时为空") } @@ -125,41 +126,105 @@ func (t *OrderAfterSaleResellerTool) checkOrderAfterSaleReseller(toolReq OrderAf serialStartTime := serialCreateTime.Unix() - 10*60 serialEndTime := serialCreateTime.Unix() + 10*60 + // 账号数量超过10直接截断 + if len(toolReq.Account) > 10 { + entitys.ResLog(requireData.Ch, t.Name(), "账号数量超过10已被截断") + toolReq.Account = toolReq.Account[:10] + } + + headers := map[string]string{ + "Authorization": fmt.Sprintf("Bearer %s", requireData.Auth), + } + + // 最终输出 + var orderList []*OrderAfterSaleResellerData + + // 多订单号 + if len(toolReq.OrderNumber) > 0 { + body := map[string]any{ + "orderNumber": toolReq.OrderNumber, // 订单号 + } + orderList, err = t.getAfterSaleResellerList(headers, body, toolReq) + if err != nil { + return err + } + } else if len(toolReq.Account) > 0 { + // 多充值账号并发 + orderListChan := make(chan []*OrderAfterSaleResellerData, len(toolReq.Account)) + waitGroup := sync.WaitGroup{} + + // 并发请求 + for _, account := range toolReq.Account { + waitGroup.Add(1) + go func(account string) { + defer waitGroup.Done() + + body := map[string]any{ + "account": account, // 充值账号 + "serialStartTime": serialStartTime, // 流水创建时间 + "serialEndTime": serialEndTime, // 流水结束时间 + } + orderListIn, errIn := t.getAfterSaleResellerList(headers, body, toolReq) + if errIn != nil { + return + } + orderListChan <- orderListIn + }(account) + } + + waitGroup.Wait() + close(orderListChan) + + // 合并结果 + for orderListIn := range orderListChan { + orderList = append(orderList, orderListIn...) + } + } else { + return fmt.Errorf("订单号 和 充值账号 不能同时为空") + } + + toolResp := OrderAfterSaleResellerResponse{ + Code: 0, + Msg: "Success", + Data: orderList, + } + + var jsonByte []byte + jsonByte, err = json.Marshal(toolResp) + if err != nil { + return err + } + + entitys.ResLog(requireData.Ch, t.Name(), "售后订单信息拉取完成") + entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) + return nil +} + +func (t *OrderAfterSaleResellerTool) getAfterSaleResellerList(headers map[string]string, body map[string]any, originInput OrderAfterSaleResellerRequest) ([]*OrderAfterSaleResellerData, error) { req := l_request.Request{ - Url: t.config.BaseURL, - Headers: map[string]string{ - "Authorization": fmt.Sprintf("Bearer %s", requireData.Auth), - }, - Method: "POST", - Json: map[string]any{ - "orderNumber": toolReq.OrderNumber, // 流水号 - "account": toolReq.Account, // 充值账号 - "serialStartTime": serialStartTime, // 流水创建时间 - "serialEndTime": serialEndTime, // 流水结束时间 - }, + Url: t.config.BaseURL, + Headers: headers, + Method: "POST", + Json: body, } res, err := req.Send() if err != nil { - return err + return nil, err } // 解析响应 var resp OrderAfterSaleResellerApiResponse if err = json.Unmarshal(res.Content, &resp); err != nil { - return err + return nil, err } if resp.Code != 0 { - return fmt.Errorf("after sale supplier failed: %s", resp.Msg) + return nil, fmt.Errorf("after sale reseller failed: %s", resp.Msg) } - toolResp := OrderAfterSaleResellerResponse{ - Code: resp.Code, - Msg: resp.Msg, - Data: make([]*OrderAfterSaleResellerData, 0, len(resp.Data.Data)), - } + orderList := make([]*OrderAfterSaleResellerData, 0, len(resp.Data.Data)) // 转换数据 for _, item := range resp.Data.Data { - toolResp.Data = append(toolResp.Data, &OrderAfterSaleResellerData{ + orderList = append(orderList, &OrderAfterSaleResellerData{ OrderType: item.OrderType, OrderNumber: item.OrderNumber, OrderAmount: item.OrderAmount, @@ -172,30 +237,23 @@ func (t *OrderAfterSaleResellerTool) checkOrderAfterSaleReseller(toolReq OrderAf OurProductTitle: item.OurProductTitle, Account: item.Account, Platforms: item.Platforms, - AfterType: toolReq.AfterType, - Remark: toolReq.AfterSalesReason, - AfterAmount: toolReq.AfterSalesPrice, - ResponsibleType: toolReq.ResponsibleType, - ResponsiblePerson: toolReq.ResponsiblePerson, + AfterType: originInput.AfterType, + Remark: originInput.AfterSalesReason, + AfterAmount: originInput.AfterSalesPrice, + ResponsibleType: originInput.ResponsibleType, + ResponsiblePerson: originInput.ResponsiblePerson, }) } // 追加扩展数据 - for _, item := range toolResp.Data { + for _, item := range orderList { if extItem, ok := resp.Data.ExtData[item.OrderNumber]; ok { item.IsExistsAfterSale = extItem.IsExistsAfterSale item.CreateTime = extItem.SerialCreateTime } } - jsonByte, err := json.Marshal(toolResp) - if err != nil { - return err - } - - entitys.ResLog(requireData.Ch, t.Name(), "售后订单信息拉取完成") - entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) - return nil + return orderList, nil } func (t *OrderAfterSaleResellerTool) checkOrderAfterSaleResellerMock(req OrderAfterSaleResellerRequest, requireData *entitys.RequireData) error { diff --git a/internal/tools/zltx/order_after_supplier.go b/internal/tools/zltx/order_after_supplier.go index 67a2391..805c38a 100644 --- a/internal/tools/zltx/order_after_supplier.go +++ b/internal/tools/zltx/order_after_supplier.go @@ -7,6 +7,7 @@ import ( "context" "encoding/json" "fmt" + "sync" "time" ) @@ -36,7 +37,7 @@ func (t *OrderAfterSaleSupplierTool) Definition() entitys.ToolDefinition { type OrderAfterSaleSupplierRequest struct { SerialNumber []string `json:"serialNumber"` // 流水号 - Account string `json:"account"` // 充值账号 + Account []string `json:"account"` // 充值账号 SerialCreateTime string `json:"serialCreateTime"` // 流水创建时间 AfterSalesReason string `json:"afterSalesReason"` // 售后原因 AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额 @@ -103,7 +104,7 @@ func (t *OrderAfterSaleSupplierTool) Execute(ctx context.Context, requireData *e if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { return err } - if len(req.SerialNumber) == 0 && req.Account == "" { + if len(req.SerialNumber) == 0 && len(req.Account) == 0 { return fmt.Errorf("充值流水号 和 充值账号 不能同时为空") } @@ -121,41 +122,105 @@ func (t *OrderAfterSaleSupplierTool) checkOrderAfterSaleSupplier(toolReq OrderAf serialStartTime := serialCreateTime.Unix() - 10*60 serialEndTime := serialCreateTime.Unix() + 10*60 - req := l_request.Request{ - Url: t.config.BaseURL, - Headers: map[string]string{ - "Authorization": fmt.Sprintf("Bearer %s", requireData.Auth), - }, - Method: "POST", - Json: map[string]any{ - "serialNumber": toolReq.SerialNumber, // 流水号 - "account": toolReq.Account, // 充值账号 - "serialStartTime": serialStartTime, // 流水创建时间 - "serialEndTime": serialEndTime, // 流水结束时间 - }, + // 账号数量超过10直接截断 + if len(toolReq.Account) > 10 { + entitys.ResLog(requireData.Ch, t.Name(), "账号数量超过10已被截断") + toolReq.Account = toolReq.Account[:10] } - res, err := req.Send() - if err != nil { - return err + + headers := map[string]string{ + "Authorization": fmt.Sprintf("Bearer %s", requireData.Auth), } - // 解析响应 - var resp OrderAfterSaleSupplierApiResponse - 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) + + // 最终输出 + var orderList []*OrderAfterSaleSupplierData + + // 多流水号 + if len(toolReq.SerialNumber) > 0 { + body := map[string]any{ + "serialNumber": toolReq.SerialNumber, // 流水号 + } + orderList, err = t.getAfterSaleSupplierList(headers, body) + if err != nil { + return err + } + } else if len(toolReq.Account) > 0 { + // 多充值账号并发 + orderListChan := make(chan []*OrderAfterSaleSupplierData, len(toolReq.Account)) + waitGroup := sync.WaitGroup{} + + // 并发请求 + for _, account := range toolReq.Account { + waitGroup.Add(1) + go func(account string) { + defer waitGroup.Done() + + body := map[string]any{ + "account": account, // 充值账号 + "serialStartTime": serialStartTime, // 流水创建时间 + "serialEndTime": serialEndTime, // 流水结束时间 + } + orderListIn, errIn := t.getAfterSaleSupplierList(headers, body) + if errIn != nil { + return + } + orderListChan <- orderListIn + }(account) + } + + // 等待所有请求完成 + waitGroup.Wait() + close(orderListChan) + + for orderListIn := range orderListChan { + orderList = append(orderList, orderListIn...) + } + } else { + return fmt.Errorf("充值流水号 和 充值账号 不能同时为空") } toolResp := OrderAfterSaleSupplierResponse{ - Code: resp.Code, - Msg: resp.Msg, - Data: make([]*OrderAfterSaleSupplierData, 0, len(resp.Data.Data)), + Code: 0, + Msg: "Success", + Data: orderList, } + var jsonByte []byte + jsonByte, err = json.Marshal(toolResp) + if err != nil { + return err + } + + entitys.ResLog(requireData.Ch, t.Name(), "售后订单信息拉取完成") + entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) + return nil +} + +func (t *OrderAfterSaleSupplierTool) getAfterSaleSupplierList(headers map[string]string, body map[string]any) ([]*OrderAfterSaleSupplierData, error) { + req := l_request.Request{ + Url: t.config.BaseURL, + Headers: headers, + Method: "POST", + Json: body, + } + res, err := req.Send() + if err != nil { + return nil, err + } + // 解析响应 + var resp OrderAfterSaleSupplierApiResponse + if err = json.Unmarshal(res.Content, &resp); err != nil { + return nil, err + } + if resp.Code != 0 { + return nil, fmt.Errorf("after sale supplier failed: %s", resp.Msg) + } + + orderList := make([]*OrderAfterSaleSupplierData, 0, len(resp.Data.Data)) + // 转换数据 for _, item := range resp.Data.Data { - toolResp.Data = append(toolResp.Data, &OrderAfterSaleSupplierData{ + orderList = append(orderList, &OrderAfterSaleSupplierData{ SerialNumber: item.SerialNumber, PlatformName: item.PlatformName, SignCompany: item.SignCompany, @@ -173,21 +238,14 @@ func (t *OrderAfterSaleSupplierTool) checkOrderAfterSaleSupplier(toolReq OrderAf } // 追加扩展数据 - for _, item := range toolResp.Data { + for _, item := range orderList { if extItem, ok := resp.Data.ExtData[item.SerialNumber]; ok { item.IsExistsAfterSale = extItem.IsExistsAfterSale item.ExecuteTime = extItem.SerialCreateTime } } - jsonByte, err := json.Marshal(toolResp) - if err != nil { - return err - } - - entitys.ResLog(requireData.Ch, t.Name(), "售后订单信息拉取完成") - entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) - return nil + return orderList, nil } // mock待删除 From 43522037db954c802503a2be1bd13ccb6bb9f949 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Wed, 26 Nov 2025 18:14:26 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=E4=B8=8A=E6=B8=B8=E5=94=AE?= =?UTF-8?q?=E5=90=8E=E6=8E=A5=E5=85=A5=E5=AE=9E=E9=99=85zltx=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config_test.yaml | 6 +- internal/pkg/util/string.go | 7 ++ internal/tools/zltx/order_after_supplier.go | 103 +++++--------------- 3 files changed, 32 insertions(+), 84 deletions(-) diff --git a/config/config_test.yaml b/config/config_test.yaml index 8134c01..9b9066c 100644 --- a/config/config_test.yaml +++ b/config/config_test.yaml @@ -57,13 +57,13 @@ tools: api_secret: "ObqxwyR20r9rVNhju0sCPQyQA98_FZSc32W4vgxnGFH_b02HZr1BPCJsOAF816nu" zltxOrderAfterSaleSupplier: enabled: true - base_url: "https://revcl.1688sup.com/api/admin/afterSales/reseller_supplier" + base_url: "https://gateway.dev.cdlsxd.cn/zltx_api/admin/afterSales/directs" zltxOrderAfterSaleReseller: enabled: true - base_url: "https://revcl.1688sup.com/api/admin/afterSales/reseller_supplier" + base_url: "https://gateway.dev.cdlsxd.cn/zltx_api/admin/afterSales/reseller_pre_ai" zltxOrderAfterSaleResellerBatch: enabled: true - base_url: "https://revcl.1688sup.com/api/admin/afterSales/reseller_supplier_batch" + base_url: "https://gateway.dev.cdlsxd.cn/zltx_api/admin/afterSales/reseller_pre_ai" diff --git a/internal/pkg/util/string.go b/internal/pkg/util/string.go index 81b7e29..e179c4a 100644 --- a/internal/pkg/util/string.go +++ b/internal/pkg/util/string.go @@ -2,6 +2,7 @@ package util import ( "encoding/json" + "strconv" "strings" ) @@ -19,3 +20,9 @@ func EscapeJSONString(s string) string { b, _ := json.Marshal(s) return string(b[1 : len(b)-1]) } + +// string 转 int +func StringToInt(s string) int { + i, _ := strconv.Atoi(s) + return i +} diff --git a/internal/tools/zltx/order_after_supplier.go b/internal/tools/zltx/order_after_supplier.go index 805c38a..321f2aa 100644 --- a/internal/tools/zltx/order_after_supplier.go +++ b/internal/tools/zltx/order_after_supplier.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" @@ -41,7 +42,7 @@ type OrderAfterSaleSupplierRequest struct { SerialCreateTime string `json:"serialCreateTime"` // 流水创建时间 AfterSalesReason string `json:"afterSalesReason"` // 售后原因 AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额 - AfterType int `json:"afterType"` // 售后类型 1.加款 2.扣款 + AfterType string `json:"afterType"` // 售后类型 1.加款 2.扣款 } // 工具最终返回 @@ -63,7 +64,7 @@ type OrderAfterSaleSupplierData struct { PlatformID int `json:"platformId"` // 上游平台id SignCompanyName string `json:"signCompanyName"` // 签约主体名称 Reason string `json:"reason"` // 售后原因 - SalePrice float64 `json:"salePrice"` // 售后金额 + SalePrice string `json:"salePrice"` // 售后金额 SaleType int `json:"saleType"` // 处理方式 1.加款 2.扣款 ExecuteTime int `json:"executeTime"` // 流水创建时间 IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 @@ -71,13 +72,13 @@ type OrderAfterSaleSupplierData struct { // 接口返回 type OrderAfterSaleSupplierApiResponse struct { - Code int `json:"code"` - Msg string `json:"msg"` - Data OrderAfterSaleSupplierApiData `json:"data"` + Code int `json:"code"` + Error string `json:"error"` + Data OrderAfterSaleSupplierApiData `json:"data"` } type OrderAfterSaleSupplierApiData struct { Data []OrderAfterSaleSupplierApiBase `json:"data"` - ExtData map[string]OrderAfterSaleSupplierApiExtItem `json:"ext"` + ExtData map[string]OrderAfterSaleSupplierApiExtItem `json:"extraData"` } type OrderAfterSaleSupplierApiBase struct { SerialNumber string `json:"serialNumber"` // 流水号 @@ -90,13 +91,11 @@ type OrderAfterSaleSupplierApiBase struct { PlatformProductID int `json:"platformProductId"` // 上有商品id PlatformID int `json:"platformId"` // 上游平台id SignCompanyName string `json:"signCompanyName"` // 签约主体名称 - Reason string `json:"reason"` // 售后原因 - SalePrice float64 `json:"salePrice"` // 售后金额 - SaleType int `json:"saleType"` // 处理方式 1.加款 2.扣款 + ExecuteTime int `json:"executeTime"` // 充值执行时间 } type OrderAfterSaleSupplierApiExtItem struct { - IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 - SerialCreateTime int `json:"serialCreateTime"` // 流水创建时间 + IsExistsAfterSale bool `json:"existAfterSales"` // 是否已存在售后 + SerialCreateTime int `json:"createTime"` // 流水创建时间 } func (t *OrderAfterSaleSupplierTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { @@ -110,7 +109,7 @@ func (t *OrderAfterSaleSupplierTool) Execute(ctx context.Context, requireData *e entitys.ResLog(requireData.Ch, t.Name(), "正在拉取售后订单信息") - return t.checkOrderAfterSaleSupplierMock(req, requireData) + return t.checkOrderAfterSaleSupplier(req, requireData) } func (t *OrderAfterSaleSupplierTool) checkOrderAfterSaleSupplier(toolReq OrderAfterSaleSupplierRequest, requireData *entitys.RequireData) error { @@ -138,9 +137,9 @@ func (t *OrderAfterSaleSupplierTool) checkOrderAfterSaleSupplier(toolReq OrderAf // 多流水号 if len(toolReq.SerialNumber) > 0 { body := map[string]any{ - "serialNumber": toolReq.SerialNumber, // 流水号 + "serial_numbers": toolReq.SerialNumber, // 流水号 } - orderList, err = t.getAfterSaleSupplierList(headers, body) + orderList, err = t.getAfterSaleSupplierList(headers, body, toolReq) if err != nil { return err } @@ -156,11 +155,10 @@ func (t *OrderAfterSaleSupplierTool) checkOrderAfterSaleSupplier(toolReq OrderAf defer waitGroup.Done() body := map[string]any{ - "account": account, // 充值账号 - "serialStartTime": serialStartTime, // 流水创建时间 - "serialEndTime": serialEndTime, // 流水结束时间 + "account": account, // 充值账号 + "create_time": []int64{serialStartTime, serialEndTime}, // 流水创建时间区间 } - orderListIn, errIn := t.getAfterSaleSupplierList(headers, body) + orderListIn, errIn := t.getAfterSaleSupplierList(headers, body, toolReq) if errIn != nil { return } @@ -196,7 +194,7 @@ func (t *OrderAfterSaleSupplierTool) checkOrderAfterSaleSupplier(toolReq OrderAf return nil } -func (t *OrderAfterSaleSupplierTool) getAfterSaleSupplierList(headers map[string]string, body map[string]any) ([]*OrderAfterSaleSupplierData, error) { +func (t *OrderAfterSaleSupplierTool) getAfterSaleSupplierList(headers map[string]string, body map[string]any, originInput OrderAfterSaleSupplierRequest) ([]*OrderAfterSaleSupplierData, error) { req := l_request.Request{ Url: t.config.BaseURL, Headers: headers, @@ -212,8 +210,8 @@ func (t *OrderAfterSaleSupplierTool) getAfterSaleSupplierList(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 supplier failed: %s", resp.Msg) + if resp.Code != 200 { + return nil, fmt.Errorf("after sale supplier failed: %s", resp.Error) } orderList := make([]*OrderAfterSaleSupplierData, 0, len(resp.Data.Data)) @@ -231,9 +229,9 @@ func (t *OrderAfterSaleSupplierTool) getAfterSaleSupplierList(headers map[string PlatformProductID: item.PlatformProductID, PlatformID: item.PlatformID, SignCompanyName: item.SignCompanyName, - Reason: item.Reason, - SalePrice: item.SalePrice, - SaleType: item.SaleType, + Reason: originInput.AfterSalesReason, + SalePrice: originInput.AfterSalesPrice, + SaleType: util.StringToInt(originInput.AfterType), }) } @@ -247,60 +245,3 @@ func (t *OrderAfterSaleSupplierTool) getAfterSaleSupplierList(headers map[string return orderList, nil } - -// mock待删除 -func (t *OrderAfterSaleSupplierTool) checkOrderAfterSaleSupplierMock(req OrderAfterSaleSupplierRequest, requireData *entitys.RequireData) error { - resp := OrderAfterSaleSupplierResponse{ - Code: 0, - Msg: "success", - Data: []*OrderAfterSaleSupplierData{ - { - SerialNumber: "847465394004430849", - PlatformName: "爱奇艺", - SignCompany: 1, - PlatformProductName: "爱奇艺官方周卡", - PlatformPrice: 6, - TerminalAccount: "15516353308", - Status: 1, - PlatformProductID: 2, - PlatformID: 4, - SignCompanyName: "成都蓝色兄弟网络科技有限公司", - ExecuteTime: 1763961931, - Reason: "测试售后", - SalePrice: 50, - SaleType: 1, - IsExistsAfterSale: false, - }, - { - SerialNumber: "843493448012140545", - PlatformName: "卓望别名1", - SignCompany: 1, - PlatformProductName: "卓望--别名商品1", - PlatformPrice: 897.7765, - TerminalAccount: "18380416326", - Status: -1, - PlatformProductID: 7497, - PlatformID: 15, - SignCompanyName: "成都蓝色兄弟网络科技有限公司", - ExecuteTime: 1763014914, - Reason: "测试售后2", - SalePrice: 30, - SaleType: 2, - IsExistsAfterSale: true, - }, - }, - } - - if len(req.SerialNumber) == 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 -} 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 4/4] =?UTF-8?q?feat:=20=E4=B8=8B=E6=B8=B8=E5=94=AE?= =?UTF-8?q?=E5=90=8E=EF=BC=88=E6=89=B9=E5=85=85=E3=80=81=E7=9B=B4=E5=85=85?= =?UTF-8?q?=EF=BC=89zltx=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