addBehavior( new SoftDelete([ 'field' => 'deleted', 'value' => 1, ]) ); } public function beforeCreate() { $this->created_at = time(); } public function beforeUpdate() { $this->updated_at = time(); } public function afterCreate() { $this->rebuildCache(); } public function afterUpdate() { $this->rebuildCache(); } public function rebuildCache() { $key = "{$this->course_id}_{$this->user_id}"; $courseUserCache = new CourseUserCache(); $courseUserCache->rebuild($key); } public static function roles() { $list = [ self::ROLE_STUDENT => '学员', self::ROLE_TEACHER => '讲师', ]; return $list; } public static function sources() { $list = [ self::SOURCE_FREE => '免费课程', self::SOURCE_PAID => '付费课程', self::SOURCE_VIP => '会员免费', self::SOURCE_IMPORT => '后台导入', ]; return $list; } }