common.php 43.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365
<?php

// 公共助手函数

use Symfony\Component\VarExporter\VarExporter;
use think\exception\HttpResponseException;
use think\Response;
use think\Db;

error_reporting(E_ERROR | E_WARNING | E_PARSE);

function get_reservoir_name($ids)
{
    return Db::name('reservoir_list')->where('id', $ids)->value('name');
}

if (!function_exists('get_root_url')) {
    /**
     * 获取网站的根Url
     * @return string
     */
    function get_root_url()
    {
        $request = request();
        $base = $request->root();
        $root = strpos($base, '.') ? ltrim(dirname($base), DS) : $base;
        if ('' != $root) {
            $root = '/' . ltrim($root, '/');
        }

        return ($request->isSsl() ? 'https' : 'http') . '://' . $request->host() . "{$root}";
    }
}
if (!function_exists('__')) {

    /**
     * 获取语言变量值
     * @param string $name 语言变量名
     * @param array $vars 动态变量值
     * @param string $lang 语言
     * @return mixed
     */
    function __($name, $vars = [], $lang = '')
    {
        if (is_numeric($name) || !$name) {
            return $name;
        }
        if (!is_array($vars)) {
            $vars = func_get_args();
            array_shift($vars);
            $lang = '';
        }
        return \think\Lang::get($name, $vars, $lang);
    }
}

if (!function_exists('format_bytes')) {

    /**
     * 将字节转换为可读文本
     * @param int $size 大小
     * @param string $delimiter 分隔符
     * @param int $precision 小数位数
     * @return string
     */
    function format_bytes($size, $delimiter = '', $precision = 2)
    {
        $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
        for ($i = 0; $size >= 1024 && $i < 6; $i++) {
            $size /= 1024;
        }
        return round($size, $precision) . $delimiter . $units[$i];
    }
}

if (!function_exists('datetime')) {

    /**
     * 将时间戳转换为日期时间
     * @param int $time 时间戳
     * @param string $format 日期时间格式
     * @return string
     */
    function datetime($time, $format = 'Y-m-d H:i:s')
    {
        $time = is_numeric($time) ? $time : strtotime($time);
        return date($format, $time);
    }
}

if (!function_exists('human_date')) {

    /**
     * 获取语义化时间
     * @param int $time 时间
     * @param int $local 本地时间
     * @return string
     */
    function human_date($time, $local = null)
    {
        return \fast\Date::human($time, $local);
    }
}

if (!function_exists('cdnurl')) {

    /**
     * 获取上传资源的CDN的地址
     * @param string $url 资源相对地址
     * @param boolean $domain 是否显示域名 或者直接传入域名
     * @return string
     */
    function cdnurl($url, $domain = false)
    {
        $regex = "/^((?:[a-z]+:)?\/\/|data:image\/)(.*)/i";
        $cdnurl = \think\Config::get('upload.cdnurl');
        $url = preg_match($regex, $url) || ($cdnurl && stripos($url, $cdnurl) === 0) ? $url : $cdnurl . $url;
        if ($domain && !preg_match($regex, $url)) {
            $domain = is_bool($domain) ? request()->domain() : $domain;
            $url = $domain . $url;
        }
        return $url;
    }
}


if (!function_exists('is_really_writable')) {

    /**
     * 判断文件或文件夹是否可写
     * @param string $file 文件或目录
     * @return    bool
     */
    function is_really_writable($file)
    {
        if (DIRECTORY_SEPARATOR === '/') {
            return is_writable($file);
        }
        if (is_dir($file)) {
            $file = rtrim($file, '/') . '/' . md5(mt_rand());
            if (($fp = @fopen($file, 'ab')) === false) {
                return false;
            }
            fclose($fp);
            @chmod($file, 0777);
            @unlink($file);
            return true;
        } elseif (!is_file($file) or ($fp = @fopen($file, 'ab')) === false) {
            return false;
        }
        fclose($fp);
        return true;
    }
}

if (!function_exists('rmdirs')) {

    /**
     * 删除文件夹
     * @param string $dirname 目录
     * @param bool $withself 是否删除自身
     * @return boolean
     */
    function rmdirs($dirname, $withself = true)
    {
        if (!is_dir($dirname)) {
            return false;
        }
        $files = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($dirname, RecursiveDirectoryIterator::SKIP_DOTS),
            RecursiveIteratorIterator::CHILD_FIRST
        );

        foreach ($files as $fileinfo) {
            $todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
            $todo($fileinfo->getRealPath());
        }
        if ($withself) {
            @rmdir($dirname);
        }
        return true;
    }
}

if (!function_exists('copydirs')) {

    /**
     * 复制文件夹
     * @param string $source 源文件夹
     * @param string $dest 目标文件夹
     */
    function copydirs($source, $dest)
    {
        if (!is_dir($dest)) {
            mkdir($dest, 0755, true);
        }
        foreach (
            $iterator = new RecursiveIteratorIterator(
                new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
                RecursiveIteratorIterator::SELF_FIRST
            ) as $item
        ) {
            if ($item->isDir()) {
                $sontDir = $dest . DS . $iterator->getSubPathName();
                if (!is_dir($sontDir)) {
                    mkdir($sontDir, 0755, true);
                }
            } else {
                copy($item, $dest . DS . $iterator->getSubPathName());
            }
        }
    }
}

