1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645 |
- <?php
- use app\common\model\Config;
- use tools\Qxsms;
- function check_mobile($phone){
- return preg_match("/1\d{10}$/",$phone);
- }
- function check_email($email){
- $pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
- return preg_match($pattern,$email);
- }
- function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=false) {
- 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.'...' : $slice;
- }
- function think_encrypt($data, $key = '', $expire = 0) {
- $key = md5(empty($key) ? config('app.encryption_key') : $key);
- $data = base64_encode($data);
- $x = 0;
- $len = strlen($data);
- $l = strlen($key);
- $char = '';
- for ($i = 0; $i < $len; $i++) {
- if ($x == $l) $x = 0;
- $char .= substr($key, $x, 1);
- $x++;
- }
- $str = sprintf('%010d', $expire ? $expire + time():0);
- for ($i = 0; $i < $len; $i++) {
- $str .= chr(ord(substr($data, $i, 1)) + (ord(substr($char, $i, 1)))%256);
- }
- return str_replace(array('+','/','='),array('-','_',''),base64_encode($str));
- }
- function think_decrypt($data, $key = ''){
- $key = md5(empty($key) ? config('app.encryption_key') : $key);
- $data = str_replace(array('-','_'),array('+','/'),$data);
- $mod4 = strlen($data) % 4;
- if ($mod4) {
- $data .= substr('====', $mod4);
- }
- $data = base64_decode($data);
- $expire = substr($data,0,10);
- $data = substr($data,10);
- if($expire > 0 && $expire < time()) {
- return '';
- }
- $x = 0;
- $len = strlen($data);
- $l = strlen($key);
- $char = $str = '';
- for ($i = 0; $i < $len; $i++) {
- if ($x == $l) $x = 0;
- $char .= substr($key, $x, 1);
- $x++;
- }
- for ($i = 0; $i < $len; $i++) {
- if (ord(substr($data, $i, 1))<ord(substr($char, $i, 1))) {
- $str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
- }else{
- $str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
- }
- }
- return base64_decode($str);
- }
- function get_birthday_sex_by_idcard($idcard){
- if(mb_strlen($idcard) != 18){
- return ['birthday'=>null,'gender'=>0];
- }
- $birthday = msubstr($idcard, 6, 8);
- $birthday = date('Y-m-d',strtotime($birthday));
- $gender = msubstr($idcard,16,1)%2;
- $gender = $gender?1:2;
- return ['birthday'=>$birthday,'gender'=>$gender];
- }
- function ajax_return_ok($data = array(),$msg = ''){
- $result['code'] = 0;
- $result['data'] = $data;
- $result['message'] = $msg ;
- header('Content-Type:application/json; charset=utf-8');
- if(version_compare(PHP_VERSION,'5.4.0','<')){
- exit(json_encode($result));
- }else{
- exit(json_encode($result,JSON_UNESCAPED_UNICODE));
- }
- }
- function ajax_return_error($msg = null,$code = 1){
- if ($msg == null){
- $msgDefault = config ( 'e_msg_default' );
- $result['msg'] = $msgDefault [$code];
- }else{
- $result['msg'] = $msg ;
- }
- $result['status'] = 0;
- $result['code'] = $code;
- header('Content-Type:application/json; charset=utf-8');
- if(version_compare(PHP_VERSION,'5.4.0','<')){
- exit(json_encode($result));
- }else{
- exit(json_encode($result,JSON_UNESCAPED_UNICODE));
- }
- }
- function aes_encrypt($data) {
- $key = config('app.encryption_key');
- $data = openssl_encrypt($data, 'aes-128-ecb', $key, OPENSSL_RAW_DATA);
- return base64_encode($data);
- }
- function aes_decrypt($data) {
- $key = config('app.encryption_key');
- $encrypted = base64_decode($data);
- return openssl_decrypt($encrypted, 'aes-128-ecb', $key, OPENSSL_RAW_DATA);
- }
- function line_to_hump($str){
- return preg_replace_callback('/(_[a-z])/', function ($match) {
- return ucfirst(trim($match[0], '_'));
- }, $str);
- }
- function hump_to_line($str){
- return preg_replace_callback('/([A-Z])/', function ($match) {
- return '_' . lcfirst($match[0]);
- }, $str);
- }
- function array_change_line_to_hump($arr){
- $tem = [];
- foreach ($arr as $k=>$v){
- if(is_array($v)){
- $tem[line_to_hump($k)] = array_change_line_to_hump($v);
- }else{
- $tem[line_to_hump($k)] = $v;
- }
- }
- return $tem;
- }
- function array_delete_char($arr,$field,$child = 'depAndJobDtos'){
- $tem = [];
- foreach ($arr as $k=>$v){
- unset($v[$field]);
- if(!empty($v[$child])){
- $v[$child] = array_delete_char($v[$child],$field);
- }
- $tem[$k] = $v;
- }
- return $tem;
- }
- function list_to_tree($list, $pid = 'pid', $child = '_child', $root = 0)
- {
- $tree = [];
- foreach($list as $k => $v){
- if($v[$pid] == $root){
- $children = list_to_tree($list, $pid, $child, $v['id']);
- if(!empty($v[$child])){
- $children = array_merge($children,$v[$child]);
- }
- $v[$child] = $children;
- $tree[] = $v;
- }
- }
- return $tree;
- }
- function get_unique_id($prefix=''){
- return $prefix.date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 12), 1))), 0, 8);
- }
- function get_unique_sn($prefix=''){
- return $prefix.date('YmdHis').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 12), 1))), 0, 6);
- }
- function sort_flow_json($flowJson,$nodeid='',&$result=[]){
- foreach ($flowJson as $k=>$v){
- if((!$nodeid && $v['type'] == 1) || $nodeid && $v['id'] == $nodeid){
- $result[] = $v;
- if(count($result) != count($flowJson)){
- sort_flow_json($flowJson,$v['nextId'],$result);
- break;
- }
- }
- }
- return $result;
- }
- function calculate_leave($start,$end,$type){
- $starts = explode(' ',$start);
- $ends = explode(' ',$end);
- $start = date('Ymd',strtotime($starts[0]));
- $stxt = $starts[1];
- $end = date('Ymd',strtotime($ends[0]));
- $etxt = $ends[1];
- if($start > $end){
- return 0;
- }
- $bxday = \think\Db::name('holiday')
- ->where('holiday',0)
- ->where('day','>=',date('Y-m-d',strtotime($starts[0])))
- ->where('day','<=',date('Y-m-d',strtotime($ends[0])))
- ->column('day');
- $bxday = $bxday?$bxday:[];
- $holiday = \think\Db::name('holiday')
- ->where('holiday',1)
- ->where('day','>=',date('Y-m-d',strtotime($starts[0])))
- ->where('day','<=',date('Y-m-d',strtotime($ends[0])))
- ->column('day');
- $holiday = $holiday?$holiday:[];
- $days = 0;
- $cday = (strtotime($end) - strtotime($start))/86400 + 1;
- for ($i=1;$i<=$cday;$i++){
- if($type == 1){
- $cur = strtotime($start) + ($i-1)*86400;
- $w = date('w',$cur);
- $itxt = date('Y-m-d',$cur);
- if(($w == 6 || $w == 0) && in_array($itxt,$bxday)){
- if($i == 1 && $stxt == '下午'){
- $days += 0.5;
- }else if($i == $cday && $etxt == '上午'){
- $days += 0.5;
- }else{
- $days++;
- }
- } else if($w >0 && $w < 6 && !in_array($itxt,$holiday)){
- if($i == 1&&$stxt == '下午'){
- $days += 0.5;
- } else if($i == $cday && $etxt == '上午'){
- $days += 0.5;
- }else{
- $days++;
- }
- }
- } else {
- $days++;
- }
- }
- return $days;
- }
- function calculate_money($money,$bl,$bl_type,$bl_extra,$free_bl){
- $gjjp = $money*$bl;
- if($bl_extra > 0){
- if($bl_type == 1){
- $gjjp += $money*$bl_extra;
- } else {
- $gjjp += $bl_extra;
- }
- }
- $gjjp = $gjjp*(1 - $free_bl);
- return round($gjjp,2);
- }
- function queue_later($delay,$data,$type = 0){
- $connector = strtolower(config('queue.connector'));
- try{
- if($type == 0){
- $job = "app\queue\OrderJob@cancel";
- $queue = "cancel";
- }else if($type == 1){
- $job = "app\queue\OrderJob@group";
- $queue = "group";
- }else{
- return false;
- }
- if($connector == 'redis'){
- \think\Queue::later($delay, $job, $data, $queue);
- return true;
- }else{
- $res = \think\Queue::later($delay, $job, $data, $queue);
- return $res?true:false;
- }
- }catch (Exception $e){
- trace($e->getMessage());
- }
- return false;
- }
- function queue_push($data,$type = 0,$delay = 0){
- try{
- if($type == 0){
- $job = "app\queue\Jobs@jpush";
- $queue = "jpush";
- }else if($type == 1){
- $job = "app\queue\Jobs@qxsms";
- $queue = "qxsms";
- }else if($type == 3){
- $job = "app\queue\Jobs@autoSend";
- $queue = "autoSend";
- }else{
- return false;
- }
- if($delay > 0){
- \think\Queue::later($delay, $job, $data, $queue);
- }else{
- \think\Queue::push($job, $data,$queue);
- }
- return true;
- }catch (Exception $e){
- trace('队列添加失败:'.$e->getMessage());
- return false;
- }
- }
- function send_verify_sms($mobile){
- \think\Db::startTrans();
- try{
- $curTime = time();
- $endTime = $curTime + 10*60;
- $code = mt_rand(100000,999999);
- $data = array(
- 'mobile' => $mobile,
- 'code' => $code,
- 'status' => 0,
- 'create_yyyymmdd' => date('Ymd',$curTime),
- 'create_time' => date('Y-m-d H:i:s',$curTime),
- 'end_time' => date('Y-m-d H:i:s',$endTime)
- );
- $ret = \think\Db::name('sms_record')->insertGetId($data);
- if (!$ret) {
- exception('短信记录失败');
- }
- $content = \app\common\util\AppMsg::getSmsMsg(\app\common\util\AppMsg::SMS_VERIFY,['code'=>$code]);
- $json = [
- 'orgId' => 0,
- 'mobiles' => [$mobile],
- 'msg' => $content,
- 'fromId' => 0,
- 'type' => 1
- ];
- $ret = queue_push(json_encode($json),1);
- if(!$ret){
- exception('添加短信队列失败');
- }
- \think\Db::commit();
- return true;
- }catch (Exception $e){
- trace('短信发送失败:'.$e->getMessage());
- trace('短信发送号码:'.$mobile);
- \think\Db::rollback();
- return false;
- }
- }
- function verify_sms($mobile,$code){
- if(!$code){
- return false;
- }
- $curTime = date('Y-m-d H:i:s');
- $info = \think\Db::name('sms_record')
- ->where('code',$code)
- ->where('mobile',$mobile)
- ->where('status',0)
- ->where('end_time','>=',$curTime)
- ->find();
- if(!$info){
- return false;
- }
- \think\Db::name('sms_record')->where('id',$info['id'])->setField('status',1);
- return true;
- }
- function send_sms($mobiles,$msg='',$orgId=0,$fromId=0){
- if(!$mobiles){
- return true;
- }
- try{
- $json = [
- 'orgId' => $orgId,
- 'mobiles' => $mobiles,
- 'msg' => $msg,
- 'fromId' => $fromId,
- 'type' => 2
- ];
- $ret = queue_push(json_encode($json),1);
- if(!$ret){
- exception('添加短信队列失败');
- }
- return true;
- }catch (Exception $e){
- trace('短信添加失败:'.$e->getMessage());
- trace('短信添加号码:'.implode(',',$mobiles));
- \think\Db::rollback();
- return false;
- }
- }
- function send_jpush($userids,$type,$msg='',$extras=array()){
- if(!$userids){
- return true;
- }
- try {
-
- $json = [
- 'users' => $userids,
- 'type' => $type,
- 'msg' => $msg,
- 'extra' => $extras
- ];
- $ret = queue_push(json_encode($json),0);
- if(!$ret){
- exception('添加推送队列失败');
- }
- return true;
- } catch (Exception $e) {
- trace('push-error:'.$e->getMessage().':'.json_encode($json));
- return false;
- }
- }
- function calculate_age($date){
- list($year,$month,$day) = explode("-",$date);
- $year_diff = date("Y") - $year;
- $month_diff = date("m") - $month;
- $day_diff = date("d") - $day;
- if ($day_diff < 0 || $month_diff < 0)
- $year_diff--;
- return $year_diff;
- }
- function check_exp_imp($data){
- if(!$data){
- return '';
- }
- $vals = explode(',',$data);
- $nr = [];
- foreach ($vals as $v){
- if($v && !in_array($v,$nr)){
- $nr[] = $v;
- }
- }
- return empty($nr)?'':implode(',',$nr);
- }
- function check_wechat($wechat){
- return preg_match('/^[_a-zA-Z0-9]{5,19}+$/isu',$wechat);
- }
- function check_url($link){
- return preg_match("/http[s]?:\/\/[\w.]+[\w\/]*[\w.]*\??[\w=&\+\%]*/is", $link);
- }
- function data_auth_sign($data) {
-
- if(!is_array($data)){
- $data = (array)$data;
- }
- ksort($data);
- $code = http_build_query($data);
- $sign = sha1($code);
- return $sign;
- }
- function education($key){
- $arr = [
- '暂无',
- '初中及以下',
- '高中',
- '中专/中技',
- '大专',
- '本科',
- '硕士',
- '博士',
- ];
- return isset($arr[$key])?$arr[$key]:'暂无';
- }
- function politics($val){
- $arr = [
- '暂无',
- '中共党员',
- '中共预备党员',
- '共青团员',
- '民革会员',
- '民盟盟员',
- '民建会员',
- '民进会员',
- '农工党党员',
- '致公党党员',
- '九三学社社员',
- '台盟盟员',
- '无党派人士',
- '群众',
- ];
- return isset($arr[$val])?$arr[$val]:'暂无';
- }
- function widget_view($template,$data){
- return \think\facade\View::fetch($template,$data);
- }
- function widget($template,$data){
- return \think\facade\View::fetch($template,$data);
- }
- function create_token($userid){
-
- $token = decoct($userid).'9'.decoct(intval(time()));
- return $token;
- }
- function int_to_string(&$data,$map=array('status'=>array(1=>'正常',0=>'禁用'))) {
- if($data === false || $data === null ){
- return $data;
- }
- $data = (array)$data;
- foreach ($data as $key => $row){
- foreach ($map as $col=>$pair){
- if(isset($row[$col]) && isset($pair[$row[$col]])){
- $data[$key][$col.'_text'] = $pair[$row[$col]];
- }
- }
- }
- return $data;
- }
- function new_guid()
- {
- if (function_exists('com_create_guid')) {
- return com_create_guid();
- } else {
- mt_srand((double)microtime()*10000);
- $charid = strtoupper(md5(uniqid(rand(), true)));
- $hyphen = chr(45);
- $uuid = chr(123)
- .substr($charid, 0, 8).$hyphen
- .substr($charid, 8, 4).$hyphen
- .substr($charid, 12, 4).$hyphen
- .substr($charid, 16, 4).$hyphen
- .substr($charid, 20, 12)
- .chr(125);
- return $uuid;
- }
- }
- function get_qrcode_str($type,$id){
- $data = array(
- 'type' => (string)$type,
- 'id' => (int)$id,
- 'ucode' => config('app.ucode')
- );
- $strs = aes_encrypt(json_encode($data),config('app.encryption_key'));
- return str_ireplace('+','_',$strs);
- }
- function get_qrcode_arr($str){
- $str = str_ireplace('_','+',$str);
- $data = json_decode(aes_decrypt($str, config('app.encryption_key')),true);
- return $data ? $data : array();
- }
- function get_week_date(){
- $week = date('W');
- $time = strtotime(date('Y-m-d'));
- $arr = array();
- for ($i=6; $i>=0; $i--){
- $t = $time - $i*24*60*60;
- $w = date('W',$t);
- if($w == $week) {
- $arr[] = date('Ymd', $t);
- }
- }
- return $arr;
- }
- function getTime(){
- return date('Y-m-d H:i:s');
- }
- function getSite(){
- $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
- return $http_type.$_SERVER['HTTP_HOST'];
- }
- function check_val_empty($str){
- if (empty($str)) {
- return false;
- }
- return true;
- }
- function list_sort_by($list,$field, $sortby='asc') {
- if(is_array($list)){
- $refer = $resultSet = array();
- foreach ($list as $i => $data)
- $refer[$i] = &$data[$field];
- switch ($sortby) {
- case 'asc':
- asort($refer);
- break;
- case 'desc':
- arsort($refer);
- break;
- case 'nat':
- natcasesort($refer);
- break;
- }
- foreach ( $refer as $key=> $val)
- $resultSet[] = &$list[$key];
- return $resultSet;
- }
- return false;
- }
- function format_str($strs,$glup = ','){
- if(!$strs){
- return '';
- }
- $arr = explode($glup,$strs);
- $news = [];
- foreach ($arr as $k=>$v){
- if($v){
- $news[] = $v;
- }
- }
- return !empty($news)?implode($glup,$news):'';
- }
- function check_two_dispatch($userId){
- $is = 0;
- $roles = \think\Db::name('user_roles')
- ->alias('a')
- ->join('roles b','a.roles_id=b.id')
- ->where('a.user_id',$userId)
- ->field('b.level,b.parent_id')
- ->find();
- if($roles && $roles['level']==2 && $roles['parent_id']==9){
- $is = 1;
- }
- return $is;
- }
- function two_dispatch_off($orgId){
- $res = (new \app\common\model\Config())
- ->getConfig('org_two_dispatch',$orgId);
- return $res?(int)$res:0;
- }
- function check_is_dispatch($userId){
- $is = 0;
- $roles = \think\Db::name('user_roles')
- ->alias('a')
- ->join('roles b','a.roles_id=b.id')
- ->where('a.user_id',$userId)
- ->field('b.*')
- ->find();
- if($roles && $roles['parent_id']==9 && $roles['level']==1){
- $is = 1;
- }
- return $is;
- }
- function get_dispatch_auth($userId){
- $ids = [];
- $roles = \think\Db::name('user_roles')
- ->alias('a')
- ->join('roles b','a.roles_id=b.id')
- ->where('a.user_id',$userId)
- ->field('b.*')
- ->find();
- if($roles){
- $ids = $roles['work_type_mode']?explode(',',$roles['work_type_mode']):[];
- }
- return $ids;
- }
- function formatArray($array1,$array2,$type=0){
- if($type==0){
- foreach ($array2 as $k=>$v){
- if(!in_array($k,$array1)){
- unset($array2[$k]);
- }
- }
- }else{
- foreach ($array2 as $k=>$v){
- if(in_array($k,$array1)){
- unset($array2[$k]);
- }
- }
- }
- return $array2;
- }
- function get_one_month(){
- $time = strtotime(date('Y-m-d'));
- $arr = array();
- for ($i=29; $i>=0; $i--){
- $arr[] = date('Ymd',$time - $i*24*60*60);
- }
- return $arr;
- }
- function get_unique_id2 ($prefix='')
- {
- return $prefix . date ( 'Ymd' ) .
- substr ( implode ( NULL, array_map ( 'ord', str_split ( substr ( uniqid (), 7, 13 ), 1 ) ) ), 0, 6 );
- }
- function get_config($name){
- $info = \think\Db::name('config')->where('name',$name)->find();
- if($info){
- return config_parse($info['type'], $info['value']);
- }
- }
- function config_parse($type, $value){
- switch ($type) {
- case 3:
- $array = preg_split('/[,;\r\n]+/', trim($value, ",;\r\n"));
- if(strpos($value,':')){
- $value = array();
- foreach ($array as $val) {
- list($k, $v) = explode(':', $val);
- $value[$k] = $v;
- }
- }else{
- $value = $array;
- }
- break;
- }
- return $value;
- }
- function birthday($birthday){
- $age = strtotime($birthday);
- if($age === false){
- return false;
- }
- list($y1,$m1,$d1) = explode("-",date("Y-m-d",$age));
- $now = strtotime("now");
- list($y2,$m2,$d2) = explode("-",date("Y-m-d",$now));
- $age = $y2 - $y1;
- if((int)($m2.$d2) < (int)($m1.$d1))
- $age -= 1;
- return $age;
- }
- function diffBetweenTwoDays ($day1, $day2) {
- $second1 = strtotime($day1);
- $second2 = strtotime($day2);
- if ($second1 < $second2) {
- $tmp = $second2;
- $second2 = $second1;
- $second1 = $tmp;
- }
- return intval(($second1 - $second2) / 86400)+1;
- }
- function curl_post($url , $data=array(),$header=[]){
- $ch = curl_init();
- if(!empty($header)){
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- }
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
-
- curl_setopt($ch, CURLOPT_POST, 1);
-
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- $output = curl_exec($ch);
- curl_close($ch);
- return $output;
- }
- function nDate($time) {
- $tag = 'Y-m-d H:i:s';
- $a = substr($time, 0, 10);
- $b = substr($time, 10);
- $date = date($tag, $a - 28800);
- return $date;
- }
- function getDay($time){
- $days =date("t",$time);
- for ($i = 0;$i <intval($days);$i++)
- {
- $day[] =date('Ymd',strtotime("+" .$i." day",strtotime(date("Y-m-01",$time))));
- }
- return $day;
- }
- function get_month($time){
- $year = $time;
- $yeararr = [];
- for ($i=1; $i <=12 ; $i++) {
- $yeararr[$i] = [
- 'key'=>$year.'年'.$i.'月份',
- 'date'=>date('Ym',strtotime($year.'-'.$i))
- ];
- }
- return $yeararr;
- }
- function beginMonth($His = true)
- {
- $timestamp = mktime(0, 0, 0, date('m'), 1, date('Y'));
- return $His ? date('Y-m-d H:i:s', $timestamp) : date('Y-m-d', $timestamp);
- }
- function endMonth($His = true)
- {
- $timestamp = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
- return $His ? date('Y-m-d H:i:s', $timestamp) : date('Y-m-d', $timestamp);
- }
- function beginYear($His = true)
- {
- $timestamp = mktime(0, 0, 0, 1, 1, date('Y'));
- return $His ? date('Y-m-d H:i:s', $timestamp) : date('Y-m-d', $timestamp);
- }
- function endYear($His = true)
- {
- $timestamp = mktime(23, 59, 59, 12, 31, date('Y'));
- return $His ? date('Y-m-d H:i:s', $timestamp) : date('Y-m-d', $timestamp);
- }
- function create_qrcode($value,$filepath)
- {
- include_once env('root_path').'/extend/phpqrcode/phpqrcode.php';
- if (empty($value)) {
- return false;
- }
- $dirfile = dirname($filepath);
- if(!file_exists($dirfile)){
- @mkdir($dirfile,0777);
- }
-
- $dir = getcwd().DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'qrcodeimg'.DIRECTORY_SEPARATOR;
- if (!file_exists($dir)) {
- @mkdir($dir);
- }
-
- $QRprefix = $dir.DIRECTORY_SEPARATOR.substr(md5($value), 8, 16);
- $QRTemp = $QRprefix.'_temp.png';
-
- if (file_exists($QRTemp)) {
- @unlink($QRTemp);
- }
- $errorCorrectionLevel = 'H';
- $matrixPointSize = 6;
-
- QRcode::png(
- $value,
- $QRTemp,
- $errorCorrectionLevel,
- $matrixPointSize,
- 2
- );
- $orgId = cur_org_id();
- if($orgId == 17){
- $logo = env('root_path').'/public/hb.png';
- }else{
- $logo = env('root_path').'/public/logo.png';
- }
- if (!empty($logo)) {
- $QRBuffer = add_logo_2qrcode($QRTemp, $logo);
- } else {
- $QRBuffer = imagecreatefromstring(print_72dip_300dip(file_get_contents($QRTemp)));
- }
-
- if (file_exists($QRTemp)) {
- @unlink($QRTemp);
- }
- imagejpeg($QRBuffer,$filepath,100);
- ImageDestroy($QRBuffer);
- }
- function add_logo_2qrcode($QRTempPath, $logoPath)
- {
- $QRBuffer = imagecreatefromstring(print_72dip_300dip(file_get_contents($QRTempPath)));
- $logo = imagecreatefromstring(print_72dip_300dip(file_get_contents($logoPath)));
- $QR_width = imagesx($QRBuffer);
- $QR_height = imagesy($QRBuffer);
- $logo_width = imagesx($logo);
- $logo_height = imagesy($logo);
- $logo_qr_width = $QR_width / 5;
- $scale = $logo_width/$logo_qr_width;
- $logo_qr_height = $logo_height/$scale;
- $from_width = ($QR_width - $logo_qr_width) / 2;
-
- imagecopyresampled(
- $QRBuffer,
- $logo,
- $from_width,
- $from_width,
- 0,
- 0,
- $logo_qr_width,
- $logo_qr_height,
- $logo_width,
- $logo_height
- );
- return $QRBuffer;
- }
- function print_72dip_300dip($QRBufferStr)
- {
-
- $len = pack("N", 9);
-
- $sign = pack("A*", "pHYs");
-
- $data = pack("NNC", 300 * 39.37, 300 * 39.37, 0x01);
-
- $checksum = pack("N", crc32($sign . $data));
- $phys = $len . $sign . $data . $checksum;
- $pos = strpos($QRBufferStr, "pHYs");
- if ($pos > 0) {
-
- $QRBufferStr = substr_replace($QRBufferStr, $phys, $pos - 4, 21);
- } else {
-
- $pos = 33;
-
- $QRBufferStr = substr_replace($QRBufferStr, $phys, $pos, 0);
- }
- return $QRBufferStr;
- }
- function add_file_to_zip($path,$zip){
- $handler=opendir($path);
- while(($filename=readdir($handler))!==false){
- if($filename != "." && $filename != ".."){
- if(is_dir($path."/".$filename)){
- add_file_to_zip($path."/".$filename, $zip);
- }else{
- $pp = $path."/".$filename;
- $pps = explode('//',$pp);
- $zip->addFile($pp,$pps[1]);
- }
- }
- }
- @closedir($path);
- }
- function deldir($path){
-
- if(is_dir($path)){
-
- $p = scandir($path);
- foreach($p as $val){
-
- if($val !="." && $val !=".."){
-
- if(is_dir($path.$val)){
-
- deldir($path.$val.'/');
-
- @rmdir($path.$val.'/');
- }else{
-
- @unlink($path.$val);
- }
- }
- }
- @rmdir($path);
- }
- }
- function btnAuth($userId,$delUrl){
- if(is_admin($userId)){
- return true;
- }
- $roles = \think\Db::name('user_roles')
- ->alias('a')
- ->join('roles b','a.roles_id=b.id')
- ->where('a.user_id',$userId)
- ->field('b.*')
- ->find();
- if(!empty($roles)){
- $authS = $roles['auths']?explode(',',$roles['auths']):[];
- if($roles['org_id'] > 0){
- $orgauths = \think\Db::name('org')->where('id',$roles['org_id'])->value('auths');
- $orgauths = $orgauths?explode(',',$orgauths):[];
- $authS = array_intersect($authS,$orgauths);
- }
- $menu = \think\Db::name('menu')
- ->where('url',$delUrl)
- ->where('enable',1)
- ->where('del',0)
- ->find();
- if(!empty($menu) && in_array($menu['id'],$authS)){
- return true;
- }
- }
- return false;
- }
- function arraySequence($array, $field, $sort = 'SORT_ASC') {
- $arrSort = array();
- foreach ($array as $uniqid =>$row) {
- foreach ($row as $key =>$value) {
- $arrSort[$key][$uniqid] = $value;
- }
- }
- array_multisort($arrSort[$field], constant($sort), $array);
- return $array;
- }
- function getM1($do,$cof){
- $diff = strtotime($do) - strtotime($cof);
- $days = floor(($diff )/ (60*60*24));
- $hours = floor(($diff - $days*60*60*24) / (60*60));
- $minutes = floor(($diff - $days*60*60*24 - $hours*60*60)/ 60);
- $seconds = floor(($diff - $days*60*60*24 - $hours*60*60 - $minutes*60));
- if ($diff < 60) {
- $time_cost = $seconds."秒";
- } else if ($diff >= 60 && $diff < 60*60) {
- $time_cost = $minutes."分钟".$seconds."秒";
- } else if ($diff >= 60*60 && $diff < 60*60*24) {
- $time_cost = $hours."小时".$minutes."分钟".$seconds."秒";
- } else {
- $time_cost = $days."天".$hours."小时".$minutes."分钟".$seconds."秒";
- }
- return $time_cost;
- }
- function getOrgGrabOrder($userId,$orgId){
- $rolesId = \think\Db::name('user_roles')
- ->where('user_id', $userId)
- ->value('roles_id');
- $rolesInfo = \think\Db::name('roles')
- ->where('id', $rolesId)
- ->find();
- if ($rolesInfo['parent_id'] > 0) {
- $rolesId = $rolesInfo['parent_id'];
- }
- $workType = \think\Db::name('work_type_mode')
- ->where('type', 1)
- ->where('roles', 'like', '%' . $rolesId . '%')
- ->column('id');
- $is = 0;
- if(empty($workType)){
- return $is;
- }
- foreach ($workType as $k=>$v){
- $orgGrabOrder = (new Config())->getConfig('org_grab_order'.$v,$orgId);
- if($orgGrabOrder && $orgGrabOrder>0){
- $is = 1;
- }
- }
- return $is;
- }
- function monthlater($type=0){
- $str = array();
- for($i=0;$i<12;$i++){
- if($type == 0){
- $str[$i] =date('Y-m',strtotime('-'.$i.'month'));
- }else{
- $str[$i] =date('Y-m',strtotime('-1month-'.$i.'month'));
- }
- }
- sort($str);
- return $str;
- }
- function get_sort_user($orgId,$work=-1,$type_id=-1){
- $rolesId = \think\Db::name('roles')
- ->where('parent_id',7)
- ->where('org_id',$orgId)
- ->where('del',0)
- ->column('id');
- $userRolesId = \think\Db::name('user_roles')
- ->where('roles_id','in',$rolesId)
- ->column('user_id');
- $map[] = ['u.id','in',$userRolesId];
- $map[] = ['u.del','=',0];
- $map[] = ['u.type','=',0];
- $map[] = ['u.enable','=',1];
- $map[] = ['u.enable_sorts','=',1];
- $map[] = ['uo.org_id','=',$orgId];
- if($work >0){
- $map[] = ['u.work','=',$work];
- }
- if($type_id >0){
- $map[] = ['u.type_id','=',$type_id];
- }
- $map= empty($map) ? true: $map;
- $lists = \think\Db::name('user')
- ->alias('u')
- ->join('user_org uo','u.id=uo.user_id')
- ->where($map)
- ->field('u.id,uo.org_id')
- ->order(['u.sorts'=>'desc','u.id'=>'asc'])
- ->column('u.id');
- return $lists;
- }
- function get_sort_user_list($orgId,$work=-1){
- $rolesId = \think\Db::name('roles')
- ->where('parent_id',7)
- ->where('org_id',$orgId)
- ->where('del',0)
- ->column('id');
- $userRolesId = \think\Db::name('user_roles')
- ->where('roles_id','in',$rolesId)
- ->column('user_id');
- $map[] = ['u.id','in',$userRolesId];
- $map[] = ['u.del','=',0];
- $map[] = ['u.type','=',0];
- $map[] = ['u.enable','=',1];
- $map[] = ['u.enable_sorts','=',1];
- $map[] = ['uo.org_id','=',$orgId];
- if($work >0){
- $map[] = ['u.work','=',$work];
- }
- $map= empty($map) ? true: $map;
- $lists = \think\Db::name('user')
- ->alias('u')
- ->join('user_org uo','u.id=uo.user_id')
- ->where($map)
- ->field('u.id,uo.org_id,u.sorts')
- ->order(['u.sorts'=>'desc','u.id'=>'asc'])
- ->select();
- return $lists;
- }
- function getDateFromRange($startdate, $enddate){
- $stimestamp = strtotime($startdate);
- $etimestamp = strtotime($enddate);
-
- $days = ($etimestamp-$stimestamp)/86400+1;
-
- $date = array();
- for($i=0; $i<$days; $i++){
- $date[] = date('Y-m-d', $stimestamp+(86400*$i));
- }
- return $date;
- }
- function encodecookie($name,$val,$expire=100*365*24*60*60){
- cookie($name,think_encrypt($val),$expire);
- }
- function decodecookie($name){
- return think_decrypt(cookie($name));
- }
- function get_pay_wechat($orgId){
- $wechat = \think\Db::name('dinner_wechat')->where('org_id',$orgId)->order('id','desc')->find();
- if(!$wechat){
- return [];
- }
- $option = [
- 'user_type' => '3'.$wechat['id'],
- 'app_id' => trim($wechat['app_id']),
- 'secret' => trim($wechat['secret']),
- 'mch_id' => trim($wechat['mch_id']),
- 'key' => trim($wechat['key']),
-
- 'cert_path' => env('root_path').'public'.$wechat['cert_path'],
- 'key_path' => env('root_path').'public'.$wechat['key_path'],
-
-
- 'response_type' => 'array',
- 'log' => [
- 'level' => 'error',
- 'file' => env('runtime_path').'/log/wechat.log',
- ],
- ];
- return $option;
- }
- function get_week_days($index = 0,$format="Y-m-d"){
- $week = date('w') == 0 ? 7 : date('w');
- $start = strtotime('today ' . (- ($week - 1) + (7 * $index)) . 'day');
- $end = strtotime('today ' . ((8 - $week) + (7 * $index)) . 'day -1second');
- return [date($format,$start), date($format,$end)];
- }
- function get_week_txt($day){
- $da = date("w",strtotime($day));
- if( $da == "1" ){
- return '周一';
- }else if( $da == "2" ){
- return '周二';
- }else if( $da == "3" ){
- return '周三';
- }else if( $da == "4" ){
- return '周四';
- }else if( $da == "5" ){
- return '周五';
- }else if( $da == "6" ){
- return '周六';
- }else if( $da == "0" ){
- return '周日';
- }
- return '';
- }
- function gtspdb($name = ''){
- $config = config('database.db_config_gt_sp');
- return \db($name,$config,false);
- }
- function bjydb($name = ''){
- $config = config('database.db_config_bjy');
- return \db($name,$config,false);
- }
- function xcydb($name = ''){
- $config = config('database.db_config_xcy');
- return \db($name,$config,false);
- }
- function second_to_str($diff){
- if($diff <= 0){
- return '0秒';
- }
- $days = floor(($diff )/ (60*60*24));
- $hours = floor(($diff - $days*60*60*24) / (60*60));
- $minutes = floor(($diff - $days*60*60*24 - $hours*60*60)/ 60);
- $seconds = floor(($diff - $days*60*60*24 - $hours*60*60 - $minutes*60));
- if ($diff < 60) {
- $time_cost = $seconds."秒";
- } else if ($diff >= 60 && $diff < 60*60) {
- $time_cost = $minutes."分钟".$seconds."秒";
- } else if ($diff >= 60*60 && $diff < 60*60*24) {
- $time_cost = $hours."小时".$minutes."分钟".$seconds."秒";
- } else {
- $time_cost = $days."天".$hours."小时".$minutes."分钟".$seconds."秒";
- }
- return $time_cost;
- }
- function getMinFromRange($startdate, $enddate){
- $stimestamp = strtotime($startdate);
- $etimestamp = strtotime($enddate);
-
- $days = ($etimestamp-$stimestamp)/3600;
-
- $date = array();
- for($i=0; $i<=$days; $i++){
- $date[] = date('Y-m-d H:i:s', $stimestamp+(3600*$i));
- }
- return $date;
- }
|