177 lines
6.0 KiB
Go
177 lines
6.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 {
|
|
SerialNumber []string `json:"serialNumber"` // 流水号
|
|
Account string `json:"account"` // 充值账号
|
|
OrderTimeStart string `json:"orderTimeStart"` // 订单执行开始时间
|
|
OrderTimeEnd string `json:"orderTimeEnd"` // 订单执行结束时间
|
|
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 == "" || req.OrderTimeStart == "") {
|
|
return fmt.Errorf("充值流水号 和 充值账号&订单执行时间 不能同时为空")
|
|
}
|
|
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.ResJson(requireData.Ch, t.Name(), string(jsonByte))
|
|
return nil
|
|
}
|