137 lines
4.2 KiB
PHP
137 lines
4.2 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | 时间段自动补回传 [ WE CAN DO IT JUST THINK IT ]
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\admin\controller;
|
|
use app\common\controller\Admin;
|
|
use think\Cache;
|
|
use think\Controller;
|
|
|
|
class Timeautofill extends Controller{
|
|
|
|
public function index(){
|
|
$checktime = $this->checktime();
|
|
if($checktime){
|
|
$trs = db('transfer')->field('id')->where('controlaccout_open',1)->select();
|
|
if($trs){
|
|
foreach($trs as $k=>$v){
|
|
$this->check($v['id'],$checktime);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function check($tid,$tim){
|
|
$is = db('returnpay_log')->where(['ldurl'=>$tid,'status'=>1])->where('addtime', 'between', [$tim['startdata'],$tim['enddata']])->count('id');
|
|
if(empty($is)){
|
|
$this->pay($tid);
|
|
}else{
|
|
$log = "当前时间段有回传 系统无需补回传";
|
|
$this->dblog($tid,0,$log);
|
|
}
|
|
}
|
|
|
|
public function pay($tid){
|
|
$startdata = time() - 3600;
|
|
$data = db('payclickid')->field('id,clickid,adid,aidname,uid')->where(['ldurl'=>$tid])->where('addtime', 'between', [$startdata,time()])->find();
|
|
if($data){
|
|
db('payclickid')->where('id',$data['id'])->delete();
|
|
$this->transpay($data['clickid']);
|
|
$returnpaylog = array(
|
|
'uid'=>$data['uid'],
|
|
'ldurl'=>$tid,
|
|
'type'=>'手动 自定义补回传 系统自动 '.$data['aidname'],
|
|
'addtime'=>time(),
|
|
'status'=>3,
|
|
'channel'=>0
|
|
);
|
|
//写入回传日志
|
|
db('returnpay_log')->insert($returnpaylog);
|
|
db('transfer')->where('id',$tid)->update(['intercept'=>1,'intercept_time'=>time()]);
|
|
$log = "系统自动补1回传";
|
|
$this->dblog($tid,0,$log);
|
|
}else{
|
|
$log = "近一小时内无充值id 系统无需补回传";
|
|
$this->dblog($tid,0,$log);
|
|
}
|
|
}
|
|
|
|
public function checktime(){
|
|
$startdata = 0;
|
|
$enddata = 0;
|
|
$tims = db('postbackconfig_list_time')->select();
|
|
$H = date('H:i');
|
|
foreach($tims as $k=>$v){
|
|
if($H>=$v['startdata'] && $H<=$v['enddata']){
|
|
$startdata = strtotime($v['startdata']);
|
|
$enddata = strtotime($v['enddata']);
|
|
}
|
|
}
|
|
if($startdata){
|
|
return array(
|
|
'startdata'=>$startdata,
|
|
'enddata'=>$enddata
|
|
);
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function dblog($tid,$adid,$log){
|
|
db('controlaccout_log')->insert([
|
|
'tid'=>$tid,
|
|
'adid'=>$adid,
|
|
'log'=>$log,
|
|
'addtime'=>time()
|
|
]);
|
|
}
|
|
|
|
// 回传方式2
|
|
public function transpay($clickid='',$type='active_pay'){
|
|
$arr = [
|
|
'event_type'=>$type,
|
|
'context'=>[
|
|
'ad'=>[
|
|
'callback'=>$clickid
|
|
]
|
|
],
|
|
'timestamp'=>time()
|
|
];
|
|
$arr = json_encode($arr);
|
|
$url = 'https://analytics.oceanengine.com/api/v2/conversion';
|
|
$this->pushMessageToClient($url,$arr);
|
|
}
|
|
|
|
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, 10);
|
|
//发送请求
|
|
$output = curl_exec($ch);
|
|
curl_close($ch);
|
|
//返回数据
|
|
return $output;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |