public static function GetInstance() { if (self::$instance) { return self::$instance; } $login = "******"; $password = "******"; return self::$instance = new AmoCRM("cargotogo", $login, $password); }
public function sendCRMVirtual($model) { $company = Company::model()->findByPk($this->company_id); if (!$company->tiu_id) { return false; } require_once Yii::app()->basePath . "/components/AmoCRM.php"; $amo = AmoCRM::GetInstance(); $responsible = $amo->GetResponsible($this->id); $addLead = false; if ($this->crm_user_id) { $crmUserId = $this->crm_user_id; } else { $crmUserId = $amo->AddUser($this->id, trim($this->last_name . " ", $this->first_name . " " . $this->middle_name), $this->email, $this->contact_phone_prefix . $this->contact_phone, $this->create_time, $this->update_time, $this->company_id, null, $responsible); $this->crm_user_id = $crmUserId; if (!$crmUserId) { return false; //TODO throw? } $command = Yii::app()->db->createCommand(); $command->update('site_user_user', array('crm_user_id' => $crmUserId), 'id=:id', array(':id' => $this->id)); $addLead = true; } if (!$company->crm_company_id) { $companyStatus = ""; if ($company->tiu_id) { $companyStatus = "Виртуал"; } else { if ($company->verify) { $companyStatus = "Верифицирован"; } else { if ($company->validate) { $companyStatus = "Создана компания"; } else { $companyStatus = "Начальная регистрация"; } } } $crmCompanyId = $amo->AddCompany($crmUserId, $company->id, $company->name, $company->create, $company->INN, $company->balance, $companyStatus, $responsible, $this->getPromo()); if (!$crmCompanyId) { return false; //TODO throw? } $command = Yii::app()->db->createCommand(); $command->update('site_company', array('crm_company_id' => $crmCompanyId), 'id=:id', array(':id' => $company->id)); } $client = Yii::app()->user->getProfile(); $clientCompany = Company::model()->findByPk($client->company_id); $href = "http://cargotogo.com/company/" . $clientCompany->id; $name = $clientCompany->name; $type = "Неизвестно"; switch ($model) { // private $_aproveModels = ['Cargo','StoreCall','Reis','Sklad','SkladCall','Insurance','SpecialTechnique','Product','Custom'] case "Product": $type = "товар"; break; case "Cargo": $type = "груз"; break; case "Reis": $type = "транспорт"; break; case "Sklad": $type = "склад"; break; case "Custom": $type = "таможня"; break; case "SpecialTechnique": $type = "спецтехника"; break; } $promo = $this->getPromo(); $leadId = $amo->AddLead($crmUserId, "Заказ у виртуальной компании", "", $responsible, AmoCRM::VIRTUAL_PROMO, $type, $_SERVER["HTTP_REFERER"], "https://cargotogo.amocrm.ru/contacts/detail/" . $client->crm_user_id); $amo->AddComment($client->crm_user_id, "Заказ у компании: https://cargotogo.amocrm.ru/leads/detail/" . $leadId); }
public function updateCRM() { require_once "/cargotogo/docs/c2go/protected/components/AmoCRM.php"; $amo = AmoCRM::GetInstance(); $companyStatus = ""; if ($this->tiu_id) { $companyStatus = "Виртуал"; } else { if ($this->verify) { $companyStatus = "Верифицирован"; } else { if ($this->validate) { $companyStatus = "Создана компания"; } else { $companyStatus = "Начальная регистрация"; } } } $amo->UpdateCompany($this->crm_company_id, $this->id, $this->name, $this->create, $this->INN, $this->balance, $companyStatus); }