From 730146385780ead3986284af3abad4ed0bf51700 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Sat, 7 Oct 2023 16:12:29 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=E4=BC=98=E5=8C=96=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8F=96=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/internal/logic/createorderlogic.go | 17 +++++++ service/repositories/order.go | 50 ++++++++++--------- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/server/order/internal/logic/createorderlogic.go b/server/order/internal/logic/createorderlogic.go index 4e2d1d78..e0d16704 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*1, 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..a4d1f5da 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 } From 0b8fc0915b4f0d35f187fab4f550c13e7ba337da Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Sat, 7 Oct 2023 16:13:08 +0800 Subject: [PATCH 2/3] fix --- service/repositories/order.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service/repositories/order.go b/service/repositories/order.go index a4d1f5da..2d39860d 100644 --- a/service/repositories/order.go +++ b/service/repositories/order.go @@ -690,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) From 9cfdfdbc775f83deac8cac5031fe561ad1922c32 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Sat, 7 Oct 2023 16:14:46 +0800 Subject: [PATCH 3/3] fix --- server/order/internal/logic/createorderlogic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/order/internal/logic/createorderlogic.go b/server/order/internal/logic/createorderlogic.go index e0d16704..5aaa7c8f 100644 --- a/server/order/internal/logic/createorderlogic.go +++ b/server/order/internal/logic/createorderlogic.go @@ -70,7 +70,7 @@ func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth // }, []interface{}{res.OrderSn}) // 延时任务 - time.AfterFunc(time.Minute*1, func() { + time.AfterFunc(time.Minute*30, func() { orderSn := res.OrderSn fmt.Println("延时任务: OrderSn--", orderSn) ctx := context.Background()