php tp获取最近七日数据,没有的赋默认值
短信预约 -IT技能 免费直播动态提醒
展示最近7天数据,当中天数没有的时候赋默认值
查询数据是这样,下图
protected $weeks = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];$nlist = [];// 得到最近7天年月日for($i=0;$i<$recent_7_day;$i++){$s_time = $startTime + (86400 * $i);$recent_date[$i] = date("Y-m-d", $s_time);$etime = date("Y-m-d",$s_time + $recent_7_day * 86400 );$Stime = date("Y-m-d",$s_time); // 医生挂号时间 $current_doc_sitschedule = XXX::where("work_time",">=",date("Y-m-d",$s_time)) ->where("work_time","<=",$etime) ->where("do_id",$do_id) ->field("id,perioddata,work_time") ->find(); // 是否有排班 if ($current_doc_sitschedule) { // 获取周几 $weekss = date('w', strtotime($current_doc_sitschedule['work_time'])); // 重新赋值 $current_doc_sitschedule['week'] = $this->weeks[$weekss]; $workTime = ['id' => $current_doc_sitschedule['id'], 'day' => $current_doc_sitschedule['work_time'], 'period' => $current_doc_sitschedule['perioddata'], 'week' => $current_doc_sitschedule['week']]; if ($current_doc_sitschedule['work_time'] >= $Stime && $current_doc_sitschedule['work_time'] <= $etime) { if (isset($nlist[$Stime])) {$nlist[$Stime] = $workTime; } else {$akl = date('w', strtotime($Stime));// 重新赋值$aklweek = $this->weeks[$akl];if ($current_doc_sitschedule['work_time'] !== $Stime) { $workTime = ['id' => 0, 'day' => $Stime, 'period' => 3, 'week' => $aklweek];}$nlist[$Stime] = $workTime; } } }else{ $akl = date('w', strtotime($Stime)); // 重新赋值 $aklweek = $this->weeks[$akl]; $workTime = ['id' => 0, 'day' => $Stime, 'period' => 3, 'week' => $aklweek]; $nlist[$Stime] = $workTime; }}// 按照 KEY 排序ksort($nlist);
循环后
来源地址:https://blog.csdn.net/weixin_43018356/article/details/126626121
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341