Files
xk-api-yii/common/handlers/ProductOrderCreatedHandlerClass.php
2024-09-19 11:32:39 +08:00

35 lines
1.0 KiB
PHP

<?php
namespace common\handlers;
use common\jobs\ProductOrderCancelJob;
class ProductOrderCreatedHandlerClass extends BaseProductOrderHandler
{
public function handle()
{
self::execute();
}
protected function execute()
{
$this->autoCancel();
return $this;
}
public function autoCancel()
{
$config = \Yii::$app->params;
$orderAutoCancelMinute = isset($config['product_order']['over_time']) ? $config['product_order']['over_time'] : 900;
if (is_numeric($orderAutoCancelMinute) && $orderAutoCancelMinute >= 0) {
// 订单自动取消任务
\Yii::$app->queue->delay($orderAutoCancelMinute)->push(new ProductOrderCancelJob([
'orderId' => $this->event->order->id,
]));
$autoCancelTime = $this->event->order->created_at + $orderAutoCancelMinute;
$this->event->order->auto_cancel_time = $autoCancelTime;
$this->event->order->save();
}
return $this;
}
}