<?php
/**
 * Created by PhpStorm.
 * User: tandunzhao
 * Date: 2017/11/17
 * Time: 下午5:45
 */

namespace App\Modules\Finance\Models;


use Illuminate\Database\Eloquent\Model;

/**
 * Class FinancialConfig 渠道配置，冻结，解冻
 * @package App\Modules\Finance\Models
 */
class FinancialConfig extends Model
{
    protected $table = 'financial_configs';
    protected $fillable = ['distribution_channel_id', 'is_frozen', 'remark'];

    /**
     * 根据渠道ID获取FinancialConfig
     * @param $distribution_channel_id
     * @return mixed
     */
    static function getByDistributionChannel($distribution_channel_id)
    {
        return self::where('distribution_channel_id',$distribution_channel_id)->first();
    }


    /**
     * 渠道是否冻结
     * @param $distribution_channel_id
     * @return bool
     */
    static function isChannelFrozen($distribution_channel_id) {
        $financialConfig = FinancialConfig::getByDistributionChannel($distribution_channel_id);
        if(!empty($financialConfig) && $financialConfig['is_frozen'] == -1) {
            return true;
        }
        return false;
    }
}