<?php

namespace App\Modules\Book\Models;

use Illuminate\Database\Eloquent\Model;

class BookPromotionChecked extends Model
{
    protected $table = 'book_promotion_info_checked';
    protected $fillable = ['id', 'book_id', 'book_name', 'cp_source', 'operator', 'status', 'size', 'is_on_shelf',
        'recharge_amount_in_24h_outside', 'recharge_amount_in_24h_inside', 'recharge_amount_in_72h_inside',
        'recharge_amount_in_72h_outside', 'periods', 'onshelf_date', 'author', 'updated_at', 'created_at'];

    static function getInfo($periods,$isAll)
    {
        $search_object = self::orderBy('created_at', 'desc');

        if ($periods){
            $search_object->where('periods',$periods);
        }

        if ($isAll) {
            return $search_object->get();
        } else {
            return $search_object->paginate();
        }
    }

    static function getMaxPeriod()
    {
        return self::max('periods')+1;
    }
}