// note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs //$val = preg_replace('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/', '', $val); // straight replacements, the user should never need these since they're normal characters // this prevents like $search = 'abcdefghijklmnopqrstuvwxyz'; $search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $search .= '1234567890!@#$%^&*()'; $search .= '~`";:?+/={}[]-_|\'\\'; for ($i = 0; $i < strlen($search); $i++) { // ;? matches the ;, which is optional // 0{0,7} matches any padded zeros, which are optional and go up to 8 chars // @ @ search for the hex values $val = preg_replace('/(&#[xX]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val); // with a ; // @ @ 0{0,7} matches '0' zero to seven times $val = preg_replace('/(�{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); // with a ; } // now the only remaining whitespace attacks are \t, \n, and \r $ra1 = array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link','script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound','base'); $ra2 = array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload'); $ra = array_merge($ra1, $ra2); $found = true; // keep replacing as long as the previous round replaced something while ($found == true) { $val_before = $val; for ($i = 0; $i < sizeof($ra); $i++) { $pattern = '/'; for ($j = 0; $j < strlen($ra[$i]); $j++) { if ($j > 0) { $pattern .= '('; $pattern .= '(&#[xX]0{0,8}([9ab]);)'; $pattern .= '|'; $pattern .= '|(�{0,8}([9|10|13]);)'; $pattern .= ')*'; } $pattern .= $ra[$i][$j]; } $pattern .= '/i'; $replacement = substr($ra[$i], 0, 2).''.substr($ra[$i], 2); // add in <> to nerf the tag $val = preg_replace($pattern, $replacement, $val); // filter out the hex tags if ($val_before == $val) { // no replacements were made, so exit the loop $found = false; } } } $filters=config("filters"); if(count($filters)&&is_string($val)){ $filters=array_map("trim",$filters); $val=str_replace($filters,"***",$val); } return $val; } /** * 导出xls * @param unknown $expTitle * @param unknown $expCellName * @param unknown $expTableData */ function exportExcel($expTitle,$expCellName,$expTableData){ error_reporting(E_ALL); date_default_timezone_set('Europe/London'); include ROOT_PATH.'extend'.DS.'PHPExcel'.DS.'PHPExcel.php'; $objPHPExcel = new \PHPExcel(); $objPHPExcel->getActiveSheet()->setTitle($expTitle); $objPHPExcel->setActiveSheetIndex(0); $cellNum=count($expCellName); $dataNum=count($expTableData); $cellName = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ'); for($i=0;$i<$cellNum;$i++){ $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i].'1', $expCellName[$i][1]); } for($i=0;$i<$dataNum;$i++){ for($j=0;$j<$cellNum;$j++){ $val=$expTableData[$i][$expCellName[$j][0]]; $opts=isset($expCellName[$j][2])?$expCellName[$j][2]:''; $format=isset($expCellName[$j][3])?$expCellName[$j][3]:''; if(is_int($val)&&$opts){ $opts=explode("||", $opts); if(isset($opts[$val]))$val=$opts[$val]; } if($format=='date'){ $val=date("Y-m-d",intval($val)); } $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j].($i+2),$val); } } ob_end_clean();//清楚缓存区,解决乱码问题 header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="'.$expTitle.'.xls"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; } /** * 多维数组查询 * @param unknown $value * @param unknown $array * @return unknown|boolean */ function deep_in_array($value, $array) { foreach($array as $item) { if(!is_array($item)) { if ($item == $value) { return $item; } else { continue; } } if(in_array($value, $item)) { return $item; } else if(deep_in_array($value, $item)) { return $item; } } return false; } /** * 对象 转 数组 * * @param object $obj 对象 * @return array */ function object_to_array($obj) { $obj = (array)$obj; foreach ($obj as $k => $v) { if (gettype($v) == 'resource') { return; } if (gettype($v) == 'object' || gettype($v) == 'array') { $obj[$k] = (array)object_to_array($v); } } return $obj; } function parseArr($str=''){ $str=str_replace(array('[',']'),'', $str); $str=trim($str,'"'); $str=explode('","', $str); array_walk($str,"walkparse"); $maps=[]; if(count($str)){ foreach ($str as $vo){ $vo=explode('=', $vo); if(count($vo)==2){ $key=isset($vo[0])?$vo[0]:''; $val=isset($vo[1])?$vo[1]:''; if($key)$maps[$key]=$val; } } } return $maps; } function walkparse(&$value,$key){ $value=urldecode($value); $value = str_replace(array("/r/n", "/r", "/n"), "", $value); $value = str_replace(array(" "), "", $value); } function parseTd($str='',$id='',$tag=''){ $str=str_replace(array('[',']'),'', $str); $str=trim($str,'"'); $str=explode('","', $str); $html=''; array_walk($str,"walkparse"); if(count($str)){ $data=implode('&', $str); $html.=''; $html.=''.$id.''; foreach ($str as $count=>$vo){ $vo=explode('=', $vo); if(count($vo)==2){ if(isset($vo[1])&&$vo[1]){ if($tag==3&&$count==0){ $title='艺术品资产托管'; if($vo[1]==2)$title='艺品拍'; $html.=''.$title.''; }else{ $html.=''.$vo[1].''; } continue; } } $html.='  '; } $html.='  '; } return $html; } // 应用公共文件 //中文截取 function sub_str($str,$length =0,$append = true,$dot='...') { $str = trim($str); $strlength = strlen($str); if(!defined('EC_CHARSET'))define('EC_CHARSET','utf-8'); if ($length == 0 || $length >= $strlength){ return $str; //截取长度等于0或大于等于本字符串的长度,返回字符串本身 }elseif ($length < 0){ //如果截取长度为负数 $length = $strlength + $length;//那么截取长度就等于字符串长度减去截取长度 if ($length < 0){ $length = $strlength;//如果截取长度的绝对值大于字符串本身长度,则截取长度取字符串本身的长度 } } if (function_exists('mb_substr')){ $newstr = mb_substr($str, 0, $length, EC_CHARSET); }elseif (function_exists('iconv_substr')){ $newstr = iconv_substr($str, 0, $length, EC_CHARSET); }else{ //$newstr = trim_right(substr($str, 0, $length)); $newstr = substr($str, 0, $length); } if ($append && $str != $newstr){ $newstr .=$dot; } return $newstr; } /** * 所有用到密码的不可逆加密方式 * @author rainfer <81818832@qq.com> * @param string $password * @param string $password_salt * @return string */ function encrypt_password($password, $password_salt) { return md5(md5($password) . md5($password_salt)); } /** * 列出本地目录的文件 * @author rainfer <81818832@qq.com> * @param string $path * @param string $pattern * @return array */ function list_file($path, $pattern = '*') { if (strpos($pattern, '|') !== false) { $patterns = explode('|', $pattern); } else { $patterns [0] = $pattern; } $i = 0; $dir = array(); if (is_dir($path)) { $path = rtrim($path, '/') . '/'; } foreach ($patterns as $pattern) { $list = glob($path . $pattern); if ($list !== false) { foreach ($list as $file) { $dir [$i] ['filename'] = basename($file); $dir [$i] ['path'] = dirname($file); $dir [$i] ['pathname'] = realpath($file); $dir [$i] ['owner'] = fileowner($file); $dir [$i] ['perms'] = substr(base_convert(fileperms($file), 10, 8), -4); $dir [$i] ['atime'] = fileatime($file); $dir [$i] ['ctime'] = filectime($file); $dir [$i] ['mtime'] = filemtime($file); $dir [$i] ['size'] = filesize($file); $dir [$i] ['type'] = filetype($file); $dir [$i] ['ext'] = is_file($file) ? strtolower(substr(strrchr(basename($file), '.'), 1)) : ''; $dir [$i] ['isDir'] = is_dir($file); $dir [$i] ['isFile'] = is_file($file); $dir [$i] ['isLink'] = is_link($file); $dir [$i] ['isReadable'] = is_readable($file); $dir [$i] ['isWritable'] = is_writable($file); $i++; } } } $cmp_func = @create_function('$a,$b', ' if( ($a["isDir"] && $b["isDir"]) || (!$a["isDir"] && !$b["isDir"]) ){ return $a["filename"]>$b["filename"]?1:-1; }else{ if($a["isDir"]){ return -1; }else if($b["isDir"]){ return 1; } if($a["filename"] == $b["filename"]) return 0; return $a["filename"]>$b["filename"]?-1:1; } '); usort($dir, $cmp_func); return $dir; } /** * 删除文件夹 * @author rainfer <81818832@qq.com> * @param string * @param int */ function remove_dir($dir, $time_thres = -1) { foreach (list_file($dir) as $f) { if ($f ['isDir']) { remove_dir($f ['pathname'] . '/'); } else if ($f ['isFile'] && $f ['filename']) { if ($time_thres == -1 || $f ['mtime'] < $time_thres) { @unlink($f ['pathname']); } } } } /** * 格式化字节大小 * @param number $size 字节数 * @param string $delimiter 数字和单位分隔符 * @return string 格式化后的带单位的大小 * @author rainfer <81818832@qq.com> */ function format_bytes($size, $delimiter = '') { $units = array(' B', ' KB', ' MB', ' GB', ' TB', ' PB'); for ($i = 0; $size >= 1024 && $i < 5; $i++) $size /= 1024; return round($size, 2) . $delimiter . $units[$i]; } /** * curl访问 * @author rainfer <81818832@qq.com> * @param string $url * @param string $type * @param boolean $data * @param string $err_msg * @param int $timeout * @param array $cert_info * @return string */ function go_curl2($url, $type, $data = false, $header=array(),&$err_msg = null, $timeout = 20,$cert_info = array()) { $type = strtoupper($type); if ($type == 'GET' && is_array($data)) { $data = http_build_query($data); } $option = array(); if ( $type == 'POST' ) { $option[CURLOPT_POST] = 1; } if ($data) { if ($type == 'POST') { $option[CURLOPT_POSTFIELDS] = http_build_query($data); } elseif ($type == 'GET') { $url = strpos($url, '?') !== false ? $url.'&'.$data : $url.'?'.$data; } } $option[CURLOPT_URL] = $url; $option[CURLOPT_FOLLOWLOCATION] = TRUE; $option[CURLOPT_MAXREDIRS] = 4; $option[CURLOPT_RETURNTRANSFER] = TRUE; $option[CURLOPT_TIMEOUT] = $timeout; if(count($header)){ $option[CURLOPT_HTTPHEADER] =$header; } //设置证书信息 if(!empty($cert_info) && !empty($cert_info['cert_file'])) { $option[CURLOPT_SSLCERT] = $cert_info['cert_file']; $option[CURLOPT_SSLCERTPASSWD] = $cert_info['cert_pass']; $option[CURLOPT_SSLCERTTYPE] = $cert_info['cert_type']; } //设置CA if(!empty($cert_info['ca_file'])) { // 对认证证书来源的检查,0表示阻止对证书的合法性的检查。1需要设置CURLOPT_CAINFO $option[CURLOPT_SSL_VERIFYPEER] = 1; $option[CURLOPT_CAINFO] = $cert_info['ca_file']; } else { // 对认证证书来源的检查,0表示阻止对证书的合法性的检查。1需要设置CURLOPT_CAINFO $option[CURLOPT_SSL_VERIFYPEER] = 0; } $ch = curl_init(); curl_setopt_array($ch, $option); $response = curl_exec($ch); $curl_no = curl_errno($ch); $curl_err = curl_error($ch); curl_close($ch); // error_log if($curl_no > 0) { if($err_msg !== null) { $err_msg = '('.$curl_no.')'.$curl_err; } } return $response; } function go_curl($url, $type, $data = false, $header=array(),&$err_msg = null, $timeout = 20,$cert_info = array()) { $type = strtoupper($type); $ch = curl_init(); $option = array(); if ($data) { if ($type == 'GET') { if (is_array($data)) { $data = http_build_query($data); } $url = strpos($url, '?') !== false ? $url.'&'.$data : $url.'?'.$data; } } curl_setopt($ch, CURLOPT_URL,$url); //设置CA if(!empty($cert_info['ca_file'])) { // 对认证证书来源的检查,0表示阻止对证书的合法性的检查。1需要设置CURLOPT_CAINFO curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,1); curl_setopt($ch, CURLOPT_CAINFO,$cert_info['ca_file']); } else { // 对认证证书来源的检查,0表示阻止对证书的合法性的检查。1需要设置CURLOPT_CAINFO curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false); } curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch, CURLOPT_MAXREDIRS,4); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); if ( $type == 'POST' ) { curl_setopt($ch, CURLOPT_POST, 1); if ($data) { if(count($data))$data=http_build_query($data); curl_setopt($ch, CURLOPT_POSTFIELDS,$data); }else{ curl_setopt($ch, CURLOPT_POSTFIELDS,[]); } } curl_setopt($ch, CURLOPT_TIMEOUT,$timeout); if(count($header)){ curl_setopt($ch, CURLOPT_HEADER,0); curl_setopt($ch, CURLOPT_HTTPHEADER,$header); } //设置证书信息 if(!empty($cert_info) && !empty($cert_info['cert_file'])) { curl_setopt($ch, CURLOPT_SSLCERT,$cert_info['cert_file']); curl_setopt($ch, CURLOPT_SSLCERTPASSWD,$cert_info['cert_pass']); curl_setopt($ch, CURLOPT_SSLCERTTYPE,$cert_info['cert_type']); } $response = curl_exec($ch); $curl_no = curl_errno($ch); $curl_err = curl_error($ch); curl_close($ch); // error_log if($curl_no > 0) { if($err_msg !== null) { $err_msg = '('.$curl_no.')'.$curl_err; } } return $response; } /** * 设置全局配置到文件 * * @param $key * @param $value * @return boolean */ function sys_config_setbykey($key, $value) { $file = ROOT_PATH.'data/conf/config.php'; $cfg = array(); if (file_exists($file)) { $cfg = include $file; } $item = explode('.', $key); switch (count($item)) { case 1: $cfg[$item[0]] = $value; break; case 2: $cfg[$item[0]][$item[1]] = $value; break; } return file_put_contents($file, " */ function get_host() { $host=$_SERVER["HTTP_HOST"]; $protocol=Request::instance()->isSsl()?"https://":"http://"; return $protocol.$host; } /** * ajax数据返回,规范格式 * @param array $data 返回的数据,默认空数组 * @param string $msg 信息,一般用于错误信息提示 * @param int $code 错误码,0-未出现错误|其他出现错误 * @param array $extend 扩展数据 * @return string */ function ajax_return($data = [], $msg = "", $code = 0, $extend = []) { $msg=empty($msg)?'失败':$msg; $ret = ["code" => $code, "msg" => $msg, "data" => $data]; $ret = array_merge($ret, $extend); return Response::create($ret, 'json'); } /** * 根据用户id获取用户组,返回值为字符串 * @param int $uid 用户id * @return string */ function get_groups($uid) { $auth = new Auth(); $group = $auth->getGroups($uid); if($group) return $group[0]['title']; else { $user_groups = db()->name('auth_group_access a') ->where("a.uid='$uid'") ->join(config('database.prefix')."auth_group g"," a.group_id = g.id") ->field('uid,group_id,title,rules')->select(); if($user_groups) return '
组已禁用
 | '.$user_groups[0]['title']; else return '
