Video.php 1.5 KB
<?php

namespace app\api\model;

use think\Model;


class Video extends Model
{

    

    

    // 表名
    protected $name = 'video';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text'
    ];
    

    
    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getVideoImageAttr($value)
    {
        if ($value) $value = cdnurl($value);
        return $value;
    }

    public function getVideoAttr($value)
    {
        if ($value) $value = cdnurl($value);
        return $value;
    }

    public function selectPageData($where,$page,$limit,$lang){
        $where['status'] = 1;
        if ($lang == 'ch') $field = 'id,title,video_image,video';
        else $field = 'id,en_title title,video_image,video';
        $total = $this
            ->where($where)
            ->count();

        $list = $this
            ->where($where)
            ->field($field)
            ->page($page,$limit)
            ->select();
        return ['total' => $total, 'list' => $list];
    }
}