diff --git a/server/order/internal/logic/createorderlogic.go b/server/order/internal/logic/createorderlogic.go index 4e2d1d78..5aaa7c8f 100644 --- a/server/order/internal/logic/createorderlogic.go +++ b/server/order/internal/logic/createorderlogic.go @@ -1,6 +1,7 @@ package logic import ( + "fmt" "fusenapi/constants" "fusenapi/service/repositories" "fusenapi/utils/auth" @@ -68,6 +69,22 @@ func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth // }) // }, []interface{}{res.OrderSn}) + // 延时任务 + time.AfterFunc(time.Minute*30, func() { + orderSn := res.OrderSn + fmt.Println("延时任务: OrderSn--", orderSn) + ctx := context.Background() + + svcCtx := svc.ServiceContext{ + Config: l.svcCtx.Config, + Repositories: l.svcCtx.Repositories, + } + svcCtx.Repositories.NewOrder.Close(ctx, &repositories.CloseReq{ + OrderSn: orderSn, + Type: 1, + }) + }) + return resp.SetStatus(basic.CodeOK, map[string]interface{}{ "order_sn": res.OrderSn, }) diff --git a/service/repositories/order.go b/service/repositories/order.go index ab3ba6f5..2d39860d 100644 --- a/service/repositories/order.go +++ b/service/repositories/order.go @@ -12,6 +12,7 @@ import ( "fusenapi/utils/order" "fusenapi/utils/pay" "fusenapi/utils/queue" + "math" "time" "github.com/aws/aws-sdk-go/aws/session" @@ -206,29 +207,32 @@ func (d *defaultOrder) CloseList(ctx context.Context, in *CloseListReq) (res *Cl logc.Errorf(ctx, "order CloseList failed, err: %v", err) return nil, result.Error } - // for _, orderInfo := range orderList { - // var ntime = time.Now().UTC() - // var cptime = orderInfo.Ctime.UTC().Add(time.Minute * 30) - // var dtime time.Time - // var dd = ntime.Unix() - cptime.Unix() - // if dd > 0 { - // dtime = time.Now().Add(time.Second * 0) - // } else { - // dtime = time.Now().Add(time.Second * time.Duration(math.Abs(float64(dd)))) - // } - // if in.Type == 1 { - // // 延时任务 - // d.DelayQueue.AddTask(dtime, constants.QUEUE_NAME_ORDER, func(args ...interface{}) { - // ctx := context.Background() - // orderSn := args[0].(string) - // logc.Infof(ctx, "order CloseList, orderSn: %s", orderSn) - // d.Close(ctx, &CloseReq{ - // OrderSn: orderSn, - // Type: 1, - // }) - // }, []interface{}{*orderInfo.OrderSn}) - // } - // } + for _, orderInfo := range orderList { + var ntime = time.Now().UTC() + var cptime = orderInfo.Ctime.UTC().Add(time.Minute * 30) + var dtime time.Duration + var dd = ntime.Unix() - cptime.Unix() + if dd > 0 { + dtime = time.Second * 0 + } else { + dtime = time.Second * time.Duration(math.Abs(float64(dd))) + } + if in.Type == 1 { + // 延时任务 + time.AfterFunc(dtime, func() { + orderSn := orderInfo.OrderSn + fmt.Println("延时任务: OrderSn--", orderSn) + ctx := context.Background() + + logc.Infof(ctx, "order CloseList, orderSn: %s", orderSn) + d.Close(ctx, &CloseReq{ + OrderSn: *orderSn, + Type: 1, + }) + }) + + } + } return nil, nil } @@ -686,8 +690,8 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create ntimeTimeOut := ntime.Unix() // 测试超时支付不限制 - //if ctimeTimeOut < ntimeTimeOut { - if ctimeTimeOut == ntimeTimeOut { + if ctimeTimeOut < ntimeTimeOut { + // if ctimeTimeOut == ntimeTimeOut { errorCode = *basic.CodeErrOrderCreatePrePaymentTimeout err = errors.New("order pay timeout") logc.Errorf(ctx, "create prePayment deposit failed, err: %v", err)