123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- <?php
- use think\facade\Config;
- use think\facade\Db;
- use think\facade\Filesystem;
- // 应用公共文件
- function error_show($code=0,$message=""){
- $result = ['code'=>$code,"message"=>$message];
- echo json_encode($result,JSON_UNESCAPED_UNICODE);
- die();
- }
- // 应用公共文件
- function app_show($code=0,$message="",$data=[]){
- $result = ['code'=>$code,"message"=>$message,"data"=>$data];
- echo json_encode($result,JSON_UNESCAPED_UNICODE);
- die();
- }
- function makeNo($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;
- }
- //参数1:访问的URL,参数2:post数据(不填则为GET),参数3:提交的$cookies,参数4:是否返回$cookies
- function curl_request($url,$post=''){
- $header = headerSign($post);
- if(is_array($post)) $post=http_build_query($post);
- $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;
- }
- 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=["Content-Type"=>"multipart/json;charset=utf-8"];
- foreach ($headerArr as $key=>$value){
- $list[]=$key.":".$value;
- }
- return $list;
- }
- }
- /**
- * @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){
- $url =env("user.hosturl")."verifyToken";
- $data=[
- "token"=>$token
- ];
- $response=curl_request($url,$data);
- return json_decode($response,true);
- }
- /**
- * @param $token
- * @param $condition
- * @return mixed
- */
- function GetUserlist($token,$condition){
- $url = env("user.hosturl")."userlist";
- $condition['token']=$token;
- $response=curl_request($url,$condition);
- return json_decode($response,true);
- }
- /**
- * @param $token
- * @param $condition
- * @return mixed
- */
- function GetAccountall($token, $condition){
- $url = env("user.hosturl")."userall";
- $condition['token']=$token;
- $response=curl_request($url,$condition);
- return json_decode($response,true);
- }
- function GetList($token,$condition){
- $url = env("user.hosturl")."userlist";
- $condition['token']=$token;
- $response=curl_request($url,$condition);
- return json_decode($response,true);
- }
- function GetUserInfo($condition){
- $url = env("user.hosturl")."userinfo";
- $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;
- }
- /**
- * @param $token
- * @param $condition
- * @return mixed
- */
- function resetinfo($token,$condition){
- $url = env("user.hosturl")."usersave";
- $condition['token']=$token;
- $response=curl_request($url,$condition);
- return json_decode($response,true);
- }
- /**
- * @param $token
- * @param $condition
- * @return mixed
- */
- function resetstatus($token,$condition){
- $host = Config::get("app");
- $url = env("user.hosturl")."userstatus";
- $condition['token']=$token;
- $response=curl_request($url,$condition);
- return json_decode($response,true);
- }
- function crea($data,$vio=0)
- {
- $db = Db::name("company_item")->where(['pid'=>$data['id'],'is_del'=>0])->select()->toArray();
- if($vio==1){
- $d = Db::name("depart_user")->where(['itemid'=>$data['id'],'is_del'=>0])->select()->toArray();
- if(empty($d)){
- $data['item']=[];
- }else{
- $data['item']=$d;
- }
- }
- if(empty($db)){
- $data['child']=[];
- return $data;
- }
- //var_dump($db);
- foreach ($db as $p){
- $data['child'][]=crea($p,$vio);
- }
- return $data;
- }
- /**
- * @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('topic/' . date("Ymd"), $file, function () use ($file) {
- return str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName() . "_" . date('YmdHis'));
- });
- $name = str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName());
- $temp = ["url" => $url, "name" => $name];
- $savename[] = $temp;
- }
- return $savename;
- } catch (\think\exception\ValidateException $e) {
- return $e->getMessage();
- }
- }
- function made($var,$data=[]){
- $str = Db::name('model')->where(['id'=>$var])->find();
- $vmn =[];
- $vmn['id'] =$str['id'];
- $vmn['rename'] =$str['name'];
- array_unshift($data,$vmn);
- if($str['pid']==0){
- return $data;
- }else{
- return made($str['pid'],$data);
- }
- }
- /**
- * @param $token
- * @param $condition ['id'=>1]
- * @return mixed
- */
- function GetInfoById($token,$condition){
- $url = env("user.hosturl")."userinfo";
- $condition['token']=$token;
- $response=curl_request($url,$condition);
- return json_decode($response,true);
- }
- function make($var,$data=[]){
- $str = Db::name('company_item')->where(['id'=>$var])->find();
- $vmn =[];
- $vmn['id'] =$str['id'];
- $vmn['name'] =$str['name'];
- array_unshift($data,$vmn);
- // $var['id']=made();
- if($str['pid']==0){
- // krsort($data);
- return $data;
- }else{
- return make($str['pid'],$data);
- }
- }
|