2025-09-12 01:15:09 +08:00
|
|
|
|
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"`
|
2025-09-14 16:34:55 +08:00
|
|
|
|
Subscription *product_entities.Subscription `json:"subscription"`
|
2025-09-12 01:15:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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.Product = product
|
2025-09-14 16:34:55 +08:00
|
|
|
|
// 注意:这里不设置Amount,应该通过SetSubscription来设置实际的扣费金额
|
2025-09-12 01:15:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
2025-09-14 16:34:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// SetSubscription 设置订阅信息(包含实际扣费金额)
|
|
|
|
|
|
func (r *ApiCallValidationResult) SetSubscription(subscription *product_entities.Subscription) {
|
|
|
|
|
|
r.SubscriptionID = subscription.ID
|
|
|
|
|
|
r.Amount = subscription.Price // 使用订阅价格作为扣费金额
|
|
|
|
|
|
r.Subscription = subscription
|
2025-09-12 01:15:09 +08:00
|
|
|
|
}
|