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