fix(card_sender): 优化订单处理及错误提示
- 将订单创建重试逻辑中的变量声明调整为函数外部,避免重复声明 - 增加订单创建失败条件判断,返回具体错误信息 - 延长订单创建等待时间,从20秒增加到30秒 - 修改多处错误提示,明确提示“重新下单”以便用户操作 - 调整重试暂停时间,由3秒延长至10秒,避免过度频繁请求 - 删除无用注释,简化代码逻辑,提高可读性
This commit is contained in:
@@ -218,7 +218,7 @@ func (s *SendCardTaskTypeNuclear) channelOne(ctx context.Context, orderItem Orde
|
||||
var err error
|
||||
|
||||
if time.Since(orderItem.CreateTime) < time.Second*20 {
|
||||
time.Sleep(time.Second*20 - time.Since(orderItem.CreateTime))
|
||||
time.Sleep(time.Second*30 - time.Since(orderItem.CreateTime))
|
||||
}
|
||||
|
||||
for range 3 {
|
||||
@@ -248,8 +248,6 @@ func (s *SendCardTaskTypeNuclear) channelOne(ctx context.Context, orderItem Orde
|
||||
}).
|
||||
Get(queryOrderInfo.Scheme + "://" + queryOrderInfo.Host + "/pay/index/captcha.html")
|
||||
span.AddEvent("finishGetCaptcha")
|
||||
//设置cookie
|
||||
|
||||
if err4 != nil {
|
||||
needChangeProxyId = utils.GenerateId()
|
||||
otelTrace.Logger.WithContext(ctx).Error("获取验证码失败", zap.Error(err4))
|
||||
@@ -319,7 +317,7 @@ func (s *SendCardTaskTypeNuclear) channelOne(ctx context.Context, orderItem Orde
|
||||
if slices.ContainsFunc(msgList, func(msg string) bool {
|
||||
return strings.Contains(submitRespStr.Msg, msg)
|
||||
}) {
|
||||
errRes = errors.New(submitRespStr.Msg)
|
||||
errRes = errors.New(submitRespStr.Msg + ",重新下单")
|
||||
span.AddEvent("restartOCR")
|
||||
continue
|
||||
}
|
||||
@@ -330,8 +328,8 @@ func (s *SendCardTaskTypeNuclear) channelOne(ctx context.Context, orderItem Orde
|
||||
if slices.ContainsFunc(msgList, func(msg string) bool {
|
||||
return strings.Contains(submitRespStr.Msg, msg)
|
||||
}) {
|
||||
errRes = errors.New(submitRespStr.Msg)
|
||||
time.Sleep(time.Second * 3)
|
||||
errRes = errors.New(submitRespStr.Msg + ",重新下单")
|
||||
time.Sleep(time.Second * 10)
|
||||
span.AddEvent("retrySubmit")
|
||||
continue
|
||||
}
|
||||
@@ -339,7 +337,7 @@ func (s *SendCardTaskTypeNuclear) channelOne(ctx context.Context, orderItem Orde
|
||||
needChangeProxyId = utils.GenerateId()
|
||||
fingerprintHash = fingerprint.GenerateRandomBrowserFingerprintHash()
|
||||
span.AddEvent("startRefreshPage")
|
||||
errRes = errors.New("访问异常,页面刷新后请重试")
|
||||
errRes = errors.New("访问异常,页面刷新后请重试,请重新下单")
|
||||
continue
|
||||
}
|
||||
if submitRespStr.Code != 1 {
|
||||
@@ -355,7 +353,7 @@ func (s *SendCardTaskTypeNuclear) channelOne(ctx context.Context, orderItem Orde
|
||||
if errRes != nil {
|
||||
return errRes
|
||||
}
|
||||
return errors.New("提交失败,请重新提交")
|
||||
return errors.New("提交失败,请重新下单")
|
||||
}
|
||||
|
||||
func (s *SendCardTaskTypeNuclear) channelTwo(ctx context.Context, orderItem OrderPoolItem, task SendCardTask) error {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"github.com/duke-git/lancet/v2/pointer"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -560,11 +561,12 @@ func (s *OrderPoolServiceImpl) SubmitOrder(ctx context.Context, task card_sender
|
||||
)
|
||||
defer span.End()
|
||||
|
||||
var err error
|
||||
var orderItem card_sender.OrderPoolItem
|
||||
|
||||
for range 3 {
|
||||
span.AddEvent("create order")
|
||||
orderItem, err := task.SendCardTaskType.GetSendCardTaskType().
|
||||
orderItem, err = task.SendCardTaskType.GetSendCardTaskType().
|
||||
CreateOrder(ctx, task.RoadUid, task.CardInfo.GetFaceTypeFloat(ctx))
|
||||
|
||||
if err != nil {
|
||||
@@ -596,6 +598,13 @@ func (s *OrderPoolServiceImpl) SubmitOrder(ctx context.Context, task card_sender
|
||||
break
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("提交订单失败: %v", err)
|
||||
}
|
||||
if pointer.IsNil(orderItem) || orderItem.OrderID == "" {
|
||||
return fmt.Errorf("订单创建失败")
|
||||
}
|
||||
|
||||
if task.NeedQuery {
|
||||
queryEvent := &OrderQueryEvent{
|
||||
BaseEvent: BaseEvent{
|
||||
|
||||
Reference in New Issue
Block a user