<?php
/**
 * Created by PhpStorm.
 * User: z-yang
 * Date: 2019/1/10
 * Time: 11:31
 */

namespace App\Modules\YunQi\Services;


use App\Modules\YunQi\Models\BookYunqi;
use Redis;

class BookYunqiService
{
    public static function create($bid,$yq_bid){
       $type = 'DEFAULT';
        if(self::getByBid($bid)){
            return false;
        }
       return BookYunqi::create(compact('bid','yq_bid','type'));
    }

    public static function getByBid($bid){
        if(empty($bid))return false;
        return BookYunqi::where('bid',$bid)->select('bid','type','id')->first();
    }

    public static function getRandomBooks($num=1):array{
        $books = BookYunqi::select('bid')->get();
        if($books->count()<=0){
            return [];
        }
        $num = $books->count()>$num ?$num:$books->count();
        return $books->random($num)->pluck('bid')->all();
    }

}