| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkPHP [ WE CAN DO IT JUST THINK ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: 流年 <liu21st@gmail.com>
- // +----------------------------------------------------------------------
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
- use PhpOffice\PhpSpreadsheet\Reader\Xls;
- use PhpOffice\PhpSpreadsheet\IOFactory;
- use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
- use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
- use PhpOffice\PhpSpreadsheet\Cell\DataType;
- use PhpOffice\PhpSpreadsheet\Style\Fill;
- use PhpOffice\PhpSpreadsheet\Style\Color;
- use PhpOffice\PhpSpreadsheet\Style\Alignment;
- use PhpOffice\PhpSpreadsheet\Style\Border;
- use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
- // 应用公共文件
- /**
- * 删除目录以及其下的文件
- * @param $directory
- * @return bool
- */
- function removeDir($directory)
- {
- if (false == is_dir($directory)) {
- return false;
- }
- $handle = opendir($directory);
- while (false !== ($file = readdir($handle))) {
- if ('.' != $file && '..' != $file) {
- is_dir("$directory/$file") ? removeDir("$directory/$file") : @unlink("$directory/$file");
- }
- }
- if (readdir($handle) == false) {
- closedir($handle);
- rmdir($directory);
- }
- return true;
- }
- function Kfid($uid)
- {
- return trim($uid, 'KF');
- }
- function kfUid($id)
- {
- return 'KF' . $id;
- }
- //数组转为健的数组
- function kftoKey($uidArray, $type = 0)
- {
- $return = [];
- foreach ($uidArray as $val) {
- if ($type == 0) {
- $return[$val] = 0;
- } elseif ($type == 1) {
- $return[$val] = [];
- } else {
- $return[$val] = $val;
- }
- }
- return $return;
- }
- //保留小数位数
- function floatPointDigit($data, $long = 2)
- {
- $long = intval($long);
- $for1 = "%." . $long . "f";
- $for2 = "%." . ($long + 1) . "f";
- return sprintf($for1, substr(sprintf($for2, $data), 0, -1));
- }
- //秒格式化为 小时分秒
- function secendToHourMinit($sec)
- {
- $array = ['h' => 0, 'm' => 0, 's' => 0];
- $sec = intval($sec);
- $array['h'] = floor($sec / 3600);
- $array['m'] = floor(($sec - 3600 * $array['h']) / 60);
- $array['s'] = $sec - 3600 * $array['h'] - 60 * $array['m'];
- $return = '';
- if ($array['h']) {
- $return .= $array['h'] . '小时';
- }
- if ($array['m']) {
- $return .= $array['m'] . '分';
- }
- if ($array['s']) {
- $return .= $array['s'] . '秒';
- }
- return $return;
- }
- //小数转百分比显示
- function perDisplay($dit, $xiaos = 2)
- {
- return floatPointDigit(floor(100 * $dit), $xiaos) . '%';
- }
- /**
- * 数据加密
- */
- function lock_url($txt, $key)
- {
- $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+";
- $nh = rand(0, 64);
- $ch = $chars[$nh];
- $mdKey = md5($key.$ch);
- $mdKey = substr($mdKey,$nh%8, $nh%8+7);
- $txt = base64_encode($txt);
- $tmp = '';
- $i = 0;
- $j = 0;
- $k = 0;
- for ($i=0; $i<strlen($txt); $i++) {
- $k = $k == strlen($mdKey) ? 0 : $k;
- $j = ($nh+strpos($chars,$txt[$i])+ord($mdKey[$k++]))%64;
- $tmp .= $chars[$j];
- }
- return urlencode($ch.$tmp);
- }
- /**
- * 数据解密
- */
- function unlock_url($txt, $key)
- {
- $txt = urldecode($txt);
- $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+";
- $ch = $txt[0];
- $nh = strpos($chars,$ch);
- $mdKey = md5($key.$ch);
- $mdKey = substr($mdKey,$nh%8, $nh%8+7);
- $txt = substr($txt,1);
- $tmp = '';
- $i = 0;
- $j = 0;
- $k = 0;
- for ($i=0; $i<strlen($txt); $i++) {
- $k = $k == strlen($mdKey) ? 0 : $k;
- $j = strpos($chars,$txt[$i])-$nh - ord($mdKey[$k++]);
- while ($j<0) $j+=64;
- $tmp .= $chars[$j];
- }
- return base64_decode($tmp);
- }
- /**
- * 接口调用
- *
- * @access public
- * @param mixed $url 接口地址
- * @param mixed $where $params参数
- * @param mixed $timeout 请求时效
- * @return String
- */
- function make_request($url, $params, $timeout=30)
- {
- set_time_limit(0);
- if (function_exists('curl_init') === true) {
- $ch = curl_init();
- $header = array(
- 'Accept-Language: zh-cn',
- 'Connection: Keep-Alive',
- 'Cache-Control: no-cache'
- );
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
- if ($timeout > 0) curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- $result = curl_exec($ch);
- $errno = curl_errno($ch);
- curl_close($ch);
- return $result;
- } else {
- $context = array(
- 'http' => array(
- 'method' => 'POST',
- 'header' => 'Content-type: application/x-www-form-urlencoded' . "\r\n" .
- 'Content-length: ' . strlen($params),
- 'content' => $params));
- if ($timeout > 0) $context['http']['timeout'] = $timeout;
- $contextid = stream_context_create($context);
- $sock = @fopen($url, 'r', false, $contextid);
- if ($sock) {
- $result = '';
- while (!feof($sock)) {
- $result .= fgets($sock, 8192);
- }
- fclose($sock);
- } else {
- return 'TimeOut';
- }
- }
- return $result;
- }//end make_request()
|