123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650 |
- <?php
- mb_internal_encoding("UTF-8");
- 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, 13), 1))), 0, 8);
- }
- function get_rand_num(){
- return mt_rand(100000000,999999999);
- }
- 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 get_contact_sn($pre,$type=0,$applyId=0){
- return get_unique_id($pre);
- }
- function calculate_leave($start,$end,$type){
- $starts = explode(' ',$start);
- $ends = explode(' ',$end);
- $start = date('Ymd',strtotime($starts[0]));
- $stxt = $starts[count($starts) - 1];
- $end = date('Ymd',strtotime($ends[0]));
- $etxt = $ends[count($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($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 send_jpush($userids,$msg='',$extras=array()){
- try {
- $jpushconfig = config('app.jpush');
- $client = new \JPush\Client($jpushconfig['appkey'], $jpushconfig['mastersecret'],null);
- $push = $client->push();
- $push->setOptions(null,null,null, true);
- $push->setPlatform(array('ios', 'android'));
- foreach ($userids as $k=>$v){
- $userids[$k] = (string)$v;
- }
- $push->addAlias($userids);
- $push->androidNotification($msg, array(
- 'extras' => $extras
- ));
- $sound = 'default';
- $push->iosNotification($msg, array(
- 'sound' => $sound,
- 'badge' => '+1',
- 'extras' => $extras
- ));
- $ret = $push->send();
- trace($ret);
- } catch (Exception $e) {
- trace('push-error:',$e->getMessage());
- }
- }
- 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($month_diff > 0){
- return $year_diff;
- }else if($month_diff == 0){
- if($day_diff >= 0){
- return $year_diff;
- }else{
- return $year_diff - 1;
- }
- }else{
- return $year_diff - 1;
- }
- }
- 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 curl_post($url, $data=[]) {
- try{
- $ch = curl_init ();
- $header = array ("Accept-Charset: utf-8",'Expect:' );
- curl_setopt ( $ch, CURLOPT_URL, $url );
- curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
- curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
- curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
- curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header );
- curl_setopt ( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)' );
- curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
- curl_setopt ( $ch, CURLOPT_AUTOREFERER, 1 );
- curl_setopt ( $ch, CURLOPT_TIMEOUT, 10 );
-
- if($data){
- curl_setopt ( $ch, CURLOPT_POSTFIELDS, http_build_query ( $data ) );
- }
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
- $result = curl_exec ( $ch );
- curl_close ( $ch );
- return $result;
- }catch (Exception $e){
- return false;
- }
- }
- function is_utf8($string) {
-
- return preg_match('%^(?:
- [\x09\x0A\x0D\x20-\x7E] # ASCII
- | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
- | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
- | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
- | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
- | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
- | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
- | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
- )*$%xs', $string);
- }
- function get_dinner_day(){
- $week = date('w');
- $day = date('Y-m-d',time() + 24*60*60);
- if($week == 5){
- $day = date('Y-m-d',time() + 3*24*60*60);
- }else if($week == 6){
- $day = date('Y-m-d',time() + 2*24*60*60);
- }
- return $day;
- }
- function get_lastmonth_by_day($day){
- $year = date('Y',strtotime($day));
- $month = date('m',strtotime($day));
- if($month == 1){
- $lastmonth = ($year-1).'-12';
- }else if($month <= 10){
- $lastmonth = $year.'-0'.($month-1);
- }else{
- $lastmonth = $year.'-'.($month-1);
- }
- return $lastmonth;
- }
- function get_attentance_srecord($records,$val){
- $sarr = [];
- $ids = [];
- foreach ($records as $k => $v){
- $ct = strtotime($v['create_time']);
- $st = strtotime($val['stime']);
- $et = strtotime($val['etime']);
- if($ct < $et && $ct > $st){
- $v['cate'] = 1;
- $v['status'] = 1;
- $sarr[] = $v;
- $ids[] = $k;
- break;
- }else if($ct <= $st){
- $v['cate'] = 1;
- $v['status'] = 0;
- $sarr[] = $v;
- $ids[] = $k;
- break;
- }else if($ct >= $et){
- }
- }
- $lastrecords = [];
- foreach ($records as $k=>$v){
- if(!in_array($k,$ids)){
- $lastrecords[] = $v;
- }
- }
- return ['arr' => $sarr,'record' => $lastrecords];
- }
- function get_attentance_erecord($records,$val,$nstart=''){
- $sarr = [];
- $ids = [];
- foreach ($records as $k => $v){
- if(!$nstart){
- $ct = strtotime($v['create_time']);
- $et = strtotime($val['etime']);
- $v['cate'] = 2;
- if($ct < $et){
- $v['status'] = 2;
- }else if($ct >= $et){
- $v['status'] = 0;
- }
- $sarr[] = $v;
- $ids[] = $k;
- }else{
- $ct = strtotime($v['create_time']);
- $et = strtotime($val['etime']);
- $nst = strtotime($nstart);
- $v['cate'] = 2;
- $v['status'] = 0;
- if($ct < $et){
- $v['status'] = 2;
- $sarr[] = $v;
- $ids[] = $k;
- }else if($ct >= $et && $ct < $nst){
- $v['status'] = 0;
- $sarr[] = $v;
- $ids[] = $k;
- break;
- }
- }
- }
- $lastrecords = [];
- foreach ($records as $k=>$v){
- if(!in_array($k,$ids)){
- $lastrecords[] = $v;
- }
- }
- return ['arr' => $sarr,'record' => $lastrecords];
- }
|