'大洲/区域', 'country' => '国家/地区', 'industry' => '行业', ]; } public static function getOptions(string $type, string $lang = 'cn'): array { $type = trim($type); $lang = strtolower(trim($lang)); $lang = $lang !== '' ? $lang : 'cn'; $rows = static::where(['type' => $type, 'lang' => $lang, 'status' => 1]) ->order('listorder', 'asc') ->order('id', 'asc') ->select() ->toArray(); if (!$rows && $lang !== 'cn') { $rows = static::where(['type' => $type, 'lang' => 'cn', 'status' => 1]) ->order('listorder', 'asc') ->order('id', 'asc') ->select() ->toArray(); } return $rows ?: []; } public static function getCountryTree(string $lang = 'cn'): array { $lang = strtolower(trim($lang)); $lang = $lang !== '' ? $lang : 'cn'; $regions = static::getOptions('country_region', $lang); $countries = static::getOptions('country', $lang); $tree = []; foreach ($regions as $region) { $value = (string)$region['value']; $tree[$value] = [ 'title' => $region['title'], 'value' => $value, 'children' => [], ]; } foreach ($countries as $country) { $parent = (string)($country['parent_value'] ?? ''); if ($parent === '' || !isset($tree[$parent])) { $parent = 'OTHER'; if (!isset($tree[$parent])) { $tree[$parent] = [ 'title' => $lang === 'en' ? 'Other' : '其他', 'value' => $parent, 'children' => [], ]; } } $tree[$parent]['children'][] = [ 'title' => $country['title'], 'value' => $country['value'], ]; } return array_values($tree); } }