40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?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,'删除购物车');
|
|
}
|
|
}
|