<?php

namespace App\Modules\Book\Models;

use Illuminate\Database\Eloquent\Model;
use DB;

class BookOrderStatistical extends Model
{
    protected $table = 'book_order_statistical';

    public static function getTopSaleBooks($start_time,$end_time,array $on_shelf,$limit=10){

        return self::join('book_configs','book_order_statistical.bid','=','book_configs.bid')
            ->select('book_order_statistical.bid')
            ->whereIn('book_configs.is_on_shelf',$on_shelf)
            ->where('book_order_statistical.day','>=',$start_time)
            ->where('book_order_statistical.day','<=',$end_time)
            ->groupBy('book_order_statistical.bid')
            ->orderBy(DB::raw('sum(book_order_statistical.fee)'),'desc')
            ->limit($limit)
            ->get();
    }
}
