feat(config): 添加售后接口
This commit is contained in:
parent
8cb59f656b
commit
687678e7d5
|
|
@ -55,6 +55,15 @@ tools:
|
||||||
enabled: true
|
enabled: true
|
||||||
api_key: "dingsbbntrkeiyazcfdg"
|
api_key: "dingsbbntrkeiyazcfdg"
|
||||||
api_secret: "ObqxwyR20r9rVNhju0sCPQyQA98_FZSc32W4vgxnGFH_b02HZr1BPCJsOAF816nu"
|
api_secret: "ObqxwyR20r9rVNhju0sCPQyQA98_FZSc32W4vgxnGFH_b02HZr1BPCJsOAF816nu"
|
||||||
|
zltxOrderAfterSaleDetail:
|
||||||
|
enabled: true
|
||||||
|
base_url: "https://revcl.1688sup.com/api/admin/afterSales/direct/%s"
|
||||||
|
api_key : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyQ2VudGVyIiwiZXhwIjoxNzU2MTgyNTM1LCJuYmYiOjE3NTYxODA3MzUsImp0aSI6IjEiLCJQaG9uZSI6IjE4MDAwMDAwMDAwIiwiVXNlck5hbWUiOiJsc3hkIiwiUmVhbE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJBY2NvdW50VHlwZSI6MSwiR3JvdXBDb2RlcyI6IlZDTF9DQVNISUVSLFZDTF9PUEVSQVRFLFZDTF9BRE1JTixWQ0xfQUFBLFZDTF9WQ0xfT1BFUkFULFZDTF9JTlZPSUNFLENSTV9BRE1JTixMSUFOTElBTl9BRE1JTixNQVJLRVRNQUcyX0FETUlOLFBIT05FQklMTF9BRE1JTixRSUFOWkhVX1NVUFBFUl9BRE0sTUFSS0VUSU5HU0FBU19TVVBFUkFETUlOLENBUkRfQ09ERSxDQVJEX1BST0NVUkVNRU5ULE1BUktFVElOR1NZU1RFTV9TVVBFUixTVEFUSVNUSUNBTFNZU1RFTV9BRE1JTixaTFRYX0FETUlOLFpMVFhfT1BFUkFURSIsIkRpbmdVc2VySWQiOiIxNjIwMjYxMjMwMjg5MzM4MzQifQ.N1xv1PYbcO8_jR5adaczc16YzGsr4z101gwEZdulkRaREBJNYTOnFrvRxTFx3RJTooXsqTqroE1MR84v_1WPX6BS6kKonA-kC1Jgot6yrt5rFWhGNGb2Cpr9rKIFCCQYmiGd3AUgDazEeaQ0_sodv3E-EXg9VfE1SX8nMcck9Yjnc8NCy7RTWaBIaSeOdZcEl-JfCD0S6GSx3oErp_hk-U9FKGwf60wAuDGTY1R0BP4BYpcEqS-C2LSnsSGyURi54Cuk5xH8r1WuF0Dm5bwAj5d7Hvs77-N_sUF-C5ONqyZJRAEhYLgcmN9RX_WQZfizdQJxizlTczdpzYfy-v-1eQ"
|
||||||
|
zltxOrderAfterSalePreCheck:
|
||||||
|
enabled: true
|
||||||
|
base_url: "https://gateway.dev.cdlsxd.cn/zltx_api/admin/afterSales/reseller_pre"
|
||||||
|
api_key : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyQ2VudGVyIiwiZXhwIjoxNzU2MTgyNTM1LCJuYmYiOjE3NTYxODA3MzUsImp0aSI6IjEiLCJQaG9uZSI6IjE4MDAwMDAwMDAwIiwiVXNlck5hbWUiOiJsc3hkIiwiUmVhbE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJBY2NvdW50VHlwZSI6MSwiR3JvdXBDb2RlcyI6IlZDTF9DQVNISUVSLFZDTF9PUEVSQVRFLFZDTF9BRE1JTixWQ0xfQUFBLFZDTF9WQ0xfT1BFUkFULFZDTF9JTlZPSUNFLENSTV9BRE1JTixMSUFOTElBTl9BRE1JTixNQVJLRVRNQUcyX0FETUlOLFBIT05FQklMTF9BRE1JTixRSUFOWkhVX1NVUFBFUl9BRE0sTUFSS0VUSU5HU0FBU19TVVBFUkFETUlOLENBUkRfQ09ERSxDQVJEX1BST0NVUkVNRU5ULE1BUktFVElOR1NZU1RFTV9TVVBFUixTVEFUSVNUSUNBTFNZU1RFTV9BRE1JTixaTFRYX0FETUlOLFpMVFhfT1BFUkFURSIsIkRpbmdVc2VySWQiOiIxNjIwMjYxMjMwMjg5MzM4MzQifQ.N1xv1PYbcO8_jR5adaczc16YzGsr4z101gwEZdulkRaREBJNYTOnFrvRxTFx3RJTooXsqTqroE1MR84v_1WPX6BS6kKonA-kC1Jgot6yrt5rFWhGNGb2Cpr9rKIFCCQYmiGd3AUgDazEeaQ0_sodv3E-EXg9VfE1SX8nMcck9Yjnc8NCy7RTWaBIaSeOdZcEl-JfCD0S6GSx3oErp_hk-U9FKGwf60wAuDGTY1R0BP4BYpcEqS-C2LSnsSGyURi54Cuk5xH8r1WuF0Dm5bwAj5d7Hvs77-N_sUF-C5ONqyZJRAEhYLgcmN9RX_WQZfizdQJxizlTczdpzYfy-v-1eQ"
|
||||||
|
|
||||||
|
|
||||||
default_prompt:
|
default_prompt:
|
||||||
img_recognize:
|
img_recognize:
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,10 @@ type ToolsConfig struct {
|
||||||
//通过账号获取订单统计信息
|
//通过账号获取订单统计信息
|
||||||
ZltxOrderStatistics ToolConfig `mapstructure:"zltxOrderStatistics"`
|
ZltxOrderStatistics ToolConfig `mapstructure:"zltxOrderStatistics"`
|
||||||
DingTalkBot ToolConfig `mapstructure:"dingTalkBot"`
|
DingTalkBot ToolConfig `mapstructure:"dingTalkBot"`
|
||||||
|
//上游售后订单流水详情
|
||||||
|
ZltxOrderAfterSaleDetail ToolConfig `mapstructure:"zltxOrderAfterSaleDetail"`
|
||||||
|
//下游订单预检
|
||||||
|
ZltxOrderAfterSalePreCheck ToolConfig `mapstructure:"zltxOrderAfterSalePreCheck"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToolConfig 单个工具配置
|
// ToolConfig 单个工具配置
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,17 @@ func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager {
|
||||||
knowledgeTool := NewKnowledgeBaseTool(config.Tools.Knowledge)
|
knowledgeTool := NewKnowledgeBaseTool(config.Tools.Knowledge)
|
||||||
m.tools[knowledgeTool.Name()] = knowledgeTool
|
m.tools[knowledgeTool.Name()] = knowledgeTool
|
||||||
}
|
}
|
||||||
|
//注册直连天下售后订单详情工具
|
||||||
|
if config.Tools.ZltxOrderAfterSaleDetail.Enabled {
|
||||||
|
zltxOrderAfterSaleDetailTool := NewZltxOrderAfterSaleDetailTool(config.Tools.ZltxOrderAfterSaleDetail)
|
||||||
|
m.tools[zltxOrderAfterSaleDetailTool.Name()] = zltxOrderAfterSaleDetailTool
|
||||||
|
}
|
||||||
|
//注册直连天下售后订单预检工具
|
||||||
|
if config.Tools.ZltxOrderAfterSalePreCheck.Enabled {
|
||||||
|
zltxOrderAfterSalePreCheckTool := NewZltxOrderAfterSalePreCheckTool(config.Tools.ZltxOrderAfterSalePreCheck)
|
||||||
|
m.tools[zltxOrderAfterSalePreCheckTool.Name()] = zltxOrderAfterSalePreCheckTool
|
||||||
|
}
|
||||||
|
|
||||||
// 普通对话
|
// 普通对话
|
||||||
chat := NewNormalChatTool(m.llm, config)
|
chat := NewNormalChatTool(m.llm, config)
|
||||||
m.tools[chat.Name()] = chat
|
m.tools[chat.Name()] = chat
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,119 @@
|
||||||
|
package tools
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ai_scheduler/internal/config"
|
||||||
|
"ai_scheduler/internal/entitys"
|
||||||
|
"ai_scheduler/internal/pkg/l_request"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ZltxOrderAfterSaleDetailTool struct {
|
||||||
|
config config.ToolConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewZltxOrderAfterSaleDetailTool 创建售后订单详情工具
|
||||||
|
func NewZltxOrderAfterSaleDetailTool(config config.ToolConfig) *ZltxOrderAfterSaleDetailTool {
|
||||||
|
return &ZltxOrderAfterSaleDetailTool{config: config}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Definition 返回工具定义
|
||||||
|
func (this *ZltxOrderAfterSaleDetailTool) Definition() entitys.ToolDefinition {
|
||||||
|
return entitys.ToolDefinition{
|
||||||
|
Type: "function",
|
||||||
|
Function: entitys.FunctionDef{
|
||||||
|
Name: this.Name(),
|
||||||
|
Description: this.Description(),
|
||||||
|
Parameters: map[string]interface{}{
|
||||||
|
"type": "object",
|
||||||
|
"properties": map[string]interface{}{
|
||||||
|
"direct_order_number": map[string]interface{}{
|
||||||
|
"type": "string",
|
||||||
|
"description": "售后订单号",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"required": []string{"direct_order_number"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type ZltxOrderAfterSaleDetailRequest struct {
|
||||||
|
DirectOrderNumber string `json:"direct_order_number"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ZltxOrderAfterSaleDetailResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data struct {
|
||||||
|
AfterSaleOrder ZltxOrderAfterSaleDetailData `json:"afterSaleOrder"`
|
||||||
|
} `json:"data"`
|
||||||
|
Error string `json:"error"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ZltxOrderAfterSaleDetailData struct {
|
||||||
|
SerialNumber string `json:"serialNumber"`
|
||||||
|
PlatformName string `json:"platformName"`
|
||||||
|
SignCompany int `json:"signCompany"`
|
||||||
|
PlatformProductName string `json:"platformProductName"`
|
||||||
|
PlatformPrice float64 `json:"platformPrice"`
|
||||||
|
TerminalAccount string `json:"terminalAccount"`
|
||||||
|
Status int `json:"status"`
|
||||||
|
PlatformProductID int `json:"platformProductId"`
|
||||||
|
PlatformID int `json:"platformId"`
|
||||||
|
SignCompanyName string `json:"signCompanyName"`
|
||||||
|
ExecuteTime int `json:"executeTime"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ZltxOrderAfterSaleDetailTool) Execute(ctx context.Context, requireData *entitys.RequireData) error {
|
||||||
|
var req ZltxOrderAfterSaleDetailRequest
|
||||||
|
if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if req.DirectOrderNumber == "" {
|
||||||
|
return fmt.Errorf("direct_order_number is required")
|
||||||
|
}
|
||||||
|
return this.getZltxOrderAfterSaleDetail(ctx, requireData, req.DirectOrderNumber)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ZltxOrderAfterSaleDetailTool) getZltxOrderAfterSaleDetail(ctx context.Context, requireData *entitys.RequireData, directOrderNumber string) error {
|
||||||
|
//查询订单详情
|
||||||
|
url := fmt.Sprintf("%s%s", this.config.BaseURL, directOrderNumber)
|
||||||
|
req := l_request.Request{
|
||||||
|
Url: url,
|
||||||
|
Headers: map[string]string{
|
||||||
|
"Authorization": fmt.Sprintf("Bearer %s", requireData.Auth),
|
||||||
|
},
|
||||||
|
Method: "GET",
|
||||||
|
}
|
||||||
|
res, err := req.Send()
|
||||||
|
var resData ZltxOrderAfterSaleDetailResponse
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(res.Content, &resData); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if resData.Code != 200 {
|
||||||
|
return fmt.Errorf("为获取到数据,请检查权限: %s", string(res.Content))
|
||||||
|
}
|
||||||
|
jsonByte, err := json.Marshal(resData)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
entitys.ResJson(requireData.Ch, this.Name(), string(jsonByte))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ZltxOrderAfterSaleDetailTool) GetConfig() config.ToolConfig {
|
||||||
|
return this.config
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name 工具名称
|
||||||
|
func (this *ZltxOrderAfterSaleDetailTool) Name() string {
|
||||||
|
return "zltx_order_after_sale_detail"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ZltxOrderAfterSaleDetailTool) Description() string {
|
||||||
|
return "查询直连天下上游售后订单详情"
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,125 @@
|
||||||
|
package tools
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ai_scheduler/internal/config"
|
||||||
|
"ai_scheduler/internal/entitys"
|
||||||
|
"ai_scheduler/internal/pkg/l_request"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ZltxOrderAfterSalePreCheckTool struct {
|
||||||
|
config config.ToolConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewZltxOrderAfterSalePreCheckTool 创建售后订单预检工具
|
||||||
|
func NewZltxOrderAfterSalePreCheckTool(config config.ToolConfig) *ZltxOrderAfterSalePreCheckTool {
|
||||||
|
return &ZltxOrderAfterSalePreCheckTool{config: config}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name 返回工具名称
|
||||||
|
func (t *ZltxOrderAfterSalePreCheckTool) Name() string {
|
||||||
|
return "zltxOrderAfterSalePreCheck"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *ZltxOrderAfterSalePreCheckTool) Description() string {
|
||||||
|
return "直连天下售后订单预检工具"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *ZltxOrderAfterSalePreCheckTool) Definition() entitys.ToolDefinition {
|
||||||
|
return entitys.ToolDefinition{
|
||||||
|
Type: "function",
|
||||||
|
Function: entitys.FunctionDef{
|
||||||
|
Name: t.Name(),
|
||||||
|
Description: t.Description(),
|
||||||
|
Parameters: map[string]interface{}{
|
||||||
|
"type": "object",
|
||||||
|
"properties": map[string]interface{}{
|
||||||
|
"orderType": map[string]interface{}{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "售后订单类型",
|
||||||
|
},
|
||||||
|
"orderNumber": map[string]interface{}{
|
||||||
|
"type": "string",
|
||||||
|
"description": "售后订单号",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"required": []string{"orderType", "orderNumber"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type ZltxOrderAfterSalePreCheckRequest struct {
|
||||||
|
OrderType int `json:"orderType"`
|
||||||
|
OrderNumber string `json:"orderNumber"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ZltxOrderAfterSalePreCheckResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Msg string `json:"msg"`
|
||||||
|
Data struct {
|
||||||
|
CheckResult bool `json:"checkResult"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CheckResult struct {
|
||||||
|
OrderType int `json:"orderType"`
|
||||||
|
OrderNumber string `json:"orderNumber"`
|
||||||
|
OrderAmount float64 `json:"orderAmount"`
|
||||||
|
OrderPrice float64 `json:"orderPrice"`
|
||||||
|
SignCompany int `json:"signCompany"`
|
||||||
|
OrderQuantity int `json:"orderQuantity"`
|
||||||
|
ResellerID int `json:"resellerId"`
|
||||||
|
ResellerName string `json:"resellerName"`
|
||||||
|
OurProductID int `json:"ourProductId"`
|
||||||
|
OurProductTitle string `json:"ourProductTitle"`
|
||||||
|
Account []string `json:"account"`
|
||||||
|
Platforms struct {
|
||||||
|
Num4 string `json:"4"`
|
||||||
|
} `json:"platforms"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *ZltxOrderAfterSalePreCheckTool) Execute(ctx context.Context, requireData *entitys.RequireData) error {
|
||||||
|
var req ZltxOrderAfterSalePreCheckRequest
|
||||||
|
if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if req.OrderType == 0 || req.OrderNumber == "" {
|
||||||
|
return fmt.Errorf("orderType and orderNumber are required")
|
||||||
|
}
|
||||||
|
return t.checkZltxOrderAfterSalePreCheck(req.OrderType, req.OrderNumber, requireData)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *ZltxOrderAfterSalePreCheckTool) checkZltxOrderAfterSalePreCheck(orderType int, orderNumber string, requireData *entitys.RequireData) error {
|
||||||
|
req := l_request.Request{
|
||||||
|
Url: t.config.BaseURL,
|
||||||
|
Headers: map[string]string{
|
||||||
|
"Authorization": fmt.Sprintf("Bearer %s", requireData.Auth),
|
||||||
|
},
|
||||||
|
Method: "POST",
|
||||||
|
Data: map[string]string{
|
||||||
|
"orderType": fmt.Sprintf("%d", orderType),
|
||||||
|
"orderNumber": orderNumber,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
res, err := req.Send()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// 解析响应
|
||||||
|
var resp ZltxOrderAfterSalePreCheckResponse
|
||||||
|
if err := json.Unmarshal(res.Content, &resp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if resp.Code != 0 {
|
||||||
|
return fmt.Errorf("check failed: %s", resp.Msg)
|
||||||
|
}
|
||||||
|
jsonByte, err := json.Marshal(resp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue