<?php

namespace App\Modules\Cpa\Models;

use Illuminate\Database\Eloquent\Model;

class AdvertiseUsers extends Model
{
    protected $table = 'advertise_users';
    protected $fillable = ['id', 'uid', 'bid', 'advertise_id'];

    static function addAdUsers($params){
        return self::create($params);
    }

    static function addOrUpdateAdUsers($insert,$update=''){
        if($update){
            return self::updateOrCreate($insert,$update);
        }
        \Log::info('insert2:'.json_encode($insert));
        return self::updateOrCreate($insert);
    }

    static function getOne($params){
        $obj = self::orderBy('id');
        if(isset($params['uid'])&&$params['uid']) {
            $obj->where('uid',$params['uid']);
        }

        if(isset($params['bid'])&&$params['bid']){
            $obj->where('bid',$params['bid']);
        }

        if(isset($params['advertise_id'])&&$params['advertise_id']) {
            $obj->where('advertise_id',$params['advertise_id']);
        }
        return $obj->first();
    }
}
