Merge branch 'v3' into test

This commit is contained in:
fuzhongyun 2025-11-26 20:00:51 +08:00
commit 4656468e8a
13 changed files with 967 additions and 760 deletions

View File

@ -57,10 +57,15 @@ tools:
api_secret: "ObqxwyR20r9rVNhju0sCPQyQA98_FZSc32W4vgxnGFH_b02HZr1BPCJsOAF816nu" api_secret: "ObqxwyR20r9rVNhju0sCPQyQA98_FZSc32W4vgxnGFH_b02HZr1BPCJsOAF816nu"
zltxOrderAfterSaleSupplier: zltxOrderAfterSaleSupplier:
enabled: true 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: zltxOrderAfterSaleReseller:
enabled: true 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://gateway.dev.cdlsxd.cn/zltx_api/admin/afterSales/reseller_pre_ai"
default_prompt: default_prompt:
img_recognize: img_recognize:

View File

@ -1,122 +1,122 @@
package biz package biz
import ( // import (
"ai_scheduler/internal/config" // "ai_scheduler/internal/config"
"ai_scheduler/internal/data/impl" // "ai_scheduler/internal/data/impl"
"ai_scheduler/internal/data/model" // "ai_scheduler/internal/data/model"
"ai_scheduler/internal/entitys" // "ai_scheduler/internal/entitys"
"ai_scheduler/internal/pkg" // "ai_scheduler/internal/pkg"
"ai_scheduler/internal/pkg/utils_ollama" // "ai_scheduler/internal/pkg/utils_ollama"
"ai_scheduler/internal/tools" // "ai_scheduler/internal/tools"
"ai_scheduler/utils" // "ai_scheduler/utils"
"encoding/json" // "encoding/json"
"flag" // "flag"
"fmt" // "fmt"
"os" // "os"
"path/filepath" // "path/filepath"
"testing" // "testing"
"github.com/gofiber/fiber/v2/log" // "github.com/gofiber/fiber/v2/log"
) // )
func Test_task(t *testing.T) { // func Test_task(t *testing.T) {
var c entitys.TaskConfig // 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"}}` // 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) // err := json.Unmarshal([]byte(config), &c)
t.Log(err) // t.Log(err)
} // }
type configData struct { // type configData struct {
Param map[string]interface{} `json:"param"` // Param map[string]interface{} `json:"param"`
Do map[string]interface{} `json:"do"` // Do map[string]interface{} `json:"do"`
} // }
func Test_Order(t *testing.T) { // func Test_Order(t *testing.T) {
routerBiz := in() // routerBiz := in()
ch := make(chan entitys.Response, 5) // ch := make(chan entitys.Response, 5)
defer close(ch) // 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": "订单编号/流水号"}}}}`}) // 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 { // select {
case v := <-ch: // 尝试接收 // case v := <-ch: // 尝试接收
fmt.Println("接收到值:", v) // fmt.Println("接收到值:", v)
default: // default:
fmt.Println("无数据可接收") // fmt.Println("无数据可接收")
} // }
t.Log(err) // t.Log(err)
} // }
func Test_OrderLog(t *testing.T) { // func Test_OrderLog(t *testing.T) {
routerBiz := in() // routerBiz := in()
ch := make(chan entitys.Response, 5) // ch := make(chan entitys.Response, 5)
defer close(ch) // 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": "订单编号/流水号"}}}}`}) // 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) // t.Log(err)
} // }
func Test_ProductLog(t *testing.T) { // func Test_ProductLog(t *testing.T) {
routerBiz := in() // routerBiz := in()
ch := make(chan entitys.Response, 5) // ch := make(chan entitys.Response, 5)
defer close(ch) // 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": "订单编号/流水号"}}}}`}) // 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) // t.Log(err)
} // }
func Test_ZltxStatistics(t *testing.T) { // func Test_ZltxStatistics(t *testing.T) {
routerBiz := in() // routerBiz := in()
ch := make(chan entitys.Response, 5) // ch := make(chan entitys.Response, 5)
defer close(ch) // 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"}}}}`}) // 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) // t.Log(err)
} // }
func in() *AiRouterBiz { // func in() *AiRouterBiz {
modDir, err := getModuleDir() // modDir, err := getModuleDir()
if err != nil { // if err != nil {
panic("1") // panic("1")
} // }
configPath := flag.String("config", fmt.Sprintf("%s/config/config.yaml", modDir), "Path to configuration file") // configPath := flag.String("config", fmt.Sprintf("%s/config/config.yaml", modDir), "Path to configuration file")
flag.Parse() // flag.Parse()
configConfig, err := config.LoadConfig(*configPath) // configConfig, err := config.LoadConfig(*configPath)
if err != nil { // if err != nil {
panic("加载配置失败") // panic("加载配置失败")
} // }
client, _, err := utils_ollama.NewClient(configConfig) // client, _, err := utils_ollama.NewClient(configConfig)
allLogger := log.DefaultLogger() // allLogger := log.DefaultLogger()
utilOllama := utils_ollama.NewUtilOllama(configConfig, allLogger) // utilOllama := utils_ollama.NewUtilOllama(configConfig, allLogger)
manager := tools.NewManager(configConfig, client) // manager := tools.NewManager(configConfig, client)
db, _ := utils.NewGormDb(configConfig) // db, _ := utils.NewGormDb(configConfig)
sessionImpl := impl.NewSessionImpl(db) // sessionImpl := impl.NewSessionImpl(db)
sysImpl := impl.NewSysImpl(db) // sysImpl := impl.NewSysImpl(db)
taskImpl := impl.NewTaskImpl(db) // taskImpl := impl.NewTaskImpl(db)
chatImpl := impl.NewChatImpl(db) // chatImpl := impl.NewChatImpl(db)
safeChannelPool, _ := pkg.NewSafeChannelPool(configConfig) // safeChannelPool, _ := pkg.NewSafeChannelPool(configConfig)
routerBiz := NewAiRouterBiz(manager, sessionImpl, sysImpl, taskImpl, chatImpl, configConfig, utilOllama, safeChannelPool, client) // routerBiz := NewAiRouterBiz(manager, sessionImpl, sysImpl, taskImpl, chatImpl, configConfig, utilOllama, safeChannelPool, client)
return routerBiz // return routerBiz
} // }
func getModuleDir() (string, error) { // func getModuleDir() (string, error) {
dir, err := os.Getwd() // dir, err := os.Getwd()
if err != nil { // if err != nil {
return "", err // return "", err
} // }
for { // for {
modPath := filepath.Join(dir, "go.mod") // modPath := filepath.Join(dir, "go.mod")
if _, err := os.Stat(modPath); err == nil { // if _, err := os.Stat(modPath); err == nil {
return dir, nil // 找到 go.mod // return dir, nil // 找到 go.mod
} // }
// 向上查找父目录 // // 向上查找父目录
parent := filepath.Dir(dir) // parent := filepath.Dir(dir)
if parent == dir { // if parent == dir {
break // 到达根目录,未找到 // break // 到达根目录,未找到
} // }
dir = parent // 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")
} // }

View File

@ -90,14 +90,12 @@ 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"`
// 上游订单售后 // 上游订单售后
ZltxOrderAfterSaleSupplier ToolConfig `mapstructure:"zltxOrderAfterSaleSupplier"` ZltxOrderAfterSaleSupplier ToolConfig `mapstructure:"zltxOrderAfterSaleSupplier"`
// 下游订单售后 // 下游订单售后
ZltxOrderAfterSaleReseller ToolConfig `mapstructure:"zltxOrderAfterSaleReseller"` ZltxOrderAfterSaleReseller ToolConfig `mapstructure:"zltxOrderAfterSaleReseller"`
// 下游批充订单售后
ZltxOrderAfterSaleResellerBatch ToolConfig `mapstructure:"zltxOrderAfterSaleResellerBatch"`
} }
// ToolConfig 单个工具配置 // ToolConfig 单个工具配置