if (!function_exists('mb_ucfirst')) {
    function mb_ucfirst($string)
    {
        return mb_strtoupper(mb_substr($string, 0, 1)) . mb_strtolower(mb_substr($string, 1));
    }
}

if (!function_exists('addtion')) {

    /**
     * 附加关联字段数据
     * @param array $items 数据列表
     * @param mixed $fields 渲染的来源字段
     * @return array
     */
    function addtion($items, $fields)
    {
        if (!$items || !$fields) {
            return $items;
        }
        $fieldsArr = [];
        if (!is_array($fields)) {
            $arr = explode(',', $fields);
            foreach ($arr as $k => $v) {
                $fieldsArr[$v] = ['field' => $v];
            }
        } else {
            foreach ($fields as $k => $v) {
                if (is_array($v)) {
                    $v['field'] = isset($v['field']) ? $v['field'] : $k;
                } else {
                    $v = ['field' => $v];
                }
                $fieldsArr[$v['field']] = $v;
            }
        }
        foreach ($fieldsArr as $k => &$v) {
            $v = is_array($v) ? $v : ['field' => $v];
            $v['display'] = isset($v['display']) ? $v['display'] : str_replace(['_ids', '_id'], ['_names', '_name'], $v['field']);
            $v['primary'] = isset($v['primary']) ? $v['primary'] : '';
            $v['column'] = isset($v['column']) ? $v['column'] : 'name';
            $v['model'] = isset($v['model']) ? $v['model'] : '';
            $v['table'] = isset($v['table']) ? $v['table'] : '';
            $v['name'] = isset($v['name']) ? $v['name'] : str_replace(['_ids', '_id'], '', $v['field']);
        }
        unset($v);
        $ids = [];
        $fields = array_keys($fieldsArr);
        foreach ($items as $k => $v) {
            foreach ($fields as $m => $n) {
                if (isset($v[$n])) {
                    $ids[$n] = array_merge(isset($ids[$n]) && is_array($ids[$n]) ? $ids[$n] : [], explode(',', $v[$n]));
                }
            }
        }
        $result = [];
        foreach ($fieldsArr as $k => $v) {
            if ($v['model']) {
                $model = new $v['model'];
            } else {
                $model = $v['name'] ? \think\Db::name($v['name']) : \think\Db::table($v['table']);
            }
            $primary = $v['primary'] ? $v['primary'] : $model->getPk();
            $result[$v['field']] = isset($ids[$v['field']]) ? $model->where($primary, 'in', $ids[$v['field']])->column("{$primary},{$v['column']}") : [];
        }

        foreach ($items as $k => &$v) {
            foreach ($fields as $m => $n) {
                if (isset($v[$n])) {
                    $curr = array_flip(explode(',', $v[$n]));

                    $v[$fieldsArr[$n]['display']] = implode(',', array_intersect_key($result[$n], $curr));
                }
            }
        }
        return $items;
    }
}

if (!function_exists('var_export_short')) {

    /**
     * 使用短标签打印或返回数组结构
     * @param mixed $data
     * @param boolean $return 是否返回数据
     * @return string
     */
    function var_export_short($data, $return = true)
    {
        return var_export($data, $return);
        $replaced = [];
        $count = 0;

        //判断是否是对象
        if (is_resource($data) || is_object($data)) {
            return var_export($data, $return);
        }

        //判断是否有特殊的键名
        $specialKey = false;
        array_walk_recursive($data, function (&$value, &$key) use (&$specialKey) {
            if (is_string($key) && (stripos($key, "\n") !== false || stripos($key, "array (") !== false)) {
                $specialKey = true;
            }
        });
        if ($specialKey) {
            return var_export($data, $return);
        }
        array_walk_recursive($data, function (&$value, &$key) use (&$replaced, &$count, &$stringcheck) {
            if (is_object($value) || is_resource($value)) {
                $replaced[$count] = var_export($value, true);
                $value = "##<{$count}>##";
            } else {
                if (is_string($value) && (stripos($value, "\n") !== false || stripos($value, "array (") !== false)) {
                    $index = array_search($value, $replaced);
                    if ($index === false) {
                        $replaced[$count] = var_export($value, true);
                        $value = "##<{$count}>##";
                    } else {
                        $value = "##<{$index}>##";
                    }
                }
            }
            $count++;
        });

        $dump = var_export($data, true);

        $dump = preg_replace('#(?:\A|\n)([ ]*)array \(#i', '[', $dump); // Starts
        $dump = preg_replace('#\n([ ]*)\),#', "\n$1],", $dump); // Ends
        $dump = preg_replace('#=> \[\n\s+\],\n#', "=> [],\n", $dump); // Empties
        $dump = preg_replace('#\)$#', "]", $dump); //End

        if ($replaced) {
            $dump = preg_replace_callback("/'##<(\d+)>##'/", function ($matches) use ($replaced) {
                return isset($replaced[$matches[1]]) ? $replaced[$matches[1]] : "''";
            }, $dump);
        }

        if ($return === true) {
            return $dump;
        } else {
            echo $dump;
        }
    }
}

