You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package order
import (
"log"
"recook/internal/dbc"
"recook/internal/model/order"
"time"
)
// 订单自动确认时间
var days time.Duration = 15
// PlanMonitorTradeSucOrderTask 一定要保证上个月的订单全部完成
func PlanMonitorTradeSucOrderTask() {
for {
select {
case <-time.After(2 * time.Minute):
t := time.Now().Add(time.Hour * 24 * -days)
//为了测试将15天改成2分钟
//t := time.Now().Add(time.Minute * -5)
var successOrderList []order.Information
var orderListGoods order.GoodsDetail
has := 0
dbc.DB.Find(&successOrderList, "status = 1 AND express_status = 1 AND created_at <= ?", t.Format("2006-01-02 15:04:05"))
for _, orderInfo := range successOrderList {
//获取不是未发货的,且有售后的。
orderListGoods = order.GoodsDetail{}
has = 0
dbc.DB.Find(&orderListGoods, "((ass_type != 0 and refund_status != 2 ) OR (express_status=0 and ass_type = 0)) AND order_id= ?", orderInfo.ID)
if orderListGoods.ID > 0 {
//有数据,不执行
has = 1
}
// 发货时间验证
goodsExpress := order.GoodsExpress{}
dbc.DB.First(&goodsExpress, "order_id = ? and express_time > ?", orderInfo.ID, t.Format("2006-01-02 15:04:05"))
if goodsExpress.ID > 0 {
//有数据,不执行
has = 1
}
if has == 0 {
ConfirmOrderTradeSuc(&orderInfo)
}
}
}
}
}
func PlanMonitorExpireOrderTask() {
for {
select {
case <-time.After(2 * time.Minute):
now := time.Now()
var expireOrderList []order.Information
dbc.DB.Find(&expireOrderList, "status = 0 AND expire_time <= ?", now)
for _, v := range expireOrderList {
err := CancelOrExpireOrder(&v, false)
if err != nil {
log.Fatal("订单无法自动设置过期:" + err.Error())
}
}
}
}
}