' => 0], null, '*', 'id'); $map = []; if (!empty($list)) { foreach ($list as $shopId => $shop) { $mainId = $shop['mainId'] ?? 0; $map[$shopId] = $mainId; } } $statList = StatItemClass::getAllByCondition(['id>' => 0], null, '*', null, true); if (!empty($statList)) { foreach ($statList as $stat) { $currentMainId = $stat->mainId ?? 0; if (!empty($currentMainId)) { continue; } $currentShopId = $stat->shopId ?? 0; if (empty($currentShopId)) { continue; } $newMainId = $map[$currentShopId] ?? 0; $stat->mainId = $newMainId; $stat->save(); } } $statList = StatItemMonthClass::getAllByCondition(['id>' => 0], null, '*', null, true); if (!empty($statList)) { foreach ($statList as $stat) { $currentMainId = $stat->mainId ?? 0; if (!empty($currentMainId)) { continue; } $currentShopId = $stat->shopId ?? 0; if (empty($currentShopId)) { continue; } $newMainId = $map[$currentShopId] ?? 0; $stat->mainId = $newMainId; $stat->save(); } } } }