travel/service/app/functions.php

71 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Here is your custom functions.
*/
/**
* Is Url In Domain With Path
* @param $urlToCheck
* @param $baseUrl
* @return bool
*/
function isUrlInDomainWithPath($urlToCheck,$baseUrl): bool
{
// 解析基础 URL
$baseUrlParts = parse_url($baseUrl);
if (!$baseUrlParts) {
return false; // 解析失败
}
$basePath = $baseUrlParts['path'] ?? '';
// 去除路径末尾的斜杠(如果有的话)
$basePath = rtrim($basePath, '/');
// 解析要检查的 URL只提取主机名
$urlToCheckParts = parse_url($urlToCheck);
if (!$urlToCheckParts) {
return false; // 解析失败
}
$checkHost = $urlToCheckParts['host'] ?? '';
// 比较主机名是否相同,并且检查路径是否包含要检查的 URL 的主机名(这里其实是检查整个路径)
if ($basePath === $checkHost && strpos($urlToCheck,$basePath) !== false) {
return true;
}
return false;
}
function get_week_days() {
// 获取当前日期
$currentDate = new DateTime();
// 获取本周的周一使用ISO-8601标准一周的开始是周一
$currentDate->modify('this week monday');
// 存储周一到周日的日期
$weekDays = [];
// 循环获取本周的每一天
for ($i = 0; $i < 7; $i++) {
// 获取当前日期并添加到数组
$weekDays[] = [
'date' => $currentDate->format('Y-m-d')
];
// 将日期调整到下一个日期(例如,周二 -> 周三)
$currentDate->modify('+1 day');
}
return $weekDays;
}
function getNewOrderId($type) {
list($msec, $sec) = explode(' ', microtime());
$msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
$orderId = $type . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
return $orderId;
}