<?php

namespace console\controllers;

use common\models\GoodsUser;
use common\models\Order;
use yii\console\Controller;

class OrderController extends Controller
{
    /**
     * 取消过期订单
     */
    public function actionAutoCancelExpirationOrder()
    {
        $now = date("Y-m-d H:i:s");
        $goodsUserIds = [];
        $orderIds = [];
        $orders = Order::find()->where(['status' => 1])->andWhere(["<","expiration_time",$now])->all();
        foreach ($orders as $order){
            /** @var Order $order */
            $goodsUserIds[] = $order->id;
            $orderIds[] = $order->goods_users_id;
        }
        Order::updateAll(['status' => 3], ['id' => $orderIds]);
        GoodsUser::updateAll(['status' => 2], ['id' => $goodsUserIds]);
        echo "ok"."\n";
    }
}