' => 0], null, '*', 'id'); $data = []; foreach ($arr as $item) { $id = $item['id'] ?? 0; $name = $item['name'] ?? ''; $data[$id] = $name; } $itemList = ProductClass::getAllByCondition(['id>'=>0], null, '*', null, true); if (!empty($itemList)) { foreach ($itemList as $item) { $bigUnitId = $item->bigUnitId ?? 1; $smallUnitId = $item->smallUnitId ?? 1; $bigUnit = $data[$bigUnitId] ?? '扎'; $smallUnit = $data[$smallUnitId] ?? '支'; $item->bigUnit = $bigUnit; $item->smallUnit = $smallUnit; $item->save(); } } } }