<?php

namespace App\Modules\OfficialAccount\Models;

use Illuminate\Database\Eloquent\Model;

class DistributionSelfDefineContent extends Model
{
	protected $connection = 'api_mysql';
	
    protected $tables = 'distribution_self_define_contents';

    protected $fillable = ['distribution_channel_id','content','status','is_pic','created_at','updated_at'];


    static function getDistributionSelfDefineContent($distribution_channel_id)
    {
        return self::where(['distribution_channel_id'=>$distribution_channel_id,'status'=>1])->first();
    }

    static function getAllDistributionSelfDefineContent($distribution_channel_id)
    {
        return self::where(['distribution_channel_id'=>$distribution_channel_id])->get();
    }

    static function setDistributionSelfDefineContent($params)
    {

        $distribution_channel_id = $params['distribution_channel_id'];
        $status = 1;
        $content = $params['content'];
        $is_pic = $params['is_pic'];
        $mode = $params['mode'];
        self::where('distribution_channel_id',$distribution_channel_id)->update(['status'=>0]);
        if($mode != 1)
        {
            self::updateOrCreate(compact('distribution_channel_id','is_pic'),compact('content','status'));
        }
        return true;
    }

}


