2024-06-17 14:18:39 +08:00
|
|
|
package console
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/qit-team/snow-core/command"
|
2024-07-16 15:52:49 +08:00
|
|
|
"qteam/app/models/ordersmodel"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
2024-06-17 14:18:39 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func RegisterCommand(c *command.Command) {
|
|
|
|
c.AddFunc("test", test)
|
|
|
|
}
|
2024-07-16 15:52:49 +08:00
|
|
|
|
|
|
|
func ClearUnpayOrder() {
|
2024-07-17 14:34:25 +08:00
|
|
|
var expire = time.Now().Add(-15 * time.Minute).Format(time.DateTime)
|
2024-07-16 15:52:49 +08:00
|
|
|
var orders []ordersmodel.Orders
|
|
|
|
ordersmodel.GetInstance().GetDb().Where("state = 1 and create_time <= ?", expire).Select("id,product_id").Find(&orders)
|
|
|
|
var ids = make([]int, 0)
|
|
|
|
var prodIds = make([]string, 0)
|
|
|
|
for _, v := range orders {
|
|
|
|
ids = append(ids, v.Id)
|
|
|
|
prodIds = append(prodIds, strconv.Itoa(v.ProductId))
|
|
|
|
}
|
|
|
|
if len(prodIds) > 0 {
|
|
|
|
var session = ordersmodel.GetInstance().GetDb().NewSession()
|
|
|
|
session.Begin()
|
|
|
|
_, err := session.In("id", ids).Update(&ordersmodel.Orders{State: 9})
|
|
|
|
if err == nil {
|
|
|
|
_, err = session.Exec("update Products set stock=stock+1 where id in (" + strings.Join(prodIds, ",") + ")")
|
|
|
|
if err == nil {
|
|
|
|
session.Commit()
|
|
|
|
} else {
|
|
|
|
session.Rollback()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
session.Rollback()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|