<?php

namespace App\Models\Subscribe;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;

/**
 * 书籍订阅 按日统计
 */

class BookOrderByDay extends Model
{

    protected $table = 'book_order_by_day';

    /**
     * 按日期查询记录
     * @param $Date
     * @param int $is_chapter
     * @param int $is_out
     * @return mixed
     */
    public static function getRecordByDate($Date, $is_chapter = -1, $is_out = -1)
    {
        $list = self::where('day', $Date);
        if ($is_chapter > -1)
            $list = $list->where('is_chapter', $is_chapter);
        if ($is_out > -1)
            $list = $list->where('is_out', $is_out);
        return $list->get();
    }

    /**
     * 按日期删除记录
     * @param $day
     * @param int $is_chapter
     * @param int $is_out
     * @return mixed
     */
    public static function deleteRecordByDay($day, $is_chapter = -1, $is_out = -1)
    {
        $list = self::where('day', $day);
        if ($is_chapter > -1)
            $list = $list->where('is_chapter', $is_chapter);
        if ($is_out > -1)
            $list = $list->where('is_out', $is_out);
        return $list->delete();
    }

    /**
     * @param $array
     */
    public static function insertRecord($array)
    {
        self::insert($array);
    }

    /**
     * 查询时间段内的记录
     * @param $dateStart
     * @param $dateEnd
     * @return mixed
     */
    public static function getRecordByDateQuantum($dateStart, $dateEnd)
    {
        try
        {
            $list = self::where('day', '>=', $dateStart)->where('day', '<', $dateEnd)->get();
            return $list;
        }
        catch (\Exception $e)
        {
            Log::info('------ 出错了'.$e->getMessage());
        }

    }
}
