<?php
defined( 'IN_WEB') or die( 'Include Error!');
/**
 * 日志
 */
class Report {
    public function upload($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid) || empty($param['data'])){
            return json_encode(['code'=>-1,'msg'=>'param error']);
        }
		
		$param['data'] = json_decode($param['data'],true);
		if(is_array($param['data'])){
			$step = $param['data'][0];
		}else{
			$step = $param['data'];
		}
        $sgsid = !empty($param['sid']) ? $param['sid'] : oo::getDefinedSid($uid);

        switch ($param['event_id']){
            case 10002:
                $count =intval(oo::commonOprRedis('Statistics')->hGet(okeys::Report($param['event_id'],$sgsid),$uid)) + 1;
                $ret = oo::commonOprRedis('Statistics')->hSet(okeys::Report($param['event_id'],$sgsid),$uid.'-'.$step,$count);
            break;
            case 10003:
                $count =intval(oo::commonOprRedis('Statistics')->hGet(okeys::Report($param['event_id'],$sgsid),$uid)) + 1;
                $ret = oo::commonOprRedis('Statistics')->hSet(okeys::Report($param['event_id'],$sgsid),$uid.'-'.$step,$count);
            break;
			case 10012:
                oo::commonOprRedis('Statistics')->hSet(okeys::Report($param['event_id'],$sgsid),$uid,$step);
            break;
            default:
                $ret = oo::commonOprRedis('Statistics')->hSet(okeys::Report($param['event_id']),$uid,$step);
				if(in_array($param['event_id'],[10005,10006,10007])){
                	//新手步骤统计 总数
                	oo::commonOprRedis('Statistics')->hIncrBy(okeys::noviceStepsSta(),$step,1);
                	//新手步骤统计 FB用户
                	if($param['lid'] == 2){
                		oo::commonOprRedis('Statistics')->hIncrBy(okeys::noviceStepsSta(1),$step,1);
                	}
                }
                if(in_array($param['event_id'],[10008,10009,10010,10011])){
                	//支付上报
                	$sid = intval($param['sid']);
                	oo::commonOprModel('report')->payReport($sid,$step,$param['event_id']);
                }
			break;
        }

        if($ret)
            return json_encode(['code'=>1]);
        return json_encode(['code'=>-1]);
    }
	
	/**
     * 客户端日记
     * @return string
     * Created by: hss
     * Created on: 2020/3/13 16:28
     */
    public function clientlog($param){
    	$uid = oo::functions()->uint($param['uid']);
    	$ret = oo::commonOprModel('report')->clientlog($param['data'],$uid);
        return json_encode(['code'=>1,'length'=>$ret]);
    }
}
