Files
xk-api-yii/common/handlers/orderHandler/BaseOrderCreatedHandler.php

40 lines
1.2 KiB
PHP
Raw Normal View History

2024-09-19 11:32:39 +08:00
<?php
namespace common\handlers\orderHandler;
use common\forms\order\CommonLog;
use common\jobs\OrderCancelJob;
use common\models\Cart;
/**
* @property User $user
*/
abstract class BaseOrderCreatedHandler extends BaseOrderHandler
{
public $user;
protected function setAutoCancel()
{
$orderAutoCancelMinute = \Yii::$app->mall->getMallSettingOne('over_time');
if (is_numeric($orderAutoCancelMinute) && $orderAutoCancelMinute >= 0) {
CommonLog::saveLog($this->event->order->id,'添加自动取消延迟队列');
// 订单自动取消任务
\Yii::$app->queue->delay($orderAutoCancelMinute * 60)->push(new OrderCancelJob([
'orderId' => $this->event->order->id,
]));
$autoCancelTime = $this->event->order->created_at + $orderAutoCancelMinute * 60;
$this->event->order->auto_cancel_time = $autoCancelTime;
$this->event->order->save();
}
return $this;
}
/**
* 购物车商品购买后删除
*/
protected function deleteCartGoods()
{
Cart::deleteAll(['id' => $this->event->cartIds]);
CommonLog::saveLog($this->event->order->id,'删除购物车');
}
}