ai_scheduler/internal/tools/zltx_order_after_supplier.go

163 lines
5.0 KiB
Go

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"`
PlatformID int `json:"platformId"`
SignCompanyName string `json:"signCompanyName"`
ExecuteTime int `json:"executeTime"`
AfterSalesReason string `json:"afterSalesReason"`
AfterSalesPrice float64 `json:"afterSalesPrice"`
}
func (t *ZltxOrderAfterSaleSupplierTool) Execute(ctx context.Context, requireData *entitys.RequireData) error {
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: "123456",
PlatformName: "测试平台",
SignCompany: 1,
PlatformProductName: "测试商品",
PlatformPrice: 100,
TerminalAccount: "123456",
Status: 1,
PlatformProductID: 1,
PlatformID: 1,
SignCompanyName: "测试公司",
ExecuteTime: 1694560000,
AfterSalesReason: "测试售后",
AfterSalesPrice: 50,
},
{
SerialNumber: "123457",
PlatformName: "测试平台2",
SignCompany: 1,
PlatformProductName: "测试商品2",
PlatformPrice: 100,
TerminalAccount: "123456",
Status: 1,
PlatformProductID: 1,
PlatformID: 1,
SignCompanyName: "测试公司2",
ExecuteTime: 1694570000,
AfterSalesReason: "测试售后2",
AfterSalesPrice: 30,
},
},
}
jsonByte, err := json.Marshal(resp)
if err != nil {
return err
}
entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte))
return nil
}