<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Video extends BaseModel
{
    use HasFactory;
    use SoftDeletes;
    protected $table = 'video';

    const STATUS_OPEN = 1;
    const STATUS_CLOSE = 0;
    public static function dealAcCid($list){
        foreach ($list as $item){
            $item->ac_cid = make_wangyiyun_accid($item->user_id);
            if(isset($item->user)){
                $item->user->ac_cid =  make_wangyiyun_accid($item->user->id);
            }
            if(isset($item->videoUser)){
                $item->videoUser->ac_cid =  make_wangyiyun_accid($item->videoUser->id);
            }
        }
        return $list;
    }

    // 过滤软删除数据
    protected static function boot()
    {
        parent::boot();

        // 在这里定义全局作用于模型的查询
        static::addGlobalScope('notDeleted', function ($query) {
            $query->whereNull('deleted_at');
        });
    }
}
