<?php

namespace App\Modules\OfficialAccount\Models;

use Illuminate\Database\Eloquent\Model;

class DistributionSelfDefineConfig extends Model
{
	protected $connection = 'api_mysql';
	
    protected $tables = 'distribution_self_define_configs';

    protected $fillable = ['distribution_channel_id','company_id','account','content','desc','status','type','created_at','updated_at'];


    static function getDistributionSelfDefineConfig($distribution_channel_id,$type)
    {
        return self::where(['distribution_channel_id'=>$distribution_channel_id,'type'=>$type,'status'=>1])->first();
    }
    
    static function getDistributionChannelSwitchByCategoryAndCompany($company_id,$type)
    {
    	return self::where(['company_id'=>$company_id,'type'=>$type,'status'=>1])->first();
    }
    
    static function getDistributionChannelSwitchByCategoryAndAccount($account,$type){
    	return self::where(['account'=>$account,'type'=>$type,'status'=>1])->first();
    }
    
    static function getDistributionsByType($type)
    {
    	return self::where(['type'=>$type,'status'=>1])->get();
    }
    
    static function getDistributionIdsByType($type):array{
    	return self::where(['type'=>$type,'status'=>1])->get()->pluck('distribution_channel_id')->all();
    }

}


