controller())); } function getNewOrderId($title){ /* * Time - 42 bits */ $time = floor(microtime(true) * 1000); /* * Substract custom epoch from current time */ $time -= 1479533469598; /* * Create a base and add time to it */ $base = decbin(1099511627775 + $time); /* * Configured machine id - 10 bits - up to 1024 machines */ $machineid = str_pad(decbin(1), 10, "0", STR_PAD_LEFT); /* * sequence number - 12 bits - up to 4096 random numbers per machine */ $random = str_pad(decbin(mt_rand(0,4095)), 12, "0", STR_PAD_LEFT); /* * Pack */ $base = $base.$machineid.$random; /* * Return unique time id no */ return $title . bindec($base); } function getModule() { return strtolower(preg_replace('/((?<=[a-z])(?=[A-Z]))/', '_', think\Request::instance()->module())); } function processingData($browse_count) { if ($browse_count > 9999) { $browse_count = bcdiv($browse_count, 10000, 1) . 'W'; } return $browse_count; } /** * 获取图片库链接地址 * @param $key * @return string */ function get_image_Url($key) { return think\Url::build('admin/widget.images/index', ['fodder' => $key]); } /** * 获取链接对应的key * @param $value * @param bool $returnType * @param string $rep * @return array|string * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ function get_key_attr($value, $returnType = true, $rep = '') { if (!$value) return ''; $inif = \app\admin\model\system\SystemAttachment::where('att_dir', $value)->find(); if ($inif) { return [ 'key' => $inif->name, 'pic' => $value, ]; } else { if ($returnType) { return [ 'key' => '', 'pic' => $value, ]; } else { return [ 'key' => '', 'pic' => '', ]; } } } /** * 获取系统配置内容 * @param $name * @param string $default * @return string */ function get_config_content($name, $default = '') { try { return \app\admin\model\system\SystemConfigContent::getValue($name); } catch (\Throwable $e) { return $default; } } /** * 打印日志 * @param $name * @param $data * @param int $type */ function live_log($name, $data, $type = 8) { file_put_contents($name . '.txt', '[' . date('Y-m-d H:i:s', time()) . ']' . print_r($data, true) . "\r\n", $type); } /**获取当前登录用户的角色信息 * @return mixed */ function get_login_role() { $role['role_id'] = \think\Session::get("adminInfo")['roles']; $role['role_sign'] = \think\Session::get("adminInfo")['role_sign']; return $role; } /**获取登录用户账户信息 * @return mixed */ function get_login_id() { $admin['admin_id'] = \think\Session::get("adminId"); return $admin; } function money_rate_num($money, $type) { if (!$money) $money = 0; if (!$type) return \service\JsonService::fail('非法参数2'); switch ($type) { case "gold": $goldRate = \service\SystemConfigService::get("gold_rate"); $num = bcmul($money, $goldRate, 0); return $num; default: return \service\JsonService::fail('汇率类型缺失'); } } function getUrlToDomain() { $site_url = \service\SystemConfigService::get('site_url'); if ($site_url == '') $site_url = $_SERVER['PHP_SELF']; $arr = parse_url($site_url); if (!isset($arr['host'])) $arr['host'] = $arr['path']; $array = explode('.', $arr['host']); return implode('_', $array); } if (!function_exists('filter_emoji')) { // 过滤掉emoji表情 function filter_emoji($str) { $str = preg_replace_callback( //执行一个正则表达式搜索并且使用一个回调进行替换 '/./u', function (array $match) { return strlen($match[0]) >= 4 ? '' : $match[0]; }, $str); return $str; } } function lightTypeNmae($light_type) { switch ($light_type) { case 1: $type = '图文'; break; case 2: $type = '音频'; break; case 3: $type = '视频'; break; } return $type; } //读取版本号 function getversion() { $version_arr = []; $curent_version = @file(dirname(__DIR__) . '/.version'); foreach ($curent_version as $val) { list($k, $v) = explode('=', $val); $version_arr[$k] = trim($v); } return $version_arr; } /** * 数据多层级 * @param array $data * @param int $pid * @return array */ function subTree(array $data, int $pid = 0, $field = 'pid') { // 返回的结果 $arr = []; foreach ($data as $val) { // 给定的PID是当前记录的上级ID if ($pid == $val[$field]) { // 递归 $val['children'] = subTree($data,$val['id'], $field); $arr[] = $val; } } return $arr; }