landingurl = $landingurl; $this->adid = $adid; $adlist = $this->getrealexpend($landingurl,3,$adid,3); if($adlist){ if($adlist['list']){ if($adid){ $this->statCost = $adlist['list'][0]['statCost']; $this->bid = $adlist['list'][0]['bid']; $this->bidconf = $this->getbidconf($adlist['list'][0]['bid']); } } } $this->conf = db('postbackconfig')->where('id',1)->find(); } //校验单计划消耗 public function checkexpend(){ //凌晨到6点之间不受限制 $h=date('H'); if($h<6){ return true; } $ispass = db('returnpay_log')->where('adid',$this->adid)->count('id'); if(empty($ispass)){ $bidconf = $this->bidconf; if($bidconf){ if($this->statCost>$bidconf['preconditions']){ return true; } } return false; }else{ return true; } } //校验首充笔数 自动修改回传比例 public function checkfirstcharge($tid){ if(empty($tid) || empty($this->adid)){ return false; } $adid = $this->adid; $bidconf = $this->bidconf; $rules = $bidconf['list']; $info = db('planratio_set')->field('id,value,firstchargenum')->where(['tid'=>$tid,'adid'=>$adid])->find(); foreach($rules as $k=>$v){ if($info['firstchargenum']>=$v['oneval']){ if($info['value']!=$v['twoval']){ db('planratio_set')->where(['tid'=>$tid,'adid'=>$adid])->update([ 'value'=>$v['twoval'], 'counts'=>0 ]); $log = '落地页id:'.$tid.'计划id:'.$adid.'首充笔数'.$info['firstchargenum'].'比例修改为'.$v['twoval'].'当前出价:'.$this->bid; $this->dblog($tid,$adid,$log); } break; } } } //获取出价对应配置 public function getbidconf($bid){ $wh['start'] = array('<',$bid); $wh['end'] = array('>',$bid); $data = db('postbackconfig_bid')->where($wh)->find(); $data['list'] = db('postbackconfig_list')->where('bid',$data['id'])->order('cast(oneval as signed) desc')->select(); return $data; } // 巨量实时消耗 time 1 近一年 2近一个小时 3近一天 // adid 单条计划没有返回所有计划 // adStatus 1 包含已删除的 2不包含 public function getrealexpend($landingurl,$time=3,$adid=null,$adStatus=2){ $timarr = $this->timetype($time); $url = 'http://ocean.cswmwangluo.cn/api/v1/ocean/cost/realTimeByLand'; $arr = array(); $arr['landUri'] = $landingurl; $arr['startTime'] = $timarr['startdata']; $arr['endTime'] = $timarr['enddata']; $arr['adStatus'] = $adStatus; if($adid){ $arr['adId'] = intval($adid); } $arr = json_encode($arr); $res = $this->pushMessageToClient($url,$arr); $res = json_decode($res,true); if($res['code']=='200'){ return $res['result']; }else{ $res['errorLandingurl'] = $landingurl; $this->wrlog($res); return 0; } } //找到对应计划数据 public function find_by_foreach($array,$find){ if(empty($array)){ return 0; } foreach ($array as $key => $v){ if($v['adId']==$find){ return $array[$key]; } } return 0; } //时间格式返回 public function timetype($t){ if($t==1){ //一年内 $startdata = '2021-03-16 0:0:0'; }elseif($t==2){ //一个小时内 $startdata = date('Y-m-d H:0:0'); }elseif($t==3){ //一天内 $startdata = date('Y-m-d 0:0:0'); } $enddata = strtotime(date('Y-m-d H:i:s')); //现在 $f = date('i'); $enddata = $enddata+((60-$f)*60); $enddata = date('Y-m-d H:i:s',$enddata); $arr = array( 'startdata'=>$startdata, 'enddata'=>$enddata ); return $arr; } public function dblog($tid,$adid,$log){ db('controlaccout_log')->insert([ 'tid'=>$tid, 'adid'=>$adid, 'log'=>$log, 'addtime'=>time() ]); } public function wrlog($txt){ $log = json_encode($txt); $log .= ' 时间:'.date("Y-m-d H:i:s",time()); $log .= "\n"; @file_put_contents('log/Controlaccout.txt',$log,FILE_APPEND); } public function pushMessageToClient($url,$data){ //初使化init方法 $ch = curl_init(); //指定URL curl_setopt($ch, CURLOPT_URL, $url); //设定请求后返回结果 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //声明使用POST方式来进行发送 curl_setopt($ch, CURLOPT_POST, 1); //发送什么数据呢 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //忽略证书 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //忽略header头信息 curl_setopt($ch, CURLOPT_HEADER, 0); //设置超时时间 curl_setopt($ch, CURLOPT_TIMEOUT,600); //发送请求 $output = curl_exec($ch); curl_close($ch); //返回数据 return $output; } }