if (!function_exists('letter_avatar')) {
    /**
     * 首字母头像
     * @param $text
     * @return string
     */
    function letter_avatar($text)
    {
        $total = unpack('L', hash('adler32', $text, true))[1];
        $hue = $total % 360;
        list($r, $g, $b) = hsv2rgb($hue / 360, 0.3, 0.9);

        $bg = "rgb({$r},{$g},{$b})";
        $color = "#ffffff";
        $first = mb_strtoupper(mb_substr($text, 0, 1));
        $src = base64_encode('<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="100" width="100"><rect fill="' . $bg . '" x="0" y="0" width="100" height="100"></rect><text x="50" y="50" font-size="50" text-copy="fast" fill="' . $color . '" text-anchor="middle" text-rights="admin" dominant-baseline="central">' . $first . '</text></svg>');
        $value = 'data:image/svg+xml;base64,' . $src;
        return $value;
    }
}

if (!function_exists('hsv2rgb')) {
    function hsv2rgb($h, $s, $v)
    {
        $r = $g = $b = 0;

        $i = floor($h * 6);
        $f = $h * 6 - $i;
        $p = $v * (1 - $s);
        $q = $v * (1 - $f * $s);
        $t = $v * (1 - (1 - $f) * $s);

        switch ($i % 6) {
            case 0:
                $r = $v;
                $g = $t;
                $b = $p;
                break;
            case 1:
                $r = $q;
                $g = $v;
                $b = $p;
                break;
            case 2:
                $r = $p;
                $g = $v;
                $b = $t;
                break;
            case 3:
                $r = $p;
                $g = $q;
                $b = $v;
                break;
            case 4:
                $r = $t;
                $g = $p;
                $b = $v;
                break;
            case 5:
                $r = $v;
                $g = $p;
                $b = $q;
                break;
        }

        return [
            floor($r * 255),
            floor($g * 255),
            floor($b * 255)
        ];
    }
}

if (!function_exists('check_nav_active')) {
    /**
     * 检测会员中心导航是否高亮
     */
    function check_nav_active($url, $classname = 'active')
    {
        $auth = \app\common\library\Auth::instance();
        $requestUrl = $auth->getRequestUri();
        $url = ltrim($url, '/');
        return $requestUrl === str_replace(".", "/", $url) ? $classname : '';
    }
}

if (!function_exists('check_cors_request')) {
    /**
     * 跨域检测
     */
    function check_cors_request()
    {
        if (isset($_SERVER['HTTP_ORIGIN']) && $_SERVER['HTTP_ORIGIN']) {
            $info = parse_url($_SERVER['HTTP_ORIGIN']);
            $domainArr = explode(',', config('fastadmin.cors_request_domain'));
            $domainArr[] = request()->host(true);
            if (in_array("*", $domainArr) || in_array($_SERVER['HTTP_ORIGIN'], $domainArr) || (isset($info['host']) && in_array($info['host'], $domainArr))) {
                header("Access-Control-Allow-Origin: " . $_SERVER['HTTP_ORIGIN']);
            } else {
                $response = Response::create('跨域检测无效', 'html', 403);
                throw new HttpResponseException($response);
            }

            header('Access-Control-Allow-Credentials: true');
            header('Access-Control-Max-Age: 86400');

            if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
                if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
                    header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
                }
                if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
                    header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
                }
                $response = Response::create('', 'html');
                throw new HttpResponseException($response);
            }
        }
    }
}

if (!function_exists('xss_clean')) {
    /**
     * 清理XSS
     */
    function xss_clean($content, $is_image = false)
    {
        return \app\common\library\Security::instance()->xss_clean($content, $is_image);
    }
}

if (!function_exists('check_ip_allowed')) {
    /**
     * 检测IP是否允许
     * @param string $ip IP地址
     */
    function check_ip_allowed($ip = null)
    {
        $ip = is_null($ip) ? request()->ip() : $ip;
        $forbiddenipArr = config('site.forbiddenip');
        $forbiddenipArr = !$forbiddenipArr ? [] : $forbiddenipArr;
        $forbiddenipArr = is_array($forbiddenipArr) ? $forbiddenipArr : array_filter(explode("\n", str_replace("\r\n", "\n", $forbiddenipArr)));
        if ($forbiddenipArr && \Symfony\Component\HttpFoundation\IpUtils::checkIp($ip, $forbiddenipArr)) {
            $response = Response::create('请求无权访问', 'html', 403);
            throw new HttpResponseException($response);
        }
    }
}

if (!function_exists('array_callback')) {
    /**
     * 2022.03.22 kevin
     * 规范数据返回函数
     * @param unknown $state
     * @param unknown $msg
     * @param unknown $data
     * @return multitype:unknown
     */
    function array_callback($state = true, $msg = '', $data = array())
    {
        return array('state' => $state, 'msg' => $msg, 'data' => $data);
    }
}

if (!function_exists('get_unique_no')) {
    function get_unique_no($before)
    {
        return $before . substr(get_uuid(16), 0, 16 - strlen($before));
    }
}

