示例#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
 /**
  * Сохранение заявки.
  *
  * @return Lead|bool
  */
 public function save()
 {
     if ($this->leadId) {
         $lead = Lead::findOne(['lead_id' => $this->leadId]);
     } else {
         $lead = new Lead();
     }
     if ($lead->getStatus() && $lead->getStatus() != $this->getStatus()) {
         $lead->setChangeStatusUserId($this->userId);
     }
     $lead->setLandingId($this->landingId);
     $lead->setFormId($this->formId);
     $lead->setUserId($this->userId);
     $lead->setCompanyId($this->companyId);
     $lead->setStatus($this->status);
     $lead->setPrice($this->price);
     $leadData = [];
     foreach ($this->data as $fieldName => $fieldValue) {
         $leadData[] = ['name' => $fieldName, 'label' => $fieldValue['label'], 'value' => $fieldValue['value']];
     }
     $lead->setData(json_encode($leadData));
     $lead->save();
     return $lead ?: false;
 }