<?php
/**
 * Created by PhpStorm.
 * User: hp
 * Date: 2017/11/21
 * Time: 8:59
 */

namespace App\Modules\MediaPush\Models;

use Illuminate\Database\Eloquent\Model;
use DB;

class MediaPushGzh extends Model
{
    protected $table = 'media_push_gzhs';
    protected $fillable = ['appid', 'media_push_channel_user_id', 'distribution_channel_id', 'channel_user_id', 'nickname', 'is_enabled', 'is_auth'];

    static function getGzhList($params)
    {
        $obj = self::orderBy('id', 'desc');

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

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

        if (isset($params['nickname']) && $params['nickname']) {
            $obj->where('nickname', 'like', '%' . $params['nickname'] . '%');
        }

        $obj->where('is_auth', 1);
        return $obj->paginate();
    }

    static function getById($id)
    {
        return self::where('id', $id)->first();
    }

    static function getByAppid($appid)
    {
        return self::where('appid', $appid)->first();
    }
}