View File

@ -2,6 +2,7 @@ package util
import ( import (
"encoding/json" "encoding/json"
"strconv"
"strings" "strings"
) )
@ -19,3 +20,9 @@ func EscapeJSONString(s string) string {
b, _ := json.Marshal(s) b, _ := json.Marshal(s)
return string(b[1 : len(b)-1]) return string(b[1 : len(b)-1])
} }
// string 转 int
func StringToInt(s string) int {
i, _ := strconv.Atoi(s)
return i
}

View File

@ -1,19 +1,17 @@
package tools package tools
import ( import (
"ai_scheduler/internal/config"
"ai_scheduler/internal/entitys"
"testing" "testing"
) )
func TestKnowledgeBaseTool_Execute(t *testing.T) { func TestKnowledgeBaseTool_Execute(t *testing.T) {
kb := NewKnowledgeBaseTool(config.ToolConfig{}) // kb := NewKnowledgeBaseTool(config.ToolConfig{})
channel := make(chan entitys.ResponseData) // channel := make(chan entitys.ResponseData)
err := kb.Execute(channel, nil, nil) // err := kb.Execute(channel, nil, nil)
if err != nil { // if err != nil {
t.Errorf("Execute() error = %v", err) // t.Errorf("Execute() error = %v", err)
} // }
} }

