/**
* 保留2位小数,只四舍
* @param type $num
* @return type 1四舍 2四舍五入 3格式化 4向上取整 5向下取整
*/
function number_format_2( $num , $type=1 , $digit=2 ) {
$digit1 = "%." . intval($digit) . "f";
$digit2 = "%." . intval($digit + 1) . "f";
if( $type == 1 ){
return sprintf( $digit1 , substr(sprintf( $digit2 , $num), 0, -1));
}elseif( $type == 2 ){
return sprintf( $digit1 , $num );
}elseif( $type == 3 ){
return number_format( $num , $digit , '.' , '' );
}elseif( $type == 4 ){
return ceil( $num );
}elseif( $type == 5 ){
return floor( $num );
}
}
if (!function_exists('getRedis')) {
function getRedis($config = []) {
$config = [
"host" => "127.0.0.1",
"port" => 6379,
];
$redis = new redis();
$redis->connect($config['host'], $config['port']);
return $redis;
}
}
/**
* @return boolean
*/
function check_multi( $key='' , $value = "check" , $ttl = 5 ){
/**
* // 使用
$key = $goods_sn . "-" . "confirm_order" . "-" . $this->id ;
$check_info = check_multi( $key );
if( !$check_info ){
$this->error( "服务器繁忙,请稍候再试" );
}
*/
$config = [
"host" => "127.0.0.1",
"port" => 6379,
];
$redis = new redis();
$redis->connect($config['host'], $config['port']);
$get_k = $redis->get( $key );
if( $get_k ){
return false;
}
$set_k = $redis->set( $key , $value , array('nx', 'ex' => $ttl));
return $set_k;
}