<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ServiceUserBindRole extends BaseModel
{
    use HasFactory;

    public function insertUserBindData($chat_id,$service_user,$role_id){
        $insertBindRoleData = [];
        $info = self::where('user_id',$service_user->user_id)
            ->where('chat_id',$chat_id)
            ->where('role_id',$role_id)
            ->exists();
        if(!$info){
            $insertBindRoleData['created_at'] = $insertBindRoleData['updated_at'] = date('Y-m-d H:i:s');
            $insertBindRoleData['chat_id'] = $chat_id;
            $insertBindRoleData['user_id'] = $service_user->user_id;
            $insertBindRoleData['role_id'] = $role_id;
            self::insert($insertBindRoleData);
        }
    }
}
