標籤:php計劃任務方法
//計劃任務批量重新整理房源 public function allRefresh(){ $houseDb=D("House"); $data=$houseDb->get_list(); //dump($data); } 下面的為model裡的資料處理,上面的為控制器部分 //查詢所有資料 public function getAll($where,$page = 1,$page_num = 10){ $houseDb=D("House"); $data=$this->where($where)->limit(($page - 1) * $page_num,$page_num)->select(); return $data; } //查詢所有資料總數 public function get_list(){ $where[‘isDel‘] = ‘0‘; $where[‘status‘] = ‘2‘; $where[‘auditstatus‘] = ‘1‘;//已審核 $where[‘salestatus‘] = ‘0‘;//在售 $houseDb=D("House"); $totalCount=$houseDb->where($where)->count(); $totalpage=ceil($totalCount/10); for ($nowPage=1;$nowPage<=$totalpage;$nowPage++){ $list=$houseDb->getAll($where,$nowPage,10); // print_r($houseDb->getLastSql()) ; $this->refreshData($list); } } //批量重新整理房源的停留時間和計算 public function refreshData($list){ // echo ‘111‘; foreach($list as $key=>$value){ //計算出來停留時間 $data=array(); $where[‘esfId‘]=$value[‘esfId‘]; $data[‘stayTime‘]=($value[‘publishScore‘]*$value[‘houseRatio‘])/100*3600+$value[‘verifyTime‘]; $houseRatio= $this->where($where)->save($data);//更新房源係數 //首頁排序數量 $data=array(); $where=array(); //計算上周經濟人日均發房源數量 $map[‘esfId‘]=$value[‘esfId‘]; $start= mktime(0,0,0,date(‘m‘),date(‘d‘)-date(‘w‘)+1-7,date(‘Y‘)); //上周起時間 $end= mktime(23,59,59,date(‘m‘),date(‘d‘)-date(‘w‘)+7-7,date(‘Y‘)); //上周結束時間 $map[‘verifyTime‘]=array(between,array($start,$end)); $count= $this->where($map)->count();//得到上周總發房源總數 $where=array(); $data=array(); $where[‘esfId‘]=$value[‘esfId‘]; if($count){ $indexNum=$count/6; //日均發房源數量 } $data[‘indexNum‘]=intval($indexNum); //日均數量 $stayTime=$this->where($where)->save($data);//更新房源停留時間 //echo $this->getLastSql();die; } }
本文出自 “PHP/[email protected]” 部落格,請務必保留此出處http://liang3391.blog.51cto.com/178205/1843760
php計劃任務方法