<?php

namespace App\Admin\Repositories;

use App\Models\DistAdminUser as Model;
use Dcat\Admin\Repositories\EloquentRepository;
use App\Models\DistAdminRoleUser;
class DistAdminUser extends EloquentRepository
{
    /**
     * Model.
     *
     * @var string
     */
    protected $eloquentClass = Model::class;


    /*
     * 增加角色用户色关系
     */
    public static function addRoleUser($userId,$roleId) {
        $distAdminRoleUser = new DistAdminRoleUser();
        $distAdminRoleUser->role_id = $roleId;
        $distAdminRoleUser->user_id = $userId;
        $distAdminRoleUser->save();
    }

    /*
     * 判断用户名是否存在
     */
    public static function findCountByUsername($id,$username)
    {
        $instance = new self();
        if ($id) {
            $count = $instance->Model()::where('username', $username)->where('id', '!=', $id)->count();
        } else {
            $count = $instance->Model()::where('username', $username)->count();
        }
        return $count;
    }
}
