手机号和身份证正则表达式
if(!empty($post['phone'])){
if (!preg_match("/^1[3456789]\d{9}$/", $post['phone'])) {
return __error('手机号码格式不正确');
}
}
if(!empty($post['identity'])) {
if (!preg_match("/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/", $post['identity'])) {
return __error('身份证格式不正确');
}
}
//生成订单号 24位
function generate($prefix = 'C')
{
return $prefix . date('YmdHis', time()) . substr(microtime(), 2, 6) . sprintf('%03d', rand(0, 999));
}
/**
* //获取指定日期内每一天的日期
* @param Date $startdate 开始日期
* @param Date $enddate 结束日期
* @return Array
*/
function getDateRange($startdate, $enddate)
{
$stimestamp = strtotime($startdate);
$etimestamp = strtotime($enddate);
// 计算日期段内有多少天
$days = (int) (($etimestamp - $stimestamp) / 86400) + 1;
// 保存每天日期
$date = [];
for ($i = 0; $i < $days; $i++) {
$date[] = date('Y-m-d', $stimestamp + (86400 * $i));
}
// unset($date[$days-1]);
return $date;
}
统计日期
$nums = BathArchiveDetail::from('bath_archive_detail as h')
->leftJoin('bath_archive as a', 'h.archive_id', '=', 'a.id')
->leftJoin('bath_device as d', 'd.id', '=', 'h.device_id')
->where('h.is_deleted', 0)
->where('a.is_deleted', 0)
->whereIn('a.site_id', $sids)
//日洗浴次数
->selectRaw('COUNT(IF(h.start_time >= ' . strtotime(date('Y-m-d 00:00:00')) . ' && h.start_time <= ' . strtotime(date('Y-m-d 23:59:59')) . ',h.id,null)) as daynums')
//日洗浴次数-异常
->selectRaw('COUNT(IF(h.start_time >= ' . strtotime(date('Y-m-d 00:00:00')) . ' && h.start_time <= ' . strtotime(date('Y-m-d 23:59:59')) . ' && h.bath_status = 0,h.id,null)) as daynonums')
//日洗浴次数-正常
->selectRaw('COUNT(IF(h.start_time >= ' . strtotime(date('Y-m-d 00:00:00')) . ' && h.start_time <= ' . strtotime(date('Y-m-d 23:59:59')) . ' && h.bath_status = 1,h.id,null)) as dayoknums')
//周洗浴次数
->selectRaw('COUNT(IF(h.start_time >= ' . strtotime(date('Y-m-d 00:00:00', strtotime('-7 days'))) . ' && h.start_time <= ' . strtotime(date('Y-m-d 23:59:59')) . ',h.id,null)) as weeknums')
//周洗浴次数-异常
->selectRaw('COUNT(IF(h.start_time >= ' . strtotime(date('Y-m-d 00:00:00', strtotime('-7 days'))) . ' && h.start_time <= ' . strtotime(date('Y-m-d 23:59:59')) . ' && h.bath_status = 0,h.id,null)) as weeknonums')
//周洗浴次数-正常
->selectRaw('COUNT(IF(h.start_time >= ' . strtotime(date('Y-m-d 00:00:00', strtotime('-7 days'))) . ' && h.start_time <= ' . strtotime(date('Y-m-d 23:59:59')) . ' && h.bath_status = 1,h.id,null)) as weekoknums')
//月洗浴次数
->selectRaw('COUNT(IF(h.start_time >= ' . strtotime(date('Y-m-d 00:00:00', strtotime('-30 days'))) . ' && h.start_time <= ' . strtotime(date('Y-m-d 23:59:59')) . ',h.id,null)) as monthnums')
//月洗浴次数-异常
->selectRaw('COUNT(IF(h.start_time >= ' . strtotime(date('Y-m-d 00:00:00', strtotime('-30 days'))) . ' && h.start_time <= ' . strtotime(date('Y-m-d 23:59:59')) . ' && h.bath_status = 0,h.id,null)) as monthnonums')
//月洗浴次数-正常
->selectRaw('COUNT(IF(h.start_time >= ' . strtotime(date('Y-m-d 00:00:00', strtotime('-30 days'))) . ' && h.start_time <= ' . strtotime(date('Y-m-d 23:59:59')) . ' && h.bath_status = 1,h.id,null)) as monthoknums')
->first();