示例#1
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;
 }