addBehavior( new SoftDelete([ 'field' => 'deleted', 'value' => 1, ]) ); } public function beforeCreate() { if (empty($this->avatar)) { $this->avatar = kg_default_avatar_path(); } elseif (Text::startsWith($this->avatar, 'http')) { $this->avatar = self::getAvatarPath($this->avatar); } $this->create_time = time(); } public function beforeUpdate() { if (time() - $this->update_time > 3 * 3600) { $sync = new GroupIndexSync(); $sync->addItem($this->id); } if (Text::startsWith($this->avatar, 'http')) { $this->avatar = self::getAvatarPath($this->avatar); } if ($this->deleted == 1) { $this->published = 0; } $this->update_time = time(); } public function afterFetch() { if (!Text::startsWith($this->avatar, 'http')) { $this->avatar = kg_cos_avatar_url($this->avatar); } } public static function getAvatarPath($url) { if (Text::startsWith($url, 'http')) { return parse_url($url, PHP_URL_PATH); } return $url; } public static function types() { return [ self::TYPE_COURSE => '课程', self::TYPE_CHAT => '聊天', self::TYPE_STAFF => '员工', ]; } }