}
if (!empty($result['stores'])) {
+ $products1cStores = Products1c::find()
+ ->andWhere(['tip' => 'city_store'])
+ ->indexBy('id')
+ ->asArray()
+ ->column();
+ $products1cTerminals = Products1c::find()
+ ->andWhere(['tip' => 'terminals'])
+ ->indexBy('id')
+ ->asArray()
+ ->column();
+ $existTerminals = Terminals::find()
+ ->indexBy('id')
+ ->asArray()
+ ->column();
+ $products1cKkms = Products1c::find()
+ ->andWhere(['tip' => 'kkms'])
+ ->indexBy('id')
+ ->asArray()
+ ->column();
foreach ($result['stores'] as $gi => $arr) {
- $products1c = new Products1c;
- $products1c->id = $arr["id"];
- $products1c->tip = 'city_store';
- $products1c->name = $arr["name"];
- $products1c->code = $arr["code"];
- $products1c->save();
- if ($products1c->getErrors()) {
- LogService::apiErrorLog(json_encode(["error_id" => 2, "error" => $products1c->getErrors()], JSON_UNESCAPED_UNICODE));
+ if (!in_array($arr["id"], $products1cStores)) {
+ $products1c = new Products1c;
+ $products1c->id = $arr["id"];
+ $products1c->tip = 'city_store';
+ $products1c->name = $arr["name"];
+ $products1c->code = $arr["code"];
+ $products1c->save();
+ if ($products1c->getErrors()) {
+ LogService::apiErrorLog(json_encode(["error_id" => 2, "error" => $products1c->getErrors()], JSON_UNESCAPED_UNICODE));
+ }
}
if ($arr["terminals"]) {
$k = 0;
- $products1cTerminals = Products1c::find()
- ->andWhere(['tip' => 'terminals'])
- ->indexBy('id')
- ->asArray()
- ->column();
- $existTerminals = Terminals::find()->indexBy('id')->asArray()->column();
foreach ($arr["terminals"] as $gi2 => $arr2) {
- if (in_array($arr2['id'], $products1cTerminals)) {
- continue;
- } else {
+ if (!in_array($arr2['id'], $products1cTerminals)) {
$products1c2 = new Products1c;
$products1c2->id = $arr2['id'];
$products1c2->tip = 'terminals';
}
}
- if (in_array($arr2['id'], $existTerminals)) {
- continue;
- } else {
+ if (!in_array($arr2['id'], $existTerminals)) {
$terminal = new Terminals;
$terminal->id = $arr2["id"];
$terminal->name = $arr2["name"];
if ($terminal->getErrors()) {
LogService::apiErrorLog(json_encode(["error_id" => 4, "error" => $terminal->getErrors()], JSON_UNESCAPED_UNICODE));
}
- $k++;
}
+ $k++;
}
}
if ($arr['kkms']) {
- $products1cKkms = Products1c::find()
- ->andWhere(['tip' => 'kkms'])
- ->indexBy('id')
- ->asArray()
- ->column();
foreach ($arr["kkms"] as $gi2 => $arr2) {
- if (in_array($arr2['id'], $products1cKkms)) {
- continue;
- } else {
+ if (!in_array($arr2['id'], $products1cKkms)) {
$products1c3 = new Products1c;
$products1c3->id = $arr2["id"];
$products1c3->tip = 'kkms';