<?phpfunction token(){
$token='';
$n='qwertyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM';
for ($i=0;$i<32;$i++){
$token.=$n[mt_rand(0,strlen($n)-1)];
}
return $token;
}function getToken(){
$header=request()->header('token');
$parm=input('get.token');
if(empty($header) && empty($parm)){
$token='';
}else if(!empty($header)){
$token=$header;
}else{
$token=$parm;
}
return $token;
}function checkLogin() {
$token=getToken();
$cache=cache($token);
if($cache==null){
return false;
}else{
cacheReset($token);
return true;
}
}function cacheReset($key){
$config=config();
if($config['cache']['default']=='file'){
$file=cache()->getCacheKey($key);
touch($file);
}
return true;
}function getUserID(){
$cache=cache(getToken());
if(empty($cache)){
die('[ ERROR ] 获取用户失败!');
}else{
return $cache['user'];
}
}function existFull($arr,$keys){
$state=true;
foreach ($keys as $key) {
if(!isset($arr[$key]) || empty($arr[$key]) || $arr[$key] === 'null'){
$state=false;
break;
}
}
return $state;
} function verify($data,$rule,$info=false){
$validate = \think\facade\Validate::rule($rule);
if($validate->check($data)){
return true;
}else{
return $info?$validate->getError():false;
}
}function zhToPy($text,$type='head'){
$nod=new \org\ZhToPy();
$result=$nod::encode($text,$type);
return strtolower($result)}function arraySeek($array,$source){
$recode=$array;
is_array($source)||($source=explode('|',$source));
foreach ($source as $sourceVo) {
if(is_array($recode) && isset($recode[$sourceVo])){
$recode=$recode[$sourceVo];
}else{
$recode='';
break;
}
}
return $recode;
}function search($arr){
$search=new \org\Search($arr);
return $search;
}function isJson($string) {
json_decode($string);
return(json_last_error()==JSON_ERROR_NONE);
}function findSubData($arr,$id){
$data=[];
$search=search($arr,[['pid','=',$id]])->select();
foreach ($search as $searchVo) {
$subSearch=search($arr,[['pid','=',$searchVo['id']]])->select();
$data[]=$searchVo;
if(!empty($subSearch)){
$data=array_merge($data,findSubData($arr,$searchVo['id'])) }
}
return $data;
}function htmlpurifier($html) {
$config = HTMLPurifier_Config::createDefault();
$config->set('CSS.AllowTricky', true);
$purifier = new \HTMLPurifier($config);
$clean_html = $purifier->purify($html);
return $clean_html;
}function getXlsx($file){
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx')->setReadDataOnly(TRUE)->load($file)->getSheet(0)->toArray (null,false,false,true);
array_walk_recursive($reader,function(&$vo){$vo=$vo===null?'':htmlpurifier($vo);});
return $reader;
}function pathChange($path=false){
return $path==false?root_path():root_path().str_replace(".",DIRECTORY_SEPARATOR,$path).DIRECTORY_SEPARATOR;
}function delOverdueFile($path,$time=30){
clearstatcache() $path=pathChange($path) $files=scandir($path) $nowTime=time() foreach ($files as $key=>$vo){
if(substr($vo,0,1)!='.'){
$filePath=$path.$vo if ($nowTime-filectime($filePath)>$time){
@unlink($filePath);
}
}
}
}function delDir($path){
$path=pathChange($path);
if(file_exists($path)){
$list=listFile($path);
foreach ($list['files'] as $file) {
@unlink($file);
}
foreach ($list['dirs'] as $dir) {
@rmdir($dir);
}
}
}function delCache(){
$cache=pathChange('runtime.cache');
if(file_exists($cache)){
$list=listFile($cache);
foreach ($list['files'] as $file) {
$content = @file_get_contents($file);
if($content!==false){
$expire = (int)substr($content, 8, 12);
if ($expire!=0 && time() - $expire > filemtime($file)){
@unlink($file);
}
}
}
foreach ($list['dirs'] as $dir) {
@rmdir($dir);
}
}
}
function calArrMaxCount($arr,$max=0){
foreach ($arr as $vo) {
if(is_array($vo)){
$count=count($vo);
if ($count==count($vo,1)) {
$count > $max&&($max=$count);
}else{
$max=CalArrMaxCount($vo,$max);
}
}
}
return $max;
}function buildExcel($fileName,$data,$down=true){
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$cellName=['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'] $shell=$spreadsheet->getActiveSheet(0) $shell->setTitle('NODCLOUD.COM') $shell->getDefaultColumnDimension()->setWidth(20) $shell->getDefaultRowDimension()->setRowHeight(16) $rowNums=1 $maxCell=calArrMaxCount($data) foreach ($data as $dataVo) {
if($dataVo['type']=='title'){
$cellNums=0 $shell->mergeCells($cellName[$cellNums].$rowNums.':'.$cellName[$maxCell-1].$rowNums) $shell->setCellValue($cellName[$cellNums].$rowNums,$dataVo['info'])->getStyle ($cellName[$cellNums].$rowNums)->applyFromArray ([
'font'=>['bold'=>true,'size'=>12],
'alignment'=>['horizontal'=>\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER]
]) $shell->getRowDimension($rowNums)->setRowHeight(26) $rowNums++ }elseif($dataVo['type']=='node'){
$cellNums=0 $shell->getStyle($cellName[$cellNums].$rowNums.':'.$cellName[$maxCell-1].$rowNums)->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setRGB('e7e6e6') foreach ($dataVo['info'] as $data_info) {
$shell->setCellValue ($cellName[$cellNums].$rowNums,$data_info);
$cellNums++ }
$shell->getRowDimension($rowNums)->setRowHeight(16) $rowNums++ }elseif($dataVo['type']=='table'){
$cellNums=0 foreach ($dataVo['info']['thead'] as $theadVo) {
$shell->setCellValue($cellName[$cellNums].$rowNums,$theadVo)->getStyle($cellName[$cellNums].$rowNums)->applyFromArray ([
'font'=>['bold'=>true],
'alignment'=>['horizontal'=>\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER]
]) $cellNums++ }
$shell->getRowDimension($rowNums)->setRowHeight(16) $rowNums++ foreach ($dataVo['info']['tbody'] as $tbodyVo) {
$cellNums=0 $RowHeight=16;
foreach ($tbodyVo as $tbodyVal) {
if(is_array($tbodyVal)){
if($tbodyVal['type']=='img'){
$drawing=new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing->setPath($tbodyVal['info']) $drawing->setOffsetX(22) $drawing->setOffsetY(3) $drawing->setWidth(100) $drawing->setCoordinates($cellName[$cellNums].$rowNums)->setWorksheet($shell) $imgInfo=getimagesize($tbodyVal['info']) $ImgHeight=($imgInfo[1]/($imgInfo[0]/100))*0.75 $RowHeight=$ImgHeight+4.5 }
}else{
$shell->setCellValueExplicit($cellName[$cellNums].$rowNums,$tbodyVal,\PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING) $shell->getStyle($cellName[$cellNums].$rowNums)->getAlignment()->setWrapText(true) }
$cellNums++ }
$shell->getRowDimension($rowNums)->setRowHeight($RowHeight) $rowNums++ }
}
}
$shell->getStyle('A1:'.$cellName[$maxCell-1].($rowNums-1))->applyFromArray (['borders'=>['allBorders'=>['borderStyle'=>\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN]],'alignment'=>['vertical'=>\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER]]);
ob_get_contents()&&(ob_end_clean()) $writer=\PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet,'Xlsx');
if($down){
header('Content-type:application/vnd.ms-excel');
header("Content-Disposition:attachment;filename=$fileName.xlsx");
$writer->save('php://output');
exit;
}else{
delOverdueFile('static.file.xlsx') $filePath=pathChange('static.file.xlsx').$fileName.'.xlsx';
$writer->save($filePath);
return $filePath;
}
}function buildZip($fileName,$files,$down=true){
delOverdueFile('static.file.zip') empty($files)&&(die('[ 文件数据为空 ]')) $filePath=pathChange('static.file.zip').$fileName.'.zip';
$zip=new ZipArchive();
if ($zip->open($filePath,ZIPARCHIVE::CREATE)!==TRUE) {
exit('创建压缩文件失败!');
}
foreach ($files as $file) {
$zip->addFile($file,basename($file));
}
$zip->close();
if($down){
header("Cache-Control: max-age=0");
header("Content-Description: File Transfer");
header('Content-disposition: attachment; filename='.basename($filePath)); header("Content-Type: application/zip"); header("Content-Transfer-Encoding: binary"); header('Content-Length: '.filesize($filePath)); @readfile($filePath) exit;
}else{
return $filePath;
}
}function curl($url,$header,$data,$method='POST'){
$ch=curl_init();
if($method == 'GET'){
$url = $url.'?'.http_build_query($data);
}
if($method == 'POST'){
curl_setopt($ch, CURLOPT_POST,TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
}
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_HEADER,FALSE);
if($header!=false){
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER,TRUE);
$result=curl_exec($ch);
curl_close($ch);
return $result;
}function getDirSize($dir){
static $sizeResult = 0;
$handle = opendir($dir);
while (false!==($FolderOrFile = readdir($handle))) {
if($FolderOrFile != "." && $FolderOrFile != "..") {
if(is_dir("$dir/$FolderOrFile")){
$sizeResult += getDirSize("$dir/$FolderOrFile");
}else{
$sizeResult += filesize("$dir/$FolderOrFile");
}
}
}
closedir($handle);
return round(($sizeResult/1048576),2);
}function getMysqlSize(){
$dbInfo=config('database.connections.mysql');
$tabs = think\facade\Db::query("SHOW TABLE STATUS FROM `".$dbInfo['database']."`");
$size = 0;
foreach($tabs as $vo) {
$size += $vo["Data_length"] + $vo["Index_length"];
}
return round(($size/1048576),2);
}
function txm($text,$type=true){
delOverdueFile('static.code.txm') $font = new BarcodeBakery\Common\BCGFontFile(pathChange('static.code.font').'Arial.ttf', 18);
$colorFront = new BarcodeBakery\Common\BCGColor(0, 0, 0);
$colorBack = new BarcodeBakery\Common\BCGColor(255, 255, 255);
$code = new BarcodeBakery\Barcode\BCGcode128();
$code->setScale(2);
$code->setThickness(30);
$code->setForegroundColor($colorFront);
$code->setBackgroundColor($colorBack);
$code->setFont($font);
$code->setStart(null);
$code->setTilde(true);
$code->parse($text);
if ($type){
header('Content-Type: image/png');
$drawing = new BarcodeBakery\Common\BCGDrawing('',$colorBack);
$drawing->setBarcode($code);
$drawing->draw();
$drawing->finish(BarcodeBakery\Common\BCGDrawing::IMG_FORMAT_PNG);
exit;
}else {
$filePath=pathChange('static.code.txm').uniqid().'.png';
$drawing = new BarcodeBakery\Common\BCGDrawing($filePath, $colorBack);
$drawing->setBarcode($code);
$drawing->draw();
$drawing->finish(BarcodeBakery\Common\BCGDrawing::IMG_FORMAT_PNG);
return $filePath;
}
}function ewm($text,$type=true){
delOverdueFile('static.code.ewm') $qrCode = new Endroid\QrCode\QrCode($text);
if($type){
header('Content-Type: '.$qrCode->getContentType());
echo $qrCode->writeString();
exit;
}else{
$filePath=pathChange('static.code.ewm').uniqid().'.png';
$qrCode->writeFile($filePath);
return $filePath;
}
}
function math($digit=6){
$math=new \org\Math($digit);
return $math;
}function mathArraySum($arr){
$sum=0;
foreach ($arr as $vo) {
$sum=math()->chain($sum)->add($vo)->done();
}
return $sum;
}function roundFloat($number,$digit){
return floatval(round($number,$digit));
}
function md5_16($str){
return substr(md5($str),8,16);
}function PageCalc($page,$limit,$type='array'){
$state=$limit*($page-1);
$end=$limit;
return $type=='array'?[$state,$end]:$state.','.$end;
}function assoc_unique($arr,$key){
$record=[];
foreach($arr as $k => $v) {
if(in_array($v[$key],$record)){
unset($arr[$k]);
}else{
$record[]=$v[$key];
}
}
sort($arr);
return $arr;
}function arraySort(&$arr,$field,$sort=SORT_ASC){
$fields = [];
foreach ($arr as $vo) {
$fields[] = $vo[$field];
}
array_multisort($fields,$sort,$arr);
}function arrayInArray($arr1,$arr2){
foreach ($arr1 as $vo) {
if(!in_array($vo,$arr2)){
return false;
}
}
return true;
}function arrayColumns($arr,$fields){
foreach ($fields as $field) {
$arr=array_column($arr,$field);
}
return $arr;
}function listFile($path,$state=true){
static $record=['dirs'=>[],'files'=>[]];
$state&&$record=['dirs'=>[],'files'=>[]];
foreach (new \FilesystemIterator($path) as $item) {
if ($item->isDir() && !$item->isLink()) {
$record['dirs'][]=$item->getPathname();
listFile($item->getPathname(),false);
} else {
$record['files'][]=$item->getPathname();
}
}
return $record;
}function is_arrays($arr,$fields){
foreach ($fields as $field) {
if(!isset($arr[$field]) || !is_array($arr[$field])){
return false;
}
}
return true;
}function getOldDay($day=7){
$time=strtotime(date('Y-m-d',time())) $tmp_time_arr=[];
for ($i = 0; $i < $day; $i++) {
array_push($tmp_time_arr,date('Y-m-d',$time-($i*86400)));
}
return array_reverse($tmp_time_arr)}
function uuid($prefix=''){
$chars = md5(uniqid(mt_rand(), true));
$uuid = substr($chars,0,8) . '-';
$uuid .= substr($chars,8,4) . '-';
$uuid .= substr($chars,12,4) . '-';
$uuid .= substr($chars,16,4) . '-';
$uuid .= substr($chars,20,12);
return $prefix . $uuid;
}function db($model){
return think\facade\Db::name($model);
}function getSys($name = []) {
if(empty($name)){
$sql=[];
}else{
$sql=is_array($name)?[['name','in',$name]]:[['name','=',$name]];
}
$sys = db('sys')->where($sql)->field(['name','info'])->select()->toArray();
foreach ($sys as $sysKey => $sysVo) {
isJson($sysVo['info']) && ($sys[$sysKey]['info'] = json_decode($sysVo['info'],true));
}
if (empty($sys)) {
$result = false;
} else {
if(is_array($name)){
$result = [];
foreach ($sys as $sysVo) {
$result[$sysVo['name']] = $sysVo['info'];
}
}else{
$result = $sys[0]['info'];
}
}
return $result;
}function pushLog($info,$user=false) {
db('log')->insert([
'time' => time(),
'user' => empty($user)?getUserID():$user,
'info' => $info
]);
}function getPeriod(){
$row=db('period')->order(['id'=>'desc'])->find();
return empty($row)?0:$row['date'];
}
function fastSql($arr,$config) {
$sql = [];
foreach ($config as $item){
$key=is_array($item[0])?key($item[0]):$item[0];
$field=is_array($item[0])?$item[0][key($item[0])]:$item[0];
if(array_key_exists($key,$arr)){
$val=$arr[$key];
$val==='null'&&($val=null);
$condition=$item[1];
if ($condition == 'eq') {
$sql[] = [$field,'=',$val];
} elseif ($condition == 'fullEq') {
empty($val) || ($sql[] = [$field,'=',$val]);
} elseif ($condition == 'noNullEq') {
$val===null || ($sql[] = [$field,'=',$val]);
} elseif ($condition == 'fullDec1') {
empty($val) || ($sql[] = [$field,'=',$val-1]);
} else if ($condition == 'md5') {
$sql[] = [$field,'=',md5($val)];
} elseif ($condition == 'like') {
$sql[] = [$field,'like','%'.$val.'%'];
} elseif ($condition == 'fullLike') {
empty($val) || ($sql[] = [$field,'like','%'.$val.'%']);
}elseif ($condition == 'fullTime') {
empty($val) || ($sql[] = [$field,'=',strtotime($val)]);
}elseif ($condition == 'fullIn') {
empty($val) || ($sql[] = [$field,'in',$val]);
} elseif ($condition == 'fullDivisionIn') {
empty($val) || ($sql[] = [$field,'in',explode(",",$val)]);
} elseif ($condition == 'startTime') {
$start=strtotime($val);
empty($start)||($sql[] = [$field,'>=',$start]);
} elseif ($condition == 'endTime') {
$end=strtotime($val);
empty($end)||($sql[] = [$field,'<=',$end+86399]);
}else{
die('[ ERROR ]未匹配条件!');
}
}
}
return array_unique($sql,SORT_REGULAR);
}function findTreeArr($mode,$data,$field = false) {
$tree = [];
if (!is_array($data)) {
$first = db($mode)->where([['id','=',$data]])->find();
$tree[] = $first;
$data = [$first];
}
$gather = array_column($data,'id');
$arr = db($mode)->where([['pid','in',$gather]])->select()->toArray();
if (!empty($arr)) {
$tree = array_merge($tree,$arr,findTreeArr($mode,$arr));
}
return $field == false?$tree:array_column($tree,$field);
}function moreTableFind($arr) {
$result = false;
foreach ($arr as $vo) {
$find = db($vo['table'])->where($vo['where'])->find();
if (!empty($find)) {
$result = true;
break;
}
}
return $result;
}function parmToIndex($parm){
$sql=[];
foreach ($parm as $parmKey=>$parmVo) {
$sql[]=[$parmKey,'=',$parmVo];
}
return $sql;
}function unitRadix($unit,$data){
$radix=1;
$state=false;
array_unshift($data,['name'=>$data[0]['source'],'nums'=>1]);
$data=array_reverse($data);
foreach ($data as $dataVo) {
if($state || $dataVo['name']==$unit){
$state=true;
$radix=math()->chain($radix)->mul($dataVo['nums'])->done();
}
}
if($state){
return $radix;
}else{
return false;
}
}function unitSwitch($nums,$data){
$record=[];
foreach ($data as $dataVo) {
if(abs($nums)<$dataVo['nums']){
$record[]=['name'=>$dataVo['source'],'nums'=>$nums];
$nums=0;
}else{
$mod=math()->chain($nums)->mod($dataVo['nums'])->done();
$record[]=['name'=>$dataVo['source'],'nums'=>abs($mod)];
$nums=math()->chain($nums)->sub($mod)->div($dataVo['nums'])->done();
}
}
$end=end($data);
$record[]=['name'=>$end['name'],'nums'=>$nums];
$text='';
foreach (array_reverse($record) as $recordVo) {
if(!empty($recordVo['nums'])){
$text.=$recordVo['nums'].$recordVo['name'];
}
}
$text==''&&$text=0;
return $text;
}function userInfo($id,$field = false) {
$user = db('user')->where([['id','=',$id]])->find();
return $field == false?$user:$user[$field];
}function getUserAuth($type){
$user=userInfo(getUserID());
if($user['role']==0){
$result='all';
}else{
$role=db('role')->where([['id','=',$user['role']]])->find();
$auth=json_decode($role['auth'],true);
if($type=='frame'){
if(count($auth['frame'])==1 && $auth['frame'][0]==-2){
$result='all';
}else if(count($auth['frame'])==1 && $auth['frame'][0]==-1){
$result=[$user['frame']];
}else{
$result=$auth['frame'];
}
}elseif($type=='customer'){
if($auth['customer']=='all'){
$result='all';
}else if($auth['customer']=='userId'){
$user=getUserAuth('user');
if($user=='all'){
$result='all';
}else{
$result=array_column(db('customer')->where([['user','in',$user]])->field(['id'])->select()->toArray(),'id');
}
}else{
$frame=getUserAuth('frame');
if($frame=='all'){
$result='all';
}else{
$result=array_column(db('customer')->where([['frame','in',$frame]])->field(['id'])->select()->toArray(),'id');
}
}
}elseif($type=='supplier'){
if($auth['supplier']=='all'){
$result='all';
}else if($auth['supplier']=='userId'){
$user=getUserAuth('user');
if($user=='all'){
$result='all';
}else{
$result=array_column(db('supplier')->where([['user','in',$user]])->field(['id'])->select()->toArray(),'id');
}
}else{
$frame=getUserAuth('frame');
if($frame=='all'){
$result='all';
}else{
$result=array_column(db('supplier')->where([['frame','in',$frame]])->field(['id'])->select()->toArray(),'id');
}
}
}elseif($type=='warehouse'){
if($auth['warehouse']=='all'){
$result='all';
}else if($auth['warehouse']=='userFrame'){
$result=[$user['frame']];
}else{
$frame=getUserAuth('frame');
if($frame=='all'){
$result='all';
}else{
$result=array_column(db('warehouse')->where([['frame','in',$frame]])->field(['id'])->select()->toArray(),'id');
}
}
}elseif($type=='account'){
if($auth['account']=='all'){
$result='all';
}else if($auth['account']=='userFrame'){
$result=[$user['frame']];
}else{
$frame=getUserAuth('frame');
if($frame=='all'){
$result='all';
}else{
$result=array_column(db('account')->where([['frame','in',$frame]])->field(['id'])->select()->toArray(),'id');
}
}
}elseif($type=='user'){
if($auth['user']=='all'){
$result='all';
}else if($auth['user']=='userId'){
$result=[getUserID()];
}else{
$frame=getUserAuth('frame');
if($frame=='all'){
$result='all';
}else{
$result=array_column(db('user')->where([['frame','in',$frame]])->field(['id'])->select()->toArray(),'id');
}
}
}elseif($type=='people'){
if($auth['people']=='all'){
$result='all';
}else if($auth['people']=='userFrame'){
$result=[$user['frame']];
}else{
$frame=getUserAuth('frame');
if($frame=='all'){
$result='all';
}else{
$result=array_column(db('people')->where([['frame','in',$frame]])->field(['id'])->select()->toArray(),'id');
}
}
}else{
$result = false;
}
}
return $result;
}function frameScope($sql,$field='frame'){
$cache=cache(getToken());
if(empty($cache['frame'])){
$frame=getUserAuth('frame');
if($frame!='all'){
$sql[]=[$field,'in',$frame];
}
}else{
$sql[]=[$field,'in',$cache['frame']];
}
return $sql;
}function sqlAuth($model,$sql=[]){
$tab=[
'user'=>['id'=>'user','frame'=>'frame'],
'log'=>['user'=>'user'],
'customer'=>['id'=>'customer','frame'=>'frame','user'=>'user'],
'supplier'=>['id'=>'supplier','frame'=>'frame','user'=>'user'],
'warehouse'=>['id'=>'warehouse','frame'=>'frame'],
'account'=>['id'=>'account','frame'=>'frame'],
'people'=>['frame'=>'frame'],
'bor'=>['frame'=>'frame','supplier'=>'supplier','people'=>'people','user'=>'user'],
'buy'=>['frame'=>'frame','supplier'=>'supplier','people'=>'people','user'=>'user'],
'bre'=>['frame'=>'frame','supplier'=>'supplier','people'=>'people','user'=>'user'],
'sor'=>['frame'=>'frame','customer'=>'customer','people'=>'people','user'=>'user'],
'sell'=>['frame'=>'frame','customer'=>'customer','people'=>'people','user'=>'user'],
'sre'=>['frame'=>'frame','customer'=>'customer','people'=>'people','user'=>'user'],
'swap'=>['frame'=>'frame','people'=>'people','user'=>'user'],
'entry'=>['frame'=>'frame','people'=>'people','user'=>'user'],
'extry'=>['frame'=>'frame','people'=>'people','user'=>'user'],
'imy'=>['frame'=>'frame','customer'=>'customer','people'=>'people','user'=>'user'],
'omy'=>['frame'=>'frame','supplier'=>'supplier','people'=>'people','user'=>'user'],
'bill'=>['frame'=>'frame','people'=>'people','user'=>'user'],
'allot'=>['frame'=>'frame','people'=>'people','user'=>'user'],
'ice'=>['frame'=>'frame','customer'=>'customer','people'=>'people','user'=>'user'],
'oce'=>['frame'=>'frame','supplier'=>'supplier','people'=>'people','user'=>'user'],
'summary'=>['warehouse'=>'warehouse'],
'room'=>['warehouse'=>'warehouse'],
'batch'=>['warehouse'=>'warehouse'],
'period'=>['user'=>'user']
];
$extend=[
'entry'=>['customer'=>[0]],
'extry'=>['supplier'=>[0]],
'ice'=>['customer'=>[0]],
'oce'=>['supplier'=>[0]]
];
$user = userInfo(getUserID());
if($user['role']!=0){
$role=db('role')->where([['id','=',$user['role']]])->find();
$auth=json_decode($role['auth'],true);
foreach ($tab[$model] as $tabKey => $tabVo) {
if(!in_array($tabKey,array_column($sql,0))){
$auth=getUserAuth($tabVo);
if($auth!='all'){
isset($extend[$model][$tabKey])&&$auth=array_merge($auth,$extend[$model][$tabKey]);
$sql[] = [$tabKey,'in',$auth];
}
}
}
}
return $sql;
}function getFields() {
$data=[];
$field = db('field')->select()->toArray();
foreach ($field as $fieldVo) {
$data[$fieldVo['key']] = json_decode($fieldVo['fields'],true);
}
return $data;
}function getUserRoot() {
$user=userInfo(getUserID());
if ($user['role'] == 0) {
return 'all';
} else {
$role = db('role')->where([['id','=',$user['role']]])->find();
$root = json_decode($role['root'],true);
foreach ($root as $rootVo) {
$data[$rootVo['module']] = $rootVo['data'];
}
return $data;
}
}function getFrameDeploy(){
$userFrame=userInfo(getUserID(),'frame');
$frame=db('frame')->where([['id','=',$userFrame]])->find();
$deploy=db('deploy')->where([['frame','=',$frame['id']]])->find();
while ($frame['pid']!=-1 && empty($deploy)){
$frame=db('frame')->where([['id','=',$frame['pid']]])->find();
$deploy=db('deploy')->where([['frame','=',$frame['id']]])->find();
}
return empty($deploy)?null:json_decode($deploy['source'],true);
}
function getRootMemu() {
$root = getUserRoot();
if ($root == 'all') {
$menu= db('menu')->order('sort asc')->select()->toArray();
} else {
$menu = db('menu')->where([['root','<>','admin'],['id','>',0]])->order('sort asc')->select()->toArray();
foreach ($menu as $menuKey=>$menuVo) {
$voRoot=explode('|',$menuVo['root']);
$menu[$menuKey]['check']=(empty($menuVo['root']) || $menuVo['resource']=='#group' || (isset($root[$voRoot[0]][count($voRoot)==1?'see':$voRoot[1]])&&$root[$voRoot[0]][count($voRoot)==1?'see':$voRoot[1]]=='true'))?1:0;
}
foreach (search($menu)->where([['type','=',1],['check','=',1]])->select() as $menuVo) {
$pidData=search($menu)->where([['id','=',$menuVo['pid']],['check','=',false]],true)->find();
empty($pidData)||$menu[$pidData['rowKey']]['check']=-1;
}
$menu=search($menu)->where([['check','in',[1,-1]]])->select();
$group=search($menu)->where([['resource','=','#group']],true)->select();
foreach ($group as $menuVo) {
$tree = new \org\Tree();
$v=$tree::vTree($menu,$menuVo['id']);
if(empty($v)){
unset($menu[$menuVo['rowKey']]);
}else{
$find=search($v)->where([['resource','<>','#group']])->find();
if(empty($find)){
unset($menu[$menuVo['rowKey']]);
}
}
}
}
return $menu;
}