View File

@ -5,6 +5,7 @@ import (
"ai_scheduler/internal/data/constants" "ai_scheduler/internal/data/constants"
"ai_scheduler/internal/entitys" "ai_scheduler/internal/entitys"
"ai_scheduler/internal/pkg/utils_ollama" "ai_scheduler/internal/pkg/utils_ollama"
zltxtool "ai_scheduler/internal/tools/zltx"
"context" "context"
"fmt" "fmt"
@ -70,27 +71,21 @@ func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager {
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
}
// 注册直连天下上游售后订单工具
if config.Tools.ZltxOrderAfterSaleSupplier.Enabled { if config.Tools.ZltxOrderAfterSaleSupplier.Enabled {
zltxOrderAfterSaleSupplierTool := NewZltxOrderAfterSaleSupplierTool(config.Tools.ZltxOrderAfterSaleSupplier) zltxOrderAfterSaleSupplierTool := zltxtool.NewOrderAfterSaleSupplierTool(config.Tools.ZltxOrderAfterSaleSupplier)
m.tools[zltxOrderAfterSaleSupplierTool.Name()] = zltxOrderAfterSaleSupplierTool m.tools[zltxOrderAfterSaleSupplierTool.Name()] = zltxOrderAfterSaleSupplierTool
} }
// 注册直连天下下游售后订单工具 // 注册直连天下下游订单售后工具
if config.Tools.ZltxOrderAfterSaleReseller.Enabled { if config.Tools.ZltxOrderAfterSaleReseller.Enabled {
zltxOrderAfterSaleResellerTool := NewZltxOrderAfterSaleResellerTool(config.Tools.ZltxOrderAfterSaleReseller) zltxOrderAfterSaleResellerTool := zltxtool.NewOrderAfterSaleResellerTool(config.Tools.ZltxOrderAfterSaleReseller)
m.tools[zltxOrderAfterSaleResellerTool.Name()] = zltxOrderAfterSaleResellerTool 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) chat := NewNormalChatTool(m.llm, config)

View File

@ -0,0 +1,326 @@
package zltx
import (
"ai_scheduler/internal/config"
"ai_scheduler/internal/entitys"
"ai_scheduler/internal/pkg/l_request"
"ai_scheduler/internal/pkg/util"
"context"
"encoding/json"
"fmt"
"sync"
"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 string `json:"afterType"` // 处理方式 1.退款 2.扣款
AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额
AfterSalesReason string `json:"afterSalesReason"` // 售后原因
ResponsibleType string `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 string `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"`
Error string `json:"error"`
Data OrderAfterSaleResellerApiData `json:"data"`
}
type OrderAfterSaleResellerApiData struct {
Data []OrderAfterSaleResellerApiBase `json:"data"`
ExtData map[string]OrderAfterSaleResellerApiExtItem `json:"extraData"`
}
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:"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 {
return fmt.Errorf("订单号 和 充值账号 不能同时为空")
}
entitys.ResLog(requireData.Ch, t.Name(), "正在拉取售后订单信息")
return t.checkOrderAfterSaleReseller(req, requireData)
}
func (t *OrderAfterSaleResellerTool) checkOrderAfterSaleReseller(toolReq OrderAfterSaleResellerRequest, requireData *entitys.RequireData) error {
// 流水创建时间上下浮动10min
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
// 账号数量超过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{
"order_numbers": 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, // 充值账号
"create_time": []int64{serialStartTime, serialEndTime}, // 流水创建时间区间
"order_type": 1, // 1.直充
}
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: headers,
Method: "POST",
Json: body,
}
res, err := req.Send()
if err != nil {
return nil, err
}
// 解析响应
var resp OrderAfterSaleResellerApiResponse
if err = json.Unmarshal(res.Content, &resp); err != nil {
return nil, err
}
if resp.Code != 200 {
return nil, fmt.Errorf("after sale reseller failed: %s", resp.Error)
}
orderList := make([]*OrderAfterSaleResellerData, 0, len(resp.Data.Data))
// 转换数据
for _, item := range resp.Data.Data {
orderList = append(orderList, &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: util.StringToInt(originInput.AfterType),
Remark: originInput.AfterSalesReason,
AfterAmount: originInput.AfterSalesPrice,
ResponsibleType: util.StringToInt(originInput.ResponsibleType),
ResponsiblePerson: originInput.ResponsiblePerson,
})
}
// 追加扩展数据
for _, item := range orderList {
if extItem, ok := resp.Data.ExtData[item.OrderNumber]; ok {
item.IsExistsAfterSale = item.OrderType > 100 // 101 直充&已售后
item.CreateTime = extItem.SerialCreateTime
}
}
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,
// },
// },
// }
// 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
// }

