false, ]; protected $casts = [ 'os' => AppOs::class, 'update_strategy' => AppUpdateStrategy::class, 'is_force' => 'bool', 'release_at' => 'datetime', ]; protected $fillable = [ 'os', 'name', 'version', 'title', 'description', 'update_strategy', 'is_force', 'apk_url', 'wgt_url', 'release_at', ]; public function scopeOnlyReleased(Builder $query) { $query->whereNotNull('release_at')->where('release_at', '<=', now()); } /** * 是否是全量包升级 */ public function isApkUpdate(): bool { return $this->update_strategy === AppUpdateStrategy::Apk; } /** * 按客户端系统和版本号获取最新的全量包 */ public static function getLatestApkUrl(AppOs $clientOs, int $clientVersion): string { return (string) static::OnlyReleased() ->where('os', $clientOs) ->where('version', '>', $clientVersion) ->whereNotNull('apk_url') ->latest('version') ->value('apk_url'); } protected function apkUrl(): Attribute { return Attribute::make( set: function (mixed $value) { if ((string) $value === '') { $value = null; } return $value; }, ); } protected function wgtUrl(): Attribute { return Attribute::make( set: function (mixed $value) { if ((string) $value === '') { $value = null; } return $value; }, ); } protected function isRelease(): Attribute { return Attribute::make( get: function (mixed $value, $attributes) { return (bool) $attributes['release_at']; }, ); } }