orderId,'订单自动取消队列start'); $t = \Yii::$app->db->beginTransaction(); try { $this->setRequest(); $Prescription = Prescription::findOne([ 'id' => $this->orderId, 'is_pay' => 0, // 'pay_type' => 0, ]); if (!$Prescription || $Prescription->cancel_status == 1) { throw new \Exception('未支付订单不存在或已取消'); } $Prescription->cancel_status = 1; $Prescription->cancel_time = time(); $Prescription->cancel_remark = '超时自动取消订单'; if ($Prescription->save()) { PrescripOrderLog::saveLog($this->orderId,'队列触发订单取消canceled事件'); $event = new OrderEvent([ 'order' => $Prescription, ]); \Yii::$app->trigger(Prescription::EVENT_CANCELED, $event); $t->commit(); } else { throw new \Exception((new BaseModel())->getErrorMsg($Prescription)); } PrescripOrderLog::saveLog($this->orderId,'订单自动取消队列end'); } catch (\Exception $exception) { $t->rollBack(); PrescripOrderLog::saveLog($this->orderId,'订单自动取消队列异常:'.$exception->getMessage()); return; } } }