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.

59 lines
1.5 KiB

package order
import (
"git.oa00.com/go/mysql"
"log"
"recook/internal/dbc"
"recook/internal/model/order"
"time"
)
// 订单自动确认时间
var days time.Duration = 15
// PlanMonitorTradeSucOrderTask 一定要保证上个月的订单全部完成
func PlanMonitorTradeSucOrderTask() {
t := time.Now().Add(time.Hour * 24 * -days)
var successOrderList []order.Information
var orderListGoods order.GoodsDetail
has := 0
mysql.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() {
now := time.Now()
var expireOrderList []order.Information
mysql.Db.Find(&expireOrderList, "status = 0 AND expire_time <= ? and order_type = 1", now)
for _, v := range expireOrderList {
err := CancelOrExpireOrder(&v, false)
if err != nil {
log.Fatal("订单无法自动设置过期:" + err.Error())
}
}
}