$code,"message"=>$message,"data"=>$data]; return json($result); } // 应用公共文件 function error_show($code=0,$message=""){ $result = ['code'=>$code,"message"=>$message]; return json($result); } function GetUserInfo($token){ $host = Config::get("app"); $url = $host["api_host"]."/verifyToken"; $data=[ "token"=>$token ]; $response=curl_request($url,$data); return json_decode($response,true); } function setUserCompany($condition){ $host = Config::get("app"); $url = $host["api_host"]."/setcompany"; $response=curl_request($url,$condition); return json_decode($response,true); } /**手机号验证 * @param $mobile * @return bool */ function checkMobile($mobile){ if (!is_numeric($mobile)) { return false; } return preg_match('#^1[3,4,5,6,7,8,9]{1}[\d]{9}$#', $mobile) ? true : false; } function checkTel($tel){ if (!$tel) { return false; } return preg_match('/^(0[0-9]{2,3}\-)([0-9]{7,8})+(\-[0-9]{1,4})?$/', $tel) ? true : false; } /**邮箱验证 * @param $email * @return bool */ function checkEmail($email){ if (!$email) { return false; } return preg_match('#[a-z0-9&\-_.]+@[\w\-_]+([\w\-.]+)?\.[\w\-]+#is', $email) ? true : false; } /** * @param * @return int */ function makeSalt(){ $salt = rand(10000000,99999999); return $salt; } /** * @param $token * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ function VerifyTokens($token){ $host = Config::get("app"); $url = $host["api_host"]."/verifyToken"; $data=[ "token"=>$token ]; $response=curl_request($url,$data); return json_decode($response,true); } /** * @param $token * @param $condition * @return mixed */ function GetUserlist($condition){ $host = Config::get("app"); $url = $host["api_host"]."/userlistbycompany"; $response=curl_request($url,$condition); return json_decode($response,true); } ///** // * @param $token // * @param $condition // * @return mixed // */ //function GetAccountall($token, $condition){ // $host = Config::get("app"); // // $url = $host["api_host"]."/Api/userall"; // $condition['token']=$token; // $response=curl_request($url,$condition); // // return json_decode($response,true); //} function GetList($condition){ $host = Config::get("app"); $url = $host["api_host"]."/userlist"; $response=curl_request($url,$condition); return json_decode($response,true); } /** * @param $token * @param $condition ['id'=>1] * @return mixed */ function GetInfoById($token,$condition){ $host = Config::get("app"); $url = $host["api_host"]."/userinfo"; $condition['token']=$token; $response=curl_request($url,$condition); return json_decode($response,true); } /** * @param $str * @return string */ function makeNo($str){ $date=date("mdHis"); $year = date("Y")-2000; $msec=rand(1000,9999); return $str.$year.$date.$msec; } function makeStr($str){ $date=date("mdHis"); $year = date("Y")-2000; $msec=randomkeys(4); return $str.$msec.$year.$date; } function randomkeys($length) { $returnStr=''; $pattern = '1234567890abcdefghijklmnopqrstuvwxyz';//ABCDEFGHIJKLOMNOPQRSTUVWXYZ for($i = 0; $i < $length; $i ++) { $returnStr .= $pattern[mt_rand ( 0, strlen($pattern)-1 )]; //生成php随机数 } return $returnStr; } /** * @param $token * @param $condition * @return mixed */ function resetpwd($condition){ $host = Config::get("app"); $url = $host["api_host"]."/setpasswd"; $response=curl_request($url,$condition); return json_decode($response,true); } function resetpasswd($token,$condition){ $host = Config::get("app"); $url = $host["api_host"]."/Api/passsave"; $condition['token']=$token; $response=curl_request($url,$condition); return json_decode($response,true); } /** * @param $condition * @return array|bool|float|int|mixed|\stdClass|string|null */ function checkLogin($condition){ $host = Config::get("app"); $url = $host["api_host"]."/login"; $response=curl_request($url,$condition); return json_decode($response,true); } /** * @param $token * @param $condition * @return mixed */ function resetinfo($condition){ $host = Config::get("app"); $url = $host["api_host"]."/usersave"; $response=curl_request($url,$condition); return json_decode($response,true); } /** * @param $condition * @return array|bool|float|int|mixed|\stdClass|string|null */ function addacount($condition){ $host = Config::get("app"); $url = $host["api_host"]."/useradd"; $response=curl_request($url,$condition); return json_decode($response,true); } if(!function_exists("headerSign")){ function headerSign($post){ $config = Config::get("sign"); $appid=$config['appid']; $appkey=$config['appkey']; $headerArr=["appid"=>'123',"noce"=>randomkeys(16),"sign"=>'',"timestamp"=>time()]; $value =array_merge($post,$headerArr); $Sign= new \Sign($appid,$appkey); $headerArr['sign'] = $Sign->makeSign($value); $list=[]; foreach ($headerArr as $key=>$value){ $list[]=$key.":".$value; } return $list; } } //参数1:访问的URL,参数2:post数据(不填则为GET),参数3:提交的$cookies,参数4:是否返回$cookies function curl_request($url,$post='',$header=["Content-Type: multipart/json;charset=utf-8"]){ $header = empty($header) ? '' : $header; $singHead = headerSign($post); if(is_array($post)) $post=json_encode($post,JSON_UNESCAPED_UNICODE); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)'); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_AUTOREFERER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); if($post) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $post); } curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); $data = curl_exec($curl); if (curl_errno($curl)) { return curl_error($curl); } curl_close($curl); return $data; } /** * @param $roleid * @param $menu * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ function checkRole($roleid,$menu){ $roleinfo = \think\facade\Db::name("role_action")->where([['role_id',"=",$roleid],["status","=",1]])->find(); if($roleinfo['private_data']!=""){ $private = explode(",",$roleinfo['private_data']); if(in_array($menu,$private)){ return true; } } return false; } /** * @param $row * @param $list */ function makeMenu($row,&$list){ $list[$row['id']]=$row; if($row['pid']==0){ return $list; } $parent =Db::name("admin_menu")->where(["id"=>$row['pid'],"status"=>1,"is_del"=>0])->field("id,menu_name,menu_img,menu_url,menu_route,pid,is_show,is_private,menu_type,weight")->find(); if($parent==false) return $list; if($parent['menu_type']==2)$value['action']=[]; if($parent['menu_type']==1)$value['child']=[]; makeMenu($parent,$list); } /** * @param $menuArr */ function MenuTree(&$menuArr,$pid=0){ $meun=[]; foreach ($menuArr as $value){ if($value['pid']==$pid){ if($value['menu_type']==1)$value['child']=MenuTree($menuArr,$value['id']); $meun[]=$value ; } } return $meun; }; function upload($files,$extend="xls") { // 获取表单上传文件 try { validate([ 'file' => [ 'fileExt' => 'xlsx,xls' ] ], [ 'file.fileExt' => '不支持的文件', ] )->check(['file' => $files]); if ($extend == 'xlsx') { $objReader = PHPExcel_IOFactory::createReader('Excel2007'); } else { $objReader = PHPExcel_IOFactory::createReader('Excel5'); } $savename = Filesystem::disk('public')->putFile('topic/excel', $files); $import_path = root_path() . 'public/storage/' . $savename; $spreadsheet = $objReader->load($import_path); $sheet = $spreadsheet->getActiveSheet(); $sheetData = $sheet->toArray(); if (empty($sheetData) || !is_array($sheetData)) { return ['code' => 1003, "msg" => '数据不能为空']; } return ['code' => 0, "msg" => '数据解析成功', 'data' => $sheetData]; } catch (think\exception\ValidateException $e) { // echo $e->getMessage(); return ['code' => 1003, "msg" => $e->getMessage()]; } } /** * @param $files * @return array */ function UploadImg($files) { $savename = []; $files = !is_array($files) ? [$files] : $files; try { //验证 validate(['imgFile' => ['fileSize' => 10240000, 'fileExt' => 'jpg,jpeg,png,bmp,gif', 'fileMime' => 'image/jpeg,image/png,image/gif']])->check(['imgFile' => $files]); foreach ($files as $file) { $url = Filesystem::disk('public')->putFile('img/' . date("Ymd"), $file, function () use ($file) { return str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName() . "_" . date('YmdHis')); }); $name = str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName()); $temp = ["url" =>"storage/".$url, "name" => $name]; $savename[] = $temp; } return $savename; } catch (\think\exception\ValidateException $e) { return $e->getMessage(); } } if(!function_exists("invoiceType")){ //发票类型 1 专用2普通3电子普通4 电子专用 function invoiceType($key=0){ $panda= ['',"004",'007','026','028']; return $panda[$key]??''; } }