mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-08-27 22:31:32 +08:00
This commit is contained in:
43
server/internal/crons/close_order.go
Normal file
43
server/internal/crons/close_order.go
Normal file
@@ -0,0 +1,43 @@
|
||||
// Package crons
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package crons
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/service"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cronList = append(cronList, CloseOrder)
|
||||
}
|
||||
|
||||
// CloseOrder 取消过期订单
|
||||
var CloseOrder = &cCloseOrder{name: "close_order"}
|
||||
|
||||
type cCloseOrder struct {
|
||||
name string
|
||||
}
|
||||
|
||||
func (c *cCloseOrder) GetName() string {
|
||||
return c.name
|
||||
}
|
||||
|
||||
// Execute 执行任务
|
||||
func (c *cCloseOrder) Execute(ctx context.Context) {
|
||||
_, err := service.AdminOrder().Model(ctx).
|
||||
Where(dao.AdminOrder.Columns().Status, consts.OrderStatusNotPay).
|
||||
WhereLTE(dao.AdminOrder.Columns().CreatedAt, gtime.Now().AddDate(0, 0, -1)).
|
||||
Data(g.Map{
|
||||
dao.AdminOrder.Columns().Status: consts.OrderStatusClose,
|
||||
}).Update()
|
||||
if err != nil {
|
||||
g.Log().Warning(ctx, "cron CloseOrder Execute err:%+v", err)
|
||||
}
|
||||
}
|
@@ -3,7 +3,6 @@
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
package crons
|
||||
|
||||
import (
|
||||
@@ -177,12 +176,13 @@ func Delete(sysCron *entity.SysCron) (err error) {
|
||||
if sysCron == nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range gcron.Entries() {
|
||||
if v.Name == sysCron.Name {
|
||||
gcron.Remove(v.Name)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user