$v) { $html[] = sprintf(Form::label("{$name}-{$k}", "%s {$v}"), Form::radio($name, $k, in_array($k, $selected), ['id' => "{$name}-{$k}"])); } return '
' . implode(' ', $html) . '
'; } /** * 生成复选按钮组 * @param string $name * @param array $list * @param mixed $selected * @return string */ function build_checkboxs($name, $list = [], $selected = null) { $html = []; $selected = is_null($selected) ? [] : $selected; $selected = is_array($selected) ? $selected : explode(',', $selected); foreach ($list as $k => $v) { $html[] = sprintf(Form::label("{$name}-{$k}", "%s {$v}"), Form::checkbox($name, $k, in_array($k, $selected), ['id' => "{$name}-{$k}"])); } return '
' . implode(' ', $html) . '
'; } /** * 生成分类下拉列表框 * @param string $name * @param string $type * @param mixed $selected * @param array $attr * @return string */ function build_category_select($name, $type, $selected = null, $attr = [], $header = []) { $tree = Tree::instance(); $tree->init(Category::getCategoryArray($type), 'pid'); $categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name'); $categorydata = $header ? $header : []; foreach ($categorylist as $k => $v) { $categorydata[$v['id']] = $v['name']; } $attr = array_merge(['id' => "c-{$name}", 'class' => 'form-control selectpicker'], $attr); return build_select($name, $categorydata, $selected, $attr); } /** * 生成表格操作按钮栏 * @param array $btns 按钮组 * @param array $attr 按钮属性值 * @return string */ function build_toolbar($btns = NULL, $attr = []) { $auth = \app\admin\library\Auth::instance(); $controller = str_replace('.', '/', strtolower(think\Request::instance()->controller())); $btns = $btns ? $btns : ['refresh', 'add', 'edit', 'del', 'import']; $btns = is_array($btns) ? $btns : explode(',', $btns); $index = array_search('delete', $btns); if ($index !== FALSE) { $btns[$index] = 'del'; } $btnAttr = [ 'refresh' => ['javascript:;', 'btn btn-primary btn-refresh', 'fa fa-refresh', '', __('Refresh')], 'add' => ['javascript:;', 'btn btn-success btn-add', 'fa fa-plus', __('Add'), __('Add')], 'edit' => ['javascript:;', 'btn btn-success btn-edit btn-disabled disabled', 'fa fa-pencil', __('Edit'), __('Edit')], 'del' => ['javascript:;', 'btn btn-danger btn-del btn-disabled disabled', 'fa fa-trash', __('Delete'), __('Delete')], 'import' => ['javascript:;', 'btn btn-danger btn-import', 'fa fa-upload', __('Import'), __('Import')], ]; $btnAttr = array_merge($btnAttr, $attr); $html = []; foreach ($btns as $k => $v) { //如果未定义或没有权限 if (!isset($btnAttr[$v]) || ($v !== 'refresh' && !$auth->check("{$controller}/{$v}"))) { continue; } list($href, $class, $icon, $text, $title) = $btnAttr[$v]; $extend = $v == 'import' ? 'id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"' : ''; $html[] = ' ' . $text . ''; } return implode(' ', $html); } /** * 生成页面Heading * * @param string $path 指定的path * @return string */ function build_heading($path = NULL, $container = TRUE) { $title = $content = ''; if (is_null($path)) { $action = request()->action(); $controller = str_replace('.', '/', request()->controller()); $path = strtolower($controller . ($action && $action != 'index' ? '/' . $action : '')); } // 根据当前的URI自动匹配父节点的标题和备注 $data = Db::name('auth_rule')->where('name', $path)->field('title,remark')->find(); if ($data) { $title = __($data['title']); $content = __($data['remark']); } if (!$content) return ''; $result = '
' . $title . '' . $content . '
'; if ($container) { $result = '
' . $result . '
'; } return $result; } //验证身份证是否有效 function validateIDCard($IDCard) { if (strlen($IDCard) == 18) { return check18IDCard($IDCard); } elseif ((strlen($IDCard) == 15)) { $IDCard = convertIDCard15to18($IDCard); return check18IDCard($IDCard); } else { return false; } } //计算身份证的最后一位验证码,根据国家标准GB 11643-1999 function calcIDCardCode($IDCardBody) { if (strlen($IDCardBody) != 17) { return false; } //加权因子 $factor = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); //校验码对应值 $code = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); $checksum = 0; for ($i = 0; $i < strlen($IDCardBody); $i++) { $checksum += substr($IDCardBody, $i, 1) * $factor[$i]; } return $code[$checksum % 11]; } // 将15位身份证升级到18位 function convertIDCard15to18($IDCard) { if (strlen($IDCard) != 15) { return false; } else { // 如果身份证顺序码是996 997 998 999,这些是为百岁以上老人的特殊编码 if (array_search(substr($IDCard, 12, 3), array('996', '997', '998', '999')) !== false) { $IDCard = substr($IDCard, 0, 6) . '18' . substr($IDCard, 6, 9); } else { $IDCard = substr($IDCard, 0, 6) . '19' . substr($IDCard, 6, 9); } } $IDCard = $IDCard . calcIDCardCode($IDCard); return $IDCard; } // 18位身份证校验码有效性检查 function check18IDCard($IDCard) { if (strlen($IDCard) != 18) { return false; } $IDCardBody = substr($IDCard, 0, 17); //身份证主体 $IDCardCode = strtoupper(substr($IDCard, 17, 1)); //身份证最后一位的验证码 if (calcIDCardCode($IDCardBody) != $IDCardCode) { return false; } else { return true; } }