<?php

namespace App\Modules\WechatMaterial\Models;


use Illuminate\Database\Eloquent\Model;

class WechatMaterialSendMsg extends Model
{
    protected $table = 'wechat_material_send_msgs';
    protected $connection = 'api_mysql';

    protected $fillable = ['batch_id', 'distribution_channel_id', 'appid', 'name', 'wechat_material_id', 'wechat_media_id',
        'status', 'send_user_num', 'receive_user_num', 'first_day_material_uv', 'first_day_url_uv', 'del_flag', 'upload_result',
        'created_at', 'updated_at'];


    public static function get_zs_wechat_batch_distribution_infos($batch_id)
    {
        return self::where('batch_id', $batch_id)->select('batch_id', 'distribution_channel_id', 'appid')->get();
    }


    public static function get_infos_by_batch_id($batch_id,$columns=[])
    {
        if(!isset($columns))
        {
            $columns ='*';
        }
        return self::where('batch_id', $batch_id)->select($columns)->get();
    }

    /**
     * 根据状态获取客服消息
     */
    public static function wechatCustomMsgsByStatus($status)
    {

        return self::where(['status' => $status, 'del_flag' => 0])->get();

    }

    public static function getMsgByAppBatchChannelId($appId, $batchId, $channelId)
    {
        $where  = ['appid' => $appId, 'batch_id' => $batchId, 'distribution_channel_id' => $channelId];
        $result = self::where($where)->first();
        return $result ? $result->toArray() : [];
    }

    /**
     *
     * @return mixed
     */
    public static function getUnCollectedList()
    {
        $result = self::whereNull('first_day_material_uv')->get();
        return $result;
    }
}