1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-22 03:32:47 +08:00
2020-01-30 16:51:10 +08:00

108 lines
1.8 KiB
PHP

<?php
namespace App\Models;
use App\Services\Vod as VodService;
class ChapterVod extends Model
{
/**
* 主键编号
*
* @var int
*/
public $id;
/**
* 课程编号
*
* @var int
*/
public $course_id;
/**
* 章节编号
*
* @var int
*/
public $chapter_id;
/**
* 文件编号
*
* @var string
*/
public $file_id;
/**
* 文件转码
*
* @var string
*/
public $file_transcode;
/**
* 创建时间
*
* @var int
*/
public $created_at;
/**
* 更新时间
*
* @var int
*/
public $updated_at;
public function getSource()
{
return 'chapter_vod';
}
public function beforeCreate()
{
$this->created_at = time();
if (!empty($this->file_transcode)) {
$this->file_transcode = kg_json_encode($this->file_transcode);
}
}
public function beforeUpdate()
{
$this->updated_at = time();
if (!empty($this->file_transcode)) {
$this->file_transcode = kg_json_encode($this->file_transcode);
}
}
public function afterFetch()
{
if (!empty($this->file_transcode)) {
$this->file_transcode = json_decode($this->file_transcode, true);
} else {
$this->getFileTranscode($this->file_id);
}
}
protected function getFileTranscode($fileId)
{
if (!$fileId) return [];
$vodService = new VodService();
$transcode = $vodService->getFileTranscode($fileId);
if ($transcode && empty($this->file_transcode)) {
$this->file_transcode = $transcode;
$this->update();
}
return $transcode;
}
}