View File

@ -0,0 +1,188 @@
package zltx
import (
"ai_scheduler/internal/config"
"ai_scheduler/internal/entitys"
"ai_scheduler/internal/pkg/l_request"
"ai_scheduler/internal/pkg/util"
"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 string `json:"afterType"` // 处理方式 1.退款 2.扣款
AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额
AfterSalesReason string `json:"afterSalesReason"` // 售后原因
ResponsibleType string `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 string `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"`
Error string `json:"error"`
Data OrderAfterSaleResellerBatchApiData `json:"data"`
}
type OrderAfterSaleResellerBatchApiData struct {
Data []OrderAfterSaleResellerBatchApiBase `json:"data"`
ExtData map[string]OrderAfterSaleResellerBatchApiExtItem `json:"extraData"`
}
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:"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 {
return fmt.Errorf("批充订单号不能为空")
}
entitys.ResLog(requireData.Ch, t.Name(), "正在拉取售后订单信息")
return t.checkOrderAfterSaleResellerBatch(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{
"order_numbers": toolReq.OrderNumber, // 流水号
"order_type": 2, // 2.批充
},
}
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 != 200 {
return fmt.Errorf("after sale supplier failed: %s", resp.Error)
}
toolResp := OrderAfterSaleResellerBatchResponse{
Code: resp.Code,
Msg: resp.Error,
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: util.StringToInt(toolReq.AfterType),
Remark: toolReq.AfterSalesReason,
AfterAmount: toolReq.AfterSalesPrice,
ResponsibleType: util.StringToInt(toolReq.ResponsibleType),
ResponsiblePerson: toolReq.ResponsiblePerson,
})
}
// 追加扩展数据
for _, item := range toolResp.Data {
if extItem, ok := resp.Data.ExtData[item.OrderNumber]; ok {
item.IsExistsAfterSale = item.OrderType > 100 // 102 批充&已售后
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
}

View File

@ -0,0 +1,252 @@
package zltx
import (
"ai_scheduler/internal/config"
"ai_scheduler/internal/entitys"
"ai_scheduler/internal/pkg/l_request"
"ai_scheduler/internal/pkg/util"
"context"
"encoding/json"
"fmt"
"sync"
"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 string `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 string `json:"salePrice"` // 售后金额
SaleType int `json:"saleType"` // 处理方式 1.加款 2.扣款
ExecuteTime int `json:"executeTime"` // 流水创建时间
IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后
}
// 接口返回
type OrderAfterSaleSupplierApiResponse struct {
Code int `json:"code"`
Error string `json:"error"`
Data OrderAfterSaleSupplierApiData `json:"data"`
}
type OrderAfterSaleSupplierApiData struct {
Data []OrderAfterSaleSupplierApiBase `json:"data"`
ExtData map[string]OrderAfterSaleSupplierApiExtItem `json:"extraData"`
}
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"` // 签约主体名称
ExecuteTime int `json:"executeTime"` // 充值执行时间
}
type OrderAfterSaleSupplierApiExtItem struct {
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 {
return fmt.Errorf("充值流水号 和 充值账号 不能同时为空")
}
entitys.ResLog(requireData.Ch, t.Name(), "正在拉取售后订单信息")
return t.checkOrderAfterSaleSupplier(req, requireData)
}
func (t *OrderAfterSaleSupplierTool) checkOrderAfterSaleSupplier(toolReq OrderAfterSaleSupplierRequest, requireData *entitys.RequireData) error {
// 流水创建时间上下浮动10min
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
// 账号数量超过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 []*OrderAfterSaleSupplierData
// 多流水号
if len(toolReq.SerialNumber) > 0 {
body := map[string]any{
"serial_numbers": toolReq.SerialNumber, // 流水号
}
orderList, err = t.getAfterSaleSupplierList(headers, body, toolReq)
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, // 充值账号
"create_time": []int64{serialStartTime, serialEndTime}, // 流水创建时间区间
}
orderListIn, errIn := t.getAfterSaleSupplierList(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 := OrderAfterSaleSupplierResponse{
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, originInput OrderAfterSaleSupplierRequest) ([]*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 != 200 {
return nil, fmt.Errorf("after sale supplier failed: %s", resp.Error)
}
orderList := make([]*OrderAfterSaleSupplierData, 0, len(resp.Data.Data))
// 转换数据
for _, item := range resp.Data.Data {
orderList = append(orderList, &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: originInput.AfterSalesReason,
SalePrice: originInput.AfterSalesPrice,
SaleType: util.StringToInt(originInput.AfterType),
})
}
// 追加扩展数据
for _, item := range orderList {
if extItem, ok := resp.Data.ExtData[item.SerialNumber]; ok {
item.IsExistsAfterSale = extItem.IsExistsAfterSale
item.ExecuteTime = extItem.SerialCreateTime
}
}
return orderList, nil
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -1,72 +1,72 @@
package utils package utils
import ( // import (
"fmt" // "fmt"
"github.com/go-kratos/kratos/v2/log" // "github.com/go-kratos/kratos/v2/log"
"google.golang.org/protobuf/runtime/protoimpl" // "google.golang.org/protobuf/runtime/protoimpl"
"gopkg.in/yaml.v3" // "gopkg.in/yaml.v3"
"io/fs" // "io/fs"
"os" // "os"
"path/filepath" // "path/filepath"
"testing" // "testing"
baseconf "trans_hub/base_conf" // baseconf "trans_hub/base_conf"
"trans_hub/pkg" // "trans_hub/pkg"
"trans_hub/pkg/mapstructure" // "trans_hub/pkg/mapstructure"
) // )
const SPACE = "public" // const SPACE = "public"
const PORT = 8848 // const PORT = 8848
const User = "" // const User = ""
const Pass = "" // const Pass = ""
const IP = "192.168.110.93" // const IP = "192.168.110.93"
const Group = "DEFAULT_GROUP" // const Group = "DEFAULT_GROUP"
const DataId = "PG_BASE_CONFIG" // const DataId = "PG_BASE_CONFIG"
func TestConfig(t *testing.T) { // func TestConfig(t *testing.T) {
type Nacos struct { // type Nacos struct {
state protoimpl.MessageState // state protoimpl.MessageState
sizeCache protoimpl.SizeCache // sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields // unknownFields protoimpl.UnknownFields
Ip string `protobuf:"bytes,1,opt,name=ip,proto3" json:"ip,omitempty"` // Ip string `protobuf:"bytes,1,opt,name=ip,proto3" json:"ip,omitempty"`
Port uint64 `protobuf:"varint,2,opt,name=port,proto3" json:"port,omitempty"` // Port uint64 `protobuf:"varint,2,opt,name=port,proto3" json:"port,omitempty"`
} // }
type Conf struct { // type Conf struct {
Nacos *Nacos `protobuf:"bytes,8,opt,name=nacos,proto3" json:"nacos,omitempty"` // Nacos *Nacos `protobuf:"bytes,8,opt,name=nacos,proto3" json:"nacos,omitempty"`
} // }
var c Conf // var c Conf
nc := &baseconf.Nacos{Ip: IP, Port: PORT, Space: SPACE, User: User, Password: Pass} // nc := &baseconf.Nacos{Ip: IP, Port: PORT, Space: SPACE, User: User, Password: Pass}
var s = ServerConfig(nc, Group, DataId) // var s = ServerConfig(nc, Group, DataId)
err := mapstructure.Decode(s, &c) // err := mapstructure.Decode(s, &c)
t.Log(s, err) // t.Log(s, err)
} // }
func TestMod(t *testing.T) { // func TestMod(t *testing.T) {
dir := pkg.GetRootPath() // dir := pkg.GetRootPath()
// 读取目录内容 // // 读取目录内容
err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { // err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
if err != nil { // if err != nil {
return err // return err
} // }
if !d.IsDir() && filepath.Ext(path) == ".yaml" { // if !d.IsDir() && filepath.Ext(path) == ".yaml" {
data, err := os.ReadFile(path) // data, err := os.ReadFile(path)
if err != nil { // if err != nil {
return err // return err
} // }
var result map[string]interface{} // var result map[string]interface{}
err = yaml.Unmarshal(data, &result) // 解析YAML到map中使用gopkg.v3的yaml包或其他你选择的版本例如encoding/yaml // err = yaml.Unmarshal(data, &result) // 解析YAML到map中使用gopkg.v3的yaml包或其他你选择的版本例如encoding/yaml
if err != nil { // if err != nil {
return err // return err
} // }
fmt.Printf("File: %s\nContent: %+v\n", path, result) // fmt.Printf("File: %s\nContent: %+v\n", path, result)
} // }
return nil // return nil
}) // })
if err != nil { // if err != nil {
log.Fatal(err) // log.Fatal(err)
} // }
} // }
func TestYaml(t *testing.T) { // func TestYaml(t *testing.T) {
t.Log(GetBaseYaml()) // t.Log(GetBaseYaml())
} // }