where('name', 'configgroup')->value('value'); $configGroupTemp = json_decode($configGroupTemp, true); foreach ($configGroupTemp as $k => $v) { $configGroup[$k]['name'] = $k; $configGroup[$k]['title'] = __($v); $configGroup[$k]['list'] = []; } return $configGroup; } /** * 按分组读取配置列表 * @param int $userSettings 是否是用户设置 * @param int $userExclusive 是否是用户专有设置 * @param int $uniappAvailable 是否是uniapp专有设置 * @return array */ public static function getConfigListByGroup($userSettings, $userExclusive, $uniappAvailable = null) { $configList = self::getConfigGroup(); $where = []; if ($userSettings !== null) { $where['user_settings'] = $userSettings; } if ($userExclusive !== null) { $where['user_exclusive'] = $userExclusive; } if ($uniappAvailable !== null) { $where['uniapp_available'] = $uniappAvailable; } $imConfig = collection(self::where($where)->order('weigh desc,id desc')->select())->toArray(); foreach ($imConfig as $key => $value) { if (!isset($configList[$value['group']]) || $value['name'] == 'configgroup') { continue; } $value['title'] = __($value['title']); if (in_array($value['type'], ['select', 'selects', 'checkbox'])) { $value['value'] = explode(',', $value['value']); } $value['content'] = json_decode($value['content'], true); $value['tip'] = htmlspecialchars($value['tip']); $configList[$value['group']]['list'][] = $value; } $index = 0; foreach ($configList as $key => &$value) { if (count($value['list'])) { $value['active'] = !$index ? true : false; $index++; } else { unset($configList[$key]); } } return $configList; } public static function getArrayData($data) { if (!isset($data['value'])) { $result = []; foreach ($data as $index => $datum) { $result['field'][$index] = $datum['key']; $result['value'][$index] = $datum['value']; } $data = $result; } $fieldarr = $valuearr = []; $field = isset($data['field']) ? $data['field'] : (isset($data['key']) ? $data['key'] : []); $value = isset($data['value']) ? $data['value'] : []; foreach ($field as $m => $n) { if ($n != '') { $fieldarr[] = $field[$m]; $valuearr[] = $value[$m]; } } return $fieldarr ? array_combine($fieldarr, $valuearr) : []; } }