// +----------------------------------------------------------------------
use cmf\view\Filter;
use cmf\view\Index;
use huo\model\menu\AdminMenuModel;
use huolib\tool\StrUtils;
function view_edit($url) {
return Index::edit($url);
}
function view_delete($url) {
return Index::delete($url);
}
function view_img($url, $width = '40') {
$url = cmf_get_image_preview_url($url);
return Index::img($url, $width);
}
function view_btn_ajax($url, $class = 'btn btn-xs btn-yellow js-ajax-dialog-btn') {
return Index::linkDialog($url);
}
function view_btn($url) {
return Index::img($url);
}
function view_copy($url, $class = '') {
return Index::copy($url, $class);
}
function filter_button() {
return Filter::button(['title' => lang('search'), 'type' => 'search']);
}
function filter_button_clear($url = '') {
return Filter::button(['title' => lang('clear'), 'type' => 'clear', 'uri' => $url]);
}
function button_export() {
return Index::exportData();
}
/**
* 输出文本框
*
* @param string $name 字段名称
* @param string $value 字段值
* @param string $placeholder 字段提示
*
* @return:string
*/
function filter_text($name, $value = '', $placeholder = '') {
return Filter::text($name, $value, $placeholder);
}
/**
* 设置游戏实名认证状态
*
* @param int $auth_status 实名认证状态1为关闭,2为开启强制,3为开启不强制
*
* @return:
*/
function select_identify($auth_status) {
return \huoIdentify\view\Index::selectIdentify($auth_status);
}
/**
* 列表编辑操作
*
* @param string|int $id_or_url 传入ID或者链接
*
* @param bool $new_frame 是否弹框
* @param int $width 弹框宽度
* @param int $height 弹框高度
*
* @return string
*/
function action_edit($id_or_url, $new_frame = false, $width = 800, $height = 500) {
if (is_numeric($id_or_url)) {
$_url = url('edit', ['id' => $id_or_url]);
$_auth_url = request()->module().'/'.request()->controller().'/edit';
} else {
$_url = $id_or_url;
$_auth_url = $id_or_url;
$name = explode('/', $id_or_url);
if (isset($name[3])) {
$_auth_url = $name[1].'/'.$name[2].'/'.$name[3];
}
}
$_auth = cmf_auth_check(cmf_get_current_admin_id(), $_auth_url);
if (false == $_auth) {
return '';
}
if ($new_frame) {
return \cmf\view\Index::linkOpenIframeDialog(
$_url, lang('EDIT'), '', $width, $height,
'btn-xs btn-link', lang('EDIT')
);
} else {
return \cmf\view\Index::edit($_url);
}
}
/**
* 列表页新增入口
*
* @param string $lang_key 语言KEY
* @param string $add_or_url 新增
*
* @param bool $new_frame 是否弹框
* @param int $width 弹框宽度
* @param int $height 弹框高度
*
* @return string
*/
function action_add($lang_key, $add_or_url = '', $new_frame = true, $width = 800, $height = 500) {
if (empty($add_or_url) || 'add' == $add_or_url) {
$_url = url('add');
$_auth_url = request()->module().'/'.request()->controller().'/add';
} else {
$_url = $add_or_url;
$_auth_url = $add_or_url;
}
$_auth = cmf_auth_check(cmf_get_current_admin_id(), $_auth_url);
if (false == $_auth) {
return '';
}
if (empty($lang_key)) {
$_lang = lang('ADD');
} else {
$_lang = lang($lang_key);
}
if (true == $_auth) {
if (true == $new_frame) {
return \cmf\view\Index::linkOpenIframeDialog(
$_url, $_lang, ''.$_lang, $width, $height, 'btn-success', $_lang
);
} else {
return ' '.$_lang.'';
}
}
return '';
}
/**
* 列表删除操作
*
* @param string|int $id_or_url 传入ID或者链接
*
* @return string
*/
function action_delete($id_or_url) {
if (is_numeric($id_or_url)) {
$_url = url('delete', ['id' => $id_or_url]);
$_auth_url = request()->module().'/'.request()->controller().'/delete';
} else {
$_url = $id_or_url;
$_auth_url = $id_or_url;
}
$_auth = cmf_auth_check(cmf_get_current_admin_id(), $_auth_url);
if (false == $_auth) {
return '';
}
return \cmf\view\Index::delete($_url);
}
/**
* 列表状态操作
*
* @param $id_or_url
* @param int $current_value 目前值
* @param int $value 目标值
* @param string $lang_key 变化的值
* @param string $current_status_str 目前状态名称
* @param string $name 字段
* @param string $func 函数
*
* @return string
*/
function action_status(
$id_or_url, $current_value, $value, $lang_key, $current_status_str, $name = 'status', $func = 'setStatus'
) {
if (is_numeric($id_or_url)) {
$_url = url($func, ['id' => $id_or_url, $name => $value, 'field' => $name]);
} else {
$_url = $id_or_url;
}
$_auth = cmf_auth_check(cmf_get_current_admin_id(), $_url);
if (false == $_auth) {
return '';
}
switch ($current_value) {
case 1:
$_class = 'btn-default';
break;
case 2:
$_class = 'btn-success';
break;
case 3:
$_class = 'btn-primary';
break;
default:
$_class = 'btn-info';
break;
}
$_lang_key = $lang_key;
$_target_status_str = lang($_lang_key);
return \cmf\view\Index::link(
$_url, '', '', 'btn btn-xs '.$_class.' js-ajax-dialog-btn',
lang('CONFIRM').$_target_status_str.'?', $current_status_str, ''
);
}
function view_param($param, $title = '') {
if (empty($param)) {
return '';
}
if (false == is_string($param)) {
$param = json_encode($param);
}
$_title = $title;
if (empty($title)) {
$_title = mb_substr($param, 0, 50);
if (strlen($_title) > 50) {
$_title .= '...';
}
}
$_html
= <<
{$title}
{$param}
EOF;
return $_html;
}
function view_sort($id, $list_order, $width = 100) {
$_max_int = CommonConst::CONST_MAX_INT;
$_html
= <<
EOF;
return $_html;
}
function view_time($ts = 0, $format = 'Y-m-d H:i') {
if (empty($ts)) {
return '';
}
return date($format, $ts);
}
function date_search(
$time_range, $func = 'index', $time_range_arr
= ['today',
'yesterday',
'seven_days',
'this_week',
'last_week',
'this_month',
'last_month',
'thirty_days']
) {
$_time_range_arr = $time_range_arr;
$_html = '';
foreach ($_time_range_arr as $_v) {
$_btn = 'btn-default';
if ($time_range == $_v) {
$_btn = 'btn-success';
}
$_html .= ''.lang(strtoupper($_v)).'';
}
return $_html;
}
/**
* 打开链接
*
* @param $url
*
* @return string
*/
function view_link($url) {
if (empty($url)) {
return '';
}
$_html = cmf\view\Index::link($url, $url, 'chain', 'btn-xs btn-link', '', '', 'info', '', 'view_window');
return $_html;
}
/**
* 列表中游戏列表
*
* @param string $url 请求地址
* @param bool $new_frame 是否Frame打开
* @param string $lang_key
*
* @param int $width
* @param int $height
*
* @return string
*/
function view_game($url, $new_frame = true, $lang_key = 'GAME_LIST', $width = 1000, $height = 600) {
if (empty($url)) {
return '';
}
if ($new_frame) {
$_html = Index::linkOpenIframeDialog(
$url, lang($lang_key), '', $width, $height,
'btn-xs btn-link', lang($lang_key)
);
} else {
$_html = cmf\view\Index::link($url, lang($lang_key), 'gamepad', '', lang($lang_key), '', 'info');
}
return $_html;
}
/**
* 列表中渠道列表
*
* @param string $url 请求地址
* @param bool $new_frame 是否Frame打开
* @param string $lang_key
*
* @param int $width
* @param int $height
*
* @return string
*/
function view_channel($url, $new_frame = true, $lang_key = 'CHANNEL_LIST', $width = 1000, $height = 600) {
if (empty($url)) {
return '';
}
if ($new_frame) {
$_html = Index::linkOpenIframeDialog(
$url, lang($lang_key), '', $width, $height,
'btn-xs btn-link', lang($lang_key)
);
} else {
$_html = cmf\view\Index::link($url, lang($lang_key), 'fa-sitemap', '', lang($lang_key), '', 'info');
}
return $_html;
}
/**
* 输出订单号文本框
*
* @param string $value 字段值
* @param string $placeholder 字段提示
*
* @return:string
*/
function filter_text_order_id($value = '', $placeholder = '') {
$_placeholder = empty($placeholder) ? lang('MSG_ORDER_ID_INPUT') : $placeholder;
return Filter::text('order_id', $value, $_placeholder);
}
/**
* 输出玩家账号文本框
*
* @param string $value 字段值
* @param string $placeholder 字段提示
*
* @return:string
*/
function filter_text_username($value = '', $placeholder = '') {
$_placeholder = empty($placeholder) ? lang('MSG_INPUT_ACCOUNT') : $placeholder;
return Filter::text('username', $value, $_placeholder);
}
/**
* 输出玩家注册手机号文本框
*
* @param string $value 字段值
* @param string $placeholder 字段提示
*
* @return string
*/
function filter_text_reg_mobile($value = '', $placeholder = '') {
$_placeholder = empty($placeholder) ? lang('MSG_MEMBER_REG_MOBILE_INPUT') : $placeholder;
return Filter::text('reg_mobile', $value, $_placeholder);
}
/**
* @param string $info 提示信息
* @param string $place 显示位置 默认底部
*
* @return string
*/
function view_tips($info, $place = 'bottom') {
return '';
}
/**
* 跳转详情操作
*
* @param string|int $id_or_url 传入ID或者链接
*
* @param string $id_key
*
* @param bool $new_frame
* @param int $width
* @param int $height
*
* @return string
*/
function action_detail($id_or_url, $id_key = 'id', $new_frame = false, $width = 1000, $height = 800) {
if (substr_count($id_or_url, '/') < 3) {
$_url = url('detail', [$id_key => $id_or_url]);
} else {
$_url = $id_or_url;
}
$_auth = cmf_auth_check(cmf_get_current_admin_id(), $_url);
if (false == $_auth) {
return '';
}
if ($new_frame) {
return Index::linkOpenIframeDialog(
$_url, lang('DETAIL'), '', $width, $height,
'btn-xs btn-link', lang('EDIT')
);
} else {
return action_link($_url, 'DETAIL', 'eye');
}
}
/**
* 跳转链接操作
*
* @param string $link 链接
* @param string $lang_key 显示文字语言KEY
* @param string $icon 图标
*
* @return: string
*/
function action_link($link, $lang_key, $icon = '') {
$_url = $link;
$_auth = cmf_auth_check(cmf_get_current_admin_id(), $_url);
if (false == $_auth) {
return '';
}
$_title = lang($lang_key);
return Index::link($_url, $_title, $icon);
}
/**
* 确认操作(二次确认操作,用于更改数据状态等操作)
*
* @param string $link 链接
* @param string $lang_key 显示文字语言KEY
* @param string $msg_lang_key 提示文字语言KEY
* @param string $type 类型,默认是btn
* @param string $class ICON下面为图标样式,BUTTON下为按钮样式
*
* @return string
*/
function action_confirm($link, $lang_key, $msg_lang_key, $type = 'btn', $class = '') {
$_url = $link;
$_auth = cmf_auth_check(cmf_get_current_admin_id(), $_url);
if (false == $_auth) {
return '';
}
$_title = lang($lang_key);
$_msg = lang($msg_lang_key);
switch ($type) {
/*图标类型*/
case 'icon':
$_class = empty($class) ? 'edit' : $class;
$_class = 'fa-'.$_class;
$_html
= <<
EOF;
break;
/*按钮类型*/
case 'btn':
case 'button':
$_class = empty($class) ? 'default' : $class;
$_class = 'btn-'.$_class;
$_html
= <<
{$_title}
EOF;
break;
default:
$_html = '';
break;
}
return $_html;
}
/**
* 弹框操作
*
* @param string $link 链接
* @param string $lang_key 显示文字语言KEY
* @param string $type 类型,默认是btn
* @param string $class ICON下面为图标样式,BUTTON下为按钮样式
* @param int $width
* @param int $height
* @param string $dialog_lang_key
*
* @return string :string
*/
function action_dialog(
$link, $lang_key, $type = 'btn', $class = '', $width = 800,
$height = 400, $dialog_lang_key = ''
) {
$_url = $link;
$_auth = cmf_auth_check(cmf_get_current_admin_id(), $_url);
if (false == $_auth) {
return '';
}
$_title = lang($lang_key);
$dialog_title = !empty($dialog_lang_key) ? lang($dialog_lang_key) : $_title;
switch ($type) {
/*图标类型*/
case 'icon':
$_class = empty($class) ? 'edit' : $class;
$_class = 'fa-'.$_class;
$_html
= <<
EOF;
break;
/*按钮类型*/
case 'btn':
case 'button':
$_class = empty($class) ? 'default' : $class;
$_class = 'btn-'.$_class;
$_html = Index::linkOpenIframeDialog(
$_url, $dialog_title, $_title, $width, $height, $_class, $_title
);
break;
default:
$_html = '';
break;
}
return $_html;
}
/***
* 列表审核操作
*
* @param $id
* @param $value
* @param $lang_key
* @param string $name
* @param string $func
* @param string $original_title_key
* @param string $id_name
* @param string $fa
* @param string $class
*
* @return string
*/
function action_check(
$id, $value, $lang_key, $name = 'status', $func = 'setStatus', $original_title_key = '', $id_name = 'id',
$fa = 'check', $class = ''
) {
$_auth_url = request()->module().'/'.request()->controller().'/'.$func;
$_auth = cmf_auth_check(cmf_get_current_admin_id(), $_auth_url);
if (false == $_auth) {
return '';
}
$_url = url($_auth_url, [$id_name => $id, $name => $value]);
$_lang_key = $lang_key;
$_target_status_str = lang($_lang_key);
$_original_title = '';
if (!empty($original_title_key)) {
$_original_title = lang($original_title_key);
}
return Index::link(
$_url, $_original_title, '', $class.' js-ajax-dialog-btn',
lang('CONFIRM').$_target_status_str.'?', '',
''
);
}
/**
* 列表删除操作
*
* @param string|int $id_or_url 传入ID或者链接
*
* @param bool $new_frame 是否弹框
* @param int $width 弹框宽度
* @param int $height 弹框高度
*
* @return string
*/
function action_add_sub($id_or_url, $new_frame = false, $width = 800, $height = 500) {
if (is_numeric($id_or_url)) {
$_url = url('add', ['id' => $id_or_url]);
} else {
$_url = $id_or_url;
}
$_auth = cmf_auth_check(cmf_get_current_admin_id(), $_url);
if (false == $_auth) {
return '';
}
if ($new_frame) {
return Index::linkOpenIframeDialog(
$_url, lang('ADD'), '', $width, $height,
'btn-xs btn-link', lang('ADD')
);
} else {
return Index::edit($_url, lang('ADD'));
}
}
/**
* 输入数字限制
*
* @param string $name 名称
* @param int $value 默认值
* @param int $min 最小值
* @param int $max 最大值
* @param string $style 样式
* @param string $required 是否必须
*
* @return string
*/
function input_num(
$name, $value = 0, $min = 0, $max = CommonConst::CONST_MAX_INT, $style = '', $required = '', $placeholder = ''
) {
$_html = '';
return $_html;
}
/**
* 输入数字与逗号
*
* @param string $name 名称
* @param int $value 默认值
*
* @return string
*/
function input_num_comma($name, $value = 0) {
$_html = '';
return $_html;
}
/**
* 输入数字与点号
*
* @param string $name 名称
* @param int $value 默认值
*
* @return string
*/
function input_num_dot($name, $value = 0) {
$_html = '';
return $_html;
}
/**
* 调用上传图片
*
* @param string $value 图片值
* @param string $name 图片名
* @param string $id 图片ID
*
* @return string
*/
function upload_image($value = '', $name = 'image', $id = 'thumb') {
$_static_site = STATICSITE;
if (empty($value)) {
$_img = "
";
} else {
$_img = "
";
}
$_lang_image_upload = lang('IMAGE_UPLOAD');
$_lang_image_cancel = lang('IMAGE_CANCEL');
$_html
= <<< EOT
{$_img}
EOT;
return $_html;
}
function action_url(
$id_or_url, $new_frame = false, $logo = 'eye', $tip = 'edit', $info = 'info', $width = 800, $height = 500
) {
if (is_numeric($id_or_url)) {
$_url = url('edit', ['id' => $id_or_url]);
$_auth_url = request()->module().'/'.request()->controller().'/edit';
} else {
$_url = $id_or_url;
$_auth_url = $id_or_url;
$name = explode('/', $id_or_url);
if (isset($name[3])) {
$_auth_url = $name[1].'/'.$name[2].'/'.$name[3];
}
}
$_auth = cmf_auth_check(cmf_get_current_admin_id(), $_auth_url);
if (false == $_auth) {
return '';
}
if ($new_frame) {
return \cmf\view\Index::linkOpenIframeDialog(
$_url, $tip, '', $width, $height,
'btn-xs btn-link', $tip
);
} else {
//return \cmf\view\Index::edit($_url);
return cmf\view\Index::link($_url, $tip, $logo, '', $tip, '', $info);
}
}
/**
* 设置菜单
*
* @param int $parent_id
* @param string $default_action
* @param int $new_frame 是否返回上级页面
*
* @return string
*/
function setting_menu($parent_id, $default_action = '', $new_frame = 1) {
$_default_action = $default_action;
if (empty($_default_action)) {
$_default_action = request()->action();
}
$_menu_model = new AdminMenuModel();
$_menu_data = $_menu_model->adminMenu($parent_id);
$_txt = '';
if (count($_menu_data) > 0) {
$_txt = '';
foreach ($_menu_data as $_menu) {
$_name = $_menu['app'];
$_controller = ucwords($_menu['controller']);
$_action = $_menu['action'];
//附带参数
if ($_menu['param']) {
$_params = "?".htmlspecialchars_decode($_menu['param']).'&new_frame='.$new_frame;
} else {
$_params = '?new_frame='.$new_frame;
}
$_url = url("{$_name}/{$_controller}/{$_action}{$_params}");
$_lang = strtoupper($_name.'_'.$_controller.'_'.$_action);
$_class = '';
if (strtolower($_default_action) == strtolower($_action)) {
$_class = 'active';
}
$_txt .= "- ".lang($_lang)."
";
}
$_txt .= "
";
}
return $_txt;
}
function button($lang_key, $id, $class) {
return Filter::button(['title' => lang($lang_key), 'type' => $id, 'class' => $class]);
}
/**
* 列表状态标识
*
* @param int $current_value 目前值
* @param string $current_status_str 目前状态名称
*
* @return string
*/
function btn_status($current_value, $current_status_str) {
switch ($current_value) {
case 1:
$_class = 'btn-default';
break;
case 2:
$_class = 'btn-success';
break;
case 3:
$_class = 'btn-primary';
break;
default:
$_class = 'btn-info';
break;
}
return Index::link(
'#', '', '', 'btn btn-xs '.$_class,
'', $current_status_str, ''
);
}
function get_btn($value) {
switch ($value) {
case 1:
$_class = 'danger';
break;
case 2:
$_class = 'success';
break;
case 3:
$_class = 'primary';
break;
case 4:
$_class = 'warning';
break;
default:
$_class = 'default';
break;
}
return $_class;
}
function get_btn1($value) {
switch ($value) {
case 1:
$_class = 'info';
break;
case 2:
$_class = 'success';
break;
case 3:
$_class = 'primary';
break;
case 4:
$_class = 'warning';
break;
default:
$_class = 'default';
break;
}
return $_class;
}
/**
* 列表删除操作
*
* @param int|string $id_or_url ID或者地址
* @param int $current_value 目前值
* @param int $value 目标值
* @param string $lang_key 变化的值
* @param string $current_status_str 目前状态名称
* @param string $name 字段
* @param string $func 函数
*
* @return string
*/
function action_switch(
$id_or_url, $current_value, $value, $lang_key, $current_status_str, $name = 'status', $func = 'setStatus'
) {
if (is_numeric($id_or_url)) {
$_url = url($func, ['id' => $id_or_url, $name => $value, 'field' => $name]);
} else {
$_url = $id_or_url;
}
$_auth = cmf_auth_check_url(cmf_get_current_admin_id(), $_url);
if (false == $_auth) {
return '';
}
switch ($current_value) {
case 1:
$_class = 'btn-success';
break;
case 2:
$_class = 'btn-default';
break;
case 3:
$_class = 'btn-primary';
break;
default:
$_class = 'btn-info';
break;
}
$_lang_key = $lang_key;
$_target_status_str = lang($_lang_key);
return Index::link(
$_url, '', '', 'btn btn-xs '.$_class.' js-ajax-dialog-btn',
lang('CONFIRM').$_target_status_str.'?', $current_status_str, ''
);
}
/**
* @param int $user_id 用户ID
* @param string $url 访问的URL
*
* @return bool
*/
function cmf_auth_check_url($user_id, $url) {
if (1 == $user_id) {
return true;
}
$_name = StrUtils::getRoute($url);
return cmf_auth_check($user_id, $_name);
}