예제 #1
0
 /**
  * Добавление заявки
  *
  * @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;
 }
예제 #2
0
 public function getActiveLandingNamesByCompanyId($companyId)
 {
     $landings = Landing::findAll(['company_id' => $companyId, 'is_deleted' => false]);
     $landingNames = [];
     if (!empty($landings)) {
         foreach ($landings as $landing) {
             $landingNames[$landing->getLandingId()] = $landing->getName();
         }
     }
     return $landingNames;
 }
예제 #3
0
 /**
  * Удаление формы.
  *
  * @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]);
 }
예제 #4
0
 /**
  * Удаление промо-страницы.
  *
  * @param int $id
  * @return string
  * @throws NotFoundHttpException
  */
 public function actionDelete($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('Промо-страница не найдена!');
     }
     if (Yii::$app->getRequest()->isPost && Yii::$app->getRequest()->post('delete')) {
         $model->setIsDeleted(true);
         if ($model->save()) {
             Yii::$app->getSession()->setFlash('success', 'Промо-страница успешно удалена!');
             return $this->redirect(['index']);
         } else {
             Yii::$app->getSession()->setFlash('danger', 'При удалении промо-страницы возникла ошибка! Пожалуйста, попробуйте позже!');
         }
     }
     return $this->render('delete', ['model' => $model]);
 }
예제 #5
0
 /**
  * Возвращает модель промо-страницы.
  *
  * @return \backend\models\Landing
  */
 public function getLanding()
 {
     return $this->hasOne(Landing::className(), ['landing_id' => 'landing_id'])->one();
 }