thinkphp 查詢當天 ,本周,本月,本季度,本年度,全部, 資料方法

來源:互聯網
上載者:User

標籤:儲存   返回   extend   splay   return   get   between   time   extends   

資料庫欄位是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();

資料就尋找出來了。。。

thinkphp 查詢當天 ,本周,本月,本季度,本年度,全部, 資料方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.