fix:优化订单自动取消
This commit is contained in:
parent
6cdb8b6e6b
commit
7301463857
|
@ -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,
|
||||
})
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user