mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-24 04:01:31 +08:00
56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
|
|
* @license https://opensource.org/licenses/GPL-2.0
|
|
* @link https://www.koogua.com
|
|
*/
|
|
|
|
namespace App\Console\Tasks;
|
|
|
|
use App\Models\Order as OrderModel;
|
|
use Phalcon\Mvc\Model\Resultset;
|
|
use Phalcon\Mvc\Model\ResultsetInterface;
|
|
|
|
class CloseOrderTask extends Task
|
|
{
|
|
|
|
public function mainAction()
|
|
{
|
|
$orders = $this->findOrders();
|
|
|
|
echo sprintf('pending orders: %s', $orders->count()) . PHP_EOL;
|
|
|
|
if ($orders->count() == 0) return;
|
|
|
|
echo '------ start close order task ------' . PHP_EOL;
|
|
|
|
foreach ($orders as $order) {
|
|
$order->status = OrderModel::STATUS_CLOSED;
|
|
$order->update();
|
|
}
|
|
|
|
echo '------ end close order task ------' . PHP_EOL;
|
|
}
|
|
|
|
/**
|
|
* 查找待关闭订单
|
|
*
|
|
* @param int $limit
|
|
* @return ResultsetInterface|Resultset|OrderModel[]
|
|
*/
|
|
protected function findOrders($limit = 1000)
|
|
{
|
|
$status = OrderModel::STATUS_PENDING;
|
|
$time = time() - 12 * 3600;
|
|
$type = 0;
|
|
|
|
return OrderModel::query()
|
|
->where('status = :status:', ['status' => $status])
|
|
->andWhere('promotion_type = :type:', ['type' => $type])
|
|
->andWhere('create_time < :time:', ['time' => $time])
|
|
->limit($limit)
|
|
->execute();
|
|
}
|
|
|
|
}
|