<?php

namespace App\Modules\OfficialAccount\Models;

use Illuminate\Database\Eloquent\Model;

class CustomMsgSwitchs extends Model
{
    protected $tables = 'custom_msg_switchs';

    protected $fillable = ['title','custom_category','status','is_self_content','desc_content','img_url'];


    static function customMsgSwitchsBySwitchId($custom_category)
    {
        
        return self::where('custom_category',$custom_category)->first();
    
    }

    /**
     * 获取所有客服消息开关
     */
    static function getCustomMsgSwitchs()
    {
    	return self::where(['status'=>1])->select('custom_category','id','title')->orderBy('id','asc')->get();
    }
    
    /**
     * 获取所有客服消息开关
     */
    static function customMsgSwitchs()
    {
        
        return self::select()->get();
    
    }
    
    /**
     * 获取类型为键名的所有客服消息开关
     */
    static function getCustomMsgSwitchByCategorys()
    {
    	$result = array();
    	$custom_msg_switchs = self::select()->get()->toArray();
    	foreach($custom_msg_switchs as $key=> $custom_msg_switch){
    		$result[$custom_msg_switch['custom_category']] = $custom_msg_switch;
    	}
    	return $result;
    
    }

}


