96 lines
2.6 KiB
Go
96 lines
2.6 KiB
Go
package dto
|
|
|
|
import (
|
|
api_entities "tyapi-server/internal/domains/api/entities"
|
|
product_entities "tyapi-server/internal/domains/product/entities"
|
|
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
// ApiCallValidationResult API调用验证结果
|
|
type ApiCallValidationResult struct {
|
|
UserID string `json:"user_id"`
|
|
ProductID string `json:"product_id"`
|
|
SubscriptionID string `json:"subscription_id"`
|
|
Amount decimal.Decimal `json:"amount"`
|
|
SecretKey string `json:"secret_key"`
|
|
IsValid bool `json:"is_valid"`
|
|
ErrorMessage string `json:"error_message"`
|
|
|
|
// 新增字段
|
|
ContractCode string `json:"contract_code"`
|
|
ApiCall *api_entities.ApiCall `json:"api_call"`
|
|
RequestParams map[string]interface{} `json:"request_params"`
|
|
Product *product_entities.Product `json:"product"`
|
|
}
|
|
|
|
// GetUserID 获取用户ID
|
|
func (r *ApiCallValidationResult) GetUserID() string {
|
|
return r.UserID
|
|
}
|
|
|
|
// GetProductID 获取产品ID
|
|
func (r *ApiCallValidationResult) GetProductID() string {
|
|
return r.ProductID
|
|
}
|
|
|
|
// GetSubscriptionID 获取订阅ID
|
|
func (r *ApiCallValidationResult) GetSubscriptionID() string {
|
|
return r.SubscriptionID
|
|
}
|
|
|
|
// GetAmount 获取金额
|
|
func (r *ApiCallValidationResult) GetAmount() decimal.Decimal {
|
|
return r.Amount
|
|
}
|
|
|
|
// GetSecretKey 获取密钥
|
|
func (r *ApiCallValidationResult) GetSecretKey() string {
|
|
return r.SecretKey
|
|
}
|
|
|
|
// IsValidResult 检查是否有效
|
|
func (r *ApiCallValidationResult) IsValidResult() bool {
|
|
return r.IsValid
|
|
}
|
|
|
|
// GetErrorMessage 获取错误消息
|
|
func (r *ApiCallValidationResult) GetErrorMessage() string {
|
|
return r.ErrorMessage
|
|
}
|
|
|
|
// NewApiCallValidationResult 创建新的API调用验证结果
|
|
func NewApiCallValidationResult() *ApiCallValidationResult {
|
|
return &ApiCallValidationResult{
|
|
IsValid: true,
|
|
RequestParams: make(map[string]interface{}),
|
|
}
|
|
}
|
|
|
|
// SetApiUser 设置API用户
|
|
func (r *ApiCallValidationResult) SetApiUser(apiUser *api_entities.ApiUser) {
|
|
r.UserID = apiUser.UserId
|
|
r.SecretKey = apiUser.SecretKey
|
|
}
|
|
|
|
// SetProduct 设置产品
|
|
func (r *ApiCallValidationResult) SetProduct(product *product_entities.Product) {
|
|
r.ProductID = product.ID
|
|
r.Amount = product.Price
|
|
r.Product = product
|
|
}
|
|
|
|
// SetApiCall 设置API调用
|
|
func (r *ApiCallValidationResult) SetApiCall(apiCall *api_entities.ApiCall) {
|
|
r.ApiCall = apiCall
|
|
}
|
|
|
|
// SetRequestParams 设置请求参数
|
|
func (r *ApiCallValidationResult) SetRequestParams(params map[string]interface{}) {
|
|
r.RequestParams = params
|
|
}
|
|
|
|
// SetContractCode 设置合同代码
|
|
func (r *ApiCallValidationResult) SetContractCode(code string) {
|
|
r.ContractCode = code
|
|
} |