网站建设资讯

NEWS

网站建设资讯

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计划任务方法(后台运行无刷新)
网站链接:http://cdweb.net/article/joccid.html