现在出现提取不了的问题,还出现提取的期数为2009062020090620162,正确的应为20090620162,请高手帮我看看是什么原因,源码如下,另它统计的未开期数也不对
<?php
 require_once('../configs/config.php');
 require_once('../libcommon/Factory.php');
 require_once('numtimes.php');
 class lottery
 {
  private $oDao = null;
  private $oReader = null;
  private $oFilter = null;
  private $tableName = 'lottery';
  private $data;
  const DATENUM = 168;
  public function __construct()
  {
  $this->oDao = Dal_Factory::getInstance()->getDao($this->tableName);
  $this->oReader = Dal_Factory::getInstance()->getReader($this->tableName);  }
  public function getInfoById($id,$property=array())
  {
  $this->oFilter = Dal_Factory::getInstance()->getDalFilter();  
  $this->oFilter->addEqual('id',$id);
  $this->oReader->setFilter($this->oFilter);
  $result = $this->oReader->getList(0,1,$property);
  return $result;
  }
  public function getInfoByDateNum($dateNum)
  {
  $this->oFilter = Dal_Factory::getInstance()->getDalFilter();  
  $this->oFilter->addEqual('datenum',trim($dateNum));
  $this->oReader->setFilter($this->oFilter);
  $result = $this->oReader->getList(0,1,array());
  return $result;
  }
  public function getInfoList($offSet,$pageSize)
  {
  $this->oReader->setOrderBy(array('datenum'=>'desc'));
  $result =  $this->oReader->getList($offSet,$pageSize);
  $timeArray = array();
        foreach ($result as $key=>$v2)
        {
           array_push($timeArray,$v2['datenum']);
        }
        array_multisort($timeArray,SORT_ASC,$result);
        return $result;
  }
  public function updateData($id,$data)
  {
  $this->oFilter = Dal_Factory::getInstance()->getDalFilter();  
  $this->oFilter->addEqual('id',$id);
  return $this->oDao->update($data,$this->oFilter);
  }
  public function insertData(array $data)
  {
  if(empty($data)){
  throw new Exception("没有采集到数据");
  }
  //检查本期号码是否已存在
  $checkResult = $this->getInfoByDateNum($data[0]);
  if($checkResult){
  return false;
  }
  $i = 1;
  foreach ($data as $key=>$v){
   if($key==0){
    $newData['datenum'] = $v;
   } else {
          $newData['num_'.$i++] = $v;
          $data[] = $v;
   }
  }
  $newData['addtime'] = time();
  $this->updateTimes($newData);
  return $this->oDao->insert($newData);
  }
  public function outputData($data,$type=NULL)
{
           $offSet = ($this->page-1)*$this->pageSize;
           $str ="";
           if($type){
            $str .=$this->createDetailHtml(1,80,$data);
            return $str;
           }
           $str .=$this->createHtml(1,40,$data);
           $str .=$this->createHtml(41,80,$data);
           return $str;
}
public  function getMaxDate($maxDate,$num)
{
          $sql  = "SELECT MAX(datenum) FROM lottery WHERE datenum<$maxDate AND(";
          for($i=1;$i<=20;$i++){
           $sql .="num_$i=$num OR ";
          }
          $sql = trim($sql);
          $sql = substr($sql,0,strlen($sql)-2);
          $sql .= ")";
          $result = $this->oReader->execQuery($sql);
          return $result[0][0];
}
public function getMaxDateInAll()
{
$sql = "SELECT MAX(datenum) FROM lottery";
$result = $this->oReader->execQuery($sql);
return $result[0][0];
}
public function getMaxId($maxId,$num)
{
  $sql  = "SELECT MAX(id) FROM lottery WHERE datenum<$maxId AND(";
          for($i=1;$i<=20;$i++){
           $sql .="num_$i=$num OR ";
          }
          $sql = trim($sql);
          $sql = substr($sql,0,strlen($sql)-2);
          $sql .= ")";
          $result = $this->oReader->execQuery($sql);
          return $result[0][0];
}
public function getMaxIdInAll()
{
$sql = "SELECT MAX(id) FROM lottery";
$result = $this->oReader->execQuery($sql);
return $result[0][0];
}
private  function createHtml($start,$end,$data)
{
if($start>40){
 $html = "<table class='Tab'>";
} else {
 $html = "<table class='Tab1'>";
}
$html .="<tr><td width='70px'>期数</td>";
for ($i=$start;$i<=$end;$i++){
if($i<10){
$html .="<td  width='25px'>0$i</td>";
} else{
$html .="<td width='25px'>$i</td>";
}
}
$html .="</tr>";
foreach ($data as $key=>$v){
$html .="<tr><td height='31'>{$v['datenum']}</td>";
for ($h=$start;$h<=$end;$h++){
$html.="<td style='text-align:center;'>";
$newV = $this->getSepcialArray($v);
                if($h==$v['num_20']){
                 $html .="<div class='award_bg_red'>".$h."</div>";
                }elseif(in_array($h,$newV)){
$html .= "<div class='award_bg_blue'>".$h."</div>";
} else{
$result = $this->getMaxDate($v['datenum'],$h);
                    $distance = $this->getDistanceDay($result,$v['datenum']);
$html .=$distance;
}
$html .="</td>";
}
$html .="</tr>";
}
 return $html;
}
private function getDistanceDay($result,$nowDay)
{
 $dayArray = array('01'=>31,'02'=>28,'03'=>31,'04'=>30,'05'=>31,'06'=>30,'07'=>31,'08'=>31,'09'=>30,'10'=>31,'11'=>30,'12'=>31);
 $resultDate = substr($result,0,8);
          
 $dateNum = substr($result,8);
 $resultDay = substr($result,6,2);
 $resultMonth = substr($result,4,2);
 $resultMD = $resultMonth.$resultDay;
 
 $thisDate =  substr($nowDay,0,8);
 $thisNum = substr($nowDay,8);
 $thisDay = substr($nowDay,6,2);
 $thisMonth = substr($nowDay,4,2);
 $thisMD = $thisMonth.$thisNum;
 if($thisMonth==$resultMonth){   //如果是当月
  if($thisDay == $resultDay){
     $distance = $thisNum-$dateNum;
  } else{
     $distance = ($thisDay-$resultDay)*self::DATENUM- $dateNum+$thisNum;
  }
    
 }else{                   //不是当月出现  
  $distance = (($thisDay-1)*self::DATENUM +$thisNum) +(($dayArray[$resultMonth]-$resultDay-1)*self::DATENUM);
 }
 return $distance;
}
private function createDetailHtml($start,$end,$data)
{
$html = "<table class='Tab'>";
$html .="<tr><td width='70px'>期数</td>";
for ($i=$start;$i<=$end;$i++){
if($i<10){
$html .="<td width='15px'>0$i</td>";
} else{
$html .="<td width='15px'>$i</td>";
}
}
$html .="<td width='25px'>和数</td></tr>"; 
foreach ($data as $key=>$v){
$html .="<tr><td height='15'>{$v['datenum']}</td>";
for ($h=$start;$h<=$end;$h++){
$html.="<td style='text-align:center;'>";
$newV = $this->getSepcialArray($v);
$sum = array_sum($newV);
                if($h==$v['num_20']){
                 $html .="<div class='lunckyred'>".$h."</div>";
                }elseif(in_array($h,$newV)){
$html .= "<div class='lunckyblue'>".$h."</div>";
} else{
$result = $this->getMaxDate($v['datenum'],$h);
                    $distance = $this->getDistanceDay($result,$v['datenum']);
$html .=$distance;
}
$html .="</td>";
}
$html .="<td>$sum</td></tr>";
}
 return $html;
}
private function getDateTimesByNum($num)
{
$now = time();

}
private function  getSepcialArray(array $data)
{
foreach ($data as $key=>$v){
if(preg_match('/num_/',$key)){
      $filterArray[$key] = $v;
}
}
return $filterArray;
}
private function updateTimes($numArray)
 {
  $oNumtimes = new numtimes();
  $maxId = $this->getMaxIdInAll();
  $dateNum = $numArray['datenum'];
  array_shift($numArray);
  array_pop($numArray);
  $numTimesInfo = $oNumtimes->getGroupInfo($numArray);
/*  if(empty($numTimesInfo)){
  for($i=1;$i<=80;$i++){
  $data = array('id'=>$i,'time'=>time());
  $oNumtimes->insertData($data);
  }
  }*/
   for($i=1;$i<=80;$i++){
     $allNumArray[] = $i; 
   }
   $unOpenArray = array_diff($allNumArray,$numArray);
   foreach ($unOpenArray as $v){
  //1.处理历史最大遗漏,先取出此号码历史最大遗漏数,然后取出此号码本次离上次出现的期数
  //2.比较上面2个数,如果前者大于后者,跳过此循环,否则,更新历史最大遗漏数。
  $numInfo = $oNumtimes->getInfoById($v);
  $numInfo = $numInfo[0];
  $nowMaxId = $this->getMaxIdInAll();
  $nowShowMaxDate = $this->getMaxDate($dateNum,$v);
  $distance = $this->getDistanceDay($nowShowMaxDate,$dateNum);
  if($distance>$numInfo['historymaxtimes']){ // 比较
  $historyMax = $distance;
  $data['historymaxtimes'] = $historyMax;
  $oNumtimes->updateData($v,$data);
  }
  //处理当天未出现次数
  //$data['unopentimes']= $numInfo['unopentimes']+1;
 
  }
 }
public function createNumTable()
{
$sql = "create table numtimes('id' int(11) not null,";
$sql .= "'times' int(11) not null";
$sql .=")engine=innodb default charset=utf8";
}
public function getMaxOpenNum($dateRang='all')
{
    $todayZero = mktime(0,0,0,date('m',time()),date('d',time()),date('Y',time()));
  $con = "";
  if($dateRang=='all'){
   $where = "addtime>$todayZero";
  } elseif($dateRang=='sub'){
   $maxDate = $this->getMaxDateInAll();
   $dateStart = (date('Ymd',time()))."001";
        if(($maxDate-12)<$dateStart){
         $where = "datenum>$dateStart";
        } else{
         $where = "datenum>($maxDate-12)";
        }
  }
    for($i=1;$i<=20;$i++){
     if($i==20){
     $con .= "SELECT num_$i as num FROM lottery where ".$where;
     } else{
     $con .="SELECT num_$i as num FROM lottery where $where union all ";
     }
    }
    $sql = "SELECT a.num,count(*) as total FROM ($con) as a group by a.num";
        $result = $this->oReader->execQuery($sql);
        return $result;
}
public function getAllData()
{
   for($i=1;$i<=80;$i++)
   {
   $data[$i] = $i;
   }
   return $data;
}
 }
?>