<?php
/**
 * ${CARET}
 * @file:NoitceService.php
 * @Created by gnitif
 * @Date: 2023/3/27
 * @Time: 11:54
 */


namespace Modules\Channel\Services\User;

use Modules\Channel\Models\Users;

class UserService {


    public static function listByRole(string $identify, array $field){
        return Users::join('user_has_roles','user_has_roles.user_id','=','users.id')
        ->join('roles','roles.id','=','user_has_roles.role_id')
        ->where('roles.identify',$identify)
        ->select($field)
        ->get();
    }


    public static function userHasRole(int $uid,string $identify){

        return self::userHasRoles($uid,[$identify]);
    }

    public static function userHasRoles(int $uid,array $identify){
        return Users::join('user_has_roles','user_has_roles.user_id','=','users.id')
        ->join('roles','roles.id','=','user_has_roles.role_id')
        ->where('users.id',$uid)
        ->whereIn('roles.identify',$identify)
        ->count();
    }

    public static function getOptimizers($pid,array $field){
        return Users::where('pid',$pid)->where('status',1)->select($field)->get();
    }
    


}