<?php

namespace App\Modules\OfficialAccount\Models;

use Illuminate\Database\Eloquent\Model;
use DB;

class WechatKeywordMsgs extends Model
{
    protected $tables = 'wechat_keyword_msgs';
    protected $fillable = ['appids', 'keyword', 'distribution_channel_id','bid','cid','book_name','chapter_name','appid','status','send_title','send_cover','send_order_id','created_at','updated_at'];

    
    /**
     * 根据渠道获取关键字列表
     */
    static function wechatKeywordMsgsBydistributionChannelId($distribtion_channel_id)
    {
    	return self::where('distribution_channel_id', $distribtion_channel_id)->where('status', 1)->paginate();
    }
    
    /**
     * 根据渠道获取关键字列表
     */
    static function wechatKeywordByDistributionChannelIdAndKeyword($distribtion_channel_id,$keyword,$status=1)
    {
    	return self::where(['distribution_channel_id'=>$distribtion_channel_id,'keyword'=>$keyword,'status'=>$status])->first();
    }
    
  
    /**
     * 根据id获取关键字
     */
    static function wechatKeywordMsgsById($id)
    {
        return self::where('id', $id)->first();
    }
    
    /**
     * 更新关键字状态
     */
    static function updateWechatKeywordMsgStatus($id,$distribution_channel_id,$status)
    {
    	return self::where('id', $id)->where('distribution_channel_id', $distribution_channel_id)->update(['status'=>$status,'updated_at'=>date('Y-m-d H:i:s')]);
    }

}


