div class="input-block__grp">
<input
class="input-block__field input-block__field-weight-tn_js"
autocomplete="off"
type="text"
value=""
readonly
/>
</div>
<div class="crm-form-calc__table-cell">
<span class="table-cell-inner-span"></span>
</div>
select * from `crmAmoUser` where `crmAmoUser`.`crmCompanyID` is null and `amoID` = ? and `crmCompanyID` = ?"
class AmoUser extends BaseCRM
{
protected $table = 'crmAmoUser';
protected $casts = [
'created' => 'datetime',
'updated' => 'datetime',
'name' => 'string',
'amoID' => 'int',
'crmCompanyID' => 'int',
];
protected $fillable = [
'name',
'amoID',
'crmCompanyID' //если закомментировать сьтрочку, то работает.
];
public function Company(){
return $this->belongsTo(Company::class, 'crmCompanyID');
}
}
class Company extends BaseCRM
{
protected $table = 'crmCompany';
public static $checkChangelog = false;
protected $casts = [
'created' => 'datetime',
'updated' => 'datetime',
'active' => 'boolean',
];
protected $fillable = [
'active'
];
public function AmoUsers()
{
return $this->hasMany(AmoUser::class, "crmCompanyID");
}
}
if ($companyID==="" || $companyID===null|| empty($companyID)){
echo "errorst\n"; // не вывело
}
var_dump($companyID); // выводит int(1)
echo $companyID; //выводит 1
echo $mainUserField ; //выводит 11198626
$amoUserEntity = AmoUser::where('amoID', $mainUserField)->where('crmCompanyID',$companyID)->first();
if ($amoUserEntity===null){
Но попало сюда, несмотря на то что юзер в бд есть
var_dump($companyID); //вывело int(1)
echo $companyID; //вывело 1
$amoUserEntity=new AmoUser();
$amoUserEntity->amoID=$mainUserField;
$amoUserEntity->crmCompanyID=1; // вот тут, грубо присваиваю 1.
$amoUserEntity->save(); // и тут выдало ошибку Illuminate\Database\QueryException : SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'crmCompanyID' cannot be null (SQL: insert into `crmAmoUser` (`crmCompanyID`, `amoID`, `updated`, `created`) values (, 11198626, 2025-01-07 19:25:50, 2025-01-07 19:25:50)
}
if ($companyID==="" || $companyID===null|| empty($companyID)){
echo "errorst\n"; // не вывело
}
$amoUserEntity = AmoUser::where('amoID', $mainUserField)->where('crmCompanyID',$companyID)->first();
if ($amoUserEntity===null){
Но попало сюда, несмотря на то что юзер в бд есть
var_dump($companyID); //вывело int(1)
echo $companyID; //вывело 1
$amoUserEntity=new AmoUser();
$amoUserEntity->amoID=$mainUserField;
$amoUserEntity->crmCompanyID=$companyID;
$amoUserEntity->save(); // и тут выдало ошибку Illuminate\Database\QueryException : SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'crmCompanyID' cannot be null (SQL: insert into `crmAmoUser` (`crmCompanyID`, `amoID`, `updated`, `created`) values (, 11198626, 2025-01-07 19:25:50, 2025-01-07 19:25:50)
}
public static function import($datas, $companyID, $constants=[])
protected $fillable = [
'name',
'amoID',
// 'crmCompanyID'
];
$amoContactEntity = AmoContact::where('amoID',$contacts[0]->getId())->where('crmCompanyID',$companyID)->first();
if ($amoContactEntity===null){
$amoContactEntity=new AmoContact();
$amoContactEntity->crmCompanyID=(int)$companyID;
$amoContactEntity->amoID=$contacts[0]->getId();
$amoContactEntity->name="fromLead";
$amoContactEntity->save();
}
$entity->crmAmoContact2ID = $amoContactEntity->id;
foreach ($companies as $company){
$amoCRMIntegration=new AmoCRMIntegration($company->id);
$amoCRMIntegration->getContacts($all); // пробовала передать $amoCRMIntegration->getLeadsWithContacts($all,(int)$company->id); .. все равно никак
}
Integrity constraint violation: 1048 Column 'crmCompanyID' cannot be null (SQL: insert into `crmAmoContact` (`amoID`, `crmCompanyID`, `name`, `updated`, `created`) values (142, , FromLead, 2025-01-07 22:36:29, 2025-01-07 22:36:29))
AmoLeadModel::import($leads,$this->crmCompanyID,$constants);
$amoStatusEntity = AmoStatus::where('amoID', $row->getStatusId())->where('crmCompanyID',$companyID)->first();
if ($amoStatusEntity===null){
//статус существует, но все равно попадает сюда, значит второй where не обрабатывает почему то....
var_dump($companyID); //int(1)
echo $companyID; //1
$amoStatusEntity=new AmoStatus();
$amoStatusEntity->amoID=$row->getStatusId();
$amoStatusEntity->crmCompanyID=$companyID;
$amoStatusEntity->name="fromLead";
$amoStatusEntity->save();
}
int(1)
1
Illuminate\Database\QueryException : SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'crmCompanyID' cannot be null (SQL: insert into `crmAmoStatus` (`amoID`, `crmCompanyID`, `name`, `updated`, `created`) values (142, , FromLead, 2025-01-07 23:01:44, 2025-01-07 23:01:44))
class AmoStatus extends BaseCRM
{
protected $table = 'crmAmoStatus';
protected $casts = [
'created' => 'datetime',
'updated' => 'datetime',
'name' => 'string',
'amoID' => 'int',
'crmCompanyID' => 'int',
];
protected $fillable = [
'name',
'amoID',
'crmCompanyID'
];
AmoContact::firstOrNew(['amoID' => $contacts[0]->getId(),'crmCompanyID'=>$companyID]);
$amoContactEntity = AmoContact::where('amoID',$contacts[0]->getId())->where('crmCompanyID',$companyID)->first();
if ($amoContactEntity===null){
$amoContactEntity=new AmoContact();
$amoContactEntity->crmCompanyID=(int)$companyID;
$amoContactEntity->amoID=$contacts[0]->getId();
$amoContactEntity->name="fromLead";
$amoContactEntity->save();
}
$entity->crmAmoContact2ID = $amoContactEntity->id;
Illuminate\Database\QueryException : SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'crmCompanyID' cannot be null (SQL: insert into `crmAmoUser` (`crmCompanyID`, `amoID`, `updated`, `created`) values (, 11198626, 2025-01-07 19:25:50, 2025-01-07 19:25:50)
class AmoContact extends BaseCRM
{
protected $table = 'crmAmoContact';
protected $casts = [
'created' => 'datetime',
'updated' => 'datetime',
'name' => 'string',
'phone' => 'string',
'phone1' => 'string',
'phoneNorm' => 'string',
'email'=>'string',
'amoID' => 'int',
'crmAmoUserID' => 'int',
'crmAmoUser2ID' => 'int',
'crmAmoContactTypeID' => 'int',
'crmCompanyID' => 'int',
];
protected $fillable = [
'name',
'amoID',
'crmCompanyID' //не учитывает в AmoContact::firstOrNew(['amoID' => $mainUserField,'crmCompanyID'=>$companyID]), AmoContact::updateOrCreate(['amoID' => $mainUserField,'crmCompanyID'=>$companyID])
];
.....
}
AmoContact::firstOrNew(['amoID' => $contacts[0]->getId(),'crmCompanyID'=>$companyID]);
//тоже не учитывает второй элемент массива первого параметра,несмотря на то, что
protected $fillable = [
'name',
'amoID',
'crmCompanyID'
];
//заполнено
Integrity constraint violation: 1048 Column 'crmCompanyID' cannot be null (SQL: insert into `crmAmoContact` (`amoID`, `crmCompanyID`, `updated`, `created`) values (42397607, , 2025-01-06 17:31:54, 2025-01-06 17:31:54))
Model::updateOrCreate(
['amoID' => 43222233, 'crmCompanyID' => 1], // Условия для поиска
['updated' => now(), 'created' => now()] // Данные для обновления или создания
);
Column 'crmCompanyID' cannot be null (SQL: insert into `crmAmoContact` (`amoID`, `crmCompanyID`, `updated`, `created`) values (42397607, , 2025-01-06 17:31:54, 2025-01-06 17:31:54))
'updated' => "2024-01-01 22:00:24", 'created' => now()
, что мне не подходит. AmoContact::firstOrNew(['amoID' => $contacts[0]->getId(),'crmCompanyID'=>$companyID]);
protected $fillable = [
'name',
'amoID',
'crmCompanyID'
];
class Model extends BaseCRM
{
protected $table = 'crmAmoContact';
protected $casts = [
'created' => 'datetime',
'updated' => 'datetime',
'name' => 'string',
'phone' => 'string',
'phone1' => 'string',
'phoneNorm' => 'string',
'email'=>'string',
'amoID' => 'int',
'crmAmoUserID' => 'int',
'crmAmoUser2ID' => 'int',
'crmAmoContactTypeID' => 'int',
'crmCompanyID' => 'int',
];
protected $fillable = [
'name',
'amoID',
// 'crmCompanyID'
];
...
}
SELECT * FROM `crmAmoLead` WHERE `amoID`=29705803 and `crmCompanyID`=1
занимает 0.0003 секунд
SELECT * FROM `crmAmoStatus` WHERE `amoID`=48505075 and `crmCompanyID`=1
0.0002 сек
SELECT * FROM `crmAmoContact` WHERE `amoID`=43222233 and `crmCompanyID`=1
0.0008 сек