/**
  * Добавление заявки
  *
  * @return string
  *
  * @throws NotFoundHttpException
  */
 public function actionLead()
 {
     $error = false;
     if (!isset($_POST['token']) && !isset($_POST['form_id'])) {
         $error = true;
     }
     $form = Form::findOne(['form_id' => (int) $_POST['form_id'], 'is_deleted' => false]);
     if (!$form) {
         $error = true;
     }
     $landing = Landing::findOne(['landing_id' => $form->getLandingId(), 'is_deleted' => false]);
     if (!$landing) {
         $error = true;
     }
     if ($_POST['token'] != $landing->getKeyAuth()) {
         $error = true;
     }
     if ($error) {
         echo 'error';
     } else {
         $lead = new Lead();
         $lead->setLandingId($landing->getLandingId());
         $lead->setCompanyId($landing->getCompanyId());
         $lead->setFormId($form->getFormId());
         $lead->setStatus(Lead::STATUS_OPEN);
         if (!empty($_POST['price'])) {
             $lead->setPrice($_POST['price']);
         }
         $lead->setData(json_encode($_POST['fields']));
         $lead->save();
         echo 'ok';
     }
     die;
 }
 /**
  * Детальная страница промо.
  *
  * @param int $id
  * @return string
  * @throws NotFoundHttpException
  */
 public function actionView($id)
 {
     /** @var \common\models\User $user */
     $user = Yii::$app->getUser()->getIdentity();
     $model = Landing::findOne(['landing_id' => $id, 'is_deleted' => false, 'company_id' => $user->getCompanyId()]);
     if (!$model) {
         throw new NotFoundHttpException('Промо-страница не найдена!');
     }
     $forms = Form::findAll(['landing_id' => $model->getLandingId(), 'is_deleted' => false]);
     return $this->render('view', ['model' => $model, 'user' => $user, 'forms' => $forms]);
 }
 /**
  * Удаление формы.
  *
  * @param int $id
  * @return string
  * @throws NotFoundHttpException
  */
 public function actionDelete($id)
 {
     /** @var \common\models\User $user */
     $user = Yii::$app->getUser()->getIdentity();
     $form = Form::findOne(['form_id' => $id, 'company_id' => $user->getCompanyId(), 'is_deleted' => false]);
     if (!$form) {
         throw new NotFoundHttpException("Not found form with ID: {$id}");
     }
     $landing = Landing::findOne(['landing_id' => $form->getLandingId(), 'is_deleted' => false]);
     if (!$landing) {
         throw new NotFoundHttpException("Not found landing!");
     }
     if (Yii::$app->getRequest()->post('delete')) {
         $form->setIsDeleted(true);
         if ($form->save()) {
             Yii::$app->getSession()->setFlash('success', 'Форма успешно удалена!');
             $this->redirect(['/landing/view', 'id' => $landing->getLandingId()]);
         } else {
             Yii::$app->getSession()->setFlash('danger', 'Невозможно удалить форму! Пожалуйста, попробуйте позже!');
         }
     }
     return $this->render('delete', ['form' => $form, 'landing' => $landing]);
 }
Beispiel #4
0
 /**
  * Возвращает модель формы.
  *
  * @return \common\models\Form
  */
 public function getForm()
 {
     return $this->hasOne(Form::className(), ['form_id' => 'form_id'])->one();
 }