123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- <?php
- use Illuminate\Support\Facades\Redis;
- function statics($file)
- {
- return config('console.static_url') . $file . '?v=' . config('console.static_v');
- }
- /**
- * 截取REQUEST_URI
- *
- * @param string $URL
- * REQUEST_URI
- */
- function REQUEST_URI($URL, $ARR)
- {
- $U = explode("?", $URL);
- $B = false;
- foreach ($ARR as $key => $value) {
- if ($value === $U[0]) {
- $B = true;
- }
- }
- return $B;
- }
- /**
- * 加密
- *
- * @param string $str
- * @return string
- */
- function setSha256(string $str): string
- {
- return hash('sha256', $str);
- }
- if (! function_exists('captchaApiCheck')) {
- /**
- *
- * @param
- * $value
- * @return bool
- */
- function captchaApiCheck($value, $key)
- {
- $ridisKey = config('console.redis_key.captcha_key') . $key;
-
- if (! Redis::EXISTS($ridisKey)) {
- return FALSE;
- } else {
- Redis::del($ridisKey);
- return app('captcha')->check_api($value, $key);
- }
- }
- }
- function makeSn()
- {
- $order_id_main = date('YmdHis') . rand(10000000, 99999999);
-
- $order_id_len = strlen($order_id_main);
-
- $order_id_sum = 0;
-
- for ($i = 0; $i < $order_id_len; $i ++) {
-
- $order_id_sum += (int) (substr($order_id_main, $i, 1));
- }
- return $order_id_main . str_pad((100 - $order_id_sum % 100) % 100, 2, '0', STR_PAD_LEFT);
- }
- function stringLength($string)
- {
- $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
- preg_match_all($re['utf-8'], $string, $match);
- return count($match[0]);
- }
- function picPath($path)
- {
- return asset('storage/' . $path);
- }
- /**
- * 数字转换为中文
- *
- * @param integer $num
- * 目标数字
- */
- function number2Chinese(int $num)
- {
- if (is_int($num) && $num < 100) {
- $char = array(
- '零',
- '一',
- '二',
- '三',
- '四',
- '五',
- '六',
- '七',
- '八',
- '九'
- );
- $unit = [
- '',
- '十',
- '百',
- '千',
- '万'
- ];
- $return = '';
- if ($num < 10) {
- $return = $char[$num];
- } elseif ($num % 10 == 0) {
- $firstNum = substr($num, 0, 1);
- if ($num != 10)
- $return .= $char[$firstNum];
- $return .= $unit[strlen($num) - 1];
- } elseif ($num < 20) {
- $return = $unit[substr($num, 0, - 1)] . $char[substr($num, - 1)];
- } else {
- $numData = str_split($num);
- $numLength = count($numData) - 1;
- foreach ($numData as $k => $v) {
- if ($k == $numLength)
- continue;
- $return .= $char[$v];
- if ($v != 0)
- $return .= $unit[$numLength - $k];
- }
- $return .= $char[substr($num, - 1)];
- }
- return $return;
- }
- }
- /**
- * 数字星期转中文
- *
- * @param int $num
- * @return string
- */
- function week2Chinese(int $num)
- {
- $weekArray = [
- "日",
- "一",
- "二",
- "三",
- "四",
- "五",
- "六"
- ];
- return $weekArray[$num];
- }
- /**
- * 中文数值转数字
- *
- * @param string $str
- * @return string
- */
- function chinese2Number(string $str)
- {
- $map = array(
- '一' => '1',
- '二' => '2',
- '三' => '3',
- '四' => '4',
- '五' => '5',
- '六' => '6',
- '七' => '7',
- '八' => '8',
- '九' => '9',
- '壹' => '1',
- '贰' => '2',
- '叁' => '3',
- '肆' => '4',
- '伍' => '5',
- '陆' => '6',
- '柒' => '7',
- '捌' => '8',
- '玖' => '9',
- '零' => '0',
- '两' => '2',
- '仟' => '千',
- '佰' => '百',
- '拾' => '十',
- '万万' => '亿'
- );
-
- $str = str_replace(array_keys($map), array_values($map), $str);
- $str = checkString($str, '/([\d亿万千百十]+)/u');
-
- $func_c2i = function ($str, $plus = false) use(&$func_c2i) {
- if(false === $plus) {
- $plus = array('亿' => 100000000,'万' => 10000,'千' => 1000,'百' => 100,'十' => 10,);
- }
-
- $i = 0;
- if($plus){
- foreach($plus as $k => $v) {
- $i++;
- if(strpos($str, $k) !== false) {
- $ex = explode($k, $str, 2);
- $new_plus = array_slice($plus, $i, null, true);
- $l = $func_c2i($ex[0], $new_plus);
- $r = $func_c2i($ex[1], $new_plus);
- if($l == 0) $l = 1;
- return $l * $v + $r;
- }
- }
- return (int)$str;
- }
- };
-
- return $func_c2i($str);
- }
- /**
- * 中文数值转数字,检查中文字符串是否满足条件
- *
- * @param string $var
- * @param string $check
- * @param string $default
- * @return string
- */
- function checkString(string $var, $check = '', $default = '')
- {
- if (! is_string($var)) {
- if (is_numeric($var)) {
- $var = (string) $var;
- } else {
- return $default;
- }
- }
- if ($check) {
- return (preg_match($check, $var, $ret) ? $ret[1] : $default);
- }
-
- return $var;
- }
- /**
- * 身份证号获取信息
- *
- * @param string $idcard 身份证号
- * @return array
- */
- function idCardInfo($idcard)
- {
- //性别
- $sex = substr($idcard, (strlen($idcard) == 18 ? - 2 : - 1), 1) % 2 ? '1' : '2';
- //获得出生年月日的时间戳
- $birthdays = strtotime(strlen($idcard) == 15 ? ('19' . substr($idcard, 6, 6)) : substr($idcard, 6, 8));
-
- // 获得今日的时间戳
- $today = time();
- // 得到两个日期相差的大体年数
- $diff = floor(($today - $birthdays) / 86400 / 365);
- // strtotime加上这个年数后得到那日的时间戳后与今日的时间戳相比
- $age = strtotime(substr($idcard, 6, 8) . ' +' . $diff . 'years') > $today ? ($diff + 1) : $diff;
-
- return [
- 'sex' => $sex,
- 'birthday' => date('Y-m-d', $birthdays),
- 'age' => $age,
- ];
- }
|