Merge branch 'v3' into test
This commit is contained in:
commit
1b423fc509
|
|
@ -55,6 +55,15 @@ tools:
|
|||
enabled: true
|
||||
api_key: "dingsbbntrkeiyazcfdg"
|
||||
api_secret: "ObqxwyR20r9rVNhju0sCPQyQA98_FZSc32W4vgxnGFH_b02HZr1BPCJsOAF816nu"
|
||||
zltxOrderAfterSaleDetail:
|
||||
enabled: true
|
||||
base_url: "https://revcl.1688sup.com/api/admin/afterSales/direct/%s"
|
||||
api_key : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyQ2VudGVyIiwiZXhwIjoxNzU2MTgyNTM1LCJuYmYiOjE3NTYxODA3MzUsImp0aSI6IjEiLCJQaG9uZSI6IjE4MDAwMDAwMDAwIiwiVXNlck5hbWUiOiJsc3hkIiwiUmVhbE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJBY2NvdW50VHlwZSI6MSwiR3JvdXBDb2RlcyI6IlZDTF9DQVNISUVSLFZDTF9PUEVSQVRFLFZDTF9BRE1JTixWQ0xfQUFBLFZDTF9WQ0xfT1BFUkFULFZDTF9JTlZPSUNFLENSTV9BRE1JTixMSUFOTElBTl9BRE1JTixNQVJLRVRNQUcyX0FETUlOLFBIT05FQklMTF9BRE1JTixRSUFOWkhVX1NVUFBFUl9BRE0sTUFSS0VUSU5HU0FBU19TVVBFUkFETUlOLENBUkRfQ09ERSxDQVJEX1BST0NVUkVNRU5ULE1BUktFVElOR1NZU1RFTV9TVVBFUixTVEFUSVNUSUNBTFNZU1RFTV9BRE1JTixaTFRYX0FETUlOLFpMVFhfT1BFUkFURSIsIkRpbmdVc2VySWQiOiIxNjIwMjYxMjMwMjg5MzM4MzQifQ.N1xv1PYbcO8_jR5adaczc16YzGsr4z101gwEZdulkRaREBJNYTOnFrvRxTFx3RJTooXsqTqroE1MR84v_1WPX6BS6kKonA-kC1Jgot6yrt5rFWhGNGb2Cpr9rKIFCCQYmiGd3AUgDazEeaQ0_sodv3E-EXg9VfE1SX8nMcck9Yjnc8NCy7RTWaBIaSeOdZcEl-JfCD0S6GSx3oErp_hk-U9FKGwf60wAuDGTY1R0BP4BYpcEqS-C2LSnsSGyURi54Cuk5xH8r1WuF0Dm5bwAj5d7Hvs77-N_sUF-C5ONqyZJRAEhYLgcmN9RX_WQZfizdQJxizlTczdpzYfy-v-1eQ"
|
||||
zltxOrderAfterSalePreCheck:
|
||||
enabled: true
|
||||
base_url: "https://gateway.dev.cdlsxd.cn/zltx_api/admin/afterSales/reseller_pre"
|
||||
api_key : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyQ2VudGVyIiwiZXhwIjoxNzU2MTgyNTM1LCJuYmYiOjE3NTYxODA3MzUsImp0aSI6IjEiLCJQaG9uZSI6IjE4MDAwMDAwMDAwIiwiVXNlck5hbWUiOiJsc3hkIiwiUmVhbE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJBY2NvdW50VHlwZSI6MSwiR3JvdXBDb2RlcyI6IlZDTF9DQVNISUVSLFZDTF9PUEVSQVRFLFZDTF9BRE1JTixWQ0xfQUFBLFZDTF9WQ0xfT1BFUkFULFZDTF9JTlZPSUNFLENSTV9BRE1JTixMSUFOTElBTl9BRE1JTixNQVJLRVRNQUcyX0FETUlOLFBIT05FQklMTF9BRE1JTixRSUFOWkhVX1NVUFBFUl9BRE0sTUFSS0VUSU5HU0FBU19TVVBFUkFETUlOLENBUkRfQ09ERSxDQVJEX1BST0NVUkVNRU5ULE1BUktFVElOR1NZU1RFTV9TVVBFUixTVEFUSVNUSUNBTFNZU1RFTV9BRE1JTixaTFRYX0FETUlOLFpMVFhfT1BFUkFURSIsIkRpbmdVc2VySWQiOiIxNjIwMjYxMjMwMjg5MzM4MzQifQ.N1xv1PYbcO8_jR5adaczc16YzGsr4z101gwEZdulkRaREBJNYTOnFrvRxTFx3RJTooXsqTqroE1MR84v_1WPX6BS6kKonA-kC1Jgot6yrt5rFWhGNGb2Cpr9rKIFCCQYmiGd3AUgDazEeaQ0_sodv3E-EXg9VfE1SX8nMcck9Yjnc8NCy7RTWaBIaSeOdZcEl-JfCD0S6GSx3oErp_hk-U9FKGwf60wAuDGTY1R0BP4BYpcEqS-C2LSnsSGyURi54Cuk5xH8r1WuF0Dm5bwAj5d7Hvs77-N_sUF-C5ONqyZJRAEhYLgcmN9RX_WQZfizdQJxizlTczdpzYfy-v-1eQ"
|
||||
|
||||
|
||||
default_prompt:
|
||||
img_recognize:
|
||||
|
|
|
|||
|
|
@ -55,6 +55,12 @@ tools:
|
|||
enabled: true
|
||||
api_key: "dingsbbntrkeiyazcfdg"
|
||||
api_secret: "ObqxwyR20r9rVNhju0sCPQyQA98_FZSc32W4vgxnGFH_b02HZr1BPCJsOAF816nu"
|
||||
zltxOrderAfterSaleSupplier:
|
||||
enabled: true
|
||||
base_url: "https://revcl.1688sup.com/api/admin/afterSales/reseller_supplier"
|
||||
zltxOrderAfterSaleReseller:
|
||||
enabled: true
|
||||
base_url: "https://revcl.1688sup.com/api/admin/afterSales/reseller_supplier"
|
||||
|
||||
default_prompt:
|
||||
img_recognize:
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"gorm.io/gorm/utils"
|
||||
"strings"
|
||||
|
||||
"gorm.io/gorm/utils"
|
||||
)
|
||||
|
||||
type Handle struct {
|
||||
|
|
@ -95,10 +95,10 @@ func (r *Handle) HandleMatch(ctx context.Context, client *gateway.Client, requir
|
|||
}
|
||||
|
||||
// 校验用户权限
|
||||
if err = r.PermissionAuth(client, pointTask); err != nil {
|
||||
log.Errorf("权限验证失败: %s", err.Error())
|
||||
return
|
||||
}
|
||||
// if err = r.PermissionAuth(client, pointTask); err != nil {
|
||||
// log.Errorf("权限验证失败: %s", err.Error())
|
||||
// return
|
||||
// }
|
||||
|
||||
switch constants.TaskType(pointTask.Type) {
|
||||
case constants.TaskTypeApi:
|
||||
|
|
|
|||
|
|
@ -90,6 +90,14 @@ 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"`
|
||||
}
|
||||
|
||||
// ToolConfig 单个工具配置
|
||||
|
|
|
|||
|
|
@ -3,5 +3,8 @@ package constants
|
|||
type BotTools string
|
||||
|
||||
const (
|
||||
BotToolsBugOptimizationSubmit = "bug_optimization_submit" // 系统的bug/优化建议
|
||||
BotToolsBugOptimizationSubmit = "bug_optimization_submit" // 系统的bug/优化建议
|
||||
BotToolsAfterSalesSupplier = "after_sales_supplier" // 供应商售后
|
||||
BotToolsAfterSalesResellerSingle = "after_sales_reseller_single" // 分销商单条售后
|
||||
BotToolsAfterSalesResellerBatch = "after_sales_reseller_batch" // 分销商批量售后
|
||||
)
|
||||
|
|
|
|||
|
|
@ -9,11 +9,12 @@ import (
|
|||
"ai_scheduler/internal/gateway"
|
||||
"ai_scheduler/internal/pkg/l_request"
|
||||
"encoding/json"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/websocket/v2"
|
||||
"log"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/websocket/v2"
|
||||
)
|
||||
|
||||
// ChatHandler 聊天处理器
|
||||
|
|
|
|||
|
|
@ -70,10 +70,28 @@ func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager {
|
|||
m.tools[knowledgeTool.Name()] = knowledgeTool
|
||||
}
|
||||
|
||||
if config.Tools.Knowledge.Enabled {
|
||||
knowledgeTool := NewKnowledgeBaseTool(config.Tools.Knowledge)
|
||||
m.tools[knowledgeTool.Name()] = knowledgeTool
|
||||
//注册直连天下售后订单详情工具
|
||||
if config.Tools.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)
|
||||
m.tools[zltxOrderAfterSaleSupplierTool.Name()] = zltxOrderAfterSaleSupplierTool
|
||||
}
|
||||
// 注册直连天下下游售后订单工具
|
||||
if config.Tools.ZltxOrderAfterSaleReseller.Enabled {
|
||||
zltxOrderAfterSaleResellerTool := NewZltxOrderAfterSaleResellerTool(config.Tools.ZltxOrderAfterSaleReseller)
|
||||
m.tools[zltxOrderAfterSaleResellerTool.Name()] = zltxOrderAfterSaleResellerTool
|
||||
}
|
||||
|
||||
// 普通对话
|
||||
chat := NewNormalChatTool(m.llm, config)
|
||||
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
|
||||
}
|
||||
|
|
@ -0,0 +1,175 @@
|
|||
package tools
|
||||
|
||||
import (
|
||||
"ai_scheduler/internal/config"
|
||||
"ai_scheduler/internal/entitys"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ZltxOrderAfterSaleResellerTool struct {
|
||||
config config.ToolConfig
|
||||
}
|
||||
|
||||
// NewZltxOrderAfterSaleResellerTool 创建售后订单预检工具
|
||||
func NewZltxOrderAfterSaleResellerTool(config config.ToolConfig) *ZltxOrderAfterSaleResellerTool {
|
||||
return &ZltxOrderAfterSaleResellerTool{config: config}
|
||||
}
|
||||
|
||||
// Name 返回工具名称
|
||||
func (t *ZltxOrderAfterSaleResellerTool) Name() string {
|
||||
return "zltxOrderAfterSaleReseller"
|
||||
}
|
||||
|
||||
func (t *ZltxOrderAfterSaleResellerTool) Description() string {
|
||||
return "直连天下上游供应商售后工具"
|
||||
}
|
||||
|
||||
func (t *ZltxOrderAfterSaleResellerTool) Definition() entitys.ToolDefinition {
|
||||
return entitys.ToolDefinition{
|
||||
Type: "function",
|
||||
Function: entitys.FunctionDef{
|
||||
Name: t.Name(),
|
||||
Description: t.Description(),
|
||||
Parameters: map[string]interface{}{
|
||||
"type": "object",
|
||||
"properties": map[string]interface{}{
|
||||
"orderType": map[string]interface{}{
|
||||
"type": "integer",
|
||||
"description": "售后订单类型",
|
||||
},
|
||||
"orderNumber": map[string]interface{}{
|
||||
"type": "string",
|
||||
"description": "售后订单号",
|
||||
},
|
||||
},
|
||||
"required": []string{"orderType", "orderNumber"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type ZltxOrderAfterSaleResellerRequest struct {
|
||||
OrderNumber string `json:"orderNumber"` // 订单号
|
||||
SerialNumber string `json:"serialNumber"` // 流水号
|
||||
Account string `json:"account"` // 充值账号
|
||||
OrderTimeStart string `json:"orderTimeStart"` // 订单执行开始时间
|
||||
OrderTimeEnd string `json:"orderTimeEnd"` // 订单执行结束时间
|
||||
AfterSalesReason string `json:"afterSalesReason"` // 售后原因
|
||||
AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额
|
||||
}
|
||||
|
||||
type ZltxOrderAfterSaleResellerResponse struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data []ZltxOrderAfterSaleResellerData `json:"data"`
|
||||
}
|
||||
|
||||
type ZltxOrderAfterSaleResellerData struct {
|
||||
OrderType int `json:"orderType"`
|
||||
OrderNumber string `json:"orderNumber"`
|
||||
OrderAmount float64 `json:"orderAmount"`
|
||||
OrderPrice float64 `json:"orderPrice"`
|
||||
SignCompany int `json:"signCompany"`
|
||||
OrderQuantity int `json:"orderQuantity"`
|
||||
ResellerID int `json:"resellerId"`
|
||||
ResellerName string `json:"resellerName"`
|
||||
OurProductID int `json:"ourProductId"`
|
||||
OurProductTitle string `json:"ourProductTitle"`
|
||||
Account []string `json:"account"`
|
||||
Platforms map[int]string `json:"platforms"`
|
||||
AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款
|
||||
Remark string `json:"remark"` // 售后原因
|
||||
AfterAmount float64 `json:"afterAmount"` // 售后金额
|
||||
ResponsibleType int `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无
|
||||
ResponsiblePerson string `json:"responsiblePerson"` // 费用承担供应商
|
||||
IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后
|
||||
}
|
||||
|
||||
func (t *ZltxOrderAfterSaleResellerTool) Execute(ctx context.Context, requireData *entitys.RequireData) error {
|
||||
var req ZltxOrderAfterSaleResellerRequest
|
||||
if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil {
|
||||
return err
|
||||
}
|
||||
if req.OrderNumber == "" {
|
||||
return fmt.Errorf("orderType and orderNumber are required")
|
||||
}
|
||||
return t.checkZltxOrderAfterSaleReseller(req.OrderNumber, requireData)
|
||||
}
|
||||
|
||||
func (t *ZltxOrderAfterSaleResellerTool) checkZltxOrderAfterSaleReseller(orderNumber string, requireData *entitys.RequireData) error {
|
||||
// req := l_request.Request{
|
||||
// Url: t.config.BaseURL,
|
||||
// Headers: map[string]string{
|
||||
// "Authorization": fmt.Sprintf("Bearer %s", requireData.Auth),
|
||||
// },
|
||||
// Method: "POST",
|
||||
// Data: map[string]string{
|
||||
// // "orderType": fmt.Sprintf("%d", orderType),
|
||||
// "orderNumber": orderNumber,
|
||||
// },
|
||||
// }
|
||||
// res, err := req.Send()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // 解析响应
|
||||
// var resp ZltxOrderAfterSaleResellerResponse
|
||||
// if err := json.Unmarshal(res.Content, &resp); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// if resp.Code != 0 {
|
||||
// return fmt.Errorf("check failed: %s", resp.Msg)
|
||||
// }
|
||||
resp := ZltxOrderAfterSaleResellerResponse{
|
||||
Code: 0,
|
||||
Msg: "success",
|
||||
Data: []ZltxOrderAfterSaleResellerData{
|
||||
{
|
||||
OrderType: 1,
|
||||
OrderNumber: "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: "爱奇艺"},
|
||||
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: "爱瓦力"},
|
||||
AfterType: 2,
|
||||
Remark: "测试售后2",
|
||||
AfterAmount: 30,
|
||||
ResponsibleType: 2,
|
||||
IsExistsAfterSale: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
jsonByte, err := json.Marshal(resp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte))
|
||||
return nil
|
||||
}
|
||||
|
|
@ -0,0 +1,181 @@
|
|||
package tools
|
||||
|
||||
import (
|
||||
"ai_scheduler/internal/config"
|
||||
"ai_scheduler/internal/entitys"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ZltxOrderAfterSaleSupplierTool struct {
|
||||
config config.ToolConfig
|
||||
}
|
||||
|
||||
// NewZltxOrderAfterSaleSupplierTool 创建售后订单预检工具
|
||||
func NewZltxOrderAfterSaleSupplierTool(config config.ToolConfig) *ZltxOrderAfterSaleSupplierTool {
|
||||
return &ZltxOrderAfterSaleSupplierTool{config: config}
|
||||
}
|
||||
|
||||
// Name 返回工具名称
|
||||
func (t *ZltxOrderAfterSaleSupplierTool) Name() string {
|
||||
return "zltxOrderAfterSaleSupplier"
|
||||
}
|
||||
|
||||
func (t *ZltxOrderAfterSaleSupplierTool) Description() string {
|
||||
return "直连天下上游供应商售后工具"
|
||||
}
|
||||
|
||||
func (t *ZltxOrderAfterSaleSupplierTool) Definition() entitys.ToolDefinition {
|
||||
return entitys.ToolDefinition{
|
||||
Type: "function",
|
||||
Function: entitys.FunctionDef{
|
||||
Name: t.Name(),
|
||||
Description: t.Description(),
|
||||
Parameters: map[string]interface{}{
|
||||
"type": "object",
|
||||
"properties": map[string]interface{}{
|
||||
"orderType": map[string]interface{}{
|
||||
"type": "integer",
|
||||
"description": "售后订单类型",
|
||||
},
|
||||
"orderNumber": map[string]interface{}{
|
||||
"type": "string",
|
||||
"description": "售后订单号",
|
||||
},
|
||||
},
|
||||
"required": []string{"orderType", "orderNumber"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type ZltxOrderAfterSaleSupplierRequest struct {
|
||||
OrderNumber string `json:"orderNumber"` // 订单号
|
||||
SerialNumber string `json:"serialNumber"` // 流水号
|
||||
Account string `json:"account"` // 充值账号
|
||||
OrderTimeStart string `json:"orderTimeStart"` // 订单执行开始时间
|
||||
OrderTimeEnd string `json:"orderTimeEnd"` // 订单执行结束时间
|
||||
AfterSalesReason string `json:"afterSalesReason"` // 售后原因
|
||||
AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额
|
||||
}
|
||||
|
||||
type ZltxOrderAfterSaleSupplierResponse struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data []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 req.OrderNumber == "" {
|
||||
return fmt.Errorf("orderType and orderNumber are required")
|
||||
}
|
||||
return t.checkZltxOrderAfterSaleSupplier(req.OrderNumber, requireData)
|
||||
}
|
||||
|
||||
func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(orderNumber string, requireData *entitys.RequireData) error {
|
||||
// req := l_request.Request{
|
||||
// Url: t.config.BaseURL,
|
||||
// Headers: map[string]string{
|
||||
// "Authorization": fmt.Sprintf("Bearer %s", requireData.Auth),
|
||||
// },
|
||||
// Method: "POST",
|
||||
// Data: map[string]string{
|
||||
// // "orderType": fmt.Sprintf("%d", orderType),
|
||||
// "orderNumber": orderNumber,
|
||||
// },
|
||||
// }
|
||||
// res, err := req.Send()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // 解析响应
|
||||
// var resp ZltxOrderAfterSaleSupplierResponse
|
||||
// if err := json.Unmarshal(res.Content, &resp); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// if resp.Code != 0 {
|
||||
// return fmt.Errorf("check failed: %s", resp.Msg)
|
||||
// }
|
||||
resp := ZltxOrderAfterSaleSupplierResponse{
|
||||
Code: 0,
|
||||
Msg: "success",
|
||||
Data: []ZltxOrderAfterSaleSupplierData{
|
||||
// {
|
||||
// "serialNumber": "847465394004430849",
|
||||
// "platformName": "爱奇艺",
|
||||
// "signCompany": 1,
|
||||
// "platformProductName": "爱奇艺官方周卡",
|
||||
// "platformPrice": 6,
|
||||
// "terminalAccount": "15516353308",
|
||||
// "status": 1,
|
||||
// "platformProductId": 2,
|
||||
// "platformId": 4,
|
||||
// "signCompanyName": "成都蓝色兄弟网络科技有限公司",
|
||||
// "executeTime": 1763961931
|
||||
// }
|
||||
{
|
||||
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,
|
||||
},
|
||||
},
|
||||
}
|
||||
jsonByte, err := json.Marshal(resp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte))
|
||||
return nil
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@ type BotTool struct {
|
|||
llm *utils_ollama.Client
|
||||
sessionImpl *impl.SessionImpl
|
||||
taskMap map[string]string // task_id -> session_id
|
||||
// zltxOrderAfterSaleTool tools.ZltxOrderAfterSaleTool
|
||||
}
|
||||
|
||||
// NewBotTool 创建直连天下订单详情工具
|
||||
|
|
|
|||
Loading…
Reference in New Issue