<?php

namespace App\Modules\Statistic\Models;

use Illuminate\Database\Eloquent\Model;

class SendOrderBreadevenStat extends Model
{
    protected $table = 'send_order_breakeven_stats';

    protected $fillable = [
        'distribution_channel_id', 'official_account_id', 'official_account_name', 'date', 'force_user_num',
        'total_force_user_num', 'unsubscribe_in_one_day_user_num', 'created_at', 'updated_at', 'recharge_amount_in_one_day',
        'recharge_amount_in_three_days', 'recharge_amount_in_one_month', 'recharge_amount_in_two_months', 'recharge_amount_in_three_months'];


    static function getInfo($params = [], $isAll = false)
    {
        $search_object = self::orderBy('created_at', 'desc');
        if (isset($params['end_date']) && $params['end_date']) $search_object->where('date', '<=', $params['end_date']);
        if (isset($params['start_date']) && $params['start_date']) $search_object->where('date', '>=', $params['start_date']);
        if (isset($params['distribution_channel_id']) && $params['distribution_channel_id']) $search_object->where('distribution_channel_id', $params['distribution_channel_id']);
        if ($isAll) {
            return $search_object->get();
        } else {
            return $search_object->paginate();
        }
    }
}
