公共方法

/**
 * 生成默认商品编号/货号
 */
function WSTGoodsNo($pref = ''){
    return $pref.(round(microtime(true),4)*10000).mt_rand(0,9);
}
/**
 * 获取订单统一流水号
 */
function WSTOrderQnique(){
    return (round(microtime(true),4)*10000).mt_rand(1000,9999);
}
/**
 * 高精度数字相加
 * @param $num
 * @param number $i 保留小数位
 */
function WSTBCMoney($num1,$num2,$i=2){
	$num = bcadd($num1, $num2, $i);
	return (float)$num;
}

  

/**
 * 提供原生分页处理
 */
function WSTPager($total,$rs,$page,$size = 0){
    $pageSize = ($size>0)?$size:config('paginate.list_rows');
    $totalPage = ($total%$pageSize==0)?($total/$pageSize):(intval($total/$pageSize)+1);
    return ['total'=>$total,'per_page'=>$pageSize,'current_page'=>$page,'last_page'=>$totalPage,'data'=>$rs];
}
/**
 * 将传过来的字符串格式化为数值字符串
 * @param string $split 要格式的字符串
 * @param string $str 字符串中的分隔符号
 * @param boolean $isJoin 是否连成字符串返回
 */
function WSTFormatIn($split,$str,$isJoin = true){
    if($str=='')return $isJoin?'':[];
    $strdatas = explode($split,$str);
    $data = array();
    for($i=0;$i<count($strdatas);$i++){
        $data[] = (int)$strdatas[$i];
    }
    $data = array_unique($data);
    if($isJoin)return implode($split,$data);
    return $data;

}
/**
 * 生成随机字符串
 * @param integer $len 要生成的字符串长度
 */
function WSTRandStr($len = 6){
    $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    $tmp = '';
    for($i=0;$i<$len;$i++){
        $tmp.=$str[rand(0,35)];
    }
    return $tmp;
}
/**
 * 获取星期几
 */
function WSTgetWeek($date){
	//强制转换日期格式
	$date_str=date('Y-m-d',strtotime($date));
	$number_wk=date("w",strtotime($date));
	$weekArr=array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
	return $weekArr[$number_wk];
}

  

/**
 * URL 64位加密处理
 * @param string $data 字符串内容
 * @param boolean $isEncode true:编码  false:解码
 */
function WSTBase64url($data,$isEncode = true) {
  return ($isEncode)?rtrim(strtr(base64_encode($data), '+/', '-_'), '='):base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
/**
 * URL 64位加密处理[编码]
 * @param string $data 字符串内容
 */
function WSTBase64urlEncode($data){
    $secretKey = WSTConf('CONF.urlSecretKey');
    $base64 = new \org\Base64();
     $key = WSTBase64url($base64->encrypt($data, $secretKey),true);
     return $key;
}

/**
 * URL 64位加密处理[解码]
 * @param string $data 字符串内容
 */
function WSTBase64urlDecode($data){
    $secretKey = WSTConf('CONF.urlSecretKey');
    $key = WSTBase64url($data,false);
    $base64 = new \org\Base64();
      $key = $base64->decrypt($key,$secretKey);
      return $key;
}
/**
 * 判断访问端来源
 */
function WSTVisitModule(){
    $request = request();
    if($request->isMobile()){
        return (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false)?'wechat':'mobile';
    }
    return 'home';
}

  

/**
 * 计算剩余时间
 */
function WSTTimeToStr($second){
	$day = floor($second/(3600*24));
	$second = $second%(3600*24);//除去整天之后剩余的时间
	$hour = floor($second/3600);
	$second = $second%3600;//除去整小时之后剩余的时间
	$minute = floor($second/60);
	$second = $second%60;//除去整分钟之后剩余的时间
	//返回字符串
	return (($day>0)?($day.'天'):"").($hour<10?"0".$hour:$hour).':'.($minute<10?"0".$minute:$minute).':'.($second<10?"0".$second:$second);
}

  

/**
 * 分词
 */
function WSTAnalysis($str){
	$str = trim($str);
	$do_fork = true;
    $do_unit = true;//新词识别
    $do_multi = true;//多元切分
    $do_prop = false;//词性标注
    $pri_dict = false;//是否预载全部词条
    $pa = new \phpanalysis\phpanalysis('utf-8', 'utf-8', $pri_dict);
    //载入词典
    $pa->LoadDict();
    //执行分词
    $pa->SetSource($str);
    $pa->differMax = $do_multi;
    $pa->unitWord = $do_unit;
    $pa->StartAnalysis( $do_fork );
    $str = $pa->GetFinallyResult(' ', $do_prop);
    $str = explode(' ',$str);
    $rs = array();
    foreach ($str as $key =>$v){
    	if(trim($v)=='' || trim($v)==')' || trim($v)=='(')continue;
    	$rs[] = $v;
    }
    return $rs;
}

  

posted @ 2021-04-22 09:47  御世制人  阅读(102)  评论(0编辑  收藏  举报