addBehavior( new SoftDelete([ 'field' => 'deleted', 'value' => 1, ]) ); } public function beforeCreate() { $this->create_time = time(); } public function beforeUpdate() { $this->update_time = time(); } public function beforeSave() { if (empty($this->cover)) { $this->cover = kg_default_package_cover_path(); } elseif (Text::startsWith($this->cover, 'http')) { $this->cover = self::getCoverPath($this->cover); } } public function afterCreate() { $cache = new MaxPackageIdCache(); $cache->rebuild(); } public function afterFetch() { if (!Text::startsWith($this->cover, 'http')) { $this->cover = kg_cos_package_cover_url($this->cover); } $this->market_price = (float)$this->market_price; $this->vip_price = (float)$this->vip_price; } public static function getCoverPath($url) { if (Text::startsWith($url, 'http')) { return parse_url($url, PHP_URL_PATH); } return $url; } }