• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Mico
好好学习。。天天向上。。
博客园    首页    新随笔    联系   管理    订阅  订阅
thinkphp 查询当天 ,本周,本月,本季度,本年度,全部, 数据方法

ReserveModel.class.php 文件

数据库字段是createtime 里面保存的是时间戳

 

<?php
/*
*按今天,本周,本月,本季度,本年,全部查询预约单数据
* $day 代表查询条件 $cid 代表 公司id
*返回array $data 查询条件 数组
*/
class ReserveModel extends BaseModel {
public function find_createtime($day,$cid){
//查询当天数据
if($day==1){
$today=strtotime(date('Y-m-d 00:00:00'));
$data['cid']=$cid;
$data['createtime'] = array('egt',$today);
return $data;
//查询本周数据
}else if($day==2){
$arr=array();
$arr=getdate();
$num=$arr['wday'];
$start=time()-($num-1)*24*60*60;
$end=time()+(7-$num)*24*60*60;
$data['cid']=$cid;
$data['createtime'] = array('between',array($start,$end));
return $data;
//查询本月数据
}else if($day==3){
$start=strtotime(date('Y-m-01 00:00:00'));
$end = strtotime(date('Y-m-d H:i:s'));
$data['cid']=$cid;
$data['createtime'] = array('between',array($start,$end));
return $data;
//查询本季度数据
}else if($day==4){
$month=date('m');
if($month==1 || $month==2 ||$month==3){
$start=strtotime(date('Y-01-01 00:00:00'));
$end=strtotime(date("Y-03-31 23:59:59"));
}elseif($month==4 || $month==5 ||$month==6){
$start=strtotime(date('Y-04-01 00:00:00'));
$end=strtotime(date("Y-06-30 23:59:59"));
}elseif($month==7 || $month==8 ||$month==9){
$start=strtotime(date('Y-07-01 00:00:00'));
$end=strtotime(date("Y-09-30 23:59:59"));
}else{
$start=strtotime(date('Y-10-01 00:00:00'));
$end=strtotime(date("Y-12-31 23:59:59"));
}
$data['cid']=$cid;
$data['createtime'] = array('between',array($start,$end));
return $data;
//查询本年度数据
}else if($day==5){
$year=strtotime(date('Y-01-01 00:00:00'));
$data['cid']=$cid;
$data['createtime'] = array('egt',$year);
return $data;
//全部数据
}else{
$data['cid']=$cid;
return $data;
}
}
}
?>

 

然后再CompanyAction.class.php中写

$list=$Shop->where($data)->select();

$this->list=$list;

$this->display();

数据就查找出来了。。。

好好学习 天天向上~
posted on 2013-11-05 13:49  yuemengke  阅读(10002)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3