if (!function_exists('get_uuid')) {
    function get_uuid($num = 32)
    {
        if ($num == 16) {
            return strtoupper(substr(md5(uniqid(mt_rand(), 1)), 10, 16));
        }
        if (function_exists('com_create_guid')) {
            return com_create_guid();
        } else {
            mt_srand(( double )microtime() * 10000); //optional for php 4.2.0 and up.随便数播种,4.2.0以后不需要了。
            $charid = strtoupper(md5(uniqid(rand(), true))); //根据当前时间(微秒计)生成唯一id.
            $uuid = substr($charid, 0, 8) . substr($charid, 8, 4) . substr($charid, 12, 4) . substr($charid, 16, 4) . substr($charid, 20, 12);
            return $uuid;
        }
    }
}

if (!function_exists('getOrderId')) {
    function getOrderId($prefix = "")
    {
        date_default_timezone_set('Asia/Shanghai');
        $time = date('mdHis', time());
        $randsix = rand('10000000', '99999999');
        if ($prefix) {
            return $prefix . $time . $randsix;
        }
        return $time . $randsix;
    }
}

/**
 * 字符串截取
 *
 */
if (!function_exists('sub_str')) {
    function sub_str($str, $length = 0, $append = true)
    {
        $str = trim($str);
        $strlength = strlen($str);

        if ($length == 0 || $length >= $strlength) {
            return $str;  //截取长度等于0或大于等于本字符串的长度,返回字符串本身
        } elseif ($length < 0)  //如果截取长度为负数
        {
            $length = $strlength + $length;//那么截取长度就等于字符串长度减去截取长度
            if ($length < 0) {
                $length = $strlength;//如果截取长度的绝对值大于字符串本身长度,则截取长度取字符串本身的长度
            }
        }

        if (function_exists('mb_substr')) {
            $newstr = mb_substr($str, 0, $length, "utf-8");
        } elseif (function_exists('iconv_substr')) {
            $newstr = iconv_substr($str, 0, $length, "utf-8");
        } else {
            //$newstr = trim_right(substr($str, 0, $length));
            $newstr = substr($str, 0, $length);
        }

        if ($append && $str != $newstr) {
            $newstr .= '...';
        }

        return $newstr;
    }
}

/**
 * 首字母排序A-Z(含汉字)
 */
if (!function_exists('getFirstChar')) {
    function getFirstChar($s)
    {
        $s0 = mb_substr($s, 0, 1); //获取名字的姓
        $s = iconv('UTF-8', 'gb2312', $s0); //将UTF-8转换成GB2312编码
//var_dump(ord($s0));
//     var_dump(ord($s));
        if (ord($s0) > 128) { //汉字开头,汉字没有以U、V开头的

            $asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
            if ($asc >= -20319 and $asc <= -20284) return "A";
            if ($asc >= -20283 and $asc <= -19776) return "B";
            if ($asc >= -19775 and $asc <= -19219) return "C";
            if ($asc >= -19218 and $asc <= -18711) return "D";
            if ($asc >= -18710 and $asc <= -18527) return "E";
            if ($asc >= -18526 and $asc <= -18240) return "F";
            if ($asc >= -18239 and $asc <= -17760) return "G";
            if ($asc >= -17759 and $asc <= -17248) return "H";
            if ($asc >= -17247 and $asc <= -17418) return "I";
            if ($asc >= -17417 and $asc <= -16475) return "J";
            if ($asc >= -16474 and $asc <= -16213) return "K";
            if ($asc >= -16212 and $asc <= -15641) return "L";
            if ($asc >= -15640 and $asc <= -15166) return "M";
            if ($asc >= -15165 and $asc <= -14923) return "N";
            if ($asc >= -14922 and $asc <= -14915) return "O";
            if ($asc >= -14914 and $asc <= -14631) return "P";
            if ($asc >= -14630 and $asc <= -14150) return "Q";
            if ($asc >= -14149 and $asc <= -14091) return "R";
            if ($asc >= -14090 and $asc <= -13319) return "S";
            if ($asc >= -13318 and $asc <= -12839) return "T";
            if ($asc >= -12838 and $asc <= -12557) return "W";
            if ($asc >= -12556 and $asc <= -11848) return "X";
            if ($asc >= -11847 and $asc <= -11056) return "Y";
            if ($asc >= -11055 and $asc <= -10247) return "Z";
        } else if (ord($s) >= 48 && ord($s) <= 57) {//数字开头
            $aa = @iconv_substr($s, 0, 1, 'utf-8');
            switch ($aa) {
                case 1:
                    return "Y";
                case 2:
                    return "E";
                case 3:
                    return "S";
                case 4:
                    return "S";
                case 5:
                    return "W";
                case 6:
                    return "L";
                case 7:
                    return "Q";
                case 8:
                    return "B";
                case 9:
                    return "J";
                case 0:
                    return "L";
            }
        } else if (ord($s) >= 65 && ord($s) <= 90) { //大写英文开头
            return substr($s, 0, 1);
        } else if (ord($s) >= 97 && ord($s) <= 122) { //小写英文开头
            return strtoupper(substr($s, 0, 1));
        } else {
            return iconv_substr($s0, 0, 1, 'utf-8');
//中英混合的词语,不适合上面的各种情况,因此直接提取首个字符即可
        }
    }
}


/**
 * 获取所有上级部门id(多个id用“,”隔开)
 */
