<?php
/**
 * Adjust 数据回传
 * Adjust.php
 * Created by: Owen
 * Created on: 2020/8/25 10:56
 */


defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * 上报方法
 */
class Adjust extends CI_Controller{
    public function __construct(){
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('cookie');
        $this->load->model('oo');
        $this->output->set_header("Access-Control-Allow-Origin: * ");
    }

    /**
     * 数据实时回传
     * 配置路径：https://dash.adjust.com/
     * @return false|string
     * Created by: HSS
     * Created on: 2020/6/20 12:25
     */
    public function callbacks(){
        $param = $this->input->get();
        $tb    = otable::AdJustData();
        $sqlTemp['adid'] = $param['adid'];
        $keyArr= ['idfa','gps_adid','tracker_name','network_name','campaign_name','adgroup_name','creative_name','created_at','activity_kind','label'];
        foreach($keyArr as $row){
            if(!empty($param[$row])){
                $sqlTemp[$row] = $param[$row];
            }
        }
        $key   = implode(',',array_keys($sqlTemp));
        $value = "'".implode("','",array_values($sqlTemp))."'";
        oo::commonOprDb('games')->query("INSERT INTO {$tb} ({$key}) VALUES ({$value})", false);
        return oo::response(1);
    }

    public function check(){
        $tb    = otable::AdJustData();
        $tbs   = otable::AdJustSta();
        $ret   = oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb}",MYSQLI_ASSOC);
        foreach ($ret as $row){
            var_dump($row['adid']);
            if(!empty($row['gps_adid'])){
                $one = oo::commonOprDb('default')->getOne("SELECT * FROM {$tbs} WHERE android='{$row['gps_adid']}' LIMIT 1",MYSQLI_ASSOC);
                if(!empty($one)){
                    var_dump($one['uid']);
                }
                continue;
            }
            if(!empty($row['idfa'])){
                $one = oo::commonOprDb('default')->getOne("SELECT * FROM {$tbs} WHERE ios='{$row['idfa']}' LIMIT 1",MYSQLI_ASSOC);
                if(!empty($one)){
                    var_dump($one['uid']);
                }
                continue;
            }
        }
    }
}

