}
if (!empty($result['stores'])) {
- $products1cStores = Products1c::find()
- ->andWhere(['tip' => 'city_store'])
- ->indexBy('id')
- ->asArray()
- ->column();
- $products1cTerminals = Products1c::find()
- ->andWhere(['tip' => 'terminals'])
- ->indexBy('id')
+ $products1cByTip = Products1c::find()
+ ->select(['id', 'tip'])
+ ->andWhere(['tip' => ['kkms', 'terminals', 'city_store']])
+ ->groupBy(['tip', 'id'])
->asArray()
- ->column();
+ ->all();
+ $products1cByTipMap = [];
+ foreach ($products1cByTip as $item) {
+ $products1cByTipMap[$item['tip']][] = $item['id'];
+ }
$existTerminals = Terminals::find()
->indexBy('id')
->asArray()
->column();
- $products1cKkms = Products1c::find()
- ->andWhere(['tip' => 'kkms'])
- ->indexBy('id')
- ->asArray()
- ->column();
+
foreach ($result['stores'] as $gi => $arr) {
- if (!in_array($arr["id"], $products1cStores)) {
+ if (!in_array($arr["id"], $products1cByTipMap['city_store'])) {
$products1c = new Products1c;
$products1c->id = $arr["id"];
$products1c->tip = 'city_store';
if ($arr["terminals"]) {
$k = 0;
foreach ($arr["terminals"] as $gi2 => $arr2) {
- if (!in_array($arr2['id'], $products1cTerminals)) {
+ if (!in_array($arr2['id'], $products1cByTipMap['terminals'])) {
$products1c2 = new Products1c;
$products1c2->id = $arr2['id'];
$products1c2->tip = 'terminals';
if ($arr['kkms']) {
foreach ($arr["kkms"] as $gi2 => $arr2) {
- if (!in_array($arr2['id'], $products1cKkms)) {
+ if (!in_array($arr2['id'], $products1cByTipMap['kkms'])) {
$products1c3 = new Products1c;
$products1c3->id = $arr2["id"];
$products1c3->tip = 'kkms';