if (!function_exists('get_parent_id')) {
    function get_parent_id($id)
    {
        $pids = '';
        $parent_id = Db::name("inspection_depart")->where("id", $id)->value("pid");
        if ($parent_id != 0) {
            $pids .= $parent_id;
            $npids = get_parent_id($parent_id);
            if (isset($npids))
                $pids .= ',' . $npids;
        }
        $pids = $pids ? trim($pids, ",") : "";
        return $pids;
    }
}
if (!function_exists('getLatelyTime')) {
    /**
     * 获取最近一周,一个月,一年
     * */
    function getLatelyTime($type = 'week')
    {
        $now = time();
        $result = [];

        if ($type == 'week5') {
            //最近一周
            for ($i = 0; $i < 5; $i++) {
                $result[] = date('Ymd', strtotime('-' . $i . ' day', $now));
            }
        } elseif ($type == 'week') {
            //最近一周
            for ($i = 0; $i < 7; $i++) {
                $result[] = date('Ymd', strtotime('-' . $i . ' day', $now));
            }
        } elseif ($type == 'month') {
            //最近一个月
            for ($i = 0; $i < 30; $i++) {
                $result[] = date('Y-m-d', strtotime('-' . $i . ' day', $now));
            }
        } elseif ($type == 'year') {
            //最近一年
            for ($i = 0; $i < 12; $i++) {
                $result[] = date('Y-m', strtotime('-' . $i . ' month', $now));
            }
        }
        return $result;
    }
}
if (!function_exists('setQiniuFileUrl')) {
    /**
     * 处理七牛一的文件地址:图片、视频、文件
     * $data 可以传入一维数组
     * 文件地址前添加域名地址
     */
    function setQiniuFileUrl($data)
    {
        $domen = 'https://qiniu.ynzhsk.cn/';
        if (is_array($data)) {
            $arr = array();
            foreach ($data as $v) {
                if (!empty($v)) {
                    array_push($arr, $domen . $v);
                }
            }
            return $arr;
        } else {
            return $domen . $data;
        }
    }
}

if (!function_exists('dam_isotonic_attr_data')) {
    /**
     * type:1.孔口到水面距离 2.水面高程
     *
     * E孔口到水面距离=D孔深(设备固定值)-A浸润线深度(设备上报值)
     * F水面高程=C孔口高程(设备固定值)—E孔口到水面距离(D孔深-A浸润线深度)
     *
     * $orifice_elevation :C孔口高程
     * $hole_depth :D孔深(固定值)
     * $dx_value A浸润深度
     */
    function dam_isotonic_attr_data($orifice_elevation, $hole_depth, $dx_value, $type)
    {
        $return_data = 0;
        if ($type == 1) {
            $return_data = bcsub($hole_depth, $dx_value, 2);
        } elseif ($type == 2) {
            $data1 = bcsub($hole_depth, $dx_value, 2);
            $return_data = bcsub($orifice_elevation, $data1, 3);
        }
        return $return_data;
    }
}
/**
 * 生成订单号
 * 重复就重新生成
 */
if (!function_exists('getOrderSn')) {
    function getOrderSn()
    {
        $orderid = date("YmdHis") . mt_rand(1000, 999999);
        $odcks = \think\Db::name('river_patrol_list')
            ->where(['ordersn' => $orderid])
            ->find();
        while (!empty($odcks)) {
            $orderid = date("YmdHis") . mt_rand(1000, 999999);
        }
        return $orderid;
    }
}
if (!function_exists('send_post')) {
//请求函数
    function send_post($url, $post_data = [], $method = 'POST')
    {
        $postdata = http_build_query($post_data);
        $options = array(
            'http' => array(
                'method' => $method, //or GET
                'header' => 'Content-type:application/x-www-form-urlencoded',
                'content' => $postdata,
                'timeout' => 15 * 60 // 超时时间(单位:s)
            )
        );
        $context = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
        return $result;
    }
}
/***
 * 按水库id和水位获得库容值
 *
 */
if (!function_exists('getWarterdataCapacityof')) {
    function getWarterdataCapacityof($reservoir_id, $water_level)
    {
        $capacityof = Db::name('warterdata_capacityof')
            ->where(['reservoir_id' => $reservoir_id, 'warterdata' => $water_level])
            ->value('CapacityOf');
        return $capacityof ? $capacityof : 0;
    }
}
/***
 * 按水库id获得库容表的最大水位
 *
 */