不存在
'; } } /** * 随机字符 * @param int $length 长度 * @param string $type 类型 * @param int $convert 转换大小写 1大写 0小写 * @return string */ function random($length=10, $type='letter', $convert=0) { $config = array( 'number'=>'1234567890', 'letter'=>'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'string'=>'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789', 'all'=>'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' ); if(!isset($config[$type])) $type = 'letter'; $string = $config[$type]; $code = ''; $strlen = strlen($string) -1; for($i = 0; $i < $length; $i++){ $code .= $string{mt_rand(0, $strlen)}; } if(!empty($convert)){ $code = ($convert > 0)? strtoupper($code) : strtolower($code); } return $code; } /** * 是否存在控制器 * @param string $module 模块 * @param string $controller 待判定控制器名 * @return boolean */ function has_controller($module,$controller) { $arr=\ReadClass::readDir(APP_PATH . $module. DS .'controller'); if((!empty($arr[$controller])) && $arr[$controller]['class_name']==$controller){ return true; }else{ return false; } } /** * 是否存在方法 * @param string $module 模块 * @param string $controller 待判定控制器名 * @param string $action 待判定控制器名 * @return number 方法结果,0不存在控制器 1存在控制器但是不存在方法 2存在控制和方法 */ function has_action($module,$controller,$action) { $arr=\ReadClass::readDir(APP_PATH . $module. DS .'controller'); if((!empty($arr[$controller])) && $arr[$controller]['class_name']==$controller ){ $method_name=array_map('array_shift',$arr[$controller]['method']); if(in_array($action, $method_name)){ return 2; }else{ return 1; } }else{ return 0; } } /** * 返回不含前缀的数据库表数组 * * @author rainfer <81818832@qq.com> * @param bool * @return array */ function db_get_tables($prefix=false) { $db_prefix =config('database.prefix'); $list = Db::query('SHOW TABLE STATUS FROM '.config('database.database')); $list = array_map('array_change_key_case', $list); $tables = array(); foreach($list as $k=>$v){ if(empty($prefix)){ if(stripos($v['name'],strtolower(config('database.prefix')))===0){ $tables [] = strtolower(substr($v['name'], strlen($db_prefix))); } }else{ $tables [] = strtolower($v['name']); } } return $tables; } /** * 返回数据表的sql * * @author rainfer <81818832@qq.com> * * @param $table : 不含前缀的表名 * @return string */ function db_get_insert_sqls($table) { $db_prefix =config('database.prefix'); $db_prefix_re = preg_quote($db_prefix); $db_prefix_holder = db_get_db_prefix_holder(); $export_sqls = array(); $export_sqls [] = "DROP TABLE IF EXISTS $db_prefix_holder$table"; switch (config('database.type')) { case 'mysql' : if (!($d = Db::query("SHOW CREATE TABLE $db_prefix$table"))) { $this->error("'SHOW CREATE TABLE $table' Error!"); } $table_create_sql = $d [0] ['Create Table']; $table_create_sql = preg_replace('/' . $db_prefix_re . '/', $db_prefix_holder, $table_create_sql); $export_sqls [] = $table_create_sql; $data_rows = Db::query("SELECT * FROM $db_prefix$table"); $data_values = array(); foreach ($data_rows as &$v) { foreach ($v as &$vv) { //TODO mysql_real_escape_string替换方法 //$vv = "'" . @mysql_real_escape_string($vv) . "'"; $vv = "'" . addslashes(str_replace(array("\r","\n"),array('\r','\n'),$vv)) . "'"; } $data_values [] = '(' . join(',', $v) . ')'; } if (count($data_values) > 0) { $export_sqls [] = "INSERT INTO `$db_prefix_holder$table` VALUES \n" . join(",\n", $data_values); } break; } return join(";\n", $export_sqls) . ";"; } /** * 检测当前数据库中是否含指定表 * * @author rainfer <81818832@qq.com> * * @param $table : 不含前缀的数据表名 * @return bool */ function db_is_valid_table_name($table) { return in_array($table, db_get_tables()); } /** * 不检测表前缀,恢复数据库 * * @author rainfer <81818832@qq.com> * * @param $file * @param $prefix */ function db_restore_file($file,$prefix='') { $prefix=$prefix?:db_get_db_prefix_holder(); $db_prefix=config('database.prefix'); $sqls = file_get_contents($file); $sqls = str_replace($prefix, $db_prefix, $sqls); $sqlarr = explode(";\n", $sqls); foreach ($sqlarr as &$sql) { Db::execute($sql); } } /** * 返回表前缀替代符 * @author rainfer <81818832@qq.com> * * @return string */ function db_get_db_prefix_holder() { return '<--db-prefix-->'; } /** * 强制下载 * @author rainfer <81818832@qq.com> * * @param string $filename * @param string $content */ function force_download_content($filename, $content) { header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Transfer-Encoding: binary"); header("Content-Disposition: attachment; filename=$filename"); echo $content; exit (); } /** * 生成参数列表,以数组形式返回 * @author rainfer <81818832@qq.com> * @param string * @return array */ function param2array($tag = '') { $param = array(); $array = explode(';',$tag); foreach ($array as $v){ $v=trim($v); if(!empty($v)){ list($key,$val) = explode(':',$v); $param[trim($key)] = trim($val); } } return $param; } /** * 获取新闻分类ids * @author rainfer <81818832@qq.com> * * @param int $id 待获取的id * @param boolean $self 是否返回自身,默认false * @param int $open 1表示只显示menu_open=1的,0表示只显示menu_open=0的,2表示不限制 * @param string $field 默认只返回id数组(一维),其它如:"*"表示全部字段,"id,menu_name"表示返回二维数组 * @param boolean $lang 是否只返回当前语言下分类,默认false * @return array|mixed */ function get_menu_byid($id=0,$self=false,$open=0,$field='id',$lang=false) { if(empty($open)){ $where['menu_open']=0; }elseif($open==1){ $where['menu_open']=1; }else{ $where=array(); } $where['menu_l']='zh-cn'; $arr=Db::name('menu')->where($where)->where(array('id'=>$id))->select(); if($arr){ $tree=new \Tree(); $tree->init($arr); $rst=$tree->get_childs($arr,$id,true,true); }else{ $rst=$self?array($id):array(); } if(empty($field) || $field=='id'){ return $rst; }else{ $where=array(); $where['id']=array('in',$rst); $arr=Db::name('menu')->where($where)->field($field)->order('listorder asc')->select(); return $arr; } } /** * 截取文字 * @author rainfer <81818832@qq.com> * * @param string $text * @param int $length * @return string */ function subtext($text, $length) { if(mb_strlen($text, 'utf8') > $length) return mb_substr($text, 0, $length, 'utf8').'...'; return $text; } /** * 将内容存到Storage中,返回转存后的文件路径 * @author rainfer <81818832@qq.com> * @param string $ext * @param string $content * @return string */ function save_storage_content($ext = null, $content = null) { $newfile = ''; $path='./data/upload/'; $path=substr($path,0,2)=='./' ? substr($path,2) :$path; $path=substr($path,0,1)=='/' ? substr($path,1) :$path; if ($ext && $content) { do { $newfile = $path.date('Y-m-d/') . uniqid() . '.' . $ext; } while (file_exists($newfile)); $dir = dirname($newfile); if (!is_dir($dir)) { mkdir($dir, 0777, true); } file_put_contents($newfile, $content); } return $newfile; } /** * 获取所有友情连接 * @author rainfer <81818832@qq.com> * @param int * @return array|mixed */ function get_links($lk_cid=1) { $links=cache('links_'.$lk_cid); if(!$links){ $links=Db::name("link")->where(array('lk_cid'=>$lk_cid,'lk_status'=>1))->order("lk_order")->select(); cache('links_'.$lk_cid,$links); } return $links; } /** * 返回指定id的菜单 * @param int $id 表示获得这个ID下的所有子级 * @param string $top_ul_id 顶级菜单ul的id * @param string $childtpl 子菜单模板 * @param string $parenttpl 父菜单模板 * @param int $showlevel 直接显示层级数,其余为异步显示,0为全部限制 * @param string $ul_class 子菜单ul样式 * @param string $li_class 子菜单li样式 * @param string $top_ul_class 顶级菜单ul的样式 * @param string $dropdown 有子元素时li的class * @return string */ function get_menu($id=0,$top_ul_id="",$childtpl="\$label",$parenttpl="\$label",$ul_class="" ,$li_class="" ,$top_ul_class="filetree",$showlevel=6,$dropdown='hasChild') { $navs=cache("site_nav"); if(empty($navs)){ $navs=get_menu_datas(); } $tree = new \Tree(); $tree->init($navs); return $tree->get_treeview_menu($id,$top_ul_id, $childtpl, $parenttpl, $showlevel,$ul_class,$li_class, $top_ul_class, 1, FALSE, $dropdown); } /** * 返回指定id的菜单 * @return array|mixed */ function get_menu_datas() { $navs= Db::name("menu")->where('menu_l',Lang::detect())->where(array('menu_open'=>1,'top'=>1))->order(array("listorder" => "ASC"))->select(); foreach ($navs as $key=>$nav){ if($nav['menu_type']==2){ $nav['href']=$nav['menu_address']; }elseif($nav['menu_type']==4){ //为了匹配单页路由 $nav['href']=url('home/Listn/index?id='.$nav['id']); }else{ $nav['href']=url('home/Listn/index',array('id'=>$nav['id'])); if(strtolower($nav['menu_enname'])=='home' && $nav['parentid']==0){ $nav['href']=url('home/Index/index'); } } $navs[$key]=$nav; } cache("site_nav",$navs); return $navs; } /** * 返回指定id的菜单 * @param int * @return array */ function get_menu_tree($id) { $navs=cache("site_nav"); if(empty($navs)){ $navs=get_menu_datas(); } $tree = new \Tree(); $tree->init($navs); return $tree->get_tree_array($id); } /** * 截取待html的文本 * @author rainfer <81818832@qq.com> * @param string $html * @param int $max * @param string $suffix * @return string; */ function html_trim($html, $max, $suffix='...') { $html = trim($html); if(strlen($html)<= $max){ return $html; } $non_paired_tags = array('br', 'hr', 'img', 'input', 'param'); $html = preg_replace('/]+)>/i', '', $html); $count = 0; $tag_status = 0; $nodes = array(); $segment = ''; $tag_name = ''; for($i=0;$i' || $char == "\t") { $tag_status = 3; }else { $tag_name .= $char; } } if($tag_status == 3 && $char == '>') { $tag_status = 4; $tag_name = strtolower($tag_name); $tag_type = 1; if(in_array($tag_name, $non_paired_tags)) { $tag_type = 0; }elseif($tag_name[0] == '/') { $tag_type = 2; } $nodes[] = array(1, $segment, $tag_name, $tag_type); $segment = ''; } if($tag_status == 0) { if($char == '&') { for($e=1;$e<=10;$e++) { if($html[$i+$e] == ';') { $segment .= substr($html, $i+1, $e); $i += $e; break; } } }else { $char_code = ord($char); if($char_code >= 224) { $segment .= $html[$i+1].$html[$i+2]; $i += 2; }elseif($char_code >= 129) { $segment .= $html[$i+1]; $i += 1; } } $count ++; if($count == $max) { $nodes[] = array(0, $segment.$suffix, 'text',0); break; } } } $html = ''; $tag_open_stack = array(); for($i=0;$i'; } return $html; } /** * 获取当前request参数数组,去除值为空 * @param string * @param int * @param int * @param string * @param bool * @return string */ function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true) { if(function_exists("mb_substr")) $slice = mb_substr($str, $start, $length, $charset); elseif(function_exists('iconv_substr')) { $slice = iconv_substr($str,$start,$length,$charset); if(false === $slice) { $slice = ''; } }else{ $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/"; $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/"; $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/"; $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/"; preg_match_all($re[$charset], $str, $match); $slice = join("",array_slice($match[0], $start, $length)); } return ($suffix && $slice!=$str)? $slice.'...' : $slice; } /** * 获取单页面菜单 * @author rainfer <81818832@qq.com> * * @param int $id 菜单id * @return array; */ function get_menu_one($id) { $rst=array(); if($id){ $rst=Db::name('menu')->where('menu_l',Lang::detect())->where(array('menu_type'=>4,'id'=>$id))->find(); } return $rst; } /** * 检查用户对某个url,内容的可访问性,用于记录如是否赞过,是否访问过等等;开发者可以自由控制,对于没有必要做的检查可以不做,以减少服务器压力 * @param string $object 访问对象的id,格式:不带前缀的表名+id;如news1表示xx_news表里id为1的记录;如果object为空,表示只检查对某个url访问的合法性 * @param int $count_limit 访问次数限制,如1,表示只能访问一次,0表示不限制 * @param boolean $ip_limit ip限制,false为不限制,true为限制 * @param int $expire 距离上次访问的最小时间单位s,0表示不限制,大于0表示最后访问$expire秒后才可以访问 * @return true 可访问,false不可访问 */ function check_user_action($object="",$count_limit=1,$ip_limit=false,$expire=0) { $action=request()->module()."-".request()->controller()."-".request()->action(); $userid=session('hid')?session('hid'):0; $ip=request()->ip(); $where=array("uid"=>$userid,"action"=>$action,"object"=>$object); if($ip_limit){ $where['ip']=$ip; } $find_log=Db::name("action_log")->where($where)->find(); $time=time(); if($find_log){ //次数限制 if($count_limit>0 && $find_log['count']>=$count_limit){ return false; } //时间限制 if($expire>0 && ($time-$find_log['last_time'])<$expire){ return false; } Db::name("action_log")->where($where)->update(array("count"=>array("exp","count+1"),"last_time"=>$time,"ip"=>$ip)); }else{ Db::name("action_log")->insert(array("uid"=>$userid,"action"=>$action,"object"=>$object,"count"=>array("exp","count+1"),"last_time"=>$time,"ip"=>$ip)); } return true; } /** * 发送邮件 * @author rainfer <81818832@qq.com> * @param string $to 收件人邮箱 * @param string $title 标题 * @param string $content 内容 * @return array */ function sendMail($to, $title, $content) { $email_options=get_email_options(); if($email_options && $email_options['email_open']){ $mail = new PHPMailer(); //实例化 // 设置PHPMailer使用SMTP服务器发送Email $mail->IsSMTP(); $mail->Mailer='smtp'; $mail->IsHTML(true); // 设置邮件的字符编码,若不指定,则为'UTF-8' $mail->CharSet='UTF-8'; // 添加收件人地址,可以多次使用来添加多个收件人 $mail->AddAddress($to); // 设置邮件正文 $mail->Body=$content; // 设置邮件头的From字段。 $mail->From=$email_options['email_name']; // 设置发件人名字 $mail->FromName=$email_options['email_rename']; // 设置邮件标题 $mail->Subject=$title; // 设置SMTP服务器。 $mail->Host=$email_options['email_smtpname']; //by Rainfer // 设置SMTPSecure。 $mail->SMTPSecure=$email_options['smtpsecure']; // 设置SMTP服务器端口。 $port=$email_options['smtp_port']; $mail->Port=empty($port)?"25":$port; // 设置为"需要验证" $mail->SMTPAuth=true; // 设置用户名和密码。 $mail->Username=$email_options['email_emname']; $mail->Password=$email_options['email_pwd']; // 发送邮件。 if(!$mail->Send()) { $mailerror=$mail->ErrorInfo; return array("error"=>1,"message"=>$mailerror); }else{ return array("error"=>0,"message"=>"success"); } }else{ return array("error"=>1,"message"=>'未开启邮件发送或未配置'); } } /** * 获取后台管理设置的邮件连接 * @author rainfer <81818832@qq.com> * @return array */ function get_email_options() { $email_options = cache("email_options"); if(empty($email_options)){ $option = Db::name("Options")->where('option_l',Lang::detect())->where("option_name='email_options'")->find(); if($option){ $email_options = json_decode($option['option_value'],true); }else{ $email_options = array(); } cache("email_options", $email_options); } return $email_options; } /** * 获取后台管理设置的邮件激活连接 * @author rainfer <81818832@qq.com> * @return array */ function get_active_options() { $active_options = cache("active_options"); if(empty($active_options)){ $option = Db::name("Options")->where('option_l',Lang::detect())->where("option_name='active_options'")->find(); if($option){ $active_options = json_decode($option['option_value'],true); }else{ $active_options = array(); } cache("active_options", $active_options); } return $active_options; } /** * 实时显示提示信息 * @param string $msg 提示信息 * @param string $class 输出样式(success:成功,error:失败) * @author huajie */ function showmsg($msg, $class = '') { echo ""; flush(); ob_flush(); } /** * 加密函数 * @param string $txt 需加密的字符串 * @param string $key 加密密钥,默认读取data_auth_key配置 * @return string 加密后的字符串 */ function jiami($txt, $key = null) { empty($key) && $key = config('data_auth_key'); $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-=_"; $nh = rand(0, 64); $ch = $chars[$nh]; $mdKey = md5($key . $ch); $mdKey = substr($mdKey, $nh % 8, $nh % 8 + 7); $txt = base64_encode($txt); $tmp = ''; $k = 0; for ($i = 0; $i < strlen($txt); $i++) { $k = $k == strlen($mdKey) ? 0 : $k; $j = ($nh + strpos($chars, $txt [$i]) + ord($mdKey[$k++])) % 64; $tmp .= $chars[$j]; } return $ch . $tmp; } /** * 解密函数 * @param string $txt 待解密的字符串 * @param string $key 解密密钥,默认读取data_auth_key配置 * @return string 解密后的字符串 */ function jiemi($txt, $key = null) { empty($key) && $key = config('data_auth_key'); $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-=_"; $ch = $txt[0]; $nh = strpos($chars, $ch); $mdKey = md5($key . $ch); $mdKey = substr($mdKey, $nh % 8, $nh % 8 + 7); $txt = substr($txt, 1); $tmp = ''; $k = 0; for ($i = 0; $i < strlen($txt); $i++) { $k = $k == strlen($mdKey) ? 0 : $k; $j = strpos($chars, $txt[$i]) - $nh - ord($mdKey[$k++]); while ($j < 0) { $j += 64; } $tmp .= $chars[$j]; } return base64_decode($tmp); } /** * 获取图片完整路径 * @param string $url 待获取图片url * @param int $cat 待获取图片类别 0为文章 1前台头像 2后台头像 * @return string 完整图片imgurl */ function get_imgurl($url,$cat=0) { if(stripos($url,'http')!==false){ //网络图片 return $url; }elseif($url && stripos($url,'/')===false && stripos($url,'\\')===false){ //头像 return __ROOT__.'/data/upload/avatar/'.$url; }elseif(empty($url)){ //$url为空 if($cat==2){ $imgurl='girl.jpg'; }elseif($cat==1){ $imgurl='headicon.png'; }else{ $imgurl='no_img.jpg'; } return __ROOT__.'/public/img/'.$imgurl; }else{ //本地上传图片 return __ROOT__.$url; } } /** * 获取当前request参数数组,去除值为空 * @return array */ function get_query() { $param=request()->except(['s']); $rst=array(); foreach($param as $k=>$v){ if(!empty($v)){ $rst[$k]=$v; } } return $rst; } /** * 货币转换 * @param float * @return string */ function long_currency($long) { return sprintf('%d.%02d', intval($long / 100), intval($long % 100)); } /** * 货币转换 * @param string * @return float */ function currency_long($currency) { $s = explode('.', trim($currency)); switch (count($s)) { case 1: return $s[0] * 100; case 2: if (strlen($s[1]) == 1) { $s[1] .= '0'; } else if (strlen($s[1]) > 2) { $s[1] = substr($s[1], 0, 2); } return $s[0] * 100 + $s[1]; } return 0; } /** * 获取客户端浏览器信息 添加win10 edge浏览器判断 * @author Jea杨 * @return string */ function getBroswer($arr=false) { $arr=$arr?:false; $sys = $_SERVER['HTTP_USER_AGENT']; //获取用户代理字符串 if (stripos($sys, "Firefox/") > 0) { preg_match("/Firefox\/([^;)]+)+/i", $sys, $b); $exp[0] = "Firefox"; $exp[1] = $b[1]; //获取火狐浏览器的版本号 } elseif (stripos($sys, "Maxthon") > 0) { preg_match("/Maxthon\/([\d\.]+)/", $sys, $aoyou); $exp[0] = "傲游"; $exp[1] = $aoyou[1]; } elseif (stripos($sys, "MSIE") > 0) { preg_match("/MSIE\s+([^;)]+)+/i", $sys, $ie); $exp[0] = "IE"; $exp[1] = $ie[1]; //获取IE的版本号 } elseif (stripos($sys, "OPR") > 0) { preg_match("/OPR\/([\d\.]+)/", $sys, $opera); $exp[0] = "Opera"; $exp[1] = $opera[1]; } elseif (stripos($sys, "Edge") > 0) { //win10 Edge浏览器 添加了chrome内核标记 在判断Chrome之前匹配 preg_match("/Edge\/([\d\.]+)/", $sys, $Edge); $exp[0] = "Edge"; $exp[1] = $Edge[1]; } elseif (stripos($sys, "Chrome") > 0) { preg_match("/Chrome\/([\d\.]+)/", $sys, $google); $exp[0] = "Chrome"; $exp[1] = $google[1]; //获取google chrome的版本号 } elseif (stripos($sys, 'rv:') > 0 && stripos($sys, 'Gecko') > 0) { preg_match("/rv:([\d\.]+)/", $sys, $IE); $exp[0] = "IE"; $exp[1] = $IE[1]; } elseif (stripos($sys, 'Safari') > 0) { preg_match("/safari\/([^\s]+)/i", $sys, $safari); $exp[0] = "Safari"; $exp[1] = $safari[1]; } else { $exp[0] = "未知浏览器"; $exp[1] = ""; } if($arr){ return $exp; }else{ return $exp[0] . '(' . $exp[1] . ')'; } } /** * 获取客户端操作系统信息包括win10 * @author Jea杨 * @return string */ function getOs() { $agent = $_SERVER['HTTP_USER_AGENT']; if (preg_match('/win/i', $agent) && strpos($agent, '95')) { $os = 'Windows 95'; } else if (preg_match('/win 9x/i', $agent) && strpos($agent, '4.90')) { $os = 'Windows ME'; } else if (preg_match('/win/i', $agent) && preg_match('/98/i', $agent)) { $os = 'Windows 98'; } else if (preg_match('/win/i', $agent) && preg_match('/nt 6.0/i', $agent)) { $os = 'Windows Vista'; } else if (preg_match('/win/i', $agent) && preg_match('/nt 6.1/i', $agent)) { $os = 'Windows 7'; } else if (preg_match('/win/i', $agent) && preg_match('/nt 6.2/i', $agent)) { $os = 'Windows 8'; } else if (preg_match('/win/i', $agent) && preg_match('/nt 10.0/i', $agent)) { $os = 'Windows 10';#添加win10判断 } else if (preg_match('/win/i', $agent) && preg_match('/nt 5.1/i', $agent)) { $os = 'Windows XP'; } else if (preg_match('/win/i', $agent) && preg_match('/nt 5/i', $agent)) { $os = 'Windows 2000'; } else if (preg_match('/win/i', $agent) && preg_match('/nt/i', $agent)) { $os = 'Windows NT'; } else if (preg_match('/win/i', $agent) && preg_match('/32/i', $agent)) { $os = 'Windows 32'; } else if (preg_match('/linux/i', $agent)) { $os = 'Linux'; } else if (preg_match('/unix/i', $agent)) { $os = 'Unix'; } else if (preg_match('/sun/i', $agent) && preg_match('/os/i', $agent)) { $os = 'SunOS'; } else if (preg_match('/ibm/i', $agent) && preg_match('/os/i', $agent)) { $os = 'IBM OS/2'; } else if (preg_match('/Mac/i', $agent)) { $os = 'Mac'; } else if (preg_match('/PowerPC/i', $agent)) { $os = 'PowerPC'; } else if (preg_match('/AIX/i', $agent)) { $os = 'AIX'; } else if (preg_match('/HPUX/i', $agent)) { $os = 'HPUX'; } else if (preg_match('/NetBSD/i', $agent)) { $os = 'NetBSD'; } else if (preg_match('/BSD/i', $agent)) { $os = 'BSD'; } else if (preg_match('/OSF1/i', $agent)) { $os = 'OSF1'; } else if (preg_match('/IRIX/i', $agent)) { $os = 'IRIX'; } else if (preg_match('/FreeBSD/i', $agent)) { $os = 'FreeBSD'; } else if (preg_match('/teleport/i', $agent)) { $os = 'teleport'; } else if (preg_match('/flashget/i', $agent)) { $os = 'flashget'; } else if (preg_match('/webzip/i', $agent)) { $os = 'webzip'; } else if (preg_match('/offline/i', $agent)) { $os = 'offline'; } elseif (preg_match('/ucweb|MQQBrowser|J2ME|IUC|3GW100|LG-MMS|i60|Motorola|MAUI|m9|ME860|maui|C8500|gt|k-touch|X8|htc|GT-S5660|UNTRUSTED|SCH|tianyu|lenovo|SAMSUNG/i', $agent)) { $os = 'mobile'; } else { $os = '未知操作系统'; } return $os; } /** * 返回按层级加前缀的菜单数组 * @author rainfer * @param array|mixed $menu 待处理菜单数组 * @param string $id_field 主键id字段名 * @param string $pid_field 父级字段名 * @param string $lefthtml 前缀 * @param int $pid 父级id * @param int $lvl 当前lv * @param int $leftpin 左侧距离 * @return array */ function menu_left($menu,$id_field='id',$pid_field='pid',$lefthtml = '─' , $pid=0 , $lvl=0, $leftpin=0) { $arr=array(); foreach ($menu as $v){ if($v[$pid_field]==$pid){ $v['lvl']=$lvl + 1; $v['leftpin']=$leftpin; $v['lefthtml']='├'.str_repeat($lefthtml,$lvl); $arr[]=$v; $arr= array_merge($arr,menu_left($menu,$id_field,$pid_field,$lefthtml,$v[$id_field], $lvl+1 ,$leftpin+20)); } } return $arr; } /** * 返回后台news相关菜单层级text数组 * @author rainfer * @return array|mixed */ function menu_text($lang='zh-cn') { $menu_text=cache('menu_text'); if(empty($menu_text)){ $map=[]; $map['menu_l']= 'zh-cn'; $menu_text=Db::name('menu')->where('menu_type <> 4 and menu_type <> 2')->where($map)-> order('menu_l desc,listorder') -> select(); $menu_text = menu_left($menu_text,'id','parentid'); cache('menu_text',$menu_text); } return $menu_text; } /** * 数据签名 * @param array $data 被认证的数据 * @return string 签名 */ function data_signature($data = []) { if(!is_array($data)){ $data = (array)$data; } ksort($data); $code = http_build_query($data); $sign = sha1($code); return $sign; } /** * 递归查找多维数组键名,返回键值数组 * * @param string * @param array * @param array * @return array */ function array_search_key($needle, $haystack,&$nodes_found=[]){ foreach ($haystack as $key1=>$value1) { if ($key1=== $needle){ $nodes_found[] = $value1; } if (is_array($value1)){ array_search_key($needle, $value1,$nodes_found); } } return $nodes_found; } /** * 递归查找多维数组值,返回键名数组 * * @param mixed $needle 待找值 * @param array $haystack 目标数组 * @param array * @param int * @param array * @return array */ function array_search_value($needle, $haystack,&$nodes_found=[], $a=0, $nodes_temp=array()){ $a++; foreach ($haystack as $key1=>$value1) { $nodes_temp[$a] = $key1; if (is_array($value1)){ array_search_value($needle, $value1,$nodes_found, $a, $nodes_temp); } else if ($value1 === $needle){ $nodes_found[] = $nodes_temp; } } return $nodes_found; } /** * 返回管理菜单待找url对应键名数组 * * @param string * @return array */ function admin_menu_find($url){ $rst=array_search_value($url,config('menu')); if(!$rst) return []; $rst=$rst[0]; $value_arr=[]; foreach ($rst as $key=>$value){ if($key % 2 ==1) $value_arr[]=$value; } return $value_arr; } //判断远程文件是否存在 /* 函数:remote_file_exists 功能:判断远程文件是否存在 参数: $url_file - 远程文件URL $flag - true为判断远程文件,false为判断非远程文件 返回:存在返回true,不存在或者其他原因返回false */ function remote_file_exists($url_file,$flag = false){ if($flag == true){ //默认是判断远程文件 //检测输入 $url_file = trim($url_file); if (empty($url_file)) { return false; } $url_arr = parse_url($url_file); if (!is_array($url_arr) || empty($url_arr)){ return false; } //获取请求数据 $host = $url_arr['host']; $path = $url_arr['path'] ."?". $url_arr['query']; $port = isset($url_arr['port']) ? $url_arr['port'] : "80"; //连接服务器 $fp = fsockopen($host, $port, $err_no, $err_str, 30); if (!$fp){ return false; } //构造请求协议 $request_str = "GET ".$path." HTTP/1.1\r\n"; $request_str .= "Host: ".$host."\r\n"; $request_str .= "Connection: Close\r\n\r\n"; //发送请求 fwrite($fp, $request_str); $first_header = fgets($fp, 1024); fclose($fp); //判断文件是否存在 if (trim($first_header) == ""){ return false; } if (!preg_match("/200/", $first_header)){ return false; } return true; }else if($flag == false){ //非远程文件 return file_exists($url_file); } } //创建TOKEN function creatToken() { $code = chr(mt_rand(0xB0, 0xF7)) . chr(mt_rand(0xA1, 0xFE)) . chr(mt_rand(0xB0, 0xF7)) . chr(mt_rand(0xA1, 0xFE)) . chr(mt_rand(0xB0, 0xF7)) . chr(mt_rand(0xA1, 0xFE)); session('TOKEN', authcode($code)); } //判断TOKEN function checkToken($token) { if ($token == session('TOKEN')) { session('TOKEN', NULL); return TRUE; } else { return FALSE; } } /* 加密TOKEN */ function authcode($str) { $key = "LEOET"; $str = substr(md5($str), 8, 10); return md5($key . $str); } /** * 获取所有父节点id(含自身) * @param int $id 节点id * @return array */ function get_menu_parents($id =0) { if(!$id) return []; $lists=Db::name('menu')->order('listorder,id')->column('parentid','id'); $ids = []; while (isset($lists[$id]) && $lists[$id] !=0){ $ids[]=$id; $id=$lists[$id]; } if(isset($lists[$id]) && $lists[$id]==0) $ids[]=$id; return array_reverse($ids); } /** * 获取创新价数据 * @return array */ function get_cx_data() { $data=Cache::get('curprice_cx'); if(!$data && config('curprice.cx_url')){ $data=json_decode(go_curl(config('curprice.cx_url'),'GET'),true); Cache::set('curprice_cx',$data,config('curprice.expire')); } return $data; } /** * 获取动态价数据 * @return array */ function get_dt_data() { $data=Cache::get('curprice_dt'); if(!$data && config('curprice.dt_url')){ $data=json_decode(go_curl(config('curprice.dt_url'),'GET'),true); Cache::set('curprice_dt',$data,config('curprice.expire')); } return $data; } /** * 亿美短信接口发送短信 * @param string * @param string * @param string * @return mixed */ function send_sms($phone='',$message='',$customSmsId = "",$extendedCode = "") { $ymsms=new Ymsms(); $resobj=$ymsms->SendSimpleSMS($phone, $message,'',$customSmsId,$extendedCode); if($resobj&&isset($resobj->plaintext)){ try { $json=json_decode($resobj->plaintext,true); if($json&&isset($json['smsId'])){ return ['code'=>1,'msg'=>'发送成功']; } } catch (Exception $e) { } return ['code'=>0,'msg'=>'发送失败']; } $SendMessageApi = "http://219.239.91.114:8080/sdkproxy/sendsms.action";//"http://hprpt2.eucp.b2m.cn:8080/sdkproxy/sendsms.action"; $param=config('ymsms'); unset($param['signname']); if(!$phone) return ['code'=>0,'msg'=>'手机号不能为空']; if(!$message) return ['code'=>0,'msg'=>'短信内容不能为空']; $param['phone']=$phone; $param['message']=$message; $param['addserial']=$addserial; if($param['cdkey'] && $param['password']){ $data=go_curl($SendMessageApi,'GET',$param); $data=xml2data($data); if($data['error']==0){ return ['code'=>1,'msg'=>'发送成功']; }else{ return ['code'=>0,'msg'=>$data['message']]; } }else{ return ['code'=>0,'msg'=>'未设置亿美接口参数']; } } function xml2data($xml){ $xml = simplexml_load_string(trim($xml)); $data = array(); foreach ($xml as $key => $value) { $data[$key] = strval($value); } return $data; } //获取含自身的auth_rule的id数组 function get_rule_ids_child($pid) { $arr=Db::name('auth_rule')->select(); $tree=new \Tree(); $tree->init($arr,['parentid'=>'pid']); return $tree->get_childs($arr,$pid,true,true); } //检查未上传文件,返回文件数组 function get_unuploadfiles($apply_id,$status=-1,$process=-1,$uid=-1,$role_id=-1,$flag=1) { $whereType=array('apply_id'=>$apply_id,'new_flag'=>1); $baseinfo=Db::name('cult4baseinfo')->field('apply_type,c_type,p_type,k_type')->where($whereType)->find(); $apply_type=$baseinfo['apply_type']; $c_type=$baseinfo['c_type']; $p_type=$baseinfo['p_type']; $k_type=$baseinfo['k_type']; if($uid > 0){ $role_id=Db::name('member_list')->where('member_list_id',$uid)->value('member_list_groupid'); }else{ $uid = -1; } if($role_id <= 0 and $role_id != -1)$role_id = -1; $rst=[]; //必须文件 //取得固定文件 $apply_uptypelist_check =UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[0],1,'ftype_id,status,apply_id,isopen',-1,$k_type); //取得补充文件 $apply_uptypelist_tempcheck =UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[0],1,'ftype_id,status,apply_id,isopen',-1,$k_type); if(config('cult4files.check')==1){ if($status==2 or $status>=32 or $process>=1){//补交材料中(初审未通过):32 //取得固定文件 $apply_uptypelist_check = array_merge($apply_uptypelist_check, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[1,19],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck = array_merge($apply_uptypelist_tempcheck, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[1,19],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); } } if(config('cult4files.checkdd')==1){ if($status==2 or $status>=35 or $process>=2){//补交材料中(尽调未通过):35 //取得固定文件 $apply_uptypelist_check = array_merge($apply_uptypelist_check, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[2,36],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck = array_merge($apply_uptypelist_tempcheck, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[2,36],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); } } if(config('cult4files.checkreview')==1){ if($status>=37 or $process>=3){//补交材料中(复审未通过):37 //取得固定文件 $apply_uptypelist_check = array_merge($apply_uptypelist_check, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[5,20],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck = array_merge($apply_uptypelist_tempcheck, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[5,20],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); } } if(config('cult4files.checkrisk')==1){ if($status>=38 or $process>=4){//补交材料中(风控审核未通过):38 //取得固定文件 $apply_uptypelist_check = array_merge($apply_uptypelist_check, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[6,21],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck = array_merge($apply_uptypelist_tempcheck, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[6,21],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); } } if(config('cult4files.checkfee')==1){ if($status>=41 or $process>=6){//补交材料中(缴费确认未通过):41 //取得固定文件 $apply_uptypelist_check = array_merge($apply_uptypelist_check, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[9,12,22,39],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck = array_merge($apply_uptypelist_tempcheck, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[9,12,22,39],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); } } if(config('cult4files.checkpro')==1){ if($status>=42 or $process>=8){//补交材料中(确认专家审核未通过):42 //取得固定文件 $apply_uptypelist_check = array_merge($apply_uptypelist_check, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[14,15,23],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck = array_merge($apply_uptypelist_tempcheck, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[14,15,23],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); } } if(config('cult4files.checkjc')==1){ if($status>=43 or $process>=9){//补交材料中(联席会审核未通过):43 //取得固定文件 $apply_uptypelist_check = array_merge($apply_uptypelist_check, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[4,34,8,11,13,17,16,28],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck = array_merge($apply_uptypelist_tempcheck, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[4,34,8,11,13,17,16,28],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); } } if(config('cult4files.checkmc')==1){ if($status>=45 or $process>=10){//补交材料中(材料核实未通过):45 //取得固定文件 $apply_uptypelist_check = array_merge($apply_uptypelist_check, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[25,46,47],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck = array_merge($apply_uptypelist_tempcheck, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[25,46,47],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); } } if(config('cult4files.checknm')==1){ if($status>=50 or $process>=11){//补交材料中(公告资料审核未通过):50 //取得固定文件 $apply_uptypelist_check = array_merge($apply_uptypelist_check, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[48,29],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck = array_merge($apply_uptypelist_tempcheck, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[48,29],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); } } if(config('cult4files.checkboard')==1){ if($status>=53 or $process>=12){//补交材料中(挂牌上市审核未通过):53 //取得固定文件 $apply_uptypelist_check = array_merge($apply_uptypelist_check, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[51,30],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck = array_merge($apply_uptypelist_tempcheck, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[51,30],1,'ftype_id,status,apply_id,isopen',-1,$k_type)); } } //固定文件,将数组键名改为$v['ftype_id'] foreach($apply_uptypelist_check as $k=>$v){ $where['ftype_id']=array('eq', $v['ftype_id']); $where['new_flag']=array('eq', 1); $where['apply_id']=array('eq', $apply_id); if($flag==1)$where['flag']=array('eq', 1);//已审核的 $fileInfo = Db::name('cult4upfiles')->where($where)->order('addorder desc')->find(); //如果没找到,根据条件添加到列表 if(!$fileInfo && $v['mustupload']==1){ if($uid==-1 and $role_id==-1){ $rst[$v['ftype_id']]=$v; }else{ if(($v['upload_role_type']==1 && $v['upload_role_id']==$role_id) || ($v['upload_role_type2']==1 && $v['upload_role_id2']==$role_id)||($role_id==5)) { $rst[$v['ftype_id']]=$v; } } } } //补充文件,将数组键名改为$v['ftype_id'] foreach($apply_uptypelist_tempcheck as $k=>$v){ $where['ftype_id']=array('eq', $v['ftype_id']); $where['new_flag']=array('eq', 1); $where['apply_id']=array('eq', $apply_id); if($flag==1)$where['flag']=array('eq', 1);//已审核的 $fileInfo = Db::name('cult4upfiles')->where($where)->order('addorder desc')->find(); //如果没找到,根据条件添加到列表 if(!$fileInfo){ if($uid==-1 and $role_id==-1){ $rst[$v['ftype_id']]=$v; }else{ if(($v['upload_role_type']==1 && $v['upload_role_id']==$role_id) || ($v['upload_role_type2']==1 && $v['upload_role_id2']==$role_id)||($role_id==5)) { $rst[$v['ftype_id']]=$v; } } } } //非必须文件 //取得固定文件 $apply_uptypelist_check2 =UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[0],1,'ftype_id,status,apply_id,isopen',0,$k_type); //取得补充文件 $apply_uptypelist_tempcheck2 =UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[0],1,'ftype_id,status,apply_id,isopen',0,$k_type); if(config('cult4files.check')==1){ if($status>=32 or $process>=1){//补交材料中(初审未通过):32 //取得固定文件 $apply_uptypelist_check2 = array_merge($apply_uptypelist_check2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[1,19],1,'ftype_id,status,apply_id,isopen',0,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck2 = array_merge($apply_uptypelist_tempcheck2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[1,19],1,'ftype_id,status,apply_id,isopen',0,$k_type)); } } if(config('cult4files.checkdd')==1){ if($status>=35 or $process>=2){//补交材料中(尽调未通过):35 //取得固定文件 $apply_uptypelist_check2 = array_merge($apply_uptypelist_check2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[2,36],1,'ftype_id,status,apply_id,isopen',0,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck2 = array_merge($apply_uptypelist_tempcheck2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[2,36],1,'ftype_id,status,apply_id,isopen',0,$k_type)); } } if(config('cult4files.checkreview')==1){ if($status>=37 or $process>=3){//补交材料中(复审未通过):37 //取得固定文件 $apply_uptypelist_check2 = array_merge($apply_uptypelist_check2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[5,20],1,'ftype_id,status,apply_id,isopen',0,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck2 = array_merge($apply_uptypelist_tempcheck2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[5,20],1,'ftype_id,status,apply_id,isopen',0,$k_type)); } } if(config('cult4files.checkrisk')==1){ if($status>=38 or $process>=4){//补交材料中(风控审核未通过):38 //取得固定文件 $apply_uptypelist_check2 = array_merge($apply_uptypelist_check2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[6,21],1,'ftype_id,status,apply_id,isopen',0,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck2 = array_merge($apply_uptypelist_tempcheck2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[6,21],1,'ftype_id,status,apply_id,isopen',0,$k_type)); } } if(config('cult4files.checkfee')==1){ if($status>=41 or $process>=6){//补交材料中(缴费确认未通过):41 //取得固定文件 $apply_uptypelist_check2 = array_merge($apply_uptypelist_check2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[9,12,22,39],1,'ftype_id,status,apply_id,isopen',0,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck2 = array_merge($apply_uptypelist_tempcheck2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[9,12,22,39],1,'ftype_id,status,apply_id,isopen',0,$k_type)); } } if(config('cult4files.checkpro')==1){ if($status>=42 or $process>=8){//补交材料中(确认专家审核未通过):42 //取得固定文件 $apply_uptypelist_check2 = array_merge($apply_uptypelist_check2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[14,15,23],1,'ftype_id,status,apply_id,isopen',0,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck2 = array_merge($apply_uptypelist_tempcheck2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[14,15,23],1,'ftype_id,status,apply_id,isopen',0,$k_type)); } } if(config('cult4files.checkjc')==1){ if($status>=43 or $process>=9){//补交材料中(联席会审核未通过):43 //取得固定文件 $apply_uptypelist_check2 = array_merge($apply_uptypelist_check2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[4,34,8,11,13,17,16,28],1,'ftype_id,status,apply_id,isopen',0,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck2 = array_merge($apply_uptypelist_tempcheck2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[4,34,8,11,13,17,16,28],1,'ftype_id,status,apply_id,isopen',0,$k_type)); } } if(config('cult4files.checkmc')==1){ if($status>=45 or $process>=10){//补交材料中(材料核实未通过):45 //取得固定文件 $apply_uptypelist_check2 = array_merge($apply_uptypelist_check2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[25,46,47],1,'ftype_id,status,apply_id,isopen',0,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck2 = array_merge($apply_uptypelist_tempcheck2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[25,46,47],1,'ftype_id,status,apply_id,isopen',0,$k_type)); } } if(config('cult4files.checknm')==1){ if($status>=50 or $process>=11){//补交材料中(公告资料审核未通过):50 //取得固定文件 $apply_uptypelist_check2 = array_merge($apply_uptypelist_check2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[48,29],1,'ftype_id,status,apply_id,isopen',0,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck2 = array_merge($apply_uptypelist_tempcheck2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[48,29],1,'ftype_id,status,apply_id,isopen',0,$k_type)); } } if(config('cult4files.checkboard')==1){ if($status>=53 or $process>=12){//补交材料中(挂牌上市审核未通过):53 //取得固定文件 $apply_uptypelist_check2 = array_merge($apply_uptypelist_check2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,1,[51,30],1,'ftype_id,status,apply_id,isopen',0,$k_type)); //取得补充文件 $apply_uptypelist_tempcheck2 = array_merge($apply_uptypelist_tempcheck2, UptypeModel::getList($apply_type,$c_type,$p_type,$apply_id,2,[51,30],1,'ftype_id,status,apply_id,isopen',0,$k_type)); } } //固定文件 foreach($apply_uptypelist_check2 as $k=>$v){ $where2['ftype_id']=array('eq', $v['ftype_id']); $where2['new_flag']=array('eq', 0); $where2['apply_id']=array('eq', $apply_id); $where2['flag']=array('eq', 0);//未审核(未通过) $fileInfo2 = Db::name('cult4upfiles')->where($where2)->order('addorder desc')->find(); //有历史数据 if($fileInfo2){ $where3['ftype_id']=array('eq', $v['ftype_id']); $where3['new_flag']=array('eq', 1); $where3['apply_id']=array('eq', $apply_id); if($flag==1)$where3['flag']=array('eq', 1);//已审核的 $fileInfo3 = Db::name('cult4upfiles')->where($where3)->order('addorder desc')->find(); //没有最新数据 if(!$fileInfo3) { if($uid==-1 and $role_id==-1){ $rst[$v['ftype_id']] = $v; } else { if (($v['upload_role_type'] == 1 && $v['upload_role_id'] == $role_id) || ($v['upload_role_type2'] == 1 && $v['upload_role_id2'] == $role_id)||($role_id==5)) { $rst[$v['ftype_id']] = $v; } } } } } //补充文件 foreach($apply_uptypelist_tempcheck2 as $k=>$v){ $where2['ftype_id']=array('eq', $v['ftype_id']); $where2['new_flag']=array('eq', 0); $where2['apply_id']=array('eq', $apply_id); $where['flag']=array('eq', 0);//未审核(未通过) $fileInfo2 = Db::name('cult4upfiles')->where($where2)->order('addorder desc')->find(); //有历史数据 if($fileInfo2){ $where3['ftype_id']=array('eq', $v['ftype_id']); $where3['new_flag']=array('eq', 1); $where3['apply_id']=array('eq', $apply_id); if($flag==1)$where['flag']=array('eq', 1);//已审核的 $fileInfo3 = Db::name('cult4upfiles')->where($where3)->order('addorder desc')->find(); //没有最新数据 if(!$fileInfo3) { if($uid==-1 and $role_id==-1){ $rst[$v['ftype_id']] = $v; } else { if (($v['upload_role_type'] == 1 && $v['upload_role_id'] == $role_id) || ($v['upload_role_type2'] == 1 && $v['upload_role_id2'] == $role_id)||($role_id==5)) { $rst[$v['ftype_id']] = $v; } } } } } return $rst; } /** * 根据模板文件id获取文件路径,返回值为字符串 * @param int $ftempid 文件id * @return string */ function get_capitaltempfile($ftempid) { $path=Db::name('capital_upfiles')->where(['file_id'=>$ftempid])->value('path'); return get_imgurl($path); } /** * 根据模板文件id获取文件路径,返回值为字符串 * @param int $ftempid 文件id * @return string */ function get_tempfile($ftempid) { $path=Db::name('cult4upfiles')->where(['file_id'=>$ftempid])->value('path'); return get_imgurl($path); } /** * 根据用户id获取前后台用户名,返回值为字符串 * @param int $uid 用户id * @param int $utype 用户类型1 前台 2后台 * @return int */ function get_capitalUserName($uid,$utype,$linkStyle='|',$errUserMsg='用户不存在') { $apply = new Capitalapply(); $userinfo = $apply->getUserInfos($uid,$utype); if(!empty($userinfo)) { if($utype==1)//前台用户 { return $userinfo[0]['member_list_username'].' '.$linkStyle.' '.$userinfo[0]['member_list_nickname']; } elseif($utype==2)//后台用户 { return $userinfo[0]['admin_username'].' '.$linkStyle.' '.$userinfo[0]['admin_realname']; } else{ return "未知状态,请联系管理员"; } }else { return $errUserMsg; } } /** * 根据用户id获取前后台用户名,返回值为字符串 * @param int $uid 用户id * @param int $utype 用户类型1 前台 2后台 * @return int */ function get_cult4UserName($uid,$utype,$linkStyle='|',$errUserMsg='用户不存在') { $apply = new Cult4apply(); $userinfo = $apply->getUserInfos($uid,$utype); if(!empty($userinfo)) { if($utype==1)//前台用户 { return $userinfo[0]['member_list_username'].' '.$linkStyle.' '.$userinfo[0]['member_list_nickname']; } elseif($utype==2)//后台用户 { return $userinfo[0]['admin_username'].' '.$linkStyle.' '.$userinfo[0]['admin_realname']; } else{ return "未知状态,请联系管理员"; } }else { return $errUserMsg; } } /** * 获取多用户名称 * @param unknown $uids * @param unknown $utype * @param string $linkStyle * @param string $errUserMsg * @return string[]|string */ function get_cult4UserNames($uids,$utype,$linkStyle='|',$errUserMsg='用户不存在'){ $apply = new Cult4apply(); $userinfo = $apply->getUserInfos($uids,$utype); $uids=explode(',', $uids); if(count($uids)){ $data=[]; foreach ($userinfo as $row){ $username=''; if($row){ $uid=intval($row['member_list_id']); if($utype==1){//前台用户 $username=$row['member_list_username'].' '.$linkStyle.' '.$row['member_list_nickname']; }elseif($utype==2){//后台用户 $username=$row['admin_username'].' '.$linkStyle.' '.$row['admin_realname']; } $data[$uid]=$username; } } foreach ($uids as $uid){ if(!isset($data[$uid]))$data[$uid]='未知'; } return $data; } return $errUserMsg; } /** * 根据角色id获取前后台角色名,返回值为字符串 * @param int $rid 角色id * @param int $utype 角色类型1 前台 2后台 * @return int */ function get_cult4RoleName($rid,$utype) { $apply = new Cult4apply(); $roleinfo = $apply->getRoleInfos($rid,$utype); if(!empty($roleinfo)) { if($utype==1)//前台用户 { return '前台 | '.$roleinfo[0]['member_group_name']; } elseif($utype==2)//后台用户 { return '后台 | '.$roleinfo[0]['title']; } else{ return "未知状态,请联系管理员"; } }else { return "无"; } } /** * 根据用户id获取前后台用户名/用户昵称,返回值为数组 * @param int $uid 用户id * @return string */ function get_cult4UserStatus($uid,$utype) { $apply = new Cult4apply(); $userinfo = $apply->getUserInfos($uid,$utype); if(!empty($userinfo)) { if ($utype == 1){//前台用户 return $userinfo[0]['member_list_open']; } elseif ($utype == 2){//后台用户 return $userinfo[0]['admin_open']; } else { return "未知用户,请联系管理员"; } } } /** * 根据用户id获取前后台用户名/用户昵称,返回值为数组 * @param int $uid 用户id * @return string */ function get_cult4UserStatuses($uids,$utype){ $apply = new Cult4apply(); $userinfo = $apply->getUserInfos($uids,$utype); $uids=explode(',', $uids); if(count($uids)){ $data=[]; foreach ($userinfo as $row){ $status=''; if($row){ $uid=intval($row['member_list_id']); if($utype==1){//前台用户 $status=$row['member_list_open']; }elseif($utype==2){//后台用户 $status=$row['admin_open']; } $data[$uid]=$status; } } foreach ($uids as $uid){ if(!isset($data[$uid]))$data[$uid]=[]; } return $data; } } /** * 根据流程status获取对应的状态描述,返回值为字符串 * @param int $status_id 流程状态id * @return string */ function get_cult4Status($status_id){ $status = new Cult4status(); $curStatus = $status->getStatus($status_id); return $curStatus[0]['descr']; } /** * 根据流程status获取对应的状态描述,返回值为字符串 * @param int $status_id 流程状态id * @return string */ function get_cult4Statuses($status_ids){ $data=[]; $status = new Cult4status(); foreach ($status_ids as $status_id){ $curStatus = $status->getStatus($status_id); $data[$status_id]=$curStatus[0]['descr']; } return $data; } /** * 根据apply_id获取对应的缴费结果,返回值为int * @param int $apply_id 申请id * @return int */ function get_cult4feeflag($apply_id){ $where=array( 'apply_id'=>$apply_id, 'new_flag'=>1, ); $check=Db::name('cult4fee')->where($where)->order('addorder desc,fee_id desc')->find (); if(!empty($check)){ return $check['fee_flag']; } return 0; } /** * 根据apply_id获取对应的缴费结果,返回值为int * @param int $apply_id 申请id * @return int */ function get_cult4feeflags($apply_ids=''){ $where=array('new_flag'=>1); $check=Db::name('cult4fee')->where($where)->where('apply_id','in',$apply_ids)->order('addorder desc,fee_id desc')->select(); $data=[]; if(count($check)){ foreach ($check as $row){ $aid=$row['apply_id']; $data[$aid]=$row['fee_flag']; } } foreach ($apply_ids as $aid){ if(!isset($data[$aid]))$data[$aid]=0; } return $data; } /** * 根据apply_id和userid获取对应的核实结果,返回值为int * @param int $apply_id 申请id * @param int $uid 用户id * @return int */ function get_cult4IsUserAdvicedMC($apply_id,$uid) { $where=array( 'apply_id'=>$apply_id, 'create_id'=>$uid, 'btnid'=>4, ); $Cnt=Db::name('cult4checkmc')->where($where)->count(); return $Cnt; } /** * 根据文件类型id获取文件描述信息,返回值为字符串 * @param int $ftypeid 文件类型id * @return string */ function get_cult4FileTypeDescr($ftypeid) { $filetypeinfo = new Cult4uptype(); $typeinfo = $filetypeinfo->getFileTypeInfo($ftypeid); return $typeinfo[0]['ftypedescr']; } /** * 根据文件id获取文件路径,返回值为字符串 * @param int $fid 文件id * @return string */ function get_cult4FilePath($fid) { $fileinfo = new Cult4upfiles(); $file = $fileinfo->getFileInfo($fid); return $file[0]['path']; } /** * 根据模板文件id获取文件路径,返回值为字符串 * @param int $ftempid 文件id * @return string */ function get_cult4TempFilePath($ftempid) { $tempfileinfo = new Cult4upfiles(); $tempfile = $tempfileinfo->getFileInfo($ftempid); return $tempfile[0]['path']; } /** * 根据模板文件id获取对应实体文件fileid,返回值为int * @param int $ftempid 模板文件id * @param int $applyid 申请id * @return int 实际文件id */ function get_cult4FileIDFromTempID($ftempid,$applyid) { $fileinfo = new Cult4upfiles(); $tempfile = $fileinfo->getFileInfoFromTempFile($ftempid,$applyid); if(!empty($tempfile)) { return $tempfile['file_id']; }else{ return 0; } } /** * 根据模板文件id获取对应实体文件fileid,返回值为int * @param int $ftempid 模板文件id * @param int $applyid 申请id * @return int 实际文件id */ function get_capitalFileIDFromTempID($ftempid,$applyid) { $fileinfo = new CapitalUpfiles(); $tempfile = $fileinfo->getFileInfoFromTempFile($ftempid,$applyid); if(!empty($tempfile)) { return $tempfile['file_id']; }else{ return 0; } } /** * 根据模板文件id获取对应实体文件user_id,返回值为int * @param int $ftempid 模板文件id * @param int $applyid 申请id * @return int 实际文件user_id */ function get_cult4UserIDFromTempID($ftempid,$applyid) { $tempfileinfo = new Cult4upfiles(); $tempfile = $tempfileinfo->getFileInfoFromTempFile($ftempid,$applyid); if(!empty($tempfile)) { return $tempfile['user_id']; }else{ return 0; } } /** * 根据模板文件id获取对应实体文件user_type,返回值为int * @param int $ftempid 模板文件id * @param int $applyid 申请id * @return int 实际文件user_type */ function get_cult4UserTypeFromTempID($ftempid,$applyid) { $tempfileinfo = new Cult4upfiles(); $tempfile = $tempfileinfo->getFileInfoFromTempFile($ftempid,$applyid); if(!empty($tempfile)) { return $tempfile['user_type']; }else{ return 0; } } /** * 根据模板文件id获取对应实体文件filesize,返回值为int * @param int $ftempid 模板文件id * @param int $applyid 申请id * @return int 实际文件filesize */ function get_cult4FileSizeFromTempID($ftempid,$applyid) { $tempfileinfo = new Cult4upfiles(); $tempfile = $tempfileinfo->getFileInfoFromTempFile($ftempid,$applyid); if(!empty($tempfile)) { return $tempfile['filesize']; }else{ return 0; } } /** * 根据模板文件id获取对应实体文件filesize,返回值为int * @param int $ftempid 模板文件id * @param int $applyid 申请id * @return int 实际文件filesize */ function get_capitalFileSizeFromTempID($ftempid,$applyid) { $tempfileinfo = new CapitalUpfiles(); $tempfile = $tempfileinfo->getFileInfoFromTempFile($ftempid,$applyid); if(!empty($tempfile)) { return $tempfile['filesize']; }else{ return 0; } } /** * 根据模板文件id获取对应实体文件upload_time,返回值为int * @param int $ftempid 模板文件id * @param int $applyid 申请id * @return int 实际文件upload_time */ function get_cult4UploadTimeFromTempID($ftempid,$applyid) { $tempfileinfo = new Cult4upfiles(); $tempfile = $tempfileinfo->getFileInfoFromTempFile($ftempid,$applyid); if(!empty($tempfile)) { return $tempfile['upload_time']; }else{ return 0; } } /** * 根据模板文件id获取对应实体文件upload_time,返回值为int * @param int $ftempid 模板文件id * @param int $applyid 申请id * @return int 实际文件upload_time */ function get_capitalUploadTimeFromTempID($ftempid,$applyid) { $tempfileinfo = new CapitalUpfiles(); $tempfile = $tempfileinfo->getFileInfoFromTempFile($ftempid,$applyid); if(!empty($tempfile)) { return $tempfile['upload_time']; }else{ return 0; } } /** * 根据模板文件id获取对应实体文件path,返回值为int * @param int $ftempid 模板文件id * @param int $applyid 申请id * @return string 实际文件path */ function get_cult4PathFromTempID($ftempid,$applyid) { $tempfileinfo = new Cult4upfiles(); $tempfile = $tempfileinfo->getFileInfoFromTempFile($ftempid,$applyid); if(!empty($tempfile)) { return $tempfile['path']; }else{ return '未上传'; } } /** * 根据模板文件id获取对应实体文件apply_id,返回值为int * @param int $fid 模板文件id * @return int 申请id */ function get_cult4ApplyIDFromTempID($fid) { $tempfileinfo = new Cult4uptype(); $tempfile = $tempfileinfo->getFileTypeInfo($fid); if(!empty($tempfile)) { return $tempfile[0]['apply_id']; }else{ return -1; } } /** * 根据模板文件id获取对应实体文件apply_id,返回值为int * @param int $fid 模板文件id * @return int 申请id */ function get_capitalApplyIDFromTempID($fid) { $tempfileinfo = new Capitaluptype(); $tempfile = $tempfileinfo->getFileTypeInfo($fid); if(!empty($tempfile)) { return $tempfile[0]['apply_id']; }else{ return -1; } } /** * 根据文件id获取对应实体文件path,返回值为int * @param int $fid 文件id * @return string 实际文件path */ function get_capitalPathFromFileID($fid) { $fileinfo = new CapitalUpfiles(); $file = $fileinfo->getFileInfoFromFileId($fid); if(!empty($file)) { return $file['path']; }else{ return '未上传'; } } /** * 根据文件id获取对应实体文件path,返回值为int * @param int $fid 文件id * @return string 实际文件path */ function get_cult4PathFromFileID($fid) { $fileinfo = new Cult4upfiles(); $file = $fileinfo->getFileInfoFromFileId($fid); if(!empty($file)) { return $file['path']; }else{ return '未上传'; } } /** * 根据文件id获取对应实体文件flag,返回值为int * @param int $fid 文件id * @return int 实际文件flag */ function get_cult4FlagFromFileID($fid) { $fileinfo = new Cult4upfiles(); $file = $fileinfo->getFileInfoFromFileId($fid); if(!empty($file)) { return $file['flag']; }else{ return -1; } } /** * 根据文件id获取对应实体文件flag,返回值为int * @param int $fid 文件id * @return int 实际文件flag */ function get_capitalFlagFromFileID($fid) { $fileinfo = new CapitalUpfiles(); $file = $fileinfo->getFileInfoFromFileId($fid); if(!empty($file)) { return $file['flag']; }else{ return -1; } } /** * 根据文件id获取对应实体文件apply_id,返回值为int * @param int $fid 文件id * @return int 申请id */ function get_cult4ApplyIDFromFileID($fid) { $fileinfo = new Cult4upfiles(); $file = $fileinfo->getFileInfoFromFileId($fid); if(!empty($file)) { return $file['apply_id']; }else{ return -1; } } /** * 根据apply_id和用户id获取用户的检查状态 * @param int $apply_id 操作的申请 * @param int $admin_id 操作的用户 * @return int 返回结果 */ function check_cult4UserRight($apply_id,$admin_id,$status) { $where=array( 'apply_id'=>$apply_id, 'status'=>$status, ); //'apply_admin_id'=>$admin_id, $apply=Db::name('cult4apply')->where($where)->find (); if(empty($apply)){ return 0; } return 1; } /** * 根据apply_id和用户id获取用户的检查状态 * @param int $apply_id 操作的申请 * @param int $admin_id 操作的用户 * @return int 返回结果 */ function check_capitalUserRight($apply_id,$admin_id,$status) { $where=array( 'apply_id'=>$apply_id, 'status'=>$status, ); $apply=Db::name('capitalapply')->where($where)->find(); if(empty($apply)){ return 0; } return 1; } /** * 根据apply_id获取对应实体的企业名称或者项目名称或者申请人名称,返回值为string * @param int $apply_id 申请id * @return string 实际文件path */ function get_cult4ApplyName($apply_id) { $data=array(); $data=Db::name('cult4apply')->alias("a")->join(config('database.prefix').'cult4baseinfo b','a.apply_id =b.apply_id') ->where(['b.new_flag'=>1,'a.apply_id'=>$apply_id])->find(); if(!empty($data)) { if($data['apply_type']==1||$data['apply_type']==4) return $data['c_name']; elseif ($data['apply_type']==2||$data['apply_type']==5) return $data['p_name']; elseif ($data['apply_type']==3) return $data['t_apply_username']; }else{ return '
未知
'; } } /** * 根据apply_id获取对应实体的企业名称或者项目名称或者申请人名称,返回值为string * @param int $apply_id 申请id * @return string 实际文件path */ function get_cult4ApplyNames($apply_ids=[]){ $db=Db::name('cult4apply')->alias("a")->join(config('database.prefix').'cult4baseinfo b','a.apply_id =b.apply_id'); $db->where(['b.new_flag'=>1]); $db->where('a.apply_id','in',$apply_ids); $data=$db->select(); $list=[]; if(count($data)){ foreach ($data as $row){ $aid=$row['apply_id']; $name=''; if($row['apply_type']==1||$row['apply_type']==4||$row['apply_type']==6){ $name=$row['c_name']; $pname=$row['p_name']; if($pname)$name=$pname; }elseif ($row['apply_type']==2){ $name=$row['p_name']; }elseif ($row['apply_type']==5){ $name=($row['p_type']==1)?$row['p_com_name']:$row['p_natural_name']; if(empty($name)){ $name=$row['c_name']; } }elseif ($row['apply_type']==3) $name=$row['t_apply_username']; else $name='
未知
'; $list[$aid]=$name; } foreach ($apply_ids as $aid){ if (!isset($list[$aid]))$list[$aid]='
未知
'; } } return $list; } /** * 根据apply_id获取对应实体的申请类型,返回值为int * @param int $apply_id 申请id * @return int 实际申请者类型 */ function get_cult4ApplyType($apply_id) { $data=array(); $data=Db::name('cult4apply')->alias("a")->join(config('database.prefix').'cult4baseinfo b','a.apply_id =b.apply_id') ->where(['b.new_flag'=>1,'a.apply_id'=>$apply_id])->find(); if(!empty($data)) { if($data['apply_type']==1) return '企业'; elseif ($data['apply_type']==2) return '项目'; elseif ($data['apply_type']==3) return '人才'; }else{ return '
未知
'; } } /** * 根据模板文件id获取对应实体的总的上传历史文件数量,返回值为int * @param int $apply_id 申请文件id * @param int $ftype_id 模板文件id * @return int 历史文件数量 */ function get_cult4CntHistory($apply_id,$ftype_id) { $count=0; $count=Db::name('cult4upfiles')->where(['apply_id'=>$apply_id,'ftype_id'=>$ftype_id,'new_flag'=>0])->count(); return $count; } /** * 是否可以上传当前文件,返回值为int * @param int $upload_role_type 上传角色类型 * @param int $upload_role_id 角色id * @param int $upload_role_type2 上传角色类型2 * @param int $upload_role_id2 角色id2 * @param int $type 2=后台 1=前台 * @return int 0:不能上传 1:能上传 */ function chk_cult4CanUpload($upload_role_type,$upload_role_id,$upload_role_type2,$upload_role_id2,$type=2) { $type=isset($type)?$type:2; if($type==1){ $user_id=session('hid'); $groupid=Db::name('member_list')->where('member_list_id',$user_id)->value('member_list_groupid'); if( (($upload_role_type==1) and ($upload_role_id==$groupid) ) or (($upload_role_type2==1) and ($upload_role_id2==$groupid)) ){ return 1; } return 0; }else{ $user_id=session('admin_auth.aid'); //当前后台用户对应的组 $group=Db::name('auth_group_access')->where('uid',$user_id)->find(); $groupid=0; if(!(empty($group))){ $groupid=$group['group_id']; } if($groupid==1)return 1; if( (($upload_role_type==2) and ($upload_role_id==$groupid) ) or (($upload_role_type2==2) and ($upload_role_id2==$groupid)) ){ return 1; } return 0; } } /** * 是否后台可以代前台专家会员评分,返回值为int * @param int $id 分配专家id * @return int 0:不能 1:能 */ function chk_cult4CanChangeScore($apply_id,$pro_id) { $where=array( 'apply_id'=>$apply_id, 'pro_id'=>$pro_id, 'assign_type'=>0, 'del_flag'=>0, ); $rst=Db::name('cult4proassign')->where($where)->find(); if($rst){ if(($rst['score']==0) and ($rst['advice']==null)) return 1; else return 0; } return 1; } /** * 是否后台可以代前台专家会员评分,返回值为int * @param int $id 分配专家id * @return int 0:不能 1:能 */ function chk_capitalCanChangeScore($apply_id,$pro_id) { $where=array( 'apply_id'=>$apply_id, 'pro_id'=>$pro_id, 'assign_type'=>0, 'del_flag'=>0, ); $rst=Db::name('capitalproassign')->where($where)->find(); if($rst){ if(($rst['score']==0) and ($rst['advice']==null)) return 1; else return 0; } return 1; } /** * 是否后台可以代前台专家会员评分,返回值为int * @param int $id 分配专家id * @return int 0:不能 1:能 */ function getRegionName($pid) { $where=array( 'id'=>$pid, ); $rst=Db::name('region')->where($where)->find(); if($rst){ return $rst['name']; } return '未知'; } function getApiSign($param){ ksort($param); $paramkeys = array_keys($param); $paramstring =""; //拼接参数名和参数值字符串 foreach ($paramkeys as $key){ $paramstring = "$paramstring$key$param[$key]"; } $private_key = "szwjs";//约定秘钥 $paramstring="$paramstring$private_key"; return md5($paramstring);//加密获得sign字符串 } /** 调用识别名片接口 * @param $param * @return array|mixed */ function ImgReconCard($filepath){ try { $filepath = realpath ( $filepath ); $file = array ( "key" => "NmMiQjAW5627rrGf6HrBp9", "secret" => "7a4a49a4d7de490aad61c63372aa615f", "typeId" => "20", "format" => "json", "file" => new \CURLFile ( $filepath, 'image/jpeg' ) ); $curl = curl_init (); curl_setopt ( $curl, CURLOPT_URL, "http://netocr.com/api/recog.do" ); curl_setopt ( $curl, CURLOPT_POST, true ); curl_setopt ( $curl, CURLOPT_POSTFIELDS, $file ); curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true ); $result = curl_exec ( $curl ); curl_close ( $curl ); $ocr =json_decode ( $result, true ); if ($ocr) { if ($ocr ['message'] ['status'] == 0) { $cardinfo = $ocr ['cardsinfo'] [0]; foreach ( $cardinfo ['items'] as $k => $v ) { if ($v ['desc'] == "姓名") { $card ['name'] = $v ['content']; } if ($v ['desc'] == "地址") { $card ['address'] = $v ['content']; } if ($v ['desc'] == "公司") { $card ['company'] = $v ['content']; } if ($v ['desc'] == "手机") { $card ['tel'] = $v ['content']; } } } } else { $card = $ocr; } return $card; } catch (SOAPFault $e) { } } /** * 根据模板文件id获取文件路径,返回值为字符串 * @param int $ftempid 文件id * @return string */ function get_tg_tempfile($ftempid) { $path=Db::name('trusteeship_upfiles')->where(['file_id'=>$ftempid])->value('path'); return get_imgurl($path); } function get_TGStatus($status_id) { $curStatus =Db::name('trusteeship_status')->where(['status'=>$status_id])->select(); return $curStatus[0]['descr']; } function get_TGPathFromFileID($fid) { $file = Db::name('trusteeship_upfiles')->where(['file_id'=>$fid])->order('upload_time desc')->find();; if(!empty($file)) { return $file['path']; }else{ return '未上传'; } } function get_OrgStatus($status_id) { $curStatus =Db::name('org_status')->where(['status'=>$status_id])->select(); return $curStatus[0]['descr']; } function get_OrgPathFromFileID($fid) { $file = Db::name('org_upfiles')->where(['file_id'=>$fid])->order('upload_time desc')->find();; if(!empty($file)) { return $file['path']; }else{ return '未上传'; } } function send_post($str_param){ $host=config('apiHost'); $api_url =$host.'/midservice/api'; $ch = curl_init (); curl_setopt ( $ch, CURLOPT_URL, $api_url ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 10 ); curl_setopt ( $ch, CURLOPT_POST, 1 ); //启用POST提交 curl_setopt($ch, CURLOPT_POSTFIELDS, $str_param); $file_contents = curl_exec ( $ch ); curl_close ( $ch ); if(json_decode($file_contents)[0]->result!='000000'){ session("api_token",null); } return json_decode($file_contents)[0]; } /** 掌柜文化金服登录 * @param $login_name 登录名 * @param $login_password 登录密码 * @param $verify 验证码(图像验证码/短信验证码) * @return string */ function login_api($login_name,$login_password,$verify) { $post_data='directives=[{ "api":"MT1100","params":{ "account": "'.$login_name ; $post_data=$post_data.'", "VERIFYCODE": "'.$verify.'", "CAPTCHA_TOKEN":"'.getapitoken().'", "pwd": "'.$login_password.'" } }]'; return send_post($post_data); } /** 获取掌柜文化金服系统配置 * @return mixed */ function getSystemConfig(){ $post_data='directives=[{"api":"MT1001", "params":{}}]'; return send_post($post_data); } /*** 获取接口token值 * @return mixed */ function getapitoken(){ if(empty(session("api_token"))){ $post_data='directives=[{"api":"MT1002", "params":{}}]'; $token=''; try { $result =send_post($post_data); $token=$result->data->CAPTCHA_TOKEN; }catch (\Exception $e){ } session("api_token",$token); } return session("api_token"); } /** 获取图形验证码url * @return string */ function getVerifyImg(){ session("api_token",null); $host=config('apiHost'); return $host.'/midservice/captcha?value='.getapitoken(); } function sendSms($phone,$verify_code,$token){ $post_data='directives=[{"api":"MT1301", "params":{"phoneNumber":"'.$phone.'","CAPTCHA":"'.$verify_code.'","CAPTCHA_TOKEN":"'.$token.'","CAPTCHA_ACTION":"RANDOMCODE"}}]'; return send_post($post_data); } function register_api($phone,$verify,$token,$password){ $post_data='directives=[{ "api":"MT1305", "params":{ "phoneNumber": "'.$phone.'", "verifyCode": "'.$verify.'",'; $post_data = $post_data.'"CAPTCHA_TOKEN":"'.$token.'", "password": "'.$password.'", "memberId":"6666" } }]'; return send_post($post_data); } /** 检查上传文件的类型 * @param $table 文件类型表名 * @param $typeid 文件类型ID * @param $uptype 上传的文件类型 */ function check_upfiletype($table,$typeid,$uptype){ $ftype = DB::name($table)->where(['ftype_id'=>$typeid])->find(); if($ftype){ if($ftype['ftype'] == 'PDF') { if(in_array(strtoupper($uptype),['PDF'])){ return true; } return false; }else if($ftype['ftype'] == 'JPG') { if(in_array(strtoupper($uptype),['JPG'])){ return true; } return false; }else if($ftype['ftype'] == 'DOC') { if(in_array(strtoupper($uptype),['DOC','DOCX'])){ return true; } return false; } }else{ return false; } } function check_cardno($cardType,$value){ if($cardType==1){//身份证 $reg = '/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/'; return preg_match($reg,$value); }else if($cardType==2){//护照 return 1; }else if($cardType==3){//军官证 return true; }else if($cardType==4){//港澳通行证 return 1; }else if($cardType==5){//台同胞 return 1; } } function checkHTMLTag($value){ if(!is_string($value))return false; $reg = '/^[<]+[a-zA-Z]*[>]*|[<]*[a-zA-Z]*[>]+$/'; return preg_match($reg,$value); }