<?php
class FunnelModel extends CI_Model
{
    private $eventTypes = [
        1001                    => 'new_guide', //新手引导
        10005                   => 'new_version_guide', //新版新手引导
        10006                   => 'create_role', //创建角色
        10007                   => 'new_guide_slot', //新手引导，老虎机
        10008                   => 'pay_report', //支付上报
        10009                   => 'pay_report_success', //支付上报支付成功
        10010                   => 'pay_report_cancel', //支付上报取消支付
        10012                   => 'advertiseID', //广告Id
        10013                   => 'network_connect_error', //网络异常
        10014                   => 'login_event',
        10015                   => 'gift_event',
        10016                   => 'invite_event',
        10017                   => 'share_event',
        10018                   => 'activity_event',
        10019                   => 'coizner',
        10020                   => 'callback_friend',
        'login_start'           => 'login_start',
        'login_gusest_click'    => 'login_gusest_click',
        'invite_friend'         => 'invite_friend',
        'invite_friend_success' => 'invite_friend_success',
        100001                  => 'login_start',     //游戏启动
        100002                  => 'login_guest_click', //点击“游客”
        100003                  => 'login_fb_login',       //“fb”原生登录
        100004                  => 'login_fb_cancel',     //“fb”原生登录失败
        100005                  => 'login_fb_fail',         //“fb”原生登录失败
        100006                  => 'login_fb_succ',         //“fb”原生登录成功
        100007                  => 'login_fb_click',       //点击“FB”
        100008                  => 'login_apple_login', //"apple"原生登录
        100009                  => 'login_apple_fail',   //“apple”原生登录失败
        100010                  => 'login_apple_succ',   //“apple”原生登录成功
        100011                  => 'login_apple_click', //点击“apple”登录
        100012                  => 'login_srv_request', //请求登录Srv
        100013                  => 'login_srv_succ',       //登录Srv成功
        100014                  => 'login_srv_timeout', //登录Srv超时
        100015                  => 'login_srv_fail',       //登录Srv超时
        100016                  => 'fb_connect',               //登录后玩家绑定Facebook
        100017                  => 'gue_logsuc',         //游客登录成功
        100018                  => 'gue_regsuc',           //游客注册成功
        100019                  => 'fb_logsuc',             //FB登录成功
        100020                  => 'fb_regsuc',               //FB重试登录成功
        100021                  => 'apple_logsuc',       //苹果登录成功
        100022                  => 'apple_regsuc',         //苹果重试登录成功
        100023                  => 'enter_mainscene',    //转景到MainScene
    ];

    public function isFunnelReport($type) {
        return $type >= 100001 && $type <= 100100;
    }

    public function getTypeByFunnel($type = 0) {
        if($type == 'login_start'){ //重复事件
            return '';
        }
        return isset($this->eventTypes[$type]) ? $this->eventTypes[$type] : '';
    }

    /**
     * 埋点上报到redis队列,go上报到elk
     * @param array $param
     */
    public function funnelReport(array $param = [], $ip = ''){
        ///////////////////////////////
        return; //elk上报关停
        ///////////////////////////////
        $oos_debug = $this->config->item('oos_debug');
        //测试环境不上报了
        if(empty($param['event_id']) || $oos_debug){
            return;
        }
        $keys = $this->getTypeByFunnel($param["event_id"]);
        if(empty($keys)){
            return;
        }
        $param['info'] = $param['data'];
        $eventId = $param["event_id"];
        unset($param['data'], $param['commonData'], $param['data'], $param['superKey'], $param['lang'], $param['param'], $param['saToken'], $param['event_id']);
        $funnelData = [
            'topic'    => $keys,
            'tag'      => 'bury-point',
            'time'     => date('Y-m-d H:i:s', time()),
            'event_id' => $eventId,
            'content'  => json_encode($param),
        ];
        if(!empty($ip)){
            $funnelData['client_ip'] = $ip;
        }
        //elk上报关停
        //oo::commonOprRedis("Statistics")->lpush(okeys::funnel(),json_encode($funnelData));
    }
}