if (!function_exists('getWarterdataMaxWaterLevel')) {
    function getWarterdataMaxWaterLevel($reservoir_id)
    {
        $capacityof = Db::name('warterdata_capacityof')
            ->where(['reservoir_id' => $reservoir_id])
            ->order('warterdata desc')
            ->value('warterdata');
        return $capacityof ? $capacityof : 0;
    }
}
if (!function_exists('full_image')) {
    /**
     * 获取图片全地址
     */
    function full_image($img)
    {

        if (!empty($img)) {
            //判断是不是数组
            if (is_array($img)) {
                foreach ($img as $k => $v) {
                    if (!empty($v)) {
                        if ('http' != substr($v, 0, 4)) {
                            $img[$k] = 'https://qiniu.ynzhsk.cn/' . $v;
                        }
                    }
                }
            } else {
                //判断是不是http开头的(若是就是就代表是本地上传。不是就是七牛上传的=>"/uploads")
                if ('http' != substr($img, 0, 4)) {
                    $img = 'https://qiniu.ynzhsk.cn/' . $img;
                }
            }
        }
        return $img;
    }
}
if (!function_exists('setDateTimes')) {
    function setdateTimes($data)
    {
        return date('Y-m-d H:i:s', $data);
    }
}
if (!function_exists('user_id_get_admin_id')) {
    /**
     * 根据用户id获取归属admin_id
     */
    function user_id_get_admin_id($id)
    {
        $admin_id = 1;
        if (!empty($id)) {
            $ad_id = Db::name("user")->alias("a")
                ->join("user_grid b", "a.unionid=b.unionid")
                ->where("a.id", $id)
                ->value("b.admin_id");
            if (!empty($ad_id)) {
                $admin_id = $ad_id;
            }
        }
        return $admin_id;
    }
}

if (!function_exists('str_add_xing')) {
    function str_add_xing($str)
    {
        //判断是否包含中文字符
        if (preg_match("/[\x{4e00}-\x{9fa5}]+/u", $str)) {
            //按照中文字符计算长度
            $len = mb_strlen($str, 'UTF-8');
            //echo '中文';
            if ($len >= 3) {
                //三个字符或三个字符以上掐头取尾,中间用*代替
                $str = mb_substr($str, 0, 1, 'UTF-8') . '*' . mb_substr($str, -1, 1, 'UTF-8');
            } elseif ($len == 2) {
                //两个字符
                $str = mb_substr($str, 0, 1, 'UTF-8') . '*';
            }
        } else {
            //按照英文字串计算长度
            $len = strlen($str);
            //echo 'English';
            if ($len >= 3) {
                //三个字符或三个字符以上掐头取尾,中间用*代替
                $str = substr($str, 0, 1) . '*' . substr($str, -1);
            } elseif ($len == 2) {
                //两个字符
                $str = substr($str, 0, 1) . '*';
            }
        }
        return $str;
    }

}

if (!function_exists('get_root_url')) {
    /**
     * 获取网站的根Url
     * @return string
     */
    function get_root_url()
    {
        $request = request();
        $base = $request->root();
        $root = strpos($base, '.') ? ltrim(dirname($base), DS) : $base;
        if ('' != $root) {
            $root = '/' . ltrim($root, '/');
        }

        return ($request->isSsl() ? 'https' : 'http') . '://' . $request->host() . "{$root}";
    }
}

if (!function_exists('del_place_qrcode')) {
    /**
     * 删除场所二维码文件(地址存在的是带域名的全路径 )
     * @param  [type] $pic [description]
     * @return [type]      [description]
     */
    function del_place_qrcode($pic)
    {
        $pic_path_arr = parse_url($pic);//parse_url函数将URL转换为关联数组
        $real_pic_path = $pic_path_arr['path'];
        $path = __FILE__;
        $paths = substr($path, 0, strpos($path, 'application'));
        $pic1 = $paths . "public" . $real_pic_path;

        if (file_exists($pic1)) {

            @unlink($pic1);

            return true;
        }
        return false;
    }
}

if (!function_exists('insert_openid_info')) {
    /**
     * 将授权用户信息保存起来
     */
    function insert_openid_info($data)
    {
        $data['upt_time'] = time();
        $res = \think\Db::name("openid_info")->where("openid", $data['openid'])->find();
//        file_put_contents("ccc.txt", date("Y-m-d H:i:s") . json_encode($data) . PHP_EOL, FILE_APPEND);
        if (!empty($res)) {
            \think\Db::name("openid_info")->where("openid", $data['openid'])->update($data);
        } else {
            \think\Db::name("openid_info")->insertGetId($data);
        }
        return true;
    }
}


if (!function_exists('headers_to_curl')) {
    /**
     * 发送数据含 header
     * @param String $url 请求的地址
     * @param Array $header 自定义的header数据
     * @param Array $content POST的数据
     * @return String
     */
    function headers_to_curl($url, $header, $content)
    {
        $ch = curl_init();
        if (substr($url, 0, 5) == 'https') {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true); // 从证书中检查SSL加密算法是否存在
        }
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($content));
        $response = curl_exec($ch);
        if ($error = curl_error($ch)) {
            die($error);
        }
        curl_close($ch);
        return $response;
    }
}

