where('code', 'site_name') ->value('value'); } } if (!function_exists('site_logo')) { function site_logo() { return Db::name('config')->where('code', 'site_logo') ->value('value'); } } //获取配置信息 if (!function_exists('getConfigByCode')) { function getConfigByCode($code) { return Db::name('config')->where('code', $code) ->value('value'); } } /* * 百度编辑器内容 多个编辑器单独引入js,重复会导致出错 */ if (!function_exists('build_ueditor_js')) { function build_ueditor_js(){ /* 配置界面语言 */ switch (config('default_lang')) { case 'zh-cn': $lang = '/static/plugins/ueditor/lang/zh-cn/zh-cn.js'; break; case 'en-us': $lang = '/static/plugins/ueditor/lang/en/en.js'; break; default: $lang = '/static/plugins/ueditor/lang/zh-cn/zh-cn.js'; break; } return $include_js = ' '; } } if (!function_exists('build_ueditor')) { function build_ueditor($params = array()) { $name = isset($params['name']) ? $params['name'] : null; $theme = isset($params['theme']) ? $params['theme'] : 'normal'; $content = isset($params['content']) ? $params['content'] : null; //http://fex.baidu.com/ueditor/#start-toolbar /* 指定使用哪种主题 */ $themes = array( 'normal' => "[ 'fullscreen', 'source', '|', 'undo', 'redo', '|', 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|', 'rowspacingtop', 'rowspacingbottom', 'lineheight', '|', 'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|', 'directionalityltr', 'directionalityrtl', 'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|', 'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|', 'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|', 'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|', 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|', 'print', 'preview', 'searchreplace', 'drafts', 'help' ]", 'simple' => " ['fullscreen', 'source', 'undo', 'redo', 'bold']", ); switch ($theme) { case 'simple': $theme_config = $themes['simple']; break; case 'normal': $theme_config = $themes['normal']; break; default: $theme_config = $themes['normal']; break; } if(!isset($params['type']) || (isset($params['type']) && $params['type']==0) ){ $include_js = build_ueditor_js(); }elseif($params['type']==1 ){ $include_js = ''; } $content = json_encode($content); $str = << var ue_{$name} = UE.getEditor('{$name}',{ toolbars:[{$theme_config}], }); if($content){ ue_{$name}.ready(function() { this.setContent($content); }) } EOT; return $str; } } if (!function_exists('p')) { function p($var, $die = 0) { print_r($var); $die && die(); } } if (!function_exists('isMobile')) { function isMobile() { if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])) { return true; } if (isset ($_SERVER['HTTP_VIA'])) { return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false; } if (isset ($_SERVER['HTTP_USER_AGENT'])) { $clientkeywords = array('nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile' ); if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) { return true; } } if (isset ($_SERVER['HTTP_ACCEPT'])) { if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) { return true; } } return false; } } if (!function_exists("json_result")){ /** 返回接送 接口 * @param int $code * @param string $msg * @param $data */ function json_result($code=200,$msg="",$data=""){ $dat["code"]=$code; $dat["msg"]=$msg; $dat["data"]=$data; $json=json_encode($dat); echo $json;exit(); } } /** * 生成操作按钮 * @param array $operate 操作按钮数组 */ if (!function_exists("showOperate")){ function showOperate($operate = []) { if(empty($operate)){ return ''; } $option = << '; return $option; } } if (!function_exists("time2string")){ function time2string($second){ $day = floor($second/(3600*24)); $second = $second%(3600*24);//除去整天之后剩余的时间 $hour = floor($second/3600); $second = $second%3600;//除去整小时之后剩余的时间 $minute = floor($second/60); $second = $second%60;//除去整分钟之后剩余的时间 //返回字符串 return $day.'天'.$hour.'小时'; } } if (!function_exists("is_admin")){ function is_admin(){ $session= \think\facade\Session::get("admin"); $admin=$session->toArray(); if ($admin["project"]){ return $admin["project"]; }else{ return false; } } } // 成绩转换 成数字 if (!function_exists("achievement_switch")){ function achievement_switch($name){ $age=0; switch ($name){ case "A":$age=4;break; case "a":$age=4;break; case "B":$age=3;break; case "b":$age=3;break; case "C":$age=2;break; case "c":$age=2;break; case "D":$age=1;break; case "d":$age=1;break; case "F":$age=0;break; case "f":$age=0;break; } return $age; } } // 成绩转换成 单词 if (!function_exists("achievement_change")){ function achievement_change($name){ $age="F"; switch ($name){ case 4: $age="A";break; case 3: $age="B";break; case 2: $age="C";break; case 1: $age="D";break; case 0: $age="F";break; case -1: $age="录入中";break; } return $age; } } // 等级换算 if (!function_exists("star_deng")){ function star_deng($name){ $age="初出茅庐"; switch ($name){ case 0: $age="初出茅庐";break; case 1: $age="心令神会";break; case 2: $age="出类拔萃";break; case 3: $age="名列前茅";break; case 4: $age="百里挑一";break; } return $age; } } // 升星标准 if (!function_exists("star_class")){ function star_class($name){ $age=0; if ($name>=3.4){ $age=5; }elseif ($name>=2.8&&$name<3.4){ $age=4; }elseif ($name>=2.2&&$name<2.8){ $age=3; }elseif ($name>=1.6&&$name<2.2){ $age=2; }elseif ($name>=1&&$name<1.5){ $age=1; } return $age; } } // 专业等级 if (!function_exists("major_levels")){ function major_levels($num,$subject_id){ $where[]=["max",">=",$num]; $where[]=["subject_id","=",$subject_id]; $type=Db::name("major_level")->order("type asc")->where($where)->find(); if (!$type){ if ($num>0){ return 4; }else{ return 0; } } return $type["type"]; } } function sortArr($arrays,$sort_key,$sort_order=SORT_ASC,$sort_type=SORT_NUMERIC ){ $key_arrays =array(); if(is_array($arrays)){ foreach ($arrays as $array){ if(is_array($array)){ $key_arrays[] = $array[$sort_key]; }else{ return false; } } }else{ return false; } array_multisort($key_arrays,$sort_order,$sort_type,$arrays); return $arrays; } //生成流水号 function getordernum(){ //生成24位唯一流水号码,格式:YYYY-MMDD-HHII-SS-NNNN,NNNN-CC,其中:YYYY=年份,MM=月份,DD=日期,HH=24格式小时,II=分,SS=秒,NNNNNNNN=随机数,CC=检查码 @date_default_timezone_set("PRC"); //日期 $order_date = date('Y-m-d'); //流水号码主体(YYYYMMDDHHIISSNNNNNNNN) $order_id_main = date('YmdHis') . rand(10000000,99999999); //流水号码主体长度 $order_id_len = strlen($order_id_main); $order_id_sum = 0; for($i=0; $i<$order_id_len; $i++){ $order_id_sum += (int)(substr($order_id_main,$i,1)); } //唯一流水号码(YYYYMMDDHHIISSNNNNNNNNCC) $order_id = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100,2,'0',STR_PAD_LEFT); return $order_id; }