示例#1
0
 public function actionCreate()
 {
     $model = new Payment();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#2
0
 public function actionCustomerCreate()
 {
     $model = new Order(['scenario' => 'customer']);
     if ($model->load(yii::$app->request->post())) {
         $model->date = date('Y-m-d');
         $model->time = date('H:i:s');
         $model->timestamp = time();
         $model->status = $this->module->defaultStatus;
         $model->payment = 'no';
         $model->user_id = yii::$app->user->id;
         if ($model->save()) {
             if ($ordersEmail = yii::$app->getModule('order')->ordersEmail) {
                 $sender = yii::$app->getModule('order')->mail->compose('admin_notification', ['model' => $model])->setTo($ordersEmail)->setFrom(yii::$app->getModule('order')->robotEmail)->setSubject(Yii::t('order', 'New order') . " #{$model->id} ({$model->client_name})")->send();
             }
             $module = $this->module;
             $orderEvent = new OrderEvent(['model' => $model]);
             $this->module->trigger($module::EVENT_ORDER_CREATE, $orderEvent);
             if ($paymentType = $model->paymentType) {
                 $payment = new Payment();
                 $payment->order_id = $model->id;
                 $payment->payment_type_id = $paymentType->id;
                 $payment->date = date('Y-m-d H:i:s');
                 $payment->amount = $model->getCost();
                 $payment->description = yii::t('order', 'Order #' . $model->id);
                 $payment->user_id = yii::$app->user->id;
                 $payment->ip = yii::$app->getRequest()->getUserIP();
                 $payment->save();
                 if ($widget = $paymentType->widget) {
                     return $widget::widget(['autoSend' => true, 'orderModel' => $model, 'description' => yii::t('order', 'Order #' . $model->id)]);
                 }
             }
             return $this->redirect([yii::$app->getModule('order')->successUrl, 'id' => $model->id, 'payment' => $model->payment_type_id]);
         } else {
             yii::$app->session->setFlash('orderError', yii::t('order', 'Error (check required fields)'));
             return $this->redirect(yii::$app->request->referrer);
         }
     } else {
         yii::$app->session->setFlash('orderError', yii::t('order', 'Error (check required fields)'));
         return $this->redirect(yii::$app->request->referrer);
     }
 }