123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkPHP [ WE CAN DO IT JUST THINK ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: 流年 <liu21st@gmail.com>
- // +----------------------------------------------------------------------
- // 应用公共文件
- function pre($content, $is_die = true)
- {
- header('Content-type: text/html; charset=utf-8');
- echo '<pre>' . print_r($content, true);
- $is_die && die();
- }
- /**
- * 成功Json返回函数
- * @param string $code
- * @param array $data
- * @param string $msg
- */
- function json_return($code,$data=[],$msg='')
- {
- exit(json_encode(['code'=>$code,'data'=>$data,'msg'=>$msg],JSON_UNESCAPED_UNICODE ));
- }
- function json_success($data,$msg='ok'){
- exit(json_encode(['code'=>0,'data'=>$data,'msg'=>$msg],JSON_UNESCAPED_UNICODE ));
- }
- function curl_get_https($url,$data){
- if(is_array($data))
- {
- $param = '';
- foreach ($data as $k=>$v){
- $param .= $k."=".$v."&";
- }
- $param = rtrim($param ,"&");
- if(!strpos($url,"?")){
- $url .= "?".$param;
- }
- else{
- $url .= "&".$param;
- }
- }
- $curl = curl_init(); // 启动一个CURL会话
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_HEADER, 0);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); // 从证书中检查SSL加密算法是否存在
- $tmpInfo = curl_exec($curl); //返回api的json对象
- //关闭URL请求
- curl_close($curl);
- return $tmpInfo; //返回json对象
- }
- function http_get($url,$data)
- {
- return json_decode(curl_get_https($url,$data),true);
- }
- /**
- * 整理菜单住方法
- * @param $param
- * @return array
- */
- function prepareMenu($param)
- {
- $param = objToArray($param);
- $parent = []; //父类
- $child = []; //子类
- foreach($param as $key=>$vo){
- if(0 == $vo['type_id']){
- $vo['href'] = '#';
- $parent[] = $vo;
- }else{
- $vo['href'] = url($vo['control_name'] .'/'. $vo['action_name']); //跳转地址
- $child[] = $vo;
- }
- }
- foreach($parent as $key=>$vo){
- foreach($child as $k=>$v){
- if($v['type_id'] == $vo['id']){
- $parent[$key]['child'][] = $v;
- }
- }
- }
- unset($child);
- return $parent;
- }
- /**
- * 统一返回信息
- * @param $code
- * @param $data
- * @param $msge
- */
- function msg($code, $data, $msg)
- {
- return compact('code', 'data', 'msg');
- }
- /**
- * 整理出tree数据 --- layui tree
- * @param $pInfo
- * @param $spread
- */
- function getTree($pInfo, $spread = true)
- {
- $res = [];
- $tree = [];
- //整理数组
- foreach($pInfo as $key=>$vo){
- if($spread){
- $vo['spread'] = true; //默认展开
- }
- $res[$vo['id']] = $vo;
- $res[$vo['id']]['children'] = [];
- }
- unset($pInfo);
- //查找子孙
- foreach($res as $key=>$vo){
- if(0 != $vo['pid']){
- $res[$vo['pid']]['children'][] = &$res[$key];
- }
- }
- //过滤杂质
- foreach( $res as $key=>$vo ){
- if(0 == $vo['pid']){
- $tree[] = $vo;
- }
- }
- unset( $res );
- return $tree;
- }
- /**
- * 对象转换成数组
- * @param $obj
- */
- function objToArray($obj)
- {
- return json_decode(json_encode($obj), true);
- }
- /**
- * 权限检测
- * @param $rule
- */
- function authCheck($rule)
- {
- $control = explode('/', $rule)['0'];
- if(in_array($control, ['login', 'index'])){
- return true;
- }
- if(in_array($rule, cache(session('role_id')))){
- return true;
- }
- return false;
- }
|