<?php

namespace App\Modules\ShareFree\Models;

use App\Modules\Book\Services\BookConfigService;
use Illuminate\Database\Eloquent\Model;

class ShareBringUsers extends Model
{
    protected $table = 'share_bring_users';
    protected $fillable = ['id', 'uid', 'bid', 'cid','buid','is_subscribe', 'share_user_id'];

    public static function addShareUsers($data) {
        if(isset($data['uid'])&&isset($data['bid'])&&isset($data['share_user_id'])) {
            return self::updateOrCreate(['uid'=>$data['uid'],'bid'=>$data['bid'],'share_user_id'=>$data['share_user_id'],'buid'=>$data['buid']]);
        }
        return self::create($data);
    }

    public static function getShareSuccessUsers($share_user_id){
        return self::join('users','users.id','=','share_bring_users.buid')->select('users.id','users.head_img','nickname')->where('share_user_id',$share_user_id)->where('share_bring_users.is_subscribe',1)->limit(3)->get();
    }
}
