orderId,'订单自动退款队列start'); $t = \Yii::$app->db->beginTransaction(); try { $this->setRequest(); $Prescription = Prescription::find()->where([ 'id' => $this->orderId, 'is_pay' => 1, 'cancel_status' => 0, ])->one(); if(!$Prescription){ throw new Exception('处方订单不存在'); } //生成记录 $PrescripOrderRefund = new PrescripOrderRefund(); $PrescripOrderRefund->user_id = $Prescription->user_id; $PrescripOrderRefund->order_id = $Prescription->id; $PrescripOrderRefund->refund_no = FuncHelper::generate_order_no('RF'); $PrescripOrderRefund->refund_price = $Prescription->total_pay_price; $PrescripOrderRefund->remark = '超时未接诊自动退款'; $PrescripOrderRefund->saveOrFail(); //取消状态 $Prescription->cancel_status = 1; $Prescription->cancel_time = time(); $Prescription->cancel_remark = '超时未接诊自动取消'; //退款状态 $Prescription->refund_status = 1; $Prescription->refund_time = time(); $Prescription->saveOrFail(); //退款操作 $PrescripRefundForm = new PrescripRefundForm(); $PrescripRefundForm->refundMoney($PrescripOrderRefund); $t->commit(); PrescripOrderLog::saveLog($this->orderId,'订单自动退款队列end'); } catch (\Exception $exception) { $t->rollBack(); PrescripOrderLog::saveLog($this->orderId,'订单自动退款队列异常:'.$exception->getMessage()); return; } } }