<?php
/**
 * Created by PhpStorm.
 * User: z-yang
 * Date: 2019/1/7
 * Time: 14:22
 */

namespace App\Modules\Statistic\Services;

use App\Modules\Statistic\Models\AdVisitStat;

class AdVisitStatService
{
    public static function create($uid,$bid,$cid,$type){
        $model = new  AdVisitStat();
        $time = date('Ym');
        if($time == '201905'){
            $model->setCurrentTable();
        }else{
            $model->setCurrentTable($time);
        }
        try{
            $model->uid = $uid;
            $model->bid = $bid;
            $model->cid = $cid;
            $model->type = $type;
            $model->save();
        }catch (\Exception $e){

        }
    }

    public static function getInfo($uid,$cid,$type){
        $model = new  AdVisitStat();
        $time = date('Ym');
        if($time == '201905'){
            $model->setCurrentTable();
        }else{
            $model->setCurrentTable($time);
        }
        return AdVisitStat::where('uid',$uid)->where('cid',$cid)->where('type',$type)->first();
    }

    public static function getInfoV2($uid,$cid,$type){
        $model = new  AdVisitStat();
        $time = date('Ym');
        if($time == '201905'){
            $model->setCurrentTable();
        }else{
            $model->setCurrentTable($time);
        }
        return $model->where('uid',$uid)->where('cid',$cid)->whereIn('type',$type)->first();
    }

    public static function getByUid($uid){
        $model = new  AdVisitStat();
        $time = date('Ym');
        if($time == '201905'){
            $model->setCurrentTable();
        }else{
            $model->setCurrentTable($time);
        }
        return $model->where('uid',$uid)->select('id','type')->where('id','<=',12723415)->first();
    }
}