This commit is contained in:
2025-03-21 20:44:35 +08:00
parent bac4fd8b11
commit 8cede57a70
21 changed files with 430 additions and 120 deletions

View File

@ -739,7 +739,7 @@ func processTakeProfitAndStopLossOrders(db *gorm.DB, preOrder *models.LinePreOrd
for _, order := range orders {
order.Num = num.String()
if fist && order.OrderCategory == 1 && order.OrderType == 1 && orderExt.TakeProfitNumRatio.Cmp(decimal.Zero) > 0 && orderExt.TakeProfitNumRatio.Cmp(decimal.NewFromInt(100)) != 0 {
if fist && (order.OrderCategory == 3 || order.OrderCategory == 1) && order.OrderType == 1 && orderExt.TakeProfitNumRatio.Cmp(decimal.Zero) > 0 && orderExt.TakeProfitNumRatio.Cmp(decimal.NewFromInt(100)) != 0 {
//主单第一次且止盈数量不是100% 止盈数量
order.Num = num.Mul(orderExt.TakeProfitNumRatio.Div(decimal.NewFromInt(100))).Truncate(int32(tradeSet.AmountDigit)).String()
}
@ -761,7 +761,7 @@ func processTakeProfitAndStopLossOrders(db *gorm.DB, preOrder *models.LinePreOrd
order.Rate = percentag.String()
percentag = percentag.Div(decimal.NewFromInt(100))
order.Price = price.Mul(decimal.NewFromInt(1).Add(percentag)).Truncate(int32(tradeSet.PriceDigit)).String()
} else if orderExt.Id > 0 {
} else if !fist && orderExt.TpTpPriceRatio.Cmp(decimal.Zero) > 0 {
percentag := orderExt.TpTpPriceRatio
order.Rate = percentag.String()
order.Price = price.Mul(decimal.NewFromInt(1).Add(percentag.Div(decimal.NewFromInt(100)))).Truncate(int32(tradeSet.PriceDigit)).String()

View File

@ -0,0 +1,76 @@
package smsservice
import (
"bytes"
"fmt"
statuscode "go-admin/common/status_code"
"go-admin/config"
"io/ioutil"
"net/http"
"time"
"github.com/bytedance/sonic"
"github.com/go-admin-team/go-admin-core/logger"
)
type GotoneService struct {
}
func (s *GotoneService) SendSMS(area, phonenumber string, content string) int {
type SmsRequest struct {
Recipient string `json:"recipient"` // 收件人电话号码
Message string `json:"message"` // 短信内容
SenderId string `json:"sender_id"` // 发送者名称
Type string `json:"type"`
}
// 创建请求数据
smsRequest := SmsRequest{
Recipient: "+" + area + phonenumber,
SenderId: config.ExtConfig.GoToneSmsConfig.SenderId,
Message: fmt.Sprintf("欢迎使用 GoTone SMS高速稳定地发送短信至中国大陆及全球用户体验验证码%s。如非本人操作请忽略此信息", content),
Type: "plain",
}
// 将请求数据编码为 JSON
requestBody, err := sonic.Marshal(smsRequest)
if err != nil {
logger.Error("GoToneSms requestBody Error:", err)
return statuscode.ServerError
}
// 创建 HTTP 请求
req, err := http.NewRequest("POST", config.ExtConfig.GoToneSmsConfig.APIEndpoint, bytes.NewBuffer(requestBody))
if err != nil {
logger.Error("GoToneSms http.NewRequest Error:", err)
return statuscode.ServerError
}
// 设置请求头
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+config.ExtConfig.GoToneSmsConfig.Authorization) // 使用 API 密钥进行身份验证
// 创建 HTTP 客户端并发送请求
client := &http.Client{
Timeout: 10 * time.Second, // 设置请求超时时间
}
resp, err := client.Do(req)
fmt.Println("resp:", resp)
if err != nil {
logger.Error("GoToneSms do NewRequest Error:", err)
return statuscode.CaptchaFailInSend
}
defer resp.Body.Close()
// 检查响应状态
if resp.StatusCode != http.StatusOK {
logger.Error("GoToneSms do NewRequest Error:", err)
return statuscode.CaptchaFailInSend
}
// 读取响应体
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
logger.Error("读取响应体失败:", err)
fmt.Printf("响应体: %s", string(body))
return statuscode.CaptchaFailInSend
//return fmt.Errorf("读取响应体失败: %v", err)
}
return statuscode.OK
}

View File

@ -0,0 +1,44 @@
package smsservice
import (
"fmt"
statuscode "go-admin/common/status_code"
"go-admin/config"
"io"
"net/http"
"strings"
"github.com/bytedance/sonic"
"github.com/go-admin-team/go-admin-core/logger"
)
type InnopaasService struct {
}
func (i *InnopaasService) SendSMS(area, phoneNumber string, message string) int {
// Implement the logic to send SMS using Innopass API
params := map[string]string{
"account": config.ExtConfig.InnoPaas.ApiKey,
"password": config.ExtConfig.InnoPaas.Password,
"mobile": area + phoneNumber,
"msg": message,
}
payload, _ := sonic.MarshalString(params) // strings.NewReader("{\"account\":\"I7145744\",\"password\":\"password\",\"mobile\":\"0012012074149,0012012074142\",\"msg\":\"Your verification code is 8888\"}")
req, _ := http.NewRequest("POST", config.ExtConfig.InnoPaas.Url, strings.NewReader(payload))
req.Header.Add("accept", "application/json")
req.Header.Add("content-type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
logger.Error("读取响应体失败:", err)
fmt.Printf("响应体: %s", string(body))
return statuscode.CaptchaFailInSend
//return fmt.Errorf("读取响应体失败: %v", err)
}
return statuscode.OK
}

View File

@ -0,0 +1,13 @@
package smsservice
type SMSService interface {
// SendSMS 发送短信
// area 区号
// phoneNumber 手机号
// message 短信内容
SendSMS(area, phoneNumber string, message string) int
}
func NewSMSService() SMSService {
return &GotoneService{}
}