<?php
defined('BASEPATH') OR exit('No direct script access allowed');
use Aws\CloudFront\CloudFrontClient;
class Test extends MY_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->library('curl');
        $this->load->model('common');
    }
    public function index()
    {
//        var_dump(111111);
//        oo::commonOprModel('currency')->cronCreatAssessTable(true);
//        exit;
//        oo::commonOprModel('currency')->cronCreatActAssessTable(1);
//        oo::commonOprModel('asynclog')->actCacheInfoDb();
//        var_dump(funs_testfuns());//测试公用方法调用
//        var_dump(logMessage('debug',123));//自定义写日志
//        var_dump($this->common->test());//测试model调用
//        $file_path = str_replace("\\","/",PUBLIC_PATH . '/1.txt');
//        var_dump($file_path);logMessage('debug',$file_path);
//        var_dump($this->common->upToOss('public/1.txt',$file_path));//上传文件
//        $this->common->getInfoFromOss('public/1.txt');//判断文件

        $tb = otable::slotWeightChangeCfg();
        $sql = "SELECT * FROM {$tb}";
        $datas = oo::commonOprDb('games')->getAll($sql,1);
        $data = array_column($datas,'config','type');
        $arr = json_decode($data['spinsLost'],true);
        echo "<pre>";
        print_r($arr);
    }
    //批量上传阿里oss
    public function plupfile(){
        ini_set('max_execution_time', 3600);
        $dir = ['/game/newAssets','/game/config','/game/image/activity_2','/game/image/newcard','/game/image/card','/avatar'];
        $public_path =str_replace("\\","/",PUBLIC_PATH);
        $file_path1 = str_replace("\\","/",PUBLIC_PATH .$dir[2]);
        $fileArr = $this->common->scan($file_path1);
        foreach ($fileArr as $v){
            $file_name = "public".substr($v,strlen($public_path));
            $res = $this->common->upToOss($file_name,$v);
            if(!$res){
                echo "error:".$file_name;
            }
        }
    }
    public function refreshCdn(){
        oo::commonOprModel('member')->updateUserGroupByUid();
        var_dump(oo::commonOprModel('member')->getUserDynamicsData(10008));
    }

    public function updateGroup(){
        $param = $this->input->get();
        $uid   = max(intval($param['uid']),0);
        if(!empty($uid)){
            $actionGroupId = oo::commonOprModel('member')->updateUserGroup2($uid);
            var_dump($actionGroupId);
            if($actionGroupId){
                $tb  = otable::Polymerization(2);
                $ret = oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb}",MYSQLI_ASSOC);
                foreach ($ret as $key=>$row){
                    $ret[$row['id']] = array_column(json_decode($row['group_pro'],true),null,'id');
                }
            }else{
                $ret = [];
            }
            $postData = array('lid' => 1, 'sid' => 1,'service'=>1);
            $postData['mod'] = 'Config';
            $postData['act'] = 'polymerization';
            $postData['uid'] = $uid;
            $res = $this->curl->req($this->config->item('officialUrl'), $postData);
            $res = json_decode($res,true)['data']['config'];
            echo "最新数据：<br/>";
            foreach ($res as $row){
                echo "广告点：".$row['name']."，广告次数：".$row['max']."，广告概率：".$row['probability']."，广告开放等级：".$ret[$row['id']][$actionGroupId]['levelId'].'<br/>';
            }
        }else{
            oo::commonOprModel('member')->updateUserGroup2();
        }
    }

    public function refreshAwsCDN($path = '*'){
        $path = '/public/game/test/test.json';
        $config = [];
        $credentials = new Aws\Credentials\Credentials('AKIASBFCV66S3SPJ3T7Q', 'c361xYWPK/EGxxgRRt8ZQ6wPKKS919cGBrRpUpDH');
        $config['credentials'] = $credentials;
        $config['version'] = '2020-05-31';
        $config['version'] = '2019-03-26';
        $config['region'] = 'us-east-1';
        $config['debug']  = true;
        $client = new CloudFrontClient($config);
        $result = $client->createInvalidation([
            'DistributionId' => 'E3GCT1DAII1ECW',
            'InvalidationBatch' => [
                'CallerReference' => time(), // REQUIRED
                'Paths' => [ // REQUIRED
                    'Items' => [$path],
                    'Quantity' => 1, // REQUIRED
                ],
            ],
        ]);
        echo '<pre>';
        var_dump($result);
    }
}