0]; /** * @var array * * 直播扩展属性 */ protected $_live_attrs = ['start_date' => '', 'end_date' => '']; /** * @var array * * 图文扩展属性 */ protected $_read_attrs = ['duration' => 0, 'word_count' => 0]; /** * 主键编号 * * @var int */ public $id; /** * 类型 * * @var string */ public $class_id; /** * 标题 * * @var string */ public $title; /** * 封面 * * @var string */ public $cover; /** * 简介 * * @var string */ public $summary; /** * 关键字 * * @var string */ public $keywords; /** * 详情 * * @var string */ public $details; /** * 市场价格 * * @var float */ public $market_price; /** * 会员价格 * * @var float */ public $vip_price; /** * 学习期限(月) * * @var int */ public $study_expiry; /** * 退款期限(天) * * @var int */ public $refund_expiry; /** * 综合得分 * * @var float */ public $score; /** * 模式类型 * * @var string */ public $model; /** * 难度级别 * * @var string */ public $level; /** * 扩展属性 * * @var string */ public $attrs; /** * 课时数 * * @var int */ public $lesson_count; /** * 学员数 * * @var int */ public $user_count; /** * 评论数 * * @var int */ public $comment_count; /** * 咨询数 * * @var int */ public $consult_count; /** * 评价数 * * @var int */ public $review_count; /** * 收藏数 * * @var int */ public $favorite_count; /** * 发布标识 * * @var int */ public $published; /** * 删除标识 * * @var int */ public $deleted; /** * 创建时间 * * @var int */ public $created_at; /** * 更新时间 * * @var int */ public $updated_at; public function getSource() { return 'kg_course'; } public function initialize() { parent::initialize(); $this->addBehavior( new SoftDelete([ 'field' => 'deleted', 'value' => 1, ]) ); } public function beforeCreate() { $this->created_at = time(); $attrs = []; switch ($this->model) { case Course::MODEL_VOD: $attrs = $this->_vod_attrs; break; case Course::MODEL_LIVE: $attrs = $this->_live_attrs; break; case Course::MODEL_READ: $attrs = $this->_read_attrs; break; } if (!empty($attrs)) { $this->attrs = kg_json_encode($attrs); } } public function beforeUpdate() { $this->updated_at = time(); if (!empty($this->attrs)) { $this->attrs = kg_json_encode($this->attrs); } } public function afterFetch() { $this->market_price = (float)$this->market_price; $this->vip_price = (float)$this->vip_price; if (!empty($this->attrs)) { $this->attrs = json_decode($this->attrs, true); } } public static function modelTypes() { $types = [ self::MODEL_VOD => '点播', self::MODEL_LIVE => '直播', self::MODEL_READ => '图文', ]; return $types; } public static function levelTypes() { $types = [ self::LEVEL_ENTRY => '入门', self::LEVEL_JUNIOR => '初级', self::LEVEL_MEDIUM => '中级', self::LEVEL_SENIOR => '高级', ]; return $types; } public static function studyExpiryOptions() { $options = [ 1 => '1个月', 3 => '3个月', 6 => '6个月', 12 => '12个月', 36 => '36个月', ]; return $options; } public static function refundExpiryOptions() { $options = [ 7 => '7天', 14 => '14天', 30 => '30天', 90 => '90天', 180 => '180天', ]; return $options; } }