php哪一个是主程序,PHP页面数据采集程序的主程序

);

continue;

}

if($this->debug)$this->debug('debug',"$type:start:$start,interver:$interval,time:".time().",lasttime:".$lasttime);$this->Run($key);

continue;

}//固定时间运行$type=$rmt['gather_time_type'];

if($this->debug)$this->debug('debug',"ui_rg_time");

if(!$rmt['points']) continue;//未设置时间点if($this->debug)$this->debug('debug',"point is set");$d=getdate();//取得当前时间的部分$now_wday=$d['wday'];//0表示周日$now_hours=$d['hours'];$now_minutes=$d['minutes'];$d=getdate($lasttime);//取得最后一次运行的时间部分$last_wday=$d['wday'];$last_hours=$d['hours'];$last_minutes=$d['minutes'];

if($this->debug)$this->debug('debug',"now:$now_wday $now_hours:$now_minutes");

if($this->debug)$this->debug('debug',"last:$last_wday $last_hours:$last_minutes");

foreach($rmt['points'] as$point){$point=$point['time_point'];

if($type=='ui_rg_everyday'){//每天运行list($set_hours,$set_minutes)=explode(':',$point);

if($this->greater2($set_hours,$set_minutes,$last_hours,$last_minutes)&&$this->greater2($now_hours,$now_minutes,$set_hours,$set_minutes)){

if($this->debug)$this->debug('debug',"every day");

if($this->debug)$this->debug('debug',"set point:$set_hours $set_minutes");$this->Run($key);

}

}else{//每周运行if($this->debug)$this->debug('debug',"every week");

list($set_wday,$set_hours,$setminutes)=split('[/.\s]',$point);

if($this->debug)$this->debug('debug',"set point:$set_wday $set_hours:$set_minutes");

if($this->greater3($set_wday,$set_hours,$set_minutes,$last_wday,$last_hours,$last_minutes)&&$this->greater3($now_wday,$now_hours,$now_minutes,$set_wday,$set_hours,$set_minutes)){$this->Run($key);

}

}//每周运行处理结束}//循环每一个采集时间点结束}//循环每一个RMT网站结束}//检查并采集方法结束

//比较第一个(时,分)是否大于第二个functiongreater2($h1,$m1,$h2,$m2){

if($h1>$h2)returntrue;

if($h1

return$m1>$m2;

}//比较第一个(天,时,分)是否大于第二个functiongreater3($d1,$h1,$m1,$d2,$h2,$m2){

if($d1>$d2)returntrue;

if($d1

if($h1>$h2)returntrue;

if($h1

return$m1>$m2;

}

functionsaveName($games){

foreach($gamesas$game){$gameName=$game['name'];$areas=$game['area'];$sql="select count(*) from `rmt_game` where `name`='$gameName'";$count=$this->db->Single($sql);

if($count<1){$sql="select count(*) from `rmt_game_alias` where `alias`='$gameName'";$count=$this->db->Single($sql);

if($count<1){$sql="insert into rmt_game(name)values('$gameName')";$this->db->Query($sql);$game_ID=$this->db->InsertID();$this->debug('game not found',_T::gameNotFound.":$gameName");

}else{$sql="select game_ID from rmt_game_alias where alias='$gameName'";$game_ID=$this->db->Single($sql);

}

}else{$sql="Select `game_ID` from `rmt_game` where `name`='$gameName'";$game_ID=$this->db->Single($sql);

}

if(count($areas)>0)

foreach($areasas$areaName){//查区域表$sql="select count(*) from `rmt_area` where `name`='$areaName' and `game_ID`='$game_ID'";

if($this->db->Single($sql)>0) continue;//查区域别名表$sql="select count(*) from rmt_area_alias where  alias='$areaName'";

if($this->db->Single($sql)>0)continue;$this->debug('area not found',_T::areaNotFound.":$gameName:$areaName");$sql="insert into rmt_area(game_ID,name)values($game_ID,'$areaName')";$this->db->Query($sql);

}

}

}/**

* 保存采集到的数据,入口参数是一个数组

* Buy ,

* Sell: {

*  $gameName=>{

*   $areaName=>{

*    'detailURL'=>$detailURL,

*    'areaName'=>$areaName,

*    'basePrice'=>$basePrice,

*    'stock'=>$stock,

*    'favor'=>{

*     $stock=>$price,

*     ......other favor price

*    }

*   },

*   ......other area

*  },

*  ......other game

* }

*

* Status:

* {

*  {

*   'code'=>$code,

*   'content'=>$content

*  },

* ......other status

* }

* @param unknown_type $all

*/functionsaveData($all,$gl_ID){//查看是否有这个RMT网站,如果有,得到rmt_ID$RMT_name=$all['rmt']['name'];$rmt_ID=$all['rmt']['rmt_ID'];

if(isset($all['Buy']))$Buy=$all['Buy'];

else$Buy=null;

if(isset($all['Sell']))$Sell=$all['Sell'];

else$Sell=null;$sellCount=0;

if($Buy)

foreach($Buyas$gameName=>$areas){$ret=$this->saveGame($gameName,$areas,'Buy',$rmt_ID,$gl_ID);

if($ret)$sellCount+=$ret;

}//处理所有购买价格if($Sell)

foreach($Sellas$gameName=>$areas){$ret=$this->saveGame($gameName,$areas,'Sell',$rmt_ID,$gl_ID);

if($ret)$sellCount+=$ret;

}

if($sellCount&&$all['rmt']['user_ID']){//将库存的减少量加到商户的人气点击上$sql='update rmt_companypro set clicks=clicks+'.$sellCount.' where user_ID='.$all['rmt']['user_ID'];$this->db->Query($sql);

}//dump($all);dump($sellCount);exit;

//记录运行信息$timeStart=$all['timeStart'];$readPages=$all['readPages'];//根据Status要发消息和邮件$status=$all['Status'];$this->debug('dump',dump($status,'',true));$company=$all['rmt']['user_ID'];

if(count($status)>0){//有消息要发送$title=_T::gatherError.":".$RMT_name.":".date('Y-m-d H:i');$content='';

foreach($statusas$s){$content.="\n";$content.=$s['code'];$content.=$s['content'];$content.="\n";$content.="\n";

}$c("'","`",$content);$params=$rmt_ID;

{//发送消息$this->sendMsg('ui_message_type_deny_gather',$title,$content,0,1,$params);

if($company>0){//发消息给商户$this->sendMsg('ui_message_type_deny_gather',$title,$content,1,$company,$params);//取商户的email$sql="select email from rmt_users where user_ID=$company";$to=$this->db->Single($sql);//发送邮件gatherMail($title,$content,$to);

}

}

}$timeEnd=time();$elapse=$timeEnd-$timeStart;$sql="update rmt_gather_log set pages=$readPages,seconds=$elapse where gl_ID=$gl_ID";$this->db->Query($sql);

}

functionsendMsg($type,$title,$content,$from,$to,$params){$sql="insert into rmt_message(type,title,content,user_ID,params,created)values(";$sql.="'$type','$title','$content',$from,'$params',".time().")";$this->db->Query($sql);$id=$this->db->InsertID();$sql="insert into rmt_message_user(user_ID,message_ID,`read`,reply,created)values(";$sql.="$to,$id,0,0,".time().")";$this->db->Query($sql);

}

functionsaveGame($gameName,$areas,$direction,$rmt_ID,$gl_ID){$sellCount=0;//本游戏的出货量

//根据游戏名查找游戏ID$gameName=strtolower(trim($gameName));$sql="select count(*) from `rmt_game` where lower(trim(`name`))='$gameName'";$count=$this->db->Single($sql);

if($count<1){$sql="select count(*) from `rmt_game_alias` where lower(trim(`alias`))='$gameName'";$count=$this->db->Single($sql);

if($count<1){$this->sendMsg('ui_message_type_gather_new_game',_T::new_game_title,_T::new_game.$gameName.".

\n",0,1,$rmt_ID);$this->debug('game not found',_T::gameNotFound.":$gameName");//$sql="insert into rmt_game(name)values('$gameName')";

//$this->db->Query($sql);

//$game_ID=$this->db->InsertID();return0;

}else{$sql="select game_ID from rmt_game_alias where lower(trim(alias))='$gameName'";$game_ID=$this->db->Single($sql);

}

}else{$sql="Select `game_ID` from `rmt_game` where lower(trim(`name`))='$gameName'";$game_ID=$this->db->Single($sql);

}

if(count($areas)>0){

foreach($areasas$areaName=>$area){$area_ID=$this->getAreaID($game_ID,$areaName,$gameName);

if($area_ID===false)continue;$basePrice=$area['basePrice'];

if($basePrice<=0)continue;$stock=$area['stock'];

if(isset($area['favor']))$favors=$area['favor'];

else$favors=null;//此处需要过滤和修正{/*

$filterTop=$this->setting['filter'][$direction]['Top'];

$filterBottom=$this->setting['filter'][$direction]['Bottom'];

if(strpos($filterTop,'%')||strpos($filterBottom,'%')){

//取出基准价格

$refPrice=0;

if(isset($this->setting['base'][$game_ID]))

if($this->setting['base'][$game_ID]){

$refRMT=$this->setting['base'][$game_ID];

$sql="select price from rmt_gather_data where game_ID=$game_ID and area_ID=$area_ID and isLast=1 and rmt_ID=$refRMT and direction='$direction'";

if($this->db->Rows($sql)>0){

$refPrice=$this->db->Single($sql);

if(strpos($filterTop,'%')){

$filterTop=$this->getMiddle($filterTop,null,'%');

$filterTop=$refPrice*$filterTop/100;

}

if(strpos($filterBottom,'%')){

$filterBottom=getMiddle($filterBottom,null,'%');

$filterBottom=$refPrice*$filterBottom/100;

}

if($filterTop)  if($basePrice>$filterTop)continue;

if($filterBottom) if($basePrice                    }//找到了基准站的价格

}//设置了基准站

}else{

if($filterTop)  if($basePrice>$filterTop)continue;

if($filterBottom) if($basePrice                    }

*/}//过滤处理完成

//以前的数据成为旧数据$sql="select count(*) from rmt_gather_data where game_ID=$game_ID and area_ID=$area_ID and rmt_ID=$rmt_ID and Direction='$direction' and isLast=1";$count=$this->db->Single($sql);

if($count>0){//取最后一次的库存$sql="Select stock from rmt_gather_data where game_ID=$game_ID and area_ID=$area_ID and rmt_ID=$rmt_ID and Direction='$direction' and isLast=1";$lastStock=$this->db->Single($sql);$sql="Select gd_ID from rmt_gather_data where game_ID=$game_ID and area_ID=$area_ID and rmt_ID=$rmt_ID and Direction='$direction' and isLast=1";$gd_IDs=$this->db->table($sql);

foreach($gd_IDsas$gd_ID){$gd_ID=$gd_ID['gd_ID'];$sql="update rmt_gather_data_favor set isLast=0 where gd_ID=$gd_ID";$this->db->Query($sql);

}$sql="update rmt_gather_data set isLast=0 where game_ID=$game_ID and area_ID=$area_ID and rmt_ID=$rmt_ID and Direction='$direction' and isLast=1";

}else$lastStock=0;//修正{$modify=$this->setting['modify'][$direction][$rmt_ID];

if($modify){$basePrice=$basePrice*$modify/100;

foreach($favorsas$fCount=>$fPrice)$favors[$fCount]=$fPrice*$modify/100;

}

}

if($lastStock&&$stock

}$this->db->Query($sql);//插入数据库一条数据if($basePrice&&$stock) {$sql="insert into `rmt_gather_data`(`game_ID`,`area_ID`,`rmt_ID`,`Direction`,`price`,`stock`,`created`,`gl_ID`,isLast) "."values('$game_ID','$area_ID','$rmt_ID','$direction','$basePrice','$stock',".time().",$gl_ID,1)";$this->db->Query($sql);$gd_ID=$this->db->InsertID();//处理优惠价if($favors)if(count($favors)>0)

foreach($favorsas$fCount=>$fPrice)if($fPrice>0){$sql="insert into rmt_gather_data_favor(gd_ID,price,count)values($gd_ID,$fPrice,$fCount)";$this->db->Query($sql);

}//写入所有优惠价}

}//处理所有区域}

return$sellCount;

}//根据区域名查找区域,如果没有这个区域,插入functiongetAreaID($game_ID,$areaName,$gameName){//查区域表$areaName=strtolower(trim($areaName));$sql="select count(*) from `rmt_area` where lower(trim(`name`))='$areaName' and `game_ID`='$game_ID'";

if($this->db->Single($sql)>0){$sql="select area_ID from rmt_area where lower(trim(`name`))='$areaName' and game_ID='$game_ID'";

return$this->db->Single($sql);

}//查区域别名表$sql="select count(*) from rmt_area_alias where  lower(trim(alias))='$areaName'";

if($this->db->Single($sql)>0){$sql="select area_ID from rmt_area_alias where  lower(trim(alias))='$areaName'";

return$this->db->Single($sql);

}$this->sendMsg('ui_message_type_new_area',_T::new_area_title,_T::new_area.$gameName.':'.$areaName,0,1,$game_ID);$this->debug('area not found',_T::areaNotFound.":".$gameName.":".$areaName);//$sql="insert into rmt_area(game_ID,name)values($game_ID,'$areaName')";

//$this->db->Query($sql);

//return $this->db->InsertID();returnfalse;

}

functiondebug($name,$content){$str=date('Y-m-d H:i:s')."\t";$str.=$name."\t";$str.=$content."\n";

echo$str;file_put_contents($this->log_file,$str,FILE_APPEND);

}/**

* 获取字符串中指定开头和结尾中间的内容(不包括开头和结尾标识),不区分大小写

*

* @param 要处理的字符串 $str

* @param 开头标识 $begin(如果空,则从字符串开头开始)

* @param 结尾标识 $end(如果空,则到字符串结尾)

*

* @return 返回中间的字符串,或者是错误代码

*/protected  final functiongetMiddle($str,$begin=null,$end=null,$enableN){

if($begin!==null){$begin=strtolower($begin);$i=strpos($str,$begin);

if($i===false){

if($enableNone)return'';$this->status(array('code'=>_T::GC_EXPLODE_NO_BEGIN,'content'=>"$begin\n$str\n"));

returnfalse;

}$str=substr($str,$i+strlen($begin));

if($str===false){

if($enableNone)return'';$this->status(array('code'=>_T::GC_EXPLODE_NO_MIDDLE,'content'=>"$begin\n$end\n$str\n"));

returnfalse;

}

}

if($end!==null){$end=strtolower($end);$j=strpos($str,$end);

if($j===false){

if($enableNone)return$str;$this->status(array('code'=>_T::GC_EXPLODE_NO_END,'content'=>"$end\n$str"));

returnfalse;

}$str=substr($str,0,$j);

if($str===false){

if($enableNone)return'';$this->status(array('code'=>_T::GC_EXPLODE_NO_MIDDLE,'content'=>"$begin\n$end\n$str"));

returnfalse;

}

}

return$str;

}

}?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值