You've already forked Atomcms-edit
77 lines
2.3 KiB
PHP
Executable File
77 lines
2.3 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models\Shop;
|
|
|
|
use App\Models\Game\Furniture\ItemBase;
|
|
use App\Models\Game\Permission;
|
|
use Carbon\Carbon;
|
|
use Database\Factories\WebsiteShopArticleFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Support\Collection;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property string $name
|
|
* @property string $description
|
|
* @property string $furniture
|
|
* @property int $give_rank
|
|
* @property int $costs
|
|
* @property int $sort_order
|
|
* @property Carbon|null $created_at
|
|
* @property Carbon|null $updated_at
|
|
* @property-read Collection<int, ItemBase> $furniItems
|
|
* @property-read Permission|null $rank
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, WebsiteShopArticleFeature> $features
|
|
* @property-read float|int $price
|
|
*
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteShopArticle orderBy($column, $direction = 'asc')
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteShopArticle get($columns = ['*'])
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteShopArticle with($relations)
|
|
*/
|
|
class WebsiteShopArticle extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected static function newFactory()
|
|
{
|
|
return WebsiteShopArticleFactory::new();
|
|
}
|
|
|
|
#[\Override]
|
|
protected $guarded = ['id', 'created_at', 'updated_at', 'price', 'credits', 'duckets', 'diamonds', 'give_rank', 'badges', 'furniture', 'is_giftable'];
|
|
|
|
public function furniItems(): Collection
|
|
{
|
|
if (! $this->furniture) {
|
|
return collect();
|
|
}
|
|
|
|
$furniture = json_decode($this->furniture, true);
|
|
$furnitureIds = array_column($furniture, 'item_id');
|
|
|
|
return ItemBase::query()->whereIn('id', $furnitureIds)->get();
|
|
}
|
|
|
|
public function rank(): HasOne
|
|
{
|
|
return $this->hasOne(Permission::class, 'id', 'give_rank');
|
|
}
|
|
|
|
public function features(): HasMany
|
|
{
|
|
return $this->HasMany(WebsiteShopArticleFeature::class, 'article_id', 'id');
|
|
}
|
|
|
|
public function price(): float|int
|
|
{
|
|
if ($this->costs < 100) {
|
|
return 1;
|
|
}
|
|
|
|
return $this->costs / 100;
|
|
}
|
|
}
|