From 1f46911f5138e787f425e5bb6e05006573b85e39 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Sat, 7 Oct 2023 15:38:59 +0800 Subject: [PATCH] fix --- constants/orders.go | 4 +- .../order/internal/logic/createorderlogic.go | 24 ++++----- service/repositories/order.go | 53 ++++++++++--------- 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/constants/orders.go b/constants/orders.go index 34b7ff71..d955c38c 100644 --- a/constants/orders.go +++ b/constants/orders.go @@ -2,8 +2,8 @@ package constants // 订单类型 const ( - DELIVERYMETHODDIRECTMAIL int64 = 1 - DELIVERYMETHODDSCLOUDSTORE int64 = 2 + DELIVERYMETHODDIRECTMAIL int64 = 1 // 直邮 + DELIVERYMETHODDSCLOUDSTORE int64 = 2 // 云仓 ) // 货币 diff --git a/server/order/internal/logic/createorderlogic.go b/server/order/internal/logic/createorderlogic.go index 148078e4..4e2d1d78 100644 --- a/server/order/internal/logic/createorderlogic.go +++ b/server/order/internal/logic/createorderlogic.go @@ -55,18 +55,18 @@ func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth } // 延时任务 - l.svcCtx.DelayQueue.AddTask(time.Now().Add(time.Minute*30), constants.QUEUE_NAME_ORDER, func(args ...interface{}) { - ctx := context.Background() - orderSn := args[0].(string) - svcCtx := svc.ServiceContext{ - Config: l.svcCtx.Config, - Repositories: l.svcCtx.Repositories, - } - svcCtx.Repositories.NewOrder.Close(ctx, &repositories.CloseReq{ - OrderSn: orderSn, - Type: 1, - }) - }, []interface{}{res.OrderSn}) + // l.svcCtx.DelayQueue.AddTask(time.Now().Add(time.Minute*30), constants.QUEUE_NAME_ORDER, func(args ...interface{}) { + // ctx := context.Background() + // orderSn := args[0].(string) + // svcCtx := svc.ServiceContext{ + // Config: l.svcCtx.Config, + // Repositories: l.svcCtx.Repositories, + // } + // svcCtx.Repositories.NewOrder.Close(ctx, &repositories.CloseReq{ + // OrderSn: orderSn, + // Type: 1, + // }) + // }, []interface{}{res.OrderSn}) 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 966910df..ab3ba6f5 100644 --- a/service/repositories/order.go +++ b/service/repositories/order.go @@ -12,7 +12,6 @@ import ( "fusenapi/utils/order" "fusenapi/utils/pay" "fusenapi/utils/queue" - "math" "time" "github.com/aws/aws-sdk-go/aws/session" @@ -207,29 +206,29 @@ 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.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}) + // } + // } return nil, nil } @@ -687,7 +686,8 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create ntimeTimeOut := ntime.Unix() // 测试超时支付不限制 - 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) @@ -740,7 +740,8 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create var table = gmodel.NewAllModels(d.MysqlConn).FsOrder.TableName() var resUpdate *gorm.DB if in.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL { - resUpdate = d.MysqlConn.Exec(fmt.Sprintf("UPDATE %s SET `order_address` = JSON_MERGE_PATCH(`order_address`,?),`status_link` = JSON_MERGE_PATCH(`status_link`,?), `delivery_method` = ? , `utime` = ? WHERE `id` = ?", table), orderAddressByte, statusLinkByte, in.DeliveryMethod, ntime, orderInfo.Id) + var oosql = fmt.Sprintf("UPDATE %s SET `order_address` = JSON_MERGE_PATCH(`order_address`,?),`status_link` = JSON_MERGE_PATCH(`status_link`,?), `delivery_method` = ? , `utime` = ? WHERE `id` = ?", table) + resUpdate = d.MysqlConn.Exec(oosql, orderAddressByte, statusLinkByte, in.DeliveryMethod, ntime, orderInfo.Id) } else { resUpdate = d.MysqlConn.Exec(fmt.Sprintf("UPDATE %s SET `delivery_method` = ? , `utime` = ? WHERE `id` = ?", table), in.DeliveryMethod, ntime, orderInfo.Id) }