if (!function_exists('httpRequest')) {
// curl请求
    function httpRequest($url, $timeout = 30, $header = array())
    {
        if (!function_exists('curl_init')) {
            throw new Exception('server not install curl');
        }
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        if (!empty($header)) {
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        }
        $data = curl_exec($ch);
        list($header, $data) = explode("\r\n\r\n", $data);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($http_code == 301 || $http_code == 302) {
            $matches = array();
            preg_match('/Location:(.*?)\n/', $header, $matches);
            $url = trim(array_pop($matches));
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_HEADER, false);
            $data = curl_exec($ch);
        }

        if ($data == false) {
            curl_close($ch);
        }
        @curl_close($ch);

        return $data;
    }
}
if (!function_exists('is_idcard')) {
    /**
     * 验证身份证
     * @param $id
     * @return bool
     */
    function is_idcard($id)
    {
        $id = strtoupper($id);
        $regx = "/(^\d{15}$)|(^\d{17}([0-9]|X)$)/";
        $arr_split = array();
        if (!preg_match($regx, $id)) {
            return false;
        }
        if (15 == strlen($id)) //检查15位
        {
            $regx = "/^(\d{6})+(\d{2})+(\d{2})+(\d{2})+(\d{3})$/";

            @preg_match($regx, $id, $arr_split);
            //检查生日日期是否正确
            $dtm_birth = "19" . $arr_split[2] . '/' . $arr_split[3] . '/' . $arr_split[4];
            if (!strtotime($dtm_birth)) {
                return false;
            } else {
                return true;
            }
        } else      //检查18位
        {
            $regx = "/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/";
            @preg_match($regx, $id, $arr_split);
            $dtm_birth = $arr_split[2] . '/' . $arr_split[3] . '/' . $arr_split[4];
            if (!strtotime($dtm_birth)) //检查生日日期是否正确
            {
                return false;
            } else {
                //检验18位身份证的校验码是否正确。
                //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
                $arr_int = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
                $arr_ch = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
                $sign = 0;
                for ($i = 0; $i < 17; $i++) {
                    $b = (int)$id{$i};
                    $w = $arr_int[$i];
                    $sign += $b * $w;
                }
                $n = $sign % 11;
                $val_num = $arr_ch[$n];
                if ($val_num != substr($id, 17, 1)) {
                    return false;
                } else {
                    return true;
                }
            }
        }

    }
}
if (!function_exists('time_diff2')) {
    /**
     * 计算时间差
     * @param int $timestamp1 时间戳开始
     * @param int $timestamp2 时间戳结束
     * @return array
     */
    function time_diff2($timestamp1, $timestamp2)
    {
        if ($timestamp2 <= $timestamp1) {
            return ['hours' => 0, 'minutes' => 0, 'seconds' => 0];
        }
        $timediff = $timestamp2 - $timestamp1;
        // 时
        $remain = $timediff % 86400;
        $hours = ($remain / 3600);
        // 分
        $remain = $timediff % 3600;
        $mins = ($remain / 60);
        // 秒
        $secs = $remain % 60;

        $time = ['hours' => $hours, 'minutes' => $mins, 'seconds' => $secs];

        $data['time'] = $time;
        $data['timeall'] = $timediff;
        return $data;
    }
}
if (!function_exists('time_diff')) {
    /**
     * 计算时间差
     * @param int $timestamp1 时间戳开始
     * @param int $timestamp2 时间戳结束
     * @return array
     */
    function time_diff($startime, $endtime)
    {
        //计算时间超时间差
        $diff = abs($endtime - $startime);
        $years = floor($diff / (365 * 60 * 60 * 24));
        $months = floor(($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24));
        $days = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24) / (60 * 60 * 24));
        $hours = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24) / (60 * 60));
        $minutes = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24 - $hours * 60 * 60) / 60);
        $seconds = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24 - $hours * 60 * 60 - $minutes * 60));
        $time = [
            'years' => $years,
            'months' => $months,
            'days' => $days,
            'hours' => $hours,
            'minutes' => $minutes,
            'seconds' => $seconds
        ];

        $data['time'] = $time;
        $data['timeall'] = $diff;
        return $data;

    }
}
if (!function_exists('time_diff_ct')) {
    /**
     * 计算时间差
     * @param int $timestamp1 时间戳开始
     * @param int $timestamp2 时间戳结束
     * @return array
     */
    function time_diff_ct($difftime)
    {
        //计算时间超时间差
        $diff = $difftime;
        $years = floor($diff / (365 * 60 * 60 * 24));
        $months = floor(($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24));
        $days = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24) / (60 * 60 * 24));
        $hours = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24) / (60 * 60));
        $minutes = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24 - $hours * 60 * 60) / 60);
        $seconds = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24 - $hours * 60 * 60 - $minutes * 60));
        $time = [
            'years' => $years,
            'months' => $months,
            'days' => $days,
            'hours' => $hours,
            'minutes' => $minutes,
            'seconds' => $seconds
        ];
        return $time;
    }
}
if (!function_exists('set_timearr_to_str')) {
    /**
     * 计算时间差
     * @param int $timestamp1 时间戳开始
     * @param int $timestamp2 时间戳结束
     * @return array
     */
    function set_timearr_to_str($timearr)
    {
        $timearr = json_decode($timearr, true);
        if ($timearr['seconds'] > 0) {
            $str = $timearr['seconds'] . '秒';
        }
        if ($timearr['minutes'] > 0) {
            $str = $timearr['minutes'] . '分' . $timearr['seconds'] . '秒';
        }
        if ($timearr['hours'] > 0) {
            $str = $timearr['hours'] . '时' . $timearr['minutes'] . '分' . $timearr['seconds'] . '秒';
        }
        if ($timearr['days'] > 0) {
            $str = $timearr['days'] . '日' . $timearr['hours'] . '时' . $timearr['minutes'] . '分' . $timearr['seconds'] . '秒';
        }
        if ($timearr['months'] > 0) {
            $str = $timearr['months'] . '月' . $timearr['days'] . '日' . $timearr['hours'] . '时' . $timearr['minutes'] . '分' . $timearr['seconds'] . '秒';
        }
        if ($timearr['years'] > 0) {
            $str = $timearr['years'] . '年' . $timearr['months'] . '月' . $timearr['days'] . '日' . $timearr['hours'] . '时' . $timearr['minutes'] . '分' . $timearr['seconds'] . '秒';
        }
        return $str;
    }
}
if (!function_exists('time_to_today_end')) {
    /**
     * 获取下次采集日期(传入某个时间戳 返回每天起始时间到结束时间 (可能多天就是返回数组))
     * 比如传的:1657756800(2022-07-14 08:00:00)
     * 返回:[["2022-07-14 08:00:00","2022-07-14 23:59:59"],["2022-07-15 00:00:00","2022-07-15 23:59:59"],["2022-07-16 00:00:00","2022-07-16 23:59:59"]]
     */
    function time_to_today_end($time)
    {
        $return_data = [];
        $chuanru_date = date("Y-m-d", $time);//传入时间的00:00:00;
        $chuanru_end_time = strtotime($chuanru_date) + 24 * 3600 - 1;//传入时间的23:59:59
        //当日23:59:59
        $end_time = strtotime(date('Y-m-d', strtotime('+1 day'))) - 1;

        $return_data[] = [
            date("Y-m-d H:i:s", $time),
            date("Y-m-d H:i:s", $chuanru_end_time)
        ];

        //传入时间的23:59:59 小于 今日23:59:59
        for ($i = 1; $chuanru_end_time < $end_time; $i++) {
            $chuanru_start_time = strtotime($chuanru_date . '+' . $i . ' day');
            $chuanru_end_time = $chuanru_start_time + 24 * 3600 - 1;

            $return_data[] = [
                date("Y-m-d H:i:s", $chuanru_start_time),
                date("Y-m-d H:i:s", $chuanru_end_time)
            ];
        }

        return $return_data;

    }
}

