<?php<liu21st@gmail.com>
function p($var) {
if (is_bool($var)) {
var_dump($var);
} elseif (is_null($var)) {
var_dump(NULL);
} else {
echo "<pre style='position:relative;z-index:1000;padding:10px;border-radius:5px;background:#F5F5F5;border:1px solid #aaa;font-size:14px;line-height:18px;opacity:0.9;'>" . print_r($var, true) . "</pre>";
}
}
define("PBKDF2_HASH_ALGORITHM", "sha256");define("PBKDF2_ITERATIONS", 1000);define("PBKDF2_SALT_BYTE_SIZE", 24);define("PBKDF2_HASH_BYTE_SIZE", 24);
define("HASH_SECTIONS", 4);
define("HASH_ALGORITHM_INDEX", 0);
define("HASH_ITERATION_INDEX", 1);
define("HASH_SALT_INDEX", 2);
define("HASH_PBKDF2_INDEX", 3);
function create_hash($password)
{
$salt = base64_encode(mcrypt_create_iv(PBKDF2_SALT_BYTE_SIZE, MCRYPT_DEV_URANDOM));
return PBKDF2_HASH_ALGORITHM . ":" . PBKDF2_ITERATIONS . ":" . $salt . ":" .
base64_encode(pbkdf2(
PBKDF2_HASH_ALGORITHM,
$password,
$salt,
PBKDF2_ITERATIONS,
PBKDF2_HASH_BYTE_SIZE,
true
));
}
function validate_password($password, $correct_hash)
{
$params = explode(":", $correct_hash);
if (count($params) < HASH_SECTIONS) {
return false;
}
$pbkdf2 = base64_decode($params[HASH_PBKDF2_INDEX]);
return slow_equals(
$pbkdf2,
pbkdf2(
$params[HASH_ALGORITHM_INDEX],
$password,
$params[HASH_SALT_INDEX],
(int)$params[HASH_ITERATION_INDEX],
strlen($pbkdf2),
true
)
);
}
function slow_equals($a, $b)
{
$diff = strlen($a) ^ strlen($b);
for($i = 0; $i < strlen($a) && $i < strlen($b); $i++)
{
$diff |= ord($a[$i]) ^ ord($b[$i]);
}
return $diff === 0;
}
function pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output = false)
{
$algorithm = strtolower($algorithm);
if(!in_array($algorithm, hash_algos(), true))
trigger_error('PBKDF2 ERROR: Invalid hash algorithm.', E_USER_ERROR);
if($count <= 0 || $key_length <= 0)
trigger_error('PBKDF2 ERROR: Invalid parameters.', E_USER_ERROR);
if (function_exists("hash_pbkdf2")) {
if (!$raw_output) {
$key_length = $key_length * 2;
}
return hash_pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output);
}
$hash_length = strlen(hash($algorithm, "", true));
$block_count = ceil($key_length / $hash_length);
$output = "";
for($i = 1; $i <= $block_count; $i++) {
$last = $salt . pack("N", $i);
$last = $xorsum = hash_hmac($algorithm, $last, $password, true);
for ($j = 1; $j < $count; $j++) {
$xorsum ^= ($last = hash_hmac($algorithm, $last, $password, true));
}
$output .= $xorsum;
}
if($raw_output) {
return substr($output, 0, $key_length);
} else {
return bin2hex(substr($output, 0, $key_length));
}
}
if (!function_exists('StrOrderOne'))
{
function StrOrderOne() {
$y = '2015';
$upper = array('1'=>'01','2'=>'02','3'=>'03','4'=>'04','5'=>'05','6'=>'06');
$unde = array('1'=>'07','2'=>'08','3'=>'09','4'=>'10','5'=>'11','6'=>'12');
$date_y = date('Y') - $y;
if ($date_y <= 0) {
$yea = '1';
} else {
$yea = $date_y + 1;
}
$date_m = date('m');
$date_d = date('d');
if ($date_m <= '06') {
$half = '5'; $key = array_search($date_m, $upper); } else {
$half = '6'; $key = array_search($date_m, $unde); }
$arr = NoRand(0,9,4);
$orders = '100' + $yea . $half . $key . $date_d . implode('',$arr);
return $orders;
}
}
function StrOrderOne2() {
$date = date('Ymd');
$arr = NoRand(0,9,3);
$orders = $date . implode('',$arr);
$result = \think\Db::name('purchase')->where('pnumber',$orders)->find();
if ($result) {
StrOrderOne2();
}
return $orders;
}
if (! function_exists('NoRand')) {
function NoRand($begin=1, $end=9, $limit=4) {
$rand_array = range($begin,$end);
shuffle($rand_array); return array_slice($rand_array,0,$limit); }
}
function Setting_Config(){
$query = new \think\db\Query();
$config = $query->table('syc_config')->field('name,value')->select();
$_fp = @fopen(APP_PATH.'Setting.php','w') or die ("Unable to open file!"); flock($_fp, LOCK_EX); fwrite($_fp, "<"."?php\r\n");
fwrite($_fp, fwrite($_fp,"return array(\r\n");
$result = array_change_key_case($config,CASE_LOWER) foreach ($result AS $k => $v){
$_string = " '$v[name]' => '$v[value]',\r\n"; fwrite($_fp, $_string, strlen($_string)); }
fwrite($_fp, ");"); flock($_fp, LOCK_UN);
fclose($_fp);}
if (!function_exists('AddSubDay'))
{
function AddSubDay($ntime, $aday) {
$dayst = 3600 * 24;
$oktime = $ntime + ($aday * $dayst);
return $oktime;
}
}
if (!function_exists('ExecTime'))
{
function ExecTime() {
$time = explode(" ", microtime());
$usec = (double)$time[0];
$sec = (double)$time[1];
return $sec + $usec;
}
}
function authCheck($rule, $uid, $true, $false='没有权限') {
if( in_array(intval($uid), Config('AUTH_ADMINISTRATOR_ID'))){
return $true; } else {
$Auth = new \Org\Auth();
return $Auth->check($rule, $uid) ? $true : $false;
}
}
function IS_ROOT($item=array()) {
$arr = is_array($item) ? $item : '';
$id = \think\Session::get('user_auth');
if (empty($arr)) {
return false;
} else {
$result = in_array($id, $arr);
if ($result == true) {
return true;
} else {
return false;
}
}
}
function getAuthGroupTree($data){
$items = array();
$tree = array();
foreach ($data as $val) {
$items[$val['id']] = $val;
}
foreach($items as $val){
if(isset($items[$val['user_auth']])){
$items[$val['user_auth']]['son'][] = &$items[$val['id']];
}else{
$tree[] = &$items[$val['id']];
}
}
p($tree);
}
if (!function_exists('get_numeric')) {
function get_numeric($val) {
if (is_numeric($val)) {
return sprintf("%.2f",$val + 0);
}
return 0;
}
}
if (!function_exists('filterOrders')) {
function filterOrders($val) {
preg_match_all('/[\x{4e00}-\x{9fa5}a-zA-Z0-9.-]/u',$val,$item);
return join('',$item[0]);
}
}
function filter_mount($val) {
preg_match_all('/[0-9.]/u',$val,$item);
return join('',$item[0]);
}
function filter_numbers($val) {
preg_match_all('/[0-9]/u',$val,$item);
return join('',$item[0]);
}
function CountDownDays($exec) {
$time = date('Y-m-d'); $date = (strtotime($exec) - strtotime($time)) / (60 * 60 * 24); $tian='发货';
switch (true)
{
case $date == 1:
$item = '明天'.$tian;
break;
case $date == 2:
$item = '后天'.$tian;
break;
case $date >= 3:
$item = '还有'.$date.'天'.$tian;
break;
case $date == 7:
$item = '还有'.$date.'天'.$tian;
break;
case $date < 0:
$item = '<code>已超期'.filter_numbers($date).'天</code>';
break;
default :
$item = '今天正好'.$tian;
break;
}
return $item;
}
function Shengchanzq($pstart, $pend) {
$date = (strtotime($pend) - strtotime($pstart)) / (60 * 60 * 24); return $date.'天';
}
function purchase_status($value, $list='list') {
if ('list' == $list) {
switch ($value)
{
case -1:
$item = '<span class="label label-sm status-n">已废除</span>';
break;
case 0:
$item = '<span class="label label-sm status-0">审核中</span>';
break;
case 1:
$item = '<span class="label label-sm status-1">已收订</span>';
break;
case 2:
$item = '<span class="label label-sm status-2">生产中</span>';
break;
case 3:
$item = '<span class="label label-sm status-3">生产完</span>';
break;
case 4:
$item = '<span class="label label-sm status-4">待出库</span>';
break;
case 5:
$item = '<span class="label label-sm status-5">已出库</span>';
break;
default:
$item = '<span class="label label-sm status-6"> 其 他 </span>';
break;
}
} else {
switch ($value)
{
case -1:
$item = '已废除';
break;
case 0:
$item = '审核中';
break;
case 1:
$item = '已收订';
break;
case 2:
$item = '生产中';
break;
case 3:
$item = '生产完';
break;
case 4:
$item = '待出库';
break;
case 5:
$item = '已出库';
break;
default:
$item = ' 其 他 ';
break;
}
}
return $item;
}
function isInteger($input){
return(ctype_digit(strval($input)));
}
function cutstr_html($string){
$str = trim($string); $str = preg_replace("/\t/","",$str); $str = preg_replace("/\r\n/","",$str);
$str = preg_replace("/\r/","",$str);
$str = preg_replace("/\n/","",$str);
$str = preg_replace("/《/","",$str);
$str = preg_replace("/》/","",$str);
$str = preg_replace("/</","",$str);
$str = preg_replace("/>/","",$str);
$str = preg_replace ('/ /is', '', $str);;
$str = preg_replace("/ /","",$str); $str = preg_replace("/ /","",$str); $str = preg_replace("/(s*?r?ns*?)+/","n",$str); $str = preg_replace('/($s*$)|(^s*^)/m', '',$str); return trim($str);}
function strFilter($str){
$str = str_replace('`', '', $str);
$str = str_replace('·', '', $str);
$str = str_replace('~', '', $str);
$str = str_replace('!', '', $str);
$str = str_replace('!', '', $str);
$str = str_replace('@', '', $str);
$str = str_replace('#', '', $str);
$str = str_replace('$', '', $str);
$str = str_replace('¥', '', $str);
$str = str_replace('%', '', $str);
$str = str_replace('^', '', $str);
$str = str_replace('……', '', $str);
$str = str_replace('&', '', $str);
$str = str_replace('*', '', $str);
$str = str_replace('(', '', $str);
$str = str_replace(')', '', $str);
$str = str_replace('(', '', $str);
$str = str_replace(')', '', $str);
$str = str_replace('-', '', $str);
$str = str_replace('_', '', $str);
$str = str_replace('——', '', $str);
$str = str_replace('+', '', $str);
$str = str_replace('=', '', $str);
$str = str_replace('|', '', $str);
$str = str_replace('\\', '', $str);
$str = str_replace('[', '', $str);
$str = str_replace(']', '', $str);
$str = str_replace('【', '', $str);
$str = str_replace('】', '', $str);
$str = str_replace('{', '', $str);
$str = str_replace('}', '', $str);
$str = str_replace(';', '', $str);
$str = str_replace(';', '', $str);
$str = str_replace(':', '', $str);
$str = str_replace(':', '', $str);
$str = str_replace('\'', '', $str);
$str = str_replace('"', '', $str);
$str = str_replace('“', '', $str);
$str = str_replace('”', '', $str);
$str = str_replace(',', '', $str);
$str = str_replace(',', '', $str);
$str = str_replace('<', '', $str);
$str = str_replace('>', '', $str);
$str = str_replace('《', '', $str);
$str = str_replace('》', '', $str);
$str = str_replace('.', '', $str);
$str = str_replace('。', '', $str);
$str = str_replace('/', '', $str);
$str = str_replace('、', '', $str);
$str = str_replace('?', '', $str);
$str = str_replace('?', '', $str);
return trim($str);
}
function cutstr_json($string) {
}
function getTime($Ymd=NULL,$xia=false){
if($Ymd=='Y' && $xia==true){
return strtotime((date('Y',time())+1).'-01-01 00:00:00');
}
else if($Ymd=='Y'){
return strtotime(date('Y',time()).'-01-01 00:00:00');
}
else if($Ymd=='m' && $xia==true){
$xiayue_nianfen = date('Y',time());
$xiayue_yuefen = date('m',time());
if($xiayue_yuefen==12){
$xiayue_nianfen += 1; $xiayue_yuefen = 1; }
else{
$xiayue_yuefen += 1; }
return strtotime($xiayue_nianfen.'-'.$xiayue_yuefen.'-01 00:00:00');
}
else if($Ymd=='m'){
return strtotime(date('Y-m',time()).'-01 00:00:00');
}
else if($Ymd=='d' && $xia==true){
return strtotime(date('Y-m-d',time()).' 00:00:00')+86400;
}
else if($Ymd=='d'){
return strtotime(date('Y-m-d',time()).' 00:00:00');
}
else{
return time();
}
}