if (!function_exists('time_to_time_end')) {
    /**
     * 获取雨量统计时间(传入两个时间戳 返回每天08:00-09:00时间,雨量统计是8点-9点统计昨天的,取靠近8点的累积量(可能多天就是返回数组))
     * 比如传的:1657756800(2022-07-14 08:00:00),1657929600(2022-07-16 08:00:00)
     * 返回:[["2022-07-14 08:00:00","2022-07-14 09:00:00"],["2022-07-15 08:00:00","2022-07-15 09:00:00"],["2022-07-16 08:00:00","2022-07-16 09:00:00"]]
     */
    function time_to_time_end($stime, $etime)
    {
        $return_data = [];
        $chuanru_date = date("Y-m-d", $stime);
        $start_time = strtotime($chuanru_date);//传入时间的00:00:00;
        $end_time = strtotime(date("Y-m-d", $etime));//传入时间的00:00:00;
        $chuanru_end_time = $start_time;
        //看有多少天

        $return_data[] = [
            date("Y-m-d 08:00:00", $stime),
            date("Y-m-d 09:00:00", $stime),
        ];

        //传入时间的23:59:59 小于 今日23:59:59
        for ($i = 1; $chuanru_end_time < $end_time; $i++) {
            $chuanru_start_time = strtotime($chuanru_date . '+' . $i . ' day');
            $chuanru_end_time = $chuanru_start_time + 24 * 3600 - 1;

            $return_data[] = [
                date("Y-m-d 08:00:00", $chuanru_start_time),
                date("Y-m-d 09:00:00", $chuanru_end_time)
            ];
        }

        return $return_data;

    }
}

if (!function_exists('check_phone_auth')) {
    function check_phone_auth($keyword)
    {
        if ($keyword == "Admin2022Hcanxyz!.") {
            return true;
        } else {
            return false;
        }
    }
}

if (!function_exists('kevin_get_header_requests')) {
    function kevin_get_header_requests($url, $header)
    {
        if (empty($header)) {
            $header[] = 'content-type: application/json';
        }
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }
}

if (!function_exists('kevin_post_header_json_requests')) {
    /**
     * POST 带header的json请求
     */
    function kevin_post_header_json_requests($url, $header = array(), $data = array())
    {

        $oCurl = curl_init();

        curl_setopt($oCurl, CURLOPT_URL, $url);

        if (empty($header)) {
            $header[] = 'content-type: application/json';
        }
        curl_setopt($oCurl, CURLOPT_HTTPHEADER, $header);

        //关闭https验证

        curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);

        $data = json_encode($data, JSON_UNESCAPED_UNICODE);

        curl_setopt($oCurl, CURLOPT_POST, true);

        curl_setopt($oCurl, CURLOPT_POSTFIELDS, $data);

        //至关重要,CURLINFO_HEADER_OUT选项可以拿到请求头信息

        curl_setopt($oCurl, CURLINFO_HEADER_OUT, TRUE);

        curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);

        //curl_setopt($oCurl, CURLOPT_POSTFIELDS, $bodystr);

        $sContent = curl_exec($oCurl);

        //通过curl_getinfo()可以得到请求头的信息

        $a = curl_getinfo($oCurl);

        return $sContent;

        //var_dump($sContent);die;

    }
}